Skip to content

Commit 66081b8

Browse files
committed
Introduce Gala.Text
1 parent 5b3b60f commit 66081b8

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

lib/Text.vala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
4+
*/
5+
6+
/*
7+
* Clutter.Text that automatically changes font-name to the system one
8+
*/
9+
public class Gala.Text : Clutter.Text {
10+
private static GLib.Settings gnome_interface_settings;
11+
12+
static construct {
13+
gnome_interface_settings = new GLib.Settings ("org.gnome.desktop.interface");
14+
}
15+
16+
construct {
17+
set_system_font_name ();
18+
gnome_interface_settings.changed["font-name"].connect (set_system_font_name);
19+
}
20+
21+
private void set_system_font_name () {
22+
var name = gnome_interface_settings.get_string ("font-name").split (" ");
23+
var last_element_index = name.length - 1;
24+
25+
if (int.try_parse (name[last_element_index])) { // if last element is a font-size
26+
name[last_element_index] = "12"; // hardcode size (can be changed later if needed)
27+
} else {
28+
name += "12";
29+
}
30+
31+
font_name = string.joinv (" ", name);
32+
}
33+
}

lib/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ gala_lib_sources = files(
1515
'Drawing/Utilities.vala',
1616
'Plugin.vala',
1717
'ShadowEffect.vala',
18+
'Text.vala',
1819
'Utils.vala',
1920
'WindowIcon.vala',
2021
'WindowManager.vala',

src/Widgets/MultitaskingView/Tooltip.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Gala.Tooltip : CanvasActor {
2525
(uint8) Drawing.Color.TOOLTIP_TEXT_COLOR.alpha * uint8.MAX,
2626
};
2727

28-
text_actor = new Clutter.Text () {
28+
text_actor = new Gala.Text () {
2929
margin_left = 6,
3030
margin_top = 6,
3131
margin_bottom = 6,

src/Widgets/WindowSwitcher/WindowSwitcher.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class Gala.WindowSwitcher : CanvasActor, GestureTarget {
8383
get_accessible ().accessible_name = _("Window switcher");
8484
container.get_accessible ().accessible_role = LIST;
8585

86-
caption = new Clutter.Text () {
86+
caption = new Gala.Text () {
8787
font_name = CAPTION_FONT_NAME,
8888
ellipsize = END,
8989
line_alignment = CENTER

0 commit comments

Comments
 (0)