-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathextension.js
More file actions
237 lines (198 loc) · 7.23 KB
/
Copy pathextension.js
File metadata and controls
237 lines (198 loc) · 7.23 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
/*
Reading Strip, Reading guide on the computer for people with dyslexia.
Copyright (C) 2021-25 Luigi Pantano
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 St from 'gi://St';
import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import { getPointerWatcher } from "resource:///org/gnome/shell/ui/pointerWatcher.js";
import {
Extension,
gettext as _,
} from 'resource:///org/gnome/shell/extensions/extension.js';
var Strip = GObject.registerClass(
class Strip extends St.Widget {
_init(name) {
super._init({
name: name,
reactive: false,
can_focus: false,
track_hover: false,
visible: false
});
this.locked = false;
Main.uiGroup.add_child(this);
}
show_hide() {
this.visible = !this.visible;
}
lock_unlock() {
this.locked = !this.locked;
}
sync(y, monitor) {
this.set_position(monitor.x, y);
this.width = monitor.width;
if (this.name != 'sMiddle') {
this.height = monitor.height;
}
}
destroy() {
Main.uiGroup.remove_child(this);
super.destroy();
}
});
export default class ReadingStrip extends Extension {
// follow cursor position and monitor as well
syncStrip() {
const currentMonitor = Main.layoutManager.currentMonitor;
const [x, y] = global.get_pointer();
if (this.sMiddle.visible == true && this.sMiddle.locked == false) {
this.sTop.sync(-currentMonitor.height + y - this.sMiddle.height / 2, currentMonitor);
this.sMiddle.sync(y - this.sMiddle.height / 2, currentMonitor);
this.sBottom.sync(y + this.sMiddle.height / 2, currentMonitor);
}
}
// update icon status
updateIcon() {
if (!this.sMiddle.visible) {
this._icon.gicon = this._icon_off;
} else if (this.sMiddle.locked) {
this._icon.gicon = this._icon_locked;
} else {
this._icon.gicon = this._icon_on;
}
}
// toggle strip on or off
toggleStrip() {
this.sMiddle.show_hide();
const focusVisible =
this.sMiddle.visible &&
this._settings.get_boolean('focusmode');
this.sTop.visible = this.sBottom.visible = focusVisible;
// update settings
this._settings.set_boolean('enabled', this.sMiddle.visible);
// add or remove pointer watcher
if (this.sMiddle.visible) {
if (!this.pointerWatch) {
this.pointerWatcher = getPointerWatcher();
this.pointerWatch = this.pointerWatcher.addWatch(
this.refresh,
this.syncStrip.bind(this)
);
}
} else {
if (this.pointerWatch) {
this.pointerWatch.remove();
this.pointerWatch = null;
}
}
}
onSettingsChanged() {
this.sMiddle.style = 'background-color : ' + this._settings.get_string('color-strip') + ';border: 1px solid #708090;';
this.sMiddle.opacity = 255 * this._settings.get_double('opacity')/100;
this.sMiddle.height = Main.layoutManager.currentMonitor.height * this._settings.get_double('height')/100;
this.sTop.visible = this.sBottom.visible = this.sMiddle.visible && this._settings.get_boolean('focusmode');
this.sTop.opacity = this.sBottom.opacity = 255 * 75/100;
this.sTop.style = this.sBottom.style = 'background-color : ' + this._settings.get_string('color-focus');
this.refresh = this._settings.get_int('refresh');
this.syncStrip();
}
enable() {
this.pointerWatch = null;
this.pointerWatcher = null;
// add Stripes
this.sTop = new Strip('sTop');
this.sMiddle = new Strip('sMiddle');
this.sBottom = new Strip('sBottom');
// add to top panel
this._icon_on = Gio.icon_new_for_string(`${this.path}/icons/readingstrip-on-symbolic.svg`);
this._icon_off = Gio.icon_new_for_string(`${this.path}/icons/readingstrip-off-symbolic.svg`);
this._icon_locked = Gio.icon_new_for_string(`${this.path}/icons/readingstrip-locked-symbolic.svg`);
this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false);
this._icon = new St.Icon({
gicon : this._icon_off,
style_class: 'system-status-icon',
});
this._indicator.add_child(this._icon);
this._buttonSwitchItem = new PopupMenu.PopupSwitchMenuItem(_('Show/Hide'), false, {});
this._buttonSwitchItem.connect('toggled', () => {
this.toggleStrip();
this.updateIcon();
});
this._indicator.menu.addMenuItem(this._buttonSwitchItem);
this._indicator.menu.addAction(
_('Settings...'),
() => this.openPreferences(),
'org.gnome.Settings-symbolic'
);
Main.panel.addToStatusArea(this.metadata.uuid, this._indicator);
// settings
this._settings = this.getSettings();
this._setting_changed_signal_ids = [];
this._setting_changed_signal_ids.push(this._settings.connect('changed', () => {this.onSettingsChanged()}));
this.onSettingsChanged();
if (this._settings.get_boolean('enabled')) {
this._buttonSwitchItem.setToggleState(!this.sMiddle.visible);
}
// synchronize hot key enable/disable
this._keybindingId_show = Main.wm.addKeybinding(
"show",
this._settings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL,
() => {
this._buttonSwitchItem.setToggleState(!this.sMiddle.visible);
this.updateIcon();
}
);
// synchronize hot key lock/unlock
this._keybindingId_lock = Main.wm.addKeybinding(
"lock",
this._settings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL,
() => {
this.sMiddle.lock_unlock();
this.updateIcon();
}
);
}
disable() {
this._indicator.destroy();
this._indicator = null;
this.sTop.destroy();
this.sMiddle.destroy();
this.sBottom.destroy();
this._setting_changed_signal_ids.forEach(id => this._settings.disconnect(id));
this._setting_changed_signal_ids = [];
this._settings = null;
if (this.pointerWatch){
this.pointerWatch.remove();
}
this.pointerWatch = null;
this.pointerWatcher = null;
this._icon = null;
this._icon_on = null;
this._icon_off = null;
this._icon_locked = null;
Main.wm.removeKeybinding('show');
this._keybindingId_show = null;
Main.wm.removeKeybinding('lock');
this._keybindingId_lock = null;
}
}