forked from mmai/Current_screen_only_on_window_switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
161 lines (140 loc) · 5.75 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
const { GObject } = imports.gi;
const PACKAGE_VERSION = imports.misc.config.PACKAGE_VERSION;
const altTab = imports.ui.altTab;
const main = imports.ui.main;
let injections = {};
function enable() {
if (cmpVersions(PACKAGE_VERSION, '3.32') < 0){
enable_older();
} else {
enable_3_32();
}
}
function disable() {
if (cmpVersions(PACKAGE_VERSION, '3.32') < 0){
disable_older();
} else {
disable_3_32();
}
}
/*******************************
* gnome-shell >= 3.32 *
*******************************/
function enable_3_32() {
injections['getWindows'] = altTab.getWindows;
altTab.getWindows = function() {
let allWindows = injections['getWindows'].apply(this, arguments);
return allWindows.filter(w => w.get_monitor() === getCurrentMonitor());
}
injections['WindowSwitcherPopup'] = altTab.WindowSwitcherPopup;
altTab.WindowSwitcherPopup = GObject.registerClass(
class CurrentMonitorWindowSwitcherPopup extends altTab.WindowSwitcherPopup {
vfunc_allocate() {
let originalPrimaryMonitor = main.layoutManager.primaryMonitor;
main.layoutManager.primaryMonitor = main.layoutManager.currentMonitor;
let response = super.vfunc_allocate.apply(this, arguments);
main.layoutManager.primaryMonitor = originalPrimaryMonitor;
return response;
}
});
injections['appSwitcherPopup'] = altTab.AppSwitcherPopup;
altTab.AppSwitcherPopup = GObject.registerClass(
class CurrentMonitorAppSwitcherPopup extends altTab.AppSwitcherPopup {
vfunc_allocate() {
let originalPrimaryMonitor = main.layoutManager.primaryMonitor;
main.layoutManager.primaryMonitor = main.layoutManager.currentMonitor;
let response = super.vfunc_allocate.apply(this, arguments);
main.layoutManager.primaryMonitor = originalPrimaryMonitor;
return response;
}
});
injections['appSwitcher'] = altTab.AppSwitcher;
altTab.AppSwitcher = GObject.registerClass(
class CurrentMonitorAppSwitcher extends altTab.AppSwitcher {
_addIcon(icon) {
icon.cachedWindows = icon.cachedWindows.filter(w => w.get_monitor() === getCurrentMonitor());
if(icon.cachedWindows.length === 0){
return;
}
return super._addIcon.call(this, icon);
}
});
}
function disable_3_32(){
altTab.getWindows = injections['getWindows'];
altTab.WindowSwitcherPopup = injections['WindowSwitcherPopup'];
altTab.AppSwitcherPopup = injections['appSwitcherPopup'];
altTab.AppSwitcher = injections['appSwitcher'];
}
/*******************************
* gnome-shell < 3.32 *
*******************************/
function enable_older() {
injections['_getWindowList'] = altTab.WindowSwitcherPopup.prototype._getWindowList;
altTab.WindowSwitcherPopup.prototype._getWindowList = function() {
let allWindows = injections['_getWindowList'].apply(this, arguments);
return allWindows.filter(w => w.get_monitor() === getCurrentMonitor());
}
injections['_getPreferredWidth'] = altTab.WindowSwitcherPopup.prototype._getPreferredWidth;
altTab.WindowSwitcherPopup.prototype._getPreferredWidth = function() {
let originalPrimaryMonitor = main.layoutManager.primaryMonitor;
main.layoutManager.primaryMonitor = main.layoutManager.currentMonitor;
let response = injections['_getPreferredWidth'].apply(this, arguments);
main.layoutManager.primaryMonitor = originalPrimaryMonitor;
return response;
}
injections['_getPreferredHeight'] = altTab.WindowSwitcherPopup.prototype._getPreferredHeight;
altTab.WindowSwitcherPopup.prototype._getPreferredHeight = function() {
let originalPrimaryMonitor = main.layoutManager.primaryMonitor;
main.layoutManager.primaryMonitor = main.layoutManager.currentMonitor;
let response = injections['_getPreferredHeight'].apply(this, arguments);
main.layoutManager.primaryMonitor = originalPrimaryMonitor;
return response;
}
injections['_allocate'] = altTab.WindowSwitcherPopup.prototype._allocate;
altTab.WindowSwitcherPopup.prototype._allocate = function() {
let originalPrimaryMonitor = main.layoutManager.primaryMonitor;
main.layoutManager.primaryMonitor = main.layoutManager.currentMonitor;
let response = injections['_allocate'].apply(this, arguments);
main.layoutManager.primaryMonitor = originalPrimaryMonitor;
return response;
}
injections['_addIcon'] = altTab.AppSwitcher.prototype._addIcon;
altTab.AppSwitcher.prototype._addIcon = function(icon) {
icon.cachedWindows = icon.cachedWindows.filter(w => w.get_monitor() === getCurrentMonitor());
if(icon.cachedWindows.length === 0) {
return;
}
return injections['_addIcon'].call(this, icon);
}
}
function disable_older(){
altTab.WindowSwitcherPopup.prototype._getWindowList = injections['_getWindowList'];
altTab.WindowSwitcherPopup.prototype._getPreferredWidth = injections['_getPreferredWidth'];
altTab.WindowSwitcherPopup.prototype._getPreferredHeight = injections['_getPreferredHeight'];
altTab.WindowSwitcherPopup.prototype._allocate = injections['_allocate'];
altTab.AppSwitcher.prototype._addIcon = injections['_addIcon'];
}
/*******************************
* utils *
*******************************/
function getCurrentMonitor(){
if (cmpVersions(PACKAGE_VERSION, '3.30') < 0){
return global.screen.get_current_monitor();
}
return global.display.get_current_monitor();
}
function cmpVersions (a, b) {
var i, diff;
var regExStrip0 = /(\.0+)+$/;
var segmentsA = a.replace(regExStrip0, '').split('.');
var segmentsB = b.replace(regExStrip0, '').split('.');
var l = Math.min(segmentsA.length, segmentsB.length);
for (i = 0; i < l; i++) {
diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
if (diff) {
return diff;
}
}
return segmentsA.length - segmentsB.length;
}