-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuToggles.js
185 lines (150 loc) · 6.87 KB
/
menuToggles.js
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
import GObject from 'gi://GObject';
import St from 'gi://St';
import Clutter from 'gi://Clutter';
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import * as QuickSettings from 'resource:///org/gnome/shell/ui/quickSettings.js';
import { MonitorConfigParameters } from "./extension.js";
const PopupMenuItemWithSelectedAndPreferredMarks = GObject.registerClass({
Properties: {
"selected": GObject.ParamSpec.boolean("selected", "", "", GObject.ParamFlags.READABLE, false),
"preferred": GObject.ParamSpec.boolean("preferred", "", "", GObject.ParamFlags.READABLE, false),
},
}, class PopupMenuItemWithSelectedAndPreferredMarks extends PopupMenu.PopupMenuItem {
_init(text, selected, preferred, params) {
super._init(text, params);
this._selected = selected;
this._preferred = preferred;
this._selectedIcon = new St.Icon({
style_class: 'popup-menu-item-icon',
icon_name: 'object-select-symbolic',
});
this.add_child(this._selectedIcon);
this._preferredIcon = new St.Icon({
style_class: 'popup-menu-item-icon',
icon_name: 'emblem-favorite-symbolic', // maybe change the icon?
});
this.add_child(this._preferredIcon);
this.bind_property("selected", this._selectedIcon, "visible", GObject.BindingFlags.SYNC_CREATE);
this.bind_property("preferred", this._preferredIcon, "visible", GObject.BindingFlags.SYNC_CREATE);
}
get selected() {
return this._selected;
}
get preferred() {
return this._preferred;
}
}
);
const MonitorsConfigMenuToggle = GObject.registerClass({
Signals: {
"monitors-config-updated": {},
},
}, class MonitorsConfigMenuToggle extends QuickSettings.QuickMenuToggle {
_init(extensionObject, params) {
super._init(params);
this._extensionObject = extensionObject;
this._items = new Map();
this.menu.addSettingsAction(_("Display Settings"), "gnome-display-panel.desktop");
}
on_monitors_config_updated() {
this._updateItems();
}
emitMonitorsConfigUpdated() {
this.emit("monitors-config-updated");
}
_updateItems() {
this._items.forEach((item, key) => item.destroy());
this._items.clear();
const monitorsConfig = this._extensionObject.monitorsConfig;
for (const monitorName in monitorsConfig){
const monitorConfigSubMenuMenuItem = new PopupMenu.PopupSubMenuMenuItem(monitorName);
let currentConfig = null;
this._getMonitorConfigElements(monitorName).forEach(el => {
monitorConfigSubMenuMenuItem.menu.addMenuItem(
this._getMonitorConfigElementMenuItem(monitorName, el)
);
if (el.isCurrent) currentConfig = el;
});
monitorConfigSubMenuMenuItem.label.set_text(monitorName + (currentConfig != null ? ` - ${this._getMonitorConfigElementName(currentConfig)}` : ""));
this._items.set(monitorName, monitorConfigSubMenuMenuItem);
this.menu.addMenuItem(monitorConfigSubMenuMenuItem);
}
}
_getMonitorConfigElements(monitorName) {
throw new GObject.NotImplementedError();
}
_getMonitorConfigElementName(monitorConfigElement) {
throw new GObject.NotImplementedError();
}
_getMonitorConfigElementMenuItem(monitorName, monitorConfigElement) {
const menuItem = new PopupMenuItemWithSelectedAndPreferredMarks(
this._getMonitorConfigElementName(monitorConfigElement),
monitorConfigElement.isCurrent,
monitorConfigElement.isPreferred
);
menuItem.connect("activate", (o, event) => {
this._getMonitorConfigElementActivateCallback(monitorName, monitorConfigElement)();
});
return menuItem;
}
_getMonitorConfigElementActivateCallback(monitorName, monitorConfigElement) {
return this._extensionObject.getMonitorConfigElementActivateCallback(monitorName, monitorConfigElement, this._monitorConfigParameter);
}
}
);
export const ResolutionMenuToggle = GObject.registerClass(
class ResolutionMenuToggle extends MonitorsConfigMenuToggle {
_init(extensionObject) {
super._init(
extensionObject,
{
title: _("Resolution"),
// subtitle: _("Example Subtitle"),
iconName: "computer-symbolic",
toggleMode: false,
checked: true
}
)
this._monitorConfigParameter = MonitorConfigParameters.RESOLUTION;
this.menu.setHeader("computer-symbolic", _("Resolution"));
// // Add an entry-point for more settings
// this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
// const settingsItem = this.menu.addAction('More Settings',
// () => extensionObject.openPreferences());
// // Ensure the settings are unavailable when the screen is locked
// settingsItem.visible = Main.sessionMode.allowSettings;
// this.menu._settingsActions[extensionObject.uuid] = settingsItem;
}
_getMonitorConfigElements(monitorName) {
return this._extensionObject.monitorsConfig[monitorName][MonitorConfigParameters.RESOLUTION]
}
_getMonitorConfigElementName(monitorConfigElement) {
return `${monitorConfigElement.horizontally}x${monitorConfigElement.vertically}`;
}
}
);
export const RefreshRateMenuToggle = GObject.registerClass(
class RefreshRateMenuToggle extends MonitorsConfigMenuToggle {
_init(extensionObject) {
super._init(
extensionObject,
{
title: _("Refresh Rate"),
// subtitle: _("Example Subtitle"),
iconName: "tablet-symbolic",
toggleMode: false,
checked: true
}
)
this._monitorConfigParameter = MonitorConfigParameters.REFRESH_RATE;
this.menu.setHeader("computer-symbolic", _("Refresh Rate"));
}
_getMonitorConfigElements(monitorName) {
let currentResolution = this._extensionObject.monitorsConfig[monitorName][MonitorConfigParameters.RESOLUTION].find(el => el.isCurrent);
return currentResolution[MonitorConfigParameters.REFRESH_RATE]
}
_getMonitorConfigElementName(monitorConfigElement) {
return monitorConfigElement.value;
}
}
);