forked from johnnyg/gnome-shell-extensions-coverflowalttab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanager.js
100 lines (83 loc) · 2.39 KB
/
manager.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
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
/* CoverflowAltTab::Manager
*
* This class is a helper class to start the actual switcher.
*/
const Lang = imports.lang;
const Main = imports.ui.main;
const CoverflowAltTab = imports.misc.extensionUtils.getCurrentExtension();
const Switcher = CoverflowAltTab.imports.switcher;
/**
* This class handles window events, so we can keep a stack of windows ordered
* by the most recently focused window.
*/
function Manager() {
this._init();
}
Manager.prototype = {
_init: function() {
},
_activateSelectedWindow: function(win) {
//if selected window has been destroyed after coverflow started, skip
if (win.get_compositor_private()!=null)
Main.activateWindow(win);
},
_removeSelectedWindow: function(win) {
win.delete(global.get_current_time());
},
_startWindowSwitcher: function (display, screen, window, binding) {
let windows = [];
let actions = {};
let currentWorkspace = screen.get_active_workspace();
let currentIndex = 0;
let mask = binding.get_mask();
// construct a list with all windows
let windowActors = global.get_window_actors();
for (let i in windowActors) {
windows.push(windowActors[i].get_meta_window());
}
windowActors = null;
windows.sort(Lang.bind(this,
function(win1, win2) {
let t1 = win1.get_user_time();
let t2 = win2.get_user_time();
return (t2 > t1) ? 1 : -1 ;
}
));
// filter by modes
if (binding.get_name() == 'switch-group') {
windows = windows.filter(
function(win) {
return win.get_workspace() == currentWorkspace && !win.is_skip_taskbar();
}
);
} else if (binding.get_name() == 'switch-panels') {
let focused = display.focus_window;
if (!focused)
focused = windows[0];
windows = windows.filter(
function(win) {
return win.get_wm_class() == focused.get_wm_class() && !win.is_skip_taskbar();
}
);
} else {
windows = windows.filter(
function(win) {
return !win.is_skip_taskbar();
}
);
}
if (windows.length) {
actions['activate_selected'] = this._activateSelectedWindow;
actions['remove_selected'] = this._removeSelectedWindow;
if (!display.focus_window) {
currentIndex = -1;
}
let switcher = new Switcher.Switcher(windows, actions);
switcher._currentIndex = currentIndex;
if (!switcher.show(display, binding, mask, window)) {
switcher.destroy();
}
}
},
}