Spike Wayland compositor, hybrid MoonBit WM, SSD decorations, and wasmtime native host
This commit is contained in:
1 parent
880ecd4102
commit
17a8a46cfd
56 files changed
+8924
-11
No files matched your search
@@ -0,0 +1,136 @@
|
||||
///| Unit tests for the pure MoonBit Window Manager engine.
|
||||
|
||||
///|
|
||||
fn mk_win(
|
||||
id : UInt64,
|
||||
floating~ : Bool = false,
|
||||
min_w~ : Int = 100,
|
||||
min_h~ : Int = 80,
|
||||
) -> WindowRecord {
|
||||
{
|
||||
id,
|
||||
app_id: "org.example.app\{id}",
|
||||
title: "App \{id}",
|
||||
geometry: { x: 0, y: 0, w: 400, h: 300 },
|
||||
floating_geometry: { x: 0, y: 0, w: 400, h: 300 },
|
||||
min_size: { w: min_w, h: min_h },
|
||||
max_size: None,
|
||||
focused: false,
|
||||
maximized: false,
|
||||
fullscreen: false,
|
||||
minimized: false,
|
||||
is_floating: floating,
|
||||
workspace: 0U,
|
||||
can_move: true,
|
||||
can_resize: true,
|
||||
can_maximize: true,
|
||||
can_minimize: true,
|
||||
can_fullscreen: true,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "work area subtracts panel exclusive zones" {
|
||||
let out : Rect = { x: 0, y: 0, w: 1280, h: 720 }
|
||||
let wa = compute_work_area(out, excl_bottom=48)
|
||||
assert_eq(wa, { x: 0, y: 0, w: 1280, h: 672 })
|
||||
}
|
||||
|
||||
///|
|
||||
test "bsp tiling splits 2 and 3 windows with gaps" {
|
||||
let wm = WmState::new(inner_gap=10, outer_gap=10)
|
||||
let wa : Rect = { x: 0, y: 0, w: 1020, h: 700 }
|
||||
ignore(wm.open_window(mk_win(1UL), wa))
|
||||
assert_eq(wm.windows[1UL].geometry, { x: 10, y: 10, w: 1000, h: 680 })
|
||||
|
||||
ignore(wm.open_window(mk_win(2UL), wa))
|
||||
// 1000 - 10 gap = 990 -> 495 + 495
|
||||
assert_eq(wm.windows[1UL].geometry, { x: 10, y: 10, w: 495, h: 680 })
|
||||
assert_eq(wm.windows[2UL].geometry, { x: 515, y: 10, w: 495, h: 680 })
|
||||
|
||||
ignore(wm.open_window(mk_win(3UL), wa))
|
||||
// Right half splits vertically: 680 - 10 = 670 -> 335 + 335
|
||||
assert_eq(wm.windows[2UL].geometry, { x: 515, y: 10, w: 495, h: 335 })
|
||||
assert_eq(wm.windows[3UL].geometry, { x: 515, y: 355, w: 495, h: 335 })
|
||||
}
|
||||
|
||||
///|
|
||||
test "closing focused window promotes MRU focus and reflows BSP" {
|
||||
let wm = WmState::new(inner_gap=10, outer_gap=10)
|
||||
let wa : Rect = { x: 0, y: 0, w: 1020, h: 700 }
|
||||
ignore(wm.open_window(mk_win(1UL), wa))
|
||||
ignore(wm.open_window(mk_win(2UL), wa))
|
||||
assert_eq(wm.focused, Some(2UL))
|
||||
|
||||
let actions = wm.close_window(2UL, wa)
|
||||
assert_eq(wm.focused, Some(1UL))
|
||||
assert_eq(wm.windows[1UL].geometry, { x: 10, y: 10, w: 1000, h: 680 })
|
||||
assert_true(actions.contains(Focus(1UL)))
|
||||
}
|
||||
|
||||
///|
|
||||
test "hybrid stacking order: tiled < floating < fullscreen" {
|
||||
let wm = WmState::new(inner_gap=8, outer_gap=8)
|
||||
let wa : Rect = { x: 0, y: 0, w: 1280, h: 672 }
|
||||
ignore(wm.open_window(mk_win(1UL, floating=false), wa))
|
||||
ignore(wm.open_window(mk_win(2UL, floating=true), wa))
|
||||
ignore(wm.open_window(mk_win(3UL, floating=false), wa))
|
||||
|
||||
let order = wm.stacking_order()
|
||||
// Tiled (1, 3) then floating (2)
|
||||
assert_eq(order, [1UL, 3UL, 2UL])
|
||||
|
||||
// Fullscreen window 1 overrides order to top and fills work_area
|
||||
ignore(wm.handle_request(1UL, Fullscreen(true), wa))
|
||||
assert_eq(wm.stacking_order(), [3UL, 2UL, 1UL])
|
||||
assert_eq(wm.windows[1UL].geometry, wa)
|
||||
}
|
||||
|
||||
///|
|
||||
test "monocle mode gives every tiled window the full padded work area" {
|
||||
let wm = WmState::new(inner_gap=8, outer_gap=12)
|
||||
let wa : Rect = { x: 0, y: 0, w: 1000, h: 600 }
|
||||
ignore(wm.open_window(mk_win(1UL), wa))
|
||||
ignore(wm.open_window(mk_win(2UL), wa))
|
||||
ignore(wm.set_layout_mode(Monocle, wa))
|
||||
let expected : Rect = { x: 12, y: 12, w: 976, h: 576 }
|
||||
assert_eq(wm.windows[1UL].geometry, expected)
|
||||
assert_eq(wm.windows[2UL].geometry, expected)
|
||||
}
|
||||
|
||||
///|
|
||||
test "hit_test distinguishes panel, client, and decoration" {
|
||||
let wm = WmState::new(inner_gap=0, outer_gap=0, titlebar_h=30, border_w=4)
|
||||
let wa : Rect = { x: 0, y: 0, w: 1280, h: 672 }
|
||||
let panel : Rect = { x: 0, y: 672, w: 1280, h: 48 }
|
||||
let w = mk_win(10UL, floating=true)
|
||||
w.geometry = { x: 100, y: 100, w: 400, h: 300 }
|
||||
ignore(wm.open_window(w, wa))
|
||||
|
||||
// Inside client
|
||||
assert_eq(wm.hit_test(150, 150, Some(panel)), Client(10UL, 50, 50))
|
||||
// Inside titlebar decoration (outer y = 100 - 30 = 70, outer x = 96)
|
||||
assert_eq(wm.hit_test(110, 80, Some(panel)), Decoration(10UL, 14, 10))
|
||||
// Inside panel
|
||||
assert_eq(wm.hit_test(20, 690, Some(panel)), ShellPanel(20, 18))
|
||||
// Outside everything
|
||||
assert_eq(wm.hit_test(10, 10, Some(panel)), HitNone)
|
||||
}
|
||||
|
||||
///|
|
||||
test "interactive drag move and resize clamps to min_size" {
|
||||
let wm = WmState::new()
|
||||
let wa : Rect = { x: 0, y: 0, w: 1280, h: 720 }
|
||||
let w = mk_win(5UL, floating=true, min_w=200, min_h=150)
|
||||
w.geometry = { x: 100, y: 100, w: 400, h: 300 }
|
||||
ignore(wm.open_window(w, wa))
|
||||
|
||||
assert_true(wm.start_drag(5UL, Move, 120, 90))
|
||||
assert_eq(wm.update_drag(170, 130), Some(SetGeometry(5UL, { x: 150, y: 140, w: 400, h: 300 })))
|
||||
wm.end_drag()
|
||||
|
||||
assert_true(wm.start_drag(5UL, ResizeSE, 550, 440))
|
||||
// Shrink by -300 -> clamped to min_w=200, min_h=150
|
||||
assert_eq(wm.update_drag(250, 140), Some(SetGeometry(5UL, { x: 150, y: 140, w: 200, h: 150 })))
|
||||
wm.end_drag()
|
||||
}
|
||||
Reference in new issue
Block a user