This repository has been archived by the owner on Jul 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
elegance-colors-prefs.vala
2274 lines (1962 loc) · 108 KB
/
elegance-colors-prefs.vala
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
public class EleganceColorsWindow : Gtk.ApplicationWindow {
// General
Gtk.ComboBox combobox;
Gtk.RadioButton match_wallpaper;
Gtk.RadioButton match_theme;
Gtk.RadioButton custom_color;
Gtk.RadioButton text_auto;
Gtk.RadioButton text_color;
Gtk.ColorButton color_button;
Gtk.ColorButton text_button;
Gtk.FontButton font_button;
Gtk.Switch dropshadow_switch;
Gtk.SpinButton selgradient_size;
Gtk.SpinButton corner_roundness;
Gtk.SpinButton transition_duration;
string color_value;
string text_value;
string[] presets = { "" };
string[] titles = { "…" };
// Panel
Gtk.ColorButton panel_bg1_color;
Gtk.ColorButton panel_bg2_color;
Gtk.ColorButton panel_fg_color;
Gtk.ColorButton panel_border_color;
Gtk.Switch panel_icon_switch;
Gtk.SpinButton panel_tint_value;
Gtk.SpinButton panel_bwidth_value;
string panel_bg1_value;
string panel_bg2_value;
string panel_fg_value;
string panel_border_value;
// Overview
Gtk.ColorButton overview_searchbg1_color;
Gtk.ColorButton overview_searchbg2_color;
Gtk.ColorButton overview_searchfocusbg1_color;
Gtk.ColorButton overview_searchfocusbg2_color;
Gtk.ColorButton overview_searchfg_color;
Gtk.ColorButton overview_searchfocusfg_color;
Gtk.ColorButton overview_searchborder_color;
Gtk.ColorButton overview_searchfocusborder_color;
string overview_searchbg1_value;
string overview_searchbg2_value;
string overview_searchfocusbg1_value;
string overview_searchfocusbg2_value;
string overview_searchfg_value;
string overview_searchfocusfg_value;
string overview_searchborder_value;
string overview_searchfocusborder_value;
// Dash
Gtk.ColorButton dash_bg1_color;
Gtk.ColorButton dash_bg2_color;
Gtk.ColorButton dash_fg_color;
Gtk.ColorButton dash_border_color;
Gtk.SpinButton dash_tint_value;
Gtk.SpinButton dash_bwidth_value;
string dash_bg1_value;
string dash_bg2_value;
string dash_fg_value;
string dash_border_value;
// Menu
Gtk.ColorButton menu_bg1_color;
Gtk.ColorButton menu_bg2_color;
Gtk.ColorButton menu_fg_color;
Gtk.ColorButton menu_border_color;
Gtk.Switch menu_arrow_switch;
Gtk.SpinButton menu_tint_value;
Gtk.SpinButton menu_bwidth_value;
string menu_bg1_value;
string menu_bg2_value;
string menu_fg_value;
string menu_border_value;
// Dialogs
Gtk.ColorButton dialog_bg1_color;
Gtk.ColorButton dialog_bg2_color;
Gtk.ColorButton dialog_fg_color;
Gtk.ColorButton dialog_heading_color;
Gtk.ColorButton dialog_border_color;
Gtk.SpinButton dialog_tint_value;
Gtk.SpinButton dialog_bwidth_value;
string dialog_bg1_value;
string dialog_bg2_value;
string dialog_fg_value;
string dialog_heading_value;
string dialog_border_value;
// Gtk.Buttons
Gtk.ColorButton button_bg1_color;
Gtk.ColorButton button_bg2_color;
Gtk.ColorButton button_hoverbg1_color;
Gtk.ColorButton button_hoverbg2_color;
Gtk.ColorButton button_activebg1_color;
Gtk.ColorButton button_activebg2_color;
Gtk.ColorButton button_fg_color;
Gtk.ColorButton button_hoverfg_color;
Gtk.ColorButton button_activefg_color;
Gtk.ColorButton button_border_color;
Gtk.ColorButton button_hoverborder_color;
Gtk.ColorButton button_activeborder_color;
Gtk.Switch button_bold_switch;
string button_bg1_value;
string button_bg2_value;
string button_hoverbg1_value;
string button_hoverbg2_value;
string button_activebg1_value;
string button_activebg2_value;
string button_fg_value;
string button_hoverfg_value;
string button_activefg_value;
string button_border_value;
string button_hoverborder_value;
string button_activeborder_value;
// Focused buttons
Gtk.ColorButton buttonfocus_bg1_color;
Gtk.ColorButton buttonfocus_bg2_color;
Gtk.ColorButton buttonfocus_hoverbg1_color;
Gtk.ColorButton buttonfocus_hoverbg2_color;
Gtk.ColorButton buttonfocus_activebg1_color;
Gtk.ColorButton buttonfocus_activebg2_color;
Gtk.ColorButton buttonfocus_fg_color;
Gtk.ColorButton buttonfocus_hoverfg_color;
Gtk.ColorButton buttonfocus_activefg_color;
Gtk.ColorButton buttonfocus_border_color;
Gtk.ColorButton buttonfocus_hoverborder_color;
Gtk.ColorButton buttonfocus_activeborder_color;
string buttonfocus_bg1_value;
string buttonfocus_bg2_value;
string buttonfocus_hoverbg1_value;
string buttonfocus_hoverbg2_value;
string buttonfocus_activebg1_value;
string buttonfocus_activebg2_value;
string buttonfocus_fg_value;
string buttonfocus_hoverfg_value;
string buttonfocus_activefg_value;
string buttonfocus_border_value;
string buttonfocus_hoverborder_value;
string buttonfocus_activeborder_value;
// Entry
Gtk.ColorButton entry_bg1_color;
Gtk.ColorButton entry_bg2_color;
Gtk.ColorButton entry_fg_color;
Gtk.ColorButton entry_border_color;
Gtk.Switch entry_shadow_switch;
string entry_bg1_value;
string entry_bg2_value;
string entry_fg_value;
string entry_border_value;
// Misc
Gtk.ColorButton misc_runningbg1_color;
Gtk.ColorButton misc_runningbg2_color;
Gtk.ColorButton misc_separator1_color;
Gtk.ColorButton misc_separator2_color;
Gtk.ColorButton misc_tooltipbg1_color;
Gtk.ColorButton misc_tooltipbg2_color;
Gtk.ColorButton misc_tooltipfg_color;
Gtk.ColorButton misc_tooltipborder_color;
Gtk.ColorButton misc_insensitive_color;
string misc_runningbg1_value;
string misc_runningbg2_value;
string misc_separator1_value;
string misc_separator2_value;
string misc_tooltipbg1_value;
string misc_tooltipbg2_value;
string misc_tooltipfg_value;
string misc_tooltipborder_value;
string misc_insensitive_value;
// HeaderBar
Gtk.Button undo_button;
Gtk.Button redo_button;
Gtk.Button clear_button;
List<string> list_undo = new List<string> ();
List<string> list_redo = new List<string> ();
bool new_button_clicked = false;
// Others
Gtk.Notebook notebook;
Gtk.Button apply_button;
File config_file;
File presets_dir_usr;
File presets_dir_sys;
string elegance_colors;
KeyFile key_file;
internal EleganceColorsWindow (EleganceColorsPref app) {
Object (application: app, title: "Elegance Colors Preferences");
// Set window properties
this.window_position = Gtk.WindowPosition.CENTER;
this.resizable = false;
this.border_width = 0;
// Set window icon
try {
this.icon = Gtk.IconTheme.get_default ().load_icon ("elegance-colors", 48, 0);
} catch (Error e) {
stderr.printf ("Failed to load application icon: %s\n", e.message);
}
// Prefer dark theme
// Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
// GMenu
var export_action = new SimpleAction ("export", null);
export_action.activate.connect (this.export_theme);
this.add_action (export_action);
var exsettings_action = new SimpleAction ("exsettings", null);
exsettings_action.activate.connect (this.export_settings);
this.add_action (exsettings_action);
var impsettings_action = new SimpleAction ("impsettings", null);
impsettings_action.activate.connect (this.import_settings);
this.add_action (impsettings_action);
var about_action = new SimpleAction ("about", null);
about_action.activate.connect (this.show_about);
this.add_action (about_action);
// Set variables
var script = File.new_for_path ("elegance-colors");
var presets = File.new_for_path ("presets");
if (script.query_exists () && script.query_file_type (0) == FileType.REGULAR && presets.query_exists () && presets.query_file_type (0) == FileType.DIRECTORY) {
presets_dir_sys = presets;
elegance_colors = "./elegance-colors";
} else {
presets_dir_sys = File.parse_name ("/usr/share/elegance-colors/presets");
elegance_colors = "elegance-colors";
}
var config_dir = File.new_for_path (Environment.get_user_config_dir ()).get_child ("elegance-colors");
config_file = config_dir.get_child ("elegance-colors.ini");
presets_dir_usr = config_dir.get_child ("presets");
key_file = new KeyFile ();
// Methods
init_process ();
load_config ();
create_widgets ();
}
private void init_process () {
var theme_file = File.new_for_path (Environment.get_home_dir ()).get_child (".themes/elegance-colors/gnome-shell/gnome-shell.css");
if (!theme_file.query_exists () || !config_file.query_exists ()) {
try {
Process.spawn_command_line_async ("%s".printf (elegance_colors));
} catch (Error e) {
stderr.printf ("Failed to run process: %s\n", e.message);
}
try {
key_file.load_from_file (presets_dir_sys.get_child ("default.ini").get_path (), KeyFileFlags.NONE);
} catch (Error e) {
stderr.printf ("Failed to load default preset: %s\n", e.message);
}
}
}
public string show_filedialog (Gtk.FileChooserAction action,
string title, string canceltext, string accepttext,
string filterpattern, string filename) {
var filechooser = new Gtk.FileChooserDialog (
title, this, action,
canceltext, Gtk.ResponseType.CANCEL,
accepttext, Gtk.ResponseType.ACCEPT, null);
var filter = new Gtk.FileFilter ();
filter.add_pattern (filterpattern);
filechooser.set_filter (filter);
filechooser.set_do_overwrite_confirmation (true);
if (action == Gtk.FileChooserAction.SAVE) {
filechooser.set_current_name (filename);
}
string current_path = null;
if (filechooser.run () == Gtk.ResponseType.ACCEPT) {
current_path = filechooser.get_file ().get_path ();
}
filechooser.close ();
return current_path;
}
private void export_theme () {
string file_path = show_filedialog (Gtk.FileChooserAction.SAVE,
"Export theme", "Cancel", "Export",
"*.zip", "Elegance Colors Custom.zip");
if (file_path != null) {
try {
Process.spawn_command_line_sync ("%s export \"%s\"".printf (elegance_colors, file_path));
} catch (Error e) {
stderr.printf ("Failed to export theme: %s\n", e.message);
}
}
}
private void export_settings () {
string file_path = show_filedialog (Gtk.FileChooserAction.SAVE,
"Export settings", "Cancel", "Export",
"*.ini", "elegance-colors-exported.ini");
if (file_path != null) {
try {
var exportpath = File.new_for_path (file_path);
var dos = new DataOutputStream (exportpath.replace (null, false, FileCreateFlags.REPLACE_DESTINATION));
dos.put_string (key_file.to_data ());
} catch (Error e) {
stderr.printf ("Failed to export settings: %s\n", e.message);
}
}
}
private void import_settings () {
string file_path = show_filedialog (Gtk.FileChooserAction.OPEN,
"Import settings", "Cancel", "Import",
"*.ini", "elegance-colors.ini");
if (file_path != null) {
try {
var importpath = File.new_for_path (file_path);
key_file.load_from_file (importpath.get_path (), KeyFileFlags.NONE);
} catch (Error e) {
stderr.printf ("Failed to import settings: %s\n", e.message);
}
on_load_keyfile ();
}
}
private void show_about (SimpleAction simple, Variant? parameter) {
string license = "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.\n\nThis 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.\n\nYou 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 St, Fifth Floor, Boston, MA 02110-1301 USA";
Gtk.show_about_dialog (this,
"program-name", "Elegance Colors",
"logo_icon_name", "elegance-colors",
"copyright", "Copyright \xc2\xa9 Satyajit Sahoo",
"comments", "Highly customizable chameleon theme for Gnome Shell",
"license", license,
"wrap-license", true,
"website", "https://github.com/satya164/elegance-colors",
"website-label", "Elegance Colors on GitHub",
null);
}
private void load_config () {
// Read the config file
try {
key_file.load_from_file (config_file.get_path (), KeyFileFlags.NONE);
} catch (Error e) {
stderr.printf ("Failed to read configuration: %s\n", e.message);
}
}
private void set_states () {
try {
var mode = key_file.get_string ("Settings", "mode");
if (mode == "wallpaper") {
match_wallpaper.set_active (true);
color_button.set_sensitive (false);
} else if (mode == "gtk") {
match_theme.set_active (true);
color_button.set_sensitive (false);
} else {
custom_color.set_active (true);
color_button.set_sensitive (true);
}
color_value = key_file.get_string ("Settings", "highlight");
var text = key_file.get_string ("Settings", "text");
if (text == "auto") {
text_auto.set_active (true);
text_button.set_sensitive (false);
} else {
text_color.set_active (true);
text_button.set_sensitive (true);
}
text_value = key_file.get_string ("Settings", "textcolor");
font_button.set_font_name (key_file.get_string ("Settings", "fontname"));
dropshadow_switch.set_active (key_file.get_boolean ("Settings", "dropshadow"));
selgradient_size.adjustment.value = key_file.get_double ("Settings", "selgradient");
corner_roundness.adjustment.value = key_file.get_double ("Settings", "roundness");
transition_duration.adjustment.value = key_file.get_double ("Settings", "transition");
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
panel_bg1_value = key_file.get_string ("Panel", "panel_bg1");
panel_bg2_value = key_file.get_string ("Panel", "panel_bg2");
panel_fg_value = key_file.get_string ("Panel", "panel_fg");
panel_border_value = key_file.get_string ("Panel", "panel_border");
panel_icon_switch.set_active (key_file.get_boolean ("Panel", "panel_icon"));
panel_tint_value.adjustment.value = key_file.get_double ("Panel", "panel_tint");
panel_bwidth_value.adjustment.value = key_file.get_double ("Panel", "panel_bwidth");
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
overview_searchbg1_value = key_file.get_string ("Overview", "overview_searchbg1");
overview_searchbg2_value = key_file.get_string ("Overview", "overview_searchbg2");
overview_searchfocusbg1_value = key_file.get_string ("Overview", "overview_searchfocusbg1");
overview_searchfocusbg2_value = key_file.get_string ("Overview", "overview_searchfocusbg2");
overview_searchfg_value = key_file.get_string ("Overview", "overview_searchfg");
overview_searchfocusfg_value = key_file.get_string ("Overview", "overview_searchfocusfg");
overview_searchborder_value = key_file.get_string ("Overview", "overview_searchborder");
overview_searchfocusborder_value = key_file.get_string ("Overview", "overview_searchfocusborder");
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
dash_bg1_value = key_file.get_string ("Dash", "dash_bg1");
dash_bg2_value = key_file.get_string ("Dash", "dash_bg2");
dash_fg_value = key_file.get_string ("Dash", "dash_fg");
dash_border_value = key_file.get_string ("Dash", "dash_border");
dash_tint_value.adjustment.value = key_file.get_double ("Dash", "dash_tint");
dash_bwidth_value.adjustment.value = key_file.get_double ("Dash", "dash_bwidth");
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
menu_bg1_value = key_file.get_string ("Menu", "menu_bg1");
menu_bg2_value = key_file.get_string ("Menu", "menu_bg2");
menu_fg_value = key_file.get_string ("Menu", "menu_fg");
menu_border_value = key_file.get_string ("Menu", "menu_border");
menu_arrow_switch.set_active (key_file.get_boolean ("Menu", "menu_arrow"));
menu_tint_value.adjustment.value = key_file.get_double ("Menu", "menu_tint");
menu_bwidth_value.adjustment.value = key_file.get_double ("Menu", "menu_bwidth");
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
dialog_bg1_value = key_file.get_string ("Dialogs", "dialog_bg1");
dialog_bg2_value = key_file.get_string ("Dialogs", "dialog_bg2");
dialog_fg_value = key_file.get_string ("Dialogs", "dialog_fg");
dialog_border_value = key_file.get_string ("Dialogs", "dialog_border");
dialog_heading_value = key_file.get_string ("Dialogs", "dialog_heading");
dialog_tint_value.adjustment.value = key_file.get_double ("Dialogs", "dialog_tint");
dialog_bwidth_value.adjustment.value = key_file.get_double ("Dialogs", "dialog_bwidth");
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
button_bg1_value = key_file.get_string ("Buttons", "button_bg1");
button_bg2_value = key_file.get_string ("Buttons", "button_bg2");
button_hoverbg1_value = key_file.get_string ("Buttons", "button_hoverbg1");
button_hoverbg2_value = key_file.get_string ("Buttons", "button_hoverbg2");
button_activebg1_value = key_file.get_string ("Buttons", "button_activebg1");
button_activebg2_value = key_file.get_string ("Buttons", "button_activebg2");
button_fg_value = key_file.get_string ("Buttons", "button_fg");
button_hoverfg_value = key_file.get_string ("Buttons", "button_hoverfg");
button_activefg_value = key_file.get_string ("Buttons", "button_activefg");
button_border_value = key_file.get_string ("Buttons", "button_border");
button_hoverborder_value = key_file.get_string ("Buttons", "button_hoverborder");
button_activeborder_value = key_file.get_string ("Buttons", "button_activeborder");
button_bold_switch.set_active (key_file.get_boolean ("Buttons", "button_bold"));
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
buttonfocus_bg1_value = key_file.get_string ("ButtonsFocus", "buttonfocus_bg1");
buttonfocus_bg2_value = key_file.get_string ("ButtonsFocus", "buttonfocus_bg2");
buttonfocus_hoverbg1_value = key_file.get_string ("ButtonsFocus", "buttonfocus_hoverbg1");
buttonfocus_hoverbg2_value = key_file.get_string ("ButtonsFocus", "buttonfocus_hoverbg2");
buttonfocus_activebg1_value = key_file.get_string ("ButtonsFocus", "buttonfocus_activebg1");
buttonfocus_activebg2_value = key_file.get_string ("ButtonsFocus", "buttonfocus_activebg2");
buttonfocus_fg_value = key_file.get_string ("ButtonsFocus", "buttonfocus_fg");
buttonfocus_hoverfg_value = key_file.get_string ("ButtonsFocus", "buttonfocus_hoverfg");
buttonfocus_activefg_value = key_file.get_string ("ButtonsFocus", "buttonfocus_activefg");
buttonfocus_border_value = key_file.get_string ("ButtonsFocus", "buttonfocus_border");
buttonfocus_hoverborder_value = key_file.get_string ("ButtonsFocus", "buttonfocus_hoverborder");
buttonfocus_activeborder_value = key_file.get_string ("ButtonsFocus", "buttonfocus_activeborder");
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
entry_bg1_value = key_file.get_string ("Entry", "entry_bg1");
entry_bg2_value = key_file.get_string ("Entry", "entry_bg2");
entry_fg_value = key_file.get_string ("Entry", "entry_fg");
entry_border_value = key_file.get_string ("Entry", "entry_border");
entry_shadow_switch.set_active (key_file.get_boolean ("Entry", "entry_shadow"));
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
try {
misc_runningbg1_value = key_file.get_string ("Misc", "misc_runningbg1");
misc_runningbg2_value = key_file.get_string ("Misc", "misc_runningbg2");
misc_separator1_value = key_file.get_string ("Misc", "misc_separator1");
misc_separator2_value = key_file.get_string ("Misc", "misc_separator2");
misc_tooltipbg1_value = key_file.get_string ("Misc", "misc_tooltipbg1");
misc_tooltipbg2_value = key_file.get_string ("Misc", "misc_tooltipbg2");
misc_tooltipfg_value = key_file.get_string ("Misc", "misc_tooltipfg");
misc_tooltipborder_value = key_file.get_string ("Misc", "misc_tooltipborder");
misc_insensitive_value = key_file.get_string ("Misc", "misc_insensitive");
} catch (Error e) {
stderr.printf ("Failed to set properties: %s\n", e.message);
}
// Set colors
var color = Gdk.RGBA ();
color.parse (color_value);
color_button.set_rgba (color);
color.parse (text_value);
text_button.set_rgba (color);
color.parse (panel_bg1_value);
panel_bg1_color.set_rgba (color);
color.parse (panel_bg2_value);
panel_bg2_color.set_rgba (color);
color.parse (panel_fg_value);
panel_fg_color.set_rgba (color);
color.parse (panel_border_value);
panel_border_color.set_rgba (color);
color.parse (overview_searchbg1_value);
overview_searchbg1_color.set_rgba (color);
color.parse (overview_searchbg2_value);
overview_searchbg2_color.set_rgba (color);
color.parse (overview_searchfocusbg1_value);
overview_searchfocusbg1_color.set_rgba (color);
color.parse (overview_searchfocusbg2_value);
overview_searchfocusbg2_color.set_rgba (color);
color.parse (overview_searchfg_value);
overview_searchfg_color.set_rgba (color);
color.parse (overview_searchborder_value);
overview_searchborder_color.set_rgba (color);
color.parse (dash_bg1_value);
dash_bg1_color.set_rgba (color);
color.parse (dash_bg2_value);
dash_bg2_color.set_rgba (color);
color.parse (dash_fg_value);
dash_fg_color.set_rgba (color);
color.parse (dash_border_value);
dash_border_color.set_rgba (color);
color.parse (menu_bg1_value);
menu_bg1_color.set_rgba (color);
color.parse (menu_bg2_value);
menu_bg2_color.set_rgba (color);
color.parse (menu_fg_value);
menu_fg_color.set_rgba (color);
color.parse (menu_border_value);
menu_border_color.set_rgba (color);
color.parse (dialog_bg1_value);
dialog_bg1_color.set_rgba (color);
color.parse (dialog_bg2_value);
dialog_bg2_color.set_rgba (color);
color.parse (dialog_fg_value);
dialog_fg_color.set_rgba (color);
color.parse (dialog_heading_value);
dialog_heading_color.set_rgba (color);
color.parse (dialog_border_value);
dialog_border_color.set_rgba (color);
color.parse (button_bg1_value);
button_bg1_color.set_rgba (color);
color.parse (button_bg2_value);
button_bg2_color.set_rgba (color);
color.parse (button_hoverbg1_value);
button_hoverbg1_color.set_rgba (color);
color.parse (button_hoverbg2_value);
button_hoverbg2_color.set_rgba (color);
color.parse (button_activebg1_value);
button_activebg1_color.set_rgba (color);
color.parse (button_activebg2_value);
button_activebg2_color.set_rgba (color);
color.parse (button_fg_value);
button_fg_color.set_rgba (color);
color.parse (button_hoverfg_value);
button_hoverfg_color.set_rgba (color);
color.parse (button_activefg_value);
button_activefg_color.set_rgba (color);
color.parse (button_border_value);
button_border_color.set_rgba (color);
color.parse (button_hoverborder_value);
button_hoverborder_color.set_rgba (color);
color.parse (button_activeborder_value);
button_activeborder_color.set_rgba (color);
color.parse (buttonfocus_bg1_value);
buttonfocus_bg1_color.set_rgba (color);
color.parse (buttonfocus_bg2_value);
buttonfocus_bg2_color.set_rgba (color);
color.parse (buttonfocus_hoverbg1_value);
buttonfocus_hoverbg1_color.set_rgba (color);
color.parse (buttonfocus_hoverbg2_value);
buttonfocus_hoverbg2_color.set_rgba (color);
color.parse (buttonfocus_activebg1_value);
buttonfocus_activebg1_color.set_rgba (color);
color.parse (buttonfocus_activebg2_value);
buttonfocus_activebg2_color.set_rgba (color);
color.parse (buttonfocus_fg_value);
buttonfocus_fg_color.set_rgba (color);
color.parse (buttonfocus_hoverfg_value);
buttonfocus_hoverfg_color.set_rgba (color);
color.parse (buttonfocus_activefg_value);
buttonfocus_activefg_color.set_rgba (color);
color.parse (buttonfocus_border_value);
buttonfocus_border_color.set_rgba (color);
color.parse (buttonfocus_hoverborder_value);
buttonfocus_hoverborder_color.set_rgba (color);
color.parse (buttonfocus_activeborder_value);
buttonfocus_activeborder_color.set_rgba (color);
color.parse (entry_bg1_value);
entry_bg1_color.set_rgba (color);
color.parse (entry_bg2_value);
entry_bg2_color.set_rgba (color);
color.parse (entry_fg_value);
entry_fg_color.set_rgba (color);
color.parse (entry_border_value);
entry_border_color.set_rgba (color);
color.parse (misc_runningbg1_value);
misc_runningbg1_color.set_rgba (color);
color.parse (misc_runningbg2_value);
misc_runningbg2_color.set_rgba (color);
color.parse (misc_separator1_value);
misc_separator1_color.set_rgba (color);
color.parse (misc_separator2_value);
misc_separator2_color.set_rgba (color);
color.parse (misc_tooltipbg1_value);
misc_tooltipbg1_color.set_rgba (color);
color.parse (misc_tooltipbg2_value);
misc_tooltipbg2_color.set_rgba (color);
color.parse (misc_tooltipfg_value);
misc_tooltipfg_color.set_rgba (color);
color.parse (misc_tooltipborder_value);
misc_tooltipborder_color.set_rgba (color);
color.parse (misc_insensitive_value);
misc_insensitive_color.set_rgba (color);
// Grey out "GTK theme" button if the theme uses gresource system
var gtk_theme = new GLib.Settings ("org.gnome.desktop.interface").get_string ("gtk-theme");
if (File.new_for_path (Environment.get_home_dir ()).get_child (".themes/%s/gtk-3.0/gtk.gresource".printf (gtk_theme)).query_exists () || File.parse_name ("/usr/share/themes/%s/gtk-3.0/gtk.gresource".printf (gtk_theme)).query_exists ()) {
match_theme.set_sensitive (false);
if (match_theme.get_active ()) {
custom_color.set_active (true);
color_button.set_sensitive (true);
}
}
}
private void create_widgets () {
// Create and setup widgets
// General
var presets_label = new Gtk.Label.with_mnemonic ("Load config from preset");
presets_label.set_halign (Gtk.Align.START);
// Create user presets directory if doesn't exist
if (!presets_dir_usr.query_exists ()) {
try {
presets_dir_usr.make_directory_with_parents (null);
} catch (Error e) {
stderr.printf ("Could not create user presets directory: %s\n", e.message);
}
}
// Read presets from user dir
try {
var dir = Dir.open (presets_dir_usr.get_path ());
var titlechanged = false;
string preset = "";
string title = "";
while ((preset = dir.read_name ()) != null) {
var path = Path.build_filename (presets_dir_usr.get_path (), preset);
if (FileUtils.test (path, FileTest.IS_REGULAR)) {
presets += preset;
try {
var dis = new DataInputStream (presets_dir_usr.get_child (preset).read ());
string line;
while ((line = dis.read_line (null)) != null) {
if ("# Name:" in line) {
title = line.substring (8, line.length-8);
titlechanged = true;
}
}
} catch (Error e) {
stderr.printf ("Could not read preset title: %s\n", e.message);
}
if (!titlechanged == true) {
title = preset;
}
titles += title;
titlechanged = false;
}
}
} catch (Error e) {
stderr.printf ("Failed to open user presets directory: %s\n", e.message);
}
// Read presets from system dir
try {
var dir = Dir.open (presets_dir_sys.get_path ());
var titlechanged = false;
string preset = "";
string title = "";
while ((preset = dir.read_name ()) != null) {
var path = Path.build_filename (presets_dir_sys.get_path (), preset);
if (FileUtils.test (path, FileTest.IS_REGULAR)) {
presets += preset;
try {
var dis = new DataInputStream (presets_dir_sys.get_child (preset).read ());
string line;
while ((line = dis.read_line (null)) != null) {
if ("# Name:" in line) {
title = line.substring (8, line.length-8);
titlechanged = true;
}
}
} catch (Error e) {
stderr.printf ("Could not read preset title: %s\n", e.message);
}
if (!titlechanged == true) {
title = preset;
}
titles += title;
titlechanged = false;
}
}
} catch (Error e) {
stderr.printf ("Failed to open systemwide presets directory: %s\n", e.message);
}
var liststore = new Gtk.ListStore (1, typeof (string));
for (int i = 0; i < titles.length; i++) {
Gtk.TreeIter iter;
liststore.append (out iter);
liststore.set (iter, 0, titles[i]);
}
var cell = new Gtk.CellRendererText ();
combobox = new Gtk.ComboBox.with_model (liststore);
combobox.pack_start (cell, false);
combobox.set_attributes (cell, "text", 0);
combobox.set_active (0);
combobox.set_tooltip_text ("Load settings from an installed preset");
combobox.set_halign (Gtk.Align.END);
var mode_label = new Gtk.Label.with_mnemonic ("Derive color from");
mode_label.set_halign (Gtk.Align.START);
match_wallpaper = new Gtk.RadioButton (null);
match_wallpaper.set_label ("Wallpaper");
match_wallpaper.set_mode (false);
match_wallpaper.set_tooltip_text ("Derive the highlight color from the current wallpaper");
match_theme = new Gtk.RadioButton.with_label (match_wallpaper.get_group (), "GTK theme");
match_theme.set_mode (false);
match_theme.set_tooltip_text ("Derive the highlight color from the current GTK theme");
custom_color = new Gtk.RadioButton.with_label (match_theme.get_group (), "Custom");
custom_color.set_mode (false);
custom_color.set_tooltip_text ("Manually set a custom highlight color");
color_button = new Gtk.ColorButton ();
((Gtk.ColorChooser) color_button).set_use_alpha (true);
color_button.set_tooltip_text ("Set a custom highlight color");
var text_label = new Gtk.Label.with_mnemonic ("Highlight text color");
text_label.set_halign (Gtk.Align.START);
text_auto = new Gtk.RadioButton (null);
text_auto.set_label ("Automatic");
text_auto.set_mode (false);
text_auto.set_tooltip_text ("Automatically determine the highlight text color");
text_color = new Gtk.RadioButton.with_label (text_auto.get_group (), "Custom");
text_color.set_mode (false);
text_color.set_tooltip_text ("Manually set a custom highlight text color");
text_button = new Gtk.ColorButton ();
((Gtk.ColorChooser) text_button).set_use_alpha (true);
text_button.set_tooltip_text ("Set a custom highlight text color");
var font_label = new Gtk.Label.with_mnemonic ("Display font");
font_label.set_halign (Gtk.Align.START);
font_button = new Gtk.FontButton ();
font_button.set_title ("Choose a font");
font_button.set_use_font (true);
font_button.set_use_size (true);
font_button.set_tooltip_text ("Choose the shell font family and font size");
font_button.set_halign (Gtk.Align.END);
var dropshadow_label = new Gtk.Label.with_mnemonic ("Drop shadows");
dropshadow_label.set_halign (Gtk.Align.START);
dropshadow_switch = new Gtk.Switch ();
dropshadow_switch.set_tooltip_text ("Enable/disable drop shadows");
dropshadow_switch.set_halign (Gtk.Align.END);
var selgradient_label = new Gtk.Label.with_mnemonic ("Highlight gradient size");
selgradient_label.set_halign (Gtk.Align.START);
selgradient_size = new Gtk.SpinButton.with_range (0, 255, 1);
selgradient_size.set_tooltip_text ("Set the gradient size for highlight color");
selgradient_size.set_halign (Gtk.Align.END);
var roundness_label = new Gtk.Label.with_mnemonic ("Roundness");
roundness_label.set_halign (Gtk.Align.START);
corner_roundness = new Gtk.SpinButton.with_range (0, 100, 1);
corner_roundness.set_tooltip_text ("Set the border radius of various elements");
corner_roundness.set_halign (Gtk.Align.END);
var transition_label = new Gtk.Label.with_mnemonic ("Transition duration");
transition_label.set_halign (Gtk.Align.START);
transition_duration = new Gtk.SpinButton.with_range (0, 1000, 1);
transition_duration.set_tooltip_text ("Set the duration of the transition animations");
transition_duration.set_halign (Gtk.Align.END);
var colorbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
colorbox.set_halign (Gtk.Align.END);
colorbox.set_homogeneous (true);
colorbox.get_style_context ().add_class ("linked");
colorbox.add (match_wallpaper);
colorbox.add (match_theme);
colorbox.add (custom_color);
colorbox.add (color_button);
var textbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
textbox.set_halign (Gtk.Align.END);
textbox.set_homogeneous (true);
textbox.get_style_context ().add_class ("linked");
textbox.add (text_auto);
textbox.add (text_color);
textbox.add (text_button);
var general_grid = new Gtk.Grid ();
general_grid.set_column_homogeneous (true);
general_grid.set_column_spacing (10);
general_grid.set_row_spacing (10);
general_grid.attach (presets_label, 0, 0, 1, 1);
general_grid.attach_next_to (combobox, presets_label, Gtk.PositionType.RIGHT, 2, 1);
general_grid.attach (mode_label, 0, 1, 1, 1);
general_grid.attach_next_to (colorbox, mode_label, Gtk.PositionType.RIGHT, 2, 1);
general_grid.attach (text_label, 0, 2, 1, 1);
general_grid.attach_next_to (textbox, text_label, Gtk.PositionType.RIGHT, 2, 1);
general_grid.attach (font_label, 0, 3, 1, 1);
general_grid.attach_next_to (font_button, font_label, Gtk.PositionType.RIGHT, 2, 1);
general_grid.attach (dropshadow_label, 0, 4, 2, 1);
general_grid.attach_next_to (dropshadow_switch, dropshadow_label, Gtk.PositionType.RIGHT, 1, 1);
general_grid.attach (selgradient_label, 0, 5, 2, 1);
general_grid.attach_next_to (selgradient_size, selgradient_label, Gtk.PositionType.RIGHT, 1, 1);
general_grid.attach (roundness_label, 0, 6, 2, 1);
general_grid.attach_next_to (corner_roundness, roundness_label, Gtk.PositionType.RIGHT, 1, 1);
general_grid.attach (transition_label, 0, 7, 2, 1);
general_grid.attach_next_to (transition_duration, transition_label, Gtk.PositionType.RIGHT, 1, 1);
// Panel
var panel_bg_label = new Gtk.Label.with_mnemonic ("Background gradient");
panel_bg_label.set_halign (Gtk.Align.START);
panel_bg1_color = new Gtk.ColorButton ();
((Gtk.ColorChooser) panel_bg1_color).set_use_alpha (true);
panel_bg1_color.set_tooltip_text ("Set the background gradient start of the top panel");
panel_bg2_color = new Gtk.ColorButton ();
((Gtk.ColorChooser) panel_bg2_color).set_use_alpha (true);
panel_bg2_color.set_tooltip_text ("Set the background gradient end of the top panel");
var panel_fg_label = new Gtk.Label.with_mnemonic ("Text color");
panel_fg_label.set_halign (Gtk.Align.START);
panel_fg_color = new Gtk.ColorButton ();
((Gtk.ColorChooser) panel_fg_color).set_use_alpha (true);
panel_fg_color.set_tooltip_text ("Set the text color of the top panel");
var panel_border_label = new Gtk.Label.with_mnemonic ("Border color");
panel_border_label.set_halign (Gtk.Align.START);
panel_border_color = new Gtk.ColorButton ();
((Gtk.ColorChooser) panel_border_color).set_use_alpha (true);
panel_border_color.set_tooltip_text ("Set the border color of the top panel");
var panel_icon_label = new Gtk.Label.with_mnemonic ("App icon");
panel_icon_label.set_halign (Gtk.Align.START);
panel_icon_switch = new Gtk.Switch ();
panel_icon_switch.set_tooltip_text ("Enable/disable app icon in the top panel");
panel_icon_switch.set_halign (Gtk.Align.END);