forked from fawtytoo/activities-icons
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.js
125 lines (102 loc) · 3.64 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
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 Lang = imports.lang;
let activities;
let button;
const ActivitiesIcons = new Lang.Class({
Name: 'ActivitiesIcons',
Extends: PanelMenu.Button,
_init()
{
this.parent(0.0, null, true);
this.wm = global.workspace_manager;
this.box = new St.BoxLayout({style_class: 'activity-box'});
this.appButton = new St.Button();
this.appIcon = new St.Icon({icon_name: 'view-app-grid-symbolic', style_class: 'activity-icon'});
this.appButton.add_actor(this.appIcon);
this.appButton.connect('clicked', () => this._changePage(true));
this.appButton.connect('scroll-event', (actor, event) => this._scrollWindows(actor, event));
this.box.add_actor(this.appButton);
this.overButton = new St.Button();
this.overIcon = new St.Icon({icon_name: 'focus-windows-symbolic', style_class: 'activity-icon-ws'});
this.overButton.add_actor(this.overIcon);
this.overButton.connect('clicked', () => this._changePage(false));
this.overButton.connect('scroll-event', (actor, event) => this._scrollWorkspace(actor, event));
this.box.add_actor(this.overButton);
this.actor.add_child(this.box);
},
destroy()
{
this.parent();
},
_changePage(appsButtonChecked)
{
// selecting the same view again will hide the overview
if (Main.overview.visible && appsButtonChecked == Main.overview.viewSelector._showAppsButton.checked)
{
Main.overview.hide();
return;
}
Main.overview.viewSelector._showAppsButton.checked = appsButtonChecked;
if (!Main.overview.visible)
Main.overview.show();
else
Main.overview.viewSelector._showAppsButtonToggled();
},
_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;
},
_scrollWorkspace(actor, 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(Meta.MotionDirection.UP).activate(global.get_current_time());
break;
case Clutter.ScrollDirection.DOWN:
if (workspace.index() + 1 == this.wm.n_workspaces)
return;
else
workspace.get_neighbor(Meta.MotionDirection.DOWN).activate(global.get_current_time());
break;
}
return Clutter.EVENT_STOP;
}
});
function init()
{
activities = Main.panel.statusArea['activities'];
}
function enable()
{
button = new ActivitiesIcons();
activities.container.hide();
Main.panel.addToStatusArea('activitiesicons', button, 0, 'left');
}
function disable()
{
button.destroy();
activities.container.show();
}