feat(nescope): log clamped configure requests and warn on a ping-pong

This commit is contained in:
Wanjohi
2026-10-18 15:19:23 +03:00
parent 7059c4812c
commit 4d44e7e59d
2 changed files with 26 additions and 0 deletions
+5
View File
@@ -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);
}
+21
View File
@@ -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<u32>, Option<u32>), 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<NescopeState>,
@@ -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<u32, (std::time::Instant, u32)>,
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,