forked from forge-ext/forge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel.js
130 lines (113 loc) · 3.94 KB
/
panel.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
/*
* This file is part of the Forge GNOME extension
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
"use strict";
// Gnome imports
const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
// Shell imports
const Button = imports.ui.panelMenu.Button;
const PopupMenuItem = imports.ui.popupMenu.PopupMenuItem;
const PopupSeparatorMenuItem = imports.ui.popupMenu.PopupSeparatorMenuItem;
const PopupSwitchMenuItem = imports.ui.popupMenu.PopupSwitchMenuItem;
// Extension imports
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
// Application imports
const Logger = Me.imports.logger;
const Msgs = Me.imports.messages;
var PanelIndicator = GObject.registerClass(
class PanelIndicator extends Button {
_init(settings, extWm) {
super._init(0.0, Msgs.panel_indicator_button_text);
this.settings = settings;
this.extWm = extWm;
let tileIconOff = Gio.icon_new_for_string(
`${Me.path}/icons/panel/focus-windows-symbolic.svg`
);
let tileIconOn = Gio.icon_new_for_string(`${Me.path}/icons/panel/view-dual-symbolic.svg`);
let workspaceIconOff = Gio.icon_new_for_string(
`${Me.path}/icons/panel/window-duplicate-symbolic.svg`
);
let buttonIcon = new St.Icon({
gicon: tileIconOn,
style_class: "system-status-icon",
});
this.buttonOn = tileIconOn;
this.buttonOff = tileIconOff;
this.buttonWsOff = workspaceIconOff;
this.icon = buttonIcon;
this._buildMenu();
this.settings.connect("changed", (_, settingName) => {
switch (settingName) {
case "tiling-mode-enabled":
case "workspace-skip-tile":
this.updateTileIcon();
this.tileSwitch.setToggleState(this._isTiled());
}
});
this.add_actor(this.icon);
this.updateTileIcon();
}
updateTileIcon() {
if (this._isTiled()) {
if (this.extWm.isCurrentWorkspaceTiled()) {
this.icon.gicon = this.buttonOn;
} else {
this.icon.gicon = this.buttonWsOff;
}
} else {
this.icon.gicon = this.buttonOff;
}
}
_buildMenu() {
// Tiling Mode switch
let tileSwitch = new PopupSwitchMenuItem(
Msgs.panel_indicator_tile_switch_text,
this._isTiled()
);
tileSwitch.connect("toggled", () => {
let state = tileSwitch.state;
this.settings.set_boolean("tiling-mode-enabled", state);
this.updateTileIcon();
});
this.tileSwitch = tileSwitch;
this.menu.addMenuItem(tileSwitch);
// Preferences Shortcut
let prefMenuItem = new PopupMenuItem(Msgs.panel_indicator_prefs_open_text);
prefMenuItem.connect("activate", () => {
const action = { name: "PrefsOpen" };
this.extWm.command(action);
});
this.menu.addMenuItem(prefMenuItem);
// Extension version
const gnomeVersion = imports.misc.config.PACKAGE_VERSION;
const versionLabel = new PopupMenuItem(
`Version ${Me.metadata.version} on GNOME ${gnomeVersion}`
);
this.menu.addMenuItem(versionLabel);
}
_isTiled() {
return this.settings.get_boolean("tiling-mode-enabled");
}
}
);