Repository navigation
Expand file tree
/
Copy pathprefs.js
More file actions
81 lines (65 loc) · 2.77 KB
/
Copy pathprefs.js
File metadata and controls
81 lines (65 loc) · 2.77 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
// SPDX-License-Identifier: GPL-2.0-or-later
import Adw from 'gi://Adw';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';
import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
export default class TrayletPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
const settings = this.getSettings();
const page = new Adw.PreferencesPage();
const group = new Adw.PreferencesGroup({title: 'Icons'});
page.add(group);
group.add(spinRow(settings, 'icon-size', 'Icon size',
'Logical pixels', 8, 96, 2, 0));
group.add(spinRow(settings, 'icon-spacing', 'Spacing',
'Gap between icons', 0, 24, 1, 0));
group.add(spinRow(settings, 'icon-opacity', 'Opacity',
'When not hovered', 0, 255, 5, 0));
group.add(spinRow(settings, 'icon-saturation', 'Desaturation',
'0 keeps colors, 1 is grayscale', 0, 1, 0.05, 2));
group.add(spinRow(settings, 'icon-brightness', 'Brightness',
null, -1, 1, 0.05, 2));
group.add(spinRow(settings, 'icon-contrast', 'Contrast',
null, -1, 1, 0.05, 2));
page.add(ramGroup(settings));
window.add(page);
}
}
const RAM_FORMATS = ['percent', 'used', 'used-total'];
function ramGroup(settings) {
const group = new Adw.PreferencesGroup({title: 'Memory'});
const enableRow = new Adw.SwitchRow({
title: 'Show RAM usage',
subtitle: 'Readout left of the tray icons',
});
settings.bind('ram-enabled', enableRow, 'active',
Gio.SettingsBindFlags.DEFAULT);
group.add(enableRow);
const intervalRow = spinRow(settings, 'ram-refresh-interval',
'Refresh interval', 'Seconds', 1, 60, 1, 0);
group.add(intervalRow);
const spacingRow = spinRow(settings, 'ram-spacing',
'Gap to icons', 'Pixels', 0, 32, 1, 0);
group.add(spacingRow);
const formatRow = new Adw.ComboRow({
title: 'Format',
model: Gtk.StringList.new(['Percent', 'Used', 'Used / total']),
});
formatRow.selected =
Math.max(0, RAM_FORMATS.indexOf(settings.get_string('ram-format')));
formatRow.connect('notify::selected', () =>
settings.set_string('ram-format', RAM_FORMATS[formatRow.selected]));
group.add(formatRow);
for (const row of [intervalRow, spacingRow, formatRow])
settings.bind('ram-enabled', row, 'sensitive', Gio.SettingsBindFlags.GET);
return group;
}
function spinRow(settings, key, title, subtitle, min, max, step, digits) {
const row = Adw.SpinRow.new_with_range(min, max, step);
row.title = title;
row.digits = digits;
if (subtitle)
row.subtitle = subtitle;
settings.bind(key, row, 'value', Gio.SettingsBindFlags.DEFAULT);
return row;
}