Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Implementation of SlabsLayout - A simple stacked layout for vertical monitors #416

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/config/bismuth_config.kcfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<default>false</default>
</entry>

<entry name="enableSlabsLayout" type="Bool">
<label>Enable/disable Slabs layout</label>
<default>true</default>
</entry>

<entry name="enableFloatingLayout" type="Bool">
<label>Enable/disable Floating layout</label>
<default>false</default>
Expand Down
1 change: 1 addition & 0 deletions src/core/ts-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ QJSValue TSProxy::jsConfig()
addLayout("enableQuarterLayout", "QuarterLayout");
addLayout("enableFloatingLayout", "FloatingLayout");
addLayout("enableCascadeLayout", "CascadeLayout");
addLayout("enableSlabsLayout", "SlabsLayout");

setProp("monocleMaximize", m_config.monocleMaximize());
setProp("maximizeSoleTile", m_config.maximizeSoleTile());
Expand Down
5 changes: 5 additions & 0 deletions src/kcm/package/contents/ui/views/Layouts.qml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ Kirigami.Page {
settingName: "enableQuarterLayout"
}

ListElement {
name: "Slabs"
settingName: "enableSlabsLayout"
}

ListElement {
name: "Floating"
settingName: "enableFloatingLayout"
Expand Down
13 changes: 13 additions & 0 deletions src/kwinscript/controller/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,19 @@ export class ToggleSpiralLayout extends ToggleCurrentLayout {
}
}

export class ToggleSlabsLayout extends ToggleCurrentLayout {
constructor(protected engine: Engine, protected log: Log) {
super(
engine,
"SlabsLayout",
"toggle_slabs_layout",
"Toggle Slabs Layout",
"",
log
);
}
}

export class Rotate extends ActionImpl implements Action {
constructor(protected engine: Engine, protected log: Log) {
super(engine, "rotate", "Rotate", "Meta+R", log);
Expand Down
1 change: 1 addition & 0 deletions src/kwinscript/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ export class ControllerImpl implements Controller {
new Action.ToggleFloatingLayout(this.engine, this.log),
new Action.ToggleQuarterLayout(this.engine, this.log),
new Action.ToggleSpiralLayout(this.engine, this.log),
new Action.ToggleSlabsLayout(this.engine, this.log),

new Action.Rotate(this.engine, this.log),
new Action.RotateReverse(this.engine, this.log),
Expand Down
83 changes: 83 additions & 0 deletions src/kwinscript/engine/layout/slabs_layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-FileCopyrightText: 2022 Joe Dean <joe@joedean.dev>
//
// SPDX-License-Identifier: MIT

import { WindowsLayout } from ".";

import { WindowState, EngineWindow } from "../window";

import { Rect } from "../../util/rect";
import { Config } from "../../config";
import { Controller } from "../../controller";

/* "Slabs" stacks up to 5 windows bottom-to-top (ideal for vertically-rotated
monitors). It shares the available space equally between windows; if there are
more than 2 windows, the "first" window will be given 50% more than the others*/
export default class SlabsLayout implements WindowsLayout {
public static readonly id = "SlabsLayout";
public readonly classID = SlabsLayout.id;
public readonly name = "Slabs Layout";
public readonly icon = "bismuth-slabs";
public readonly capacity = 3;

private config: Config;

public constructor(config: Config) {
this.config = config;
}

public clone(): WindowsLayout {
return new SlabsLayout(this.config);
}

public apply(
_controller: Controller,
tileables: EngineWindow[],
area: Rect
): void {
if (tileables.length <= 0) {
return;
}

const tileCount = Math.min(this.capacity, tileables.length);
let tileSize =
(area.height - Math.max(0, tileCount - 1) * this.config.tileLayoutGap) /
tileCount;
let firstTileSize = tileSize;
if (tileCount > 2) {
firstTileSize *= 1.5;
tileSize =
(area.height - firstTileSize - tileCount * this.config.tileLayoutGap) /
(tileCount - 1);
}

let xPos = 0;
for (let i = 0; i < tileCount; i++) {
const currentTileSize = i == 0 ? firstTileSize : tileSize;
tileables[i].geometry = new Rect(
area.x,
area.height - (xPos + currentTileSize),
area.width,
currentTileSize
);
xPos += this.config.tileLayoutGap + currentTileSize;
}
for (let i = 0; i < tileables.length; i++) {
if (i < tileCount) {
tileables[i].state = WindowState.Tiled;
} else {
tileables[i].state = WindowState.TiledAfloat;
tileables[i].geometry = new Rect(
area.x,
area.y,
area.width,
area.height
);
}
}
}

public toString(): string {
return "SlabsLayout()";
}
}
3 changes: 3 additions & 0 deletions src/kwinscript/engine/layout_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import SpiralLayout from "./layout/spiral_layout";
import SpreadLayout from "./layout/spread_layout";
import StairLayout from "./layout/stair_layout";
import ThreeColumnLayout from "./layout/three_column_layout";
import SlabsLayout from "./layout/slabs_layout";

export class LayoutStoreEntry {
public get currentLayout(): WindowsLayout {
Expand Down Expand Up @@ -96,6 +97,8 @@ export class LayoutStoreEntry {
return new ThreeColumnLayout(this.config);
} else if (id == TileLayout.id) {
return new TileLayout(this.config);
} else if (id == SlabsLayout.id) {
return new SlabsLayout(this.config);
} else {
return new FloatingLayout();
}
Expand Down
13 changes: 13 additions & 0 deletions src/kwinscript/icons/16-status-bismuth-slabs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/kwinscript/icons/32-status-bismuth-slabs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/kwinscript/icons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ecm_install_icons(
16-status-bismuth-floating.svg
16-status-bismuth-monocle.svg
16-status-bismuth-quarter.svg
16-status-bismuth-slabs.svg
16-status-bismuth-spiral.svg
16-status-bismuth-spread.svg
16-status-bismuth-stair.svg
Expand All @@ -15,6 +16,7 @@ ecm_install_icons(
32-status-bismuth-floating.svg
32-status-bismuth-monocle.svg
32-status-bismuth-quarter.svg
32-status-bismuth-slabs.svg
32-status-bismuth-spiral.svg
32-status-bismuth-spread.svg
32-status-bismuth-stair.svg
Expand Down