forked from Ed-von-Schleck/gnome-shell-edge-flipping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
executable file
·219 lines (193 loc) · 8.71 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
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
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* edge-fipping
* Copyright (C) 2012 Agus Lopez <[email protected]>,
* Christian Schramm <[email protected]>
*
* edge-flipping 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.
*
* edge-flipping 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/>.
*/
const Clutter = imports.gi.Clutter;
const Lang = imports.lang;
const Main = imports.ui.main
const Mainloop = imports.mainloop;
const WorkspaceSwitcherPopup = imports.ui.workspaceSwitcherPopup;
const Meta = imports.gi.Meta
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
// Object structure
const EdgeFlipping = new Lang.Class({
Name: 'EdgeFlipping',
_init: function() {
this._settings = Convenience.getSettings();
// Calculate some variables
this._monitor = Main.layoutManager.primaryMonitor;
let offsetx = this._monitor.width * this._settings.get_int("offset")/100;
let offsety = this._monitor.height * this._settings.get_int("offset")/100;
let size = this._settings.get_int("size");
// create all four edges and set reactivity to whether they are enabled
// or not
this._edges = {};
this._edges["top"] = new Clutter.Rectangle ({
name: "top-edge",
x: this._monitor.x + offsetx,
y: this._monitor.y,
width: this._monitor.width - 2 * offsetx,
height: size,
reactive: this._settings.get_boolean("enable-vertical")
});
this._edges["bottom"] = new Clutter.Rectangle ({
name: "bottom-edge",
x: this._monitor.x + offsetx,
y: this._monitor.height - size,
width: this._monitor.width - 2 * offsetx,
height: size,
reactive: this._settings.get_boolean("enable-vertical")
});
this._edges["right"] = new Clutter.Rectangle ({
name: "right-edge",
x: this._monitor.width - size,
y: this._monitor.y + offsety,
width: size,
height: this._monitor.height - 2 * offsety,
reactive: this._settings.get_boolean("enable-horizontal")
});
this._edges["left"] = new Clutter.Rectangle ({
name: "left-edge",
x: this._monitor.x,
y: this._monitor.y + offsety,
width: size,
height: this._monitor.height - 2 * offsety,
reactive: this._settings.get_boolean("enable-horizontal")
});
for (var edge in this._edges) {
this._edges[edge].connect ('enter-event', Lang.bind (this, this._switchWorkspace));
this._edges[edge].connect ('leave-event', Lang.bind (this, this._removeTimeout));
this._edges[edge].opacity = this._settings.get_int("opacity");
Main.layoutManager.addChrome (this._edges[edge], { trackFullscreen: true });
};
// When display setup changes, recreate edges
global.screen.connect('monitors-changed', Lang.bind(this, this._resetEdges));
// Monitor changes on edge offset
this._settings.connect('changed::offset', Lang.bind(this, function(){
let offsetx = this._monitor.width * this._settings.get_int("offset")/100;
let offsety = this._monitor.height * this._settings.get_int("offset")/100;
this._edges["top"].x = this._edges["bottom"].x = this._monitor.x + offsetx;
this._edges["top"].width = this._edges["bottom"].width = this._monitor.width - 2 * offsetx;
this._edges["right"].y = this._edges["left"].y = this._monitor.y + offsety;
this._edges["right"].height = this._edges["left"].height = this._monitor.height - 2 * offsety;
}));
// Monitor changes on edge size
this._settings.connect('changed::size', Lang.bind(this, function(){
let size = this._settings.get_int("size");
this._edges["top"].height = size;
this._edges["bottom"].height = size;
this._edges["right"].width = size;
this._edges["left"].width = size;
this._edges["bottom"].y = this._monitor.height - size;
this._edges["right"].x = this._monitor.width - size;
}));
// Monitor changes on edge opacity
this._settings.connect('changed::opacity', Lang.bind(this, function(){
for (edge in this._edges) {
this._edges[edge].set_opacity(this._settings.get_int("opacity"));
}
}));
// When enabling or disabling vertical flipping, set reactivity of correspinding edge
this._settings.connect('changed::enable-vertical', Lang.bind(this, function(){
this._edges["bottom"].set_reactive(this._settings.get_boolean("enable-vertical"));
this._edges["top"].set_reactive(this._settings.get_boolean("enable-vertical"));
}));
// Likewise with horizontal flipping
this._settings.connect('changed::enable-horizontal', Lang.bind(this, function(){
this._edges["left"].set_reactive(this._settings.get_boolean("enable-horizontal"));
this._edges["right"].set_reactive(this._settings.get_boolean("enable-horizontal"));
}));
},
_switchWorkspace: function (actor, event) {
this._initialDelayTimeoutId = Mainloop.timeout_add (this._settings.get_int("delay-timeout"), Lang.bind(this, function() {
var ws;
let activews = global.screen.get_active_workspace();
switch (actor.name) {
case "top-edge":
ws = activews.get_neighbor(Meta.MotionDirection.UP);
break;
case "bottom-edge":
ws = activews.get_neighbor(Meta.MotionDirection.DOWN);
break;
case "right-edge":
ws = activews.get_neighbor(Meta.MotionDirection.RIGHT);
break;
case "left-edge":
ws = activews.get_neighbor(Meta.MotionDirection.LEFT);
break;
};
if( ws != null ) {
Main.wm.actionMoveWorkspace(ws);
}
// Check if we are in the last workspace on either end
// and continuous switching is enabled
let currentWorkspace = global.screen.get_active_workspace_index();
let lastWorkspace = global.screen.n_workspaces - 1;
if ( actor.name == "top-edge" || actor.name == "left-edge" ) {
if ( this._settings.get_boolean("continue") && currentWorkspace != 0 )
// If not, return true for the process to repeat
return true;
} else if ( actor.name == "bottom-edge" || actor.name == "right-edge" ) {
if ( this._settings.get_boolean("continue") && currentWorkspace != lastWorkspace )
// If not, return true for the process to repeat
return true;
}
// If not, return false so timeout is automatically removed
this._initialDelayTimeoutId = 0;
return false;
}));
},
_removeTimeout: function (actor, event) {
// If timeout exists, remove it
if (this._initialDelayTimeoutId != 0) {
Mainloop.source_remove(this._initialDelayTimeoutId);
this._initialDelayTimeoutId = 0;
}
},
_resetEdges: function (actor, event) {
// Remove edges
this.destroy();
// Recreate edges
this._init();
},
destroy: function() {
// Remove timeout
this._removeTimeout();
// Remove and destroy all edges that were enabled
for (var edge in this._edges) {
Main.layoutManager.removeChrome (this._edges[edge]);
this._edges[edge].destroy();
}
}
})
function init() {
if (Main.wm._workspaceSwitcherPopup == null)
Main.wm._workspaceSwitcherPopup = new WorkspaceSwitcherPopup.WorkspaceSwitcherPopup();
}
// Enable extension
var switcher;
function enable() {
switcher = new EdgeFlipping();
}
// Disable extension
function disable() {
switcher.destroy();
}
/* vim: set shiftwidth=4 tabstop=4 expandtab : */