-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathAppearance.vala
More file actions
621 lines (505 loc) · 23.1 KB
/
Appearance.vala
File metadata and controls
621 lines (505 loc) · 23.1 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/*
* Copyright 2018–2021 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
*/
public class PantheonShell.Appearance : Switchboard.SettingsPage {
private const string INTERFACE_SCHEMA = "org.gnome.desktop.interface";
private const string STYLESHEET_KEY = "gtk-theme";
private const string STYLESHEET_PREFIX = "io.elementary.stylesheet.";
private enum AccentColor {
NO_PREFERENCE,
RED,
ORANGE,
YELLOW,
GREEN,
MINT,
BLUE,
PURPLE,
PINK,
BROWN,
GRAY;
public string to_string () {
switch (this) {
case RED:
return "strawberry";
case ORANGE:
return "orange";
case YELLOW:
return "banana";
case GREEN:
return "lime";
case MINT:
return "mint";
case BLUE:
return "blueberry";
case PURPLE:
return "grape";
case PINK:
return "bubblegum";
case BROWN:
return "cocoa";
case GRAY:
return "slate";
}
return "auto";
}
}
public Appearance () {
Object (
title: _("Appearance"),
description : _("Preferred accents and style for system components. Apps may also follow these preferences, but can always choose their own accents or style."),
icon: new ThemedIcon ("preferences-desktop-theme"),
show_end_title_buttons: true
);
}
construct {
var dark_label = new Granite.HeaderLabel (_("Style")) {
secondary_text = _("Preferred visual style for system components. Apps may also choose to follow this preference.")
};
var default_preview = new DesktopPreview ("default");
var prefer_default_radio = new Gtk.CheckButton ();
prefer_default_radio.add_css_class ("image-button");
var prefer_default_grid = new Gtk.Grid ();
prefer_default_grid.attach (default_preview, 0, 0);
prefer_default_grid.attach (new Gtk.Label (_("Default")), 0, 1);
prefer_default_grid.set_parent (prefer_default_radio);
var default_photo_button = new Gtk.Button.from_icon_name ("insert-image-symbolic") {
tooltip_text = _("Select Photo")
};
var wallpaper_color_button = new Gtk.ColorDialogButton (null) {
tooltip_text = _("Solid color")
};
var default_wallpaper_options_box = new Gtk.Box (HORIZONTAL, 3) {
halign = CENTER
};
default_wallpaper_options_box.append (default_photo_button);
default_wallpaper_options_box.append (wallpaper_color_button);
var dark_preview = new DesktopPreview ("dark");
var prefer_dark_radio = new Gtk.CheckButton () {
group = prefer_default_radio
};
prefer_dark_radio.add_css_class ("image-button");
var prefer_dark_grid = new Gtk.Grid ();
prefer_dark_grid.attach (dark_preview, 0, 0);
prefer_dark_grid.attach (new Gtk.Label (_("Dark")), 0, 1);
prefer_dark_grid.set_parent (prefer_dark_radio);
var photo_button = new Gtk.Button.from_icon_name ("insert-image-symbolic") {
tooltip_text = _("Select Photo")
};
var pair_button = new Gtk.Button.from_icon_name ("edit-clear-all-symbolic") {
tooltip_text = _("Same as default style")
};
var dim_toggle = new Gtk.ToggleButton () {
icon_name = "display-brightness-symbolic",
tooltip_text = _("Dim Wallpaper")
};
var dark_wallpaper_options_box = new Gtk.Box (HORIZONTAL, 3) {
halign = CENTER
};
dark_wallpaper_options_box.append (photo_button);
dark_wallpaper_options_box.append (pair_button);
dark_wallpaper_options_box.append (dim_toggle);
var prefer_style_grid = new Gtk.Grid () {
row_spacing = 6,
column_spacing = 12
};
prefer_style_grid.attach (prefer_default_radio, 0, 0);
prefer_style_grid.attach (default_wallpaper_options_box, 0, 1);
prefer_style_grid.attach (prefer_dark_radio, 1, 0);
prefer_style_grid.attach (dark_wallpaper_options_box, 1, 1);
var schedule_label = new Granite.HeaderLabel (_("Schedule"));
var schedule_disabled_radio = new Gtk.CheckButton.with_label (_("Disabled")) {
margin_bottom = 3
};
var schedule_sunset_radio = new Gtk.CheckButton.with_label (
_("Sunset to Sunrise")
) {
group = schedule_disabled_radio
};
var from_label = new Gtk.Label (_("From:"));
var from_time = new Granite.TimePicker () {
hexpand = true,
margin_end = 6
};
var to_label = new Gtk.Label (_("To:"));
var to_time = new Granite.TimePicker () {
hexpand = true
};
var schedule_manual_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
schedule_manual_box.append (from_label);
schedule_manual_box.append (from_time);
schedule_manual_box.append (to_label);
schedule_manual_box.append (to_time);
var schedule_manual_radio = new Gtk.CheckButton () {
group = schedule_disabled_radio
};
Pantheon.AccountsService? pantheon_act = null;
string? user_path = null;
try {
FDO.Accounts? accounts_service = GLib.Bus.get_proxy_sync (
GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts"
);
user_path = accounts_service.find_user_by_name (GLib.Environment.get_user_name ());
} catch (Error e) {
critical (e.message);
}
if (user_path != null) {
try {
pantheon_act = GLib.Bus.get_proxy_sync (
GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
user_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES
);
} catch (Error e) {
warning ("Unable to get AccountsService proxy, color scheme preference may be incorrect");
}
}
var grid = new Gtk.Grid () {
row_spacing = 6
};
if (((GLib.DBusProxy) pantheon_act).get_cached_property ("PrefersColorScheme") != null) {
grid.attach (dark_label, 0, 0, 2);
grid.attach (prefer_style_grid, 0, 2, 2);
grid.attach (schedule_label, 0, 4, 2);
grid.attach (schedule_disabled_radio, 0, 5, 2);
grid.attach (schedule_sunset_radio, 0, 6, 2);
grid.attach (schedule_manual_radio, 0, 7);
grid.attach (schedule_manual_box, 1, 7);
switch (pantheon_act.prefers_color_scheme) {
case Granite.Settings.ColorScheme.DARK:
prefer_dark_radio.active = true;
break;
default:
prefer_default_radio.active = true;
break;
}
var settings = new GLib.Settings ("io.elementary.settings-daemon.prefers-color-scheme");
settings.bind_with_mapping (
"prefer-dark-schedule", schedule_disabled_radio, "active", GLib.SettingsBindFlags.DEFAULT,
(value, variant, user_data) => {
value.set_boolean (variant.get_string () == "disabled");
return true;
},
(value, expected_type, user_data) => {
if (value.get_boolean ()) {
return new Variant ("s", "disabled");
}
return null;
},
null, null
);
settings.bind_with_mapping (
"prefer-dark-schedule", schedule_manual_radio, "active", GLib.SettingsBindFlags.DEFAULT,
(value, variant, user_data) => {
value.set_boolean (variant.get_string () == "manual");
return true;
},
(value, expected_type, user_data) => {
if (value.get_boolean ()) {
return new Variant ("s", "manual");
}
return null;
},
null, null
);
settings.bind_with_mapping (
"prefer-dark-schedule", schedule_sunset_radio, "active", GLib.SettingsBindFlags.DEFAULT,
(value, variant, user_data) => {
value.set_boolean (variant.get_string () == "sunset-to-sunrise");
return true;
},
(value, expected_type, user_data) => {
if (value.get_boolean ()) {
return new Variant ("s", "sunset-to-sunrise");
}
return null;
},
null, null
);
prefer_default_radio.toggled.connect (() => {
pantheon_act.prefers_color_scheme = Granite.Settings.ColorScheme.NO_PREFERENCE;
});
prefer_dark_radio.toggled.connect (() => {
pantheon_act.prefers_color_scheme = Granite.Settings.ColorScheme.DARK;
});
/* Connect to focus_in_event so that this is only triggered
* through user interaction, not if scheduling changes the selection
*/
var prefer_default_radio_controller = new Gtk.EventControllerFocus ();
prefer_default_radio.add_controller (prefer_default_radio_controller);
prefer_default_radio_controller.enter.connect (() => {
// Check if selection changed
if (pantheon_act.prefers_color_scheme != Granite.Settings.ColorScheme.NO_PREFERENCE) {
schedule_disabled_radio.active = true;
}
});
var prefer_dark_radio_controller = new Gtk.EventControllerFocus ();
prefer_dark_radio.add_controller (prefer_dark_radio_controller);
prefer_dark_radio_controller.enter.connect (() => {
// Check if selection changed
if (pantheon_act.prefers_color_scheme != Granite.Settings.ColorScheme.DARK) {
schedule_disabled_radio.active = true;
}
});
((GLib.DBusProxy) pantheon_act).g_properties_changed.connect ((changed, invalid) => {
var color_scheme = changed.lookup_value ("PrefersColorScheme", new VariantType ("i"));
if (color_scheme != null) {
switch ((Granite.Settings.ColorScheme) color_scheme.get_int32 ()) {
case Granite.Settings.ColorScheme.DARK:
prefer_dark_radio.active = true;
break;
default:
prefer_default_radio.active = true;
break;
}
}
});
from_time.time = double_date_time (settings.get_double ("prefer-dark-schedule-from"));
from_time.time_changed.connect (() => {
settings.set_double ("prefer-dark-schedule-from", date_time_double (from_time.time));
});
to_time.time = double_date_time (settings.get_double ("prefer-dark-schedule-to"));
to_time.time_changed.connect (() => {
settings.set_double ("prefer-dark-schedule-to", date_time_double (to_time.time));
});
schedule_manual_radio.bind_property ("active", schedule_manual_box, "sensitive", BindingFlags.SYNC_CREATE);
}
var interface_settings = new GLib.Settings (INTERFACE_SCHEMA);
var current_stylesheet = interface_settings.get_string (STYLESHEET_KEY);
debug ("Current stylesheet: %s", current_stylesheet);
if (current_stylesheet.has_prefix (STYLESHEET_PREFIX)) {
var accent_label = new Granite.HeaderLabel (_("Accent Color")) {
margin_top = 18,
secondary_text = _("Used across the system by default. Apps can always use their own accent color.")
};
var blueberry_button = new PrefersAccentColorButton (pantheon_act, AccentColor.BLUE);
blueberry_button.tooltip_text = _("Blueberry");
var mint_button = new PrefersAccentColorButton (pantheon_act, AccentColor.MINT, blueberry_button);
mint_button.tooltip_text = _("Mint");
var lime_button = new PrefersAccentColorButton (pantheon_act, AccentColor.GREEN, blueberry_button);
lime_button.tooltip_text = _("Lime");
var banana_button = new PrefersAccentColorButton (pantheon_act, AccentColor.YELLOW, blueberry_button);
banana_button.tooltip_text = _("Banana");
var orange_button = new PrefersAccentColorButton (pantheon_act, AccentColor.ORANGE, blueberry_button);
orange_button.tooltip_text = _("Orange");
var strawberry_button = new PrefersAccentColorButton (pantheon_act, AccentColor.RED, blueberry_button);
strawberry_button.tooltip_text = _("Strawberry");
var bubblegum_button = new PrefersAccentColorButton (pantheon_act, AccentColor.PINK, blueberry_button);
bubblegum_button.tooltip_text = _("Bubblegum");
var grape_button = new PrefersAccentColorButton (pantheon_act, AccentColor.PURPLE, blueberry_button);
grape_button.tooltip_text = _("Grape");
var cocoa_button = new PrefersAccentColorButton (pantheon_act, AccentColor.BROWN, blueberry_button);
cocoa_button.tooltip_text = _("Cocoa");
var slate_button = new PrefersAccentColorButton (pantheon_act, AccentColor.GRAY, blueberry_button);
slate_button.tooltip_text = _("Slate");
var auto_button = new PrefersAccentColorButton (pantheon_act, AccentColor.NO_PREFERENCE, blueberry_button);
auto_button.tooltip_text = _("Automatic based on wallpaper");
var accent_box = new Gtk.Box (HORIZONTAL, 6);
accent_box.append (blueberry_button);
accent_box.append (mint_button);
accent_box.append (lime_button);
accent_box.append (banana_button);
accent_box.append (orange_button);
accent_box.append (strawberry_button);
accent_box.append (bubblegum_button);
accent_box.append (grape_button);
accent_box.append (cocoa_button);
accent_box.append (slate_button);
accent_box.append (auto_button);
grid.attach (accent_label, 0, 8, 2);
grid.attach (accent_box, 0, 9, 2);
}
var animations_switch = new Gtk.Switch () {
halign = Gtk.Align.END,
hexpand = true,
valign = Gtk.Align.CENTER
};
var animations_label = new Granite.HeaderLabel (_("Reduce Motion")) {
mnemonic_widget = animations_switch,
secondary_text = _("Disable animations in the window manager and some other interface elements.")
};
var animations_box = new Gtk.Box (HORIZONTAL, 12) {
margin_top = 18
};
animations_box.append (animations_label);
animations_box.append (animations_switch);
var scrollbar_switch = new Gtk.Switch () {
valign = CENTER
};
var scrollbar_label = new Granite.HeaderLabel (_("Always Show Scrollbars")) {
hexpand = true,
mnemonic_widget = scrollbar_switch,
secondary_text = _("Scrollbars will take up space, even when not in use.")
};
var scrollbar_box = new Gtk.Box (HORIZONTAL, 12) {
margin_top = 18
};
scrollbar_box.append (scrollbar_label);
scrollbar_box.append (scrollbar_switch);
grid.attach (animations_box, 0, 10, 2);
grid.attach (scrollbar_box, 0, 11, 2);
child = grid;
add_css_class ("appearance-view");
var animations_settings = new Settings ("org.pantheon.desktop.gala.animations");
animations_settings.bind ("enable-animations", animations_switch, "active", SettingsBindFlags.INVERT_BOOLEAN);
interface_settings.bind ("overlay-scrolling", scrollbar_switch, "active", INVERT_BOOLEAN);
var background_settings = new GLib.Settings ("io.elementary.desktop.background");
background_settings.bind ("dim-wallpaper-in-dark-style", dim_toggle, "active", DEFAULT);
var gnome_background_settings = new Settings ("org.gnome.desktop.background");
pair_button.clicked.connect (() => {
gnome_background_settings.set_string ("picture-uri-dark", "");
});
}
private class PrefersAccentColorButton : Gtk.CheckButton {
public AccentColor color { get; construct; }
public Pantheon.AccountsService? pantheon_act { get; construct; default = null; }
private static GLib.Settings interface_settings;
public PrefersAccentColorButton (Pantheon.AccountsService? pantheon_act, AccentColor color, Gtk.CheckButton? group_member = null) {
Object (
pantheon_act: pantheon_act,
color: color,
group: group_member
);
}
static construct {
interface_settings = new GLib.Settings (INTERFACE_SCHEMA);
var current_stylesheet = interface_settings.get_string (STYLESHEET_KEY);
}
construct {
add_css_class (Granite.STYLE_CLASS_COLOR_BUTTON);
add_css_class (color.to_string ());
realize.connect (() => {
active = color == pantheon_act.prefers_accent_color;
toggled.connect (() => {
if (color != AccentColor.NO_PREFERENCE) {
interface_settings.set_string (
STYLESHEET_KEY,
STYLESHEET_PREFIX + color.to_string ()
);
}
if (((GLib.DBusProxy) pantheon_act).get_cached_property ("PrefersAccentColor") != null) {
pantheon_act.prefers_accent_color = color;
}
});
});
}
}
private static DateTime double_date_time (double dbl) {
var hours = (int) dbl;
var minutes = (int) Math.round ((dbl - hours) * 60);
var date_time = new DateTime.local (1, 1, 1, hours, minutes, 0.0);
return date_time;
}
private static double date_time_double (DateTime date_time) {
double time_double = 0;
time_double += date_time.get_hour ();
time_double += (double) date_time.get_minute () / 60;
return time_double;
}
private class DesktopPreview : Gtk.Widget {
private static Settings pantheon_settings;
private static Settings gnome_settings;
private Gtk.Picture picture;
class construct {
set_css_name ("desktop-preview");
}
static construct {
set_layout_manager_type (typeof (Gtk.BinLayout));
pantheon_settings = new Settings ("io.elementary.desktop.background");
gnome_settings = new Settings ("org.gnome.desktop.background");
}
public DesktopPreview (string style_class) {
picture = new Gtk.Picture () {
content_fit = COVER
};
var window_back = new Gtk.Box (HORIZONTAL, 0) {
halign = CENTER,
valign = CENTER
};
window_back.add_css_class ("window");
window_back.add_css_class ("back");
var window_front = new Gtk.Box (HORIZONTAL, 0) {
halign = CENTER,
valign = CENTER
};
window_front.add_css_class ("window");
window_front.add_css_class ("front");
var shell = new Gtk.Box (HORIZONTAL, 0);
shell.add_css_class ("shell");
var overlay = new Gtk.Overlay () {
child = picture,
overflow = HIDDEN
};
overlay.add_overlay (shell);
overlay.add_overlay (window_back);
overlay.add_overlay (window_front);
overlay.add_css_class (Granite.STYLE_CLASS_CARD);
overlay.add_css_class (Granite.STYLE_CLASS_ROUNDED);
var monitor = Gdk.Display.get_default ().get_monitor_at_surface (
(((Gtk.Application) Application.get_default ()).active_window).get_surface ()
);
var monitor_ratio = (float) monitor.geometry.width / monitor.geometry.height;
var frame = new Gtk.AspectFrame (0.5f, 0.5f, monitor_ratio, false) {
child = overlay
};
frame.set_parent (this);
add_css_class (style_class);
update_picture ();
gnome_settings.changed.connect (update_picture);
if (has_css_class ("dark")) {
update_dim ();
pantheon_settings.changed.connect (update_dim);
}
}
private void update_dim () {
if (pantheon_settings.get_boolean ("dim-wallpaper-in-dark-style")) {
add_css_class ("dim");
} else {
remove_css_class ("dim");
}
}
private void update_picture () {
if (gnome_settings.get_string ("picture-options") == "none") {
Gdk.RGBA rgba = {};
rgba.parse (gnome_settings.get_string ("primary-color"));
var pixbuf = new Gdk.Pixbuf (RGB, false, 8, 500, 500);
pixbuf.fill (PantheonShell.SolidColorContainer.rgba_to_pixel (rgba));
picture.paintable = Gdk.Texture.for_pixbuf (pixbuf);
return;
}
if (has_css_class ("dark")) {
var dark_file = File.new_for_uri (
gnome_settings.get_string ("picture-uri-dark")
);
if (dark_file.query_exists ()) {
picture.file = dark_file;
return;
}
}
picture.file = File.new_for_uri (
gnome_settings.get_string ("picture-uri")
);
}
~DesktopPreview () {
get_first_child ().unparent ();
}
}
}