-
Notifications
You must be signed in to change notification settings - Fork 1
/
prefs.js
120 lines (103 loc) · 4.09 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
/* prefs.js
*
* FancyTiling - GNOME extension
* Copyright (C) 2024 DevRoamer <[email protected]>
*
* 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 3 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 <https://www.gnu.org/licenses/>.
*/
import Adw from 'gi://Adw';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk';
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
export default class FtPreferences extends ExtensionPreferences {
constructor(metadata) {
super(metadata);
}
fillPreferencesWindow(window) {
this._settings = this.getSettings('org.gnome.shell.extensions.fancy-tiling');
let g = new GeneralPage(this._settings);
window.add(g);
window.set_visible_page(g);
window.set_size_request(-1, 600);
}
}
const GeneralPage = GObject.registerClass(
{
GTypeName: 'GeneralPage',
Template: GLib.uri_resolve_relative(import.meta.url, 'resources/ui/prefs-general.ui', GLib.UriFlags.NONE),
InternalChildren: [
'btnOverlayColor',
'opacity',
'highlightDistance',
'switchAnimations',
'dropDownDefaultLayout',
'layouts',
'btnOpenEditor',
],
},
class GeneralPage extends Adw.PreferencesPage {
constructor(settings) {
super({});
this._settings = settings;
// Zone
this._settings.bind('animate', this._switchAnimations, 'active', Gio.SettingsBindFlags.DEFAULT);
// Overlay
this._settings.bind('zone-snap', this._highlightDistance, 'value', Gio.SettingsBindFlags.DEFAULT);
this._bindColorWidget('overlay-color', this._btnOverlayColor);
this._settings.bind('overlay-opacity', this._opacity, 'value', Gio.SettingsBindFlags.DEFAULT);
// Layout
this._bindLayoutDropDown();
this._btnOpenEditor.connect('clicked', (_) => {
console.log('CLICKED');
Editor.showEditor();
});
}
_bindLayoutDropDown() {
let dropDown = this._dropDownDefaultLayout;
let defaultLayout = this._settings.get_string('default-layout');
let stringList = this._layouts;
let json = JSON.parse(this._settings.get_string('layouts'));
for (let name in json['layouts']) {
stringList.append(name);
if (name === defaultLayout) {
dropDown.selected = stringList.get_n_items() - 1;
}
}
dropDown.connect('notify::selected', (_) => {
let item = stringList.get_item(dropDown.selected);
if (!item) {
return;
}
this._settings.set_string('default-layout', item.get_string());
});
}
_bindColorWidget(settingsKey, widget) {
if (!(widget instanceof Gtk.ColorButton)) {
return;
}
widget.connect('color-set', (_) => {
let val = new GLib.Variant('(ddd)', [widget.rgba.red, widget.rgba.green, widget.rgba.blue]);
this._settings.set_value(settingsKey, val);
});
let rgb = widget.rgba;
let initColor = this._settings.get_value(settingsKey).deepUnpack();
rgb.red = initColor[0];
rgb.green = initColor[1];
rgb.blue = initColor[2];
widget.rgba = rgb;
}
}
);