-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathprefs.ts
More file actions
1434 lines (1318 loc) · 49 KB
/
prefs.ts
File metadata and controls
1434 lines (1318 loc) · 49 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
import { Gtk, Adw, Gio, GLib, Gdk, GObject } from '@gi.prefs';
import Settings, { ActivationKey } from './settings/settings';
import { logger } from './utils/logger';
import { ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import Layout from '@components/layout/Layout';
import SettingsExport from '@settings/settingsExport';
import { gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
// @ts-expect-error "Module exists"
import * as Config from 'resource:///org/gnome/Shell/Extensions/js/misc/config.js';
const debug = logger('prefs');
/**
* This function is called when the preferences window is first created to build
* and return a GTK4 widget. Prior to version 42, the prefs.js needed a
* buildPrefsWidget function, returning a GtkWidget to be inserted in the
* preferences dialog.
*
* The preferences window will be a `Adw.PreferencesWindow`, and the widget
* returned by this function will be added to an `Adw.PreferencesPage` or
* `Adw.PreferencesGroup` if necessary.
*
* @returns {Gtk.Widget} the preferences widget
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function buildPrefsWidget(): Gtk.Widget {
return new Gtk.Label({
label: 'Preferences',
});
}
export default class TilingShellExtensionPreferences extends ExtensionPreferences {
/**
* This function is called when the preferences window is first created to fill
* the `Adw.PreferencesWindow`.
*
* @param {Adw.PreferencesWindow} window - The preferences window
*/
fillPreferencesWindow(window: Adw.PreferencesWindow) {
Settings.initialize(this.getSettings());
const prefsPage = new Adw.PreferencesPage({
name: 'general',
title: _('General'),
iconName: 'dialog-information-symbolic',
});
window.add(prefsPage);
// Appearence section
const appearenceGroup = new Adw.PreferencesGroup({
title: _('Appearance'),
description: _('Configure the appearance of Tiling Shell'),
});
prefsPage.add(appearenceGroup);
const showIndicatorRow = this._buildSwitchRow(
Settings.KEY_SHOW_INDICATOR,
_('Show Indicator'),
_('Whether to show the panel indicator'),
);
appearenceGroup.add(showIndicatorRow);
const innerGapsRow = this._buildSpinButtonRow(
Settings.KEY_INNER_GAPS,
_('Inner gaps'),
_('Gaps between windows'),
);
appearenceGroup.add(innerGapsRow);
const outerGapsRow = this._buildSpinButtonRow(
Settings.KEY_OUTER_GAPS,
_('Outer gaps'),
_('Gaps between a window and the monitor borders'),
);
appearenceGroup.add(outerGapsRow);
const blurRow = new Adw.ExpanderRow({
title: _('Blur (experimental feature)'),
subtitle: _(
'Apply blur effect to Snap Assistant and tile previews',
),
});
appearenceGroup.add(blurRow);
const snapAssistantThresholdRow = this._buildSpinButtonRow(
Settings.KEY_SNAP_ASSISTANT_THRESHOLD,
_('Snap Assistant threshold'),
_(
'Minimum distance from the Snap Assistant to the pointer to open it',
),
0,
512,
);
appearenceGroup.add(snapAssistantThresholdRow);
blurRow.add_row(
this._buildSwitchRow(
Settings.KEY_ENABLE_BLUR_SNAP_ASSISTANT,
_('Snap Assistant'),
_('Apply blur effect to Snap Assistant'),
),
);
blurRow.add_row(
this._buildSwitchRow(
Settings.KEY_ENABLE_BLUR_SELECTED_TILEPREVIEW,
_('Selected tile preview'),
_('Apply blur effect to selected tile preview'),
),
);
const windowBorderRow = new Adw.ExpanderRow({
title: _('Window border'),
subtitle: _('Show a border around focused window'),
});
appearenceGroup.add(windowBorderRow);
windowBorderRow.add_row(
this._buildSwitchRow(
Settings.KEY_ENABLE_WINDOW_BORDER,
_('Enable'),
_('Show a border around focused window'),
),
);
windowBorderRow.add_row(
this._buildSwitchRow(
Settings.KEY_ENABLE_SMART_WINDOW_BORDER_RADIUS,
_('Smart border radius'),
_('Dynamically adapt to the window’s actual border radius'),
),
);
windowBorderRow.add_row(
this._buildSpinButtonRow(
Settings.KEY_WINDOW_BORDER_WIDTH,
_('Width'),
_('The size of the border'),
1,
),
);
windowBorderRow.add_row(
this._buildColorRow(
_('Border color'),
_('Choose the color of the border'),
this._getRGBAFromString(Settings.WINDOW_BORDER_COLOR),
(val: string) => (Settings.WINDOW_BORDER_COLOR = val),
),
);
const animationsRow = new Adw.ExpanderRow({
title: _('Animations'),
subtitle: _('Customize animations'),
});
appearenceGroup.add(animationsRow);
animationsRow.add_row(
this._buildSpinButtonRow(
Settings.KEY_SNAP_ASSISTANT_ANIMATION_TIME,
_('Snap assistant animation time'),
_('The snap assistant animation time in milliseconds'),
0,
2000,
),
);
animationsRow.add_row(
this._buildSpinButtonRow(
Settings.KEY_TILE_PREVIEW_ANIMATION_TIME,
_('Tiles animation time'),
_('The tiles animation time in milliseconds'),
0,
2000,
),
);
// Behaviour section
const behaviourGroup = new Adw.PreferencesGroup({
title: _('Behaviour'),
description: _('Configure the behaviour of Tiling Shell'),
});
prefsPage.add(behaviourGroup);
const snapAssistRow = this._buildSwitchRow(
Settings.KEY_SNAP_ASSIST,
_('Enable Snap Assistant'),
_('Move the window on top of the screen to snap assist it'),
);
behaviourGroup.add(snapAssistRow);
const enableTilingSystemRow = this._buildSwitchRow(
Settings.KEY_TILING_SYSTEM,
_('Enable Tiling System'),
_('Hold the activation key while moving a window to tile it'),
this._buildActivationKeysDropDown(
Settings.TILING_SYSTEM_ACTIVATION_KEY,
(val: ActivationKey) =>
(Settings.TILING_SYSTEM_ACTIVATION_KEY = val),
),
);
behaviourGroup.add(enableTilingSystemRow);
const tilingSystemDeactivationRow = this._buildDropDownRow(
_('Tiling System deactivation key'),
_(
'Hold the deactivation key while moving a window to deactivate the tiling system',
),
Settings.TILING_SYSTEM_DEACTIVATION_KEY,
(val: ActivationKey) =>
(Settings.TILING_SYSTEM_DEACTIVATION_KEY = val),
);
behaviourGroup.add(tilingSystemDeactivationRow);
const spanMultipleTilesRow = this._buildSwitchRow(
Settings.KEY_SPAN_MULTIPLE_TILES,
_('Span multiple tiles'),
_('Hold the activation key to span multiple tiles'),
this._buildActivationKeysDropDown(
Settings.SPAN_MULTIPLE_TILES_ACTIVATION_KEY,
(val: ActivationKey) =>
(Settings.SPAN_MULTIPLE_TILES_ACTIVATION_KEY = val),
),
);
behaviourGroup.add(spanMultipleTilesRow);
const autoTilingRow = this._buildSwitchRow(
Settings.KEY_ENABLE_AUTO_TILING,
_('Enable Auto Tiling'),
_('Automatically tile new windows to the best tile'),
);
behaviourGroup.add(autoTilingRow);
const resizeComplementingRow = this._buildSwitchRow(
Settings.KEY_RESIZE_COMPLEMENTING_WINDOWS,
_('Enable auto-resize of the complementing tiled windows'),
_(
'When a tiled window is resized, auto-resize the other tiled windows near it',
),
);
behaviourGroup.add(resizeComplementingRow);
const restoreToOriginalSizeRow = this._buildSwitchRow(
Settings.KEY_RESTORE_WINDOW_ORIGINAL_SIZE,
_('Restore window size'),
_(
'Whether to restore the windows to their original size when untiled',
),
);
behaviourGroup.add(restoreToOriginalSizeRow);
const overrideWindowMenuRow = this._buildSwitchRow(
Settings.KEY_OVERRIDE_WINDOW_MENU,
_('Add snap assistant and auto-tile buttons to window menu'),
_(
'Add snap assistant and auto-tile buttons in the menu that shows up when you right click on a window title',
),
);
behaviourGroup.add(overrideWindowMenuRow);
// Screen Edges section
const activeScreenEdgesGroup = new Adw.PreferencesGroup({
title: _('Screen Edges'),
description: _(
'Drag windows against the top, left and right screen edges to resize them',
),
headerSuffix: new Gtk.Switch({
vexpand: false,
valign: Gtk.Align.CENTER,
}),
});
Settings.bind(
Settings.KEY_ACTIVE_SCREEN_EDGES,
activeScreenEdgesGroup.headerSuffix,
'active',
);
const topEdgeMaximize = this._buildSwitchRow(
Settings.KEY_TOP_EDGE_MAXIMIZE,
_('Drag against top edge to maximize window'),
_('Drag windows against the top edge to maximize them'),
);
Settings.bind(
Settings.KEY_ACTIVE_SCREEN_EDGES,
topEdgeMaximize,
'sensitive',
);
activeScreenEdgesGroup.add(topEdgeMaximize);
const quarterTiling = this._buildScaleRow(
_('Quarter tiling activation area'),
_('Activation area to trigger quarter tiling (% of the screen)'),
(sc: Gtk.Scale) => {
Settings.QUARTER_TILING_THRESHOLD = sc.get_value();
},
Settings.QUARTER_TILING_THRESHOLD,
1,
50,
1,
);
Settings.bind(
Settings.KEY_ACTIVE_SCREEN_EDGES,
quarterTiling,
'sensitive',
);
activeScreenEdgesGroup.add(quarterTiling);
prefsPage.add(activeScreenEdgesGroup);
// Windows suggestions section
const windowsSuggestionsGroup = new Adw.PreferencesGroup({
title: _('Windows suggestions'),
description: _('Enable and disable windows suggestions'),
});
prefsPage.add(behaviourGroup);
const tilingSystemWindowSuggestionRow = this._buildSwitchRow(
Settings.KEY_ENABLE_TILING_SYSTEM_WINDOWS_SUGGESTIONS,
_('Enable window suggestions for the tiling system'),
_(
'Provides smart suggestions to fill empty tiles when using the tiling system',
),
);
windowsSuggestionsGroup.add(tilingSystemWindowSuggestionRow);
const snapAssistWindowSuggestionRow = this._buildSwitchRow(
Settings.KEY_ENABLE_SNAP_ASSISTANT_WINDOWS_SUGGESTIONS,
_('Enable window suggestions for the snap assistant'),
_(
'Offers suggestions to populate empty tiles when using the snap assistant',
),
);
windowsSuggestionsGroup.add(snapAssistWindowSuggestionRow);
const screenEdgesWindowSuggestionRow = this._buildSwitchRow(
Settings.KEY_ENABLE_SCREEN_EDGES_WINDOWS_SUGGESTIONS,
_('Enable window suggestions for screen edge snapping'),
_(
'Suggests windows to occupy empty tiles when snapping to screen edges',
),
);
windowsSuggestionsGroup.add(screenEdgesWindowSuggestionRow);
snapAssistWindowSuggestionRow.set_sensitive(false);
snapAssistWindowSuggestionRow.set_tooltip_text('To be released soon!');
prefsPage.add(windowsSuggestionsGroup);
// Layouts section
const layoutsGroup = new Adw.PreferencesGroup({
title: _('Layouts'),
description: _('Configure the layouts of Tiling Shell'),
});
prefsPage.add(layoutsGroup);
const editLayoutsBtn = this._buildButtonRow(
_('Edit layouts'),
_('Edit layouts'),
_('Open the layouts editor'),
() => this._openLayoutEditor(),
);
layoutsGroup.add(editLayoutsBtn);
const exportLayoutsBtn = this._buildButtonRow(
_('Export layouts'),
_('Export layouts'),
_('Export layouts to a file'),
() => {
const fc = this._buildFileChooserDialog(
_('Export layouts'),
Gtk.FileChooserAction.SAVE,
window,
_('Save'),
_('Cancel'),
new Gtk.FileFilter({
suffixes: ['json'],
name: 'JSON',
}),
(_source: Gtk.FileChooserNative, response_id: number) => {
try {
if (response_id === Gtk.ResponseType.ACCEPT) {
const file = _source.get_file();
if (!file) throw new Error('no file selected');
debug(
`Create file with path ${file.get_path()}`,
);
const content = JSON.stringify(
Settings.get_layouts_json(),
);
file.replace_contents_bytes_async(
new TextEncoder().encode(content),
null,
false,
Gio.FileCreateFlags.REPLACE_DESTINATION,
null,
(thisFile, res) => {
try {
thisFile?.replace_contents_finish(
res,
);
} catch (e) {
debug(e);
}
},
);
}
} catch (error: unknown) {
debug(error);
}
_source.destroy();
},
);
fc.set_current_name('tilingshell-layouts.json');
fc.show();
},
);
layoutsGroup.add(exportLayoutsBtn);
const importLayoutsBtn = this._buildButtonRow(
_('Import layouts'),
_('Import layouts'),
_('Import layouts from a file'),
() => {
const fc = this._buildFileChooserDialog(
_('Select layouts file'),
Gtk.FileChooserAction.OPEN,
window,
_('Open'),
_('Cancel'),
new Gtk.FileFilter({
suffixes: ['json'],
name: 'JSON',
}),
(_source: Gtk.FileChooserNative, response_id: number) => {
try {
if (response_id === Gtk.ResponseType.ACCEPT) {
const file = _source.get_file();
if (!file) {
_source.destroy();
return;
}
debug(`Selected path ${file.get_path()}`);
const [success, content] =
file.load_contents(null);
if (success) {
let importedLayouts = JSON.parse(
new TextDecoder('utf-8').decode(
content,
),
) as Layout[];
if (importedLayouts.length === 0) {
throw new Error(
'At least one layout is required',
);
}
importedLayouts = importedLayouts.filter(
(layout) => layout.tiles.length > 0,
);
const newLayouts =
Settings.get_layouts_json();
newLayouts.push(...importedLayouts);
Settings.save_layouts_json(newLayouts);
} else {
debug('Error while opening file');
}
}
} catch (error: unknown) {
debug(error);
}
_source.destroy();
},
);
fc.show();
},
);
layoutsGroup.add(importLayoutsBtn);
const resetBtn = this._buildButtonRow(
_('Reset layouts'),
_('Reset layouts'),
_('Bring back the default layouts'),
() => {
Settings.reset_layouts_json();
const layouts = Settings.get_layouts_json();
const newSelectedLayouts = Settings.get_selected_layouts().map(
(monitors_selected) =>
monitors_selected.map(() => layouts[0].id),
);
Settings.save_selected_layouts(newSelectedLayouts);
},
'destructive-action',
);
layoutsGroup.add(resetBtn);
// Keybindings section
const keybindingsGroup = new Adw.PreferencesGroup({
title: _('Keybindings'),
description: _(
'Use hotkeys to perform actions on the focused window',
),
headerSuffix: new Gtk.Switch({
vexpand: false,
valign: Gtk.Align.CENTER,
}),
});
Settings.bind(
Settings.KEY_ENABLE_MOVE_KEYBINDINGS,
keybindingsGroup.headerSuffix,
'active',
);
prefsPage.add(keybindingsGroup);
const gioSettings = this.getSettings();
const keybindings: [
string, // settings key
string, // title
string | undefined, // subtitle
boolean, // is set
boolean, // is on main page
][] = [
[
Settings.SETTING_MOVE_WINDOW_RIGHT, // settings key
_('Move window to right tile'), // title
_('Move the focused window to the tile on its right'), // subtitle
false, // is set
true, // is on main page
],
[
Settings.SETTING_MOVE_WINDOW_LEFT,
_('Move window to left tile'),
_('Move the focused window to the tile on its left'),
false,
true,
],
[
Settings.SETTING_MOVE_WINDOW_UP,
_('Move window to tile above'),
_('Move the focused window to the tile above'),
false,
true,
],
[
Settings.SETTING_MOVE_WINDOW_DOWN,
_('Move window to tile below'),
_('Move the focused window to the tile below'),
false,
true,
],
[
Settings.SETTING_SPAN_WINDOW_RIGHT,
_('Span window to right tile'),
_('Span the focused window to the tile on its right'),
false,
false,
],
[
Settings.SETTING_SPAN_WINDOW_LEFT,
_('Span window to left tile'),
_('Span the focused window to the tile on its left'),
false,
false,
],
[
Settings.SETTING_SPAN_WINDOW_UP,
_('Span window above'),
_('Span the focused window to the tile above'),
false,
false,
],
[
Settings.SETTING_SPAN_WINDOW_DOWN,
_('Span window down'),
_('Span the focused window to the tile below'),
false,
false,
],
[
Settings.SETTING_SPAN_WINDOW_ALL_TILES,
_('Span window to all tiles'),
_('Span the focused window to all the tiles'),
false,
false,
],
[
Settings.SETTING_UNTILE_WINDOW,
_('Untile focused window'),
undefined,
false,
false,
],
[
Settings.SETTING_MOVE_WINDOW_CENTER, // settings key
_('Move window to the center'), // title
_('Move the focused window to the center of the screen'), // subtitle
false, // is set
false, // is on main page
],
[
Settings.SETTING_FOCUS_WINDOW_RIGHT,
_('Focus window to the right'),
_(
'Focus the window to the right of the current focused window',
),
false,
false,
],
[
Settings.SETTING_FOCUS_WINDOW_LEFT,
_('Focus window to the left'),
_('Focus the window to the left of the current focused window'),
false,
false,
],
[
Settings.SETTING_FOCUS_WINDOW_UP,
_('Focus window above'),
_('Focus the window above the current focused window'),
false,
false,
],
[
Settings.SETTING_FOCUS_WINDOW_DOWN,
_('Focus window below'),
_('Focus the window below the current focused window'),
false,
false,
],
[
Settings.SETTING_FOCUS_WINDOW_NEXT,
_('Focus next window'),
_('Focus the window next to the current focused window'),
false,
false,
],
[
Settings.SETTING_FOCUS_WINDOW_PREV,
_('Focus previous window'),
_('Focus the window prior to the current focused window'),
false,
false,
],
];
// set if the keybinding was set or not by the user
for (let i = 0; i < keybindings.length; i++) {
keybindings[i][3] =
gioSettings.get_strv(keybindings[i][0])[0].length > 0;
}
// draw keybindings set or not optional
keybindings.forEach(
([settingsKey, title, subtitle, isSet, isOnMainPage]) => {
if (!isSet && !isOnMainPage) return;
const row = this._buildShortcutButtonRow(
settingsKey,
gioSettings,
title,
subtitle,
);
Settings.bind(
Settings.KEY_ENABLE_MOVE_KEYBINDINGS,
row,
'sensitive',
);
keybindingsGroup.add(row);
},
);
const openKeybindingsDialogRow = new Adw.ActionRow({
title: _('View and Customize all the Shortcuts'),
activatable: true,
});
openKeybindingsDialogRow.add_suffix(
new Gtk.Image({
icon_name: 'go-next-symbolic',
valign: Gtk.Align.CENTER,
}),
);
Settings.bind(
Settings.KEY_ENABLE_MOVE_KEYBINDINGS,
openKeybindingsDialogRow,
'sensitive',
);
keybindingsGroup.add(openKeybindingsDialogRow);
const keybindingsDialog = new Adw.PreferencesWindow({
searchEnabled: true,
modal: true,
hide_on_close: true,
transient_for: window,
width_request: 480,
height_request: 320,
});
openKeybindingsDialogRow.connect('activated', () =>
keybindingsDialog.present(),
);
const keybindingsPage = new Adw.PreferencesPage({
name: _('View and Customize Shortcuts'),
title: _('View and Customize Shortcuts'),
iconName: 'dialog-information-symbolic',
});
keybindingsDialog.add(keybindingsPage);
const keybindingsDialogGroup = new Adw.PreferencesGroup();
keybindingsPage.add(keybindingsDialogGroup);
// draw all the keybindings in the dialog
keybindings.forEach(([settingsKey, title, subtitle]) => {
const row = this._buildShortcutButtonRow(
settingsKey,
gioSettings,
title,
subtitle,
);
Settings.bind(
Settings.KEY_ENABLE_MOVE_KEYBINDINGS,
row,
'sensitive',
);
keybindingsDialogGroup.add(row);
});
const wrapAroundRow = this._buildSwitchRow(
Settings.KEY_WRAPAROUND_FOCUS,
_('Enable next/previous window focus to wrap around'),
_(
'When focusing next or previous window, wrap around at the window edge',
),
);
keybindingsGroup.add(wrapAroundRow);
// Import/export/reset section
const importExportGroup = new Adw.PreferencesGroup({
title: _('Import, export and reset'),
description: _(
'Import, export and reset the settings of Tiling Shell',
),
});
prefsPage.add(importExportGroup);
const exportSettingsBtn = this._buildButtonRow(
_('Export settings'),
_('Export settings'),
_('Export settings to a file'),
() => {
const fc = this._buildFileChooserDialog(
_('Export settings to a text file'),
Gtk.FileChooserAction.SAVE,
window,
_('Save'),
_('Cancel'),
new Gtk.FileFilter({
suffixes: ['txt'],
name: _('Text file'),
}),
(_source: Gtk.FileChooserNative, response_id: number) => {
try {
if (response_id === Gtk.ResponseType.ACCEPT) {
const file = _source.get_file();
if (!file) throw new Error('no file selected');
debug(
`Create file with path ${file.get_path()}`,
);
const settingsExport = new SettingsExport(
this.getSettings(),
);
const content = settingsExport.exportToString();
file.replace_contents_bytes_async(
new TextEncoder().encode(content),
null,
false,
Gio.FileCreateFlags.REPLACE_DESTINATION,
null,
(thisFile, res) => {
try {
thisFile?.replace_contents_finish(
res,
);
} catch (e) {
debug(e);
}
},
);
}
} catch (error: unknown) {
debug(error);
}
_source.destroy();
},
);
fc.set_current_name('tilingshell-settings.txt');
fc.show();
},
);
importExportGroup.add(exportSettingsBtn);
const importSettingsBtn = this._buildButtonRow(
_('Import settings'),
_('Import settings'),
_('Import settings from a file'),
() => {
const fc = this._buildFileChooserDialog(
_('Select a text file to import from'),
Gtk.FileChooserAction.OPEN,
window,
_('Open'),
_('Cancel'),
new Gtk.FileFilter({
suffixes: ['txt'],
name: 'Text file',
}),
(_source: Gtk.FileChooserNative, response_id: number) => {
try {
if (response_id === Gtk.ResponseType.ACCEPT) {
const file = _source.get_file();
if (!file) {
_source.destroy();
return;
}
debug(`Selected path ${file.get_path()}`);
const [success, content] =
file.load_contents(null);
if (success) {
const imported = new TextDecoder(
'utf-8',
).decode(content);
const settingsExport = new SettingsExport(
this.getSettings(),
);
settingsExport.importFromString(imported);
} else {
debug('Error while opening file');
}
}
} catch (error: unknown) {
debug(error);
}
_source.destroy();
},
);
fc.show();
},
);
importExportGroup.add(importSettingsBtn);
const resetSettingsBtn = this._buildButtonRow(
_('Reset settings'),
_('Reset settings'),
_('Bring back the default settings'),
() => new SettingsExport(this.getSettings()).restoreToDefault(),
'destructive-action',
);
importExportGroup.add(resetSettingsBtn);
// footer
const footerGroup = new Adw.PreferencesGroup();
prefsPage.add(footerGroup);
const buttons = new Gtk.Box({
hexpand: false,
spacing: 8,
margin_bottom: 16,
halign: Gtk.Align.CENTER,
});
buttons.append(
this._buildLinkButton(
`♥︎ ${_('Donate on ko-fi')}`,
'https://ko-fi.com/domferr',
),
);
buttons.append(
this._buildLinkButton(
_('Report a bug'),
'https://github.com/domferr/tilingshell/issues/new?template=bug_report.md',
),
);
buttons.append(
this._buildLinkButton(
_('Request a feature'),
'https://github.com/domferr/tilingshell/issues/new?template=feature_request.md',
),
);
footerGroup.add(buttons);
footerGroup.add(
new Gtk.Label({
label: _(
'Have issues, you want to suggest a new feature or contribute?',
),
margin_bottom: 4,
}),
);
footerGroup.add(
new Gtk.Label({
label: `${_('Open a new issue on')} <a href="https://github.com/domferr/tilingshell">GitHub</a>!`,
useMarkup: true,
margin_bottom: 32,
}),
);
if (this.metadata['version-name']) {
footerGroup.add(
new Gtk.Label({
label: `· Tiling Shell v${this.metadata['version-name']} ·`,
}),
);
}
window.searchEnabled = true;
window.connect('close-request', () => {
Settings.destroy();
});
}
_buildSwitchRow(
settingsKey: string,
title: string,
subtitle: string,
suffix?: Gtk.Widget,
): Adw.ActionRow {
const gtkSwitch = new Gtk.Switch({
vexpand: false,
valign: Gtk.Align.CENTER,
});
const adwRow = new Adw.ActionRow({
title,
subtitle,
activatableWidget: gtkSwitch,
});
if (suffix) adwRow.add_suffix(suffix);
adwRow.add_suffix(gtkSwitch);
Settings.bind(settingsKey, gtkSwitch, 'active');
return adwRow;
}
_buildDropDownRow(
title: string,
subtitle: string,
initialValue: ActivationKey,
onChange: (_: ActivationKey) => void,
styleClass?: string,
): Adw.ActionRow {
const dropDown = this._buildActivationKeysDropDown(
initialValue,
onChange,
styleClass,
);
dropDown.set_vexpand(false);
dropDown.set_valign(Gtk.Align.CENTER);
const adwRow = new Adw.ActionRow({
title,
subtitle,
activatableWidget: dropDown,
});
adwRow.add_suffix(dropDown);
return adwRow;
}
_buildSpinButtonRow(
settingsKey: string,
title: string,
subtitle: string,
min = 0,
max = 32,
) {
const spinBtn = Gtk.SpinButton.new_with_range(min, max, 1);
spinBtn.set_vexpand(false);
spinBtn.set_valign(Gtk.Align.CENTER);
const adwRow = new Adw.ActionRow({
title,
subtitle,
activatableWidget: spinBtn,
});
adwRow.add_suffix(spinBtn);
Settings.bind(settingsKey, spinBtn, 'value');
return adwRow;
}
_buildButtonRow(
label: string,
title: string,
subtitle: string,
onClick: () => void,
styleClass?: string,
) {
const btn = Gtk.Button.new_with_label(label);
if (styleClass) btn.add_css_class(styleClass);
btn.connect('clicked', onClick);
btn.set_vexpand(false);
btn.set_valign(Gtk.Align.CENTER);
const adwRow = new Adw.ActionRow({
title,
subtitle,