diff --git a/README.md b/README.md index c7a87e3f..81f544b5 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,8 @@ is a strip of columns that runs past the edges of the monitor and scrolls to the window that has the focus. `minimize` and `close` ask KWin to minimize or close the focused window, `unmanage` takes it out of the layout until `manage` takes it back, and `toggle-pause` stops the daemon acting on events and orders -until it is resumed. +until it is resumed. The padding commands set the gaps around the tiles, and +the work area offsets keep parts of a monitor free of tiles. A program such as a status bar can subscribe to the daemon's notifications: it listens on a socket of its own, and after each event and each message, the diff --git a/docs/cli/adjust-container-padding.md b/docs/cli/adjust-container-padding.md new file mode 100644 index 00000000..496cff5a --- /dev/null +++ b/docs/cli/adjust-container-padding.md @@ -0,0 +1,19 @@ +```text +Adjust container padding on the focused workspace + +Usage: adjust-container-padding + +Arguments: + + Possible values: + - increase: Increase + - decrease: Decrease + + + Pixels to adjust by as an integer + +Options: + -h, --help + Print help (see a summary with '-h') + +``` diff --git a/docs/cli/adjust-workspace-padding.md b/docs/cli/adjust-workspace-padding.md new file mode 100644 index 00000000..32add7c5 --- /dev/null +++ b/docs/cli/adjust-workspace-padding.md @@ -0,0 +1,19 @@ +```text +Adjust workspace padding on the focused workspace + +Usage: adjust-workspace-padding + +Arguments: + + Possible values: + - increase: Increase + - decrease: Decrease + + + Pixels to adjust by as an integer + +Options: + -h, --help + Print help (see a summary with '-h') + +``` diff --git a/docs/cli/container-padding.md b/docs/cli/container-padding.md new file mode 100644 index 00000000..4dd1bfe5 --- /dev/null +++ b/docs/cli/container-padding.md @@ -0,0 +1,20 @@ +```text +Set the container padding for the specified workspace + +Usage: container-padding + +Arguments: + + Monitor index (zero-indexed) + + + Workspace index on the specified monitor (zero-indexed) + + + Pixels to pad with as an integer + +Options: + -h, --help + Print help + +``` diff --git a/docs/cli/focused-workspace-container-padding.md b/docs/cli/focused-workspace-container-padding.md new file mode 100644 index 00000000..45302a9a --- /dev/null +++ b/docs/cli/focused-workspace-container-padding.md @@ -0,0 +1,14 @@ +```text +Set container padding on the focused workspace + +Usage: focused-workspace-container-padding + +Arguments: + + Pixels size to set as an integer + +Options: + -h, --help + Print help + +``` diff --git a/docs/cli/focused-workspace-padding.md b/docs/cli/focused-workspace-padding.md new file mode 100644 index 00000000..de2ebe2d --- /dev/null +++ b/docs/cli/focused-workspace-padding.md @@ -0,0 +1,14 @@ +```text +Set workspace padding on the focused workspace + +Usage: focused-workspace-padding + +Arguments: + + Pixels size to set as an integer + +Options: + -h, --help + Print help + +``` diff --git a/docs/cli/global-work-area-offset.md b/docs/cli/global-work-area-offset.md new file mode 100644 index 00000000..8dbb1cd6 --- /dev/null +++ b/docs/cli/global-work-area-offset.md @@ -0,0 +1,23 @@ +```text +Set offsets to exclude parts of the work area from tiling + +Usage: global-work-area-offset + +Arguments: + + Size of the left work area offset (set right to left * 2 to maintain right padding) + + + Size of the top work area offset (set bottom to the same value to maintain bottom padding) + + + Size of the right work area offset + + + Size of the bottom work area offset + +Options: + -h, --help + Print help + +``` diff --git a/docs/cli/monitor-work-area-offset.md b/docs/cli/monitor-work-area-offset.md new file mode 100644 index 00000000..d01e1b7f --- /dev/null +++ b/docs/cli/monitor-work-area-offset.md @@ -0,0 +1,26 @@ +```text +Set offsets for a monitor to exclude parts of the work area from tiling + +Usage: monitor-work-area-offset + +Arguments: + + Monitor index (zero-indexed) + + + Size of the left work area offset (set right to left * 2 to maintain right padding) + + + Size of the top work area offset (set bottom to the same value to maintain bottom padding) + + + Size of the right work area offset + + + Size of the bottom work area offset + +Options: + -h, --help + Print help + +``` diff --git a/docs/cli/toggle-window-based-work-area-offset.md b/docs/cli/toggle-window-based-work-area-offset.md new file mode 100644 index 00000000..a4814769 --- /dev/null +++ b/docs/cli/toggle-window-based-work-area-offset.md @@ -0,0 +1,10 @@ +```text +Toggle application of the window-based work area offset for the focused workspace + +Usage: toggle-window-based-work-area-offset + +Options: + -h, --help + Print help + +``` diff --git a/docs/cli/workspace-padding.md b/docs/cli/workspace-padding.md new file mode 100644 index 00000000..91728311 --- /dev/null +++ b/docs/cli/workspace-padding.md @@ -0,0 +1,20 @@ +```text +Set the workspace padding for the specified workspace + +Usage: workspace-padding + +Arguments: + + Monitor index (zero-indexed) + + + Workspace index on the specified monitor (zero-indexed) + + + Pixels to pad with as an integer + +Options: + -h, --help + Print help + +``` diff --git a/docs/cli/workspace-work-area-offset.md b/docs/cli/workspace-work-area-offset.md new file mode 100644 index 00000000..34858b1b --- /dev/null +++ b/docs/cli/workspace-work-area-offset.md @@ -0,0 +1,29 @@ +```text +Set offsets for a workspace to exclude parts of the work area from tiling + +Usage: workspace-work-area-offset + +Arguments: + + Monitor index (zero-indexed) + + + Workspace index (zero-indexed) + + + Size of the left work area offset (set right to left * 2 to maintain right padding) + + + Size of the top work area offset (set bottom to the same value to maintain bottom padding) + + + Size of the right work area offset + + + Size of the bottom work area offset + +Options: + -h, --help + Print help + +``` diff --git a/docs/dev/ARCHITECTURE.md b/docs/dev/ARCHITECTURE.md index ef6a4405..276a3d20 100644 --- a/docs/dev/ARCHITECTURE.md +++ b/docs/dev/ARCHITECTURE.md @@ -85,8 +85,10 @@ element focused, so that "the focused workspace" or "the focused container" mean the same thing at every level. - A **monitor** ([`Monitor`]) is one of the backend's monitors: its bounds, its work area, - its padding, an optional work area offset, and its workspaces. It shows the focused one. -- A **workspace** ([`Workspace`]) has a layout, its padding, its containers, in order, and its + its padding, an optional work area offset, an optional window-based offset with the number of + windows up to which it applies, and its workspaces. It shows the focused one. +- A **workspace** ([`Workspace`]) has a layout, its padding, an optional work area offset of its + own, whether it takes the monitor's window-based offset, its containers, in order, and its floating windows, which are in no container and which the layout does not tile. - A **container** ([`Container`]) has its windows. A new window gets a container of its own. A container can be locked, which keeps it at its index while others are inserted, @@ -95,9 +97,11 @@ the same thing at every level. Everything else about the window, and every change to it, goes through the backend. Tiling a workspace ([`Workspace::update`]) is a function of this tree and a work area. The -monitor gives its focused workspace the work area, the padding to fall back to and the -offset ([`WorkspaceGlobals`]). The workspace takes the offset and its padding off the work -area, the layout gives one tile per container, in order, each shrunk by the container +monitor gives its focused workspace the work area, the padding to fall back to, the offset +(its own, or else the window manager's) and its window-based offset ([`WorkspaceGlobals`]). +The workspace takes the offset (its own, or else the monitor's) off the work area, then the +window-based offset while it has no more containers than the monitor's limit, then its +padding; the layout gives one tile per container, in order, each shrunk by the container padding, and every window of a container is asked to move onto its tile with `set_rect`. A tile is clamped to the work area, so it cannot reach onto a neighboring monitor. @@ -328,6 +332,15 @@ window manager. `UnmanagedWindowOperationBehaviour` sets focused is in no container of the focused workspace ([`WindowManager::handle_unmanaged_window_behaviour`]). +`WorkspacePadding`, `ContainerPadding` and their `FocusedWorkspace` forms set a workspace's own +padding, and `AdjustWorkspacePadding` and `AdjustContainerPadding` change the focused +workspace's by a number of pixels, which needs a padding of its own to change +([`WindowManager::adjust_workspace_padding`]). `WorkAreaOffset`, `MonitorWorkAreaOffset` and +`WorkspaceWorkAreaOffset` set the offset of the window manager, of a monitor or of a workspace, +and `ToggleWindowBasedWorkAreaOffset` sets whether the focused workspace takes its monitor's +window-based offset ([`Workspace::apply_window_based_work_area_offset`]). Each tiles the +workspace in front again, or every monitor. + `ResizeWindowEdge` and `ResizeWindowAxis` resize the focused container ([`WindowManager::resize_window`]). A resize is an adjustment of the container's tile, kept in [`Workspace::resize_dimensions`], one per container, which the layout applies when it calculates @@ -396,8 +409,8 @@ module's unit. - [`window_manager`](../../komorebi/src/window_manager.rs): the [`WindowManager`] and the operations on it (tile the workspace in front, tile every monitor, take a minimized window out, move the focus, move the focused container, change the layout, resize or - promote the focused container, float a window, lock a container, manage and unmanage a - window). + promote the focused container, float a window, lock a container, set the padding of a + workspace, manage and unmanage a window). - [`desktop`](../../komorebi/src/desktop.rs): loads the monitors and the open windows from the backend. - [`window_manager_event`](../../komorebi/src/window_manager_event.rs) and @@ -484,6 +497,7 @@ the fake. The window manager is its only caller, through [`backend`]. The contra | A container moved onto a locked index is locked in its place, and the lock leaves the container that moved away | framework path: [`Workspace::swap_containers`] swaps through `LockableSequence`, which keeps the lock with the index | `test_swap_respecting_locks_various_cases`, `a_lock_stays_with_its_index_when_a_window_is_moved_onto_it` | `containers_mut()` is the `VecDeque` itself | | A window komorebi puts off the screen stays there | framework path: the bridge asks again for the position of a window KWin pulled back after a `geo` command, for a second, three times at most | `a window KWin pulls back from where it was asked to be is asked for the position again`, `a window that cannot go where it was asked is asked again three times at most`, `vm-scrolling` | a window that cannot go where it was asked is left where KWin put it | | A resize leaves no tile smaller than a tenth of the work area, or than it was | framework path: [`WindowManager::resize_window`] calculates the tiles for the adjustment, and cuts the adjustment down until they all fit | `a_resize_leaves_every_tile_about_a_tenth_of_the_work_area_wide_at_least` | the paddings are taken off afterwards, so a tile can end up a little smaller | +| The offset of a workspace wins over its monitor's, which wins over the window manager's | framework path: [`Monitor::update_workspace_globals`] gives the workspace the monitor's offset or else the window manager's, and [`Workspace::update`] takes its own before that | `the_workspaces_offset_wins_over_the_monitors_which_wins_over_the_global_one` | none | | A workspace whose tiling is off moves no window | framework path: [`Workspace::update`] returns before the layout when [`Workspace::tile`] is false | `with_tiling_off_no_window_is_moved_until_it_is_back_on` | none | | Moving the focus moves no window | test | `focus_gives_the_focus_to_the_window_on_that_side_and_moves_nothing`, `vm-core-e2e` ("moving the focus moved no window") | none | | A subscriber that is gone is dropped, not retried | test | `a_subscriber_that_is_gone_is_dropped_and_not_tried_again` | none | @@ -604,7 +618,9 @@ A window is shown, and ends up on a tile: [`komorebi/tests/float.rs`](../../komorebi/tests/float.rs), floating; [`komorebi/tests/lock.rs`](../../komorebi/tests/lock.rs), locking; [`komorebi/tests/manage.rs`](../../komorebi/tests/manage.rs), minimizing, closing, - unmanaging and managing the focused window, and pausing. + unmanaging and managing the focused window, and pausing; + [`komorebi/tests/padding.rs`](../../komorebi/tests/padding.rs), the paddings and the work area + offsets. - [`nix/tests/vm/suites/scrolling`](../../nix/tests/vm/suites/scrolling/test.py): the scrolling strip in a real KWin, with its columns out of view off the screen. - [`nix/tests/vm/suites/commands`](../../nix/tests/vm/suites/commands/test.py): every layout, @@ -646,6 +662,9 @@ A window is shown, and ends up on a tile: [`WindowManager::resize_window`]: ../../komorebi/src/window_manager.rs [`WindowManager::toggle_float`]: ../../komorebi/src/window_manager.rs [`WindowManager::toggle_lock`]: ../../komorebi/src/window_manager.rs +[`WindowManager::adjust_workspace_padding`]: ../../komorebi/src/window_manager.rs +[`Workspace::apply_window_based_work_area_offset`]: ../../komorebi/src/workspace.rs +[`Monitor::update_workspace_globals`]: ../../komorebi/src/monitor.rs [`WindowManager::manage_focused_window`]: ../../komorebi/src/window_manager.rs [`WindowManager::unmanage_focused_window`]: ../../komorebi/src/window_manager.rs [`WindowManager::is_paused`]: ../../komorebi/src/window_manager.rs diff --git a/docs/index.md b/docs/index.md index e198924c..d4498d01 100644 --- a/docs/index.md +++ b/docs/index.md @@ -36,9 +36,11 @@ daemon, ask it what it is doing and read its log. [Moving windows](usage/moving-windows.md) how to move the focused window to another tile, [Layouts](usage/layouts.md) how to change the arrangement of the tiles, [Resizing windows](usage/resizing-windows.md) how to change the size of one, -[Floating windows](usage/floating-windows.md) how to take a window out of the layout, and +[Floating windows](usage/floating-windows.md) how to take a window out of the layout, [Managing windows](usage/managing-windows.md) how to minimize, close and unmanage the focused -window and pause the daemon. +window and pause the daemon, and +[Padding and work area offsets](usage/padding-and-offsets.md) how to put gaps around the tiles +and keep parts of a monitor free of them. [Subscribing to notifications](usage/subscribing-to-notifications.md) explains how a program such as a status bar follows what komorebi does. The [CLI reference](cli/start.md) has a page for every `komorebic` command, generated from its help. diff --git a/docs/usage/padding-and-offsets.md b/docs/usage/padding-and-offsets.md new file mode 100644 index 00000000..a058c9a6 --- /dev/null +++ b/docs/usage/padding-and-offsets.md @@ -0,0 +1,76 @@ +# Padding and work area offsets + +komorebi tiles the windows of a workspace in the work area of its monitor, which is the part of +the monitor that KWin reports free of Plasma's panels. Padding puts gaps around the tiles, and an +offset keeps a part of the work area free of tiles. + +## Padding + +A workspace has two paddings, in pixels: + +- the **workspace padding**, between the edges of the work area and the tiles; +- the **container padding**, around each tile, so that two tiles side by side are twice that far + apart. + +A workspace that has no padding of its own takes 5 pixels for each. + +[`komorebic focused-workspace-padding`](../cli/focused-workspace-padding.md) and +[`komorebic focused-workspace-container-padding`](../cli/focused-workspace-container-padding.md) +set the paddings of the focused workspace, and +[`komorebic workspace-padding`](../cli/workspace-padding.md) and +[`komorebic container-padding`](../cli/container-padding.md) those of a workspace given by the +index of its monitor and its own, counted from 0. + +```sh +komorebic focused-workspace-padding 20 +komorebic focused-workspace-container-padding 10 +komorebic workspace-padding 0 1 0 +komorebic container-padding 0 1 0 +``` + +[`komorebic adjust-workspace-padding`](../cli/adjust-workspace-padding.md) and +[`komorebic adjust-container-padding`](../cli/adjust-container-padding.md) make a padding of the +focused workspace larger or smaller by a number of pixels. They change a padding the workspace +has of its own, set by one of the commands above: on a workspace that has none, the daemon logs +"there is no workspace padding" or "there is no container padding". A padding is not made +smaller than 0. + +```sh +komorebic adjust-workspace-padding increase 5 +komorebic adjust-container-padding decrease 5 +``` + +## Work area offsets + +An offset is four numbers. The first two move the top left corner of the work area right and +down; the last two make the work area narrower and shorter. So `0 40 0 40` keeps a strip of 40 +pixels at the top free, `0 0 0 40` a strip at the bottom, and `40 0 40 0` a strip on the left. + +[`komorebic global-work-area-offset`](../cli/global-work-area-offset.md) sets the offset of every +monitor, [`komorebic monitor-work-area-offset`](../cli/monitor-work-area-offset.md) the offset of +one monitor, which it takes instead of the global one, and +[`komorebic workspace-work-area-offset`](../cli/workspace-work-area-offset.md) the offset of one +workspace, which it takes instead of both. Each tiles every monitor again, as +[`komorebic retile`](../cli/retile.md) does. + +```sh +komorebic global-work-area-offset 0 40 0 40 +komorebic monitor-work-area-offset 1 0 0 0 40 +komorebic workspace-work-area-offset 0 2 40 0 40 0 +``` + +A monitor can also have a window-based offset, which applies on top of the other one while the +workspace in front has no more windows than the monitor's limit, 1 unless it is given another. +With a window-based offset, a window that is alone on a wide monitor does not have to take its +whole width. No command sets a monitor's window-based offset: it is part of the configuration of +a monitor. +[`komorebic toggle-window-based-work-area-offset`](../cli/toggle-window-based-work-area-offset.md) +turns it off for the focused workspace, and on again. + +```sh +komorebic toggle-window-based-work-area-offset +``` + +The daemon's state has the offsets as `work_area_offset` (of the window manager, of each monitor +and of each workspace), and a monitor's window-based offset and limit as +`window_based_work_area_offset` and `window_based_work_area_offset_limit`. diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index ca685759..d6701e68 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -363,6 +363,8 @@ pub enum SocketMessage { // Current Workspace Commands ManageFocusedWindow, UnmanageFocusedWindow, + AdjustContainerPadding(Sizing, i32), + AdjustWorkspacePadding(Sizing, i32), ChangeLayout(DefaultLayout), CycleLayout(CycleDirection), ScrollingLayoutColumns(NonZeroUsize), @@ -380,6 +382,14 @@ pub enum SocketMessage { QuickLoad, Save(#[serde_as(as = "ResolvedPathBuf")] PathBuf), Load(#[serde_as(as = "ResolvedPathBuf")] PathBuf), + ContainerPadding(usize, usize, i32), + FocusedWorkspaceContainerPadding(i32), + WorkspacePadding(usize, usize, i32), + FocusedWorkspacePadding(i32), + WorkAreaOffset(Rect), + MonitorWorkAreaOffset(usize, Rect), + WorkspaceWorkAreaOffset(usize, usize, Rect), + ToggleWindowBasedWorkAreaOffset, ResizeDelta(i32), State, MonitorInformation, diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index c7c52cf7..7be95cea 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -54,6 +54,8 @@ pub struct Monitor { pub size: Rect, pub work_area_offset: Option, pub work_area_size: Rect, + pub window_based_work_area_offset: Option, + pub window_based_work_area_offset_limit: isize, pub container_padding: Option, pub workspace_padding: Option, } @@ -77,6 +79,8 @@ pub fn new( size, work_area_size, work_area_offset: None, + window_based_work_area_offset: None, + window_based_work_area_offset_limit: 1, workspaces, container_padding: None, workspace_padding: None, @@ -103,6 +107,8 @@ impl Monitor { size, work_area_offset: None, work_area_size, + window_based_work_area_offset: None, + window_based_work_area_offset_limit: 1, container_padding: None, workspace_padding: None, } @@ -137,6 +143,8 @@ impl Monitor { .or(Some(DEFAULT_WORKSPACE_PADDING.load(Ordering::Relaxed))); let work_area = self.work_area_size; let work_area_offset = self.work_area_offset.or(offset); + let window_based_work_area_offset = self.window_based_work_area_offset; + let window_based_work_area_offset_limit = self.window_based_work_area_offset_limit; if let Some(workspace) = self.workspaces_mut().get_mut(workspace_idx) { workspace.globals = WorkspaceGlobals { @@ -144,6 +152,8 @@ impl Monitor { workspace_padding, work_area, work_area_offset, + window_based_work_area_offset, + window_based_work_area_offset_limit, } } } diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 1964cf0c..1984fd7b 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -44,6 +44,18 @@ //! - **ToggleFloat** takes the focused window out of the layout into the floating windows of the //! workspace, which komorebi does not move, or puts a floating window back //! ([`WindowManager::toggle_float`]). +//! - **WorkspacePadding** and **ContainerPadding** set the paddings of a workspace given by the +//! index of its monitor and its own, **FocusedWorkspacePadding** and +//! **FocusedWorkspaceContainerPadding** those of the focused workspace, and +//! **AdjustWorkspacePadding** and **AdjustContainerPadding** make the focused workspace's larger +//! or smaller ([`WindowManager::set_workspace_padding`], +//! [`WindowManager::set_container_padding`], [`WindowManager::adjust_workspace_padding`], +//! [`WindowManager::adjust_container_padding`]). +//! - **WorkAreaOffset**, **MonitorWorkAreaOffset** and **WorkspaceWorkAreaOffset** set the work +//! area offset of every monitor, of one monitor or of one workspace, and tile every monitor again +//! (a monitor or a workspace that is not there is ignored), and +//! **ToggleWindowBasedWorkAreaOffset** sets whether the focused workspace takes its monitor's +//! window-based offset. //! - **Minimize** and **Close** ask the compositor to minimize or close the window that has the //! focus. The window leaves the layout when the compositor reports that it did. //! - **UnmanageFocusedWindow** takes the window that has the focus out of the layout and leaves it @@ -170,6 +182,9 @@ impl WindowManager { /// `UnlockMonitorWorkspaceContainer` is not there (a container that is not there is ignored). /// - The focused window cannot be floated or put back, for one of the reasons /// [`WindowManager::toggle_float`] gives. + /// - The monitor or the workspace of `WorkspacePadding` or `ContainerPadding` is not there, or + /// the focused workspace has no padding of its own for `AdjustWorkspacePadding` or + /// `AdjustContainerPadding` to change. /// - `Minimize`, `Close`, `ManageFocusedWindow` or `UnmanageFocusedWindow` when the compositor /// reports no focused window, or the backend refuses to minimize or close it. /// - The file of `QuickSave` or `Save` cannot be written, or the file of `QuickLoad` or @@ -370,6 +385,13 @@ impl WindowManager { SocketMessage::Retile => self.retile_all(false)?, SocketMessage::RetileWithResizeDimensions => self.retile_all(true)?, SocketMessage::ToggleLock => self.toggle_lock()?, + SocketMessage::ToggleWindowBasedWorkAreaOffset => { + let workspace = self.focused_workspace_mut()?; + workspace.apply_window_based_work_area_offset = + !workspace.apply_window_based_work_area_offset; + + self.retile_all(true)?; + } SocketMessage::ToggleTiling => { self.toggle_tiling()?; } @@ -439,9 +461,57 @@ impl WindowManager { reply.write_all(response.as_bytes())?; } + SocketMessage::ContainerPadding(monitor_idx, workspace_idx, size) => { + self.set_container_padding(monitor_idx, workspace_idx, size)?; + } + SocketMessage::WorkspacePadding(monitor_idx, workspace_idx, size) => { + self.set_workspace_padding(monitor_idx, workspace_idx, size)?; + } + SocketMessage::FocusedWorkspaceContainerPadding(adjustment) => { + let focused_monitor_idx = self.focused_monitor_idx(); + + let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?; + + let focused_workspace_idx = focused_monitor.focused_workspace_idx(); + + self.set_container_padding(focused_monitor_idx, focused_workspace_idx, adjustment)?; + } + SocketMessage::FocusedWorkspacePadding(adjustment) => { + let focused_monitor_idx = self.focused_monitor_idx(); + + let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?; + + let focused_workspace_idx = focused_monitor.focused_workspace_idx(); + + self.set_workspace_padding(focused_monitor_idx, focused_workspace_idx, adjustment)?; + } + SocketMessage::WorkAreaOffset(rect) => { + self.work_area_offset = Option::from(rect); + self.retile_all(false)?; + } + SocketMessage::MonitorWorkAreaOffset(monitor_idx, rect) => { + if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx) { + monitor.work_area_offset = Option::from(rect); + self.retile_all(false)?; + } + } + SocketMessage::WorkspaceWorkAreaOffset(monitor_idx, workspace_idx, rect) => { + if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx) + && let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx) + { + workspace.work_area_offset = Option::from(rect); + self.retile_all(false)? + } + } SocketMessage::ResizeDelta(delta) => { self.resize_delta = delta; } + SocketMessage::AdjustContainerPadding(sizing, adjustment) => { + self.adjust_container_padding(sizing, adjustment)?; + } + SocketMessage::AdjustWorkspacePadding(sizing, adjustment) => { + self.adjust_workspace_padding(sizing, adjustment)?; + } SocketMessage::ScrollingLayoutColumns(count) => { let focused_workspace = self.focused_workspace_mut()?; diff --git a/komorebi/src/state.rs b/komorebi/src/state.rs index a75fcbbf..2df52fed 100644 --- a/komorebi/src/state.rs +++ b/komorebi/src/state.rs @@ -76,6 +76,8 @@ impl From<&WindowManager> for State { size: monitor.size, work_area_size: monitor.work_area_size, work_area_offset: monitor.work_area_offset, + window_based_work_area_offset: monitor.window_based_work_area_offset, + window_based_work_area_offset_limit: monitor.window_based_work_area_offset_limit, workspaces: { let mut ws = Ring::default(); *ws.elements_mut() = monitor @@ -92,6 +94,9 @@ impl From<&WindowManager> for State { latest_layout: workspace.latest_layout.clone(), resize_dimensions: workspace.resize_dimensions.clone(), tile: workspace.tile, + work_area_offset: workspace.work_area_offset, + apply_window_based_work_area_offset: workspace + .apply_window_based_work_area_offset, globals: workspace.globals, preselected_container_idx: None, promotion_swap_container_idx: None, diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index e317fc3b..7275aee6 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1013,6 +1013,120 @@ impl WindowManager { } } + /// Gives the workspace at `workspace_idx` on the monitor at `monitor_idx` a workspace padding + /// of `size` pixels, around its tiles, and tiles the focused workspace again + /// + /// # Errors + /// + /// There is no monitor or no workspace at the index, or the focused workspace cannot be tiled + /// again. + #[tracing::instrument(skip(self))] + pub fn set_workspace_padding( + &mut self, + monitor_idx: usize, + workspace_idx: usize, + size: i32, + ) -> eyre::Result<()> { + tracing::info!("setting workspace padding"); + + let monitor = self + .monitors_mut() + .get_mut(monitor_idx) + .ok_or_eyre("there is no monitor")?; + + let workspace = monitor + .workspaces_mut() + .get_mut(workspace_idx) + .ok_or_eyre("there is no monitor")?; + + workspace.workspace_padding = Option::from(size); + + self.update_focused_workspace(false, false) + } + + /// Gives the workspace at `workspace_idx` on the monitor at `monitor_idx` a container padding + /// of `size` pixels, around each tile, and tiles the focused workspace again + /// + /// # Errors + /// + /// There is no monitor or no workspace at the index, or the focused workspace cannot be tiled + /// again. + #[tracing::instrument(skip(self))] + pub fn set_container_padding( + &mut self, + monitor_idx: usize, + workspace_idx: usize, + size: i32, + ) -> eyre::Result<()> { + tracing::info!("setting container padding"); + + let monitor = self + .monitors_mut() + .get_mut(monitor_idx) + .ok_or_eyre("there is no monitor")?; + + let workspace = monitor + .workspaces_mut() + .get_mut(workspace_idx) + .ok_or_eyre("there is no monitor")?; + + workspace.container_padding = Option::from(size); + + self.update_focused_workspace(false, false) + } + + /// Makes the workspace padding of the focused workspace `adjustment` pixels larger or smaller, + /// and tiles it again + /// + /// # Errors + /// + /// There is no focused workspace, it has no workspace padding of its own (set with + /// [`WindowManager::set_workspace_padding`]), or it cannot be tiled again. + #[tracing::instrument(skip(self))] + pub fn adjust_workspace_padding( + &mut self, + sizing: Sizing, + adjustment: i32, + ) -> eyre::Result<()> { + tracing::info!("adjusting workspace padding"); + + let workspace = self.focused_workspace_mut()?; + + let padding = workspace + .workspace_padding + .ok_or_eyre("there is no workspace padding")?; + + workspace.workspace_padding = Option::from(sizing.adjust_by(padding, adjustment)); + + self.update_focused_workspace(false, false) + } + + /// Makes the container padding of the focused workspace `adjustment` pixels larger or smaller, + /// and tiles it again + /// + /// # Errors + /// + /// There is no focused workspace, it has no container padding of its own (set with + /// [`WindowManager::set_container_padding`]), or it cannot be tiled again. + #[tracing::instrument(skip(self))] + pub fn adjust_container_padding( + &mut self, + sizing: Sizing, + adjustment: i32, + ) -> eyre::Result<()> { + tracing::info!("adjusting container padding"); + + let workspace = self.focused_workspace_mut()?; + + let padding = workspace + .container_padding + .ok_or_eyre("there is no container padding")?; + + workspace.container_padding = Option::from(sizing.adjust_by(padding, adjustment)); + + self.update_focused_workspace(false, false) + } + /// Asks the window manager to manage the window that has the focus in the compositor again /// after [`WindowManager::unmanage_focused_window`], by raising a /// [`WindowManagerEvent::Manage`] for it, which is handled like a window that opens diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index bd2ca5d7..edc3e7bc 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -37,6 +37,10 @@ pub struct Workspace { pub latest_layout: Vec, pub resize_dimensions: Vec>, pub tile: bool, + /// The work area offset of this workspace, which it takes instead of its monitor's + pub work_area_offset: Option, + /// Whether this workspace takes its monitor's window-based offset (true by default) + pub apply_window_based_work_area_offset: bool, #[serde(skip)] pub globals: WorkspaceGlobals, #[serde(skip_serializing_if = "Option::is_none")] @@ -56,11 +60,13 @@ impl Default for Workspace { container_padding: None, resize_dimensions: vec![], layout: Layout::Default(DefaultLayout::BSP), + work_area_offset: None, latest_layout: vec![], layout_flip: None, layout_options: None, globals: Default::default(), tile: true, + apply_window_based_work_area_offset: true, floating_windows: Default::default(), preselected_container_idx: None, promotion_swap_container_idx: None, @@ -69,13 +75,15 @@ impl Default for Workspace { } #[derive(Debug, Default, Copy, Clone, Serialize, Deserialize, PartialEq)] -/// The work area a monitor gives the workspace it shows, and the padding and the offset the -/// workspace falls back to when it sets none of its own +/// The work area a monitor gives the workspace it shows, the padding and the offset the +/// workspace falls back to when it sets none of its own, and the monitor's window-based offset pub struct WorkspaceGlobals { pub container_padding: Option, pub workspace_padding: Option, pub work_area: Rect, pub work_area_offset: Option, + pub window_based_work_area_offset: Option, + pub window_based_work_area_offset_limit: isize, } /// `komorebi_layouts::Rect::percentage_within_horizontal_bounds`, which that crate compiles only @@ -532,7 +540,10 @@ impl Workspace { impl Workspace { /// Tiles the workspace: asks the layout for a tile per container in the work area, less the - /// offset and the workspace padding, and puts every window of each container on its tile. + /// offset (the workspace's own, or else the one its monitor gives it), the monitor's + /// window-based offset while there are no more containers than its limit and + /// [`Workspace::apply_window_based_work_area_offset`] is set, and the workspace padding, and + /// puts every window of each container on its tile. /// /// Containers that have no windows left are dropped first, except the one a preselection /// reserved, and so is a window that is in more than one container. A tile is clamped to the @@ -565,7 +576,9 @@ impl Workspace { .or(self.globals.workspace_padding) .unwrap_or_default(); let work_area = self.globals.work_area; - let work_area_offset = self.globals.work_area_offset; + let work_area_offset = self.work_area_offset.or(self.globals.work_area_offset); + let window_based_work_area_offset = self.globals.window_based_work_area_offset; + let window_based_work_area_offset_limit = self.globals.window_based_work_area_offset_limit; let mut adjusted_work_area = work_area_offset.map_or_else( || work_area, @@ -580,6 +593,23 @@ impl Workspace { }, ); + if self.containers().len() <= window_based_work_area_offset_limit as usize + && self.apply_window_based_work_area_offset + { + adjusted_work_area = window_based_work_area_offset.map_or_else( + || adjusted_work_area, + |offset| { + let mut with_offset = adjusted_work_area; + with_offset.left += offset.left; + with_offset.top += offset.top; + with_offset.right -= offset.right; + with_offset.bottom -= offset.bottom; + + with_offset + }, + ); + } + adjusted_work_area.add_padding(workspace_padding); self.enforce_resize_constraints(); diff --git a/komorebi/tests/padding.rs b/komorebi/tests/padding.rs new file mode 100644 index 00000000..92c5c936 --- /dev/null +++ b/komorebi/tests/padding.rs @@ -0,0 +1,244 @@ +//! The padding around and between the tiles, and the offsets that keep parts of the work area +//! free of tiles, against an in-memory desktop: the messages go in through +//! [`WindowManager::process_command`], and what comes out is where the backend was asked to put +//! the windows. +//! +//! The fake's one monitor is 1920x1080 with a work area of 1920x1050, and a workspace falls back to +//! a workspace padding and a container padding of 5 pixels each. +//! +//! Window ids are in the 28_000s. + +use komorebi::backend::fake::FakeBackend; +use komorebi::backend::with_backend; +use komorebi::core::Rect; +use komorebi::core::Sizing; +use komorebi::core::SocketMessage; +use komorebi::window::Window; +use komorebi::window_manager::WindowManager; +use komorebi::window_manager_event::KWinNotification; +use komorebi::window_manager_event::SystemNotification; +use komorebi::window_manager_event::WindowManagerEvent; +use std::sync::Arc; + +fn added(id: u32) -> WindowManagerEvent { + WindowManagerEvent::Show( + SystemNotification::KWin(KWinNotification::WindowAdded), + Window::from(id), + ) +} + +/// A window manager over a fake desktop with one 1920x1080 monitor, and a window for each of +/// `ids`, opened in that order +fn desktop_with(ids: &[u32]) -> (Arc, WindowManager) { + let fake = Arc::new(FakeBackend::with_one_monitor()); + let (_sender, receiver) = crossbeam_channel::bounded(1); + // unix socket paths are limited to ~104 bytes on macOS, which the temp dir alone can exceed + static NEXT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); + let socket = std::path::PathBuf::from(format!( + "/tmp/kmp-{}-{}.sock", + std::process::id(), + NEXT.fetch_add(1, std::sync::atomic::Ordering::SeqCst) + )); + + let mut wm = with_backend(fake.clone(), || { + let mut wm = WindowManager::new(receiver, Some(socket)).unwrap(); + wm.init().unwrap(); + wm + }); + for &id in ids { + open(&fake, &mut wm, id); + } + + (fake, wm) +} + +fn open(fake: &Arc, wm: &mut WindowManager, id: u32) { + fake.open_window(id, "foot", "foot", &format!("terminal {id}")); + with_backend(fake.clone(), || wm.process_event(added(id))).unwrap(); +} + +fn send( + fake: &Arc, + wm: &mut WindowManager, + message: SocketMessage, +) -> color_eyre::Result<()> { + with_backend(fake.clone(), || wm.process_command(message, Vec::new())) +} + +fn rect(left: i32, top: i32, right: i32, bottom: i32) -> Rect { + Rect { + left, + top, + right, + bottom, + } +} + +/// A desktop with one window and no padding, so that the window's frame is its tile +fn one_window_without_padding(id: u32) -> (Arc, WindowManager) { + let (fake, mut wm) = desktop_with(&[id]); + send(&fake, &mut wm, SocketMessage::FocusedWorkspacePadding(0)).unwrap(); + send( + &fake, + &mut wm, + SocketMessage::FocusedWorkspaceContainerPadding(0), + ) + .unwrap(); + assert_eq!(fake.rect_of(id), Some(rect(0, 0, 1920, 1050))); + (fake, wm) +} + +#[test] +fn the_paddings_of_the_focused_workspace_are_set_and_adjusted() { + let (fake, mut wm) = desktop_with(&[28_001]); + assert_eq!(fake.rect_of(28_001), Some(rect(10, 10, 1900, 1030))); + + // with no padding of its own, the workspace has none to adjust + assert_eq!( + send( + &fake, + &mut wm, + SocketMessage::AdjustWorkspacePadding(Sizing::Increase, 5) + ) + .map_err(|error| error.to_string()), + Err(String::from("there is no workspace padding")) + ); + + send(&fake, &mut wm, SocketMessage::FocusedWorkspacePadding(20)).unwrap(); + assert_eq!(fake.rect_of(28_001), Some(rect(25, 25, 1870, 1000))); + + send( + &fake, + &mut wm, + SocketMessage::FocusedWorkspaceContainerPadding(0), + ) + .unwrap(); + assert_eq!(fake.rect_of(28_001), Some(rect(20, 20, 1880, 1010))); + + send( + &fake, + &mut wm, + SocketMessage::AdjustWorkspacePadding(Sizing::Increase, 5), + ) + .unwrap(); + assert_eq!(fake.rect_of(28_001), Some(rect(25, 25, 1870, 1000))); + + send( + &fake, + &mut wm, + SocketMessage::AdjustContainerPadding(Sizing::Increase, 10), + ) + .unwrap(); + assert_eq!(fake.rect_of(28_001), Some(rect(35, 35, 1850, 980))); + + // a padding is not made smaller than nothing: a decrease past 0 changes nothing + send( + &fake, + &mut wm, + SocketMessage::AdjustContainerPadding(Sizing::Decrease, 30), + ) + .unwrap(); + assert_eq!(fake.rect_of(28_001), Some(rect(35, 35, 1850, 980))); +} + +#[test] +fn the_paddings_of_a_workspace_are_set_by_its_indices() { + let (fake, mut wm) = desktop_with(&[28_011]); + + send(&fake, &mut wm, SocketMessage::ContainerPadding(0, 0, 0)).unwrap(); + send(&fake, &mut wm, SocketMessage::WorkspacePadding(0, 0, 0)).unwrap(); + assert_eq!(fake.rect_of(28_011), Some(rect(0, 0, 1920, 1050))); + + assert_eq!( + send(&fake, &mut wm, SocketMessage::WorkspacePadding(1, 0, 0)) + .map_err(|error| error.to_string()), + Err(String::from("there is no monitor")) + ); +} + +#[test] +fn the_workspaces_offset_wins_over_the_monitors_which_wins_over_the_global_one() { + let (fake, mut wm) = one_window_without_padding(28_021); + + send( + &fake, + &mut wm, + SocketMessage::WorkAreaOffset(rect(0, 40, 0, 40)), + ) + .unwrap(); + assert_eq!(fake.rect_of(28_021), Some(rect(0, 40, 1920, 1010))); + + send( + &fake, + &mut wm, + SocketMessage::MonitorWorkAreaOffset(0, rect(100, 0, 100, 0)), + ) + .unwrap(); + assert_eq!(fake.rect_of(28_021), Some(rect(100, 0, 1820, 1050))); + + send( + &fake, + &mut wm, + SocketMessage::WorkspaceWorkAreaOffset(0, 0, rect(0, 0, 0, 200)), + ) + .unwrap(); + assert_eq!(fake.rect_of(28_021), Some(rect(0, 0, 1920, 850))); + + // a monitor or a workspace that is not there is ignored + send( + &fake, + &mut wm, + SocketMessage::MonitorWorkAreaOffset(3, rect(0, 0, 0, 0)), + ) + .unwrap(); + send( + &fake, + &mut wm, + SocketMessage::WorkspaceWorkAreaOffset(0, 3, rect(0, 0, 0, 0)), + ) + .unwrap(); + assert_eq!(fake.rect_of(28_021), Some(rect(0, 0, 1920, 850))); +} + +#[test] +fn the_window_based_offset_is_taken_up_to_its_window_limit_and_can_be_turned_off() { + let (fake, mut wm) = one_window_without_padding(28_031); + // the monitor's window-based offset applies while the workspace has at most one window + let monitor = wm.monitors_mut().get_mut(0).unwrap(); + monitor.window_based_work_area_offset = Some(rect(200, 0, 400, 0)); + assert_eq!(monitor.window_based_work_area_offset_limit, 1); + + send(&fake, &mut wm, SocketMessage::Retile).unwrap(); + assert_eq!(fake.rect_of(28_031), Some(rect(200, 0, 1520, 1050))); + + open(&fake, &mut wm, 28_032); + assert_eq!(fake.rect_of(28_031), Some(rect(0, 0, 960, 1050))); + assert_eq!(fake.rect_of(28_032), Some(rect(960, 0, 960, 1050))); + + fake.close_window_now(28_032); + with_backend(fake.clone(), || wm.process_event(removed(28_032))).unwrap(); + assert_eq!(fake.rect_of(28_031), Some(rect(200, 0, 1520, 1050))); + + send( + &fake, + &mut wm, + SocketMessage::ToggleWindowBasedWorkAreaOffset, + ) + .unwrap(); + assert_eq!(fake.rect_of(28_031), Some(rect(0, 0, 1920, 1050))); + + send( + &fake, + &mut wm, + SocketMessage::ToggleWindowBasedWorkAreaOffset, + ) + .unwrap(); + assert_eq!(fake.rect_of(28_031), Some(rect(200, 0, 1520, 1050))); +} + +fn removed(id: u32) -> WindowManagerEvent { + WindowManagerEvent::Destroy( + SystemNotification::KWin(KWinNotification::WindowRemoved), + Window::from(id), + ) +} diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index c6d19657..3b9b64ea 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -18,6 +18,11 @@ //! tile, or the focus to it. //! - `toggle-float` takes the focused window out of the layout, or puts it back, and //! `toggle-lock` locks the focused container at its index, or unlocks it. +//! - `focused-workspace-padding`, `focused-workspace-container-padding`, `workspace-padding`, +//! `container-padding` and the two `adjust-*-padding` set the padding around the tiles and +//! between them, and `global-work-area-offset`, `monitor-work-area-offset`, +//! `workspace-work-area-offset` and `toggle-window-based-work-area-offset` keep parts of the work +//! area free of tiles. //! - `minimize` and `close` minimize and close the focused window, `unmanage` takes it out of //! the layout until `manage` takes it back, `unmanaged-window-operation-behaviour` sets whether //! the daemon carries out an order while the focused window is not one it tiles, and @@ -46,6 +51,7 @@ use komorebi_client::CycleDirection; use komorebi_client::DefaultLayout; use komorebi_client::OperationBehaviour; use komorebi_client::OperationDirection; +use komorebi_client::Rect; use komorebi_client::Sizing; use komorebi_client::SocketMessage; use komorebi_client::StateQuery; @@ -108,6 +114,66 @@ gen_enum_subcommand_args! { PromoteWindow: OperationDirection, } +macro_rules! gen_focused_workspace_padding_subcommand_args { + // SubCommand Pattern + ( $( $name:ident ),+ $(,)? ) => { + $( + #[derive(clap::Parser)] + pub struct $name { + /// Pixels size to set as an integer + size: i32, + } + )+ + }; +} + +gen_focused_workspace_padding_subcommand_args! { + FocusedWorkspaceContainerPadding, + FocusedWorkspacePadding, +} + +macro_rules! gen_padding_subcommand_args { + // SubCommand Pattern + ( $( $name:ident ),+ $(,)? ) => { + $( + #[derive(clap::Parser)] + pub struct $name { + /// Monitor index (zero-indexed) + monitor: usize, + /// Workspace index on the specified monitor (zero-indexed) + workspace: usize, + /// Pixels to pad with as an integer + size: i32, + } + )+ + }; +} + +gen_padding_subcommand_args! { + ContainerPadding, + WorkspacePadding, +} + +macro_rules! gen_padding_adjustment_subcommand_args { + // SubCommand Pattern + ( $( $name:ident ),+ $(,)? ) => { + $( + #[derive(clap::Parser)] + pub struct $name { + #[clap(value_enum)] + sizing: Sizing, + /// Pixels to adjust by as an integer + adjustment: i32, + } + )+ + }; +} + +gen_padding_adjustment_subcommand_args! { + AdjustContainerPadding, + AdjustWorkspacePadding, +} + #[derive(Parser)] struct Resize { #[clap(value_enum)] @@ -142,6 +208,48 @@ struct UnsubscribeSocket { socket: String, } +#[derive(Parser)] +struct GlobalWorkAreaOffset { + /// Size of the left work area offset (set right to left * 2 to maintain right padding) + left: i32, + /// Size of the top work area offset (set bottom to the same value to maintain bottom padding) + top: i32, + /// Size of the right work area offset + right: i32, + /// Size of the bottom work area offset + bottom: i32, +} + +#[derive(Parser)] +struct MonitorWorkAreaOffset { + /// Monitor index (zero-indexed) + monitor: usize, + /// Size of the left work area offset (set right to left * 2 to maintain right padding) + left: i32, + /// Size of the top work area offset (set bottom to the same value to maintain bottom padding) + top: i32, + /// Size of the right work area offset + right: i32, + /// Size of the bottom work area offset + bottom: i32, +} + +#[derive(Parser)] +struct WorkspaceWorkAreaOffset { + /// Monitor index (zero-indexed) + monitor: usize, + /// Workspace index (zero-indexed) + workspace: usize, + /// Size of the left work area offset (set right to left * 2 to maintain right padding) + left: i32, + /// Size of the top work area offset (set bottom to the same value to maintain bottom padding) + top: i32, + /// Size of the right work area offset + right: i32, + /// Size of the bottom work area offset + bottom: i32, +} + #[derive(Parser)] #[allow(clippy::struct_excessive_bools)] struct Start { @@ -288,6 +396,32 @@ enum SubCommand { /// Set the resize delta (used by resize-edge and resize-axis) #[clap(arg_required_else_help = true)] ResizeDelta(ResizeDelta), + // /// Set the invisible border dimensions around each window + // #[clap(arg_required_else_help = true)] + // InvisibleBorders(InvisibleBorders), + /// Set offsets to exclude parts of the work area from tiling + #[clap(arg_required_else_help = true)] + GlobalWorkAreaOffset(GlobalWorkAreaOffset), + /// Set offsets for a monitor to exclude parts of the work area from tiling + #[clap(arg_required_else_help = true)] + MonitorWorkAreaOffset(MonitorWorkAreaOffset), + /// Set offsets for a workspace to exclude parts of the work area from tiling + #[clap(arg_required_else_help = true)] + WorkspaceWorkAreaOffset(WorkspaceWorkAreaOffset), + /// Toggle application of the window-based work area offset for the focused workspace + ToggleWindowBasedWorkAreaOffset, + /// Set container padding on the focused workspace + #[clap(arg_required_else_help = true)] + FocusedWorkspaceContainerPadding(FocusedWorkspaceContainerPadding), + /// Set workspace padding on the focused workspace + #[clap(arg_required_else_help = true)] + FocusedWorkspacePadding(FocusedWorkspacePadding), + /// Adjust container padding on the focused workspace + #[clap(arg_required_else_help = true)] + AdjustContainerPadding(AdjustContainerPadding), + /// Adjust workspace padding on the focused workspace + #[clap(arg_required_else_help = true)] + AdjustWorkspacePadding(AdjustWorkspacePadding), /// Set the layout on the focused workspace #[clap(arg_required_else_help = true)] ChangeLayout(ChangeLayout), @@ -316,6 +450,12 @@ enum SubCommand { PromoteWindow(PromoteWindow), /// Force the retiling of all managed windows Retile, + /// Set the container padding for the specified workspace + #[clap(arg_required_else_help = true)] + ContainerPadding(ContainerPadding), + /// Set the workspace padding for the specified workspace + #[clap(arg_required_else_help = true)] + WorkspacePadding(WorkspacePadding), /// Toggle the paused state for all window tiling TogglePause, /// Toggle window tiling on the focused workspace @@ -519,6 +659,9 @@ fn main() -> eyre::Result<()> { SubCommand::PromoteWindow(args) => { send_message(&SocketMessage::PromoteWindow(args.operation_direction))?; } + SubCommand::ToggleWindowBasedWorkAreaOffset => { + send_message(&SocketMessage::ToggleWindowBasedWorkAreaOffset)?; + } SubCommand::ToggleTiling => { send_message(&SocketMessage::ToggleTiling)?; } @@ -537,6 +680,70 @@ fn main() -> eyre::Result<()> { SubCommand::ResizeDelta(args) => { send_message(&SocketMessage::ResizeDelta(args.pixels))?; } + SubCommand::MonitorWorkAreaOffset(args) => { + send_message(&SocketMessage::MonitorWorkAreaOffset( + args.monitor, + Rect { + left: args.left, + top: args.top, + right: args.right, + bottom: args.bottom, + }, + ))?; + } + SubCommand::GlobalWorkAreaOffset(args) => { + send_message(&SocketMessage::WorkAreaOffset(Rect { + left: args.left, + top: args.top, + right: args.right, + bottom: args.bottom, + }))?; + } + + SubCommand::WorkspaceWorkAreaOffset(args) => { + send_message(&SocketMessage::WorkspaceWorkAreaOffset( + args.monitor, + args.workspace, + Rect { + left: args.left, + top: args.top, + right: args.right, + bottom: args.bottom, + }, + ))?; + } + SubCommand::ContainerPadding(args) => { + send_message(&SocketMessage::ContainerPadding( + args.monitor, + args.workspace, + args.size, + ))?; + } + SubCommand::WorkspacePadding(args) => { + send_message(&SocketMessage::WorkspacePadding( + args.monitor, + args.workspace, + args.size, + ))?; + } + SubCommand::FocusedWorkspacePadding(args) => { + send_message(&SocketMessage::FocusedWorkspacePadding(args.size))?; + } + SubCommand::FocusedWorkspaceContainerPadding(args) => { + send_message(&SocketMessage::FocusedWorkspaceContainerPadding(args.size))?; + } + SubCommand::AdjustWorkspacePadding(args) => { + send_message(&SocketMessage::AdjustWorkspacePadding( + args.sizing, + args.adjustment, + ))?; + } + SubCommand::AdjustContainerPadding(args) => { + send_message(&SocketMessage::AdjustContainerPadding( + args.sizing, + args.adjustment, + ))?; + } SubCommand::ScrollingLayoutColumns(args) => { send_message(&SocketMessage::ScrollingLayoutColumns(args.count))?; } diff --git a/komorebic/tests/cli.rs b/komorebic/tests/cli.rs index 93f36fbd..9d8c8c79 100644 --- a/komorebic/tests/cli.rs +++ b/komorebic/tests/cli.rs @@ -297,6 +297,62 @@ fn the_promote_subcommands_send_their_message() { ); } +#[test] +fn the_padding_subcommands_send_the_workspace_and_the_pixels_they_are_given() { + sends( + &["focused-workspace-padding", "20"], + r#"{"type":"FocusedWorkspacePadding","content":20}"#, + ); + sends( + &["focused-workspace-container-padding", "10"], + r#"{"type":"FocusedWorkspaceContainerPadding","content":10}"#, + ); + sends( + &["workspace-padding", "0", "1", "12"], + r#"{"type":"WorkspacePadding","content":[0,1,12]}"#, + ); + sends( + &["container-padding", "1", "0", "8"], + r#"{"type":"ContainerPadding","content":[1,0,8]}"#, + ); + sends( + &["adjust-workspace-padding", "increase", "5"], + r#"{"type":"AdjustWorkspacePadding","content":["Increase",5]}"#, + ); + sends( + &["adjust-container-padding", "decrease", "3"], + r#"{"type":"AdjustContainerPadding","content":["Decrease",3]}"#, + ); +} + +#[test] +fn the_offset_subcommands_send_the_offset_they_are_given() { + sends( + &["global-work-area-offset", "10", "20", "30", "40"], + r#"{"type":"WorkAreaOffset","content":{"left":10,"top":20,"right":30,"bottom":40}}"#, + ); + sends( + &["monitor-work-area-offset", "1", "10", "20", "30", "40"], + r#"{"type":"MonitorWorkAreaOffset","content":[1,{"left":10,"top":20,"right":30,"bottom":40}]}"#, + ); + sends( + &[ + "workspace-work-area-offset", + "1", + "2", + "10", + "20", + "30", + "40", + ], + r#"{"type":"WorkspaceWorkAreaOffset","content":[1,2,{"left":10,"top":20,"right":30,"bottom":40}]}"#, + ); + sends( + &["toggle-window-based-work-area-offset"], + r#"{"type":"ToggleWindowBasedWorkAreaOffset"}"#, + ); +} + #[test] fn the_subcommands_about_the_focused_window_and_pausing_send_their_message() { sends(&["minimize"], r#"{"type":"Minimize"}"#); @@ -369,22 +425,29 @@ fn docgen_writes_the_help_of_every_subcommand_in_a_text_fence() { assert_eq!( pages, [ + "adjust-container-padding.md", + "adjust-workspace-padding.md", "cancel-preselect.md", "change-layout.md", "close.md", "completions.md", + "container-padding.md", "cycle-focus.md", "cycle-layout.md", "cycle-move.md", "data-directory.md", "flip-layout.md", "focus.md", + "focused-workspace-container-padding.md", + "focused-workspace-padding.md", + "global-work-area-offset.md", "layout-ratios.md", "load-resize.md", "log.md", "manage.md", "minimize.md", "monitor-information.md", + "monitor-work-area-offset.md", "mouse-follows-focus.md", "move.md", "preselect-direction.md", @@ -410,9 +473,12 @@ fn docgen_writes_the_help_of_every_subcommand_in_a_text_fence() { "toggle-mouse-follows-focus.md", "toggle-pause.md", "toggle-tiling.md", + "toggle-window-based-work-area-offset.md", "unmanage.md", "unmanaged-window-operation-behaviour.md", "unsubscribe-socket.md", + "workspace-padding.md", + "workspace-work-area-offset.md", ] ); diff --git a/nix/tests/vm/suites/commands/test.py b/nix/tests/vm/suites/commands/test.py index 118fc25a..e2d6b5f3 100644 --- a/nix/tests/vm/suites/commands/test.py +++ b/nix/tests/vm/suites/commands/test.py @@ -192,6 +192,26 @@ toggle-tiling toggle-tiling toggle-pause toggle-pause +global-work-area-offset 10 10 20 20 +global-work-area-offset 0 0 0 0 +monitor-work-area-offset 0 10 10 20 20 +monitor-work-area-offset 0 0 0 0 0 +workspace-work-area-offset 0 0 10 10 20 20 +workspace-work-area-offset 0 0 0 0 0 0 +toggle-window-based-work-area-offset +toggle-window-based-work-area-offset +focused-workspace-container-padding 20 +focused-workspace-container-padding 10 +focused-workspace-padding 20 +focused-workspace-padding 10 +adjust-container-padding increase 5 +adjust-container-padding decrease 5 +adjust-workspace-padding increase 5 +adjust-workspace-padding decrease 5 +container-padding 0 0 12 +container-padding 0 0 10 +workspace-padding 0 0 12 +workspace-padding 0 0 10 unmanaged-window-operation-behaviour op unmanaged-window-operation-behaviour no-op unmanaged-window-operation-behaviour op