CI / test (push) Failing after 16s
Two left presses on the same title bar within 400ms and 4px of each other toggle maximize, like the title-bar button. A press that turned into a drag never starts a double-click. A tiled window now floats only once the pointer actually moves, so clicking or double-clicking its title bar leaves it in (and restores it to) its tile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjF2tD2UuaXLzFzrvV
132 lines
4.5 KiB
MoonBit
132 lines
4.5 KiB
MoonBit
///| Double-clicking a title bar toggles maximize; single clicks and drags keep working.
|
|
|
|
///|
|
|
fn two_windows(tag : String) -> @host.ChandraCompositor {
|
|
let socket_path = "/tmp/wayland-moon-" +
|
|
tag +
|
|
"-" +
|
|
@sys.getpid().to_string() +
|
|
".sock"
|
|
let theme = @scene.ThemeTokens::moon_night()
|
|
let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
|
ignore(open_and_configure_client(comp, socket_path, "A", "a"))
|
|
ignore(open_and_configure_client(comp, socket_path, "B", "b"))
|
|
ignore(comp.compose_frame())
|
|
comp
|
|
}
|
|
|
|
///|
|
|
/// Press and release the left button at (x, y), at time t (press) and t + 1 (release).
|
|
fn title_click(
|
|
comp : @host.ChandraCompositor,
|
|
x : Int32,
|
|
y : Int32,
|
|
t : UInt32,
|
|
) -> Unit {
|
|
comp.handle_input(
|
|
@nested.InputEvent::PointerMove(x.to_double(), y.to_double()),
|
|
t,
|
|
)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), t)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), t + 1U)
|
|
}
|
|
|
|
///|
|
|
fn maximized(comp : @host.ChandraCompositor, wid : UInt64) -> Bool {
|
|
comp.wm.windows.get(wid).unwrap().maximized
|
|
}
|
|
|
|
///|
|
|
fn floating(comp : @host.ChandraCompositor, wid : UInt64) -> Bool {
|
|
comp.wm.windows.get(wid).unwrap().is_floating
|
|
}
|
|
|
|
///|
|
|
test "double-clicking a tiled window's title bar maximizes it, and again restores its tile" {
|
|
let comp = two_windows("dbl-tiled")
|
|
let g0 = comp.windows.get(2UL).unwrap().geometry
|
|
let (x, y) = (g0.x + g0.w / 3, g0.y - 16)
|
|
// A single click focuses but neither floats nor maximizes the window.
|
|
title_click(comp, x, y, 100U)
|
|
assert_false(floating(comp, 2UL))
|
|
assert_false(maximized(comp, 2UL))
|
|
assert_eq(comp.windows.get(2UL).unwrap().geometry, g0)
|
|
// The second click, 200ms later and 2px off, makes it a double-click.
|
|
title_click(comp, x + 2, y + 1, 300U)
|
|
assert_true(maximized(comp, 2UL))
|
|
assert_false(floating(comp, 2UL))
|
|
let gm = comp.windows.get(2UL).unwrap().geometry
|
|
assert_true(gm.w > g0.w)
|
|
// Double-click the maximized title bar: back in its tile.
|
|
let (mx, my) = (gm.x + gm.w / 3, gm.y - 16)
|
|
title_click(comp, mx, my, 2000U)
|
|
title_click(comp, mx, my, 2100U)
|
|
assert_false(maximized(comp, 2UL))
|
|
assert_eq(comp.windows.get(2UL).unwrap().geometry, g0)
|
|
}
|
|
|
|
///|
|
|
test "double-clicking a floating window's title bar restores its old size and place" {
|
|
let comp = two_windows("dbl-float")
|
|
let g = comp.windows.get(2UL).unwrap().geometry
|
|
// Float it by dragging its title bar 100px left and 30px down.
|
|
comp.handle_input(
|
|
@nested.InputEvent::PointerMove(
|
|
(g.x + 60).to_double(),
|
|
(g.y - 16).to_double(),
|
|
),
|
|
10U,
|
|
)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, true), 11U)
|
|
comp.handle_input(
|
|
@nested.InputEvent::PointerMove(
|
|
(g.x - 40).to_double(),
|
|
(g.y + 14).to_double(),
|
|
),
|
|
12U,
|
|
)
|
|
comp.handle_input(@nested.InputEvent::PointerButton(272U, false), 13U)
|
|
assert_true(floating(comp, 2UL))
|
|
let g0 = comp.windows.get(2UL).unwrap().geometry
|
|
assert_eq(g0.x, g.x - 100)
|
|
assert_eq(g0.y, g.y + 30)
|
|
// A click right after the drag, on the spot where it was dropped, is not a double-click.
|
|
title_click(comp, g.x - 40, g.y + 14, 14U)
|
|
assert_false(maximized(comp, 2UL))
|
|
// A real double-click maximizes it…
|
|
let (x, y) = (g0.x + 50, g0.y - 16)
|
|
title_click(comp, x, y, 1000U)
|
|
title_click(comp, x, y, 1150U)
|
|
assert_true(maximized(comp, 2UL))
|
|
// …and another one puts it back where and as big as it was.
|
|
let gm = comp.windows.get(2UL).unwrap().geometry
|
|
title_click(comp, gm.x + 50, gm.y - 16, 3000U)
|
|
title_click(comp, gm.x + 50, gm.y - 16, 3100U)
|
|
assert_false(maximized(comp, 2UL))
|
|
assert_eq(comp.windows.get(2UL).unwrap().geometry, g0)
|
|
}
|
|
|
|
///|
|
|
test "slow or far-apart title-bar clicks are not a double-click" {
|
|
let comp = two_windows("dbl-slow")
|
|
let g0 = comp.windows.get(2UL).unwrap().geometry
|
|
let (x, y) = (g0.x + g0.w / 3, g0.y - 16)
|
|
// Too slow: 500ms between the presses.
|
|
title_click(comp, x, y, 100U)
|
|
title_click(comp, x, y, 600U)
|
|
assert_false(maximized(comp, 2UL))
|
|
// Too far apart: 20px.
|
|
title_click(comp, x, y, 2000U)
|
|
title_click(comp, x + 20, y, 2100U)
|
|
assert_false(maximized(comp, 2UL))
|
|
// On two different windows.
|
|
let g1 = comp.windows.get(1UL).unwrap().geometry
|
|
title_click(comp, g1.x + 40, g1.y - 16, 4000U)
|
|
title_click(comp, x, y, 4100U)
|
|
assert_false(maximized(comp, 1UL))
|
|
assert_false(maximized(comp, 2UL))
|
|
// Nothing above floated a window.
|
|
assert_false(floating(comp, 1UL))
|
|
assert_false(floating(comp, 2UL))
|
|
}
|