Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Gala.Text #1869

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/Text.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-2.0-or-later
*/

/*
* Clutter.Text that automatically changes font-name to the system one
*/
public class Gala.Text : Clutter.Text {
private static GLib.Settings gnome_interface_settings;

static construct {
gnome_interface_settings = new GLib.Settings ("org.gnome.desktop.interface");
}

construct {
set_system_font_name ();
gnome_interface_settings.changed["font-name"].connect (set_system_font_name);
}

private void set_system_font_name () {
var name = gnome_interface_settings.get_string ("font-name").split (" ");
var last_element_index = name.length - 1;

if (int.try_parse (name[last_element_index])) { // if last element is a font-size
name[last_element_index] = "12"; // hardcode size (can be changed later if needed)
} else {
name += "12";
}

font_name = string.joinv (" ", name);

warning ("Gala.Text: Changing font to %s", font_name);
}
}
1 change: 1 addition & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gala_lib_sources = files(
'Drawing/Utilities.vala',
'Plugin.vala',
'ShadowEffect.vala',
'Text.vala',
'Utils.vala',
'WindowIcon.vala',
'WindowManager.vala',
Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/Tooltip.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Gala.Tooltip : CanvasActor {
/**
* Actor to display the Tooltip text.
*/
private Clutter.Text text_actor;
private Gala.Text text_actor;

/**
* Maximum width of the Tooltip.
Expand All @@ -29,7 +29,7 @@ public class Gala.Tooltip : CanvasActor {
(uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.alpha * uint8.MAX,
};

text_actor = new Clutter.Text () {
text_actor = new Gala.Text () {
margin_left = 6,
margin_top = 6,
margin_bottom = 6,
Expand Down
13 changes: 4 additions & 9 deletions src/Widgets/WindowSwitcher/WindowSwitcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class Gala.WindowSwitcher : CanvasActor {
public const int ICON_SIZE = 64;
public const int WRAPPER_PADDING = 12;

private const string CAPTION_FONT_NAME = "Inter";
private const int MIN_OFFSET = 64;
private const int ANIMATION_DURATION = 200;
// https://github.com/elementary/gala/issues/1317#issuecomment-982484415
Expand All @@ -26,7 +25,7 @@ public class Gala.WindowSwitcher : CanvasActor {
private Gala.ModalProxy modal_proxy = null;
private Granite.Settings granite_settings;
private Clutter.Actor container;
private Clutter.Text caption;
private Gala.Text caption;

private Gtk.WidgetPath widget_path;
private Gtk.StyleContext style_context;
Expand Down Expand Up @@ -146,13 +145,9 @@ public class Gala.WindowSwitcher : CanvasActor {

container.button_release_event.connect (container_mouse_release);

var caption_color = "#2e2e31";

if (granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK) {
caption_color = "#fafafa";
}

caption = new Clutter.Text.full (CAPTION_FONT_NAME, "", Clutter.Color.from_string (caption_color));
caption = new Gala.Text () {
color = Clutter.Color.from_string (granite_settings.prefers_color_scheme == DARK ? "#fafafa" : "#2e2e31")
};
caption.set_pivot_point (0.5f, 0.5f);
caption.set_ellipsize (Pango.EllipsizeMode.END);
caption.set_line_alignment (Pango.Alignment.CENTER);
Expand Down