Skip to content

Commit

Permalink
Add a workspace list to IPC messages
Browse files Browse the repository at this point in the history
  • Loading branch information
TheZoq2 committed Jul 2, 2024
1 parent 7b6fa12 commit 0e16272
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
4 changes: 3 additions & 1 deletion niri-ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down Expand Up @@ -523,6 +523,8 @@ pub struct Workspace {
pub output: Option<String>,
/// Whether the workspace is currently active on its output.
pub is_active: bool,
/// The windows currently on this workspace
pub windows: Vec<Window>
}

impl FromStr for WorkspaceReferenceArg {
Expand Down
40 changes: 23 additions & 17 deletions src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<XdgToplevelSurfaceData>()
.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) => {
Expand Down Expand Up @@ -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::<XdgToplevelSurfaceData>()
.unwrap()
.lock()
.unwrap();

niri_ipc::Window {
title: role.title.clone(),
app_id: role.app_id.clone(),
}
})
}
14 changes: 13 additions & 1 deletion src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ 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;
use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
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;
Expand Down Expand Up @@ -2387,8 +2388,11 @@ impl<W: LayoutElement> Layout<W> {
}
}
}
}

impl Layout<Mapped> {
pub fn ipc_workspaces(&self) -> Vec<niri_ipc::Workspace> {
info!("Responding to ipc_workspaces");
match &self.monitor_set {
MonitorSet::Normal {
monitors,
Expand All @@ -2404,6 +2408,10 @@ impl<W: LayoutElement> Layout<W> {
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(),
})
}
}
Expand All @@ -2418,6 +2426,10 @@ impl<W: LayoutElement> Layout<W> {
name: ws.name.clone(),
output: None,
is_active: false,
windows: ws
.windows()
.map(|mapped| smithay_window_to_ipc(&mapped.window))
.collect(),
})
.collect(),
}
Expand Down

0 comments on commit 0e16272

Please sign in to comment.