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
|
import Adw from 'gi://Adw';
import GObject from "gi://GObject";
import Gio from "gi://Gio";
import Gtk from "gi://Gtk";
import Gdk from "gi://Gdk";
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
class PrefsWidget {
constructor(schema) {
this._updating = false;
this._buildable = new Gtk.Builder();
this._buildable.add_from_file(
Gio.File.new_for_uri(import.meta.url).get_parent().get_path() + '/settings.ui'
);
let prefsWidget = this._getWidget('prefs_widget');
if (!prefsWidget) {
console.error('UnityLikeAppSwitcher: Main widget not found');
}
this._settings = schema;
this._bindBooleans();
this._bindNumbers();
this._bindStrings();
let resetButton = this._getWidget('reset_button');
if (resetButton) {
resetButton.connect('clicked', () => {
this._resetAll();
});
}
this._settings.connect(
'changed::first-change-window',
this._firstChangeWindowChanged.bind(this)
);
this._firstChangeWindowChanged();
}
_resetAll() {
this._updating = true;
try {
this._getNumbers().forEach(setting => {
this._settings.reset(setting);
// Trigger UI update manually for numbers since they use manual binding
this._updateNumberWidget(setting);
});
this._getBooleans().forEach(setting => {
this._settings.reset(setting);
});
this._getStrings().forEach(setting => {
this._settings.reset(setting);
this._updateStringWidget(setting);
});
Gio.Settings.sync();
} finally {
this._updating = false;
}
}
_updateNumberWidget(setting) {
if (this._updating) return;
let widget = this._getWidget(setting);
if (!widget || !widget.set_value) {
return;
}
if (!this._settings.list_keys().includes(setting)) {
// Fallback values if key is missing
let defaultValues = {
'hover-shade-level': 0.2,
'hover-opacity': 0.8,
'hover-border-width': 2,
'hover-glow-size': 15,
'icon-spacing': 10,
'container-padding': 24,
'border-size': 2,
'background-border-radius': 24,
'icon-border-radius': 16
};
widget.set_value(defaultValues[setting] || 0);
return;
}
let isDouble = (setting === 'hover-shade-level' || setting === 'hover-opacity');
if (isDouble) {
widget.set_value(this._settings.get_double(setting));
} else {
widget.set_value(this._settings.get_int(setting));
}
}
_updateStringWidget(setting) {
if (this._updating) return;
let widget = this._getWidget(setting);
if (!widget) return;
let colorStr = '';
if (!this._settings.list_keys().includes(setting)) {
let defaultValues = {
'background-color': 'rgba(0, 0, 0, 0.5)',
'border-color': 'rgba(255, 255, 255, 0.2)'
};
colorStr = defaultValues[setting] || '';
} else {
colorStr = this._settings.get_string(setting);
}
if (widget instanceof Gtk.ColorDialogButton) {
let rgba = new Gdk.RGBA();
if (rgba.parse(colorStr)) {
this._updating = true;
widget.set_rgba(rgba);
this._updating = false;
}
} else if (widget.set_text) {
this._updating = true;
widget.set_text(colorStr);
this._updating = false;
}
}
_getWidget(name) {
let wname = name.replace(/-/g, '_');
return this._buildable.get_object(wname);
}
_getBooleans() {
return [
'first-change-window'
];
}
_getNumbers() {
return [
'hover-shade-level',
'hover-border-width',
'hover-glow-size',
'hover-opacity',
'icon-spacing',
'container-padding',
'border-size',
'background-border-radius',
'icon-border-radius'
];
}
_getStrings() {
return [
'background-color',
'border-color'
];
}
_bindBoolean(setting) {
let widget = this._getWidget(setting);
if (!widget) return;
this._settings.bind(setting, widget, 'active', Gio.SettingsBindFlags.DEFAULT);
}
_bindBooleans() {
this._getBooleans().forEach(this._bindBoolean, this);
}
_bindString(setting) {
let widget = this._getWidget(setting);
if (!widget) return;
this._updateStringWidget(setting);
if (widget instanceof Gtk.ColorDialogButton) {
widget.connect('notify::rgba', (w) => {
if (this._updating) return;
if (!this._settings.list_keys().includes(setting)) return;
let rgba = w.get_rgba();
let val = rgba.to_string(); // CSS format
let current = this._settings.get_string(setting);
if (current !== val) {
this._settings.set_string(setting, val);
}
});
} else {
widget.connect('changed', (w) => {
if (this._updating) return;
if (!this._settings.list_keys().includes(setting)) return;
let val = w.get_text();
let current = this._settings.get_string(setting);
if (current !== val) {
this._settings.set_string(setting, val);
}
});
}
this._settings.connect(`changed::${setting}`, () => {
if (this._updating) return;
this._updateStringWidget(setting);
});
}
_bindStrings() {
this._getStrings().forEach(this._bindString, this);
}
_bindNumber(setting) {
let widget = this._getWidget(setting);
if (!widget) return;
let isDouble = (setting === 'hover-shade-level' || setting === 'hover-opacity');
// Érték betöltése indításkor
this._updateNumberWidget(setting);
// Automatikus mentés változáskor
widget.connect('notify::value', (w) => {
if (this._updating) return;
if (!this._settings.list_keys().includes(setting)) return;
let val = w.get_value();
if (isDouble) {
// Only update if significantly different to avoid feedback loops
let current = this._settings.get_double(setting);
if (Math.abs(current - val) > 0.001) {
this._settings.set_double(setting, val);
}
} else {
let current = this._settings.get_int(setting);
if (current !== Math.round(val)) {
this._settings.set_int(setting, Math.round(val));
}
}
});
// Update widget if setting changes externally (e.g. reset)
this._settings.connect(`changed::${setting}`, () => {
if (this._updating) return;
this._updateNumberWidget(setting);
});
}
_bindNumbers() {
this._getNumbers().forEach(this._bindNumber, this);
}
_firstChangeWindowChanged() {
this._settings.get_boolean('first-change-window');
}
}
export default class UnityLikeAppSwitcherPreferences extends ExtensionPreferences {
fillPreferencesWindow (window) {
this.initTranslations("unity-window-switcher");
window._settings = this.getSettings();
const widget = new PrefsWidget(window._settings);
window.add(widget._getWidget('prefs_widget'));
}
}
|