GTK windows (Gajim, GNOME apps) resize from their shadow and all four edges
CI / test (push) Successful in 3m44s

GTK draws no border, only a shadow, and resizes only from a press in that
shadow, which Chandra never hands to the client. Chandra's own zones were
~4px wide around the visible edge and there was none on the top edge, so
Gajim (GTK 4) looked unresizable. Client-decorated windows now get zones
that reach up to 12px into the shadow (GTK's own handle size, at least 6px)
plus 3px over their edge, with 16px corners, top edge included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiu4r7mEXBdKY6cgv6
This commit is contained in:
Claude committed 2026-11-26 02:48:22 +00:00
1 parent b4f7149c72
commit fa932f9ac0
2 files changed
+148

No files matched your search

+85
View File
@@ -1208,6 +1208,79 @@ fn ChandraCompositor::window_at(self : ChandraCompositor, x : Int, y : Int) -> (
None
}
///| How far a client-decorated window's resize zones reach out past its visible edge, at most:
/// GTK puts its resize handles in its shadow (12px, `RESIZE_HANDLE_SIZE` in gtkwindow.c).
let csd_grip_out : Int = 12
///| ... and at least, for a client with a thin or no shadow.
let csd_grip_min : Int = 6
///| ... and how far in over the client's own pixels (its header bar and borders).
let csd_grip_in : Int = 3
///| Corner zones: this far along each edge from a corner.
let csd_grip_corner : Int = 16
///| The resize zone a client-decorated window has at (x, y), if any. GTK (Gajim, GNOME apps)
/// draws no border at all, only a shadow, and only resizes from a press in that shadow, which
/// Chandra doesn't hand to the client: the shadow (up to 12px of it) plus a few pixels of the
/// window's own edge resize it from Chandra instead, on all four sides and corners.
fn csd_resize_zone(win : HostWindow, x : Int, y : Int) -> @wm.DragMode? {
let c = win.client_rect()
// The shadow the client draws on each side (buffer pixels around its window geometry).
let (bw, bh) = match win.surface {
Some(s) => (s.width, s.height)
None => (c.w, c.h)
}
let reach = fn(shadow : Int) {
if shadow > csd_grip_out {
csd_grip_out
} else if shadow < csd_grip_min {
csd_grip_min
} else {
shadow
}
}
let ol = reach(win.geo_x)
let ot = reach(win.geo_y)
let or_ = reach(bw - win.geo_x - c.w)
let ob = reach(bh - win.geo_y - c.h)
let l = c.x
let t = c.y
let r = c.x + c.w
let b = c.y + c.h
if x < l - ol || x >= r + or_ || y < t - ot || y >= b + ob {
return None
}
let on_l = x < l + csd_grip_in
let on_r = x >= r - csd_grip_in
let on_t = y < t + csd_grip_in
let on_b = y >= b - csd_grip_in
let near_l = x < l + csd_grip_corner
let near_r = x >= r - csd_grip_corner
let near_t = y < t + csd_grip_corner
let near_b = y >= b - csd_grip_corner
if (on_t && near_l) || (on_l && near_t) {
Some(@wm.DragMode::ResizeNW)
} else if (on_t && near_r) || (on_r && near_t) {
Some(@wm.DragMode::ResizeNE)
} else if (on_b && near_l) || (on_l && near_b) {
Some(@wm.DragMode::ResizeSW)
} else if (on_b && near_r) || (on_r && near_b) {
Some(@wm.DragMode::ResizeSE)
} else if on_t {
Some(@wm.DragMode::ResizeN)
} else if on_b {
Some(@wm.DragMode::ResizeS)
} else if on_l {
Some(@wm.DragMode::ResizeW)
} else if on_r {
Some(@wm.DragMode::ResizeE)
} else {
None
}
}
///| Resize zone under (x, y) on a floating window: its corners (12px) and left/right/bottom
/// edges. The first window whose outer box contains the point decides; tiled windows resize
/// through the dividers instead.
@@ -1221,6 +1294,18 @@ fn ChandraCompositor::resize_at(
while i >= 0 {
let id = order[i]
match (self.windows.get(id), self.wm.windows.get(id)) {
(Some(win), Some(rec)) if win.csd && !win.fullscreen => {
let floating = rec.is_floating && !rec.maximized
match csd_resize_zone(win, x, y) {
Some(mode) if floating => return Some((id, mode))
_ => {
let c = win.client_rect()
if x >= c.x && x < c.x + c.w && y >= c.y && y < c.y + c.h {
return None // over the window itself: windows below don't count
}
}
}
}
(Some(win), Some(rec)) => {
let g = win.geometry
let l = g.x
+63
View File
@@ -257,3 +257,66 @@ test "a GTK 3 window asking through org_kde_kwin_server_decoration gets Chandra'
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
assert_true(comp.windows.get(1UL).unwrap().csd)
}
///|
test "a GTK window resizes from its shadow and from every edge, top included" {
// Gajim (GTK 4) couldn't be resized: GTK only resizes from a press in its shadow, which
// Chandra keeps, and Chandra's own zones were a few pixels wide with none on the top edge.
let (comp, c, shm, surf, xdg, tl) = csd_setup("grips")
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
let drag = fn(px : Int, py : Int, dx : Int, dy : Int) -> @scene.Rect raise {
comp.handle_input(@nested.InputEvent::PointerMove(px.to_double(), py.to_double()), 30U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 31U)
assert_true(comp.wm.drag is Some(_))
comp.handle_input(@nested.InputEvent::PointerMove((px + dx).to_double(), (py + dy).to_double()), 32U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 33U)
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
comp.windows.get(1UL).unwrap().client_rect()
}
// 10px out into the shadow on the right: wider.
let r0 = comp.windows.get(1UL).unwrap().client_rect()
let r1 = drag(r0.x + r0.w + 10, r0.y + r0.h / 2, 30, 0)
assert_eq((r1.x, r1.y, r1.w, r1.h), (r0.x, r0.y, r0.w + 30, r0.h))
// The top edge (the header bar's top 2px): taller, growing upwards.
let r2 = drag(r1.x + r1.w / 2, r1.y + 1, 0, -20)
assert_eq((r2.x, r2.y, r2.w, r2.h), (r1.x, r1.y - 20, r1.w, r1.h + 20))
// 8px out past the bottom-left corner: both at once.
let r3 = drag(r2.x - 8, r2.y + r2.h + 8, -10, 10)
assert_eq((r3.x, r3.y, r3.w, r3.h), (r2.x - 10, r2.y, r2.w + 10, r2.h + 10))
// Further out than GTK's 12px handles is the desktop again, and the header bar itself
// (below its top edge) still goes to the client.
comp.handle_input(@nested.InputEvent::PointerMove((r3.x + r3.w + 20).to_double(), (r3.y + 100).to_double()), 40U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 41U)
assert_true(comp.wm.drag is None)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 42U)
comp.handle_input(@nested.InputEvent::PointerMove((r3.x + r3.w / 2).to_double(), (r3.y + 15).to_double()), 43U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 44U)
assert_true(comp.wm.drag is None)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 45U)
}
///|
test "a maximized GTK window has no resize zones, and restores to its size" {
let (comp, c, shm, surf, xdg, tl) = csd_setup("max")
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
let before = comp.windows.get(1UL).unwrap().client_rect()
// The header bar's maximize button: xdg_toplevel.set_maximized.
c.send(@wayland.WireWriter::new().finish_msg(tl, 9U))
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
let win = comp.windows.get(1UL).unwrap()
assert_true(win.maximized)
let m = win.client_rect()
assert_true(m.w > before.w && m.h > before.h)
comp.handle_input(@nested.InputEvent::PointerMove((m.x + m.w - 1).to_double(), (m.y + m.h / 2).to_double()), 50U)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 51U)
assert_true(comp.wm.drag is None)
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 52U)
// ... and unset_maximized puts it back.
c.send(@wayland.WireWriter::new().finish_msg(tl, 10U))
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
let after = comp.windows.get(1UL).unwrap().client_rect()
assert_false(comp.windows.get(1UL).unwrap().maximized)
assert_eq((after.w, after.h), (before.w, before.h))
}