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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
/*
Copyright (C) 2014 spin83
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 2
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, visit https://www.gnu.org/licenses/.
*/
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const Meta = imports.gi.Meta;
const Main = imports.ui.main;
const WorkspacesView = imports.ui.workspacesView;
const ExtensionUtils = imports.misc.extensionUtils;
const MultiMonitors = ExtensionUtils.getCurrentExtension();
const Convenience = MultiMonitors.imports.convenience;
const MMLayout = MultiMonitors.imports.mmlayout;
const MMOverview = MultiMonitors.imports.mmoverview;
const MMIndicator = MultiMonitors.imports.indicator;
const Config = imports.misc.config;
const OVERRIDE_SCHEMA = 'org.gnome.shell.overrides';
const MUTTER_SCHEMA = 'org.gnome.mutter';
const WORKSPACES_ONLY_ON_PRIMARY_ID = 'workspaces-only-on-primary';
const SHOW_INDICATOR_ID = 'show-indicator';
const SHOW_THUMBNAILS_SLIDER_ID = 'show-thumbnails-slider';
const MultiMonitorsAddOn = new Lang.Class({
Name: 'MultiMonitorsAddOn',
_init() {
this._settings = Convenience.getSettings();
this._ov_settings = new Gio.Settings({ schema: OVERRIDE_SCHEMA });
this._mu_settings = new Gio.Settings({ schema: MUTTER_SCHEMA });
this._currentVersion = Config.PACKAGE_VERSION.split('.');
this.mmIndicator = null;
Main.mmOverview = null;
Main.mmLayoutManager = null;
this._mmMonitors = 0;
},
_showIndicator() {
if(this._settings.get_boolean(SHOW_INDICATOR_ID)) {
if(!this.mmIndicator) {
this.mmIndicator = Main.panel.addToStatusArea('MultiMonitorsAddOn', new MMIndicator.MultiMonitorsIndicator());
}
}
else {
this._hideIndicator();
}
},
_hideIndicator() {
if(this.mmIndicator) {
this.mmIndicator.destroy();
this.mmIndicator = null;
}
},
_showThumbnailsSlider() {
if(this._settings.get_boolean(SHOW_THUMBNAILS_SLIDER_ID)){
if(this._ov_settings.get_boolean(WORKSPACES_ONLY_ON_PRIMARY_ID))
this._ov_settings.set_boolean(WORKSPACES_ONLY_ON_PRIMARY_ID, false);
if(this._mu_settings.get_boolean(WORKSPACES_ONLY_ON_PRIMARY_ID))
this._mu_settings.set_boolean(WORKSPACES_ONLY_ON_PRIMARY_ID, false);
Main.mmOverview = [];
for (let i = 0; i < Main.layoutManager.monitors.length; i++) {
let monitor = Main.layoutManager.monitors[i];
if(i != Main.layoutManager.primaryIndex) {
Main.mmOverview[i] = new MMOverview.MultiMonitorsOverview(i);
Main.mmOverview[i].init();
}
}
if (Main.overview.visible)
return;
let workspacesDisplay = Main.overview.viewSelector._workspacesDisplay;
if (workspacesDisplay._restackedNotifyId === undefined) {
workspacesDisplay._restackedNotifyId = 0;
}
workspacesDisplay.hide();
workspacesDisplay.actor._delegate = null;
workspacesDisplay.actor.destroy();
Main.overview.viewSelector._workspacesPage.hide();
Main.overview.viewSelector._workspacesPage.destroy();
workspacesDisplay.actor = null;
workspacesDisplay = new MMOverview.MultiMonitorsWorkspacesDisplay();
Main.overview.viewSelector._workspacesDisplay = workspacesDisplay;
Main.overview.viewSelector._workspacesPage = Main.overview.viewSelector._addPage(workspacesDisplay.actor,
_("Windows"), 'focus-windows-symbolic');
if (Main.overview.visible) {
Main.overview._controls._updateWorkspacesGeometry();
Main.overview.viewSelector._workspacesPage.show();
workspacesDisplay.show();
}
}
else{
this._hideThumbnailsSlider();
}
},
_hideThumbnailsSlider() {
if (Main.mmOverview) {
if (!Main.overview.visible) {
let workspacesDisplay = Main.overview.viewSelector._workspacesDisplay;
workspacesDisplay.hide();
workspacesDisplay.actor._delegate = null;
workspacesDisplay.actor.destroy();
Main.overview.viewSelector._workspacesPage.hide();
Main.overview.viewSelector._workspacesPage.destroy();
workspacesDisplay.actor = null;
workspacesDisplay = new WorkspacesView.WorkspacesDisplay();
Main.overview.viewSelector._workspacesDisplay = workspacesDisplay;
Main.overview.viewSelector._workspacesPage = Main.overview.viewSelector._addPage(workspacesDisplay.actor,
_("Windows"), 'focus-windows-symbolic');
}
for (let i = 0; i < Main.mmOverview.length; i++) {
if(Main.mmOverview[i])
Main.mmOverview[i].destroy();
}
Main.mmOverview = null;
}
},
_relayout() {
// global.log(".....................................................................")
if(this._mmMonitors!=Main.layoutManager.monitors.length){
this._mmMonitors = Main.layoutManager.monitors.length;
global.log("pi:"+Main.layoutManager.primaryIndex);
for (let i = 0; i < Main.layoutManager.monitors.length; i++) {
let monitor = Main.layoutManager.monitors[i];
global.log("i:"+i+" x:"+monitor.x+" y:"+monitor.y+" w:"+monitor.width+" h:"+monitor.height);
}
this._hideThumbnailsSlider();
this._showThumbnailsSlider();
}
},
_switchOffThumbnails() {
if(this._ov_settings.get_boolean(WORKSPACES_ONLY_ON_PRIMARY_ID))
this._settings.set_boolean(SHOW_THUMBNAILS_SLIDER_ID, false);
if(this._mu_settings.get_boolean(WORKSPACES_ONLY_ON_PRIMARY_ID))
this._settings.set_boolean(SHOW_THUMBNAILS_SLIDER_ID, false);
},
enable(version) {
global.log("Enable Multi Monitors Add-On ("+version+")...")
if(Main.panel.statusArea.MultiMonitorsAddOn)
disable();
this._mmMonitors = 0;
this._switchOffThumbnailsOvId = this._ov_settings.connect('changed::'+WORKSPACES_ONLY_ON_PRIMARY_ID,
this._switchOffThumbnails.bind(this));
this._switchOffThumbnailsMuId = this._mu_settings.connect('changed::'+WORKSPACES_ONLY_ON_PRIMARY_ID,
this._switchOffThumbnails.bind(this));
this._showIndicatorId = this._settings.connect('changed::'+SHOW_INDICATOR_ID, this._showIndicator.bind(this));
this._showIndicator();
Main.mmLayoutManager = new MMLayout.MultiMonitorsLayoutManager();
this._showPanelId = this._settings.connect('changed::'+MMLayout.SHOW_PANEL_ID, Main.mmLayoutManager.showPanel.bind(Main.mmLayoutManager));
Main.mmLayoutManager.showPanel();
this._showThumbnailsSliderId = this._settings.connect('changed::'+SHOW_THUMBNAILS_SLIDER_ID, this._showThumbnailsSlider.bind(this));
this._relayoutId = Main.layoutManager.connect('monitors-changed', this._relayout.bind(this));
this._relayout();
},
disable() {
Main.layoutManager.disconnect(this._relayoutId);
this._ov_settings.disconnect(this._switchOffThumbnailsOvId);
this._mu_settings.disconnect(this._switchOffThumbnailsMuId);
this._settings.disconnect(this._showPanelId);
this._settings.disconnect(this._showThumbnailsSliderId);
this._settings.disconnect(this._showIndicatorId);
this._hideIndicator();
Main.mmLayoutManager.hidePanel();
Main.mmLayoutManager = null;
this._hideThumbnailsSlider();
this._mmMonitors = 0;
global.log("Disable Multi Monitors Add-On ...")
}
});
let multiMonitorsAddOn = null;
let version = null;
function init(extensionMeta) {
Convenience.initTranslations();
let theme = imports.gi.Gtk.IconTheme.get_default();
theme.append_search_path(extensionMeta.path + "/icons");
// fix bug in panel: Destroy function many time added to this same indicator.
Main.panel._ensureIndicator = function(role) {
let indicator = this.statusArea[role];
if (indicator) {
indicator.container.show();
return null;
}
else {
let constructor = PANEL_ITEM_IMPLEMENTATIONS[role];
if (!constructor) {
// This icon is not implemented (this is a bug)
return null;
}
indicator = new constructor(this);
this.statusArea[role] = indicator;
}
return indicator;
};
// fix bug in workspacesView: Object, has been already deallocated — impossible to access it.
WorkspacesView.WorkspacesDisplay.prototype._parentSet = function(actor, oldParent) {
if (oldParent && this._notifyOpacityId)
oldParent.disconnect(this._notifyOpacityId);
this._notifyOpacityId = 0;
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
if (!this.actor)
return;
let newParent = this.actor.get_parent();
if (!newParent)
return;
// This is kinda hackish - we want the primary view to
// appear as parent of this.actor, though in reality it
// is added directly to Main.layoutManager.overviewGroup
this._notifyOpacityId = newParent.connect('notify::opacity', () => {
let opacity = this.actor.get_parent().opacity;
let primaryView = this._getPrimaryView();
if (!primaryView)
return;
primaryView.actor.opacity = opacity;
primaryView.actor.visible = opacity != 0;
});
});
};
let metaVersion = MultiMonitors.metadata['version'];
if (Number.isFinite(metaVersion)) {
version = 'v'+Math.trunc(metaVersion);
switch(Math.round((metaVersion%1)*10)) {
case 0:
break;
case 1:
version += '+bugfix';
break;
case 2:
version += '+develop';
break;
default:
version += '+modified';
break;
}
}
else
version = metaVersion;
}
function enable() {
if (multiMonitorsAddOn !== null)
return;
multiMonitorsAddOn = new MultiMonitorsAddOn();
multiMonitorsAddOn.enable(version);
}
function disable() {
if (multiMonitorsAddOn == null)
return;
multiMonitorsAddOn.disable();
multiMonitorsAddOn = null;
}
|