niri-ipc: Add window positions and sizes (#1265)
Browse files at this commit11 changed files +223 -19
- niri-ipc/src/lib.rs +53 -0
- niri-ipc/src/state.rs +7 -0
- src/ipc/client.rs +65 -1
- src/ipc/server.rs +28 -5
- src/layout/floating.rs +17 -1
- src/layout/mod.rs +12 -7
- src/layout/scrolling.rs +17 -1
- src/layout/tile.rs +14 -0
- src/layout/workspace.rs +7 -1
- src/niri.rs +2 -2
- src/protocols/foreign_toplevel.rs +1 -1
niri-ipc/src/lib.rsmodified+53 -0
| @@ -1155,6 +1155,54 @@ pub struct Window { | |||
| 1155 | pub is_floating: bool, | 1155 | pub is_floating: bool, |
| 1156 | /// Whether this window requests your attention. | 1156 | /// Whether this window requests your attention. |
| 1157 | pub is_urgent: bool, | 1157 | pub is_urgent: bool, |
| 1158 | + /// Position- and size-related properties of the window. | ||
| 1159 | + pub layout: WindowLayout, | ||
| 1160 | +} | ||
| 1161 | + | ||
| 1162 | +/// Position- and size-related properties of a [`Window`]. | ||
| 1163 | +/// | ||
| 1164 | +/// Optional properties will be unset for some windows, do not rely on them being present. Whether | ||
| 1165 | +/// some optional properties are present or absent for certain window types may change across niri | ||
| 1166 | +/// releases. | ||
| 1167 | +/// | ||
| 1168 | +/// All sizes and positions are in *logical pixels* unless stated otherwise. Logical sizes may be | ||
| 1169 | +/// fractional. For example, at 1.25 monitor scale, a 2-physical-pixel-wide window border is 1.6 | ||
| 1170 | +/// logical pixels wide. | ||
| 1171 | +/// | ||
| 1172 | +/// This struct contains positions and sizes both for full tiles ([`Self::tile_size`], | ||
| 1173 | +/// [`Self::tile_pos_in_workspace_view`]) and the window geometry ([`Self::window_size`], | ||
| 1174 | +/// [`Self::window_offset_in_tile`]). For visual displays, use the tile properties, as they | ||
| 1175 | +/// correspond to what the user visually considers "window". The window properties on the other | ||
| 1176 | +/// hand are mainly useful when you need to know the underlying Wayland window sizes, e.g. for | ||
| 1177 | +/// application debugging. | ||
| 1178 | +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
| 1179 | +#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] | ||
| 1180 | +pub struct WindowLayout { | ||
| 1181 | + /// Location of a tiled window within a workspace: (column index, tile index in column). | ||
| 1182 | + /// | ||
| 1183 | + /// The indices are 1-based, i.e. the leftmost column is at index 1 and the topmost tile in a | ||
| 1184 | + /// column is at index 1. This is consistent with [`Action::FocusColumn`] and | ||
| 1185 | + /// [`Action::FocusWindowInColumn`]. | ||
| 1186 | + pub pos_in_scrolling_layout: Option<(usize, usize)>, | ||
| 1187 | + /// Size of the tile this window is in, including decorations like borders. | ||
| 1188 | + pub tile_size: (f64, f64), | ||
| 1189 | + /// Size of the window's visual geometry itself. | ||
| 1190 | + /// | ||
| 1191 | + /// Does not include niri decorations like borders. | ||
| 1192 | + /// | ||
| 1193 | + /// Currently, Wayland toplevel windows can only be integer-sized in logical pixels, even | ||
| 1194 | + /// though it doesn't necessarily align to physical pixels. | ||
| 1195 | + pub window_size: (i32, i32), | ||
| 1196 | + /// Tile position within the current view of the workspace. | ||
| 1197 | + /// | ||
| 1198 | + /// This is the same "workspace view" as in gradients' `relative-to` in the niri config. | ||
| 1199 | + pub tile_pos_in_workspace_view: Option<(f64, f64)>, | ||
| 1200 | + /// Location of the window's visual geometry within its tile. | ||
| 1201 | + /// | ||
| 1202 | + /// This includes things like border sizes. For fullscreened fixed-size windows this includes | ||
| 1203 | + /// the distance from the corner of the black backdrop to the corner of the (centered) window | ||
| 1204 | + /// contents. | ||
| 1205 | + pub window_offset_in_tile: (f64, f64), | ||
| 1158 | } | 1206 | } |
| 1159 | 1207 | ||
| 1160 | /// Output configuration change result. | 1208 | /// Output configuration change result. |
| @@ -1331,6 +1379,11 @@ pub enum Event { | |||
| 1331 | /// The new urgency state of the window. | 1379 | /// The new urgency state of the window. |
| 1332 | urgent: bool, | 1380 | urgent: bool, |
| 1333 | }, | 1381 | }, |
| 1382 | + /// The layout of one or more windows has changed. | ||
| 1383 | + WindowLayoutsChanged { | ||
| 1384 | + /// Pairs consisting of a window id and new layout information for the window. | ||
| 1385 | + changes: Vec<(u64, WindowLayout)>, | ||
| 1386 | + }, | ||
| 1334 | /// The configured keyboard layouts have changed. | 1387 | /// The configured keyboard layouts have changed. |
| 1335 | KeyboardLayoutsChanged { | 1388 | KeyboardLayoutsChanged { |
| 1336 | /// The new keyboard layout configuration. | 1389 | /// The new keyboard layout configuration. |
niri-ipc/src/state.rsmodified+7 -0
| @@ -189,6 +189,13 @@ impl EventStreamStatePart for WindowsState { | |||
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| 192 | + Event::WindowLayoutsChanged { changes } => { | ||
| 193 | + for (id, update) in changes { | ||
| 194 | + let win = self.windows.get_mut(&id); | ||
| 195 | + let win = win.expect("changed window was missing from the map"); | ||
| 196 | + win.layout = update; | ||
| 197 | + } | ||
| 198 | + } | ||
| 192 | event => return Some(event), | 199 | event => return Some(event), |
| 193 | } | 200 | } |
| 194 | None | 201 | None |
src/ipc/client.rsmodified+65 -1
| @@ -7,7 +7,7 @@ use niri_config::OutputName; | |||
| 7 | use niri_ipc::socket::Socket; | 7 | use niri_ipc::socket::Socket; |
| 8 | use niri_ipc::{ | 8 | use niri_ipc::{ |
| 9 | Event, KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Overview, Request, | 9 | Event, KeyboardLayouts, LogicalOutput, Mode, Output, OutputConfigChanged, Overview, Request, |
| 10 | - Response, Transform, Window, | 10 | + Response, Transform, Window, WindowLayout, |
| 11 | }; | 11 | }; |
| 12 | use serde_json::json; | 12 | use serde_json::json; |
| 13 | 13 | ||
| @@ -447,6 +447,9 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | |||
| 447 | Event::WindowUrgencyChanged { id, urgent } => { | 447 | Event::WindowUrgencyChanged { id, urgent } => { |
| 448 | println!("Window {id}: urgency changed to {urgent}"); | 448 | println!("Window {id}: urgency changed to {urgent}"); |
| 449 | } | 449 | } |
| 450 | + Event::WindowLayoutsChanged { changes } => { | ||
| 451 | + println!("Window layouts changed: {changes:?}"); | ||
| 452 | + } | ||
| 450 | Event::KeyboardLayoutsChanged { keyboard_layouts } => { | 453 | Event::KeyboardLayoutsChanged { keyboard_layouts } => { |
| 451 | println!("Keyboard layouts changed: {keyboard_layouts:?}"); | 454 | println!("Keyboard layouts changed: {keyboard_layouts:?}"); |
| 452 | } | 455 | } |
| @@ -612,4 +615,65 @@ fn print_window(window: &Window) { | |||
| 612 | } else { | 615 | } else { |
| 613 | println!(" Workspace ID: (none)"); | 616 | println!(" Workspace ID: (none)"); |
| 614 | } | 617 | } |
| 618 | + | ||
| 619 | + let WindowLayout { | ||
| 620 | + pos_in_scrolling_layout, | ||
| 621 | + tile_size, | ||
| 622 | + window_size, | ||
| 623 | + tile_pos_in_workspace_view, | ||
| 624 | + window_offset_in_tile, | ||
| 625 | + } = window.layout; | ||
| 626 | + | ||
| 627 | + println!(" Layout:"); | ||
| 628 | + println!( | ||
| 629 | + " Tile size: {} x {}", | ||
| 630 | + fmt_rounded(tile_size.0), | ||
| 631 | + fmt_rounded(tile_size.1) | ||
| 632 | + ); | ||
| 633 | + | ||
| 634 | + if let Some(pos) = pos_in_scrolling_layout { | ||
| 635 | + println!(" Scrolling position: column {}, tile {}", pos.0, pos.1); | ||
| 636 | + } | ||
| 637 | + | ||
| 638 | + if let Some(pos) = tile_pos_in_workspace_view { | ||
| 639 | + println!( | ||
| 640 | + " Workspace-view position: {}, {}", | ||
| 641 | + fmt_rounded(pos.0), | ||
| 642 | + fmt_rounded(pos.1) | ||
| 643 | + ); | ||
| 644 | + } | ||
| 645 | + | ||
| 646 | + println!(" Window size: {} x {}", window_size.0, window_size.1); | ||
| 647 | + println!( | ||
| 648 | + " Window offset in tile: {} x {}", | ||
| 649 | + fmt_rounded(window_offset_in_tile.0), | ||
| 650 | + fmt_rounded(window_offset_in_tile.1) | ||
| 651 | + ); | ||
| 652 | +} | ||
| 653 | + | ||
| 654 | +fn fmt_rounded(x: f64) -> String { | ||
| 655 | + let r = x.round(); | ||
| 656 | + if (r - x).abs() <= 0.005 { | ||
| 657 | + format!("{r}") | ||
| 658 | + } else { | ||
| 659 | + format!("{x:.2}") | ||
| 660 | + } | ||
| 661 | +} | ||
| 662 | + | ||
| 663 | +#[cfg(test)] | ||
| 664 | +mod tests { | ||
| 665 | + use insta::assert_snapshot; | ||
| 666 | + | ||
| 667 | + use super::*; | ||
| 668 | + | ||
| 669 | + #[test] | ||
| 670 | + fn test_fmt_rounded() { | ||
| 671 | + assert_snapshot!(fmt_rounded(1.9), @"1.90"); | ||
| 672 | + assert_snapshot!(fmt_rounded(1.994), @"1.99"); | ||
| 673 | + assert_snapshot!(fmt_rounded(1.996), @"2"); | ||
| 674 | + assert_snapshot!(fmt_rounded(2.0), @"2"); | ||
| 675 | + assert_snapshot!(fmt_rounded(2.004), @"2"); | ||
| 676 | + assert_snapshot!(fmt_rounded(2.006), @"2.01"); | ||
| 677 | + assert_snapshot!(fmt_rounded(2.1), @"2.10"); | ||
| 678 | + } | ||
| 615 | } | 679 | } |
src/ipc/server.rsmodified+28 -5
| @@ -17,7 +17,8 @@ use futures_util::{select_biased, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, Fu | |||
| 17 | use niri_config::OutputName; | 17 | use niri_config::OutputName; |
| 18 | use niri_ipc::state::{EventStreamState, EventStreamStatePart as _}; | 18 | use niri_ipc::state::{EventStreamState, EventStreamStatePart as _}; |
| 19 | use niri_ipc::{ | 19 | use niri_ipc::{ |
| 20 | - Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response, Workspace, | 20 | + Event, KeyboardLayouts, OutputConfigChanged, Overview, Reply, Request, Response, WindowLayout, |
| 21 | + Workspace, | ||
| 21 | }; | 22 | }; |
| 22 | use smithay::desktop::layer_map_for_output; | 23 | use smithay::desktop::layer_map_for_output; |
| 23 | use smithay::input::pointer::{ | 24 | use smithay::input::pointer::{ |
| @@ -477,7 +478,11 @@ async fn handle_event_stream_client(client: EventStreamClient) -> anyhow::Result | |||
| 477 | Ok(()) | 478 | Ok(()) |
| 478 | } | 479 | } |
| 479 | 480 | ||
| 480 | -fn make_ipc_window(mapped: &Mapped, workspace_id: Option<WorkspaceId>) -> niri_ipc::Window { | 481 | +fn make_ipc_window( |
| 482 | + mapped: &Mapped, | ||
| 483 | + workspace_id: Option<WorkspaceId>, | ||
| 484 | + layout: WindowLayout, | ||
| 485 | +) -> niri_ipc::Window { | ||
| 481 | with_toplevel_role(mapped.toplevel(), |role| niri_ipc::Window { | 486 | with_toplevel_role(mapped.toplevel(), |role| niri_ipc::Window { |
| 482 | id: mapped.id().get(), | 487 | id: mapped.id().get(), |
| 483 | title: role.title.clone(), | 488 | title: role.title.clone(), |
| @@ -487,6 +492,7 @@ fn make_ipc_window(mapped: &Mapped, workspace_id: Option<WorkspaceId>) -> niri_i | |||
| 487 | is_focused: mapped.is_focused(), | 492 | is_focused: mapped.is_focused(), |
| 488 | is_floating: mapped.is_floating(), | 493 | is_floating: mapped.is_floating(), |
| 489 | is_urgent: mapped.is_urgent(), | 494 | is_urgent: mapped.is_urgent(), |
| 495 | + layout, | ||
| 490 | }) | 496 | }) |
| 491 | } | 497 | } |
| 492 | 498 | ||
| @@ -657,10 +663,12 @@ impl State { | |||
| 657 | let mut events = Vec::new(); | 663 | let mut events = Vec::new(); |
| 658 | let layout = &self.niri.layout; | 664 | let layout = &self.niri.layout; |
| 659 | 665 | ||
| 666 | + let mut batch_change_layouts: Vec<(u64, WindowLayout)> = Vec::new(); | ||
| 667 | + | ||
| 660 | // Check for window changes. | 668 | // Check for window changes. |
| 661 | let mut seen = HashSet::new(); | 669 | let mut seen = HashSet::new(); |
| 662 | let mut focused_id = None; | 670 | let mut focused_id = None; |
| 663 | - layout.with_windows(|mapped, _, ws_id| { | 671 | + layout.with_windows(|mapped, _, ws_id, window_layout| { |
| 664 | let id = mapped.id().get(); | 672 | let id = mapped.id().get(); |
| 665 | seen.insert(id); | 673 | seen.insert(id); |
| 666 | 674 | ||
| @@ -669,7 +677,7 @@ impl State { | |||
| 669 | } | 677 | } |
| 670 | 678 | ||
| 671 | let Some(ipc_win) = state.windows.get(&id) else { | 679 | let Some(ipc_win) = state.windows.get(&id) else { |
| 672 | - let window = make_ipc_window(mapped, ws_id); | 680 | + let window = make_ipc_window(mapped, ws_id, window_layout); |
| 673 | events.push(Event::WindowOpenedOrChanged { window }); | 681 | events.push(Event::WindowOpenedOrChanged { window }); |
| 674 | return; | 682 | return; |
| 675 | }; | 683 | }; |
| @@ -683,11 +691,15 @@ impl State { | |||
| 683 | }); | 691 | }); |
| 684 | 692 | ||
| 685 | if changed { | 693 | if changed { |
| 686 | - let window = make_ipc_window(mapped, ws_id); | 694 | + let window = make_ipc_window(mapped, ws_id, window_layout); |
| 687 | events.push(Event::WindowOpenedOrChanged { window }); | 695 | events.push(Event::WindowOpenedOrChanged { window }); |
| 688 | return; | 696 | return; |
| 689 | } | 697 | } |
| 690 | 698 | ||
| 699 | + if ipc_win.layout != window_layout { | ||
| 700 | + batch_change_layouts.push((id, window_layout)); | ||
| 701 | + } | ||
| 702 | + | ||
| 691 | if mapped.is_focused() && !ipc_win.is_focused { | 703 | if mapped.is_focused() && !ipc_win.is_focused { |
| 692 | events.push(Event::WindowFocusChanged { id: Some(id) }); | 704 | events.push(Event::WindowFocusChanged { id: Some(id) }); |
| 693 | } | 705 | } |
| @@ -698,6 +710,17 @@ impl State { | |||
| 698 | } | 710 | } |
| 699 | }); | 711 | }); |
| 700 | 712 | ||
| 713 | + // It might make sense to push layout changes after closed windows (since windows about to | ||
| 714 | + // be closed will occupy the same column/tile positions as the window that moved into this | ||
| 715 | + // vacated space), but also we are already pushing some layout changes in | ||
| 716 | + // WindowOpenedOrChanged above, meaning that the receiving end has to handle this case | ||
| 717 | + // anyway. | ||
| 718 | + if !batch_change_layouts.is_empty() { | ||
| 719 | + events.push(Event::WindowLayoutsChanged { | ||
| 720 | + changes: batch_change_layouts, | ||
| 721 | + }); | ||
| 722 | + } | ||
| 723 | + | ||
| 701 | // Check for closed windows. | 724 | // Check for closed windows. |
| 702 | let mut ipc_focused_id = None; | 725 | let mut ipc_focused_id = None; |
| 703 | for (id, ipc_win) in &state.windows { | 726 | for (id, ipc_win) in &state.windows { |
src/layout/floating.rsmodified+17 -1
| @@ -3,7 +3,7 @@ use std::iter::zip; | |||
| 3 | use std::rc::Rc; | 3 | use std::rc::Rc; |
| 4 | 4 | ||
| 5 | use niri_config::{PresetSize, RelativeTo}; | 5 | use niri_config::{PresetSize, RelativeTo}; |
| 6 | -use niri_ipc::{PositionChange, SizeChange}; | 6 | +use niri_ipc::{PositionChange, SizeChange, WindowLayout}; |
| 7 | use smithay::backend::renderer::gles::GlesRenderer; | 7 | use smithay::backend::renderer::gles::GlesRenderer; |
| 8 | use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size}; | 8 | use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size}; |
| 9 | 9 | ||
| @@ -322,6 +322,22 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 322 | }) | 322 | }) |
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | + pub fn tiles_with_ipc_layouts(&self) -> impl Iterator<Item = (&Tile<W>, WindowLayout)> { | ||
| 326 | + let scale = self.scale; | ||
| 327 | + self.tiles_with_offsets().map(move |(tile, offset)| { | ||
| 328 | + // Do not include animated render offset here to avoid IPC spam. | ||
| 329 | + let pos = offset; | ||
| 330 | + // Round to physical pixels. | ||
| 331 | + let pos = pos.to_physical_precise_round(scale).to_logical(scale); | ||
| 332 | + | ||
| 333 | + let layout = WindowLayout { | ||
| 334 | + tile_pos_in_workspace_view: Some(pos.into()), | ||
| 335 | + ..tile.ipc_layout_template() | ||
| 336 | + }; | ||
| 337 | + (tile, layout) | ||
| 338 | + }) | ||
| 339 | + } | ||
| 340 | + | ||
| 325 | pub fn new_window_toplevel_bounds(&self, rules: &ResolvedWindowRules) -> Size<i32, Logical> { | 341 | pub fn new_window_toplevel_bounds(&self, rules: &ResolvedWindowRules) -> Size<i32, Logical> { |
| 326 | let border_config = rules.border.resolve_against(self.options.border); | 342 | let border_config = rules.border.resolve_against(self.options.border); |
| 327 | compute_toplevel_bounds(border_config, self.working_area.size) | 343 | compute_toplevel_bounds(border_config, self.working_area.size) |
src/layout/mod.rsmodified+12 -7
| @@ -42,7 +42,7 @@ use niri_config::{ | |||
| 42 | CenterFocusedColumn, Config, CornerRadius, FloatOrInt, PresetSize, Struts, | 42 | CenterFocusedColumn, Config, CornerRadius, FloatOrInt, PresetSize, Struts, |
| 43 | Workspace as WorkspaceConfig, WorkspaceReference, | 43 | Workspace as WorkspaceConfig, WorkspaceReference, |
| 44 | }; | 44 | }; |
| 45 | -use niri_ipc::{ColumnDisplay, PositionChange, SizeChange}; | 45 | +use niri_ipc::{ColumnDisplay, PositionChange, SizeChange, WindowLayout}; |
| 46 | use scrolling::{Column, ColumnWidth}; | 46 | use scrolling::{Column, ColumnWidth}; |
| 47 | use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; | 47 | use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; |
| 48 | use smithay::backend::renderer::element::utils::RescaleRenderElement; | 48 | use smithay::backend::renderer::element::utils::RescaleRenderElement; |
| @@ -1742,25 +1742,30 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1742 | moving_window.chain(mon_windows) | 1742 | moving_window.chain(mon_windows) |
| 1743 | } | 1743 | } |
| 1744 | 1744 | ||
| 1745 | - pub fn with_windows(&self, mut f: impl FnMut(&W, Option<&Output>, Option<WorkspaceId>)) { | 1745 | + pub fn with_windows( |
| 1746 | + &self, | ||
| 1747 | + mut f: impl FnMut(&W, Option<&Output>, Option<WorkspaceId>, WindowLayout), | ||
| 1748 | + ) { | ||
| 1746 | if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move { | 1749 | if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move { |
| 1747 | - f(move_.tile.window(), Some(&move_.output), None); | 1750 | + // We don't fill any positions for interactively moved windows. |
| 1751 | + let layout = move_.tile.ipc_layout_template(); | ||
| 1752 | + f(move_.tile.window(), Some(&move_.output), None, layout); | ||
| 1748 | } | 1753 | } |
| 1749 | 1754 | ||
| 1750 | match &self.monitor_set { | 1755 | match &self.monitor_set { |
| 1751 | MonitorSet::Normal { monitors, .. } => { | 1756 | MonitorSet::Normal { monitors, .. } => { |
| 1752 | for mon in monitors { | 1757 | for mon in monitors { |
| 1753 | for ws in &mon.workspaces { | 1758 | for ws in &mon.workspaces { |
| 1754 | - for win in ws.windows() { | 1759 | + for (tile, layout) in ws.tiles_with_ipc_layouts() { |
| 1755 | - f(win, Some(&mon.output), Some(ws.id())); | 1760 | + f(tile.window(), Some(&mon.output), Some(ws.id()), layout); |
| 1756 | } | 1761 | } |
| 1757 | } | 1762 | } |
| 1758 | } | 1763 | } |
| 1759 | } | 1764 | } |
| 1760 | MonitorSet::NoOutputs { workspaces } => { | 1765 | MonitorSet::NoOutputs { workspaces } => { |
| 1761 | for ws in workspaces { | 1766 | for ws in workspaces { |
| 1762 | - for win in ws.windows() { | 1767 | + for (tile, layout) in ws.tiles_with_ipc_layouts() { |
| 1763 | - f(win, None, Some(ws.id())); | 1768 | + f(tile.window(), None, Some(ws.id()), layout); |
| 1764 | } | 1769 | } |
| 1765 | } | 1770 | } |
| 1766 | } | 1771 | } |
src/layout/scrolling.rsmodified+17 -1
| @@ -4,7 +4,7 @@ use std::rc::Rc; | |||
| 4 | use std::time::Duration; | 4 | use std::time::Duration; |
| 5 | 5 | ||
| 6 | use niri_config::{CenterFocusedColumn, PresetSize, Struts}; | 6 | use niri_config::{CenterFocusedColumn, PresetSize, Struts}; |
| 7 | -use niri_ipc::{ColumnDisplay, SizeChange}; | 7 | +use niri_ipc::{ColumnDisplay, SizeChange, WindowLayout}; |
| 8 | use ordered_float::NotNan; | 8 | use ordered_float::NotNan; |
| 9 | use smithay::backend::renderer::gles::GlesRenderer; | 9 | use smithay::backend::renderer::gles::GlesRenderer; |
| 10 | use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size}; | 10 | use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size}; |
| @@ -2366,6 +2366,22 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2366 | }) | 2366 | }) |
| 2367 | } | 2367 | } |
| 2368 | 2368 | ||
| 2369 | + pub fn tiles_with_ipc_layouts(&self) -> impl Iterator<Item = (&Tile<W>, WindowLayout)> { | ||
| 2370 | + self.columns | ||
| 2371 | + .iter() | ||
| 2372 | + .enumerate() | ||
| 2373 | + .flat_map(move |(col_idx, col)| { | ||
| 2374 | + col.tiles().enumerate().map(move |(tile_idx, (tile, _))| { | ||
| 2375 | + let layout = WindowLayout { | ||
| 2376 | + // Our indices are 1-based, consistent with the actions. | ||
| 2377 | + pos_in_scrolling_layout: Some((col_idx + 1, tile_idx + 1)), | ||
| 2378 | + ..tile.ipc_layout_template() | ||
| 2379 | + }; | ||
| 2380 | + (tile, layout) | ||
| 2381 | + }) | ||
| 2382 | + }) | ||
| 2383 | + } | ||
| 2384 | + | ||
| 2369 | pub(super) fn insert_hint_area( | 2385 | pub(super) fn insert_hint_area( |
| 2370 | &self, | 2386 | &self, |
| 2371 | position: InsertPosition, | 2387 | position: InsertPosition, |
src/layout/tile.rsmodified+14 -0
| @@ -2,6 +2,7 @@ use core::f64; | |||
| 2 | use std::rc::Rc; | 2 | use std::rc::Rc; |
| 3 | 3 | ||
| 4 | use niri_config::{Color, CornerRadius, GradientInterpolation}; | 4 | use niri_config::{Color, CornerRadius, GradientInterpolation}; |
| 5 | +use niri_ipc::WindowLayout; | ||
| 5 | use smithay::backend::renderer::element::{Element, Kind}; | 6 | use smithay::backend::renderer::element::{Element, Kind}; |
| 6 | use smithay::backend::renderer::gles::GlesRenderer; | 7 | use smithay::backend::renderer::gles::GlesRenderer; |
| 7 | use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; | 8 | use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; |
| @@ -688,6 +689,19 @@ impl<W: LayoutElement> Tile<W> { | |||
| 688 | loc | 689 | loc |
| 689 | } | 690 | } |
| 690 | 691 | ||
| 692 | + /// Returns a partially-filled [`WindowLayout`]. | ||
| 693 | + /// | ||
| 694 | + /// Only the sizing properties that a [`Tile`] can fill are filled. | ||
| 695 | + pub fn ipc_layout_template(&self) -> WindowLayout { | ||
| 696 | + WindowLayout { | ||
| 697 | + pos_in_scrolling_layout: None, | ||
| 698 | + tile_size: self.tile_size().into(), | ||
| 699 | + window_size: self.window().size().into(), | ||
| 700 | + tile_pos_in_workspace_view: None, | ||
| 701 | + window_offset_in_tile: self.window_loc().into(), | ||
| 702 | + } | ||
| 703 | + } | ||
| 704 | + | ||
| 691 | fn is_in_input_region(&self, mut point: Point<f64, Logical>) -> bool { | 705 | fn is_in_input_region(&self, mut point: Point<f64, Logical>) -> bool { |
| 692 | point -= self.window_loc().to_f64(); | 706 | point -= self.window_loc().to_f64(); |
| 693 | self.window.is_in_input_region(point) | 707 | self.window.is_in_input_region(point) |
src/layout/workspace.rsmodified+7 -1
| @@ -5,7 +5,7 @@ use std::time::Duration; | |||
| 5 | use niri_config::{ | 5 | use niri_config::{ |
| 6 | CenterFocusedColumn, CornerRadius, OutputName, PresetSize, Workspace as WorkspaceConfig, | 6 | CenterFocusedColumn, CornerRadius, OutputName, PresetSize, Workspace as WorkspaceConfig, |
| 7 | }; | 7 | }; |
| 8 | -use niri_ipc::{ColumnDisplay, PositionChange, SizeChange}; | 8 | +use niri_ipc::{ColumnDisplay, PositionChange, SizeChange, WindowLayout}; |
| 9 | use smithay::backend::renderer::gles::GlesRenderer; | 9 | use smithay::backend::renderer::gles::GlesRenderer; |
| 10 | use smithay::desktop::{layer_map_for_output, Window}; | 10 | use smithay::desktop::{layer_map_for_output, Window}; |
| 11 | use smithay::output::Output; | 11 | use smithay::output::Output; |
| @@ -1427,6 +1427,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1427 | floating.chain(scrolling) | 1427 | floating.chain(scrolling) |
| 1428 | } | 1428 | } |
| 1429 | 1429 | ||
| 1430 | + pub fn tiles_with_ipc_layouts(&self) -> impl Iterator<Item = (&Tile<W>, WindowLayout)> { | ||
| 1431 | + let scrolling = self.scrolling.tiles_with_ipc_layouts(); | ||
| 1432 | + let floating = self.floating.tiles_with_ipc_layouts(); | ||
| 1433 | + floating.chain(scrolling) | ||
| 1434 | + } | ||
| 1435 | + | ||
| 1430 | pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<f64, Logical>> { | 1436 | pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<f64, Logical>> { |
| 1431 | if self.floating_is_active.get() { | 1437 | if self.floating_is_active.get() { |
| 1432 | self.floating.active_tile_visual_rectangle() | 1438 | self.floating.active_tile_visual_rectangle() |
src/niri.rsmodified+2 -2
| @@ -2208,7 +2208,7 @@ impl State { | |||
| 2208 | }, | 2208 | }, |
| 2209 | ); | 2209 | ); |
| 2210 | 2210 | ||
| 2211 | - self.niri.layout.with_windows(|mapped, _, _| { | 2211 | + self.niri.layout.with_windows(|mapped, _, _, _| { |
| 2212 | let id = mapped.id().get(); | 2212 | let id = mapped.id().get(); |
| 2213 | let props = with_toplevel_role(mapped.toplevel(), |role| { | 2213 | let props = with_toplevel_role(mapped.toplevel(), |role| { |
| 2214 | gnome_shell_introspect::WindowProperties { | 2214 | gnome_shell_introspect::WindowProperties { |
| @@ -3998,7 +3998,7 @@ impl Niri { | |||
| 3998 | let mut seen = HashSet::new(); | 3998 | let mut seen = HashSet::new(); |
| 3999 | let mut output_changed = vec![]; | 3999 | let mut output_changed = vec![]; |
| 4000 | 4000 | ||
| 4001 | - self.layout.with_windows(|mapped, output, _| { | 4001 | + self.layout.with_windows(|mapped, output, _, _| { |
| 4002 | seen.insert(mapped.window.clone()); | 4002 | seen.insert(mapped.window.clone()); |
| 4003 | 4003 | ||
| 4004 | let Some(output) = output else { | 4004 | let Some(output) = output else { |
src/protocols/foreign_toplevel.rsmodified+1 -1
| @@ -93,7 +93,7 @@ pub fn refresh(state: &mut State) { | |||
| 93 | // Save the focused window for last, this way when the focus changes, we will first deactivate | 93 | // Save the focused window for last, this way when the focus changes, we will first deactivate |
| 94 | // the previous window and only then activate the newly focused window. | 94 | // the previous window and only then activate the newly focused window. |
| 95 | let mut focused = None; | 95 | let mut focused = None; |
| 96 | - state.niri.layout.with_windows(|mapped, output, _| { | 96 | + state.niri.layout.with_windows(|mapped, output, _, _| { |
| 97 | let toplevel = mapped.toplevel(); | 97 | let toplevel = mapped.toplevel(); |
| 98 | let wl_surface = toplevel.wl_surface(); | 98 | let wl_surface = toplevel.wl_surface(); |
| 99 | with_toplevel_role(toplevel, |role| { | 99 | with_toplevel_role(toplevel, |role| { |