Skip to content

Commit

Permalink
Implement draft of simpler version of the workspace oveview
Browse files Browse the repository at this point in the history
References #13
  • Loading branch information
mzur committed Jul 27, 2019
1 parent 8cda4d5 commit 2813894
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 85 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This is a clone of the [Workspace Grid](https://github.com/zakkak/workspace-grid
- Configurable timeout of the workspace switcher popup.
- Two wraparound modes for navigating workspaces (optional).
- Workspace labels in the workspace switcher popup (optional).
- Workspace overview on <kbd>Super</kbd>+<kbd>W</kbd>.

## Installation

Expand Down
12 changes: 9 additions & 3 deletions wsmatrix@martin.zurowietz.de/BaseWorkspaceSwitcherPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ class BaseWorkspaceSwitcherPopup extends WorkspaceSwitcherPopup {
display(direction, activeWorkspaceIndex) {
super.display(direction, activeWorkspaceIndex);

Mainloop.source_remove(this._timeoutId);
this._timeoutId = Mainloop.timeout_add(this._popupTimeout, this._onTimeout.bind(this));
GLib.Source.set_name_by_id(this._timeoutId, '[gnome-shell] this._onTimeout');
if (this._timeoutId !== 0) {
Mainloop.source_remove(this._timeoutId);
this._timeoutId = 0;
}

if (this._popupTimeout > 0) {
this._timeoutId = Mainloop.timeout_add(this._popupTimeout, this._onTimeout.bind(this));
GLib.Source.set_name_by_id(this._timeoutId, '[gnome-shell] this._onTimeout');
}
}
});
222 changes: 172 additions & 50 deletions wsmatrix@martin.zurowietz.de/WmOverride.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const WraparoundMode = {
};

