diff options
| author | yrkv <yegor@tydbits.com> | 2025-08-16 01:42:08 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-16 11:42:08 +0300 |
| commit | af30cc8df68b29973c8b9eec290f9e6b93463929 (patch) | |
| tree | c216831fe217e191c958545b7536183d67b1b186 /niri-ipc | |
| parent | a003e013074b5188a2b1f2364fff90fb4caf972a (diff) | |
| download | niri-af30cc8df68b29973c8b9eec290f9e6b93463929.tar.gz niri-af30cc8df68b29973c8b9eec290f9e6b93463929.tar.bz2 niri-af30cc8df68b29973c8b9eec290f9e6b93463929.zip | |
niri-ipc: Add window positions and sizes (#1265)
* Add window sizes and positions to the IPC
* basic fixes
* report window_loc instead of window pos
* clean ups
* make scrolling indices 1-based
* add printing to niri msg windows
* don't include render offset in floating tile pos
---------
Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
Diffstat (limited to 'niri-ipc')
| -rw-r--r-- | niri-ipc/src/lib.rs | 53 | ||||
| -rw-r--r-- | niri-ipc/src/state.rs | 7 |
2 files changed, 60 insertions, 0 deletions
diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index 70175c01..737f1647 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -1155,6 +1155,54 @@ pub struct Window { pub is_floating: bool, /// Whether this window requests your attention. pub is_urgent: bool, + /// Position- and size-related properties of the window. + pub layout: WindowLayout, +} + +/// Position- and size-related properties of a [`Window`]. +/// +/// Optional properties will be unset for some windows, do not rely on them being present. Whether +/// some optional properties are present or absent for certain window types may change across niri +/// releases. +/// +/// All sizes and positions are in *logical pixels* unless stated otherwise. Logical sizes may be +/// fractional. For example, at 1.25 monitor scale, a 2-physical-pixel-wide window border is 1.6 +/// logical pixels wide. +/// +/// This struct contains positions and sizes both for full tiles ([`Self::tile_size`], +/// [`Self::tile_pos_in_workspace_view`]) and the window geometry ([`Self::window_size`], +/// [`Self::window_offset_in_tile`]). For visual displays, use the tile properties, as they +/// correspond to what the user visually considers "window". The window properties on the other +/// hand are mainly useful when you need to know the underlying Wayland window sizes, e.g. for +/// application debugging. +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] +pub struct WindowLayout { + /// Location of a tiled window within a workspace: (column index, tile index in column). + /// + /// The indices are 1-based, i.e. the leftmost column is at index 1 and the topmost tile in a + /// column is at index 1. This is consistent with [`Action::FocusColumn`] and + /// [`Action::FocusWindowInColumn`]. + pub pos_in_scrolling_layout: Option<(usize, usize)>, + /// Size of the tile this window is in, including decorations like borders. + pub tile_size: (f64, f64), + /// Size of the window's visual geometry itself. + /// + /// Does not include niri decorations like borders. + /// + /// Currently, Wayland toplevel windows can only be integer-sized in logical pixels, even + /// though it doesn't necessarily align to physical pixels. + pub window_size: (i32, i32), + /// Tile position within the current view of the workspace. + /// + /// This is the same "workspace view" as in gradients' `relative-to` in the niri config. + pub tile_pos_in_workspace_view: Option<(f64, f64)>, + /// Location of the window's visual geometry within its tile. + /// + /// This includes things like border sizes. For fullscreened fixed-size windows this includes + /// the distance from the corner of the black backdrop to the corner of the (centered) window + /// contents. + pub window_offset_in_tile: (f64, f64), } /// Output configuration change result. @@ -1331,6 +1379,11 @@ pub enum Event { /// The new urgency state of the window. urgent: bool, }, + /// The layout of one or more windows has changed. + WindowLayoutsChanged { + /// Pairs consisting of a window id and new layout information for the window. + changes: Vec<(u64, WindowLayout)>, + }, /// The configured keyboard layouts have changed. KeyboardLayoutsChanged { /// The new keyboard layout configuration. diff --git a/niri-ipc/src/state.rs b/niri-ipc/src/state.rs index ef03321f..ef883021 100644 --- a/niri-ipc/src/state.rs +++ b/niri-ipc/src/state.rs @@ -189,6 +189,13 @@ impl EventStreamStatePart for WindowsState { } } } + Event::WindowLayoutsChanged { changes } => { + for (id, update) in changes { + let win = self.windows.get_mut(&id); + let win = win.expect("changed window was missing from the map"); + win.layout = update; + } + } event => return Some(event), } None |
