Skip to content

Commit 04c16d9

Browse files
committed
version 5: add support to light theme and new scaling factor algorithm
1 parent 79a7789 commit 04c16d9

28 files changed

+452
-268
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ dist_legacy/
5353
### IntelliJ IDEA
5454
.idea/
5555

56-
package-lock.json
56+
package-lock.json
57+
58+

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "modernwindowmanager",
3-
"version": "4.0.0",
3+
"version": "5.0.0",
44
"author": "Domenico Ferraro <[email protected]>",
55
"private": true,
66
"license": "GPL v2.0",
@@ -9,7 +9,7 @@
99
"clean": "rm -rf dist; rm -rf dist_legacy",
1010
"build:schema": "npm run clean:schema && glib-compile-schemas ./resources/schemas --targetdir=./dist/schemas/ && cp ./dist/schemas/ ./dist_legacy/ -r",
1111
"clean:schema": "rm -rf ./dist/schemas/*.compiled; rm -rf ./dist_legacy/schemas/*.compiled",
12-
"build:package": "rm -rf './dist/[email protected]'; rm -rf './dist_legacy/[email protected]'; npm run build && cd ./dist && zip -qr '[email protected]' . && cd ../dist_legacy && zip -qr '[email protected]' .",
12+
"build:package": "rm -rf './dist/[email protected]'; rm -rf './dist_legacy/[email protected]'; npm run build && cd ./dist && zip -qr ../[email protected] * && cd ../dist_legacy && zip -qr ../GNOME.40-44.[email protected] *",
1313
"install:extension": "mkdir -p ~/.local/share/gnome-shell/extensions/[email protected] && cp ./dist$([ $(gnome-shell --version | grep -o -E '[0-9]+' | head -n 1) -le 44 ] && echo '_legacy')/* ~/.local/share/gnome-shell/extensions/[email protected]/ -r",
1414
"wayland-session": "dbus-run-session -- gnome-shell --nested --wayland",
1515
"dev:wayland": "npm run build && npm run install:extension && npm run wayland-session"

Diff for: resources/metadata.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"45",
1212
"46"
1313
],
14-
"version": 4,
14+
"version": 5,
1515
"url": "https://github.com/domferr/modernwindowmanager",
1616
"settings-schema": "org.gnome.shell.extensions.modernwindowmanager"
1717
}

Diff for: src/components/editor/editorDialog.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Layout from '@/components/layout/Layout';
99
import SignalHandling from '@/signalHandling';
1010
import Tile from '@/components/layout/Tile';
1111
import * as ModalDialog from 'resource:///org/gnome/shell/ui/modalDialog.js';
12+
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
13+
import { enableScalingFactorSupport, getScalingFactor } from '@utils/ui';
1214

1315
const debug = logger('EditorDialog');
1416

@@ -22,7 +24,7 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
2224
private _layoutsBoxLayout: St.BoxLayout;
2325

2426
constructor(params: {
25-
scalingFactor: number,
27+
enableScaling: boolean,
2628
onDeleteLayout: (ind: number, lay: Layout) => void,
2729
onSelectLayout: (ind: number, lay: Layout) => void,
2830
onNewLayout: () => void,
@@ -33,6 +35,12 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
3335
styleClass: 'editor-dialog',
3436
});
3537

38+
if (params.enableScaling) {
39+
const monitor = Main.layoutManager.findMonitorForActor(this);
40+
const scalingFactor = getScalingFactor(monitor?.index || Main.layoutManager.primaryIndex);
41+
enableScalingFactorSupport(this, scalingFactor);
42+
}
43+
3644
this._signals = new SignalHandling();
3745

