diff --git a/src/lib/actions/Actions.ts b/src/lib/actions/Actions.ts index ab677d1..ab6ac3e 100644 --- a/src/lib/actions/Actions.ts +++ b/src/lib/actions/Actions.ts @@ -268,76 +268,6 @@ namespace Actions { } } - public getNumAction(name: string) { - switch (name) { - case "focus-": return (columnIndex: number) => { - this.world.do((clientManager, desktopManager) => { - const grid = desktopManager.getCurrentDesktop().grid; - const targetColumn = grid.getColumnAtIndex(columnIndex); - if (targetColumn === null) { - return; - } - targetColumn.focus(); - }); - }; - - case "window-move-to-column-": return (columnIndex: number) => { - this.world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { - const targetColumn = grid.getColumnAtIndex(columnIndex); - if (targetColumn === null) { - return; - } - window.moveToColumn(targetColumn); - grid.desktop.autoAdjustScroll(); - }); - }; - - case "column-move-to-column-": return (columnIndex: number) => { - this.world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { - const targetColumn = grid.getColumnAtIndex(columnIndex); - if (targetColumn === null || targetColumn === column) { - return; - } - if (targetColumn.isToTheRightOf(column)) { - grid.moveColumn(column, targetColumn); - } else { - grid.moveColumn(column, grid.getPrevColumn(targetColumn)); - } - }); - }; - - case "column-move-to-desktop-": return (desktopIndex: number) => { - this.world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => { - const kwinDesktop = Workspace.desktops[desktopIndex]; - if (kwinDesktop === undefined) { - return; - } - const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid; - if (newGrid === null || newGrid === oldGrid) { - return; - } - column.moveToGrid(newGrid, newGrid.getLastColumn()); - }); - }; - - case "tail-move-to-desktop-": return (desktopIndex: number) => { - this.world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => { - const kwinDesktop = Workspace.desktops[desktopIndex]; - if (kwinDesktop === undefined) { - return; - } - const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid; - if (newGrid === null || newGrid === oldGrid) { - return; - } - oldGrid.evacuateTail(newGrid, column); - }); - }; - - default: throw new Error("unknown num action: " + name); - } - } - private gridScroll(amount: number) { this.world.do((clientManager, desktopManager) => { const grid = desktopManager.getCurrentDesktop().grid; diff --git a/src/lib/actions/Getter.ts b/src/lib/actions/Getter.ts index 5c0da48..7a6f30b 100644 --- a/src/lib/actions/Getter.ts +++ b/src/lib/actions/Getter.ts @@ -1,9 +1,11 @@ namespace Actions { export class Getter { private readonly actions: Actions; + private readonly numActions: NumActions; constructor(world: World, config: Config) { this.actions = new Actions(world, config); + this.numActions = new NumActions(world); } public getAction(action: string) { @@ -11,7 +13,7 @@ namespace Actions { } public getNumAction(action: string) { - return this.actions.getNumAction(action); + return this.numActions.getNumAction(action); } } diff --git a/src/lib/actions/NumActions.ts b/src/lib/actions/NumActions.ts new file mode 100644 index 0000000..f443778 --- /dev/null +++ b/src/lib/actions/NumActions.ts @@ -0,0 +1,75 @@ +namespace Actions { + export class NumActions { + constructor(private readonly world: World) {} + + public getNumAction(name: string) { + switch (name) { + case "focus-": return (columnIndex: number) => { + this.world.do((clientManager, desktopManager) => { + const grid = desktopManager.getCurrentDesktop().grid; + const targetColumn = grid.getColumnAtIndex(columnIndex); + if (targetColumn === null) { + return; + } + targetColumn.focus(); + }); + }; + + case "window-move-to-column-": return (columnIndex: number) => { + this.world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { + const targetColumn = grid.getColumnAtIndex(columnIndex); + if (targetColumn === null) { + return; + } + window.moveToColumn(targetColumn); + grid.desktop.autoAdjustScroll(); + }); + }; + + case "column-move-to-column-": return (columnIndex: number) => { + this.world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, grid) => { + const targetColumn = grid.getColumnAtIndex(columnIndex); + if (targetColumn === null || targetColumn === column) { + return; + } + if (targetColumn.isToTheRightOf(column)) { + grid.moveColumn(column, targetColumn); + } else { + grid.moveColumn(column, grid.getPrevColumn(targetColumn)); + } + }); + }; + + case "column-move-to-desktop-": return (desktopIndex: number) => { + this.world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => { + const kwinDesktop = Workspace.desktops[desktopIndex]; + if (kwinDesktop === undefined) { + return; + } + const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid; + if (newGrid === null || newGrid === oldGrid) { + return; + } + column.moveToGrid(newGrid, newGrid.getLastColumn()); + }); + }; + + case "tail-move-to-desktop-": return (desktopIndex: number) => { + this.world.doIfTiledFocused(true, (clientManager, desktopManager, window, column, oldGrid) => { + const kwinDesktop = Workspace.desktops[desktopIndex]; + if (kwinDesktop === undefined) { + return; + } + const newGrid = desktopManager.getDesktopInCurrentActivity(kwinDesktop).grid; + if (newGrid === null || newGrid === oldGrid) { + return; + } + oldGrid.evacuateTail(newGrid, column); + }); + }; + + default: throw new Error("unknown num action: " + name); + } + } + } +}