var WmOverride = class {
constructor(settings) {
constructor(settings, keybindings) {
this.wm = Main.wm;
this.settings = settings;
this._mutterSettings = new Gio.Settings({ schema_id: 'org.gnome.mutter' });
this.wsManager = DisplayWrapper.getWorkspaceManager();
this.originalNumberOfWorkspaces = this.wsManager.n_workspaces;
this.originalDynamicWorkspaces = this._mutterSettings.get_boolean('dynamic-workspaces');
this.originalAllowedKeybindings = {};
this._keybindings = keybindings;

this._overrideDynamicWorkspaces();
this._overrideKeybindingHandlers();
Expand All @@ -34,6 +35,7 @@ var WmOverride = class {
this._handleWraparoundModeChanged();
this._connectSettings();
this._notify();
this._addKeybindings();
}

destroy() {
Expand All @@ -44,6 +46,7 @@ var WmOverride = class {
this._restoreNumberOfWorkspaces();
this._restoreDynamicWorkspaces();
this._notify();
this._removeKeybindings();
}

_connectSettings() {
Expand Down Expand Up @@ -99,6 +102,70 @@ var WmOverride = class {
this.settings.disconnect(this.settingsHandlerCachePopup);
}

_addKeybindings() {
this.wm.addKeybinding(
'workspace-overview-toggle',
this._keybindings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
this._toggleWorkspaceOverview.bind(this)
);
}

_removeKeybindings() {
this.wm.removeKeybinding('workspace-overview-toggle');
}

_addWsOverviewKeybindings(keybindings) {
this.wm.addKeybinding(
'workspace-overview-right',
this._keybindings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
this._workspaceOverviewMoveRight.bind(this)
);

this.wm.addKeybinding(
'workspace-overview-left',
this._keybindings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
this._workspaceOverviewMoveLeft.bind(this)
);

this.wm.addKeybinding(
'workspace-overview-up',
this._keybindings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
this._workspaceOverviewMoveUp.bind(this)
);

this.wm.addKeybinding(
'workspace-overview-down',
this._keybindings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
this._workspaceOverviewMoveDown.bind(this)
);

this.wm.addKeybinding(
'workspace-overview-confirm',
this._keybindings,
Meta.KeyBindingFlags.NONE,
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW,
this._workspaceOverviewConfirm.bind(this)
);
}

_removeWsOverviewKeybindings() {
this.wm.removeKeybinding('workspace-overview-right');
this.wm.removeKeybinding('workspace-overview-left');
this.wm.removeKeybinding('workspace-overview-up');
this.wm.removeKeybinding('workspace-overview-down');
this.wm.removeKeybinding('workspace-overview-confirm');
}

_handleNumberOfWorkspacesChanged() {
this.rows = this.settings.get_int('num-rows');
this.columns = this.settings.get_int('num-columns');
Expand Down Expand Up @@ -256,39 +323,7 @@ var WmOverride = class {
}

direction = Meta.MotionDirection[target.toUpperCase()];
newWs = workspaceManager.get_active_workspace().get_neighbor(direction);

let currentIndex = workspaceManager.get_active_workspace_index();
if (this.wraparoundMode !== WraparoundMode.NONE && currentIndex === newWs.index()) {
// Given a direction input the workspace has not changed, so do wraparound.
let targetRow = Math.floor(currentIndex / this.columns);
let targetColumn = currentIndex % this.columns;

let offset = 0;
if (direction === Meta.MotionDirection.UP || direction === Meta.MotionDirection.LEFT) {
offset = -1;
} else if (direction === Meta.MotionDirection.DOWN || direction === Meta.MotionDirection.RIGHT) {
offset = 1;
}

if (this.wraparoundMode === WraparoundMode.NEXT_PREV) {
targetRow += offset;
targetColumn += offset;
} else if (this.wraparoundMode === WraparoundMode.ROW_COL) {
if (direction === Meta.MotionDirection.UP || direction === Meta.MotionDirection.DOWN) {
targetRow += offset;
} else if (direction === Meta.MotionDirection.LEFT || direction === Meta.MotionDirection.RIGHT) {
targetColumn += offset;
}
}

// Handle negative targets.
targetColumn = (targetColumn + this.columns) % this.columns;
targetRow = (targetRow + this.rows) % this.rows;

target = targetRow * this.columns + targetColumn;
newWs = workspaceManager.get_workspace_by_index(target);
}
newWs = this._getTargetWorkspace(direction);
} else if (target > 0) {
target--;
newWs = workspaceManager.get_workspace_by_index(target);
Expand All @@ -307,22 +342,7 @@ var WmOverride = class {
if (!Main.overview.visible && this.popupTimeout > 0) {
if (this.wm._workspaceSwitcherPopup == null) {
this.wm._workspaceTracker.blockUpdates();
if (this.showThumbnails) {
this.wm._workspaceSwitcherPopup = new ThumbnailWsmatrixPopup(
this.rows,
this.columns,
this.scale,
this.popupTimeout,
this.cachePopup
);
} else {
this.wm._workspaceSwitcherPopup = new IndicatorWsmatrixPopup(
this.rows,
this.columns,
this.popupTimeout,
this.showWorkspaceNames
);
}
this.wm._workspaceSwitcherPopup = this._createNewPopup();
this.wm._workspaceSwitcherPopup.connect('destroy', () => {
this.wm._workspaceTracker.unblockUpdates();
this.wm._workspaceSwitcherPopup = null;
Expand All @@ -342,4 +362,106 @@ var WmOverride = class {
}
}
}

_getTargetWorkspace(direction) {
let newWs = this.wsManager.get_active_workspace().get_neighbor(direction);
let currentIndex = this.wsManager.get_active_workspace_index();
if (this.wraparoundMode !== WraparoundMode.NONE && currentIndex === newWs.index()) {
// Given a direction input the workspace has not changed, so do wraparound.
let targetRow = Math.floor(currentIndex / this.columns);
let targetColumn = currentIndex % this.columns;

let offset = 0;
if (direction === Meta.MotionDirection.UP || direction === Meta.MotionDirection.LEFT) {
offset = -1;
} else if (direction === Meta.MotionDirection.DOWN || direction === Meta.MotionDirection.RIGHT) {
offset = 1;
}

if (this.wraparoundMode === WraparoundMode.NEXT_PREV) {
targetRow += offset;
targetColumn += offset;
} else if (this.wraparoundMode === WraparoundMode.ROW_COL) {
if (direction === Meta.MotionDirection.UP || direction === Meta.MotionDirection.DOWN) {
targetRow += offset;
} else if (direction === Meta.MotionDirection.LEFT || direction === Meta.MotionDirection.RIGHT) {
targetColumn += offset;
}
}

// Handle negative targets.
targetColumn = (targetColumn + this.columns) % this.columns;
targetRow = (targetRow + this.rows) % this.rows;

target = targetRow * this.columns + targetColumn;
newWs = this.wsManager.get_workspace_by_index(target);
}

return newWs;
}

_createNewPopup(timeout) {
timeout = timeout === undefined ? this.popupTimeout : timeout;

if (this.showThumbnails) {
return new ThumbnailWsmatrixPopup(
this.rows,
this.columns,
this.scale,
timeout,
this.cachePopup
);
}

return new IndicatorWsmatrixPopup(
this.rows,
this.columns,
timeout,
this.showWorkspaceNames
);
}

_toggleWorkspaceOverview() {
if (this.wm._workspaceSwitcherPopup === null) {
this.wm._workspaceSwitcherPopup = this._createNewPopup(0);
this.wm._workspaceSwitcherPopup.connect('destroy', () => {
this.wm._workspaceTracker.unblockUpdates();
this.wm._workspaceSwitcherPopup = null;
this.wm._isWorkspacePrepended = false;
this._removeWsOverviewKeybindings();
});
this.wm._workspaceSwitcherPopup.display(null, this.wsManager.get_active_workspace_index());
this._addWsOverviewKeybindings();
} else {
this._destroyWorkspaceSwitcherPopup();
}
}

_moveToWorkspace(direction) {
let workspace = this._getTargetWorkspace(direction);
this.wm.actionMoveWorkspace(workspace);
if (this.wm._workspaceSwitcherPopup) {
this.wm._workspaceSwitcherPopup.display(direction, workspace.index());
}
}

_workspaceOverviewMoveRight() {
this._moveToWorkspace(Meta.MotionDirection.RIGHT);
}

_workspaceOverviewMoveLeft() {
this._moveToWorkspace(Meta.MotionDirection.LEFT);
}

_workspaceOverviewMoveUp() {
this._moveToWorkspace(Meta.MotionDirection.UP);
}

_workspaceOverviewMoveDown() {
this._moveToWorkspace(Meta.MotionDirection.DOWN);
}

_workspaceOverviewConfirm() {
this._destroyWorkspaceSwitcherPopup();
}
}
27 changes: 0 additions & 27 deletions wsmatrix@martin.zurowietz.de/WorkspaceOverview.js

This file was deleted.

5 changes: 1 addition & 4 deletions wsmatrix@martin.zurowietz.de/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ const Lang = imports.lang;
const Meta = imports.gi.Meta;
const Settings = WsMatrix.imports.Settings.Settings;
const WmOverride = WsMatrix.imports.WmOverride.WmOverride;
const WorkspaceOverview = WsMatrix.imports.WorkspaceOverview.WorkspaceOverview;

class WsMatrixExtension {
constructor() {
let settings = new Settings(WsMatrix.metadata['settings-schema']);
let keybindings = new Settings(WsMatrix.metadata['keybindings-schema']);
this.override = new WmOverride(settings);
this.overview = new WorkspaceOverview(keybindings);
this.override = new WmOverride(settings, keybindings);
}
destroy() {
this.override.destroy();
this.overview.destroy();
}
}

Expand Down
Binary file modified wsmatrix@martin.zurowietz.de/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,47 @@
</key>
</schema>
<schema id="org.gnome.shell.extensions.wsmatrix-keybindings" path="/org/gnome/shell/extensions/wsmatrix/">
<key name="toggle-workspace-overview" type="as">
<key name="workspace-overview-toggle" type="as">
<default>["&lt;Super&gt;w"]</default>
<summary>Keybinding to open the workspace overview</summary>
<description>
Keybinding to open the workspace overview.
</description>
</key>
<key name="workspace-overview-right" type="as">
<default>["Right"]</default>
<summary>Keybinding to move to the right in the workspace overview</summary>
<description>
Keybinding to move to the right in the workspace overview
</description>
</key>
<key name="workspace-overview-left" type="as">
<default>["Left"]</default>
<summary>Keybinding to move to the left in the workspace overview</summary>
<description>
Keybinding to move to the left in the workspace overview
</description>
</key>
<key name="workspace-overview-up" type="as">
<default>["Up"]</default>
<summary>Keybinding to move up in the workspace overview</summary>
<description>
Keybinding to move up in the workspace overview
</description>
</key>
<key name="workspace-overview-down" type="as">
<default>["Down"]</default>
<summary>Keybinding to move down in the workspace overview</summary>
<description>
Keybinding to move down in the workspace overview
</description>
</key>
<key name="workspace-overview-confirm" type="as">
<default>["Return","Escape"]</default>
<summary>Keybinding to confirm and close the workspace overview</summary>
<description>
Keybinding to confirm and close the workspace overview
</description>
</key>
</schema>
</schemalist>

0 comments on commit 2813894

Please sign in to comment.