-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
prefs.js
584 lines (506 loc) · 19.2 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
/*
This file is part of CoverflowAltTab.
CoverflowAltTab 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.
CoverflowAltTab 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 CoverflowAltTab. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* CoverflowAltTab
*
* Preferences dialog for "gnome-extensions prefs" tool
*
* Based on preferences in the following extensions: JustPerfection, dash2doc-lite, night theme switcher, and desktop cube
*
*/
const { Adw, Gdk, GLib, Gtk, Gio, GObject} = imports.gi;
const Config = imports.misc.config;
const Gettext = imports.gettext.domain('coverflow');
const _ = Gettext.gettext;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const UIFolderPath = Me.dir.get_child('ui').get_path();
const ExtensionImports = Me.imports;
const Lib = ExtensionImports.lib;
const SCHEMA = "org.gnome.shell.extensions.coverflowalttab";
const easing_options = [
{
id: 'ease-linear', name: 'easeLinear'
}, {
id: 'ease-in-quad', name: "easeInQuad"
}, {
id: 'ease-out-quad', name: "easeOutQuad"
}, {
id: 'ease-in-out-quad', name: "easeInOutQuad"
}, {
id: 'ease-in-cubic', name: "easeInCubic"
}, {
id: 'ease-out-cubic', name: "easeOutCubic"
}, {
id: 'ease-in-out-cubic', name: "easeInOutCubic"
}, {
id: 'ease-in-quart', name: "easeInQuart"
}, {
id: 'ease-out-quart', name: "easeOutQuart"
}, {
id: 'ease-in-out-quart', name: "easeInOutQuart"
}, {
id: 'ease-in-quint', name: "easeInQuint"
}, {
id: 'ease-out-quint', name: "easeOutQuint"
}, {
id: 'ease-in-out-quint', name: "easeInOutQuint"
}, {
id: 'ease-in-sine', name: "easeInSine"
}, {
id: 'ease-out-sine', name: "easeOutSine"
}, {
id: 'ease-in-out-sine', name: "easeInOutSine"
}, {
id: 'ease-in-expo', name: "easeInExpo"
}, {
id: 'ease-out-expo', name: "easeOutExpo"
}, {
id: 'ease-in-out-expo', name: "easeInOutExpo"
}, {
id: 'ease-in-circ', name: "easeInCirc"
}, {
id: 'ease-out-circ', name: "easeOutCirc"
}, {
id: 'ease-in-out-circ', name: "easeInOutCirc"
}, {
id: 'ease-in-back', name: "easeInBack"
}, {
id: 'ease-out-back', name: "easeOutBack"
}, {
id: 'ease-in-out-back', name: "easeInOutBack"
}, {
id: 'ease-in-elastic', name: "easeInElastic"
}, {
id: 'ease-out-elastic', name: "easeOutElastic"
}, {
id: 'ease-in-out-elastic', name: "easeInOutElastic"
}, {
id: 'ease-in-bounce', name: "easeInBounce"
}, {
id: 'ease-out-bounce', name: "easeOutBounce"
}, {
id: 'ease-in-out-bounce', name: "easeInOutBounce"
}, {
id: 'random', name: "Random"
}];
function init() {
let iconTheme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default());
iconTheme.add_search_path(`${UIFolderPath}/icons`);
Lib.initTranslations("coverflow");
}
function getBaseString(translatedString) {
switch (translatedString) {
case _("Coverflow"): return "Coverflow";
case _("Timeline"): return "Timeline";
case _("Bottom"): return "Bottom";
case _("Top"): return "Top";
case _("Classic"): return "Classic";
case _("Overlay"): return "Overlay";
default: return translatedString;
}
}
function makeResetButton() {
return new Gtk.Button({
icon_name: "edit-clear-symbolic",
tooltip_text: _("Reset to default value"),
valign: Gtk.Align.CENTER,
});
}
function getVersionString(_page) {
return _('Version %d').format(Me.metadata.version);
}
function fillPreferencesWindow(window) {
let settings = Lib.getSettings(SCHEMA);
let general_page = new Adw.PreferencesPage({
title: _('General'),
icon_name: 'general-symbolic',
});
let switcher_pref_group = new Adw.PreferencesGroup({
title: _('Switcher'),
});
switcher_pref_group.add(buildRadioAdw(settings, "switcher-style", new Map([ [_("Coverflow"), []], [_("Timeline"), []] ]), _("Style"), _("Pick the type of switcher.")))
switcher_pref_group.add(buildSpinAdw(settings, "offset", [-500, 500, 1, 10], _("Vertical Offset"), _("Positive value moves everything down, negative up.")));
switcher_pref_group.add(buildRadioAdw(settings, "position", new Map([ [_("Bottom"), []], [_("Top"), []]]), _("Window Title Position"), _("Place window title above or below the switcher.")));
switcher_pref_group.add(buildSwitcherAdw(settings, "enforce-primary-monitor", [], _("Enforce Primary Monitor"), _("Always show on the primary monitor, otherwise, show on the active monitor.")));
let switcher_looping_method_buttons = new Map([ [_("Flip Stack"), []], [_("Carousel"), []]]);
switcher_pref_group.add(buildRadioAdw(settings, "switcher-looping-method", switcher_looping_method_buttons, _("Looping Method"), _("How to cycle through windows.")));
switcher_pref_group.add(buildSwitcherAdw(settings, "hide-panel", [], _("Hide Panel"), _("Hide panel when switching windows.")));
let animation_pref_group = new Adw.PreferencesGroup({
title: _('Animation'),
});
animation_pref_group.add(buildDropDownAdw(settings, "easing-function", easing_options, "Easing Function", "Determine how windows move."));
animation_pref_group.add(buildRangeAdw(settings, "animation-time", [0.01, 20, 0.001, [0.5, 1, 1.5]], _("Duration [s]"), "", true));
animation_pref_group.add(buildSwitcherAdw(settings, "randomize-animation-times", [], _("Randomize Durations"), _("Each animation duration assigned randomly between 0 and configured duration.")));
let windows_pref_group = new Adw.PreferencesGroup({
title: _('Switcher Windows'),
});
options = [{
id: 'current', name: _("Current workspace only")
}, {
id: 'all', name: _("All workspaces")
}, {
id: 'all-currentfirst', name: _("All workspaces, current first")
}];
windows_pref_group.add(buildDropDownAdw(settings, "current-workspace-only", options, _("Workspaces"), _("Switch between windows on current or on all workspaces.")));
windows_pref_group.add(buildSwitcherAdw(settings, "switch-per-monitor", [], _("Current Monitor"), _("Switch between windows on current monitor.")));
let icon_pref_group = new Adw.PreferencesGroup({
title: _("Icon"),
});
let size_row = buildRangeAdw(settings, "overlay-icon-size", [0, 1024, 1, [32, 64, 128, 256, 512]], _("Overlay Icon Size"), _("Set the overlay icon size in pixels."), true);
let opacity_row = buildRangeAdw(settings, "overlay-icon-opacity", [0, 1, 0.001, [0.25, 0.5, 0.75]], _("Overlay Icon Opacity"), _("Set the overlay icon opacity."), true);
let buttons = new Map([ [_("Classic"), []], [_("Overlay"), [size_row, opacity_row]] ]);
icon_pref_group.add(buildRadioAdw(settings, "icon-style", buttons, _("Application Icon Style")));
icon_pref_group.add(size_row);
icon_pref_group.add(opacity_row);
icon_pref_group.add(buildSwitcherAdw(settings, "icon-has-shadow", [], _("Icon Shadow")));
let window_size_pref_group = new Adw.PreferencesGroup({
title: _("Windows")
});
window_size_pref_group.add(buildRangeAdw(settings, "preview-to-monitor-ratio", [0, 1, 0.001, [0.250, 0.500, 0.750]], _("Window Preview Size to Monitor Size Ratio"), _("Maximum ratio of window preview size to monitor size."), true));
window_size_pref_group.add(buildRangeAdw(settings, "preview-scaling-factor", [0, 1, 0.001, [0.250, 0.500, 0.800]], _("Off-center Size Factor"), _("Factor by which to successively shrink previews off to the side."), true));
let background_application_switcher_pref_group = new Adw.PreferencesGroup({
title: _('Application Switcher'),
});
background_application_switcher_pref_group.add(buildSwitcherAdw(settings, "switch-application-behaves-like-switch-windows", [], _("Make the Application Switcher Behave Like the Window Switcher"), _("Don't group windows of the same application in a subswitcher.")));
background_application_switcher_pref_group.add(buildRangeAdw(settings, "desaturate-factor", [0, 1, 0.001, [0.25, 0.5, 0.75]], _("Desaturate"), _("Larger means more desaturation."), true));
background_application_switcher_pref_group.add(buildSpinAdw(settings, "blur-sigma", [0, 20, 1, 1], _("Blur"), _("Larger means more blurry.")));
let color_row = new Adw.ActionRow({
title: _("Tint"),
subtitle: _("The opacity of the color controls how much it is blended. The theme color is blended at 0.75."),
});
background_application_switcher_pref_group.add(color_row);
let use_tint_switch = new Gtk.Switch({
valign: Gtk.Align.CENTER,
active: settings.get_boolean("use-tint"),
});
settings.bind("use-tint", use_tint_switch, "active", Gio.SettingsBindFlags.DEFAULT);
color_row.add_suffix(use_tint_switch);
let choose_tint_box = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
spacing: 10,
valign: Gtk.Align.CENTER,
});
color_row.add_suffix(choose_tint_box);
settings.bind("use-tint", choose_tint_box, "sensitive", Gio.SettingsBindFlags.GET);
let color_dialog = new Gtk.ColorDialog({
with_alpha: true,
});
let color_button = new Gtk.ColorDialogButton({
valign: Gtk.Align.CENTER,
dialog: color_dialog,
});
let use_theme_color_button = new Gtk.ToggleButton({
label: "Use Theme Color",
valign: Gtk.Align.CENTER,
});
use_theme_color_button.bind_property("active", color_button, "sensitive", GObject.BindingFlags.INVERT_BOOLEAN | GObject.BindingFlags.SYNC_CREATE);
settings.bind("use-theme-color-for-tint-color", use_theme_color_button, "active", Gio.SettingsBindFlags.DEFAULT);
choose_tint_box.append(use_theme_color_button);
choose_tint_box.append(color_button);
let c = settings.get_value("tint-color").deep_unpack();
let rgba = color_button.rgba;
rgba.red = c[0];
rgba.green = c[1];
rgba.blue = c[2];
rgba.alpha = c[3];
color_button.set_rgba(rgba);
color_button.connect('notify::rgba', _ => {
let c = color_button.rgba;
let val = new GLib.Variant("(dddd)", [c.red, c.green, c.blue, c.alpha]);
settings.set_value("tint-color", val);
});
color_row.set_activatable_widget(use_tint_switch);
reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset("use-tint");
settings.reset("use-theme-color-for-tint-color");
});
color_row.add_suffix(reset_button);
background_application_switcher_pref_group.add(buildSwitcherAdw(settings, "use-glitch-effect", [], _("Glitch")));
let background_pref_group = new Adw.PreferencesGroup({
title: _('Background'),
});
background_pref_group.add(buildRangeAdw(settings, "dim-factor", [0, 1, 0.001, [0.25, 0.5, 0.75]], _("Dim-factor"), _("Smaller means darker."), true));
let keybinding_pref_group = new Adw.PreferencesGroup({
title: _("Keybindings"),
});
keybinding_pref_group.add(buildSwitcherAdw(settings, "bind-to-switch-windows", [], _("Bind to 'switch-windows'")));
keybinding_pref_group.add(buildSwitcherAdw(settings, "bind-to-switch-applications", [background_application_switcher_pref_group], _("Bind to 'switch-applications'")));
let pcorrection_pref_group = new Adw.PreferencesGroup({
title: _("Perspective Correction")
})
pcorrection_pref_group.add(buildDropDownAdw(settings, "perspective-correction-method", [
{ id: "None", name:_("None") },
{ id: "Move Camera", name: _("Move Camera") },
{ id: "Adjust Angles", name: _("Adjust Angles")}],
_("Perspective Correction"), ("Method to make off-center switcher look centered.")));
let highlight_mouse_over_pref_group = new Adw.PreferencesGroup({
title: _("Highlight Window Under Mouse"),
});
window_size_pref_group.add(buildSwitcherAdw(settings, "highlight-mouse-over", [], _("Highlight Window Under Mouse"), _("Draw embelishment on window under the mouse to know the effects of clicking.")));
window_size_pref_group.add(buildSwitcherAdw(settings, "raise-mouse-over", [], _("Raise Window Under Mouse"), _("Raise the window under the mouse above all others.")));
/*let tweaks_page = new Adw.PreferencesPage({
title: _('Tweaks'),
icon_name: 'applications-symbolic',
});
tweaks_page.add(pcorrection_pref_group);
tweaks_page.add(highlight_mouse_over_pref_group);*/
general_page.add(switcher_pref_group);
general_page.add(animation_pref_group);
general_page.add(icon_pref_group);
general_page.add(windows_pref_group);
general_page.add(window_size_pref_group);
general_page.add(background_pref_group);
general_page.add(background_application_switcher_pref_group);
general_page.add(pcorrection_pref_group);
general_page.add(keybinding_pref_group);
let contribution_page = new Adw.PreferencesPage({
title: _("Contribute"),
icon_name: 'contribute-symbolic',
});
let contribute_icon_pref_group = new Adw.PreferencesGroup();
let icon_box = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
margin_top: 24,
margin_bottom: 24,
spacing: 18,
});
let icon_image = new Gtk.Image({
icon_name: "coverflow-symbolic",
pixel_size: 128,
});
let label_box = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 6,
});
let label = new Gtk.Label({
label: "Coverflow Alt-Tab",
wrap: true,
});
let context = label.get_style_context();
context.add_class("title-1");
let another_label = new Gtk.Label({
label: getVersionString(),
});
let links_pref_group = new Adw.PreferencesGroup();
let code_row = new Adw.ActionRow({
icon_name: "code-symbolic",
title: _("Code (create pull requests, report issues, etc.)")
});
let github_link = new Gtk.LinkButton({
label: "Github",
uri: "https://github.com/dmo60/CoverflowAltTab",
});
let donate_row = new Adw.ActionRow({
title: _("Support me with a Donation"),
icon_name: "support-symbolic",
})
let donate_link = new Gtk.LinkButton({
label: "Liberapay",
uri: "https://liberapay.com/dsheeler/donate",
});
code_row.add_suffix(github_link);
code_row.set_activatable_widget(github_link);
donate_row.add_suffix(donate_link);
donate_row.set_activatable_widget(donate_link);
links_pref_group.add(code_row);
links_pref_group.add(donate_row);
label_box.append(label);
label_box.append(another_label);
icon_box.append(icon_image);
icon_box.append(label_box);
contribute_icon_pref_group.add(icon_box);
contribution_page.add(contribute_icon_pref_group);
contribution_page.add(links_pref_group)
window.add(general_page);
// window.add(appearance_page);
window.add(contribution_page);
window.set_search_enabled(true);
}
function buildSwitcherAdw(settings, key, dependant_widgets, title, subtitle=null) {
let pref = new Adw.ActionRow({
title: title,
});
if (subtitle != null) {
pref.set_subtitle(subtitle);
}
let switcher = new Gtk.Switch({
valign: Gtk.Align.CENTER,
active: settings.get_boolean(key)
});
switcher.expand = false;
switcher.connect('notify::active', function(widget) {
settings.set_boolean(key, widget.active);
});
pref.set_activatable_widget(switcher);
pref.add_suffix(switcher);
switcher.connect('notify::active', function(widget) {
for (let dep of dependant_widgets) {
dep.set_sensitive(widget.get_active());
}
});
for (let widget of dependant_widgets) {
widget.set_sensitive(switcher.get_active());
}
reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
switcher.set_active(settings.get_boolean(key));
})
pref.add_suffix(reset_button);
return pref;
}
function buildRangeAdw(settings, key, values, title, subtitle="", draw_value=false) {
let [min, max, step, defvs] = values;
let pref = new Adw.ActionRow({
title: title, });
if (subtitle !== null && subtitle !== "") {
pref.set_subtitle(subtitle);
}
let range = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, min, max, step);
range.set_value(settings.get_double(key));
if (draw_value) {
range.set_draw_value(true);
range.set_value_pos(Gtk.PositionType.RIGHT)
}
for (let defv of defvs) {
range.add_mark(defv, Gtk.PositionType.BOTTOM, null);
}
range.set_size_request(200, -1);
range.connect('value-changed', function(slider) {
settings.set_double(key, slider.get_value());
});
pref.set_activatable_widget(range);
pref.add_suffix(range)
reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
range.set_value(settings.get_double(key));
});
pref.add_suffix(reset_button);
return pref;
}
function buildRadioAdw(settings, key, buttons, title, subtitle=null) {
let pref = new Adw.ActionRow({
title: title,
});
if (subtitle != null) {
pref.set_subtitle(subtitle);
}
let hbox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
spacing: 10,
valign: Gtk.Align.CENTER,
});
let radio = new Gtk.ToggleButton();
let radio_for_button = {};
for (let button_name of buttons.keys()) {
radio = new Gtk.ToggleButton({group: radio, label: button_name});
if (getBaseString(button_name) == settings.get_string(key)) {
radio.set_active(true);
}
radio_for_button[button_name] = radio;
radio.connect('toggled', function(widget) {
if (widget.get_active()) {
settings.set_string(key, getBaseString(widget.get_label()));
}
for (let pref_row of buttons.get(button_name)) {
pref_row.set_sensitive(widget.get_active());
}
});
for (let pref_row of buttons.get(button_name)) {
pref_row.set_sensitive(radio_for_button[button_name].get_active());
}
hbox.append(radio);
};
reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
for (let button of buttons.keys()) {
if (getBaseString(button) == settings.get_string(key)) {
radio_for_button[button].set_active(true);
}
}
});
pref.set_activatable_widget(hbox);
pref.add_suffix(hbox);
pref.add_suffix(reset_button);
return pref;
};
function buildSpinAdw(settings, key, values, title, subtitle=null) {
let [min, max, step, page] = values;
let pref = new Adw.ActionRow({
title: title,
});
if (subtitle != null) {
pref.set_subtitle(subtitle);
}
let spin = new Gtk.SpinButton({ valign: Gtk.Align.CENTER });
spin.set_range(min, max);
spin.set_increments(step, page);
spin.set_value(settings.get_int(key));
spin.connect('value-changed', function(widget) {
settings.set_int(key, widget.get_value());
});
pref.set_activatable_widget(spin);
pref.add_suffix(spin);
reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
spin.set_value(settings.get_int(key));
});
pref.add_suffix(reset_button);
return pref;
}
function buildDropDownAdw(settings, key, values, title, subtitle=null) {
let pref = new Adw.ActionRow({
title: title,
});
if (subtitle != null) {
pref.set_subtitle(subtitle);
}
let model = new Gtk.StringList();
let chosen_idx = 0;
for (let i = 0; i < values.length; i++) {
let item = values[i];
model.append(item.name);
if (item.id == settings.get_string(key)) {
chosen_idx = i;
}
}
let chooser = new Gtk.DropDown({
valign: Gtk.Align.CENTER,
model: model,
selected: chosen_idx,
});
chooser.connect('notify::selected-item', function(c) {
let idx = c.get_selected();
settings.set_string(key, values[idx].id);
});
pref.set_activatable_widget(chooser);
pref.add_suffix(chooser);
reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
for (let i = 0; i < values.length; i++) {
let item = values[i];
if (item.id == settings.get_string(key)) {
chooser.set_selected(i);
break;
}
}
});
pref.add_suffix(reset_button);
return pref;
}