-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
212 lines (178 loc) · 8.41 KB
/
Copy pathextension.js
File metadata and controls
212 lines (178 loc) · 8.41 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
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import Clutter from 'gi://Clutter';
import GObject from 'gi://GObject';
import St from 'gi://St';
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 { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
const OverlayClickIndicator = GObject.registerClass(
class OverlayClickIndicator extends PanelMenu.Button {
_init(extension) {
super._init(0.0, 'Overlay Click Indicator');
this.ext = extension;
let icon = new St.Icon({
icon_name: 'view-grid-symbolic',
style_class: 'system-status-icon',
});
this.add_child(icon);
this._buildMenu();
this.settingsId = this.ext._settings.connect('changed::windows-data', () => this._buildMenu());
}
_buildMenu() {
this.menu.removeAll();
let data = [];
try { data = JSON.parse(this.ext._settings.get_string('windows-data') || '[]'); } catch(e) {}
let addBtn = new PopupMenu.PopupMenuItem('➕ Añadir Ventana');
addBtn.connect('activate', () => {
data.push({ id: 'win_' + Date.now(), url: 'https://www.google.com', opacity: 1.0, visible: true });
this.ext._settings.set_string('windows-data', JSON.stringify(data));
});
this.menu.addMenuItem(addBtn);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
for (let i = 0; i < data.length; i++) {
let win = data[i];
let item = new PopupMenu.PopupSubMenuMenuItem(`🌐 Ventana ${i+1} (${win.visible ? 'Visible' : 'Oculta'})`);
// URL Entry
let urlItem = new PopupMenu.PopupBaseMenuItem({ reactive: false });
let urlEntry = new St.Entry({ text: win.url, can_focus: true, x_expand: true });
urlItem.add_child(urlEntry);
urlEntry.clutter_text.connect('activate', () => {
data[i].url = urlEntry.get_text();
this.ext._settings.set_string('windows-data', JSON.stringify(data));
});
item.menu.addMenuItem(urlItem);
// Opacity Controls
let opacityItem = new PopupMenu.PopupBaseMenuItem({ reactive: false });
let opLabel = new St.Label({ text: 'Opacidad: ' + Math.round(win.opacity * 100) + '%', y_align: Clutter.ActorAlign.CENTER, x_expand: true });
let btnMinus = new St.Button({ style_class: 'button', label: ' - ' });
btnMinus.connect('clicked', () => {
data[i].opacity = Math.max(0.1, win.opacity - 0.1);
this.ext._settings.set_string('windows-data', JSON.stringify(data));
});
let btnPlus = new St.Button({ style_class: 'button', label: ' + ' });
btnPlus.connect('clicked', () => {
data[i].opacity = Math.min(1.0, win.opacity + 0.1);
this.ext._settings.set_string('windows-data', JSON.stringify(data));
});
opacityItem.add_child(opLabel);
opacityItem.add_child(btnMinus);
opacityItem.add_child(btnPlus);
item.menu.addMenuItem(opacityItem);
// Toggle Visibility
let visBtn = new PopupMenu.PopupMenuItem(win.visible ? '👁️ Ocultar' : '👁️ Mostrar');
visBtn.connect('activate', () => {
data[i].visible = !win.visible;
this.ext._settings.set_string('windows-data', JSON.stringify(data));
});
item.menu.addMenuItem(visBtn);
// Delete
let delBtn = new PopupMenu.PopupMenuItem('❌ Eliminar');
delBtn.connect('activate', () => {
data.splice(i, 1);
this.ext._settings.set_string('windows-data', JSON.stringify(data));
});
item.menu.addMenuItem(delBtn);
this.menu.addMenuItem(item);
}
}
destroy() {
if (this.settingsId) this.ext._settings.disconnect(this.settingsId);
super.destroy();
}
});
export default class OverlayClickExtension extends Extension {
enable() {
this._settings = this.getSettings('org.gnome.shell.extensions.overlayclick');
this._mode = 0;
this._processes = {};
this._indicator = new OverlayClickIndicator(this);
Main.panel.addToStatusArea('overlay-click-indicator', this._indicator);
this._syncProcesses();
this._settings.connect('changed::windows-data', () => this._syncProcesses());
Main.wm.addKeybinding(
'toggle-shortcut',
this._settings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.ALL,
() => this._toggleReactive()
);
this._wsId = global.workspace_manager.connect('workspace-switched', () => this._applyWindowHacks());
// Timer persistente para hacks (on top, stick) a TODAS las ventanas de la extensión
this._positionTimer = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
this._applyWindowHacks();
return GLib.SOURCE_CONTINUE;
});
}
_syncProcesses() {
let data = [];
try { data = JSON.parse(this._settings.get_string('windows-data') || '[]'); } catch(e) {}
let schemaDir = this.dir.get_child('schemas').get_path();
let scriptPath = this.dir.get_child('browser-window.js').get_path();
let activeIds = data.map(w => w.id);
for (let win of data) {
if (!this._processes[win.id]) {
try {
let proc = new Gio.Subprocess({
argv: ['gjs', '-m', scriptPath, win.id, schemaDir],
flags: Gio.SubprocessFlags.NONE
});
proc.init(null);
this._processes[win.id] = proc;
// Al nacer la ventana, sincronizar el modo actual
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
proc.send_signal(this._mode === 0 ? 10 : 12);
return false;
});
} catch(e) { console.error(e); }
}
}
for (let id in this._processes) {
if (!activeIds.includes(id)) {
delete this._processes[id]; // El proceso se cerrará solo al no encontrarse en JSON
}
}
}
_applyWindowHacks() {
let windowActors = global.get_window_actors();
let targets = windowActors.filter(a => {
let win = a.meta_window;
if (!win || !win.get_title() || !win.get_title().startsWith('Overlay')) return false;
// No aplicar hacks a ventanas minimizadas u ocultas (las que estamos escondiendo)
if (win.minimized || win.is_hidden && win.is_hidden()) return false;
return true;
});
for (let target of targets) {
let currentWs = global.workspace_manager.get_active_workspace();
target.meta_window.change_workspace(currentWs);
target.meta_window.stick();
target.meta_window.make_above();
}
}
_toggleReactive() {
this._mode = (this._mode === 0) ? 1 : 0;
let signal = this._mode === 0 ? 10 : 12;
for (let id in this._processes) {
try { this._processes[id].send_signal(signal); } catch(e) {}
}
if (this._mode === 1) {
let windowActors = global.get_window_actors();
let target = windowActors.find(a => a.meta_window && a.meta_window.get_title() && a.meta_window.get_title().startsWith('Overlay'));
if (target) target.meta_window.activate(global.get_current_time());
}
}
disable() {
Main.wm.removeKeybinding('toggle-shortcut');
if (this._wsId) { global.workspace_manager.disconnect(this._wsId); this._wsId = null; }
if (this._positionTimer) { GLib.source_remove(this._positionTimer); this._positionTimer = null; }
if (this._indicator) { this._indicator.destroy(); this._indicator = null; }
for (let id in this._processes) {
try { this._processes[id].force_exit(); } catch(e) {}
}
this._processes = {};
this._settings = null;
}
}