Add floating layout

This commit is contained in:
2023-05-13 15:58:13 +09:00
parent 3599ae4bdb
commit 7286c71da5
5 changed files with 63 additions and 17 deletions
+4
View File
@@ -51,6 +51,10 @@ function fillPreferencesWindow(window) {
const tileBindings = new Adw.PreferencesGroup();
keybinds.add(tileBindings);
tileBindings.add(_createKeybind(settings, "set-layout-tiling"));
tileBindings.add(_createKeybind(settings, "set-layout-monocle"));
tileBindings.add(_createKeybind(settings, "set-layout-floating"));
tileBindings.add(_createKeybind(settings, "incrmfact"));
tileBindings.add(_createKeybind(settings, "decmfact"));
tileBindings.add(_createKeybind(settings, "incrnmaster"));
@@ -55,6 +55,11 @@
<default><![CDATA[['<Super>j']]]></default>
<summary>Cycle prev</summary>
</key>
<key type="as" name="zoom">
<default><![CDATA[['<Super><Return>']]]></default>
<summary>Swap the current window with the master</summary>
</key>
<key type="as" name="incrmfact">
<default><![CDATA[['<Super>l']]]></default>
@@ -70,15 +75,10 @@
<summary>Increase the number of windows in the master area</summary>
</key>
<key type="as" name="decnmaster">
<default><![CDATA[['<Super>d']]]></default>
<default><![CDATA[['<Super>o']]]></default>
<summary>Decrease the number of windows in the master area</summary>
</key>
<key type="as" name="zoom">
<default><![CDATA[['<Super><Return>']]]></default>
<summary>Swap the current window with the master</summary>
</key>
<!-- TODO: Add fullscreen, swapnext/swapprev, monitors and tags key -->
</schema>
</schemalist>
+23 -2
View File
@@ -12,7 +12,6 @@ var KeyboardManager = GObject.registerClass(
super._init();
this._state = state;
this._renderer = renderer;
// TODO: Handle rerender from here.
}
/**
@@ -41,6 +40,25 @@ var KeyboardManager = GObject.registerClass(
}
enable() {
this._addBinding("set-layout-tiling", () => {
const mon = global.display.get_current_monitor();
const state = this._state.monitors[mon];
state.layout = "tiling";
this._renderer.render(mon);
});
this._addBinding("set-layout-monocle", () => {
const mon = global.display.get_current_monitor();
const state = this._state.monitors[mon];
state.layout = "monocle";
this._renderer.render(mon);
});
this._addBinding("set-layout-floating", () => {
const mon = global.display.get_current_monitor();
const state = this._state.monitors[mon];
state.layout = "floating";
this._renderer.render(mon);
});
this._addBinding("incrmfact", () => {
const mon = global.display.get_current_monitor();
const state = this._state.monitors[mon];
@@ -68,9 +86,12 @@ var KeyboardManager = GObject.registerClass(
}
disable() {
this._removeBinding("set-layout-tiling");
this._removeBinding("set-layout-monocle");
this._removeBinding("set-layout-floating");
this._removeBinding("incrmfact");
this._removeBinding("decrmfact");
this._removeBinding("incrnmaster");
this._removeBinding("decrnmaster");
}
+20 -7
View File
@@ -161,6 +161,8 @@ var Renderer = GObject.registerClass(
window._signals = [
window.connect("unmanaging", (window) => {
window._isInvalid = true;
const faWindow = this._state.popByActor(actor);
if (faWindow) this.render(faWindow.monitor, faWindow.tags);
}),
window.connect("workspace-changed", (window) => {
if (!this._isValidWindow(window)) return;
@@ -168,14 +170,18 @@ var Renderer = GObject.registerClass(
if (oldW) this.render(oldW.monitor, oldW.tags);
if (newW) this.render(newW.monitor, newW.tags);
}),
];
const actor = window.get_compositor_private();
actor._signals = [
actor.connect("destroy", (actor) => {
const faWindow = this._state.popByActor(actor);
if (faWindow) this.render(faWindow.monitor, faWindow.tags);
window.connect("focus", (window) => {
if (!this._isValidWindow(window)) return;
this._state.monitors[window.get_monitor()].focused = window;
}),
];
const actor = window.get_compositor_private();
// actor._signals = [
// actor.connect("destroy", (actor) => {
// const faWindow = this._state.popByActor(actor);
// if (faWindow) this.render(faWindow.monitor, faWindow.tags);
// }),
// ];
this._state.newWindow(window);
}
@@ -212,6 +218,9 @@ var Renderer = GObject.registerClass(
for (const window of this._state.render(mon, tags)) {
if (window.handle.get_monitor() !== mon)
window.handle.move_to_monitor(mon);
if (window.floating) continue;
if (window.handle.minimized !== window.minimized) {
if (window.minimized) window.handle.minimize();
else window.handle.unminimize();
@@ -221,7 +230,11 @@ var Renderer = GObject.registerClass(
window.handle["maximized-horizontally"] ||
window.handle["maximized-vertically"] != window.maximized
) {
if (window.maximized) window.handle.maximize(Meta.MaximizeFlags.BOTH);
if (window.maximized) {
window.handle.maximize(Meta.MaximizeFlags.BOTH);
// Do not resize if maximizing to keep the overview tiled.
continue;
}
else window.handle.unmaximize(Meta.MaximizeFlags.BOTH);
}
+10 -2
View File
@@ -13,7 +13,7 @@ var StateManager = GObject.registerClass(
*/
focused: null,
tags: 1,
layout: "tiled",
layout: "tiling",
nmaster: 1,
mfact: 55,
}));
@@ -79,6 +79,9 @@ var StateManager = GObject.registerClass(
* @property {number} y - in percentage from the top left
* @property {number} width - in percentage (0-100)
* @property {number} height - in percentage
* @property {boolean} minimized
* @property {boolean} maximized
* @property {boolean} floating
* @returns WindowGeometry[]
*/
render(mon, tags) {
@@ -102,7 +105,7 @@ var StateManager = GObject.registerClass(
height: 100,
},
];
case "tiled":
case "tiling":
return windows.map((x, i) => {
const stackLength =
i < nmaster
@@ -124,6 +127,11 @@ var StateManager = GObject.registerClass(
height: 100 / stackLength,
};
});
case "floating":
return windows.map((x) => ({
handle: x.handle,
floating: true,
}));
default:
return [];
}