diff --git a/extension.js b/extension.js index e448f51..9dc3092 100644 --- a/extension.js +++ b/extension.js @@ -63,6 +63,13 @@ const PREVIOUSKEY = 'key-previous-task'; const NEXTKEY = 'key-next-task'; const DESKTOPKEY = 'key-toggle-desktop'; + +let workspaceManager; +if (global.screen) + workspaceManager = global.screen; // mutter < 3.29 +else + workspaceManager = global.workspace_manager; // mutter >= 3.29 + function init(extensionMeta) { return new TaskBar(extensionMeta, schema); } @@ -450,11 +457,11 @@ TaskBar.prototype = { //Disconnect Workspace Signals if (this.workspaceSwitchedId !== null) { - global.screen.disconnect(this.workspaceSwitchedId); + workspaceManager.disconnect(this.workspaceSwitchedId); this.workspaceSwitchedId = null; } if (this.nWorkspacesId !== null) { - global.screen.disconnect(this.nWorkspacesId); + workspaceManager.disconnect(this.nWorkspacesId); this.nWorkspacesId = null; } @@ -924,7 +931,7 @@ TaskBar.prototype = { keyPreviousTask: function() { this.previousTask = null; let focusWindow = global.display.focus_window; - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); this.tasksList.forEach( function(task) { let [windowTask, buttonTask, signalsTask] = task; @@ -947,7 +954,7 @@ TaskBar.prototype = { keyNextTask: function() { this.nextTask = false; let focusWindow = global.display.focus_window; - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); this.tasksList.forEach( function(task) { let [windowTask, buttonTask, signalsTask] = task; @@ -971,7 +978,7 @@ TaskBar.prototype = { keyToggleDesktop: function() { let maxWindows = false; let userTime = null; - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); let windows = activeWorkspace.list_windows().filter(function(w) { return w.get_window_type() !== Meta.WindowType.DESKTOP; }); @@ -1160,8 +1167,8 @@ TaskBar.prototype = { this.nWorkspacesId = null; if (this.settings.get_boolean("display-workspace-button")) { //Connect Workspace Changes - this.workspaceSwitchedId = global.screen.connect('workspace-switched', Lang.bind(this, this.updateWorkspaces)); - this.nWorkspacesId = global.screen.connect('notify::n-workspaces', Lang.bind(this, this.updateWorkspaces)); + this.workspaceSwitchedId = workspaceManager.connect('workspace-switched', Lang.bind(this, this.updateWorkspaces)); + this.nWorkspacesId = workspaceManager.connect('notify::n-workspaces', Lang.bind(this, this.updateWorkspaces)); this.buttonWorkspace = new St.Button({ style_class: "tkb-task-button" }); @@ -1183,9 +1190,9 @@ TaskBar.prototype = { }, updateWorkspaces: function() { - this.activeWorkspaceIndex = global.screen.get_active_workspace().index(); + this.activeWorkspaceIndex = workspaceManager.get_active_workspace().index(); let workspaceButtonWidth = this.settings.get_int("workspace-button-width"); - this.totalWorkspace = global.screen.n_workspaces - 1; + this.totalWorkspace = workspaceManager.n_workspaces - 1; let labelWorkspaceIndex = this.activeWorkspaceIndex + 1; let labelTotalWorkspace = this.totalWorkspace + 1; if (this.settings.get_enum("workspace-button-index") === 1) { @@ -1711,13 +1718,13 @@ TaskBar.prototype = { { if (this.activeWorkspaceIndex === this.totalWorkspace) this.activeWorkspaceIndex = -1; - let newActiveWorkspace = global.screen.get_workspace_by_index(this.activeWorkspaceIndex + 1); + let newActiveWorkspace = workspaceManager.get_workspace_by_index(this.activeWorkspaceIndex + 1); newActiveWorkspace.activate(global.get_current_time()); } else if (numButton === RIGHTBUTTON) //Right Button { if (this.activeWorkspaceIndex === 0) this.activeWorkspaceIndex = this.totalWorkspace + 1; - let newActiveWorkspace = global.screen.get_workspace_by_index(this.activeWorkspaceIndex - 1); + let newActiveWorkspace = workspaceManager.get_workspace_by_index(this.activeWorkspaceIndex - 1); newActiveWorkspace.activate(global.get_current_time()); } }, @@ -1725,7 +1732,7 @@ TaskBar.prototype = { onClickDesktopButton: function(button, pspec) { let maxWindows = false; let userTime = null; - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); let windows = activeWorkspace.list_windows().filter(function(w) { return w.get_window_type() !== Meta.WindowType.DESKTOP; }); @@ -1806,7 +1813,7 @@ TaskBar.prototype = { //Actions executed depending on button click on Task clickActionMinMax: function(window, appname, index) { - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); let focusWindow = global.display.focus_window; let nextApp = false; @@ -1916,7 +1923,7 @@ TaskBar.prototype = { windowsList = new PopupMenu.PopupMenuItem(title); windowsList.connect('activate', Lang.bind(this, function() { - if (windowWorkspace !== global.screen.get_active_workspace()) + if (windowWorkspace !== workspaceManager.get_active_workspace()) windowWorkspace.activate(global.get_current_time()); windowTask.activate(global.get_current_time()); })); @@ -1972,13 +1979,13 @@ TaskBar.prototype = { ((scrollDirection === Clutter.ScrollDirection.DOWN) && (this.settings.get_enum("scroll-workspaces") === 2))) { if (this.activeWorkspaceIndex === this.totalWorkspace) this.activeWorkspaceIndex = -1; - let newActiveWorkspace = global.screen.get_workspace_by_index(this.activeWorkspaceIndex + 1); + let newActiveWorkspace = workspaceManager.get_workspace_by_index(this.activeWorkspaceIndex + 1); newActiveWorkspace.activate(global.get_current_time()); } else if (((scrollDirection === Clutter.ScrollDirection.DOWN) && (this.settings.get_enum("scroll-workspaces") === 1)) || ((scrollDirection === Clutter.ScrollDirection.UP) && (this.settings.get_enum("scroll-workspaces") === 2))) { if (this.activeWorkspaceIndex === 0) this.activeWorkspaceIndex = this.totalWorkspace + 1; - let newActiveWorkspace = global.screen.get_workspace_by_index(this.activeWorkspaceIndex - 1); + let newActiveWorkspace = workspaceManager.get_workspace_by_index(this.activeWorkspaceIndex - 1); newActiveWorkspace.activate(global.get_current_time()); } } @@ -1989,7 +1996,7 @@ TaskBar.prototype = { this.nextTask = false; this.previousTask = null; let focusWindow = global.display.focus_window; - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); let scrollDirection = event.get_scroll_direction(); if (((scrollDirection === Clutter.ScrollDirection.UP) && (this.settings.get_enum("scroll-tasks") === 1)) || ((scrollDirection === Clutter.ScrollDirection.DOWN) && (this.settings.get_enum("scroll-tasks") === 2))) { @@ -2043,7 +2050,7 @@ TaskBar.prototype = { if (!this.resetHover) { let focusWindow = global.display.focus_window; let appname = Shell.WindowTracker.get_default().get_window_app(focusWindow).get_name(); - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); this.tasksList.forEach( function(task) { let [windowTask, buttonTask, signalsTask] = task; @@ -2207,7 +2214,7 @@ TaskBar.prototype = { //Active Tasks activeTasks: function(window) { let active = false; - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); this.tasksList.forEach( function(task) { let [windowTask, buttonTask, signalsTask] = task; @@ -2250,7 +2257,7 @@ TaskBar.prototype = { let _app_name = Shell.WindowTracker.get_default().get_window_app(window).get_name(); let appname = Shell.WindowTracker.get_default().get_window_app(windowTask).get_name(); let workspaceTask = windowTask.get_workspace(); - let activeWorkspace = global.screen.get_active_workspace(); + let activeWorkspace = workspaceManager.get_active_workspace(); if ((_app_name === appname) && ((workspaceTask === activeWorkspace) || (this.settings.get_enum("sort-tasks") === 3))) buttonTask.hide(); } @@ -2392,7 +2399,7 @@ TaskBar.prototype = { ]; //Display Tasks of All Workspaces if (!this.settings.get_boolean("tasks-all-workspaces")) { - let workspace = global.screen.get_active_workspace(); + let workspace = workspaceManager.get_active_workspace(); if (!this.settings.get_boolean("tasks-all-workspaces")) { buttonTask.visible = window.located_on_workspace(workspace); } diff --git a/windows.js b/windows.js index 799801c..35fb048 100644 --- a/windows.js +++ b/windows.js @@ -20,6 +20,13 @@ const Lang = imports.lang; + +let workspaceManager; +if (global.screen) + workspaceManager = global.screen; // mutter < 3.29 +else + workspaceManager = global.workspace_manager; // mutter >= 3.29 + function Windows(callBackThis, callbackWindowsListChanged, callbackWindowChanged) { this.init(callBackThis, callbackWindowsListChanged, callbackWindowChanged); } @@ -49,15 +56,15 @@ Windows.prototype = { //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)); + this.workspaceSwitchSignal = workspaceManager.connect('workspace-switched', Lang.bind(this, this.buildWindowsList)); + this.nWorkspacesSignal = workspaceManager.connect('notify::n-workspaces', Lang.bind(this, this.onWorkspaceChanged)); }, destruct: function() { //Remove window manager signals - let numWorkspaces = global.screen.n_workspaces; + let numWorkspaces = workspaceManager.n_workspaces; for (let i = 0; i < numWorkspaces; i++) { - let workspace = global.screen.get_workspace_by_index(i); + let workspace = workspaceManager.get_workspace_by_index(i); let signals = this.workspaceSignals.get(workspace); this.workspaceSignals.delete(workspace); workspace.disconnect(signals.windowAddedId); @@ -69,9 +76,9 @@ Windows.prototype = { }, onWorkspaceChanged: function() { - let numWorkspaces = global.screen.n_workspaces; + let numWorkspaces = workspaceManager.n_workspaces; for (let i = 0; i < numWorkspaces; i++) { - let workspace = global.screen.get_workspace_by_index(i); + let workspace = workspaceManager.get_workspace_by_index(i); if (this.workspaceSignals.has(workspace)) continue; let signals = { @@ -89,9 +96,9 @@ Windows.prototype = { this.cleanWindowsList(); //Build windows list - let totalWorkspaces = global.screen.n_workspaces; + let totalWorkspaces = workspaceManager.n_workspaces; for (let i = 0; i < totalWorkspaces; i++) { - let activeWorkspace = global.screen.get_workspace_by_index(i); + let activeWorkspace = workspaceManager.get_workspace_by_index(i); activeWorkspace.list_windows().sort(this.sortWindowsCompareFunction).forEach( function(window) { this.addWindowInList(window);