From e9a93cae11a4f3d305fe358489c4de8217938fc3 Mon Sep 17 00:00:00 2001 From: TheZoq2 Date: Tue, 2 Jul 2024 19:15:55 +0200 Subject: [PATCH] Add a workspace list to IPC messages --- niri-ipc/src/lib.rs | 4 +++- src/ipc/server.rs | 40 +++++++++++++++++++++++----------------- src/layout/mod.rs | 13 ++++++++++++- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index 4db883e..9727037 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -491,7 +491,7 @@ pub enum Transform { } /// Toplevel window. -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Eq, PartialEq, Serialize, Deserialize, Debug, Clone)] pub struct Window { /// Title, if set. pub title: Option, @@ -523,6 +523,8 @@ pub struct Workspace { pub output: Option, /// Whether the workspace is currently active on its output. pub is_active: bool, + /// The windows currently on this workspace + pub windows: Vec, } impl FromStr for WorkspaceReferenceArg { diff --git a/src/ipc/server.rs b/src/ipc/server.rs index 7987ca5..028a4ac 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -146,23 +146,12 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply { Response::Outputs(ipc_outputs) } Request::FocusedWindow => { - let window = ctx.ipc_focused_window.lock().unwrap().clone(); - let window = window.map(|window| { - let wl_surface = window.toplevel().expect("no X11 support").wl_surface(); - with_states(wl_surface, |states| { - let role = states - .data_map - .get::() - .unwrap() - .lock() - .unwrap(); - - niri_ipc::Window { - title: role.title.clone(), - app_id: role.app_id.clone(), - } - }) - }); + let window = ctx + .ipc_focused_window + .lock() + .unwrap() + .as_ref() + .map(smithay_window_to_ipc); Response::FocusedWindow(window) } Request::Action(action) => { @@ -237,3 +226,20 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply { Ok(response) } + +pub fn smithay_window_to_ipc(window: &smithay::desktop::Window) -> niri_ipc::Window { + let wl_surface = window.toplevel().expect("no X11 support").wl_surface(); + with_states(wl_surface, |states| { + let role = states + .data_map + .get::() + .unwrap() + .lock() + .unwrap(); + + niri_ipc::Window { + title: role.title.clone(), + app_id: role.app_id.clone(), + } + }) +} diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 8fabba6..4ac204f 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -46,6 +46,7 @@ use smithay::utils::{Logical, Point, Scale, Serial, Size, Transform}; pub use self::monitor::MonitorRenderElement; use self::monitor::{Monitor, WorkspaceSwitch}; use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Workspace}; +use crate::ipc::server::smithay_window_to_ipc; use crate::niri_render_elements; use crate::render_helpers::renderer::NiriRenderer; use crate::render_helpers::snapshot::RenderSnapshot; @@ -53,7 +54,7 @@ use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderEleme use crate::render_helpers::texture::TextureBuffer; use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; use crate::utils::{output_size, round_logical_in_physical_max1, ResizeEdge}; -use crate::window::ResolvedWindowRules; +use crate::window::{Mapped, ResolvedWindowRules}; pub mod closing_window; pub mod focus_ring; @@ -2387,7 +2388,9 @@ impl Layout { } } } +} +impl Layout { pub fn ipc_workspaces(&self) -> Vec { match &self.monitor_set { MonitorSet::Normal { @@ -2404,6 +2407,10 @@ impl Layout { name: workspace.name.clone(), output: Some(monitor.output.name()), is_active: monitor.active_workspace_idx == idx, + windows: workspace + .windows() + .map(|mapped| smithay_window_to_ipc(&mapped.window)) + .collect(), }) } } @@ -2418,6 +2425,10 @@ impl Layout { name: ws.name.clone(), output: None, is_active: false, + windows: ws + .windows() + .map(|mapped| smithay_window_to_ipc(&mapped.window)) + .collect(), }) .collect(), }