/usr/share/gnome-shell/extensions/TaskBar@zpydr/windows.js is in gnome-shell-extension-taskbar 57.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // GNOME Shell Extension TaskBar
// Copyright (C) 2013-2018 zpydr
//
// Version 57
//
// This program 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.
//
// This program 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 <https://www.gnu.org/licenses/>.
//
// zpydr@openmailbox.org
const Lang = imports.lang;
function Windows(callBackThis, callbackWindowsListChanged, callbackWindowChanged) {
this.init(callBackThis, callbackWindowsListChanged, callbackWindowChanged);
}
Windows.prototype = {
workspace: null,
windowsList: [],
callBackThis: null,
callbackWindowsListChanged: null,
callbackWindowChanged: null,
workspaceSwitchSignal: null,
windowAddedSignal: null,
windowRemovedSignal: null,
windowsSignals: [],
init: function(callBackThis, callbackWindowsListChanged, callbackWindowChanged) {
//Set User Callback
this.callBackThis = callBackThis;
this.callbackWindowsListChanged = callbackWindowsListChanged;
this.callbackWindowChanged = callbackWindowChanged;
//Init WindowsList
this.workspaceSignals = new Map();
this.buildWindowsList();
this.onWorkspaceChanged();
//Add window manager signals
this.workspaceSwitchSignal = global.screen.connect('workspace-switched', Lang.bind(this, this.buildWindowsList));
this.nWorkspacesSignal = global.screen.connect('notify::n-workspaces', Lang.bind(this, this.onWorkspaceChanged));
},
destruct: function() {
//Remove window manager signals
let numWorkspaces = global.screen.n_workspaces;
for (let i = 0; i < numWorkspaces; i++) {
let workspace = global.screen.get_workspace_by_index(i);
let signals = this.workspaceSignals.get(workspace);
this.workspaceSignals.delete(workspace);
workspace.disconnect(signals.windowAddedId);
workspace.disconnect(signals.windowRemovedId);
}
//Clean windows list
this.cleanWindowsList();
},
onWorkspaceChanged: function() {
let numWorkspaces = global.screen.n_workspaces;
for (let i = 0; i < numWorkspaces; i++) {
let workspace = global.screen.get_workspace_by_index(i);
if (this.workspaceSignals.has(workspace))
continue;
let signals = {
windowAddedId: 0,
windowRemovedId: 0
};
signals.windowAddedId = workspace.connect_after('window-added', Lang.bind(this, this.buildWindowsList));
signals.windowRemovedId = workspace.connect('window-removed', Lang.bind(this, this.buildWindowsList));
this.workspaceSignals.set(workspace, signals);
}
},
buildWindowsList: function() {
//Clean windows list
this.cleanWindowsList();
//Build windows list
let totalWorkspaces = global.screen.n_workspaces;
for (let i = 0; i < totalWorkspaces; i++) {
let activeWorkspace = global.screen.get_workspace_by_index(i);
activeWorkspace.list_windows().sort(this.sortWindowsCompareFunction).forEach(
function(window) {
this.addWindowInList(window);
},
this
);
}
//Call User Callback
this.callbackWindowsListChanged.call(this.callBackThis, this.windowsList, 0, null);
},
sortWindowsCompareFunction: function(windowA, windowB) {
return windowA.get_stable_sequence() > windowB.get_stable_sequence();
},
onWindowChanged: function(window, object, type) {
if (type === 0) { //Focus changed
if (window.appears_focused) {
this.callbackWindowChanged.call(this.callBackThis, window, 0);
}
} else if (type === 1) { //Title changed
this.callbackWindowChanged.call(this.callBackThis, window, 1);
} else if (type === 2) { //Minimized
this.callbackWindowChanged.call(this.callBackThis, window, 2);
} else if (type === 3) { //Icon
this.callbackWindowChanged.call(this.callBackThis, window, 3);
} else if (type === 4) { //Icon
this.callbackWindowChanged.call(this.callBackThis, window, 4);
}
},
searchWindowInList: function(window) {
let index = null;
for (let indexWindow in this.windowsList) {
if (this.windowsList[indexWindow] === window) {
index = indexWindow;
break;
}
}
return index;
},
addWindowInList: function(window) {
let index = this.searchWindowInList(window);
if (index === null && !window.is_skip_taskbar()) {
this.windowsList.push(window);
//Add window signals
let objectAndSignals = [
window, [
window.connect('notify::appears-focused', Lang.bind(this, this.onWindowChanged, 0)),
window.connect('notify::title', Lang.bind(this, this.onWindowChanged, 1)),
window.connect('notify::minimized', Lang.bind(this, this.onWindowChanged, 2)),
window.connect('notify::wm-class', Lang.bind(this, this.onWindowChanged, 3)),
window.connect('notify::gtk-application-id', Lang.bind(this, this.onWindowChanged, 4))
]
];
this.windowsSignals.push(objectAndSignals);
return true;
} else
return false;
},
removeWindowInList: function(window) {
let index = this.searchWindowInList(window);
if (index !== null) {
this.windowsList.splice(index, 1);
//Remove window signals
for (let indexSignal in this.windowsSignals) {
let [object, signals] = this.windowsSignals[indexSignal];
if (object === window) {
signals.forEach(
function(signal) {
object.disconnect(signal);
},
this
);
this.windowsSignals.splice(indexSignal, 1);
break;
}
}
return true;
} else
return false;
},
cleanWindowsList: function() {
for (let i = this.windowsList.length - 1; i >= 0; i--)
this.removeWindowInList(this.windowsList[i]);
}
}
|