3846
this.contentLayout.add_child(new St.Label({
@@ -74,11 +82,12 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
7482
const suggestion1 = new St.BoxLayout({ vertical: false });
7583
// LEFT-CLICK to split a tile
7684
suggestion1.add_child(new St.Label({
77-
text: "LEFT-CLICK",
85+
text: "LEFT CLICK",
7886
xAlign: Clutter.ActorAlign.CENTER,
7987
yAlign: Clutter.ActorAlign.CENTER,
8088
styleClass: 'button kbd',
81-
xExpand: false
89+
xExpand: false,
90+
pseudoClass: "active"
8291
}));
8392
suggestion1.add_child(new St.Label({
8493
text: " to split a tile.",
@@ -91,11 +100,12 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
91100
const suggestion2 = new St.BoxLayout({ vertical: false });
92101
// LEFT-CLICK + CTRL to split a tile vertically
93102
suggestion2.add_child(new St.Label({
94-
text: "LEFT-CLICK",
103+
text: "LEFT CLICK",
95104
xAlign: Clutter.ActorAlign.CENTER,
96105
yAlign: Clutter.ActorAlign.CENTER,
97106
styleClass: 'button kbd',
98-
xExpand: false
107+
xExpand: false,
108+
pseudoClass: "active"
99109
}));
100110
suggestion2.add_child(new St.Label({
101111
text: " + ",
@@ -109,7 +119,8 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
109119
xAlign: Clutter.ActorAlign.CENTER,
110120
yAlign: Clutter.ActorAlign.CENTER,
111121
styleClass: 'button kbd',
112-
xExpand: false
122+
xExpand: false,
123+
pseudoClass: "active"
113124
}));
114125
suggestion2.add_child(new St.Label({
115126
text: " to split a tile vertically.",
@@ -122,11 +133,12 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
122133
const suggestion3 = new St.BoxLayout({ vertical: false });
123134
// RIGHT-CLICK to delete a tile
124135
suggestion3.add_child(new St.Label({
125-
text: "RIGHT-CLICK",
136+
text: "RIGHT CLICK",
126137
xAlign: Clutter.ActorAlign.CENTER,
127138
yAlign: Clutter.ActorAlign.CENTER,
128139
styleClass: 'button kbd',
129-
xExpand: false
140+
xExpand: false,
141+
pseudoClass: "active"
130142
}));
131143
suggestion3.add_child(new St.Label({
132144
text: " to delete a tile.",
@@ -163,7 +175,6 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
163175

164176
private _drawLayouts(params: {
165177
layouts: Layout[],
166-
scalingFactor: number,
167178
onDeleteLayout: (ind: number, lay: Layout) => void,
168179
onSelectLayout: (ind: number, lay: Layout) => void,
169180
onNewLayout: () => void
@@ -178,7 +189,7 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
178189
styleClass: "layout-button-container"
179190
});
180191
this._layoutsBoxLayout.add_child(box);
181-
const btn = new LayoutButton(box, lay, gaps, params.scalingFactor, this._layoutHeight, this._layoutWidth);
192+
const btn = new LayoutButton(box, lay, gaps, this._layoutHeight, this._layoutWidth);
182193
if (params.layouts.length > 1) {
183194
const deleteBtn = new St.Button({xExpand: false, xAlign: Clutter.ActorAlign.CENTER, styleClass: "message-list-clear-button icon-button button delete-layout-button"});
184195
deleteBtn.child = new St.Icon({ iconName: "edit-delete-symbolic", iconSize: 16 });
@@ -195,12 +206,12 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
195206
});
196207

197208
const box = new St.BoxLayout({
198-
vertical: true,
209+
vertical: true,
199210
xAlign: Clutter.ActorAlign.CENTER,
200211
styleClass: "layout-button-container"
201212
});
202213
this._layoutsBoxLayout.add_child(box);
203-
const newLayoutBtn = new LayoutButton(box, new Layout([new Tile({x: 0, y: 0, width: 1, height: 1, groups: []})], "New Layout"), gaps, params.scalingFactor, this._layoutHeight, this._layoutWidth);
214+
const newLayoutBtn = new LayoutButton(box, new Layout([new Tile({x: 0, y: 0, width: 1, height: 1, groups: []})], "New Layout"), gaps, this._layoutHeight, this._layoutWidth);
204215
const icon = new St.Icon({ iconName: "list-add-symbolic", iconSize: 32 });
205216
icon.set_size(newLayoutBtn.child.width, newLayoutBtn.child.height);
206217
newLayoutBtn.child.add_child(icon);

Diff for: src/components/editor/hoverLine.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Mtk from 'gi://Mtk';
66
import Clutter from "gi://Clutter";
77
import EditableTilePreview from "./editableTilePreview";
88
import { logger } from "@/utils/shell";
9+
import { getScalingFactorOf } from "@utils/ui";
910

1011
const debug = logger("HoverLine");
1112

@@ -18,10 +19,13 @@ export default class HoverLine extends St.Widget {
1819

1920
private _hoveredTile: EditableTilePreview | null;
2021

21-
constructor(workArea: Mtk.Rectangle, scalingFactor: number) {
22+
constructor(parent: Clutter.Actor, workArea: Mtk.Rectangle) {
2223
super({ styleClass: "hover-line"});
24+
parent.add_child(this);
2325

2426
this._hoveredTile = null;
27+
28+
const [_, scalingFactor] = getScalingFactorOf(this);
2529
this._size = 16 * scalingFactor;
2630
this._workArea = workArea;
2731

Diff for: src/components/editor/layoutEditor.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Mtk from "gi://Mtk";
66
import Settings from "@/settings";
77
import Shell from 'gi://Shell';
88
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
9-
import { buildMargin, buildRectangle, buildTileMargin, getEventCoords, getScalingFactor, getWindowsOfMonitor } from "@/utils/ui";
9+
import { buildMargin, buildRectangle, buildTileGaps, enableScalingFactorSupport, getEventCoords, getScalingFactor, getWindowsOfMonitor } from "@/utils/ui";
1010
import Layout from "../layout/Layout";
1111
import TileUtils from "../layout/TileUtils";
1212
import Slider from "./slider";
@@ -23,33 +23,35 @@ export default class LayoutEditor extends St.Widget {
2323
private _layout: Layout;
2424
private _containerRect: Mtk.Rectangle;
2525
private _sliders: Slider[];
26-
private _scaleFactor: number;
2726
private _innerGaps: Clutter.Margin;
2827
private _outerGaps: Clutter.Margin;
2928

3029
private _minimizedWindows: Meta.Window[];
3130

3231
private readonly _hoverWidget: HoverLine;
3332

34-
constructor(layout: Layout, monitor: Monitor) {
33+
constructor(layout: Layout, monitor: Monitor, enableScaling: boolean) {
3534
super({ styleClass: "layout-editor" });
36-
Shell.Global.get().windowGroup.add_child(this);
35+
global.windowGroup.add_child(this);
36+
37+
if (enableScaling) {
38+
const scalingFactor = getScalingFactor(monitor.index);
39+
enableScalingFactorSupport(this, scalingFactor);
40+
}
3741

3842
const workArea = Main.layoutManager.getWorkAreaForMonitor(monitor.index);
3943
this.set_position(workArea.x, workArea.y);
4044
this.set_size(workArea.width, workArea.height);
41-
this._scaleFactor = getScalingFactor(monitor.index);
42-
this._innerGaps = buildMargin(Settings.get_inner_gaps(this._scaleFactor));
43-
this._outerGaps = buildMargin(Settings.get_outer_gaps(this._scaleFactor));
45+
this._innerGaps = buildMargin(Settings.get_inner_gaps());
46+
this._outerGaps = buildMargin(Settings.get_outer_gaps());
4447
this._sliders = [];
4548
this._containerRect = buildRectangle({ x: 0, y: 0, width: workArea.width, height: workArea.height });
4649

4750

4851
this._minimizedWindows = getWindowsOfMonitor(monitor).filter(win => !win.is_hidden());
4952
this._minimizedWindows.forEach(win => win.can_minimize() && win.minimize());
5053

51-
this._hoverWidget = new HoverLine(workArea.copy(), this._scaleFactor);
52-
this.add_child(this._hoverWidget);
54+
this._hoverWidget = new HoverLine(this, workArea.copy());
5355

5456
this.connect("destroy", this._onDestroy.bind(this));
5557

@@ -129,7 +131,7 @@ export default class LayoutEditor extends St.Widget {
129131
}
130132

131133
private _buildEditableTile(tile: Tile, rect: Mtk.Rectangle) : EditableTilePreview {
132-
const gaps = buildTileMargin(rect, this._innerGaps, this._outerGaps, this._containerRect);
134+
const gaps = buildTileGaps(rect, this._innerGaps, this._outerGaps, this._containerRect);
133135
const editableTile = new EditableTilePreview({ parent: this, tile, containerRect: this._containerRect, rect, gaps });
134136
editableTile.open();
135137
editableTile.connect("clicked", (_, clicked_button: number) => {
@@ -243,8 +245,7 @@ export default class LayoutEditor extends St.Widget {
243245
groupId,
244246
coord,
245247
coord,
246-
isHorizontal,
247-
this._scaleFactor
248+
isHorizontal
248249
);
249250
}
250251

Diff for: src/components/editor/slider.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Meta from 'gi://Meta';
77
import Mtk from 'gi://Mtk';
88
import GObject from "gi://GObject";
99
import { MetaInfo } from "gi://GObject";
10-
import { getEventCoords } from "@utils/ui";
10+
import { getEventCoords, getScalingFactorOf } from "@utils/ui";
1111

1212
const debug = logger("Slider");
1313

@@ -37,19 +37,21 @@ export default class Slider extends St.Button {
3737
private _maxTileCoord: number;
3838
private _scalingFactor: number;
3939

40-
constructor(parent: Clutter.Actor, groupId: number, x: number, y: number, horizontal: boolean, scaleFactor: number) {
40+
constructor(parent: Clutter.Actor, groupId: number, x: number, y: number, horizontal: boolean) {
4141
super({
4242
styleClass: "layout-editor-slider",
4343
canFocus: true,
4444
xExpand: false,
4545
trackHover: true,
4646
});
4747
parent.add_child(this);
48+
4849
this._signals = new Map<EditableTilePreview, number[]>();
4950

5051
this._groupId = groupId;
5152
this._horizontalDir = horizontal;
52-
this._scalingFactor = scaleFactor;
53+
const [_, scalingFactor] = getScalingFactorOf(this);
54+
this._scalingFactor = scalingFactor;
5355
this.set_width(this.desiredWidth);
5456
this.set_height(this.desiredHeight);
5557

Diff for: src/components/layout/LayoutWidget.ts

+44-20
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import St from "gi://St";
22
import TilePreview from "../tilepreview/tilePreview";
33
import Clutter from 'gi://Clutter';
44
import Mtk from 'gi://Mtk';
5-
import GObject from 'gi://GObject';
6-
import { buildRectangle, buildTileMargin } from "@/utils/ui";
5+
import { buildRectangle, buildTileGaps, enableScalingFactorSupport } from "@/utils/ui";
76
import { logger } from "@/utils/shell";
87
import Layout from "./Layout";
98
import Tile from "./Tile";
@@ -12,30 +11,55 @@ import { registerGObjectClass } from "@utils/gjs";
1211

1312
const debug = logger(`LayoutWidget`);
1413

14+
export module LayoutWidget {
15+
export interface ConstructorProperties
16+
extends St.Widget.ConstructorProperties {
17+
parent: Clutter.Actor;
18+
layout: Layout;
19+
innerGaps: Clutter.Margin;
20+
outerGaps: Clutter.Margin
21+
containerRect: Mtk.Rectangle;
22+
scalingFactor?: number;
23+
}
24+
}
25+
1526
// A widget to draw a layout
1627
@registerGObjectClass
1728
export default class LayoutWidget<TileType extends TilePreview> extends St.Widget {
1829
protected _previews: TileType[];
1930
protected _containerRect: Mtk.Rectangle;
2031
protected _layout: Layout;
21-
protected _innerMargin: Clutter.Margin;
22-
protected _outerMargin: Clutter.Margin;
32+
protected _innerGaps: Clutter.Margin;
33+
protected _outerGaps: Clutter.Margin;
34+
35+
constructor(params: LayoutWidget.ConstructorProperties) {
36+
super({ styleClass: params.styleClass || "" });
37+
params.parent.add_child(this);
38+
if (params.scalingFactor) this.scalingFactor = params.scalingFactor;
2339

24-
constructor(parent: Clutter.Actor | null, layout: Layout, innerMargin: Clutter.Margin, outerMargin: Clutter.Margin, containerRect: Mtk.Rectangle, styleClass: string = "") {
25-
super({ styleClass });
26-
if (parent) parent.add_child(this);
2740
this._previews = [];
28-
this._containerRect = buildRectangle();
29-
this._layout = new Layout([], "");
30-
this._innerMargin = new Clutter.Margin();
31-
this._outerMargin = new Clutter.Margin();
32-
this.relayout({ containerRect, layout, innerMargin, outerMargin });
41+
this._containerRect = params.containerRect || buildRectangle();
42+
this._layout = params.layout || new Layout([], "");
43+
this._innerGaps = params.innerGaps || new Clutter.Margin();
44+
this._outerGaps = params.outerGaps || new Clutter.Margin();
45+
}
46+
47+
public set scalingFactor(value: number) {
48+
enableScalingFactorSupport(this, value);
49+
}
50+
51+
public get innerGaps(): Clutter.Margin {
52+
return this._innerGaps.copy();
53+
}
54+
55+
public get outerGaps(): Clutter.Margin {
56+
return this._outerGaps.copy();
3357
}
3458

3559
protected draw_layout(): void {
3660
this._previews = this._layout.tiles.map(tile => {
3761
const tileRect = TileUtils.apply_props(tile, this._containerRect);
38-
const tileMargin = buildTileMargin(tileRect, this._innerMargin, this._outerMargin, this._containerRect);
62+
const tileMargin = buildTileGaps(tileRect, this._innerGaps, this._outerGaps, this._containerRect);
3963
return this.buildTile(this, tileRect, tileMargin, tile);
4064
});
4165
}
@@ -47,16 +71,16 @@ export default class LayoutWidget<TileType extends TilePreview> extends St.Widge
4771
public relayout(params?: Partial<{
4872
layout: Layout,
4973
containerRect: Mtk.Rectangle,
50-
innerMargin: Clutter.Margin,
51-
outerMargin: Clutter.Margin
74+
innerGaps: Clutter.Margin,
75+
outerGaps: Clutter.Margin
5276
}>) {
53-
var trigger_relayout = false;
54-
if (params?.innerMargin) {
55-
this._innerMargin = params.innerMargin.copy();
77+
var trigger_relayout = this._previews.length === 0;
78+
if (params?.innerGaps) {
79+
this._innerGaps = params.innerGaps.copy();
5680
trigger_relayout = true;
5781
}
58-
if (params?.outerMargin && this._outerMargin !== params.outerMargin) {
59-
this._outerMargin = params.outerMargin.copy();
82+
if (params?.outerGaps && this._outerGaps !== params.outerGaps) {
83+
this._outerGaps = params.outerGaps.copy();
6084
trigger_relayout = true;
6185
}
6286
if (params?.layout && this._layout !== params.layout) {

0 commit comments

Comments
 (0)