forked from home-sweet-gnome/dash-to-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
2467 lines (2008 loc) · 124 KB
/
prefs.js
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
/*
* This file is part of the Dash-To-Panel extension for Gnome 3
*
* 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 2 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, see <http://www.gnu.org/licenses/>.
*
*
* Credits:
* This file is based on code from the Dash to Dock extension by micheleg.
* Some code was also adapted from the upstream Gnome Shell source code.
*/
const GdkPixbuf = imports.gi.GdkPixbuf;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
const _ = Gettext.gettext;
const N_ = function(e) { return e };
const PanelSettings = Me.imports.panelSettings;
const Pos = Me.imports.panelPositions;
const SCALE_UPDATE_TIMEOUT = 500;
const DEFAULT_PANEL_SIZES = [ 128, 96, 64, 48, 32, 24, 16 ];
const DEFAULT_FONT_SIZES = [ 96, 64, 48, 32, 24, 16, 0 ];
const DEFAULT_MARGIN_SIZES = [ 32, 24, 16, 12, 8, 4, 0 ];
const DEFAULT_PADDING_SIZES = [ 32, 24, 16, 12, 8, 4, 0, -1 ];
// Minimum length could be 0, but a higher value may help prevent confusion about where the panel went.
const LENGTH_MARKS = [ 100, 90, 80, 70, 60, 50, 40, 30, 20, 10 ];
const MAX_WINDOW_INDICATOR = 4;
const SCHEMA_PATH = '/org/gnome/shell/extensions/dash-to-panel/';
const GSET = 'gnome-shell-extension-tool';
/**
* This function was copied from the activities-config extension
* https://github.com/nls1729/acme-code/tree/master/activities-config
* by Norman L. Smith.
*/
function cssHexString(css) {
let rrggbb = '#';
let start;
for (let loop = 0; loop < 3; loop++) {
let end = 0;
let xx = '';
for (let loop = 0; loop < 2; loop++) {
while (true) {
let x = css.slice(end, end + 1);
if ((x == '(') || (x == ',') || (x == ')'))
break;
end++;
}
if (loop == 0) {
end++;
start = end;
}
}
xx = parseInt(css.slice(start, end)).toString(16);
if (xx.length == 1)
xx = '0' + xx;
rrggbb += xx;
css = css.slice(end);
}
return rrggbb;
}
function setShortcut(settings, shortcutName) {
let shortcut_text = settings.get_string(shortcutName + '-text');
let [key, mods] = Gtk.accelerator_parse(shortcut_text);
if (Gtk.accelerator_valid(key, mods)) {
let shortcut = Gtk.accelerator_name(key, mods);
settings.set_strv(shortcutName, [shortcut]);
}
else {
settings.set_strv(shortcutName, []);
}
}
function checkHotkeyPrefix(settings) {
settings.delay();
let hotkeyPrefix = settings.get_string('hotkey-prefix-text');
if (hotkeyPrefix == 'Super')
hotkeyPrefix = '<Super>';
else if (hotkeyPrefix == 'SuperAlt')
hotkeyPrefix = '<Super><Alt>';
let [, mods] = Gtk.accelerator_parse(hotkeyPrefix);
let [, shift_mods] = Gtk.accelerator_parse('<Shift>' + hotkeyPrefix);
let [, ctrl_mods] = Gtk.accelerator_parse('<Ctrl>' + hotkeyPrefix);
let numHotkeys = 10;
for (let i = 1; i <= numHotkeys; i++) {
let number = i;
if (number == 10)
number = 0;
let key = Gdk.keyval_from_name(number.toString());
let key_kp = Gdk.keyval_from_name('KP_' + number.toString());
if (Gtk.accelerator_valid(key, mods)) {
let shortcut = Gtk.accelerator_name(key, mods);
let shortcut_kp = Gtk.accelerator_name(key_kp, mods);
// Setup shortcut strings
settings.set_strv('app-hotkey-' + i, [shortcut]);
settings.set_strv('app-hotkey-kp-' + i, [shortcut_kp]);
// With <Shift>
shortcut = Gtk.accelerator_name(key, shift_mods);
shortcut_kp = Gtk.accelerator_name(key_kp, shift_mods);
settings.set_strv('app-shift-hotkey-' + i, [shortcut]);
settings.set_strv('app-shift-hotkey-kp-' + i, [shortcut_kp]);
// With <Control>
shortcut = Gtk.accelerator_name(key, ctrl_mods);
shortcut_kp = Gtk.accelerator_name(key_kp, ctrl_mods);
settings.set_strv('app-ctrl-hotkey-' + i, [shortcut]);
settings.set_strv('app-ctrl-hotkey-kp-' + i, [shortcut_kp]);
}
else {
// Reset default settings for the relevant keys if the
// accelerators are invalid
let keys = ['app-hotkey-' + i, 'app-shift-hotkey-' + i, 'app-ctrl-hotkey-' + i, // Regular numbers
'app-hotkey-kp-' + i, 'app-shift-hotkey-kp-' + i, 'app-ctrl-hotkey-kp-' + i]; // Key-pad numbers
keys.forEach(function(val) {
settings.set_value(val, settings.get_default_value(val));
}, this);
}
}
settings.apply();
}
function mergeObjects(main, bck) {
for (var prop in bck) {
if (!main.hasOwnProperty(prop) && bck.hasOwnProperty(prop)) {
main[prop] = bck[prop];
}
}
return main;
};
const Preferences = new Lang.Class({
Name: 'DashToPanel.Preferences',
_init: function() {
this._settings = Convenience.getSettings('org.gnome.shell.extensions.dash-to-panel');
this._rtl = (Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL);
this._builder = new Gtk.Builder();
this._builder.set_scope(new BuilderScope(this));
this._builder.set_translation_domain(Me.metadata['gettext-domain']);
this._builder.add_from_file(Me.path + '/Settings.ui');
this.notebook = this._builder.get_object('settings_notebook');
// Timeout to delay the update of the settings
this._panel_size_timeout = 0;
this._dot_height_timeout = 0;
this._tray_size_timeout = 0;
this._leftbox_size_timeout = 0;
this._appicon_margin_timeout = 0;
this._appicon_padding_timeout = 0;
this._opacity_timeout = 0;
this._tray_padding_timeout = 0;
this._statusicon_padding_timeout = 0;
this._leftbox_padding_timeout = 0;
this._addFormatValueCallbacks();
this._bindSettings();
},
/**
* Connect signals
*/
_connector: function(builder, object, signal, handler) {
object.connect(signal, Lang.bind(this, this._SignalHandler[handler]));
},
_updateVerticalRelatedOptions: function() {
let position = this._getPanelPosition(this._currentMonitorIndex);
let isVertical = position == Pos.LEFT || position == Pos.RIGHT;
let showDesktopWidthLabel = this._builder.get_object('show_showdesktop_width_label');
showDesktopWidthLabel.set_text(isVertical ? _('Show Desktop button height (px)') : _('Show Desktop button width (px)'));
this._displayPanelPositionsForMonitor(this._currentMonitorIndex);
},
_maybeDisableTopPosition: function() {
let keepTopPanel = this._settings.get_boolean('stockgs-keep-top-panel');
let monitorSync = this._settings.get_boolean('panel-element-positions-monitors-sync');
let topAvailable = !keepTopPanel || (!monitorSync && this._currentMonitorIndex != this.monitors[0]);
let topRadio = this._builder.get_object('position_top_button');
topRadio.set_sensitive(topAvailable);
topRadio.set_tooltip_text(!topAvailable ? _('Unavailable when gnome-shell top panel is present') : '');
},
_getPanelPosition: function(monitorIndex) {
return PanelSettings.getPanelPosition(this._settings, monitorIndex);
},
_setPanelPosition: function(position) {
const monitorSync = this._settings.get_boolean('panel-element-positions-monitors-sync');
const monitorsToSetFor = monitorSync ? this.monitors : [this._currentMonitorIndex];
monitorsToSetFor.forEach(monitorIndex => {
PanelSettings.setPanelPosition(this._settings, monitorIndex, position);
});
this._setAnchorLabels(this._currentMonitorIndex);
},
_setPositionRadios: function(position) {
this._ignorePositionRadios = true;
switch (position) {
case Pos.BOTTOM:
this._builder.get_object('position_bottom_button').set_active(true);
break;
case Pos.TOP:
this._builder.get_object('position_top_button').set_active(true);
break;
case Pos.LEFT:
this._builder.get_object('position_left_button').set_active(true);
break;
case Pos.RIGHT:
this._builder.get_object('position_right_button').set_active(true);
break;
}
this._ignorePositionRadios = false;
},
/**
* Set panel anchor combo labels according to whether the monitor's panel is vertical
* or horizontal, or if all monitors' panels are being configured and they are a mix
* of vertical and horizontal.
*/
_setAnchorLabels: function(currentMonitorIndex) {
const monitorSync = this._settings.get_boolean('panel-element-positions-monitors-sync');
const monitorsToSetFor = monitorSync ? this.monitors : [currentMonitorIndex];
const allVertical = monitorsToSetFor.every(i => {
const position = PanelSettings.getPanelPosition(this._settings, i);
return position === Pos.LEFT || position === Pos.RIGHT
});
const allHorizontal = monitorsToSetFor.every(i => {
const position = PanelSettings.getPanelPosition(this._settings, i);
return position === Pos.TOP || position === Pos.BOTTOM;
});
const anchor_combo = this._builder.get_object('panel_anchor_combo');
anchor_combo.remove_all();
if (allHorizontal) {
anchor_combo.append(Pos.START, _('Left'));
anchor_combo.append(Pos.MIDDLE, _('Center'));
anchor_combo.append(Pos.END, _('Right'));
} else if (allVertical) {
anchor_combo.append(Pos.START, _('Top'));
anchor_combo.append(Pos.MIDDLE, _('Middle'));
anchor_combo.append(Pos.END, _('Bottom'));
} else {
// Setting for a mix of horizontal and vertical panels on different monitors.
anchor_combo.append(Pos.START, _('Start'));
anchor_combo.append(Pos.MIDDLE, _('Middle'));
anchor_combo.append(Pos.END, _('End'));
}
// Set combo box after re-populating its options. But only if it's for a single-panel
// configuration, or a multi-panel configuration where they all have the same anchor
// setting. So don't set the combo box if there is a multi-panel configuration with
// different anchor settings.
const someAnchor = PanelSettings.getPanelAnchor(this._settings, currentMonitorIndex);
if (monitorsToSetFor.every(i =>
PanelSettings.getPanelAnchor(this._settings, i) === someAnchor)) {
const panel_anchor = PanelSettings.getPanelAnchor(this._settings, currentMonitorIndex);
this._builder.get_object('panel_anchor_combo').set_active_id(panel_anchor);
}
},
/**
* When a monitor is selected, update the widgets for panel position, size, anchoring,
* and contents so they accurately show the settings for the panel on that monitor.
*/
_updateWidgetSettingsForMonitor: function(monitorIndex) {
// Update display of panel screen position setting
this._maybeDisableTopPosition();
const panelPosition = this._getPanelPosition(monitorIndex);
this._setPositionRadios(panelPosition);
// Update display of thickness, length, and anchor settings
const panel_size_scale = this._builder.get_object('panel_size_scale');
const size = PanelSettings.getPanelSize(this._settings, monitorIndex);
panel_size_scale.set_value(size);
const panel_length_scale = this._builder.get_object('panel_length_scale');
const length = PanelSettings.getPanelLength(this._settings, monitorIndex);
panel_length_scale.set_value(length);
this._setAnchorWidgetSensitivity(length);
this._setAnchorLabels(monitorIndex);
// Update display of panel content settings
this._displayPanelPositionsForMonitor(monitorIndex);
},
/**
* Anchor is only relevant if panel length is less than 100%. Enable or disable
* anchor widget sensitivity accordingly.
*/
_setAnchorWidgetSensitivity: function(panelLength) {
const isPartialLength = panelLength < 100;
this._builder.get_object('panel_anchor_label').set_sensitive(isPartialLength);
this._builder.get_object('panel_anchor_combo').set_sensitive(isPartialLength);
},
_displayPanelPositionsForMonitor: function(monitorIndex) {
let taskbarListBox = this._builder.get_object('taskbar_display_listbox');
while(taskbarListBox.get_first_child())
{
taskbarListBox.remove(taskbarListBox.get_first_child());
}
let labels = {};
let panelPosition = this._getPanelPosition(monitorIndex);
let isVertical = panelPosition == Pos.LEFT || panelPosition == Pos.RIGHT;
let panelElementPositionsSettings = PanelSettings.getSettingsJson(this._settings, 'panel-element-positions');
let panelElementPositions = panelElementPositionsSettings[monitorIndex] || Pos.defaults;
let updateElementsSettings = () => {
let newPanelElementPositions = [];
let monitorSync = this._settings.get_boolean('panel-element-positions-monitors-sync');
let monitors = monitorSync ? this.monitors : [monitorIndex];
let child = taskbarListBox.get_first_child();
while (child != null)
{
newPanelElementPositions.push({
element: child.id,
visible: child.visibleToggleBtn.get_active(),
position: child.positionCombo.get_active_id()
});
child = child.get_next_sibling();
}
monitors.forEach(m => panelElementPositionsSettings[m] = newPanelElementPositions);
this._settings.set_string('panel-element-positions', JSON.stringify(panelElementPositionsSettings));
};
labels[Pos.SHOW_APPS_BTN] = _('Show Applications button');
labels[Pos.ACTIVITIES_BTN] = _('Activities button');
labels[Pos.TASKBAR] = _('Taskbar');
labels[Pos.DATE_MENU] = _('Date menu');
labels[Pos.SYSTEM_MENU] = _('System menu');
labels[Pos.LEFT_BOX] = _('Left box');
labels[Pos.CENTER_BOX] = _('Center box');
labels[Pos.RIGHT_BOX] = _('Right box');
labels[Pos.DESKTOP_BTN] = _('Desktop button');
panelElementPositions.forEach(el => {
let row = new Gtk.ListBoxRow();
let grid = new Gtk.Grid({ margin_start: 12, margin_end: 12, column_spacing: 8 });
let upDownGrid = new Gtk.Grid({ column_spacing: 2 });
let upBtn = new Gtk.Button({ tooltip_text: _('Move up') });
let upImg = new Gtk.Image({ icon_name: 'go-up-symbolic', pixel_size: 12 });
let downBtn = new Gtk.Button({ tooltip_text: _('Move down') });
let downImg = new Gtk.Image({ icon_name: 'go-down-symbolic', pixel_size: 12 });
let visibleToggleBtn = new Gtk.ToggleButton({ label: _('Visible'), active: el.visible });
let positionCombo = new Gtk.ComboBoxText({ tooltip_text: _('Select element position') });
let upDownClickHandler = limit => {
let index = row.get_index();
if (index != limit) {
taskbarListBox.remove(row);
taskbarListBox.insert(row, index + (!limit ? -1 : 1));
updateElementsSettings();
}
};
positionCombo.append(Pos.STACKED_TL, isVertical ? _('Stacked to top') : _('Stacked to left'));
positionCombo.append(Pos.STACKED_BR, isVertical ? _('Stacked to bottom') :_('Stacked to right'));
positionCombo.append(Pos.CENTERED, _('Centered'));
positionCombo.append(Pos.CENTERED_MONITOR, _('Monitor Center'));
positionCombo.set_active_id(el.position);
upBtn.connect('clicked', () => upDownClickHandler(0));
downBtn.connect('clicked', () => upDownClickHandler(panelElementPositions.length - 1));
visibleToggleBtn.connect('toggled', () => updateElementsSettings());
positionCombo.connect('changed', () => updateElementsSettings());
upBtn.set_child(upImg);
downBtn.set_child(downImg);
upDownGrid.attach(upBtn, 0, 0, 1, 1);
upDownGrid.attach(downBtn, 1, 0, 1, 1);
grid.attach(upDownGrid, 0, 0, 1, 1);
grid.attach(new Gtk.Label({ label: labels[el.element], xalign: 0, hexpand: true }), 1, 0, 1, 1);
if (Pos.optionDialogFunctions[el.element]) {
let cogImg = new Gtk.Image({ icon_name: 'emblem-system-symbolic' });
let optionsBtn = new Gtk.Button({ tooltip_text: _('More options') });
optionsBtn.get_style_context().add_class('circular');
optionsBtn.set_child(cogImg);
grid.attach(optionsBtn, 2, 0, 1, 1);
optionsBtn.connect('clicked', () => this[Pos.optionDialogFunctions[el.element]]());
}
grid.attach(visibleToggleBtn, 3, 0, 1, 1);
grid.attach(positionCombo, 4, 0, 1, 1);
row.id = el.element;
row.visibleToggleBtn = visibleToggleBtn;
row.positionCombo = positionCombo;
row.set_child(grid);
taskbarListBox.insert(row, -1);
});
},
_showShowAppsButtonOptions: function() {
let dialog = new Gtk.Dialog({ title: _('Show Applications options'),
transient_for: this.notebook.get_root(),
use_header_bar: true,
modal: true });
// GTK+ leaves positive values for application-defined response ids.
// Use +1 for the reset action
dialog.add_button(_('Reset to defaults'), 1);
let box = this._builder.get_object('show_applications_options');
dialog.get_content_area().append(box);
let fileChooserButton = this._builder.get_object('show_applications_icon_file_filebutton');
let fileChooser = new Gtk.FileChooserNative({ title: _('Open icon'), transient_for: dialog });
let fileImage = this._builder.get_object('show_applications_current_icon_image');
let fileFilter = new Gtk.FileFilter();
fileFilter.add_pixbuf_formats();
fileChooser.filter = fileFilter;
let handleIconChange = function(newIconPath) {
if (newIconPath && GLib.file_test(newIconPath, GLib.FileTest.EXISTS)) {
let file = Gio.File.new_for_path(newIconPath);
let pixbuf = GdkPixbuf.Pixbuf.new_from_stream_at_scale(file.read(null), 32, 32, true, null);
fileImage.set_from_pixbuf(pixbuf);
fileChooser.set_file(file);
fileChooserButton.set_label(newIconPath);
} else {
newIconPath = '';
fileImage.set_from_icon_name('view-app-grid-symbolic');
let picturesFolder = Gio.File.new_for_path(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES));
fileChooser.set_file(picturesFolder);
fileChooserButton.set_label("(None)");
}
this._settings.set_string('show-apps-icon-file', newIconPath || '');
};
fileChooserButton.connect('clicked', Lang.bind(this, function() {
fileChooser.show();
}));
fileChooser.connect('response', widget => handleIconChange.call(this, widget.get_file().get_path()));
handleIconChange.call(this, this._settings.get_string('show-apps-icon-file'));
dialog.connect('response', Lang.bind(this, function(dialog, id) {
if (id == 1) {
// restore default settings
this._settings.set_value('show-apps-icon-side-padding', this._settings.get_default_value('show-apps-icon-side-padding'));
this._builder.get_object('show_applications_side_padding_spinbutton').set_value(this._settings.get_int('show-apps-icon-side-padding'));
this._settings.set_value('show-apps-override-escape', this._settings.get_default_value('show-apps-override-escape'));
handleIconChange.call(this, null);
} else {
// remove the settings box so it doesn't get destroyed;
dialog.get_content_area().remove(box);
dialog.destroy();
}
return;
}));
dialog.show();
dialog.set_default_size(1, 1);
},
_showDesktopButtonOptions: function() {
let dialog = new Gtk.Dialog({ title: _('Show Desktop options'),
transient_for: this.notebook.get_root(),
use_header_bar: true,
modal: true });
// GTK+ leaves positive values for application-defined response ids.
// Use +1 for the reset action
dialog.add_button(_('Reset to defaults'), 1);
let box = this._builder.get_object('box_show_showdesktop_options');
dialog.get_content_area().append(box);
this._builder.get_object('show_showdesktop_width_spinbutton').set_value(this._settings.get_int('showdesktop-button-width'));
this._builder.get_object('show_showdesktop_width_spinbutton').connect('value-changed', Lang.bind (this, function(widget) {
this._settings.set_int('showdesktop-button-width', widget.get_value());
}));
this._builder.get_object('show_showdesktop_delay_spinbutton').set_value(this._settings.get_int('show-showdesktop-delay'));
this._builder.get_object('show_showdesktop_delay_spinbutton').connect('value-changed', Lang.bind (this, function(widget) {
this._settings.set_int('show-showdesktop-delay', widget.get_value());
}));
this._builder.get_object('show_showdesktop_time_spinbutton').set_value(this._settings.get_int('show-showdesktop-time'));
this._builder.get_object('show_showdesktop_time_spinbutton').connect('value-changed', Lang.bind (this, function(widget) {
this._settings.set_int('show-showdesktop-time', widget.get_value());
}));
dialog.connect('response', Lang.bind(this, function(dialog, id) {
if (id == 1) {
// restore default settings
this._settings.set_value('showdesktop-button-width', this._settings.get_default_value('showdesktop-button-width'));
this._builder.get_object('show_showdesktop_width_spinbutton').set_value(this._settings.get_int('showdesktop-button-width'));
this._settings.set_value('show-showdesktop-hover', this._settings.get_default_value('show-showdesktop-hover'));
this._settings.set_value('show-showdesktop-delay', this._settings.get_default_value('show-showdesktop-delay'));
this._builder.get_object('show_showdesktop_delay_spinbutton').set_value(this._settings.get_int('show-showdesktop-delay'));
this._settings.set_value('show-showdesktop-time', this._settings.get_default_value('show-showdesktop-time'));
this._builder.get_object('show_showdesktop_time_spinbutton').set_value(this._settings.get_int('show-showdesktop-time'));
} else {
// remove the settings box so it doesn't get destroyed;
dialog.get_content_area().remove(box);
dialog.destroy();
}
return;
}));
dialog.show();
dialog.set_default_size(1, 1);
},
_addFormatValueCallbacks: function() {
// position
this._builder.get_object('panel_size_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return value + ' px';
}));
// style
this._builder.get_object('appicon_margin_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return value + ' px';
}));
this._builder.get_object('appicon_padding_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return value + ' px';
}));
// fine-tune box1
this._builder.get_object('tray_size_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return value + ' px';
}));
this._builder.get_object('leftbox_size_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return value + ' px';
}));
// fine-tune box2
this._builder.get_object('tray_padding_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return value + ' px';
}));
this._builder.get_object('statusicon_padding_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return value + ' px';
}));
this._builder.get_object('leftbox_padding_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return value + ' px';
}));
// animate hovering app icons dialog
this._builder.get_object('animate_appicon_hover_options_duration_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return _("%d ms").format(value);
}));
this._builder.get_object('animate_appicon_hover_options_rotation_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return _("%d °").format(value);
}));
this._builder.get_object('animate_appicon_hover_options_travel_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return _("%d %%").format(value);
}));
this._builder.get_object('animate_appicon_hover_options_zoom_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return _("%d %%").format(value);
}));
this._builder.get_object('animate_appicon_hover_options_convexity_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return _("%.1f").format(value);
}));
this._builder.get_object('animate_appicon_hover_options_extent_scale')
.set_format_value_func(Lang.bind(this, function(scale, value) {
return Gettext.ngettext("%d icon", "%d icons", value).format(value);
}));
},
_bindSettings: function() {
// size options
let panel_size_scale = this._builder.get_object('panel_size_scale');
panel_size_scale.set_range(DEFAULT_PANEL_SIZES[DEFAULT_PANEL_SIZES.length - 1], DEFAULT_PANEL_SIZES[0]);
DEFAULT_PANEL_SIZES.slice(1, -1).forEach(function(val) {
panel_size_scale.add_mark(val, Gtk.PositionType.TOP, val.toString());
});
// Correct for rtl languages
if (this._rtl) {
// Flip value position: this is not done automatically
panel_size_scale.set_value_pos(Gtk.PositionType.LEFT);
// I suppose due to a bug, having a more than one mark and one above a value of 100
// makes the rendering of the marks wrong in rtl. This doesn't happen setting the scale as not flippable
// and then manually inverting it
panel_size_scale.set_flippable(false);
panel_size_scale.set_inverted(true);
}
// Dots Position option
let dotPosition = this._settings.get_string('dot-position');
switch (dotPosition) {
case 'BOTTOM':
this._builder.get_object('dots_bottom_button').set_active(true);
break;
case 'TOP':
this._builder.get_object('dots_top_button').set_active(true);
break;
case 'LEFT':
this._builder.get_object('dots_left_button').set_active(true);
break;
case 'RIGHT':
this._builder.get_object('dots_right_button').set_active(true);
break;
}
this._builder.get_object('dot_style_focused_combo').set_active_id(this._settings.get_string('dot-style-focused'));
this._builder.get_object('dot_style_focused_combo').connect('changed', Lang.bind (this, function(widget) {
this._settings.set_string('dot-style-focused', widget.get_active_id());
}));
this._builder.get_object('dot_style_unfocused_combo').set_active_id(this._settings.get_string('dot-style-unfocused'));
this._builder.get_object('dot_style_unfocused_combo').connect('changed', Lang.bind (this, function(widget) {
this._settings.set_string('dot-style-unfocused', widget.get_active_id());
}));
for (let i = 1; i <= MAX_WINDOW_INDICATOR; i++) {
let idx = i;
this._builder.get_object('dot_color_' + idx + '_colorbutton').connect('color-set', Lang.bind(this, function(button) {
let rgba = button.get_rgba();
let css = rgba.to_string();
let hexString = cssHexString(css);
this._settings.set_string('dot-color-' + idx, hexString);
}));
this._builder.get_object('dot_color_unfocused_' + idx + '_colorbutton').connect('color-set', Lang.bind(this, function(button) {
let rgba = button.get_rgba();
let css = rgba.to_string();
let hexString = cssHexString(css);
this._settings.set_string('dot-color-unfocused-' + idx, hexString);
}));
}
this._builder.get_object('dot_color_apply_all_button').connect('clicked', Lang.bind(this, function() {
for (let i = 2; i <= MAX_WINDOW_INDICATOR; i++) {
this._settings.set_value('dot-color-' + i, this._settings.get_value('dot-color-1'));
let rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('dot-color-' + i));
this._builder.get_object('dot_color_' + i + '_colorbutton').set_rgba(rgba);
}
}));
this._builder.get_object('dot_color_unfocused_apply_all_button').connect('clicked', Lang.bind(this, function() {
for (let i = 2; i <= MAX_WINDOW_INDICATOR; i++) {
this._settings.set_value('dot-color-unfocused-' + i, this._settings.get_value('dot-color-unfocused-1'));
let rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('dot-color-unfocused-' + i));
this._builder.get_object('dot_color_unfocused_' + i + '_colorbutton').set_rgba(rgba);
}
}));
this._builder.get_object('focus_highlight_color_colorbutton').connect('color-set', Lang.bind(this, function(button) {
let rgba = button.get_rgba();
let css = rgba.to_string();
let hexString = cssHexString(css);
this._settings.set_string('focus-highlight-color', hexString);
}));
this._builder.get_object('dot_style_options_button').connect('clicked', Lang.bind(this, function() {
let dialog = new Gtk.Dialog({ title: _('Running Indicator Options'),
transient_for: this.notebook.get_root(),
use_header_bar: true,
modal: true });
// GTK+ leaves positive values for application-defined response ids.
// Use +1 for the reset action
dialog.add_button(_('Reset to defaults'), 1);
let box = this._builder.get_object('box_dots_options');
dialog.get_content_area().append(box);
this._settings.bind('dot-color-dominant',
this._builder.get_object('dot_color_dominant_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('dot-color-override',
this._builder.get_object('dot_color_override_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
// when either becomes active, turn the other off
this._builder.get_object('dot_color_dominant_switch').connect('state-set', Lang.bind (this, function(widget) {
if (widget.get_active()) this._settings.set_boolean('dot-color-override', false);
}));
this._builder.get_object('dot_color_override_switch').connect('state-set', Lang.bind (this, function(widget) {
if (widget.get_active()) this._settings.set_boolean('dot-color-dominant', false);
}));
this._settings.bind('dot-color-unfocused-different',
this._builder.get_object('dot_color_unfocused_different_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('dot-color-override',
this._builder.get_object('grid_dot_color'),
'sensitive',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('dot-color-override',
this._builder.get_object('dot_color_unfocused_box'),
'sensitive',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('dot-color-unfocused-different',
this._builder.get_object('grid_dot_color_unfocused'),
'sensitive',
Gio.SettingsBindFlags.DEFAULT);
for (let i = 1; i <= MAX_WINDOW_INDICATOR; i++) {
let rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('dot-color-' + i));
this._builder.get_object('dot_color_' + i + '_colorbutton').set_rgba(rgba);
rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('dot-color-unfocused-' + i));
this._builder.get_object('dot_color_unfocused_' + i + '_colorbutton').set_rgba(rgba);
}
this._settings.bind('focus-highlight',
this._builder.get_object('focus_highlight_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('focus-highlight',
this._builder.get_object('grid_focus_highlight_options'),
'sensitive',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('focus-highlight-dominant',
this._builder.get_object('focus_highlight_dominant_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('focus-highlight-dominant',
this._builder.get_object('focus_highlight_color_label'),
'sensitive',
Gio.SettingsBindFlags.INVERT_BOOLEAN);
this._settings.bind('focus-highlight-dominant',
this._builder.get_object('focus_highlight_color_colorbutton'),
'sensitive',
Gio.SettingsBindFlags.INVERT_BOOLEAN);
(function() {
let rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('focus-highlight-color'));
this._builder.get_object('focus_highlight_color_colorbutton').set_rgba(rgba);
}).apply(this);
this._builder.get_object('focus_highlight_opacity_spinbutton').set_value(this._settings.get_int('focus-highlight-opacity'));
this._builder.get_object('focus_highlight_opacity_spinbutton').connect('value-changed', Lang.bind (this, function(widget) {
this._settings.set_int('focus-highlight-opacity', widget.get_value());
}));
this._builder.get_object('dot_size_spinbutton').set_value(this._settings.get_int('dot-size'));
this._builder.get_object('dot_size_spinbutton').connect('value-changed', Lang.bind (this, function(widget) {
this._settings.set_int('dot-size', widget.get_value());
}));
dialog.connect('response', Lang.bind(this, function(dialog, id) {
if (id == 1) {
// restore default settings
this._settings.set_value('dot-color-dominant', this._settings.get_default_value('dot-color-dominant'));
this._settings.set_value('dot-color-override', this._settings.get_default_value('dot-color-override'));
this._settings.set_value('dot-color-unfocused-different', this._settings.get_default_value('dot-color-unfocused-different'));
this._settings.set_value('focus-highlight-color', this._settings.get_default_value('focus-highlight-color'));
let rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('focus-highlight-color'));
this._builder.get_object('focus_highlight_color_colorbutton').set_rgba(rgba);
this._settings.set_value('focus-highlight-opacity', this._settings.get_default_value('focus-highlight-opacity'));
this._builder.get_object('focus_highlight_opacity_spinbutton').set_value(this._settings.get_int('focus-highlight-opacity'));
for (let i = 1; i <= MAX_WINDOW_INDICATOR; i++) {
this._settings.set_value('dot-color-' + i, this._settings.get_default_value('dot-color-' + i));
rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('dot-color-' + i));
this._builder.get_object('dot_color_' + i + '_colorbutton').set_rgba(rgba);
this._settings.set_value('dot-color-unfocused-' + i, this._settings.get_default_value('dot-color-unfocused-' + i));
rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('dot-color-unfocused-' + i));
this._builder.get_object('dot_color_unfocused_' + i + '_colorbutton').set_rgba(rgba);
}
this._settings.set_value('dot-size', this._settings.get_default_value('dot-size'));
this._builder.get_object('dot_size_spinbutton').set_value(this._settings.get_int('dot-size'));
this._settings.set_value('focus-highlight', this._settings.get_default_value('focus-highlight'));
this._settings.set_value('focus-highlight-dominant', this._settings.get_default_value('focus-highlight-dominant'));
} else {
// remove the settings box so it doesn't get destroyed;
dialog.get_content_area().remove(box);
dialog.destroy();
}
return;
}));
dialog.show();
dialog.set_default_size(1, 1);
}));
//multi-monitor
this.monitors = this._settings.get_value('available-monitors').deep_unpack();
let dtpPrimaryMonitorIndex = this.monitors.indexOf(this._settings.get_int('primary-monitor'));
if (dtpPrimaryMonitorIndex < 0) {
dtpPrimaryMonitorIndex = 0;
}
this._currentMonitorIndex = this.monitors[dtpPrimaryMonitorIndex];
this._settings.connect('changed::panel-positions', () => this._updateVerticalRelatedOptions());
this._updateVerticalRelatedOptions();
for (let i = 0; i < this.monitors.length; ++i) {
//the primary index is the first one in the "available-monitors" setting
let label = !i ? _('Primary monitor') : _('Monitor ') + (i + 1);
this._builder.get_object('multimon_primary_combo').append_text(label);
this._builder.get_object('taskbar_position_monitor_combo').append_text(label);
}
this._builder.get_object('multimon_primary_combo').set_active(dtpPrimaryMonitorIndex);
this._builder.get_object('taskbar_position_monitor_combo').set_active(dtpPrimaryMonitorIndex);
this._settings.bind('panel-element-positions-monitors-sync',
this._builder.get_object('taskbar_position_sync_button'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('panel-element-positions-monitors-sync',
this._builder.get_object('taskbar_position_monitor_combo'),
'sensitive',
Gio.SettingsBindFlags.INVERT_BOOLEAN);
this._settings.connect('changed::panel-element-positions-monitors-sync', () => {
this._maybeDisableTopPosition();
// The anchor combo box may has different labels for single- or all-monitor configuration.
this._setAnchorLabels(this._currentMonitorIndex);
});
this._builder.get_object('multimon_primary_combo').connect('changed', Lang.bind (this, function(widget) {
this._settings.set_int('primary-monitor', this.monitors[widget.get_active()]);
}));
this._builder.get_object('taskbar_position_monitor_combo').connect('changed', Lang.bind (this, function(widget) {
this._currentMonitorIndex = this.monitors[widget.get_active()];
this._updateWidgetSettingsForMonitor(this._currentMonitorIndex);
}));
this._settings.bind('multi-monitors',
this._builder.get_object('multimon_multi_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
if (this.monitors.length === 1) {
this._builder.get_object('multimon_multi_switch').set_sensitive(false);
}
const panel_length_scale = this._builder.get_object('panel_length_scale');
panel_length_scale.connect('value-changed', Lang.bind (this, function(widget) {
const value = widget.get_value();
const monitorSync = this._settings.get_boolean('panel-element-positions-monitors-sync');
const monitorsToSetFor = monitorSync ? this.monitors : [this._currentMonitorIndex];
monitorsToSetFor.forEach(monitorIndex => {
PanelSettings.setPanelLength(this._settings, monitorIndex, value);
});
this._setAnchorWidgetSensitivity(value);
}));
this._builder.get_object('panel_anchor_combo').connect('changed', Lang.bind (this, function(widget) {
const value = widget.get_active_id();
// Value can be null while anchor labels are being swapped out
if (value !== null) {
const monitorSync = this._settings.get_boolean('panel-element-positions-monitors-sync');
const monitorsToSetFor = monitorSync ? this.monitors : [this._currentMonitorIndex];
monitorsToSetFor.forEach(monitorIndex => {
PanelSettings.setPanelAnchor(this._settings, monitorIndex, value);
});
}
}));
this._updateWidgetSettingsForMonitor(this._currentMonitorIndex);
//dynamic opacity
this._settings.bind('trans-use-custom-bg',
this._builder.get_object('trans_bg_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('trans-use-custom-bg',
this._builder.get_object('trans_bg_color_colorbutton'),
'sensitive',
Gio.SettingsBindFlags.DEFAULT);
let rgba = new Gdk.RGBA();
rgba.parse(this._settings.get_string('trans-bg-color'));
this._builder.get_object('trans_bg_color_colorbutton').set_rgba(rgba);
this._builder.get_object('trans_bg_color_colorbutton').connect('color-set', Lang.bind(this, function (button) {
let rgba = button.get_rgba();
let css = rgba.to_string();
let hexString = cssHexString(css);
this._settings.set_string('trans-bg-color', hexString);
}));
this._settings.bind('trans-use-custom-opacity',
this._builder.get_object('trans_opacity_override_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('trans-use-custom-opacity',
this._builder.get_object('trans_opacity_box'),
'sensitive',
Gio.SettingsBindFlags.DEFAULT);
this._builder.get_object('trans_opacity_override_switch').connect('notify::active', (widget) => {
if (!widget.get_active())
this._builder.get_object('trans_dyn_switch').set_active(false);
});
this._builder.get_object('trans_opacity_spinbutton').set_value(this._settings.get_double('trans-panel-opacity') * 100);
this._builder.get_object('trans_opacity_spinbutton').connect('value-changed', Lang.bind(this, function (widget) {
this._settings.set_double('trans-panel-opacity', widget.get_value() * 0.01);
}));
this._settings.bind('trans-use-dynamic-opacity',
this._builder.get_object('trans_dyn_switch'),