-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefs.js
More file actions
362 lines (323 loc) · 10.9 KB
/
prefs.js
File metadata and controls
362 lines (323 loc) · 10.9 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
import Adw from "gi://Adw";
import Gtk from "gi://Gtk";
import Gdk from "gi://Gdk";
import Gio from "gi://Gio";
import GLib from "gi://GLib";
import GObject from "gi://GObject";
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
// ── Keybinding row ──────────────────────────────────────────────────────────
const KeybindingRow = GObject.registerClass(
{
GTypeName: "SuperbarKeybindingRow",
},
class KeybindingRow extends Adw.ActionRow {
_init(settings, key, params = {}) {
super._init(params);
this._settings = settings;
this._key = key;
this._shortcutLabel = new Gtk.ShortcutLabel({
valign: Gtk.Align.CENTER,
disabled_text: "Disabled",
});
this._syncLabel();
const editBtn = new Gtk.Button({
icon_name: "document-edit-symbolic",
valign: Gtk.Align.CENTER,
has_frame: false,
tooltip_text: "Change shortcut",
});
editBtn.connect("clicked", () => this._startCapture());
const clearBtn = new Gtk.Button({
icon_name: "edit-clear-symbolic",
valign: Gtk.Align.CENTER,
has_frame: false,
tooltip_text: "Disable shortcut",
});
clearBtn.connect("clicked", () => {
this._settings.set_strv(this._key, []);
this._syncLabel();
});
this.add_suffix(this._shortcutLabel);
this.add_suffix(editBtn);
this.add_suffix(clearBtn);
}
_syncLabel() {
const shortcuts = this._settings.get_strv(this._key);
this._shortcutLabel.accelerator = shortcuts.length ? shortcuts[0] : "";
}
_startCapture() {
const dialog = new Adw.Window({
modal: true,
transient_for: this.get_root(),
default_width: 380,
default_height: 200,
title: "New Shortcut",
});
const box = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 12,
margin_top: 24,
margin_bottom: 24,
margin_start: 24,
margin_end: 24,
valign: Gtk.Align.CENTER,
});
const headerBar = new Adw.HeaderBar({ show_end_title_buttons: false });
const cancelBtn = new Gtk.Button({ label: "Cancel" });
cancelBtn.connect("clicked", () => dialog.destroy());
headerBar.pack_start(cancelBtn);
const label = new Gtk.Label({
label: "<b>Press a new key combination…</b>",
use_markup: true,
});
const hint = new Gtk.Label({
label: "Press Escape to cancel",
css_classes: ["dim-label"],
});
box.append(label);
box.append(hint);
const content = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
});
content.append(headerBar);
content.append(box);
dialog.set_content(content);
const controller = new Gtk.EventControllerKey();
controller.connect("key-pressed", (_ctrl, keyval, keycode, state) => {
if (keyval === Gdk.KEY_Escape) {
dialog.destroy();
return Gdk.EVENT_STOP;
}
// Ignore bare modifiers
if (
[
Gdk.KEY_Shift_L,
Gdk.KEY_Shift_R,
Gdk.KEY_Control_L,
Gdk.KEY_Control_R,
Gdk.KEY_Alt_L,
Gdk.KEY_Alt_R,
Gdk.KEY_Super_L,
Gdk.KEY_Super_R,
Gdk.KEY_Meta_L,
Gdk.KEY_Meta_R,
].includes(keyval)
)
return Gdk.EVENT_PROPAGATE;
const mask =
state &
(Gdk.ModifierType.SHIFT_MASK |
Gdk.ModifierType.CONTROL_MASK |
Gdk.ModifierType.ALT_MASK |
Gdk.ModifierType.SUPER_MASK);
const accel = Gtk.accelerator_name_with_keycode(
null,
keyval,
keycode,
mask,
);
if (accel && accel !== "") {
this._settings.set_strv(this._key, [accel]);
this._syncLabel();
}
dialog.destroy();
return Gdk.EVENT_STOP;
});
dialog.add_controller(controller);
dialog.present();
}
},
);
// ── Preferences page ────────────────────────────────────────────────────────
export default class SuperbarPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
window.set_default_size(600, 500);
const settings = this.getSettings("org.gnome.shell.extensions.superbar");
// ── Keyboard shortcut page ─────────────────────────────────────────────
const shortcutPage = new Adw.PreferencesPage({
title: "General",
icon_name: "preferences-system-symbolic",
});
window.add(shortcutPage);
const shortcutGroup = new Adw.PreferencesGroup({
title: "Keyboard Shortcut",
description: "Shortcut to open and close Superbar",
});
shortcutPage.add(shortcutGroup);
const row = new KeybindingRow(settings, "toggle-shortcut", {
title: "Toggle Superbar",
subtitle: "Click the edit button and press your desired key combination",
});
shortcutGroup.add(row);
// ── Behavior group ─────────────────────────────────────────────────────
const behaviorGroup = new Adw.PreferencesGroup({
title: "Clipboard",
description: "Control how clipboard history is collected and stored",
});
shortcutPage.add(behaviorGroup);
const clipToggleRow = new Adw.SwitchRow({
title: "Enable Clipboard Monitoring",
subtitle: "Track clipboard changes to build a searchable history",
});
settings.bind(
"clipboard-monitor-enabled",
clipToggleRow,
"active",
Gio.SettingsBindFlags.DEFAULT,
);
behaviorGroup.add(clipToggleRow);
const clipLimitRow = new Adw.SpinRow({
title: "History Limit",
subtitle: "Maximum number of clipboard entries to remember",
adjustment: new Gtk.Adjustment({
lower: 10,
upper: 200,
step_increment: 5,
page_increment: 20,
value: settings.get_int("clipboard-history-limit"),
}),
});
settings.bind(
"clipboard-history-limit",
clipLimitRow,
"value",
Gio.SettingsBindFlags.DEFAULT,
);
behaviorGroup.add(clipLimitRow);
const clearRow = new Adw.ActionRow({
title: "Clear Clipboard History",
subtitle: "Remove all saved clipboard entries from disk",
});
const clearBtn = new Gtk.Button({
label: "Clear",
valign: Gtk.Align.CENTER,
css_classes: ["destructive-action"],
});
clearBtn.connect("clicked", () => {
const historyPath = GLib.build_filenamev([
GLib.get_user_data_dir(),
"search-bar-clipboard-history.json",
]);
try {
GLib.file_set_contents(historyPath, "[]");
} catch (_e) {}
});
clearRow.add_suffix(clearBtn);
behaviorGroup.add(clearRow);
// ── Appearance group ───────────────────────────────────────────────────
const appearanceGroup = new Adw.PreferencesGroup({
title: "Appearance",
description: "Adjust the size and position of the bar",
});
shortcutPage.add(appearanceGroup);
const maxResultsRow = new Adw.SpinRow({
title: "Max Search Results",
subtitle: "How many results to show in the list",
adjustment: new Gtk.Adjustment({
lower: 3,
upper: 20,
step_increment: 1,
page_increment: 5,
value: settings.get_int("max-results"),
}),
});
settings.bind(
"max-results",
maxResultsRow,
"value",
Gio.SettingsBindFlags.DEFAULT,
);
appearanceGroup.add(maxResultsRow);
const barWidthRow = new Adw.SpinRow({
title: "Bar Width",
subtitle: "Width of the Superbar in pixels",
adjustment: new Gtk.Adjustment({
lower: 400,
upper: 1200,
step_increment: 10,
page_increment: 50,
value: settings.get_int("bar-width"),
}),
});
settings.bind(
"bar-width",
barWidthRow,
"value",
Gio.SettingsBindFlags.DEFAULT,
);
appearanceGroup.add(barWidthRow);
const positionLabels = ["Top (¼ from top)", "Center", "Bottom"];
const positionKeys = ["top", "center", "bottom"];
const positionRow = new Adw.ComboRow({
title: "Vertical Position",
subtitle: "Where on screen the bar appears",
model: Gtk.StringList.new(positionLabels),
});
const currentPos = settings.get_string("bar-position");
positionRow.set_selected(Math.max(0, positionKeys.indexOf(currentPos)));
positionRow.connect("notify::selected", () => {
settings.set_string(
"bar-position",
positionKeys[positionRow.selected] ?? "top",
);
});
appearanceGroup.add(positionRow);
// ── About / Donate page ────────────────────────────────────────────────
const aboutPage = new Adw.PreferencesPage({
title: "About",
icon_name: "help-about-symbolic",
});
window.add(aboutPage);
// Project info
const infoGroup = new Adw.PreferencesGroup({ title: "Superbar" });
aboutPage.add(infoGroup);
const descRow = new Adw.ActionRow({
title: "Version",
subtitle: `${this.metadata.version}`,
});
infoGroup.add(descRow);
const sourceRow = new Adw.ActionRow({
title: "Source Code",
subtitle: "github.com/Furkan-rgb/superbar",
activatable: true,
});
sourceRow.add_suffix(
new Gtk.Image({
icon_name: "external-link-symbolic",
valign: Gtk.Align.CENTER,
}),
);
sourceRow.connect("activated", () =>
Gio.AppInfo.launch_default_for_uri(
"https://github.com/Furkan-rgb/superbar",
null,
),
);
infoGroup.add(sourceRow);
// Donate
const donateGroup = new Adw.PreferencesGroup({
title: "Support Development",
description:
"Superbar is free and open-source. If you find it useful, consider buying me a coffee — it keeps the project going!",
});
aboutPage.add(donateGroup);
const coffeeRow = new Adw.ActionRow({
title: "Buy Me a Coffee ☕",
subtitle: "buymeacoffee.com/furkan12",
activatable: true,
});
coffeeRow.add_suffix(
new Gtk.Image({
icon_name: "external-link-symbolic",
valign: Gtk.Align.CENTER,
}),
);
coffeeRow.connect("activated", () =>
Gio.AppInfo.launch_default_for_uri(
"https://buymeacoffee.com/furkan12",
null,
),
);
donateGroup.add(coffeeRow);
}
}