-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefs.js
More file actions
111 lines (90 loc) · 4.2 KB
/
Copy pathprefs.js
File metadata and controls
111 lines (90 loc) · 4.2 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
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import Adw from 'gi://Adw';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';
import Gdk from 'gi://Gdk';
export default class GnomeBehafuchaPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
const settings = this.getSettings('org.gnome.shell.extensions.gnome-behafucha');
// Define the stability note once to avoid duplicate translations
const stabilityNote = _('Note: Shortcuts without "Shift" are more stable.');
const page = new Adw.PreferencesPage();
const group = new Adw.PreferencesGroup({ title: _('Settings') });
const row = new Adw.ActionRow({
title: _('Keyboard Shortcut'),
subtitle: `${_('Shortcut to convert text.')} ${stabilityNote}`,
activatable: true
});
const shortcutLabel = new Gtk.ShortcutLabel({
disabled_text: _('Not Set'),
valign: Gtk.Align.CENTER
});
const updateLabel = () => {
const shortcut = settings.get_strv('convert-text-shortcut');
shortcutLabel.accelerator = (shortcut && shortcut.length > 0) ? shortcut[0] : '';
};
updateLabel();
settings.connect('changed::convert-text-shortcut', updateLabel);
const startEditing = () => {
const editor = new Adw.Window({
modal: true,
transient_for: window,
width_request: 450,
height_request: 250,
title: _('Set Shortcut')
});
const view = new Adw.StatusPage({
title: _('Recording...'),
description: `${_('Press full combination (e.g., Super+Z).')}\n${stabilityNote}\n${_('Esc to cancel')}`,
icon_name: 'preferences-desktop-keyboard-shortcuts-symbolic'
});
const eventController = new Gtk.EventControllerKey();
editor.add_controller(eventController);
eventController.connect('key-pressed', (controller, keyval, keycode, state) => {
if (keyval === Gdk.KEY_Escape) {
editor.close();
return true;
}
let mask = state & Gtk.accelerator_get_default_mod_mask();
const isAlt = (state & Gdk.ModifierType.ALT_MASK) || (state & Gdk.ModifierType.MOD1_MASK);
const isCtrl = (state & Gdk.ModifierType.CONTROL_MASK);
const isShift = (state & Gdk.ModifierType.SHIFT_MASK);
const isSuper = (state & Gdk.ModifierType.SUPER_MASK) || (state & Gdk.ModifierType.META_MASK);
let isModifierKey = (
keyval === Gdk.KEY_Control_L || keyval === Gdk.KEY_Control_R ||
keyval === Gdk.KEY_Shift_L || keyval === Gdk.KEY_Shift_R ||
keyval === Gdk.KEY_Alt_L || keyval === Gdk.KEY_Alt_R ||
keyval === Gdk.KEY_Super_L || keyval === Gdk.KEY_Super_R
);
if (!isModifierKey && mask !== 0) {
let res = '';
if (isCtrl) res += '<Control>';
if (isAlt) res += '<Alt>';
if (isShift) res += '<Shift>';
if (isSuper) res += '<Super>';
let keyName = Gtk.accelerator_name(keyval, 0);
res += keyName;
if (res) {
settings.set_strv('convert-text-shortcut', [res]);
editor.close();
}
}
return true;
});
editor.set_content(view);
editor.present();
};
const editButton = new Gtk.Button({
icon_name: 'edit-symbolic',
valign: Gtk.Align.CENTER,
css_classes: ['flat']
});
editButton.connect('clicked', startEditing);
row.connect('activated', startEditing);
row.add_suffix(shortcutLabel);
row.add_suffix(editButton);
group.add(row);
page.add(group);
window.add(page);
}
}