forked from material-shell/material-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefs.js
410 lines (367 loc) · 12.3 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
const { GObject, Gtk, Gdk, Gio, GLib } = imports.gi;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const { getSettings } = Me.imports.utils.settings;
// eslint-disable-next-line no-unused-vars
function init() {}
const makePage = (title, content) => {
const tabWindow = new Gtk.ScrolledWindow({ vexpand: true });
tabWindow.add(content);
const tabLabel = new Gtk.Label({
label: title,
halign: Gtk.Align.START,
use_markup: false
});
return [tabWindow, tabLabel];
};
const makeItemRow = (name, description, item) => {
const nameLabel = new Gtk.Label({ xalign: 0 });
nameLabel.set_markup(`<span size="medium">${name}</span>`);
const descriptionLabel = new Gtk.Label({ xalign: 0 });
descriptionLabel.set_markup(`<span size="small">${description}</span>`);
const labelsVBox = new Gtk.VBox();
labelsVBox.pack_start(nameLabel, false, false, 0);
labelsVBox.pack_start(descriptionLabel, false, false, 0);
const rowHBox = new Gtk.HBox();
rowHBox.pack_start(labelsVBox, true, true, 10);
rowHBox.pack_start(item, false, false, 0);
const listRow = new Gtk.ListBoxRow();
listRow.add(rowHBox);
return listRow;
};
const makeItemList = rows => {
const listBox = new Gtk.ListBox({
valign: Gtk.Align.START
});
const listWrapper = new Gtk.VBox({
border_width: 10
});
rows.forEach(row => listBox.add(row));
listWrapper.add(listBox);
return listWrapper;
};
const hotKeysLabels = {
'previous-window': 'Focus the previous window',
'next-window': 'Focus the next window',
'previous-workspace': 'Focus the previous workspace',
'next-workspace': 'Focus the next workspace',
'kill-focused-window': 'Kill the current window',
'move-window-left': 'Move the current window to the left',
'move-window-right': 'Move the current window to the right',
'move-window-top': 'Move the current window to upper workspace',
'move-window-bottom': 'Move the current window to lower workspace',
'cycle-tiling-layout':
'Cycle around the tiling layout on the current workspace',
'reverse-cycle-tiling-layout':
'Cycle around in reverse order the tiling layout on the current workspace',
'toggle-material-shell-ui':
'Toggle the material-shell UI to simulate fullscreen'
};
const layouts = {
maximize: 'Maximize all windows',
split: 'Put all windows side by side, two at a time',
float: 'Windows are not tiled',
half: 'Tile windows according to screen ratio',
'half-horizontal': 'Tile windows horizontally',
'half-vertical': 'Tile windows vertically',
ratio: 'Tile windows according to the ratio of remaining space',
grid: 'Tile windows according to a regular grid',
simple: 'Split screen unidirectionally according to screen ratio',
'simple-horizontal': 'Split screen horizontally',
'simple-vertical': 'Split screen vertically'
};
// eslint-disable-next-line no-unused-vars
function buildPrefsWidget() {
const notebook = new Gtk.Notebook();
GlobalSettingsTab(notebook);
accelTab(notebook);
layoutsTab(notebook);
layoutsSettingsTab(notebook);
let mainVBox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL
});
mainVBox.pack_start(notebook, true, true, 0);
mainVBox.show_all();
return mainVBox;
}
function accelTab(notebook) {
const settings = getSettings('bindings');
const model = new Gtk.ListStore();
model.set_column_types([
GObject.TYPE_STRING,
GObject.TYPE_STRING,
GObject.TYPE_INT,
GObject.TYPE_INT
]);
Object.entries(hotKeysLabels).forEach(([key, label]) => {
const [accelKey, mods] = Gtk.accelerator_parse(
settings.get_strv(key)[0]
);
const row = model.insert(55);
model.set(row, [0, 1, 2, 3], [key, label, mods, accelKey]);
});
const cellTextRenderer = new Gtk.CellRendererText();
const actionColumn = new Gtk.TreeViewColumn({
title: 'Action',
expand: true
});
actionColumn.pack_start(cellTextRenderer, true);
actionColumn.add_attribute(cellTextRenderer, 'text', 1);
const cellAccelRenderer = new Gtk.CellRendererAccel({
editable: true,
'accel-mode': Gtk.CellRendererAccelMode.GTK
});
cellAccelRenderer.connect('accel-cleared', (rend, strIter) => {
const [success, iter] = model.get_iter_from_string(strIter);
if (!success) {
throw new Error('Something be broken, yo.');
}
const name = model.get_value(iter, 0);
model.set(iter, [3], [0]);
settings.set_strv(name, ['']);
});
cellAccelRenderer.connect('accel-edited', (rend, strIter, key, mods) => {
const value = Gtk.accelerator_name(key, mods);
const [success, iter] = model.get_iter_from_string(strIter);
if (!success) {
throw new Error('Something be broken, yo.');
}
const name = model.get_value(iter, 0);
model.set(iter, [2, 3], [mods, key]);
settings.set_strv(name, [value]);
});
const hotkeyColumn = new Gtk.TreeViewColumn({
title: 'hotkeys'
});
hotkeyColumn.pack_end(cellAccelRenderer, false);
hotkeyColumn.add_attribute(cellAccelRenderer, 'accel-mods', 2);
hotkeyColumn.add_attribute(cellAccelRenderer, 'accel-key', 3);
const treeview = new Gtk.TreeView({
expand: true,
model: model
});
treeview.append_column(actionColumn);
treeview.append_column(hotkeyColumn);
const accelGrid = new Gtk.Grid({
column_spacing: 10,
margin: 24,
orientation: Gtk.Orientation.VERTICAL,
row_spacing: 10
});
accelGrid.add(
new Gtk.Label({
label: 'Keyboard shortcuts.',
halign: Gtk.Align.START,
justify: Gtk.Justification.LEFT,
use_markup: false,
wrap: true
})
);
accelGrid.add(treeview);
notebook.append_page(...makePage('Shortcuts', accelGrid));
}
function layoutsTab(notebook) {
const settings = getSettings('layouts');
const layoutItemCreator = (rows, [layout, description]) => {
const name = layout
.replace('-', ' ')
.replace(/^\w/g, c => c.toUpperCase());
const item = new Gtk.Switch({ valign: Gtk.Align.CENTER });
settings.bind(layout, item, 'active', Gio.SettingsBindFlags.DEFAULT);
rows.push(makeItemRow(name, description, item));
if (layout === 'ratio') {
const ratio = Gtk.SpinButton.new_with_range(0, 1, 0.01);
settings.bind(
'ratio-value',
ratio.get_adjustment(),
'value',
Gio.SettingsBindFlags.DEFAULT
);
rows.push(
makeItemRow(
'Ratio value',
'Ratio between frame and available space.',
ratio
)
);
}
return rows;
};
notebook.append_page(
...makePage(
'Layouts',
makeItemList(Object.entries(layouts).reduce(layoutItemCreator, []))
)
);
}
function layoutsSettingsTab(notebook) {
const settings = getSettings('layouts');
const itemRows = [];
const gap = Gtk.SpinButton.new_with_range(0, 1000, 1);
settings.bind(
'gap',
gap.get_adjustment(),
'value',
Gio.SettingsBindFlags.DEFAULT
);
itemRows.push(
makeItemRow(
'Gap size',
'Determines the gap size in pixel between windows.',
gap
)
);
const useScreenGap = new Gtk.Switch({ valign: Gtk.Align.CENTER });
itemRows.push(
makeItemRow(
'Use a different gap size for screen',
'Determines whether to use a different screen gap config.',
useScreenGap
)
);
settings.bind(
'use-screen-gap',
useScreenGap,
'active',
Gio.SettingsBindFlags.DEFAULT
);
const screenGap = Gtk.SpinButton.new_with_range(0, 1000, 1);
settings.bind(
'screen-gap',
screenGap.get_adjustment(),
'value',
Gio.SettingsBindFlags.DEFAULT
);
settings.bind(
'use-screen-gap',
screenGap,
'sensitive',
Gio.SettingsBindFlags.DEFAULT
);
itemRows.push(
makeItemRow(
'Screen edge gap size',
'Determines the screen edge gap size in pixel between windows.',
screenGap
)
);
const tweentime = Gtk.SpinButton.new_with_range(0, 1, 0.01);
settings.bind(
'tween-time',
tweentime.get_adjustment(),
'value',
Gio.SettingsBindFlags.DEFAULT
);
itemRows.push(
makeItemRow(
'Animation duration',
'Ajust duration (in seconds) of window move/resize animation.',
tweentime
)
);
notebook.append_page(
...makePage('Tiling settings', makeItemList(itemRows))
);
}
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 GlobalSettingsTab(notebook) {
const settings = getSettings('theme');
const itemRows = [];
const darkMode = new Gtk.Switch({ valign: Gtk.Align.CENTER });
let model = new Gtk.ListStore();
model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING]);
let cbox = new Gtk.ComboBox({ model: model });
let renderer = new Gtk.CellRendererText();
cbox.pack_start(renderer, true);
cbox.add_attribute(renderer, 'text', 1);
model.set(model.append(), [0, 1], ['dark', 'Dark']);
model.set(model.append(), [0, 1], ['light', 'Light']);
model.set(model.append(), [0, 1], ['primary', 'Primary']);
let shit = ['dark', 'light', 'primary'];
log('toto');
log(settings.get_string('theme'));
cbox.set_active(shit.indexOf(settings.get_string('theme'))); // set value
cbox.connect('changed', entry => {
let [success, iter] = cbox.get_active_iter();
if (!success) return;
let themeValue = model.get_value(iter, 0); // get value
settings.set_string('theme', themeValue);
});
itemRows.push(
makeItemRow(
'Theme',
'Determines the active theme for Material Shell',
cbox
)
);
const primaryColor = new Gtk.ColorButton();
let rgba = new Gdk.RGBA();
rgba.parse(settings.get_string('primary-color'));
primaryColor.set_rgba(rgba);
itemRows.push(
makeItemRow(
'Primary color',
'A color that stylizes the majority of the UI',
primaryColor
)
);
primaryColor.connect('notify::color', button => {
let rgba = button.get_rgba();
let css = rgba.to_string();
let hexString = cssHexString(css);
settings.set_string('primary-color', hexString);
});
const doDialogBackdrop = new Gtk.Switch({ valign: Gtk.Align.CENTER });
itemRows.push(
makeItemRow(
'Show dialog backdrop',
'Shows a semi-transparent overlay over other windows when a dialog is open.',
doDialogBackdrop
)
);
settings.bind(
'do-dialog-backdrop',
doDialogBackdrop,
'active',
Gio.SettingsBindFlags.DEFAULT
);
const showSettingsButtonOnLeftPanel = new Gtk.Switch({ valign: Gtk.Align.CENTER });
itemRows.push(
makeItemRow(
'Show settings button on left panel',
'Shows a quick shortcut to the Settings dialog in the left panel.',
showSettingsButtonOnLeftPanel
)
);
settings.bind(
'show-settings-button-on-panel',
showSettingsButtonOnLeftPanel,
'active',
Gio.SettingsBindFlags.DEFAULT
);
notebook.append_page(
...makePage('Global settings', makeItemList(itemRows))
);
}