Skip to content

Commit

Permalink
support gnome 3.30
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmytheneutrino committed Sep 19, 2018
1 parent 9110448 commit 00631d8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
49 changes: 28 additions & 21 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
});
Expand Down Expand Up @@ -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"
});
Expand All @@ -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) {
Expand Down Expand Up @@ -1711,21 +1718,21 @@ 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());
}
},

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;
});
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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());
}));
Expand Down Expand Up @@ -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());
}
}
Expand All @@ -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))) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand Down
23 changes: 15 additions & 8 deletions windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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 = {
Expand All @@ -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);
Expand Down

0 comments on commit 00631d8

Please sign in to comment.