From faabf34eb6056aeec821519530912025b0ddd65f Mon Sep 17 00:00:00 2001 From: Will Nayes Date: Sat, 6 Jan 2024 22:12:42 -0600 Subject: [PATCH] Minor style change in layout-tiling. --- packages/layout-tiling/index.ts | 136 +++++++++++++++----------------- 1 file changed, 64 insertions(+), 72 deletions(-) diff --git a/packages/layout-tiling/index.ts b/packages/layout-tiling/index.ts index 6e68e6b..384a46a 100644 --- a/packages/layout-tiling/index.ts +++ b/packages/layout-tiling/index.ts @@ -1,92 +1,84 @@ /// -import { - IGeometry, - LayoutFunction, - LayoutPluginConfig, - WindowPosition, - addLayoutResult, - windowIsDialog, -} from "@bond-wm/shared"; +import { IGeometry, LayoutPluginConfig, WindowPosition, addLayoutResult, windowIsDialog } from "@bond-wm/shared"; import TilingIcon from "./tiling.png"; -const TilingLayout: LayoutFunction = ({ windows, screen }) => { - const results = new Map(); +/** A tiling layout for bond-wm. */ +const Plugin: LayoutPluginConfig = { + name: "Tiling", + icon: TilingIcon, + supportsMaximize: false, + fn: ({ windows, screen }) => { + const results = new Map(); - const { workArea } = screen; + const { workArea } = screen; - const windowsWithinGrid = []; + const windowsWithinGrid = []; - for (const win of windows) { - if (win.fullscreen) { - addLayoutResult(results, win, screen, { - x: 0, - y: 0, - width: screen.width, - height: screen.height, - }); - } else if (windowIsDialog(win)) { - // Center the window. - addLayoutResult(results, win, screen, { - x: workArea.x + Math.max(0, Math.floor((workArea.width - win.outer.width) / 2)), - y: workArea.y + Math.max(0, Math.floor((workArea.height - win.outer.height) / 2)), - width: win.outer.width, - height: win.outer.height, - }); - } else if (win.position === WindowPosition.UserPositioned) { - addLayoutResult(results, win, screen, { - x: win.outer.x, - y: win.outer.y, - width: win.outer.width, - height: win.outer.height, - }); - } else { - windowsWithinGrid.push(win); + for (const win of windows) { + if (win.fullscreen) { + addLayoutResult(results, win, screen, { + x: 0, + y: 0, + width: screen.width, + height: screen.height, + }); + } else if (windowIsDialog(win)) { + // Center the window. + addLayoutResult(results, win, screen, { + x: workArea.x + Math.max(0, Math.floor((workArea.width - win.outer.width) / 2)), + y: workArea.y + Math.max(0, Math.floor((workArea.height - win.outer.height) / 2)), + width: win.outer.width, + height: win.outer.height, + }); + } else if (win.position === WindowPosition.UserPositioned) { + addLayoutResult(results, win, screen, { + x: win.outer.x, + y: win.outer.y, + width: win.outer.width, + height: win.outer.height, + }); + } else { + windowsWithinGrid.push(win); + } } - } - const GridWidth = 2; - const GridHeight = Math.ceil(windowsWithinGrid.length / GridWidth); - const GridCellWidth = Math.floor(workArea.width / GridWidth); - const GridCellHeight = Math.floor(workArea.height / GridHeight); - let x = 0; - let y = 0; - for (let i = 0; i < windowsWithinGrid.length; i++) { - const win = windowsWithinGrid[i]; + const GridWidth = 2; + const GridHeight = Math.ceil(windowsWithinGrid.length / GridWidth); + const GridCellWidth = Math.floor(workArea.width / GridWidth); + const GridCellHeight = Math.floor(workArea.height / GridHeight); + let x = 0; + let y = 0; + for (let i = 0; i < windowsWithinGrid.length; i++) { + const win = windowsWithinGrid[i]; + + // When the last window is odd out, give it the full remaining Grid width. + // This assumes GridWidth == 2 but could be generalized if needed. + if (i === windowsWithinGrid.length - 1 && windowsWithinGrid.length % 2 !== 0) { + addLayoutResult(results, win, screen, { + x: workArea.x + x * GridCellWidth, + y: workArea.y + y * GridCellHeight, + width: workArea.width, + height: GridCellHeight, + }); + continue; + } - // When the last window is odd out, give it the full remaining Grid width. - // This assumes GridWidth == 2 but could be generalized if needed. - if (i === windowsWithinGrid.length - 1 && windowsWithinGrid.length % 2 !== 0) { addLayoutResult(results, win, screen, { x: workArea.x + x * GridCellWidth, y: workArea.y + y * GridCellHeight, - width: workArea.width, + width: GridCellWidth, height: GridCellHeight, }); - continue; - } - addLayoutResult(results, win, screen, { - x: workArea.x + x * GridCellWidth, - y: workArea.y + y * GridCellHeight, - width: GridCellWidth, - height: GridCellHeight, - }); - - x++; - if (x >= GridWidth) { - x = 0; - y++; + x++; + if (x >= GridWidth) { + x = 0; + y++; + } } - } - return results; + return results; + }, }; -/** A tiling layout for bond-wm. */ -const Plugin: LayoutPluginConfig = { - name: "Tiling", - icon: TilingIcon, - supportsMaximize: false, - fn: TilingLayout, -}; export default Plugin;