Skip to content

Commit 0dfa910

Browse files
committed
feat: save layouts and active layouts between sessions
1 parent 82179c6 commit 0dfa910

17 files changed

+256
-156
lines changed

layouts.example.json

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
[
2+
{
3+
"tiles": [
4+
{
5+
"x": 0,
6+
"y": 0,
7+
"width": 0.22,
8+
"height": 0.5
9+
},
10+
{
11+
"x": 0,
12+
"y": 0.5,
13+
"width": 0.22,
14+
"height": 0.5
15+
},
16+
{
17+
"x": 0.22,
18+
"y": 0,
19+
"width": 0.56,
20+
"height": 1
21+
},
22+
{
23+
"x": 0.78,
24+
"y": 0,
25+
"width": 0.22,
26+
"height": 0.5
27+
},
28+
{
29+
"x": 0.78,
30+
"y": 0.5,
31+
"width": 0.22,
32+
"height": 0.5
33+
}
34+
]
35+
},
36+
{
37+
"tiles": [
38+
{
39+
"x": 0,
40+
"y": 0,
41+
"width": 0.22,
42+
"height": 1
43+
},
44+
{
45+
"x": 0.22,
46+
"y": 0,
47+
"width": 0.56,
48+
"height": 1
49+
},
50+
{
51+
"x": 0.78,
52+
"y": 0,
53+
"width": 0.22,
54+
"height": 1
55+
}
56+
]
57+
},
58+
{
59+
"tiles": [
60+
{
61+
"x": 0,
62+
"y": 0,
63+
"width": 0.33,
64+
"height": 1
65+
},
66+
{
67+
"x": 0.33,
68+
"y": 0,
69+
"width": 0.67,
70+
"height": 1
71+
}
72+
]
73+
},
74+
{
75+
"tiles": [
76+
{
77+
"x": 0.33,
78+
"y": 0,
79+
"width": 0.67,
80+
"height": 1
81+
},
82+
{
83+
"x": 0,
84+
"y": 0,
85+
"width": 0.33,
86+
"height": 1
87+
}
88+
]
89+
}
90+
]

resources/schemas/org.gnome.shell.extensions.modernwindowmanager.gschema.xml

+12-2
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,28 @@
2020
<key name="inner-gaps" type="u">
2121
<default>16</default>
2222
<summary>Inner gaps</summary>
23-
<description>Internal gaps between tiles in a layout</description>
23+
<description>Internal gaps between tiles in a layout.</description>
2424
</key>
2525
<key name="outer-gaps" type="u">
2626
<default>16</default>
2727
<summary>Outer gaps</summary>
28-
<description>External gaps between the layout and the monitor borders</description>
28+
<description>External gaps between the layout and the monitor borders.</description>
2929
</key>
3030
<key name="enable-span-multiple-tiles" type="b">
3131
<default>true</default>
3232
<summary>Span multiple tiles</summary>
3333
<description>Hold ALT to span multiple tiles.</description>
3434
</key>
35+
<key name="layouts-json" type="s">
36+
<default>'[]'</default>
37+
<summary>Layouts</summary>
38+
<description>The layouts available to the tiling managers and the snap assist.</description>
39+
</key>
40+
<key name="selected-layouts" type="as">
41+
<default>['0']</default>
42+
<summary>Selected layouts</summary>
43+
<description>Each monitor's active layout used by the monitor tiling manager.</description>
44+
</key>
3545
</schema>
3646

3747
</schemalist>

src/components/layout/Layout.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tile } from "./Tile";
1+
import Tile from "./Tile";
22

