Skip to content

Commit d14f525

Browse files
committed
add geometry info to mayland window socket
1 parent 32125e8 commit d14f525

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

mayland-comm/src/lib.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@ pub mod output {
314314
/// a mayland window
315315
#[derive(Debug, Serialize, Deserialize)]
316316
pub struct Window {
317+
/// relative window geometry
318+
///
319+
/// relative, as in relative to the workspace
320+
pub relative: window::Geometry,
321+
/// absolute window geometry
322+
///
323+
/// may be `None` if the window is on an orphaned
324+
/// workspace or no output is connected.
325+
pub absolute: Option<window::Geometry>,
326+
317327
/// the window app id
318328
///
319329
/// x11 calls this "class"
@@ -330,8 +340,11 @@ pub struct Window {
330340
pub xwayland: bool,
331341
}
332342

333-
mod window {
343+
pub mod window {
344+
//! mayland window extra info
345+
334346
use super::Window;
347+
use serde::{Deserialize, Serialize};
335348
use std::fmt::Display;
336349

337350
impl Display for Window {
@@ -342,6 +355,10 @@ mod window {
342355
writeln!(f, "window")?;
343356
}
344357

358+
let geometry = self.absolute.as_ref().unwrap_or(&self.relative);
359+
writeln!(f, " at: {},{}", geometry.x, geometry.y)?;
360+
writeln!(f, " size: {}x{}", geometry.w, geometry.h)?;
361+
345362
if let Some(app_id) = &self.app_id {
346363
writeln!(f, " app_id: {app_id:?}")?;
347364
}
@@ -356,6 +373,19 @@ mod window {
356373
Ok(())
357374
}
358375
}
376+
377+
/// the window geometry
378+
#[derive(Debug, Deserialize, Serialize)]
379+
pub struct Geometry {
380+
/// x
381+
pub x: i32,
382+
/// y
383+
pub y: i32,
384+
/// width
385+
pub w: i32,
386+
/// height
387+
pub h: i32,
388+
}
359389
}
360390

361391
/// a mayland workspace

src/comm.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,14 @@ async fn handle_client(mut stream: Async<'_, UnixStream>, state: SocketState) ->
139139
.workspaces
140140
.workspaces
141141
.values()
142-
.flat_map(|workspace| workspace.windows().map(move |window| (window, workspace)))
143-
.map(|(window, workspace)| window.comm_info(workspace, keyboard_focus))
142+
.flat_map(|workspace| {
143+
workspace
144+
.windows_geometry()
145+
.map(move |(window, geometry)| (window, geometry, workspace))
146+
})
147+
.map(|(window, geometry, workspace)| {
148+
window.comm_info(geometry, workspace, keyboard_focus)
149+
})
144150
.collect();
145151

146152
let _ = tx.send_blocking(windows);

src/layout/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl WorkspaceManager {
380380
#[derive(Debug)]
381381
pub struct Workspace {
382382
pub idx: usize,
383-
output: Option<Output>,
383+
pub output: Option<Output>,
384384

385385
tiling: Tiling,
386386
floating: Floating,

src/shell/window.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,32 @@ impl MappedWindow {
444444
/// get [`mayland_comm::Window`] info for [`mayland`]
445445
pub fn comm_info(
446446
&self,
447+
geometry: Rectangle<i32, Logical>,
447448
workspace: &Workspace,
448449
keyboard_focus: Option<&KeyboardFocusTarget>,
449450
) -> mayland_comm::Window {
450451
let active = keyboard_focus.is_some_and(|focus| focus == self);
451452

453+
let absolute = workspace.output.as_ref().map(|output| {
454+
let output_location = output.current_location();
455+
let mut absolute = geometry;
456+
absolute.loc += output_location;
457+
458+
mayland_comm::window::Geometry {
459+
x: absolute.loc.x,
460+
y: absolute.loc.y,
461+
w: absolute.size.w,
462+
h: absolute.size.h,
463+
}
464+
});
465+
466+
let relative = mayland_comm::window::Geometry {
467+
x: geometry.loc.x,
468+
y: geometry.loc.y,
469+
w: geometry.size.w,
470+
h: geometry.size.h,
471+
};
472+
452473
match self.underlying_surface() {
453474
WindowSurface::Wayland(xdg) => with_states(xdg.wl_surface(), |states| {
454475
let surface_data = states
@@ -459,6 +480,9 @@ impl MappedWindow {
459480
.unwrap();
460481

461482
mayland_comm::Window {
483+
relative,
484+
absolute,
485+
462486
app_id: surface_data.app_id.clone(),
463487
title: surface_data.title.clone(),
464488

0 commit comments

Comments
 (0)