Repository navigation
Expand file tree
/
Copy pathquickButton.js
More file actions
322 lines (289 loc) · 11.5 KB
/
Copy pathquickButton.js
File metadata and controls
322 lines (289 loc) · 11.5 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
/*
* Floating-Mini-Panel for GNOME Shell 46+
*
* Copyright 2024, 2025 Gerhard Himmel
*
* 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 2 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 <http://www.gnu.org/licenses/>.
*/
'use strict';
import Clutter from 'gi://Clutter';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Shell from 'gi://Shell';
import St from 'gi://St';
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
const PANELBOX = Main.layoutManager.panelBox;
const QUICKSETTINGS = Main.panel.statusArea['quickSettings'];
const QUICKSOURCEACTOR = QUICKSETTINGS.menu.sourceActor;
const QUICKARROWALIGNMENT = QUICKSETTINGS.menu._arrowAlignment;
const shellVersion = parseFloat(Config.PACKAGE_VERSION);
export const QuickButton = GObject.registerClass(
class QuickButton extends St.BoxLayout {
constructor(parent) {
super({
name: 'quickBtn',
reactive: true,
track_hover: true,
style_class: 'button btn',
});
this._parent = parent;
// START CODE VERTICAL
this.orientStr = shellVersion > 47 ? 'orientation' : 'vertical';
this._parent.bind_property_full(
this.orientStr,
this,
this.orientStr,
GObject.BindingFlags.SYNC_CREATE,
(binding, value) => {
if (value) {
QUICKSETTINGS.menu._boxPointer._userArrowSide =
St.Side.LEFT;
} else {
QUICKSETTINGS.menu._boxPointer._userArrowSide =
St.Side.TOP;
}
return [binding, value];
},
null
);
this.connect('notify::mapped', () => {
QUICKSETTINGS.menu.close();
if (this.mapped) {
QUICKSETTINGS.menu.sourceActor = this;
QUICKSETTINGS.menu._arrowAlignment = 0.5;
// START CODE VERTICAL
if (this[this.orientStr])
QUICKSETTINGS.menu._boxPointer._userArrowSide =
St.Side.LEFT;
} else {
QUICKSETTINGS.menu.sourceActor = QUICKSOURCEACTOR;
QUICKSETTINGS.menu._arrowAlignment = QUICKARROWALIGNMENT;
// START CODE VERTICAL
QUICKSETTINGS.menu._boxPointer._userArrowSide = St.Side.TOP;
}
});
this.connect('button-press-event', (obj, event) => {
if (event.get_button() === 1) QUICKSETTINGS.menu.toggle();
// Open QuickSettings menu with ShutdownItem menu opened
// with right click
if (event.get_button() === 3) {
QUICKSETTINGS.menu.toggle();
QUICKSETTINGS._system._systemItem.menu.toggle();
}
});
this._qmConId = QUICKSETTINGS.menu.connect(
'open-state-changed',
() => {
if (this.has_style_pseudo_class('active')) {
this.remove_style_pseudo_class('active');
} else {
this.add_style_pseudo_class('active');
}
return GLib.SOURCE_PROPAGATE;
}
);
this._cloneIndicators();
// If QuickSettings indicators are added or removed
// !!! make own functions for add and remove (array splice) !!!
this._qiConId = QUICKSETTINGS._indicators.connectObject(
'child-added',
this._cloneIndicators.bind(this),
'child-removed',
this._cloneIndicators.bind(this),
this
);
if (QUICKSETTINGS._system) {
// Close QuickSettings menu when PowerToggle is clicked.
this._ptConId1 =
QUICKSETTINGS._system._systemItem._powerToggle.connect(
'clicked',
() => {
QUICKSETTINGS.menu.close();
}
);
// Close QuickSettings menu when SettingsItem is clicked.
let childs =
QUICKSETTINGS._system._systemItem.firstChild.get_children();
for (let child of childs) {
if (child._settingsApp) {
this._settingsItem = child;
this._siConId2 = this._settingsItem.connect(
'clicked',
() => {
QUICKSETTINGS.menu.close();
}
);
break;
}
}
// Close QuickSettings menu when Shutdown-Suspend is clicked.
this._simConId3 =
QUICKSETTINGS._system._systemItem.menu.connect(
'activate',
() => {
QUICKSETTINGS.menu.close();
}
);
}
Main.wm.setCustomKeybindingHandler(
'toggle-quick-settings',
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW |
Shell.ActionMode.POPUP,
this._toggleQuickSettings.bind(this)
);
}
_toggleQuickSettings() {
if (this.visible || PANELBOX.visible) {
QUICKSETTINGS.menu.toggle();
if (QUICKSETTINGS.menu.isOpen) {
QUICKSETTINGS.menu.actor.navigate_focus(
null,
St.DirectionType.TAB_FORWARD,
false
);
}
}
}
_create_clone(orgInd, type, i) {
this._orgInds[i] = orgInd;
if (type === 'gicon') {
this._cloneInds[i] = new St.Icon({
style_class: 'system-status-icon',
visible: true,
});
} else {
this._cloneInds[i] = new St.Label({
y_expand: true,
y_align: Clutter.ActorAlign.CENTER,
visible: true,
});
}
// Scrolling on output volume
if (orgInd.get_parent()) {
if (orgInd.get_parent()._output) {
this._cloneInds[i].reactive = true;
this._cloneInds[i].connect('scroll-event', (actor, event) =>
this._orgInds[i]
.get_parent()
._handleScrollEvent(
this._orgInds[i].get_parent()._output,
event
)
);
}
// Scrolling on input volume
if (orgInd.get_parent()._input) {
this._cloneInds[i].reactive = true;
this._cloneInds[i].connect('scroll-event', (actor, event) =>
this._orgInds[i]
.get_parent()
._handleScrollEvent(
this._orgInds[i].get_parent()._input,
event
)
);
}
// Scrolling on Caffeine
if (orgInd.get_parent()._name === 'Caffeine') {
this._cloneInds[i].reactive = true;
this._cloneInds[i].connect('scroll-event', (actor, event) =>
this._orgInds[i].get_parent()._handleScrollEvent(event)
);
}
}
this.add_child(this._cloneInds[i]);
this._orgInds[i].bind_property(
type,
this._cloneInds[i],
type,
GObject.BindingFlags.SYNC_CREATE
);
this._orgInds[i].bind_property(
'visible',
this._cloneInds[i],
'visible',
GObject.BindingFlags.SYNC_CREATE
);
}
_cloneIndicators() {
this._cloneInds = [];
this._orgInds = [];
this.remove_all_children();
let quickInds = QUICKSETTINGS._indicators;
let i = 0;
for (const ind of quickInds) {
if (ind._indicator) {
this._create_clone(ind._indicator, 'gicon', i);
if (ind._percentageLabel) {
// Battery Percentage
i++;
this._create_clone(ind._percentageLabel, 'text', i);
}
if (ind._timerLabel) {
// Caffeine Timer
i++;
this._create_clone(ind._timerLabel, 'text', i);
}
if (ind._label) {
// Ubuntu Net Speed
i++;
this._create_clone(ind._label, 'text', i);
}
} else {
if (ind._vpnIndicator) {
this._create_clone(ind._vpnIndicator, 'gicon', i);
}
if (ind._primaryIndicator) {
this._create_clone(ind._primaryIndicator, 'gicon', i);
}
}
i++;
}
}
destroy() {
this._cloneInds = null;
this._orgInds = null;
Main.wm.setCustomKeybindingHandler(
'toggle-quick-settings',
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW |
Shell.ActionMode.POPUP,
Main.wm._toggleQuickSettings.bind(Main.wm)
);
if (QUICKSETTINGS._system) {
QUICKSETTINGS._system._systemItem._powerToggle.disconnect(
this._ptConId1
);
this._ptConId1 = null;
if (this._settingsItem) {
this._settingsItem.disconnect(this._siConId2);
this._siConId2 = null;
}
if (this._simConId3) {
QUICKSETTINGS._system._systemItem.menu.disconnect(
this._simConId3
);
this._simConId3 = null;
}
}
QUICKSETTINGS._indicators.disconnectObject(this._qiConId);
this._qiConId = null;
QUICKSETTINGS.menu.disconnect(this._qmConId);
this._qmConId = null;
super.destroy();
}
}
);