Skip to content

Commit cdd5235

Browse files
authored
Merge pull request #263 from myyc/master
GNOME 45 support
2 parents 106f43f + 92c6707 commit cdd5235

16 files changed

+773
-1049
lines changed

[email protected]/Override.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {InjectionManager} from 'resource:///org/gnome/shell/extensions/extension.js';
2+
3+
export default class Override {
4+
constructor() {
5+
this._im = new InjectionManager();
6+
}
7+
8+
enable () {
9+
//
10+
}
11+
12+
destroy() {
13+
this.disable();
14+
}
15+
16+
disable() {
17+
this._im.clear();
18+
}
19+
}

[email protected]/extension.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
const ExtensionUtils = imports.misc.extensionUtils;
2-
const Self = ExtensionUtils.getCurrentExtension();
3-
const WorkspaceManagerOverride = Self.imports.workspacePopup.workspaceManagerOverride;
4-
const OverviewManager = Self.imports.overview.overviewManager;
1+
import OverviewManager from "./overview/overviewManager.js";
2+
import WorkspaceManagerOverride from "./workspacePopup/workspaceManagerOverride.js";
3+
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
54

6-
class Extension {
5+
export default class WsmatrixExtension extends Extension {
76
enable() {
8-
let settings = ExtensionUtils.getSettings(Self.metadata['settings-schema']);
9-
let keybindings = ExtensionUtils.getSettings(Self.metadata['keybindings-schema']);
10-
this.overrideWorkspace = new WorkspaceManagerOverride.WorkspaceManagerOverride(settings, keybindings);
11-
this.overrideOverview = new OverviewManager.OverviewManager(settings);
7+
let settings = this.getSettings();
8+
let keybindings = this.getSettings(this.metadata['keybindings-schema']);
9+
this.overrideWorkspace = new WorkspaceManagerOverride(settings, keybindings);
10+
this.overrideOverview = new OverviewManager(settings);
1211
}
1312

1413
disable() {
1514
this.overrideWorkspace.destroy();
15+
this.overrideWorkspace = null;
16+
1617
this.overrideOverview.destroy();
18+
this.overrideOverview = null;
1719
}
1820
}
19-
20-
function init() {
21-
return new Extension();
22-
}

[email protected]/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"shell-version": [
3-
"44"
3+
"45"
44
],
55
"uuid": "[email protected]",
66
"url": "https://github.com/mzur/gnome-shell-wsmatrix",
Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,48 @@
1-
const ExtensionUtils = imports.misc.extensionUtils;
2-
const Self = ExtensionUtils.getCurrentExtension();
3-
const Util = Self.imports.util;
4-
const OverviewControls = imports.ui.overviewControls;
5-
const { ControlsState } = OverviewControls;
6-
7-
//const { SMALL_WORKSPACE_RATIO } = OverviewControls;
8-
const SMALL_WORKSPACE_RATIO = 0.15;
9-
10-
var ControlsManagerLayout = class {
11-
constructor() {
12-
this.originalLayout = null;
13-
this._overrideProperties = {
14-
_computeWorkspacesBoxForState() {
15-
let state, box, workAreaBox, searchHeight, dashHeight, thumbnailsHeight;
16-
if (arguments.length === 5) {
17-
[state, box, searchHeight, dashHeight, thumbnailsHeight] = arguments;
18-
workAreaBox = this._workAreaBox;
19-
} else {
20-
[state, box, workAreaBox, searchHeight, dashHeight, thumbnailsHeight] = arguments;
21-
}
22-
23-
const workspaceBox = box.copy();
24-
const [width, height] = workspaceBox.get_size();
25-
const { y1: startY } = workAreaBox;
26-
const {spacing} = this;
27-
const {expandFraction} = this._workspacesThumbnails;
28-
let workspaceManager = global.workspace_manager;
29-
let rows = workspaceManager.layout_rows;
30-
31-
switch (state) {
32-
case ControlsState.HIDDEN:
33-
workspaceBox.set_origin(...workAreaBox.get_origin());
34-
workspaceBox.set_size(...workAreaBox.get_size());
35-
break;
36-
case ControlsState.WINDOW_PICKER:
37-
workspaceBox.set_origin(0,
38-
startY + searchHeight + spacing +
39-
thumbnailsHeight * rows + spacing * expandFraction);
40-
workspaceBox.set_size(width,
41-
height -
42-
dashHeight - spacing -
43-
searchHeight - spacing -
44-
thumbnailsHeight * rows - spacing * expandFraction);
45-
break;
46-
case ControlsState.APP_GRID:
47-
workspaceBox.set_origin(0, startY + searchHeight + spacing);
48-
workspaceBox.set_size(
49-
width,
50-
Math.round(height * rows * SMALL_WORKSPACE_RATIO));
51-
break;
52-
}
53-
54-
return workspaceBox;
55-
},
56-
}
1+
import Override from '../Override.js';
2+
import {overview} from 'resource:///org/gnome/shell/ui/main.js';
3+
import {SMALL_WORKSPACE_RATIO, ControlsState} from 'resource:///org/gnome/shell/ui/overviewControls.js';
4+
5+
const _computeWorkspacesBoxForState = function(state, box, searchHeight, dashHeight, thumbnailsHeight) {
6+
const workspaceBox = box.copy();
7+
const [width, height] = workspaceBox.get_size();
8+
const { y1: startY } = this._workAreaBox;
9+
const {spacing} = this;
10+
const {expandFraction} = this._workspacesThumbnails;
11+
12+
const workspaceManager = global.workspace_manager;
13+
const rows = workspaceManager.layout_rows;
14+
15+
switch (state) {
16+
case ControlsState.HIDDEN:
17+
workspaceBox.set_origin(...this._workAreaBox.get_origin());
18+
workspaceBox.set_size(...this._workAreaBox.get_size());
19+
break;
20+
case ControlsState.WINDOW_PICKER:
21+
workspaceBox.set_origin(0,
22+
startY + searchHeight + spacing +
23+
thumbnailsHeight * rows + spacing * expandFraction);
24+
workspaceBox.set_size(width,
25+
height -
26+
dashHeight - spacing -
27+
searchHeight - spacing -
28+
thumbnailsHeight * rows - spacing * expandFraction);
29+
break;
30+
case ControlsState.APP_GRID:
31+
workspaceBox.set_origin(0, startY + searchHeight + spacing);
32+
workspaceBox.set_size(
33+
width,
34+
Math.round(height * rows * SMALL_WORKSPACE_RATIO));
35+
break;
5736
}
5837

59-
destroy() {
60-
this.restoreOriginalProperties();
61-
}
62-
63-
overrideOriginalProperties() {
64-
this.originalLayout = Util.overrideProto(OverviewControls.ControlsManagerLayout.prototype, this._overrideProperties);
65-
}
38+
return workspaceBox;
39+
}
6640

67-
restoreOriginalProperties() {
68-
Util.overrideProto(OverviewControls.ControlsManagerLayout.prototype, this.originalLayout);
41+
export default class ControlsManagerLayout extends Override {
42+
enable() {
43+
const subject = overview._overview._controls.layout_manager;
44+
this._im.overrideMethod(subject, '_computeWorkspacesBoxForState', (original) => {
45+
return _computeWorkspacesBoxForState.bind(subject);
46+
});
6947
}
7048
}
Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
1-
const ExtensionUtils = imports.misc.extensionUtils;
2-
const Self = ExtensionUtils.getCurrentExtension();
3-
const ThumbnailsBox = Self.imports.overview.thumbnailsBox;
4-
const ControlsManagerLayout = Self.imports.overview.controlsManagerLayout;
5-
const SecondaryMonitorDisplay = Self.imports.overview.secondaryMonitorDisplay;
6-
const WorkspacesView = Self.imports.overview.workspacesView;
7-
8-
var OverviewManager = class {
1+
// import ControlsManagerLayout from './controlsManagerLayout.js';
2+
import SecondaryMonitorDisplay from './secondaryMonitorDisplay.js';
3+
// import ThumbnailsBox from './thumbnailsBox.js';
4+
import WorkspacesView from './workspacesView.js';
5+
import {GNOMEversionCompare} from 'resource:///org/gnome/shell/misc/util.js';
6+
import {PACKAGE_VERSION} from 'resource:///org/gnome/shell/misc/config.js';
7+
8+
export default class OverviewManager {
99
constructor(settings) {
1010
this._settings = settings;
11+
this._initOverrides()
12+
.then(this._handleShowOverviewGridChanged.bind(this))
13+
.catch(e => console.error(e));
1114

12-
this._thumbnailsBoxOverride = new ThumbnailsBox.ThumbnailsBox();
13-
this._workspacesViewOverride = new WorkspacesView.WorkspacesView();
14-
this._controlsManagerLayoutOverride = new ControlsManagerLayout.ControlsManagerLayout();
15-
this._secondaryMonitorDisplayOverride = new SecondaryMonitorDisplay.SecondaryMonitorDisplay();
16-
17-
this._handleShowOverviewGridChanged();
15+
// this._handleShowOverviewGridChanged();
1816
this._connectSettings();
1917
}
2018

19+
// This can be moved to the constructor again if there is no need for the conditional
20+
// import any more.
21+
async _initOverrides() {
22+
this._overrides = [
23+
new WorkspacesView(),
24+
new SecondaryMonitorDisplay(),
25+
// new ThumbnailsBox(),
26+
// new ControlsManagerLayout(),
27+
];
28+
29+
// This only works starting in GNOME Shell 45.1 and up.
30+
if (GNOMEversionCompare(PACKAGE_VERSION, '45.1') >= 0) {
31+
const {default: ThumbnailsBox} = await import('./thumbnailsBox.js');
32+
this._overrides.push(new ThumbnailsBox());
33+
const {default: ControlsManagerLayout} = await import('./controlsManagerLayout.js');
34+
this._overrides.push(new ControlsManagerLayout());
35+
}
36+
}
37+
2138
_connectSettings() {
2239
this.settingsHandlerShowOverviewGrid = this._settings.connect(
2340
'changed::show-overview-grid',
@@ -39,23 +56,15 @@ var OverviewManager = class {
3956
}
4057

4158
override() {
42-
this._thumbnailsBoxOverride.overrideOriginalProperties();
43-
this._workspacesViewOverride.overrideOriginalProperties();
44-
this._controlsManagerLayoutOverride.overrideOriginalProperties();
45-
// Disabled until override objects can be imported again
46-
// see: https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2266
47-
// this._secondaryMonitorDisplayOverride.overrideOriginalProperties();
59+
this._overrides.forEach(o => o.enable());
4860
}
4961

5062
restore() {
51-
this._thumbnailsBoxOverride.restoreOriginalProperties();
52-
this._workspacesViewOverride.restoreOriginalProperties();
53-
this._controlsManagerLayoutOverride.restoreOriginalProperties();
54-
// Disabled (see above).
55-
// this._secondaryMonitorDisplayOverride.restoreOriginalProperties();
63+
this._overrides.forEach(o => o.disable());
5664
}
5765

5866
destroy() {
67+
this.restore();
5968
this._disconnectSettings();
6069
}
6170
}
Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,40 @@
1-
const ExtensionUtils = imports.misc.extensionUtils;
2-
const Self = ExtensionUtils.getCurrentExtension();
3-
const Util = Self.imports.util;
4-
const GWorkspacesView = imports.ui.workspacesView;
5-
const OverviewControls = imports.ui.overviewControls;
1+
import Override from '../Override.js';
2+
import {ControlsState} from 'resource:///org/gnome/shell/ui/overviewControls.js';
3+
import {SecondaryMonitorDisplay as GSecondaryMonitorDisplay} from 'resource:///org/gnome/shell/ui/workspacesView.js';
64

7-
var SecondaryMonitorDisplay = class {
8-
constructor() {
9-
this.originalDisplay = null;
10-
this._overrideProperties = {
11-
_getWorkspacesBoxForState(state, box, padding, thumbnailsHeight, spacing) {
12-
const { ControlsState } = OverviewControls;
13-
const workspaceBox = box.copy();
14-
const [width, height] = workspaceBox.get_size();
15-
let workspaceManager = global.workspace_manager;
16-
let rows = workspaceManager.layout_rows;
5+
const _getWorkspacesBoxForState = function (state, box, padding, thumbnailsHeight, spacing) {
6+
const workspaceBox = box.copy();
7+
const [width, height] = workspaceBox.get_size();
8+
const workspaceManager = global.workspace_manager;
9+
const rows = workspaceManager.layout_rows;
1710

18-
switch (state) {
19-
case ControlsState.HIDDEN:
20-
break;
21-
case ControlsState.WINDOW_PICKER:
22-
workspaceBox.set_origin(0, padding + thumbnailsHeight * rows + spacing);
23-
workspaceBox.set_size(
24-
width,
25-
height - 2 * padding - thumbnailsHeight * rows - spacing);
26-
break;
27-
case ControlsState.APP_GRID:
28-
workspaceBox.set_origin(0, padding);
29-
workspaceBox.set_size(
30-
width,
31-
height - 2 * padding);
32-
break;
33-
}
34-
35-
return workspaceBox;
36-
},
37-
}
38-
}
39-
40-
destroy() {
41-
this.restoreOriginalProperties();
11+
switch (state) {
12+
case ControlsState.HIDDEN:
13+
break;
14+
case ControlsState.WINDOW_PICKER:
15+
workspaceBox.set_origin(0, padding + thumbnailsHeight * rows + spacing);
16+
workspaceBox.set_size(
17+
width,
18+
height - 2 * padding - thumbnailsHeight * rows - spacing);
19+
break;
20+
case ControlsState.APP_GRID:
21+
workspaceBox.set_origin(0, padding);
22+
workspaceBox.set_size(
23+
width,
24+
height - 2 * padding);
25+
break;
4226
}
4327

44-
overrideOriginalProperties() {
45-
this.originalDisplay = Util.overrideProto(GWorkspacesView.SecondaryMonitorDisplay.prototype, this._overrideProperties);
46-
}
28+
return workspaceBox;
29+
};
4730

48-
restoreOriginalProperties() {
49-
Util.overrideProto(GWorkspacesView.SecondaryMonitorDisplay.prototype, this.originalDisplay);
31+
export default class SecondaryMonitorDisplay extends Override {
32+
enable() {
33+
const subject = GSecondaryMonitorDisplay.prototype;
34+
this._im.overrideMethod(subject, '_getWorkspacesBoxForState', (original) => {
35+
return function () {
36+
return _getWorkspacesBoxForState.call(this, ...arguments)
37+
};
38+
});
5039
}
5140
}

0 commit comments

Comments
 (0)