diff --git a/src/controller/shortcut.ts b/src/controller/action.ts similarity index 96% rename from src/controller/shortcut.ts rename to src/controller/action.ts index 7df9819e..1295b01d 100644 --- a/src/controller/shortcut.ts +++ b/src/controller/action.ts @@ -3,7 +3,7 @@ // // SPDX-License-Identifier: MIT -export enum Shortcut { +export enum Action { Left, Right, Up, diff --git a/src/controller/index.ts b/src/controller/index.ts index 0bc3f414..533141ff 100644 --- a/src/controller/index.ts +++ b/src/controller/index.ts @@ -3,7 +3,7 @@ // // SPDX-License-Identifier: MIT -import { Shortcut } from "./shortcut"; +import { Action } from "./action"; import { Engine, TilingEngine } from "../engine"; import Window from "../engine/window"; @@ -144,7 +144,7 @@ export interface Controller { * @param input the shortcut action. For example focus the next window, or change the layout. * @param data the action optional data, that it could held. For example the layout name to which user want to change. */ - onShortcut(input: Shortcut, data?: any): void; + onShortcut(input: Action, data?: any): void; /** * Ask engine to manage the window @@ -348,33 +348,33 @@ export class TilingController implements Controller { window.timestamp = new Date().getTime(); } - public onShortcut(input: Shortcut, data?: string): void { + public onShortcut(input: Action, data?: string): void { if (this.config.directionalKeyMode === "focus") { switch (input) { - case Shortcut.Up: - input = Shortcut.FocusUp; + case Action.Up: + input = Action.FocusUp; break; - case Shortcut.Down: - input = Shortcut.FocusDown; + case Action.Down: + input = Action.FocusDown; break; - case Shortcut.Left: - input = Shortcut.FocusLeft; + case Action.Left: + input = Action.FocusLeft; break; - case Shortcut.Right: - input = Shortcut.FocusRight; + case Action.Right: + input = Action.FocusRight; break; - case Shortcut.ShiftUp: - input = Shortcut.SwapUp; + case Action.ShiftUp: + input = Action.SwapUp; break; - case Shortcut.ShiftDown: - input = Shortcut.SwapDown; + case Action.ShiftDown: + input = Action.SwapDown; break; - case Shortcut.ShiftLeft: - input = Shortcut.SwapLeft; + case Action.ShiftLeft: + input = Action.SwapLeft; break; - case Shortcut.ShiftRight: - input = Shortcut.SwapRight; + case Action.ShiftRight: + input = Action.SwapRight; break; } } @@ -386,92 +386,92 @@ export class TilingController implements Controller { const window = this.currentWindow; switch (input) { - case Shortcut.Up: + case Action.Up: this.engine.focusOrder(-1); break; - case Shortcut.Down: + case Action.Down: this.engine.focusOrder(+1); break; - case Shortcut.FocusUp: + case Action.FocusUp: this.engine.focusDir("up"); break; - case Shortcut.FocusDown: + case Action.FocusDown: this.engine.focusDir("down"); break; - case Shortcut.FocusLeft: + case Action.FocusLeft: this.engine.focusDir("left"); break; - case Shortcut.FocusRight: + case Action.FocusRight: this.engine.focusDir("right"); break; - case Shortcut.GrowWidth: + case Action.GrowWidth: if (window) { this.engine.resizeWindow(window, "east", 1); } break; - case Shortcut.ShrinkWidth: + case Action.ShrinkWidth: if (window) { this.engine.resizeWindow(window, "east", -1); } break; - case Shortcut.GrowHeight: + case Action.GrowHeight: if (window) { this.engine.resizeWindow(window, "south", 1); } break; - case Shortcut.ShrinkHeight: + case Action.ShrinkHeight: if (window) { this.engine.resizeWindow(window, "south", -1); } break; - case Shortcut.ShiftUp: + case Action.ShiftUp: if (window) { this.engine.swapOrder(window, -1); } break; - case Shortcut.ShiftDown: + case Action.ShiftDown: if (window) { this.engine.swapOrder(window, +1); } break; - case Shortcut.SwapUp: + case Action.SwapUp: this.engine.swapDirOrMoveFloat("up"); break; - case Shortcut.SwapDown: + case Action.SwapDown: this.engine.swapDirOrMoveFloat("down"); break; - case Shortcut.SwapLeft: + case Action.SwapLeft: this.engine.swapDirOrMoveFloat("left"); break; - case Shortcut.SwapRight: + case Action.SwapRight: this.engine.swapDirOrMoveFloat("right"); break; - case Shortcut.SetMaster: + case Action.SetMaster: if (window) { this.engine.setMaster(window); } break; - case Shortcut.ToggleFloat: + case Action.ToggleFloat: if (window) { this.engine.toggleFloat(window); } break; - case Shortcut.ToggleFloatAll: + case Action.ToggleFloatAll: this.engine.floatAll(this.currentSurface); break; - case Shortcut.NextLayout: + case Action.NextLayout: this.engine.cycleLayout(1); break; - case Shortcut.PreviousLayout: + case Action.PreviousLayout: this.engine.cycleLayout(-1); break; - case Shortcut.SetLayout: + case Action.SetLayout: if (typeof data === "string") { this.engine.setLayout(data); } diff --git a/src/driver/index.ts b/src/driver/index.ts index f508a2bf..94be0384 100644 --- a/src/driver/index.ts +++ b/src/driver/index.ts @@ -9,7 +9,7 @@ import { KWinSurface } from "./surface"; import { KWinWindow } from "./window"; import { Controller } from "../controller"; -import { Shortcut } from "../controller/shortcut"; +import { Action } from "../controller/action"; import Window from "../engine/window"; @@ -344,42 +344,42 @@ export class KWinDriver implements DriverContext { } private bindMainShortcuts(): void { - const bind = (seq: string, title: string, input: Shortcut): void => { + const bind = (seq: string, title: string, action: Action): void => { title = "Bismuth: " + title; seq = "Meta+" + seq; this.kwinApi.KWin.registerShortcut(title, "", seq, () => { - this.enter(() => this.controller.onShortcut(input)); + this.enter(() => this.controller.onShortcut(action)); }); }; - bind("J", "Down/Next", Shortcut.Down); - bind("K", "Up/Prev", Shortcut.Up); - bind("H", "Left", Shortcut.Left); - bind("L", "Right", Shortcut.Right); + bind("J", "Down/Next", Action.Down); + bind("K", "Up/Prev", Action.Up); + bind("H", "Left", Action.Left); + bind("L", "Right", Action.Right); - bind("Shift+J", "Move Down/Next", Shortcut.ShiftDown); - bind("Shift+K", "Move Up/Prev", Shortcut.ShiftUp); - bind("Shift+H", "Move Left", Shortcut.ShiftLeft); - bind("Shift+L", "Move Right", Shortcut.ShiftRight); + bind("Shift+J", "Move Down/Next", Action.ShiftDown); + bind("Shift+K", "Move Up/Prev", Action.ShiftUp); + bind("Shift+H", "Move Left", Action.ShiftLeft); + bind("Shift+L", "Move Right", Action.ShiftRight); - bind("Ctrl+J", "Grow Height", Shortcut.GrowHeight); - bind("Ctrl+K", "Shrink Height", Shortcut.ShrinkHeight); - bind("Ctrl+H", "Shrink Width", Shortcut.ShrinkWidth); - bind("Ctrl+L", "Grow Width", Shortcut.GrowWidth); + bind("Ctrl+J", "Grow Height", Action.GrowHeight); + bind("Ctrl+K", "Shrink Height", Action.ShrinkHeight); + bind("Ctrl+H", "Shrink Width", Action.ShrinkWidth); + bind("Ctrl+L", "Grow Width", Action.GrowWidth); - bind("I", "Increase", Shortcut.Increase); - bind("D", "Decrease", Shortcut.Decrease); + bind("I", "Increase", Action.Increase); + bind("D", "Decrease", Action.Decrease); - bind("F", "Float", Shortcut.ToggleFloat); - bind("Shift+F", "Float All", Shortcut.ToggleFloatAll); - bind("", "Cycle Layout", Shortcut.NextLayout); // TODO: remove this shortcut - bind("\\", "Next Layout", Shortcut.NextLayout); - bind("|", "Previous Layout", Shortcut.PreviousLayout); + bind("F", "Float", Action.ToggleFloat); + bind("Shift+F", "Float All", Action.ToggleFloatAll); + bind("", "Cycle Layout", Action.NextLayout); // TODO: remove this shortcut + bind("\\", "Next Layout", Action.NextLayout); + bind("|", "Previous Layout", Action.PreviousLayout); - bind("R", "Rotate", Shortcut.Rotate); - bind("Shift+R", "Rotate Part", Shortcut.RotatePart); + bind("R", "Rotate", Action.Rotate); + bind("Shift+R", "Rotate Part", Action.RotatePart); - bind("Return", "Set master", Shortcut.SetMaster); + bind("Return", "Set master", Action.SetMaster); } private bindLayoutShortcuts(): void { @@ -392,7 +392,7 @@ export class KWinDriver implements DriverContext { seq = seq !== "" ? "Meta+" + seq : ""; this.kwinApi.KWin.registerShortcut(title, "", seq, () => { this.enter(() => - this.controller.onShortcut(Shortcut.SetLayout, layoutClass.id) + this.controller.onShortcut(Action.SetLayout, layoutClass.id) ); }); }; diff --git a/src/engine/index.ts b/src/engine/index.ts index 2edb5360..294a8fc3 100644 --- a/src/engine/index.ts +++ b/src/engine/index.ts @@ -11,7 +11,7 @@ import Window from "./window"; import { WindowState } from "./window"; import { Controller } from "../controller"; -import { Shortcut } from "../controller/shortcut"; +import { Action } from "../controller/action"; import { DriverSurface } from "../driver/surface"; @@ -49,7 +49,7 @@ export interface Engine { step: -1 | 1 ): void; enforceSize(window: Window): void; - handleLayoutShortcut(input: Shortcut, data?: any): boolean; + handleLayoutShortcut(input: Action, data?: any): boolean; focusOrder(step: -1 | 1): void; focusDir(dir: Direction): void; swapOrder(window: Window, step: -1 | 1): void; @@ -566,7 +566,7 @@ export class TilingEngine implements Engine { * * @returns True if the layout overrides the shortcut. False, otherwise. */ - public handleLayoutShortcut(input: Shortcut, data?: string): boolean { + public handleLayoutShortcut(input: Action, data?: string): boolean { const layout = this.layouts.getCurrentLayout( this.controller.currentSurface ); diff --git a/src/engine/layout/cascade_layout.ts b/src/engine/layout/cascade_layout.ts index 7760d9f1..e960083d 100644 --- a/src/engine/layout/cascade_layout.ts +++ b/src/engine/layout/cascade_layout.ts @@ -9,7 +9,7 @@ import { Engine } from ".."; import Window from "../window"; import { WindowState } from "../window"; -import { Shortcut } from "../../controller/shortcut"; +import { Action } from "../../controller/action"; import { Controller } from "../../controller"; import Rect from "../../util/rect"; @@ -97,15 +97,15 @@ export default class CascadeLayout implements WindowsLayout { public handleShortcut( engine: Engine, - input: Shortcut, + input: Action, _data?: string ): boolean { switch (input) { - case Shortcut.Increase: + case Action.Increase: this.dir = (this.dir + 1 + 8) % 8; engine.showNotification(this.description); break; - case Shortcut.Decrease: + case Action.Decrease: this.dir = (this.dir - 1 + 8) % 8; engine.showNotification(this.description); break; diff --git a/src/engine/layout/index.ts b/src/engine/layout/index.ts index c118d9f9..cfeb8bdf 100644 --- a/src/engine/layout/index.ts +++ b/src/engine/layout/index.ts @@ -7,7 +7,7 @@ import Window from "../window"; import { Engine } from ".."; import { Controller } from "../../controller"; -import { Shortcut } from "../../controller/shortcut"; +import { Action } from "../../controller/action"; import Rect from "../../util/rect"; import RectDelta from "../../util/rectdelta"; @@ -24,7 +24,7 @@ export interface WindowsLayout { adjust?(area: Rect, tiles: Window[], basis: Window, delta: RectDelta): void; apply(controller: Controller, tileables: Window[], area: Rect): void; - handleShortcut?(engine: Engine, input: Shortcut, data?: any): boolean; + handleShortcut?(engine: Engine, input: Action, data?: any): boolean; toString(): string; } diff --git a/src/engine/layout/monocle_layout.ts b/src/engine/layout/monocle_layout.ts index b596994e..a6d017e7 100644 --- a/src/engine/layout/monocle_layout.ts +++ b/src/engine/layout/monocle_layout.ts @@ -10,7 +10,7 @@ import { WindowState } from "../window"; import { KWinWindow } from "../../driver/window"; -import { Shortcut } from "../../controller/shortcut"; +import { Action } from "../../controller/action"; import Rect from "../../util/rect"; import Config from "../../config"; @@ -62,20 +62,20 @@ export default class MonocleLayout implements WindowsLayout { public handleShortcut( engine: Engine, - input: Shortcut, + input: Action, _data?: string ): boolean { switch (input) { - case Shortcut.Up: - case Shortcut.FocusUp: - case Shortcut.Left: - case Shortcut.FocusLeft: + case Action.Up: + case Action.FocusUp: + case Action.Left: + case Action.FocusLeft: engine.focusOrder(-1); return true; - case Shortcut.Down: - case Shortcut.FocusDown: - case Shortcut.Right: - case Shortcut.FocusRight: + case Action.Down: + case Action.FocusDown: + case Action.Right: + case Action.FocusRight: engine.focusOrder(1); return true; default: diff --git a/src/engine/layout/spread_layout.ts b/src/engine/layout/spread_layout.ts index 17c5b6eb..daba1cf3 100644 --- a/src/engine/layout/spread_layout.ts +++ b/src/engine/layout/spread_layout.ts @@ -8,7 +8,7 @@ import { WindowsLayout } from "."; import Window from "../window"; import { WindowState } from "../window"; -import { Shortcut } from "../../controller/shortcut"; +import { Action } from "../../controller/action"; import Rect from "../../util/rect"; import { Controller } from "../../controller"; @@ -58,13 +58,13 @@ export default class SpreadLayout implements WindowsLayout { return other; } - public handleShortcut(_engine: Engine, input: Shortcut): boolean { + public handleShortcut(_engine: Engine, input: Action): boolean { switch (input) { - case Shortcut.Decrease: + case Action.Decrease: // TODO: define arbitrary constants this.space = Math.max(0.04, this.space - 0.01); break; - case Shortcut.Increase: + case Action.Increase: // TODO: define arbitrary constants this.space = Math.min(0.1, this.space + 0.01); break; diff --git a/src/engine/layout/stair_layout.ts b/src/engine/layout/stair_layout.ts index a320b005..04084c14 100644 --- a/src/engine/layout/stair_layout.ts +++ b/src/engine/layout/stair_layout.ts @@ -8,7 +8,7 @@ import { WindowsLayout } from "."; import Window from "../window"; import { WindowState } from "../window"; -import { Shortcut } from "../../controller/shortcut"; +import { Action } from "../../controller/action"; import Rect from "../../util/rect"; import { Controller } from "../../controller"; @@ -54,13 +54,13 @@ export default class StairLayout implements WindowsLayout { return other; } - public handleShortcut(_engine: Engine, input: Shortcut): boolean { + public handleShortcut(_engine: Engine, input: Action): boolean { switch (input) { - case Shortcut.Decrease: + case Action.Decrease: // TODO: define arbitrary constants this.space = Math.max(16, this.space - 8); break; - case Shortcut.Increase: + case Action.Increase: // TODO: define arbitrary constants this.space = Math.min(160, this.space + 8); break; diff --git a/src/engine/layout/three_column_layout.ts b/src/engine/layout/three_column_layout.ts index cd524297..df43178b 100644 --- a/src/engine/layout/three_column_layout.ts +++ b/src/engine/layout/three_column_layout.ts @@ -9,7 +9,7 @@ import LayoutUtils from "./layout_utils"; import Window from "../window"; import { WindowState } from "../window"; -import { Shortcut } from "../../controller/shortcut"; +import { Action } from "../../controller/action"; import { partitionArrayBySizes, clip, slide } from "../../util/func"; import Rect from "../../util/rect"; @@ -199,24 +199,24 @@ export default class ThreeColumnLayout implements WindowsLayout { public handleShortcut( engine: Engine, - input: Shortcut, + input: Action, _data?: string ): boolean { switch (input) { - case Shortcut.Increase: + case Action.Increase: this.resizeMaster(engine, +1); return true; - case Shortcut.Decrease: + case Action.Decrease: this.resizeMaster(engine, -1); return true; - case Shortcut.Left: + case Action.Left: this.masterRatio = clip( slide(this.masterRatio, -0.05), ThreeColumnLayout.MIN_MASTER_RATIO, ThreeColumnLayout.MAX_MASTER_RATIO ); return true; - case Shortcut.Right: + case Action.Right: this.masterRatio = clip( slide(this.masterRatio, +0.05), ThreeColumnLayout.MIN_MASTER_RATIO, diff --git a/src/engine/layout/tile_layout.ts b/src/engine/layout/tile_layout.ts index c418f99d..843660cd 100644 --- a/src/engine/layout/tile_layout.ts +++ b/src/engine/layout/tile_layout.ts @@ -13,7 +13,7 @@ import { import Window from "../window"; import { WindowState } from "../window"; -import { Shortcut } from "../../controller/shortcut"; +import { Action } from "../../controller/action"; import { clip, slide } from "../../util/func"; import Rect from "../../util/rect"; @@ -96,39 +96,39 @@ export default class TileLayout implements WindowsLayout { return other; } - public handleShortcut(engine: Engine, input: Shortcut): boolean { + public handleShortcut(engine: Engine, input: Action): boolean { switch (input) { - case Shortcut.Left: + case Action.Left: this.masterRatio = clip( slide(this.masterRatio, -0.05), TileLayout.MIN_MASTER_RATIO, TileLayout.MAX_MASTER_RATIO ); break; - case Shortcut.Right: + case Action.Right: this.masterRatio = clip( slide(this.masterRatio, +0.05), TileLayout.MIN_MASTER_RATIO, TileLayout.MAX_MASTER_RATIO ); break; - case Shortcut.Increase: + case Action.Increase: // TODO: define arbitrary constant if (this.numMaster < 10) { this.numMaster += 1; } engine.showNotification(this.description); break; - case Shortcut.Decrease: + case Action.Decrease: if (this.numMaster > 0) { this.numMaster -= 1; } engine.showNotification(this.description); break; - case Shortcut.Rotate: + case Action.Rotate: this.parts.rotate(90); break; - case Shortcut.RotatePart: + case Action.RotatePart: this.parts.inner.primary.rotate(90); break; default: