From 4d44e7e59d8fc5fa3ab089c33e38ce0bc9c99cbb Mon Sep 17 00:00:00 2001 From: Wanjohi Date: Sun, 18 Oct 2026 15:19:23 +0300 Subject: [PATCH] feat(nescope): log clamped configure requests and warn on a ping-pong --- apps/nescope/src/handlers.rs | 5 +++++ apps/nescope/src/state.rs | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/apps/nescope/src/handlers.rs b/apps/nescope/src/handlers.rs index 24173aa2..7c5f6886 100644 --- a/apps/nescope/src/handlers.rs +++ b/apps/nescope/src/handlers.rs @@ -543,12 +543,17 @@ impl XwmHandler for CalloopData { if window.is_override_redirect() { return; } + let (req_w, req_h) = (w, h); let cur = window.geometry(); let (x, y, w, h) = crate::state::clamp_to_output( (cur.loc.x, cur.loc.y, cur.size.w, cur.size.h), (w, h), (self.state.width as i32, self.state.height as i32), ); + let asked = (req_w, req_h); + if req_w.is_some_and(|v| v as i32 != w) || req_h.is_some_and(|v| v as i32 != h) { + self.state.note_clamp(window.window_id(), asked, (w, h)); + } let geo = Rectangle::new((x, y).into(), (w, h).into()); let _ = window.configure(geo); } diff --git a/apps/nescope/src/state.rs b/apps/nescope/src/state.rs index 31c80276..4915d636 100644 --- a/apps/nescope/src/state.rs +++ b/apps/nescope/src/state.rs @@ -110,6 +110,24 @@ pub fn clamp_to_output( (x, y, w, h) } +impl NescopeState { + /// Say a request was clamped. A window that keeps asking is fighting the + /// configure: warn once when the run passes 50 inside 5 seconds. + pub fn note_clamp(&mut self, id: u32, asked: (Option, Option), got: (i32, i32)) { + let now = std::time::Instant::now(); + let run = self.clamp_runs.entry(id).or_insert((now, 0)); + if now.duration_since(run.0) > std::time::Duration::from_secs(5) { + *run = (now, 0); + } + run.1 += 1; + let n = run.1; + tracing::debug!(window = id, ?asked, clamped = ?got, repeats = n, "configure_request clamped"); + if n == 50 { + tracing::warn!(window = id, ?asked, clamped = ?got, "window keeps asking past the output: configure ping-pong?"); + } + } +} + pub struct CalloopData { pub state: NescopeState, pub display: Display, @@ -258,6 +276,8 @@ pub struct NescopeState { /// counted for, ref(d-0036): a client's window can shrink the output /// below it, never grow it past. pub launch_size: (u32, u32), + /// Per X11 window: when its run of clamped requests began and how many. + pub clamp_runs: std::collections::HashMap, pub fps: u32, // ── Lifecycle ───────────────────────────────────────────────────────── @@ -395,6 +415,7 @@ impl NescopeState { width, height, launch_size: (width, height), + clamp_runs: std::collections::HashMap::new(), fps, loop_handle, game_launched: false,