srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/wayland
diff options
context:
space:
mode:
Diffstat (limited to 'crates/wayland')
-rw-r--r--crates/wayland/src/protocols/compositor.rs7
-rw-r--r--crates/wayland/src/state/geometry.rs58
-rw-r--r--crates/wayland/src/state/lifecycle.rs9
-rw-r--r--crates/wayland/src/state/mod.rs8
-rw-r--r--crates/wayland/src/udev/platform.rs1
-rw-r--r--crates/wayland/src/winit/connect.rs1
6 files changed, 83 insertions, 1 deletions
diff --git a/crates/wayland/src/protocols/compositor.rs b/crates/wayland/src/protocols/compositor.rs
index f7e7b74..e2868e4 100644
--- a/crates/wayland/src/protocols/compositor.rs
+++ b/crates/wayland/src/protocols/compositor.rs
@@ -83,6 +83,13 @@ impl CompositorHandler for CompState {
if let Some(w) = self.id_to_window.get(&id) {
w.on_commit();
}
+ // See `Window::size_is_provisional`'s own doc comment: before
+ // anything below reads `Window::geometry` (`redraw_decoration_
+ // buffer`, `sync_geometry`), give a window still waiting on its
+ // own first real size a chance to adopt it from what `on_commit`
+ // just recomputed, rather than keep rendering/configuring
+ // against the guessed placeholder for one more round-trip.
+ self.adopt_provisional_size(id);
// See `content_epoch`'s doc comment: this is the only per-commit
// signal the udev backend's rounded-corner mask cache has to
// invalidate itself, since content can change every frame,
diff --git a/crates/wayland/src/state/geometry.rs b/crates/wayland/src/state/geometry.rs
index 3d201dd..b8629bc 100644
--- a/crates/wayland/src/state/geometry.rs
+++ b/crates/wayland/src/state/geometry.rs
@@ -392,10 +392,19 @@ impl CompState {
!caught_up && sent_at.elapsed() < CONFIGURE_THROTTLE_TIMEOUT
});
if size_changed && !throttled {
+ // See `Window::size_is_provisional`'s own doc comment:
+ // the very first configure for a window whose size was
+ // never a real decision - just `Window::new`'s/a
+ // backend's own hardcoded guess - tells the client to
+ // pick its own size (`state.size = None`) instead of
+ // forcing this one on it. `last_synced_size` having no
+ // entry yet is exactly "this is that first configure";
+ // checked before the `insert` just below overwrites it.
+ let let_client_choose = self.provisional_size.contains(&id) && !self.last_synced_size.contains_key(&id);
self.last_synced_size.insert(id, size);
self.pending_size_configure.insert(id, (size, Instant::now()));
top.with_pending_state(|state| {
- state.size = Some(size.into());
+ state.size = if let_client_choose { None } else { Some(size.into()) };
// No configure from this compositor, ever, set any
// `xdg_toplevel` state bit at all before this --
// confirmed by grepping the whole crate for
@@ -507,4 +516,51 @@ impl CompState {
self.resync_stacking_order();
}
}
+
+ /// Called from `CompositorHandler::commit`, right after `w.on_commit()`
+ /// - the first time a window still in `provisional_size` commits a
+ /// real, non-empty buffer, adopts the client's own chosen content size
+ /// into `Window::geometry` instead of leaving `add_window`'s guessed
+ /// placeholder in place. A no-op once `provisional_size` no longer
+ /// names this window (the ordinary case, checked first, so every other
+ /// commit pays only one `HashSet` lookup).
+ ///
+ /// Position is left exactly where `SmartPlacement` put it - only
+ /// clamped so a client that picked a bigger size than the guess can't
+ /// end up hanging off its monitor's right/bottom edge - since the
+ /// guessed size was only ever wrong about *size*; the cascade/grid
+ /// position it computed is still a perfectly good place for a window
+ /// of any size to open.
+ pub(crate) fn adopt_provisional_size(&mut self, id: WindowId) {
+ if !self.provisional_size.contains(&id) {
+ return;
+ }
+ let Some(dwindow) = self.id_to_window.get(&id) else { return };
+ // Logical points, same as `xdg_toplevel::configure`'s own `size`
+ // (see `sync_geometry`'s doc comment on that) - converted to this
+ // compositor's physical-pixel `Rect` space below via the window's
+ // own monitor scale, the same conversion `sync_geometry` does in
+ // reverse.
+ let content = dwindow.geometry();
+ if content.size.w <= 0 || content.size.h <= 0 {
+ // Compositor/role-only commit, no real buffer attached yet --
+ // wait for the commit that actually has one.
+ return;
+ }
+ self.provisional_size.remove(&id);
+ let mut wm = self.wm.borrow_mut();
+ let Some(w) = wm.window(id) else { return };
+ let scale = wm.monitors().iter().find(|m| m.id == w.monitor).map(|m| m.scale).unwrap_or(1.0);
+ let monitor_geometry = wm.monitors().iter().find(|m| m.id == w.monitor).map(|m| m.geometry);
+ let band = if w.decorated { TITLEBAR_HEIGHT } else { 0 };
+ let width = ((content.size.w as f64 * scale).round() as u32).max(srdwm_core::placement::MIN_WINDOW_WIDTH);
+ let height = ((content.size.h as f64 * scale).round() as u32).max(srdwm_core::placement::MIN_WINDOW_HEIGHT) + band;
+ let Some(w) = wm.window_mut(id) else { return };
+ w.geometry.width = width;
+ w.geometry.height = height;
+ if let Some(monitor) = monitor_geometry {
+ w.geometry.x = w.geometry.x.min(monitor.right() - width as i32).max(monitor.x);
+ w.geometry.y = w.geometry.y.min(monitor.bottom() - height as i32).max(monitor.y);
+ }
+ }
}
diff --git a/crates/wayland/src/state/lifecycle.rs b/crates/wayland/src/state/lifecycle.rs
index 1749a3c..1afa738 100644
--- a/crates/wayland/src/state/lifecycle.rs
+++ b/crates/wayland/src/state/lifecycle.rs
@@ -10,6 +10,15 @@ impl CompState {
w.app_id = with_toplevel_app_id(toplevel.wl_surface()).unwrap_or_default();
w.geometry = srdwm_core::Rect::new(0, 0, 800, 600 + TITLEBAR_HEIGHT as i32 as u32);
wm.add_window(w);
+ // See `Window::size_is_provisional`'s own doc comment: only
+ // when `add_window` actually used the guessed `800x600` above
+ // (not a remembered size, a rule's own `geometry` action, or a
+ // maximize/phone-mode fill) does the client get to pick its own
+ // size instead - `sync_geometry`/`adopt_provisional_size` are
+ // what actually act on membership here.
+ if wm.window(id).is_some_and(|w| w.size_is_provisional) {
+ self.provisional_size.insert(id);
+ }
// Starts the open-slide tween (see `WindowAnim`'s doc comment):
// the window's first `sync_geometry` call below will see this,
// register the tween, and place it here - a few pixels below
diff --git a/crates/wayland/src/state/mod.rs b/crates/wayland/src/state/mod.rs
index 629b58c..f39edcc 100644
--- a/crates/wayland/src/state/mod.rs
+++ b/crates/wayland/src/state/mod.rs
@@ -586,6 +586,14 @@ pub(crate) struct CompState {
/// motion event of every drag, which is what made moving a window
/// stutter. Only a real size change now does either.
pub(crate) last_synced_size: HashMap<WindowId, (i32, i32)>,
+ /// Windows whose `Window::size_is_provisional` was `true` at creation
+ /// and whose client hasn't sent a real, non-empty content commit yet --
+ /// see that field's own doc comment. `sync_geometry` sends `size: None`
+ /// (let the client pick) instead of forcing this guessed size for the
+ /// one configure sent while a window is in this set; `commit()` removes
+ /// it and adopts the client's own real first size into `Window::
+ /// geometry` the moment one arrives.
+ pub(crate) provisional_size: HashSet<WindowId>,
/// A size-changing `xdg_toplevel.configure` that's been sent but not
/// yet reflected in the client's own real committed content size --
/// `(size requested, when it was sent)`. `sync_geometry` won't send
diff --git a/crates/wayland/src/udev/platform.rs b/crates/wayland/src/udev/platform.rs
index d7132ee..732fbc2 100644
--- a/crates/wayland/src/udev/platform.rs
+++ b/crates/wayland/src/udev/platform.rs
@@ -269,6 +269,7 @@ impl UdevPlatform {
border_side_buffers: HashMap::new(),
color_filter_buffers: HashMap::new(),
last_synced_size: HashMap::new(),
+ provisional_size: HashSet::new(),
pending_size_configure: HashMap::new(),
pending: pending.clone(),
bound_keys: Rc::new(bound_keys.iter().cloned().collect::<HashSet<_>>()),
diff --git a/crates/wayland/src/winit/connect.rs b/crates/wayland/src/winit/connect.rs
index 39eda5a..4c6954b 100644
--- a/crates/wayland/src/winit/connect.rs
+++ b/crates/wayland/src/winit/connect.rs
@@ -181,6 +181,7 @@ impl WaylandPlatform {
border_side_buffers: HashMap::new(),
color_filter_buffers: HashMap::new(),
last_synced_size: HashMap::new(),
+ provisional_size: HashSet::new(),
pending_size_configure: HashMap::new(),
pending: pending.clone(),
bound_keys: Rc::new(bound_keys.iter().cloned().collect()),