33
export class Layout {
44
tiles: Tile[];

src/components/layout/LayoutUtils.ts

-61
This file was deleted.

src/components/layout/LayoutWidget.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { registerGObjectClass } from "@/utils/gjs";
66
import { buildTileMargin } from "@/utils/ui";
77
import { logger } from "@/utils/shell";
88
import { Layout } from "./Layout";
9-
import { Tile } from "./Tile";
9+
import Tile from "./Tile";
10+
import TileUtils from "./TileUtils";
1011

1112
const debug = logger(`LayoutWidget`);
1213

@@ -32,7 +33,7 @@ export class LayoutWidget<TileType extends TilePreview> extends Widget {
3233

3334
protected draw_layout(): void {
3435
this._previews = this._layout.tiles.map(tile => {
35-
const tileRect = tile.apply_props(this._containerRect);
36+
const tileRect = TileUtils.apply_props(tile, this._containerRect);
3637
const tileMargin = buildTileMargin(tileRect, this._innerMargin, this._outerMargin, this._containerRect);
3738
return this.buildTile(this, tileRect, tileMargin, tile);
3839
});

src/components/layout/Tile.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Rectangle } from "@gi-types/meta10";
21
import GObject from "@gi-types/gobject2";
32

4-
export class Tile {
3+
export default class Tile {
54
static $gtype = GObject.TYPE_JSOBJECT;
65

76
x: number;
@@ -15,13 +14,4 @@ export class Tile {
1514
this.width = width;
1615
this.height = height;
1716
}
18-
19-
public apply_props(container: Rectangle): Rectangle {
20-
return new Rectangle({
21-
x: (container.width * this.x) + container.x,
22-
y: (container.height * this.y) + container.y,
23-
width: container.width * this.width,
24-
height: container.height * this.height,
25-
})
26-
}
2717
}

src/components/layout/TileUtils.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Rectangle } from "@gi-types/meta10";
2+
import Tile from "./Tile";
3+
4+
export default class TileUtils {
5+
static apply_props(tile: Tile, container: Rectangle): Rectangle {
6+
return new Rectangle({
7+
x: (container.width * tile.x) + container.x,
8+
y: (container.height * tile.y) + container.y,
9+
width: container.width * tile.width,
10+
height: container.height * tile.height,
11+
})
12+
}
13+
}

src/components/snapassist/snapAssist.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { MetaInfo } from "@gi-types/gobject2";
77
import { SnapAssistTile } from "./snapAssistTile";
88
import { SnapAssistLayout } from "./snapAssistLayout";
99
import { Layout } from "../layout/Layout";
10-
import { Tile } from "../layout/Tile";
10+
import Tile from "../layout/Tile";
11+
import Settings from "@/settings";
1112

1213
export const SNAP_ASSIST_SIGNAL = 'snap-assist';
1314
export const SNAP_ASSIST_ANIMATION_TIME = 180;
@@ -33,6 +34,7 @@ export class SnapAssist extends BoxLayout {
3334
private _shrinkHeight = 16;
3435
// distance between layouts
3536
private readonly _separatorSize = 8;
37+
private readonly _gaps = 3;
3638

3739
private _showing: boolean;
3840
private _snapAssistLayouts: SnapAssistLayout[];
@@ -42,7 +44,7 @@ export class SnapAssist extends BoxLayout {
4244
private _workArea: Rectangle = new Rectangle();
4345
private _hoveredTile: SnapAssistTile | undefined;
4446

45-
constructor(parent: Actor, layouts: Layout[], margin: Margin, workArea: Rectangle, scaleFactor: number) {
47+
constructor(parent: Actor, workArea: Rectangle, scaleFactor: number) {
4648
super({
4749
name: 'snap_assist',
4850
x_align: ActorAlign.CENTER,
@@ -57,13 +59,14 @@ export class SnapAssist extends BoxLayout {
5759

5860
this._shrinkHeight *= scaleFactor;
5961

60-
const gap = 3;
62+
const inner_gaps = Settings.get_inner_gaps(1);
6163
const layoutGaps = new Margin({
62-
top: margin.top === 0 ? 0:gap,
63-
bottom: margin.bottom === 0 ? 0:gap,
64-
left: margin.left === 0 ? 0:gap,
65-
right: margin.right === 0 ? 0:gap,
66-
})
64+
top: inner_gaps.top === 0 ? 0:this._gaps,
65+
bottom: inner_gaps.bottom === 0 ? 0:this._gaps,
66+
left: inner_gaps.left === 0 ? 0:this._gaps,
67+
right: inner_gaps.right === 0 ? 0:this._gaps,
68+
});
69+
const layouts = Settings.get_layouts();
6770
// build the layouts inside the snap assistant. Place a spacer between each layout
6871
this._snapAssistLayouts = layouts.map((lay, ind) => {
6972
const saLay = new SnapAssistLayout(this, lay, layoutGaps, scaleFactor);
@@ -80,14 +83,10 @@ export class SnapAssist extends BoxLayout {
8083

8184
const padding = this.get_theme_node().get_padding(Side.BOTTOM);
8285
const scaledPadding = ThemeContext.get_for_stage(global.get_stage()).get_scale_factor() === 1 ?
83-
padding * scaleFactor:padding;
86+
(padding * scaleFactor):padding;
8487
this.set_style(`
8588
padding: ${scaledPadding}px !important;
8689
`);
87-
/*const color = this.get_theme_node().get_background_color();
88-
const newAlpha = 220;
89-
background-color: rgba(${color.red}, ${color.green}, ${color.blue}, ${newAlpha / 255}) !important;
90-
*/
9190

9291
this.ensure_style();
9392
this._enlargedRect.height = this.size.height;

src/components/snapassist/snapAssistLayout.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LayoutWidget } from "../layout/LayoutWidget";
66
import { SnapAssistTile } from "./snapAssistTile";
77
import { logger } from "@/utils/shell";
88
import { Layout } from "../layout/Layout";
9-
import { Tile } from "../layout/Tile";
9+
import Tile from "../layout/Tile";
1010

1111
const debug = logger("snapAssistLayout");
1212

src/components/tilepreview/selectionTilePreview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Rectangle } from "@gi-types/meta10";
33
import { Actor, Color, Margin } from '@gi-types/clutter10';
44
import { TilePreview } from "./tilePreview";
55
import { logger } from "@/utils/shell";
6-
import { Tile } from "../layout/Tile";
6+
import Tile from "../layout/Tile";
77

88
const debug = logger("SelectionTilePreview");
99

src/components/tilepreview/tilePreview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {registerGObjectClass} from "@/utils/gjs";
44
import {logger} from "@/utils/shell";
55
import {global} from "@/utils/ui";
66
import { Actor, AnimationMode, Margin } from '@gi-types/clutter10';
7-
import { Tile } from "../layout/Tile";
7+
import Tile from "../layout/Tile";
88

99
export const WINDOW_ANIMATION_TIME = 100;
1010

src/components/tilingLayout.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BlurTilePreview } from './tilepreview/blurTilePreview';
77
import { TilePreview, WINDOW_ANIMATION_TIME } from './tilepreview/tilePreview';
88
import { LayoutWidget } from './layout/LayoutWidget';
99
import { Layout } from './layout/Layout';
10-
import { Tile } from './layout/Tile';
10+
import Tile from './layout/Tile';
1111

1212
const debug = logger('tilingLayout');
1313

0 commit comments

Comments
 (0)