From 8f4c20138eb285f6f430016bf9abb908102186ed Mon Sep 17 00:00:00 2001 From: Peter Fajdiga Date: Fri, 6 Sep 2024 00:15:36 +0200 Subject: [PATCH] merge NumActions into Actions --- src/lib/actions/Actions.ts | 54 ++++++++++++++++++++++++++++ src/lib/actions/NumActions.ts | 59 ------------------------------- src/lib/keyBindings/definition.ts | 12 +++---- src/lib/keyBindings/loader.ts | 3 +- 4 files changed, 61 insertions(+), 67 deletions(-) delete mode 100644 src/lib/actions/NumActions.ts diff --git a/src/lib/actions/Actions.ts b/src/lib/actions/Actions.ts index d7c761f..ceaf7dc 100644 --- a/src/lib/actions/Actions.ts +++ b/src/lib/actions/Actions.ts @@ -207,6 +207,60 @@ namespace Actions { desktopManager.selectScreen(Workspace.activeScreen); } + public focus(columnIndex: number, clientManager: ClientManager, desktopManager: DesktopManager) { + const grid = desktopManager.getCurrentDesktop().grid; + const targetColumn = grid.getColumnAtIndex(columnIndex); + if (targetColumn === null) { + return; + } + targetColumn.focus(); + }; + + public windowMoveToColumn(columnIndex: number, clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) { + const targetColumn = grid.getColumnAtIndex(columnIndex); + if (targetColumn === null) { + return; + } + window.moveToColumn(targetColumn); + grid.desktop.autoAdjustScroll(); + }; + + public columnMoveToColumn(columnIndex: number, clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: 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.getLeftColumn(targetColumn)); + } + }; + + public columnMoveToDesktop(desktopIndex: number, clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, oldGrid: Grid) { + 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()); + }; + + public tailMoveToDesktop(desktopIndex: number, clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, oldGrid: Grid) { + 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); + }; + private gridScroll(desktopManager: DesktopManager, amount: number) { const grid = desktopManager.getCurrentDesktop().grid; grid.desktop.adjustScroll(amount, false); diff --git a/src/lib/actions/NumActions.ts b/src/lib/actions/NumActions.ts deleted file mode 100644 index 83d86fa..0000000 --- a/src/lib/actions/NumActions.ts +++ /dev/null @@ -1,59 +0,0 @@ -namespace Actions { - export class NumActions { - constructor() {} - - public focus(columnIndex: number, clientManager: ClientManager, desktopManager: DesktopManager) { - const grid = desktopManager.getCurrentDesktop().grid; - const targetColumn = grid.getColumnAtIndex(columnIndex); - if (targetColumn === null) { - return; - } - targetColumn.focus(); - }; - - public windowMoveToColumn(columnIndex: number, clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: Grid) { - const targetColumn = grid.getColumnAtIndex(columnIndex); - if (targetColumn === null) { - return; - } - window.moveToColumn(targetColumn); - grid.desktop.autoAdjustScroll(); - }; - - public columnMoveToColumn(columnIndex: number, clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, grid: 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.getLeftColumn(targetColumn)); - } - }; - - public columnMoveToDesktop(desktopIndex: number, clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, oldGrid: Grid) { - 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()); - }; - - public tailMoveToDesktop(desktopIndex: number, clientManager: ClientManager, desktopManager: DesktopManager, window: Window, column: Column, oldGrid: Grid) { - 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); - }; - } -} diff --git a/src/lib/keyBindings/definition.ts b/src/lib/keyBindings/definition.ts index d1dcd9c..e1a6b26 100644 --- a/src/lib/keyBindings/definition.ts +++ b/src/lib/keyBindings/definition.ts @@ -184,7 +184,7 @@ function getKeyBindings(world: World, actions: Actions.Actions): KeyBinding[] { ]; } -function getNumKeyBindings(world: World, numActions: Actions.NumActions): NumKeyBinding[] { +function getNumKeyBindings(world: World, actions: Actions.Actions): NumKeyBinding[] { return [ { name: "focus-", @@ -192,7 +192,7 @@ function getNumKeyBindings(world: World, numActions: Actions.NumActions): NumKey comment: "Clashes with default KDE shortcuts, may require manual remapping", defaultModifiers: "Meta", fKeys: false, - action: composeNum(world.do, numActions.focus), + action: composeNum(world.do, actions.focus), }, { name: "window-move-to-column-", @@ -200,7 +200,7 @@ function getNumKeyBindings(world: World, numActions: Actions.NumActions): NumKey comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Shift+1 -> Meta+!", defaultModifiers: "Meta+Shift", fKeys: false, - action: composeNum(world.doIfTiledFocused, numActions.windowMoveToColumn), + action: composeNum(world.doIfTiledFocused, actions.windowMoveToColumn), }, { name: "column-move-to-column-", @@ -208,21 +208,21 @@ function getNumKeyBindings(world: World, numActions: Actions.NumActions): NumKey comment: "Requires manual remapping according to your keyboard layout, e.g. Meta+Ctrl+Shift+1 -> Meta+Ctrl+!", defaultModifiers: "Meta+Ctrl+Shift", fKeys: false, - action: composeNum(world.doIfTiledFocused, numActions.columnMoveToColumn), + action: composeNum(world.doIfTiledFocused, actions.columnMoveToColumn), }, { name: "column-move-to-desktop-", description: "Move column to desktop ", defaultModifiers: "Meta+Ctrl+Shift", fKeys: true, - action: composeNum(world.doIfTiledFocused, numActions.columnMoveToDesktop), + action: composeNum(world.doIfTiledFocused, actions.columnMoveToDesktop), }, { name: "tail-move-to-desktop-", description: "Move this and all following columns to desktop ", defaultModifiers: "Meta+Ctrl+Shift+Alt", fKeys: true, - action: composeNum(world.doIfTiledFocused, numActions.tailMoveToDesktop), + action: composeNum(world.doIfTiledFocused, actions.tailMoveToDesktop), }, ]; } diff --git a/src/lib/keyBindings/loader.ts b/src/lib/keyBindings/loader.ts index 36af9a0..0d1af75 100644 --- a/src/lib/keyBindings/loader.ts +++ b/src/lib/keyBindings/loader.ts @@ -54,14 +54,13 @@ function registerNumKeyBindings(shortcutActions: ShortcutAction[], numKeyBinding function registerKeyBindings(world: World, config: Actions.Config) { const actions = new Actions.Actions(config); - const numActions = new Actions.NumActions(); const shortcutActions: ShortcutAction[] = []; for (const keyBinding of getKeyBindings(world, actions)) { registerKeyBinding(shortcutActions, keyBinding); } - for (const numKeyBinding of getNumKeyBindings(world, numActions)) { + for (const numKeyBinding of getNumKeyBindings(world, actions)) { registerNumKeyBindings(shortcutActions, numKeyBinding); }