-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextScale.vala
More file actions
74 lines (61 loc) · 2.5 KB
/
TextScale.vala
File metadata and controls
74 lines (61 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/
public class QuickSettings.TextScale : Gtk.Box {
private Gtk.Button zoom_in_button;
private Gtk.Button zoom_out_button;
private Settings interface_settings;
class construct {
set_css_name ("scalebox");
}
construct {
zoom_out_button = new Gtk.Button.from_icon_name ("quick-settings-text-small-symbolic") {
tooltip_text = _("Decrease text size"),
valign = CENTER
};
zoom_out_button.add_css_class (Granite.CssClass.CIRCULAR);
var zoom_adjustment = new Gtk.Adjustment (-1, 0.75, 1.75, 0.05, 0, 0);
var zoom_scale = new Gtk.Scale (HORIZONTAL, zoom_adjustment) {
draw_value = false,
hexpand = true
};
zoom_scale.add_mark (1, BOTTOM, null);
zoom_scale.add_mark (1.5, BOTTOM, null);
zoom_in_button = new Gtk.Button.from_icon_name ("quick-settings-text-large-symbolic") {
tooltip_text = _("Increase text size"),
valign = CENTER
};
zoom_in_button.add_css_class (Granite.CssClass.CIRCULAR);
add_css_class ("font-size");
append (zoom_out_button);
append (zoom_scale);
append (zoom_in_button);
interface_settings = new Settings ("org.gnome.desktop.interface");
interface_settings.bind ("text-scaling-factor", zoom_adjustment, "value", GET);
interface_settings.changed["text-scaling-factor"].connect (update_zoom_buttons);
update_zoom_buttons ();
uint update_timeout_id = 0;
zoom_adjustment.value_changed.connect (() => {
if (update_timeout_id != 0) {
GLib.Source.remove (update_timeout_id);
}
update_timeout_id = Timeout.add (300, () => {
update_timeout_id = 0;
interface_settings.set_double ("text-scaling-factor", zoom_adjustment.value);
return GLib.Source.REMOVE;
});
});
zoom_in_button.clicked.connect (() => {
zoom_adjustment.value += 0.05;
});
zoom_out_button.clicked.connect (() => {
zoom_adjustment.value += -0.05;
});
}
private void update_zoom_buttons () {
var scaling_factor = interface_settings.get_double ("text-scaling-factor");
zoom_in_button.sensitive = scaling_factor < 1.75;
zoom_out_button.sensitive = scaling_factor > 0.75;
}
}