Skip to content

Commit

Permalink
Merge pull request #218 from mzur/gnome-42
Browse files Browse the repository at this point in the history
GNOME 42 support
  • Loading branch information
mzur authored Apr 29, 2022
2 parents 2afeac4 + 6683c38 commit 3748703
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 62 deletions.
3 changes: 1 addition & 2 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"shell-version": [
"40",
"41"
"42"
],
"uuid": "[email protected]",
"url": "https://github.com/mzur/gnome-shell-wsmatrix",
Expand Down
17 changes: 10 additions & 7 deletions [email protected]/overview/controlsManagerLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@ const ExtensionUtils = imports.misc.extensionUtils;
const Self = ExtensionUtils.getCurrentExtension();
const Util = Self.imports.util;
const OverviewControls = imports.ui.overviewControls;
const { ControlsState } = OverviewControls;

const { SMALL_WORKSPACE_RATIO } = OverviewControls;
//const { SMALL_WORKSPACE_RATIO } = OverviewControls;
const SMALL_WORKSPACE_RATIO = 0.15;

var ControlsManagerLayout = class {
constructor() {
this.originalLayout = null;
this._overrideProperties = {
_computeWorkspacesBoxForState(state, workAreaBox, searchHeight, dashHeight, thumbnailsHeight) {
const { ControlsState } = OverviewControls;
const workspaceBox = workAreaBox.copy();
const [startX, startY] = workAreaBox.get_origin();
_computeWorkspacesBoxForState(state, box, workAreaBox, searchHeight, dashHeight, thumbnailsHeight) {
const workspaceBox = box.copy();
const [width, height] = workspaceBox.get_size();
const { y1: startY } = workAreaBox;
const {spacing} = this;
const {expandFraction} = this._workspacesThumbnails;
let workspaceManager = global.workspace_manager;
let rows = workspaceManager.layout_rows;

switch (state) {
case ControlsState.HIDDEN:
workspaceBox.set_origin(...workAreaBox.get_origin());
workspaceBox.set_size(...workAreaBox.get_size());
break;
case ControlsState.WINDOW_PICKER:
workspaceBox.set_origin(startX,
workspaceBox.set_origin(0,
startY + searchHeight + spacing +
thumbnailsHeight * rows + spacing * expandFraction);
workspaceBox.set_size(width,
Expand All @@ -33,7 +36,7 @@ var ControlsManagerLayout = class {
thumbnailsHeight * rows - spacing * expandFraction);
break;
case ControlsState.APP_GRID:
workspaceBox.set_origin(startX, startY + searchHeight + spacing);
workspaceBox.set_origin(0, startY + searchHeight + spacing);
workspaceBox.set_size(
width,
Math.round(height * rows * SMALL_WORKSPACE_RATIO));
Expand Down
7 changes: 5 additions & 2 deletions [email protected]/overview/overviewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ var OverviewManager = class {
this._thumbnailsBoxOverride.overrideOriginalProperties();
this._workspacesViewOverride.overrideOriginalProperties();
this._controlsManagerLayoutOverride.overrideOriginalProperties();
this._secondaryMonitorDisplayOverride.overrideOriginalProperties();
// Disabled until override objects can be imported again
// see: https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2266
// this._secondaryMonitorDisplayOverride.overrideOriginalProperties();
}

restore() {
this._thumbnailsBoxOverride.restoreOriginalProperties();
this._workspacesViewOverride.restoreOriginalProperties();
this._controlsManagerLayoutOverride.restoreOriginalProperties();
this._secondaryMonitorDisplayOverride.restoreOriginalProperties();
// Disabled (see above).
// this._secondaryMonitorDisplayOverride.restoreOriginalProperties();
}

destroy() {
Expand Down
Binary file modified [email protected]/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
</enum>
<schema id="org.gnome.shell.extensions.wsmatrix-settings" path="/org/gnome/shell/extensions/wsmatrix/">
<key type="i" name="num-columns">
<default>3</default>
<default>2</default>
<range min="1" max="36"/>
<summary>Number of columns of workspaces</summary>
</key>
<key type="i" name="num-rows">
<default>3</default>
<default>2</default>
<range min="1" max="36"/>
<summary>Number of rows of workspaces</summary>
</key>
<key type="i" name="popup-timeout">
<default>10</default>
<default>500</default>
<range min="0" max="5000"/>
<summary>Time to show the popup (ms)</summary>
</key>
Expand All @@ -35,7 +35,7 @@
<summary>Whether to allow hovering on workspaces in popup or not</summary>
</key>
<key type="b" name="show-workspace-names">
<default>true</default>
<default>false</default>
<summary>Whether to show workspace names or not</summary>
</key>
<key name="wraparound-mode" enum="org.gnome.shell.extensions.wsmatrix.wraparoundMode">
Expand Down
2 changes: 1 addition & 1 deletion [email protected]/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Gio = imports.gi.Gio;
const Self = imports.misc.extensionUtils.getCurrentExtension();

function hookVfunc(proto, symbol, func) {
proto[Gi.hook_up_vfunc_symbol](symbol, func);
proto[Gi.hook_up_vfunc_symbol].call(proto[Gi.gobject_prototype_symbol], symbol, func);
}

function overrideProto(proto, overrides) {
Expand Down
105 changes: 93 additions & 12 deletions [email protected]/workspacePopup/workspaceAnimation.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,105 @@
const {GObject, Meta, St} = imports.gi;
const {Clutter, GObject, Meta, St} = imports.gi;

const Main = imports.ui.main;
const GWorkspaceAnimation = imports.ui.workspaceAnimation;
const Layout = imports.ui.layout;
const ExtensionUtils = imports.misc.extensionUtils;
const Self = ExtensionUtils.getCurrentExtension();
const Util = Self.imports.util;
// const {WORKSPACE_SPACING} = GWorkspaceAnimation;
const WORKSPACE_SPACING = 100;

const MonitorGroup = GObject.registerClass({
Properties: {
'progress': GObject.ParamSpec.double(
'progress', 'progress', 'progress',
GObject.ParamFlags.READWRITE,
-Infinity, Infinity, 0),
},
}, class MonitorGroup extends St.Widget {
get baseDistance() {
const spacing = WORKSPACE_SPACING * St.ThemeContext.get_for_stage(global.stage).scale_factor;

if (global.workspace_manager.layout_rows === -1)
return this._monitor.height + spacing;
else
return this._monitor.width + spacing;
}

get index() {
return this._monitor.index;
}

getWorkspaceProgress(workspace) {
const group = this._workspaceGroups.find(g =>
g.workspace.index() === workspace.index());
return this._getWorkspaceGroupProgress(group);
}

getSnapPoints() {
return this._workspaceGroups.map(g =>
this._getWorkspaceGroupProgress(g));
}

findClosestWorkspace(progress) {
const distances = this.getSnapPoints().map(p =>
Math.abs(p - progress));
const index = distances.indexOf(Math.min(...distances));
return this._workspaceGroups[index].workspace;
}

_interpolateProgress(progress, monitorGroup) {
if (this.index === monitorGroup.index)
return progress;

const { WORKSPACE_SPACING } = GWorkspaceAnimation;
const points1 = monitorGroup.getSnapPoints();
const points2 = this.getSnapPoints();

const upper = points1.indexOf(points1.find(p => p >= progress));
const lower = points1.indexOf(points1.slice().reverse().find(p => p <= progress));

if (points1[upper] === points1[lower])
return points2[upper];

const t = (progress - points1[lower]) / (points1[upper] - points1[lower]);

return points2[lower] + (points2[upper] - points2[lower]) * t;
}

updateSwipeForMonitor(progress, monitorGroup) {
this.progress = this._interpolateProgress(progress, monitorGroup);
}

// The above is a copy of now inaccessible GWorkspaceAnimation.MonitorGroup
// Modifications below.

const MonitorGroup = GObject.registerClass(
class MonitorGroup extends GWorkspaceAnimation.MonitorGroup {
_init(monitor, workspaceIndices, movingWindow) {
super._init(monitor, workspaceIndices, movingWindow);
super._init({
clip_to_allocation: true,
style_class: 'workspace-animation',
});

this._monitor = monitor;

const constraint = new Layout.MonitorConstraint({ index: monitor.index });
this.add_constraint(constraint);

this._container = new Clutter.Actor();
this.add_child(this._container);

const stickyGroup = new GWorkspaceAnimation.WorkspaceGroup(null, monitor, movingWindow);
this.add_child(stickyGroup);

this.activeWorkspace = workspaceIndices[0];
this.targetWorkspace = workspaceIndices[workspaceIndices.length - 1];

this._workspaceGroups = [];

const workspaceManager = global.workspace_manager;
const activeWorkspace = workspaceManager.get_active_workspace();

let x = 0;
let y = 0;
let workspaceManager = global.workspace_manager;
this._workspaceGroups = [];

for (const i of workspaceIndices) {
let fromRow = Math.floor(this.activeWorkspace / this.columns);
Expand All @@ -37,10 +120,6 @@ class MonitorGroup extends GWorkspaceAnimation.MonitorGroup {
}

const group = new GWorkspaceAnimation.WorkspaceGroup(ws, monitor, movingWindow);
// avoid warnings
group._syncStacking = () => {
};

this._workspaceGroups.push(group);
this._container.add_child(group);
group.set_position(x, y);
Expand All @@ -55,6 +134,8 @@ class MonitorGroup extends GWorkspaceAnimation.MonitorGroup {
else if (targetColumn < fromColumn)
x -= this.baseDistanceX;
}

this.progress = this.getWorkspaceProgress(activeWorkspace);
}

get rows() {
Expand Down Expand Up @@ -132,7 +213,7 @@ class MonitorGroup extends GWorkspaceAnimation.MonitorGroup {
}
});

class WorkspaceAnimationController extends GWorkspaceAnimation.WorkspaceAnimationController {
var WorkspaceAnimationController = class WorkspaceAnimationController extends GWorkspaceAnimation.WorkspaceAnimationController {
_prepareWorkspaceSwitch(workspaceIndices) {
if (this._switchData)
return;
Expand Down
69 changes: 35 additions & 34 deletions [email protected]/workspacePopup/workspaceManagerOverride.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var WorkspaceManagerOverride = class {
'_workspaceAnimation',
'handleWorkspaceScroll',
];

this._overrideDynamicWorkspaces();
this._overrideKeybindingHandlers();
this._overrideOriginalProperties();
Expand Down Expand Up @@ -422,46 +421,48 @@ var WorkspaceManagerOverride = class {
}

_showWorkspaceSwitcherPopup(toggle) {
if (Main.overview.visible) {
return;
}

if (toggle) {
this._addWorkspaceOverviewKeybindings();
}

if (!Main.overview.visible) {
this.monitors.forEach((monitor) => {
let monitorIndex = monitor.index;

if (!this.wm._wsPopupList[monitorIndex]) {
this.wm._workspaceTracker.blockUpdates();
this.wm._wsPopupList[monitorIndex] = this._createNewPopup({
monitorIndex: monitorIndex,
toggle: toggle,
});
this.wm._wsPopupList[monitorIndex].connect('destroy', () => {
this.wm._workspaceTracker.unblockUpdates();
this.wm._wsPopupList[monitorIndex] = null;
if (monitorIndex === Main.layoutManager.primaryIndex) {
this.wm._workspaceSwitcherPopup = null;
this.wm._isWorkspacePrepended = false;
if (toggle) {
this._removeWorkspaceOverviewKeybindings();
}
}
});

let event = Clutter.get_current_event();
let modifiers = event ? event.get_state() & Clutter.ModifierType.MODIFIER_MASK : 0;
this.wm._wsPopupList[monitorIndex].showToggle(false, null, modifiers, toggle);
if (monitorIndex === Main.layoutManager.primaryIndex) {
this.wm._workspaceSwitcherPopup = this.wm._wsPopupList[monitorIndex];
}
} else {
// reset of popup
this.monitors.forEach((monitor) => {
let monitorIndex = monitor.index;

if (!this.wm._wsPopupList[monitorIndex]) {
this.wm._workspaceTracker.blockUpdates();
this.wm._wsPopupList[monitorIndex] = this._createNewPopup({
monitorIndex: monitorIndex,
toggle: toggle,
});
this.wm._wsPopupList[monitorIndex].connect('destroy', () => {
this.wm._workspaceTracker.unblockUpdates();
this.wm._wsPopupList[monitorIndex] = null;
if (monitorIndex === Main.layoutManager.primaryIndex) {
this.wm._wsPopupList[monitorIndex].resetTimeout();
this.wm._workspaceSwitcherPopup = null;
this.wm._isWorkspacePrepended = false;
if (toggle) {
this._removeWorkspaceOverviewKeybindings();
}
}
});

let event = Clutter.get_current_event();
let modifiers = event ? event.get_state() & Clutter.ModifierType.MODIFIER_MASK : 0;
this.wm._wsPopupList[monitorIndex].showToggle(false, null, modifiers, toggle);
if (monitorIndex === Main.layoutManager.primaryIndex) {
this.wm._workspaceSwitcherPopup = this.wm._wsPopupList[monitorIndex];
}
});
}
} else {
// reset of popup
if (monitorIndex === Main.layoutManager.primaryIndex) {
this.wm._wsPopupList[monitorIndex].resetTimeout();
}
}
});
}

_destroyWorkspaceSwitcherPopup() {
Expand Down

0 comments on commit 3748703

Please sign in to comment.