forked from markakritas/activities-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
189 lines (154 loc) · 5.37 KB
/
extension.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
186
187
188
189
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
const Meta = imports.gi.Meta;
const GObject = imports.gi.GObject;
const Config = imports.misc.config;
const Version = parseInt(Config.PACKAGE_VERSION.split('.')[0]);
const ShowAppsButton = Version == 3 ? Main.overview.viewSelector._showAppsButton : Main.overview.dash.showAppsButton;
const MainOverview = Version == 3 ? Main.overview.viewSelector : Main.overview.dash;
const OverviewShowApps = Version == 3 ? Main.overview.viewSelector : Main.overview;
const DirBack = Version == 3 ? Meta.MotionDirection.UP : Meta.MotionDirection.LEFT;
const DirForward = Version == 3 ? Meta.MotionDirection.DOWN : Meta.MotionDirection.RIGHT;
let activities;
let buttonWorkspace;
let buttonApps;
const AppsIcon = GObject.registerClass(
class AppsIcon extends PanelMenu.Button {
_init()
{
super._init()
this.wm = global.workspace_manager;
this.box = new St.BoxLayout({style_class: 'activity-box'});
this.appButton = new St.Button();
this.appButton.child = new St.Icon({icon_name: 'view-app-grid-symbolic', style_class: 'system-status-icon activity-icon'});
this.appButton.connect('clicked', () => this._changePage(true));
this.appButton.connect('scroll-event', (self, event) => this._scrollWindows(self, event));
this.box.add_child(this.appButton);
this.add_child(this.box);
}
destroy()
{
this.parent();
}
_changePage(appsButtonChecked)
{
// selecting the same view again will hide the overview
if (Main.overview.visible && appsButtonChecked == ShowAppsButton.checked)
{
Main.overview.hide();
return;
}
ShowAppsButton.checked = appsButtonChecked;
if (!Main.overview.visible)
{
if (appsButtonChecked)
OverviewShowApps.showApps();
else
Main.overview.show();
}
else
{
ShowAppsButton.checked = appsButtonChecked;
MainOverview._onShowAppsButtonToggled();
}
}
_scrollWindows(actor, event)
{
let workspace = this.wm.get_active_workspace();
let windows = global.display.get_tab_list(Meta.TabList.NORMAL_ALL, workspace);
if (windows.length < 2)
return;
switch (event.get_scroll_direction())
{
case Clutter.ScrollDirection.UP:
windows[windows.length - 1].activate(global.get_current_time());
break;
case Clutter.ScrollDirection.DOWN:
windows[windows.length - windows.length > 2 ? 2 : 1].activate(global.get_current_time());
//windows[0].lower(); // the windows loses focus using this method
break;
}
return Clutter.EVENT_STOP;
}
});
const WorkspaceIcon = GObject.registerClass(
class WorkspaceIcon extends PanelMenu.Button {
_init()
{
super._init();
this.wm = global.workspace_manager;
this.box = new St.BoxLayout({style_class: 'activity-box'});
this.overButton = new St.Button();
this.overButton.child = new St.Icon({icon_name: 'focus-windows-symbolic', style_class: 'system-status-icon activity-icon-ws'});
this.overButton.connect('clicked', () => this._changePage(false));
this.overButton.connect('scroll-event', (self, event) => this._scrollWorkspace(self, event));
this.box.add_child(this.overButton);
this.add_child(this.box);
}
destroy()
{
this.parent();
}
_changePage(appsButtonChecked)
{
// selecting the same view again will hide the overview
if (Main.overview.visible && appsButtonChecked == ShowAppsButton.checked)
{
Main.overview.hide();
return;
}
ShowAppsButton.checked = appsButtonChecked;
if (!Main.overview.visible)
{
if (appsButtonChecked)
OverviewShowApps.showApps();
else
Main.overview.show();
}
else
{
ShowAppsButton.checked = appsButtonChecked;
MainOverview._onShowAppsButtonToggled();
}
}
_scrollWorkspace(self, event)
{
let workspace = this.wm.get_active_workspace();
switch (event.get_scroll_direction())
{
case Clutter.ScrollDirection.UP:
if (workspace.index() == 0)
return;
else
workspace.get_neighbor(DirBack).activate(global.get_current_time());
break;
case Clutter.ScrollDirection.DOWN:
if (workspace.index() + 1 == this.wm.n_workspaces)
return;
else
workspace.get_neighbor(DirForward).activate(global.get_current_time());
break;
}
return Clutter.EVENT_STOP;
}
});
function init()
{
activities = Main.panel.statusArea['activities'];
}
function enable()
{
buttonWorkspace = new WorkspaceIcon();
buttonApps = new AppsIcon();
activities.container.hide();
Main.panel.addToStatusArea('WorskpaceIcon', buttonWorkspace, 1, 'left');
Main.panel.addToStatusArea('AppsIcon', buttonApps, 0, 'left');
}
function disable()
{
buttonWorkspace.destroy();
buttonApps.destroy();
activities.container.show();
}