forked from paperwm/PaperWM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liveAltTab.js
175 lines (150 loc) · 5.99 KB
/
liveAltTab.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
var Extension;
if (imports.misc.extensionUtils.extensions) {
Extension = imports.misc.extensionUtils.extensions["paperwm@hedning:matrix.org"];
} else {
Extension = imports.ui.main.extensionManager.lookup("paperwm@hedning:matrix.org");
}
var Clutter = imports.gi.Clutter;
var Meta = imports.gi.Meta;
var AltTab = imports.ui.altTab;
var Main = imports.ui.main;
var Tweener = Extension.imports.utils.tweener;
var Scratch = Extension.imports.scratch;
var Tiling = Extension.imports.tiling;
var Keybindings = Extension.imports.keybindings;
var utils = Extension.imports.utils;
var debug = utils.debug;
var prefs = Extension.imports.settings.prefs;
var LiveAltTab = utils.registerClass(
class LiveAltTab extends AltTab.WindowSwitcherPopup {
_init(reverse) {
this.reverse = reverse;
super._init();
}
_getWindowList(reverse) {
let tabList = global.display.get_tab_list(
Meta.TabList.NORMAL_ALL,
global.workspace_manager.get_active_workspace())
.filter(w => !Scratch.isScratchWindow(w));
let scratch = Scratch.getScratchWindows();
if (Scratch.isScratchWindow(global.display.focus_window)) {
// Access scratch windows in mru order with shift-super-tab
return scratch.concat(this.reverse ? tabList.reverse() : tabList);
} else {
return tabList.concat(this.reverse ? scratch.reverse() : scratch);
}
}
_initialSelection(backward, actionName) {
this.space = Tiling.spaces.selectedSpace;
this.space.startAnimate();
let monitor = Tiling.spaces.selectedSpace.monitor;
let workArea = Main.layoutManager.getWorkAreaForMonitor(monitor.index);
let fog = new Clutter.Actor({x: workArea.x, y: workArea.y,
width: workArea.width, height: workArea.height,
opacity: 0
});
// this.blur = new Clutter.BlurEffect();
// this.space.cloneContainer.add_effect(this.blur);
this.space.setSelectionInactive();
fog.background_color = Clutter.color_from_string("black")[1];
Tweener.addTween(fog, {
time: prefs.animation_time,
opacity: 100,
});
Main.uiGroup.insert_child_above(fog, global.window_group);
this.fog = fog;
super._initialSelection(backward, actionName);
}
_keyPressHandler(keysym, mutterActionId) {
if (keysym === Clutter.KEY_Escape)
return Clutter.EVENT_PROPAGATE;
// After the first super-tab the mutterActionId we get is apparently
// SWITCH_APPLICATIONS so we need to case on those too.
switch(mutterActionId) {
case Meta.KeyBindingAction.SWITCH_APPLICATIONS:
mutterActionId = Meta.KeyBindingAction.SWITCH_WINDOWS;
break;
case Meta.KeyBindingAction.SWITCH_APPLICATIONS_BACKWARD:
mutterActionId = Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD;
break;
case Keybindings.idOf('live-alt-tab'):
mutterActionId = Meta.KeyBindingAction.SWITCH_WINDOWS;
break;
;;
case Keybindings.idOf('live-alt-tab-backward'):
mutterActionId = Meta.KeyBindingAction.SWITCH_WINDOWS_BACKWARD;
break;
;;
}
// let action = Keybindings.byId(mutterActionId);
// if (action && action.options.activeInNavigator) {
// let space = Tiling.spaces.selectedSpace;
// let metaWindow = space.selectedWindow;
// action.handler(metaWindow, space);
// return true;
// }
return super._keyPressHandler(keysym, mutterActionId);
}
_select(num) {
let from = this._switcherList.windows[this._selectedIndex];
let to = this._switcherList.windows[num];
this.clone && this.clone.destroy();
this.clone = null;
let actor = to.get_compositor_private();
let frame = to.get_frame_rect();
let clone = new Clutter.Clone({source: actor});
clone.position = actor.position;
let space = Tiling.spaces.spaceOfWindow(to);
if (space.indexOf(to) !== -1) {
clone.x = Tiling.ensuredX(to, space) + space.monitor.x;
clone.x -= frame.x - actor.x;
}
this.clone = clone;
Main.uiGroup.insert_child_above(clone, this.fog);
// Tiling.ensureViewport(to, space);
this._selectedIndex = num;
this._switcherList.highlight(num);
}
_finish() {
this.was_accepted = true;
super._finish();
}
_itemEnteredHandler() {
// The item-enter (mouse hover) event is triggered even after a item is
// accepted. This can cause _select to run on the item below the pointer
// ensuring the wrong window.
if(!this.was_accepted) {
super._itemEnteredHandler.apply(this, arguments);
}
}
_onDestroy() {
super._onDestroy();
debug('#preview', 'onDestroy', this.was_accepted);
if(!this.was_accepted) {
// Select the starting window
this._select(0);
}
Tweener.addTween(this.fog, {
time: prefs.animation_time,
opacity: 0,
onComplete: () => {
this.fog.destroy();
this.fog = null;
// this.space.cloneContainer.remove_effect(this.blur);
this.clone && this.clone.destroy();
this.clone = null;
this.space.moveDone();
}
});
let to = this._switcherList.windows[this._selectedIndex];
Tiling.focus_handler(to);
let actor = to.get_compositor_private();
actor.x = this.clone.x;
actor.y = this.clone.y;
actor.set_scale(1, 1);
}
});
function liveAltTab(meta_window, space, {display, screen, binding}) {
let tabPopup = new LiveAltTab(binding.is_reversed());
tabPopup.show(binding.is_reversed(), binding.get_name(), binding.get_mask());
}