srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/wayland/src/udev/platform.rs
diff options
context:
space:
mode:
authorsrdusr <[email protected]>2025-09-26 22:07:00 +0200
committersrdusr <[email protected]>2025-09-26 22:07:00 +0200
commit9a9aa8fe9d4f4f9b15860b45244e695942c90afd (patch)
treea7a8289731d49713caeaf06f023ab04f78cc663c /crates/wayland/src/udev/platform.rs
parentb46dfa56504f62ecf969914dfed106bf587c4c4a (diff)
downloadsrdwm-9a9aa8fe9d4f4f9b15860b45244e695942c90afd.tar.gz
srdwm-9a9aa8fe9d4f4f9b15860b45244e695942c90afd.zip
Fake (headless) monitors, and fix new windows all opening in one spot
Two independent pieces landed together this pass - both real, both scoped, see docs/TODO.md for the full narrative on each: Fake monitors: a genuinely independent, additional wl_output with no DRM connector/CRTC behind it at all - distinct from srd.monitor.split (divides one real output's own placement rectangle). Researched niri's own Headless backend first (cloned at ~/reference-wms/niri): its render() never actually composites anything, a no-render stub for that project's test suite only. This one is real: it renders whatever is placed on it, on demand, whenever a zwlr_screencopy_manager_v1 client asks for a frame. New crates/wayland/src/udev/virtual_heads.rs (create/remove a real Output + global, render-on-demand for screencopy, integrated into platform.rs's monitors() as a genuine srdwm_core::Monitor so core placement/workspace code needs zero special-casing). New IPC/CLI: srd dispatch create fake-monitor <name> <w>x<h> / remove fake-monitor <name>. Core-side request queue in crates/core/src/manager/fake_monitor.rs. Placement bug, root-caused and fixed: every new window opened alone landed in the exact same spot, "not at all like Windows" (reported live). SmartPlacement::place tried a grid cell first, and grid's own cell count is existing.len() + 1 - with nothing else open (opening one app at a time, the ordinary case), that's always 1, so a 1x1 grid returns the same single cell forever regardless of session history. Cascade had the same bug in a second form (its own step was existing.len() % max_steps, also always 0 with nothing open). Fixed: WindowManager::next_cascade_step (a Cell - add_window's own target_monitor stays borrowed across the call) advances on every real placement and is never reset by a window closing; place() now skips grid entirely when nothing else is open, going straight to cascade, since grid's real job (dividing space among concurrent windows) has nothing to divide when there's no concurrency. Full workspace build/test/clippy clean (223 core / 141 wayland / 29 platform / 24 ctl / 28 config / 10 x11 tests, 0 failed, 0 clippy warnings), built and installed.
Diffstat (limited to 'crates/wayland/src/udev/platform.rs')
-rw-r--r--crates/wayland/src/udev/platform.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/crates/wayland/src/udev/platform.rs b/crates/wayland/src/udev/platform.rs
index 9023cb9..b09bd4b 100644
--- a/crates/wayland/src/udev/platform.rs
+++ b/crates/wayland/src/udev/platform.rs
@@ -162,6 +162,7 @@ impl UdevPlatform {
card: card.clone(),
renderer,
heads,
+ virtual_heads: Vec::new(),
active: true,
pointer_pos: (width as f64 / 2.0, height as f64 / 2.0).into(),
secondary_cursors: std::collections::HashMap::new(),
@@ -621,6 +622,22 @@ impl Platform for UdevPlatform {
for (pid, window) in pin_requests {
self.state.set_virtual_pointer_pin(pid, window);
}
+ // Applies any `srd dispatch create fake-monitor`/`remove fake-
+ // monitor` IPC requests queued since the last poll - see
+ // `crates/wayland/src/udev/virtual_heads.rs`'s own module doc
+ // comment.
+ let create_fake_monitor_requests = self.state.wm.borrow_mut().drain_create_fake_monitor_requests();
+ for (name, width, height) in create_fake_monitor_requests {
+ if let Err(e) = self.state.create_virtual_head(name.clone(), width as i32, height as i32) {
+ log::warn!("fake monitor: failed to create {name}: {e}");
+ }
+ }
+ let remove_fake_monitor_requests = self.state.wm.borrow_mut().drain_remove_fake_monitor_requests();
+ for name in remove_fake_monitor_requests {
+ if let Err(e) = self.state.remove_virtual_head(&name) {
+ log::warn!("fake monitor: failed to remove {name}: {e}");
+ }
+ }
// Throttled the same way and for the same underlying reason as the
// `ipc.poll()` call above - this is the *other*, larger half of
// this cycle's needless work at the dead-pipe-driven spin rate.
@@ -648,6 +665,12 @@ impl Platform for UdevPlatform {
const RENDER_INTERVAL: Duration = Duration::from_millis(8);
if self.last_render.elapsed() >= RENDER_INTERVAL {
self.last_render = Instant::now();
+ // Before `render_udev_frame` drains `self.screencopy_pending`
+ // for real heads - see `service_virtual_head_captures`'s own
+ // doc comment for why a fake-monitor capture must never reach
+ // that drain at all (it would wait forever for a real page-
+ // flip that will never come).
+ self.state.service_virtual_head_captures();
self.state.render_udev_frame();
}
Ok(self.pending.borrow_mut().drain(..).collect())
@@ -826,6 +849,23 @@ impl Platform for UdevPlatform {
next_id += 1;
}
}
+ // Fake monitors (`virtual_heads.rs`) get the same treatment a real
+ // head does, minus the layer-shell exclusive-zone/reservation math
+ // (nothing binds a bar/dock to one in this phase, so there is
+ // never a zone to shrink `usable` by) and minus `srd.monitor.
+ // split` (a fake monitor already *is* exactly the size it was
+ // created at - splitting it further is a real, separate ask this
+ // phase doesn't attempt). `full == usable == maximize`, `scale`
+ // always `1.0` - see `VirtualHead`'s own doc comment for why.
+ for head in &udev.virtual_heads {
+ let full = srdwm_core::Rect::new(head.location.x, head.location.y, head.size.0 as u32, head.size.1 as u32);
+ let mut m = srdwm_core::Monitor::new(next_id, head.name.clone(), full);
+ m.full_geometry = full;
+ m.maximize_geometry = full;
+ m.primary = false;
+ out.push(m);
+ next_id += 1;
+ }
Ok(out)
}