-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathconfigModel.vala
More file actions
1403 lines (1270 loc) · 50.9 KB
/
configModel.vala
File metadata and controls
1403 lines (1270 loc) · 50.9 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
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
namespace SwayNotificationCenter {
public enum PositionX {
RIGHT, LEFT, CENTER, NONE;
}
public enum PositionY {
TOP, BOTTOM, CENTER, NONE;
}
public enum ImageVisibility {
ALWAYS, WHEN_AVAILABLE, NEVER;
public string parse () {
switch (this) {
default:
return "always";
case WHEN_AVAILABLE:
return "when_available";
case NEVER:
return "never";
}
}
}
public enum Layer {
BACKGROUND, BOTTOM, TOP, OVERLAY;
public string parse () {
switch (this) {
case BACKGROUND:
return "background";
case BOTTOM:
return "bottom";
case TOP:
return "top";
default:
case OVERLAY:
return "overlay";
}
}
public GtkLayerShell.Layer to_layer () {
switch (this) {
case BACKGROUND:
return GtkLayerShell.Layer.BACKGROUND;
case BOTTOM:
return GtkLayerShell.Layer.BOTTOM;
case TOP:
return GtkLayerShell.Layer.TOP;
default:
case OVERLAY:
return GtkLayerShell.Layer.OVERLAY;
}
}
}
public enum CssPriority {
APPLICATION, USER;
public int get_priority () {
switch (this) {
case APPLICATION:
return Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION;
default:
case USER:
return Gtk.STYLE_PROVIDER_PRIORITY_USER;
}
}
}
public class Category : Object {
public string ?sound { get; set; default = null; }
public string ?icon { get; set; default = null; }
public string to_string () {
string[] fields = {};
if (sound != null) {
fields += "sound: %s".printf (sound);
}
if (icon != null) {
fields += "icon: %s".printf (icon);
}
return string.joinv (", ", fields);
}
}
private struct MatchCase {
string ?pattern;
string ?str;
public MatchCase (string ?pattern, string ?str) {
this.pattern = pattern;
this.str = str;
}
public bool is_valid () {
return pattern != null && str != null;
}
}
public class NotificationMatching : Object, Json.Serializable {
public string ?app_name { get; set; default = null; }
public string ?desktop_entry { get; set; default = null; }
public string ?summary { get; set; default = null; }
public string ?body { get; set; default = null; }
public string ?urgency { get; set; default = null; }
public string ?category { get; set; default = null; }
public string ?sound_name { get; set; default = null; }
public string ?sound_file { get; set; default = null; }
private const RegexCompileFlags REGEX_COMPILE_OPTIONS =
RegexCompileFlags.MULTILINE;
private const RegexMatchFlags REGEX_MATCH_FLAGS = RegexMatchFlags.NOTEMPTY;
public virtual bool matches_notification (NotifyParams param) {
if (app_name != null) {
if (param.app_name == null) {
return false;
}
bool result = Regex.match_simple (
app_name, param.app_name,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
}
if (desktop_entry != null) {
if (param.desktop_entry == null) {
return false;
}
bool result = Regex.match_simple (
desktop_entry, param.desktop_entry,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
}
if (summary != null) {
if (param.summary == null) {
return false;
}
bool result = Regex.match_simple (
summary, param.summary,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
}
if (body != null) {
if (param.body == null) {
return false;
}
bool result = Regex.match_simple (
body, param.body,
0,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
}
if (urgency != null) {
bool result = Regex.match_simple (
urgency, param.urgency.to_string (),
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
}
if (category != null) {
if (param.category == null) {
return false;
}
bool result = Regex.match_simple (
category, param.category,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
}
if (sound_file != null) {
if (param.sound_file == null) {
return false;
}
bool result = Regex.match_simple (
sound_file, param.sound_file,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
}
if (sound_name != null) {
if (param.sound_name == null) {
return false;
}
bool result = Regex.match_simple (
sound_name, param.sound_name,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
}
return true;
}
public string to_string () {
string[] fields = {};
if (app_name != null) {
fields += "app-name: %s".printf (app_name);
}
if (desktop_entry != null) {
fields += "desktop-entry: %s".printf (desktop_entry);
}
if (summary != null) {
fields += "summary: %s".printf (summary);
}
if (body != null) {
fields += "body: %s".printf (body);
}
if (urgency != null) {
fields += "urgency: %s".printf (urgency);
}
if (category != null) {
fields += "category: %s".printf (category);
}
return string.joinv (", ", fields);
}
public override Json.Node serialize_property (string property_name,
Value value,
ParamSpec pspec) {
// Return enum nickname instead of enum int value
if (value.type ().is_a (Type.ENUM)) {
var node = new Json.Node (Json.NodeType.VALUE);
EnumClass enumc = (EnumClass) value.type ().class_ref ();
unowned EnumValue ?eval
= enumc.get_value (value.get_enum ());
if (eval == null) {
node.set_value (value);
return node;
}
node.set_string (eval.value_nick);
return node;
} else if (value.type ().is_a (Type.BOOLEAN)) {
// Somehow the default serializer doesn't handle booleans :/
var node = new Json.Node (Json.NodeType.VALUE);
node.set_boolean (value.get_boolean ());
return node;
}
return default_serialize_property (property_name, value, pspec);
}
}
public class ActionMatching : Object, Json.Serializable {
public string ?app_name { get; set; default = null; }
public string ?desktop_entry { get; set; default = null; }
public string ?id_matcher { get; set; }
public string ?text_matcher { get; set; }
public bool use_regex { get; set; default = false; }
private const RegexCompileFlags REGEX_COMPILE_OPTIONS =
RegexCompileFlags.MULTILINE;
private const RegexMatchFlags REGEX_MATCH_FLAGS = RegexMatchFlags.NOTEMPTY;
public bool matches_action (Action action) {
MatchCase[] matchers = {
MatchCase (id_matcher, action.identifier),
MatchCase (text_matcher, action.text),
};
foreach (MatchCase matcher in matchers) {
if (!matcher.is_valid ()) {
continue;
}
if (use_regex) {
bool result = Regex.match_simple (
matcher.pattern, matcher.str,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
} else {
if (matcher.pattern != matcher.str) {
return false;
}
}
}
return true;
}
public bool matches_notification (NotifyParams param) {
if (id_matcher == null && text_matcher == null) {
critical ("Action filter doesn't contain a matcher: %s", this.to_string ());
return false;
}
MatchCase[] matchers = {
MatchCase (app_name, param.app_name),
MatchCase (desktop_entry, param.desktop_entry),
};
foreach (MatchCase matcher in matchers) {
if (!matcher.is_valid ()) {
continue;
}
if (use_regex) {
bool result = Regex.match_simple (
matcher.pattern, matcher.str,
REGEX_COMPILE_OPTIONS,
REGEX_MATCH_FLAGS);
if (!result) {
return false;
}
} else {
if (matcher.pattern != matcher.str) {
return false;
}
}
}
return true;
}
public string to_string () {
string[] fields = {};
if (app_name != null) {
fields += "app-name: %s".printf (app_name);
}
if (desktop_entry != null) {
fields += "desktop-entry: %s".printf (desktop_entry);
}
if (id_matcher != null) {
fields += "name_matcher: %s".printf (id_matcher);
}
if (text_matcher != null) {
fields += "text_matcher: %s".printf (text_matcher);
}
return string.joinv (", ", fields);
}
public override Json.Node serialize_property (string property_name,
Value value,
ParamSpec pspec) {
// Return enum nickname instead of enum int value
if (value.type ().is_a (Type.ENUM)) {
var node = new Json.Node (Json.NodeType.VALUE);
EnumClass enumc = (EnumClass) value.type ().class_ref ();
unowned EnumValue ?eval
= enumc.get_value (value.get_enum ());
if (eval == null) {
node.set_value (value);
return node;
}
node.set_string (eval.value_nick);
return node;
} else if (value.type ().is_a (Type.BOOLEAN)) {
// Somehow the default serializer doesn't handle booleans :/
var node = new Json.Node (Json.NodeType.VALUE);
node.set_boolean (value.get_boolean ());
return node;
}
return default_serialize_property (property_name, value, pspec);
}
}
public enum NotificationStatusEnum {
ENABLED,
MUTED,
IGNORED,
TRANSIENT;
public string to_string () {
switch (this) {
default :
return "enabled";
case MUTED:
return "muted";
case IGNORED:
return "ignored";
case TRANSIENT:
return "transient";
}
}
public static NotificationStatusEnum from_value (string value) {
switch (value) {
default:
return ENABLED;
case "muted":
return MUTED;
case "ignored":
return IGNORED;
case "transient":
return TRANSIENT;
}
}
}
public enum NotificationUrgencyEnum {
UNSET = -1,
LOW = UrgencyLevels.LOW,
NORMAL = UrgencyLevels.NORMAL,
CRITICAL = UrgencyLevels.CRITICAL;
public uint8 to_byte () {
return this;
}
public string to_string () {
switch (this) {
case LOW:
return "Low";
case NORMAL:
return "Normal";
case CRITICAL:
return "Critical";
default:
return "Unset";
}
}
}
public class NotificationVisibility : NotificationMatching {
public NotificationStatusEnum state { get; set; }
public NotificationUrgencyEnum override_urgency {
get; set; default = NotificationUrgencyEnum.UNSET;
}
}
public enum ScriptRunOnType {
ACTION,
RECEIVE;
}
#if WANT_SCRIPTING
public class Script : NotificationMatching {
public string ?exec { get; set; default = null; }
public ScriptRunOnType run_on { get; set; default = ScriptRunOnType.RECEIVE; }
public async bool run_script (NotifyParams param, out string msg) {
string[] spawn_env = {};
spawn_env += "SWAYNC_APP_NAME=%s".printf (param.app_name);
spawn_env += "SWAYNC_SUMMARY=%s".printf (param.summary);
spawn_env += "SWAYNC_BODY=%s".printf (param.body);
spawn_env += "SWAYNC_URGENCY=%s".printf (param.urgency.to_string ());
spawn_env += "SWAYNC_CATEGORY=%s".printf (param.category);
spawn_env += "SWAYNC_SOUND_NAME=%s".printf (param.sound_name);
spawn_env += "SWAYNC_SOUND_FILE=%s".printf (param.sound_file);
spawn_env += "SWAYNC_ID=%s".printf (param.applied_id.to_string ());
spawn_env += "SWAYNC_REPLACES_ID=%s".printf (param.replaces_id.to_string ());
spawn_env += "SWAYNC_TIME=%s".printf (param.time.to_string ());
spawn_env += "SWAYNC_DESKTOP_ENTRY=%s".printf (param.desktop_entry ?? "");
foreach (string hint in param.hints.get_keys ()) {
if (hint.contains ("image") || hint.contains ("icon")) {
continue;
}
spawn_env += "SWAYNC_HINT_%s=%s".printf (
hint.up ().replace ("-", "_"),
param.hints[hint].print (false));
}
return yield Functions.execute_command (exec, spawn_env, out msg);
}
public override bool matches_notification (NotifyParams param) {
if (exec == null) {
return false;
}
return base.matches_notification (param);
}
}
#endif
public class ConfigModel : Object, Json.Serializable {
private static ConfigModel ?_instance = null;
private static string _path = "";
/** Get the static singleton */
public static unowned ConfigModel instance {
get {
if (_instance == null) {
_instance = new ConfigModel ();
}
if (_path.length <= 0) {
_path = Functions.get_config_path (null);
}
return _instance;
}
}
/** Get the static singleton and reload the config */
public static unowned ConfigModel init (string ?path) {
_path = path;
reload_config ();
return _instance;
}
public delegate void ModifyNode (Json.Node node);
/** Reloads the config and calls `ModifyNode` before deserializing */
public static void reload_config (ModifyNode modify_cb = () => {}) {
// Re-check if config file path still exists
string path = Functions.get_config_path (_path);
path = File.new_for_path (path).get_path () ?? path;
message ("Loading Config: \"%s\"", path);
ConfigModel m = null;
try {
if (path.strip ().length == 0) {
return;
}
Json.Parser parser = new Json.Parser ();
parser.load_from_file (path);
Json.Node ?node = parser.get_root ();
if (node == null) {
throw new Json.ParserError.PARSE ("Node is null!");
}
modify_cb (node);
ConfigModel model = Json.gobject_deserialize (
typeof (ConfigModel), node) as ConfigModel;
if (model == null) {
throw new Json.ParserError.UNKNOWN ("Json model is null!");
}
m = model;
} catch (Error e) {
critical (e.message);
m = new ConfigModel ();
}
ConfigModel ?previous_config = _instance;
_instance = m;
_path = path;
debug (_instance.to_string ());
if (app != null) {
app.config_reload (previous_config, m);
}
}
/* Properties */
/** Unsets the GTK_THEME env variable when true */
public bool ignore_gtk_theme { get; set; default = true; }
/** The notifications and controlcenters horizontal alignment */
public PositionX positionX { // vala-lint=naming-convention
get; set; default = PositionX.RIGHT;
}
/** The notifications and controlcenters vertical alignment */
public PositionY positionY { // vala-lint=naming-convention
get; set; default = PositionY.TOP;
}
/** Layer of notification window */
public Layer layer {
get; set; default = Layer.OVERLAY;
}
/**
* Wether or not the windows should be opened as layer-shell surfaces
*/
public bool layer_shell { get; set; default = true; }
/**
* Wether or not the windows should cover the whole screen when
* layer-shell is used.
*/
public bool layer_shell_cover_screen { get; set; default = true; }
/** The CSS loading priority */
public CssPriority cssPriority { // vala-lint=naming-convention
get; set; default = CssPriority.USER;
}
/** The timeout for notifications with NORMAL priority */
private const int TIMEOUT_DEFAULT = 10;
private int _timeout = TIMEOUT_DEFAULT;
public int timeout {
get {
return _timeout;
}
set {
_timeout = value < 0 ? TIMEOUT_DEFAULT : value;
}
}
/** The timeout for notifications with LOW priority */
private const int TIMEOUT_LOW_DEFAULT = 5;
private int _timeout_low = TIMEOUT_LOW_DEFAULT;
public int timeout_low {
get {
return _timeout_low;
}
set {
_timeout_low = value < 0 ? TIMEOUT_LOW_DEFAULT : value;
}
}
/** The timeout for notifications with CRITICAL priority */
private const int TIMEOUT_CRITICAL_DEFAULT = 0;
private int _timeout_critical = TIMEOUT_CRITICAL_DEFAULT;
public int timeout_critical {
get {
return _timeout_critical;
}
set {
_timeout_critical = value < 0 ? TIMEOUT_CRITICAL_DEFAULT : value;
}
}
/** The transition time for all animations */
private const int TRANSITION_TIME_DEFAULT = 200;
private int _transition_time = TRANSITION_TIME_DEFAULT;
public int transition_time {
get {
return _transition_time;
}
set {
_transition_time = value < 0 ? TRANSITION_TIME_DEFAULT : value;
}
}
/*
* Specifies if the control center should use keyboard shortcuts
* and block keyboard input for other applications while open
*/
public bool keyboard_shortcuts { get; set; default = true; }
/**
* If notifications should be grouped by app name
*/
public bool notification_grouping { get; set; default = true; }
/** Specifies if the notification image should be shown or not */
public ImageVisibility image_visibility {
get;
set;
default = ImageVisibility.WHEN_AVAILABLE;
}
/**
* Notification window's width, in pixels.
*/
public int notification_window_width { get; set; default = 500; }
/** Max height of the notification in pixels */
public int notification_window_height { get; set; default = -1; }
/**
* The preferred output to open the notification window (popup notifications).
*
* Can either be the monitor connector name (ex: "DP-1"),
* or the full name, manufacturer model serial
* (ex: "Acer Technologies XV272U V 503023B314202").
*
* If the output is not found, the currently focused one is picked.
*/
public string notification_window_preferred_output { get; set; default = ""; }
/** Hides the control center after clearing all notifications */
public bool hide_on_clear { get; set; default = false; }
/** Hides the control center when clicking on notification action */
public bool hide_on_action { get; set; default = true; }
/** Text that appears when there are no notifications to show */
public string text_empty { get; set; default = "No Notifications"; }
/** The controlcenters horizontal alignment. Supersedes `positionX` if not `NONE` */
public PositionX control_center_positionX { // vala-lint=naming-convention
get; set; default = PositionX.NONE;
}
/** The controlcenters vertical alignment. Supersedes `positionY` if not `NONE` */
public PositionY control_center_positionY { // vala-lint=naming-convention
get; set; default = PositionY.NONE;
}
/** GtkLayerShell margins around the notification center */
private int control_center_margin_top_ = 0;
public int control_center_margin_top {
get {
return control_center_margin_top_;
}
set {
control_center_margin_top_ = value < 0 ? 0 : value;
}
}
private int control_center_margin_bottom_ = 0;
public int control_center_margin_bottom {
get {
return control_center_margin_bottom_;
}
set {
control_center_margin_bottom_ = value < 0 ? 0 : value;
}
}
private int control_center_margin_left_ = 0;
public int control_center_margin_left {
get {
return control_center_margin_left_;
}
set {
control_center_margin_left_ = value < 0 ? 0 : value;
}
}
private int control_center_margin_right_ = 0;
public int control_center_margin_right {
get {
return control_center_margin_right_;
}
set {
control_center_margin_right_ = value < 0 ? 0 : value;
}
}
/** Layer of Control Center window */
public Layer control_center_layer {
get; set; default = Layer.TOP;
}
public bool control_center_exclusive_zone {
get; set; default = true;
}
/** Categories settings */
public OrderedHashTable<Category> categories_settings {
get;
set;
default = new OrderedHashTable<Category> ();
}
/** Filter Notification Actions */
public OrderedHashTable<ActionMatching> notification_action_filter {
get;
set;
default = new OrderedHashTable<ActionMatching> ();
}
/** Notification Status */
public OrderedHashTable<NotificationVisibility> notification_visibility {
get;
set;
default = new OrderedHashTable<NotificationVisibility> ();
}
#if WANT_SCRIPTING
/** Scripts */
public OrderedHashTable<Script> scripts {
get;
set;
default = new OrderedHashTable<Script> ();
}
/** Show notification if script fails */
public bool script_fail_notify { get; set; default = true; }
#endif
/** Whether to expand the notification center across both edges of the screen */
public bool fit_to_screen { get; set; default = true; }
/**
* Display notification timestamp relative to now e.g. "26 minutes ago".
* If false, a local iso8601-formatted absolute timestamp is displayed.
*/
public bool relative_timestamps { get; set; default = true; }
/**
* Height of the control center in pixels. A value of -1 means that it
* will fit to the content. Ignored when 'fit-to-screen' is set to 'true'.
* Also limited to the height of the monitor, unless 'layer-shell-cover-screen'
* is set to false.
*/
private int _control_center_height = 500;
public int control_center_height {
get {
return _control_center_height;
}
set {
if (value < 1) {
_control_center_height = -1;
return;
}
_control_center_height = value;
}
}
/**
* Notification center's width, in pixels.
*/
private const int CONTROL_CENTER_MINIMUM_WIDTH = 300;
private const int CONTROL_CENTER_DEFAULT_WIDTH = 500;
private int _control_center_width = CONTROL_CENTER_DEFAULT_WIDTH;
public int control_center_width {
get {
return _control_center_width;
}
set {
_control_center_width = value > CONTROL_CENTER_MINIMUM_WIDTH
? value : CONTROL_CENTER_MINIMUM_WIDTH;
}
}
/**
* The preferred output to open the control center.
*
* Can either be the monitor connector name (ex: "DP-1"),
* or the full name, manufacturer model serial
* (ex: "Acer Technologies XV272U V 503023B314202").
*
* If the output is not found, the currently focused one is picked.
*/
public string control_center_preferred_output { get; set; default = ""; }
/**
* If each notification should display a 'COPY \"1234\"' action
*/
public bool notification_2fa_action { get; set; default = true; }
/**
* If notifications should display a text field to reply if the
* sender requests it.
*/
public bool notification_inline_replies { get; set; default = false; }
/**
* Notification icon size, in pixels.
*/
[Version (deprecated = true, replacement = "CSS root variable")]
public int notification_icon_size {
get; set; default = -1;
}
/**
* Notification body image height, in pixels.
*/
private const int NOTIFICATION_BODY_IMAGE_MINIMUM_HEIGHT = 100;
private const int NOTIFICATION_BODY_IMAGE_DEFAULT_HEIGHT = 100;
private int _notification_body_image_height = NOTIFICATION_BODY_IMAGE_DEFAULT_HEIGHT;
public int notification_body_image_height {
get {
return _notification_body_image_height;
}
set {
_notification_body_image_height =
value > NOTIFICATION_BODY_IMAGE_MINIMUM_HEIGHT
? value : NOTIFICATION_BODY_IMAGE_MINIMUM_HEIGHT;
}
}
/**
* Notification body image width, in pixels.
*/
private const int NOTIFICATION_BODY_IMAGE_MINIMUM_WIDTH = 200;
private const int NOTIFICATION_BODY_IMAGE_DEFAULT_WIDTH = 200;
private int _notification_body_image_width = NOTIFICATION_BODY_IMAGE_DEFAULT_WIDTH;
public int notification_body_image_width {
get {
return _notification_body_image_width;
}
set {
_notification_body_image_width =
value > NOTIFICATION_BODY_IMAGE_MINIMUM_WIDTH
? value : NOTIFICATION_BODY_IMAGE_MINIMUM_WIDTH;
}
}
/** Widgets to show in ControlCenter */
public GenericArray<string> widgets {
get;
set;
default = new GenericArray<string> ();
}
/** Widgets to show in ControlCenter */
public OrderedHashTable<Json.Object> widget_config {
get;
set;
default = new OrderedHashTable<Json.Object> ();
}
/* Methods */
/**
* Selects the deserialization method based on the property name.
* Needed to parse those parameters of complex types like hashtables,
* which are not natively supported by the default deserialization function.
*/
public override bool deserialize_property (string property_name,
out Value value,
ParamSpec pspec,
Json.Node property_node) {
switch (property_name) {
case "categories-settings" :
bool status;
OrderedHashTable<Category> result =
extract_hashtable<Category> (
property_name,
property_node,
out status);
value = result;
return status;
case "notification-action-filter" :
bool status;
OrderedHashTable<ActionMatching> result =
extract_hashtable<ActionMatching> (
property_name,
property_node,
out status);
value = result;
return status;
case "notification-visibility" :
bool status;
OrderedHashTable<NotificationVisibility> result =
extract_hashtable<NotificationVisibility> (
property_name,
property_node,
out status);
value = result;
return status;
#if WANT_SCRIPTING
case "scripts":
bool status;
OrderedHashTable<Script> result =
extract_hashtable<Script> (
property_name,
property_node,
out status);
value = result;
return status;
#endif
case "widgets":
bool status;
GenericArray<string> result =
extract_array<string> (property_name,
property_node,
out status);
value = result;
return status;
case "widget-config":
OrderedHashTable<Json.Object> result
= new OrderedHashTable<Json.Object> ();
if (property_node.get_value_type ().name () != "JsonObject") {
value = result;
return true;
}
Json.Object obj = property_node.get_object ();
if (obj.get_size () == 0) {
value = result;
return true;
}
foreach (var key in obj.get_members ()) {
Json.Node ?node = obj.get_member (key);
if (node.get_node_type () != Json.NodeType.OBJECT) {
continue;
}
Json.Object ?o = node.get_object ();
if (o != null) {
result.insert (key, o);
}
}
value = result;
return true;
default :
// Handles all other properties
return default_deserialize_property (
property_name, out value, pspec, property_node);
}
}
/**
* Called when `Json.gobject_serialize (ConfigModel.instance)` is called
*/
public Json.Node serialize_property (string property_name,
Value value,
ParamSpec pspec) {
var node = new Json.Node (Json.NodeType.VALUE);
if (value.type ().is_a (Type.ENUM)) {
EnumClass enumc = (EnumClass) pspec.value_type.class_ref ();
EnumValue ?eval
= enumc.get_value (value.get_enum ());
if (eval == null) {
node.set_value (value);
return node;
}
node.set_string (eval.value_nick);
return node;