Skip to content

Commit 71c6f71

Browse files
committed
version 6: tiles are dynamically split when there is an irregular selection
1 parent 04c16d9 commit 71c6f71

File tree

15 files changed

+248
-81
lines changed

15 files changed

+248
-81
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "modernwindowmanager",
3-
"version": "5.0.0",
3+
"version": "6.0.0",
44
"author": "Domenico Ferraro <[email protected]>",
55
"private": true,
66
"license": "GPL v2.0",

resources/metadata.json

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

src/components/editor/editorDialog.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
1919
private readonly _layoutHeight: number = 72;
2020
private readonly _layoutWidth: number = 128; // 16:9 ratio. -> (16*layoutHeight) / 9 and then rounded to int
2121
private readonly _gapsSize: number = 3;
22-
private readonly _signals: SignalHandling;
2322

2423
private _layoutsBoxLayout: St.BoxLayout;
2524

@@ -31,7 +30,7 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
3130
legend: boolean
3231
}) {
3332
super({
34-
destroyOnClose: false,
33+
destroyOnClose: true,
3534
styleClass: 'editor-dialog',
3635
});
3736

@@ -59,9 +58,9 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
5958

6059
if (!params.legend) {
6160
this._drawLayouts({ layouts: GlobalState.get().layouts, ...params });
62-
this._signals.connect(GlobalState.get(), "layouts-changed", () => {
61+
/*this._signals.connect(GlobalState.get(), GlobalState.SIGNAL_LAYOUTS_CHANGED, () => {
6362
this._drawLayouts({ layouts: GlobalState.get().layouts, ...params });
64-
});
63+
});*/
6564
}
6665

6766
this.addButton({
@@ -74,8 +73,6 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
7473
});
7574

7675
if (params.legend) this._makeLegendDialog();
77-
78-
this.connect("destroy", () => this._signals.disconnect());
7976
}
8077

8178
private _makeLegendDialog() {
@@ -152,8 +149,8 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
152149
legend.add_child(suggestion1);
153150
legend.add_child(suggestion2);
154151
legend.add_child(suggestion3);
155-
this._signals.disconnect();
156-
this.contentLayout.remove_all_children();
152+
153+
this.contentLayout.destroy_all_children();
157154
this.contentLayout.add_child(new St.Label({
158155
text: "How to use the editor",
159156
xAlign: Clutter.ActorAlign.CENTER,
@@ -180,7 +177,7 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
180177
onNewLayout: () => void
181178
}) {
182179
const gaps = Settings.get_inner_gaps(1).top > 0 ? this._gapsSize:0
183-
this._layoutsBoxLayout.remove_all_children();
180+
this._layoutsBoxLayout.destroy_all_children();
184181

185182
params.layouts.forEach((lay, btnInd) => {
186183
const box = new St.BoxLayout({
@@ -195,6 +192,7 @@ export default class EditorDialog extends ModalDialog.ModalDialog {
195192
deleteBtn.child = new St.Icon({ iconName: "edit-delete-symbolic", iconSize: 16 });
196193
deleteBtn.connect('clicked', (self) => {
197194
params.onDeleteLayout(btnInd, lay);
195+
this._drawLayouts({ ...params, layouts: GlobalState.get().layouts });
198196
});
199197
box.add_child(deleteBtn);
200198
}

src/components/editor/layoutEditor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export default class LayoutEditor extends St.Widget {
6464
}
6565

6666
public set layout(newLayout: Layout) {
67-
debug("set layout");
6867
// cleanup
6968
this._sliders.forEach(slider => slider.destroy());
7069
this._sliders = [];

src/components/layout/LayoutWidget.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default class LayoutWidget<TileType extends TilePreview> extends St.Widge
7373
containerRect: Mtk.Rectangle,
7474
innerGaps: Clutter.Margin,
7575
outerGaps: Clutter.Margin
76-
}>) {
76+
}>): boolean {
7777
var trigger_relayout = this._previews.length === 0;
7878
if (params?.innerGaps) {
7979
this._innerGaps = params.innerGaps.copy();
@@ -94,15 +94,21 @@ export default class LayoutWidget<TileType extends TilePreview> extends St.Widge
9494

9595
if (!trigger_relayout) {
9696
debug("relayout not needed");
97-
return;
97+
return false;
9898
}
9999

100-
this._previews?.forEach((preview) => preview.destroy());
101-
this.remove_all_children();
100+
this._previews?.forEach((preview) => {
101+
if (preview.get_parent() === this) {
102+
this.remove_child(preview);
103+
}
104+
preview.destroy();
105+
});
102106
this._previews = [];
103-
if (this._containerRect.width === 0 || this._containerRect.height === 0) return;
107+
if (this._containerRect.width === 0 || this._containerRect.height === 0) return true;
104108

105109
this.draw_layout();
106110
this._previews.forEach((lay) => lay.open());
111+
112+
return true;
107113
}
108114
}

src/components/snapassist/snapAssistLayout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class SnapAssistLayout extends LayoutWidget<SnapAssistTile> {
3131

3232
super.relayout({
3333
containerRect: buildRectangle({x: 0, y: 0, width, height})
34-
})
34+
});
3535
}
3636

3737
buildTile(parent: Clutter.Actor, rect: Mtk.Rectangle, gaps: Clutter.Margin, tile: Tile): SnapAssistTile {

src/components/snapassist/snapAssistTile.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const debug = logger("SnapAssistTile");
1212
@registerGObjectClass
1313
export default class SnapAssistTile extends TilePreview {
1414
protected _tile: Tile;
15+
private _styleChangedSignalID: number | undefined;
1516

1617
constructor(params: {
1718
parent?: Clutter.Actor,
@@ -42,14 +43,13 @@ export default class SnapAssistTile extends TilePreview {
4243
);
4344

4445
this._applyStyle();
45-
const styleChangedSignalID = St.ThemeContext.get_for_stage(global.get_stage()).connect(
46-
"changed",
46+
this._styleChangedSignalID = St.ThemeContext.get_for_stage(global.get_stage()).connect(
47+
"changed",
4748
() => {
4849
this._applyStyle();
4950
}
5051
);
51-
52-
this.connect("destroy", () => St.ThemeContext.get_for_stage(global.get_stage()).disconnect(styleChangedSignalID));
52+
this.connect("destroy", () => this.onDestroy());
5353
}
5454

5555
_init() {
@@ -74,4 +74,11 @@ export default class SnapAssistTile extends TilePreview {
7474
this.add_style_class_name("dark");
7575
}
7676
}
77+
78+
onDestroy(): void {
79+
if (this._styleChangedSignalID) {
80+
St.ThemeContext.get_for_stage(global.get_stage()).disconnect(this._styleChangedSignalID);
81+
this._styleChangedSignalID = undefined;
82+
}
83+
}
7784
}

src/components/tilepreview/selectionTilePreview.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { registerGObjectClass } from "@/utils/gjs";
2-
import Mtk from 'gi://Mtk';
32
import Clutter from 'gi://Clutter';
43
import St from 'gi://St';
54
import TilePreview from "./tilePreview";
@@ -40,8 +39,8 @@ export default class SelectionTilePreview extends TilePreview {
4039
close() {
4140
if (!this._showing) return;
4241

43-
this._rect.width = 0;
44-
this._rect.height = 0;
42+
this._rect.width = this.gaps.left + this.gaps.right;
43+
this._rect.height = this.gaps.top + this.gaps.bottom;
4544
super.close();
4645
}
4746
}

src/components/tilepreview/tilePreview.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ export const WINDOW_ANIMATION_TIME = 100;
1010

1111
const debug = logger('tilePreview');
1212

13-
export module TilePreview {
14-
export interface ConstructorProperties
13+
//export module TilePreview {
14+
export interface TilePreviewConstructorProperties
1515
extends St.Widget.ConstructorProperties {
1616
parent: Clutter.Actor;
1717
rect: Mtk.Rectangle;
1818
gaps: Clutter.Margin;
1919
}
20-
}
20+
//}
2121

2222
@registerGObjectClass
2323
export default class TilePreview extends St.Widget {
@@ -26,7 +26,7 @@ export default class TilePreview extends St.Widget {
2626

2727
private _gaps: Clutter.Margin;
2828

29-
constructor(params: Partial<TilePreview.ConstructorProperties>) {
29+
constructor(params: Partial<TilePreviewConstructorProperties>) {
3030
super(params);
3131
if (params.parent) params.parent.add_child(this);
3232

@@ -44,6 +44,10 @@ export default class TilePreview extends St.Widget {
4444
this._gaps.left = gaps.left * scalingFactor;
4545
}
4646

47+
public get gaps(): Clutter.Margin {
48+
return this._gaps;
49+
}
50+
4751
_init() {
4852
super._init();
4953
this.set_style_class_name('tile-preview custom-tile-preview');

0 commit comments

Comments
 (0)