- Apps open maximized on a touchscreen whose short side is under 720px. Restore gives a floating window that fits the screen. - Maximized windows can't be dragged or resized. - Dialogs (xdg_toplevel.set_parent) open floating and centered, and stay above their app when it is activated. - Under tiling, the last used app is drawn on top. - Add transient_for to WmState and make inner_work_area and fit_rect public for the compositor. - Tests cover maximized opening, dialog stacking, drag suppression and restore. - Document the handset window behavior in docs/handset.md.
274 lines
11 KiB
MoonBit
274 lines
11 KiB
MoonBit
///| Touch (touch.mbt): wl_touch for fingers on an app's content, the pointer everywhere else.
|
|
|
|
///|
|
|
/// A 540x1170 handset with one window, whose client has the pointer and (with `touch`) wl_touch.
|
|
fn touch_setup(tag : String, touch : Bool) -> (@host.ChandraCompositor, TestWaylandClient, UInt, UInt) raise {
|
|
let path = "/tmp/wayland-moon-touch-" + tag + "-" + @sys.getpid().to_string() + ".sock"
|
|
let comp = @host.ChandraCompositor::new(path, @scene.ThemeTokens::moon_night(), 540, 1170).unwrap()
|
|
comp.handle_input(Touch(Present), 1U)
|
|
let (c, shm, surf, xdg, _, _) = open_and_configure_client(comp, path, "T", "t")
|
|
commit_shm_frame(comp, c, shm, surf, xdg, 1UL)
|
|
let seat = bind_global(c, 2U, "wl_seat", 7U)
|
|
let get = fn(op : UInt) {
|
|
let id = c.alloc_id()
|
|
let w = @wayland.WireWriter::new()
|
|
w.u32(id)
|
|
c.send(w.finish_msg(seat, op))
|
|
id
|
|
}
|
|
let ptr = get(0U)
|
|
let t = if touch { get(2U) } else { 0U }
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
ignore(drain_msgs(c))
|
|
(comp, c, ptr, t)
|
|
}
|
|
|
|
///|
|
|
fn window_middle(comp : @host.ChandraCompositor) -> (Double, Double) {
|
|
let g = comp.windows.get(1UL).unwrap().geometry
|
|
((g.x + g.w / 2).to_double(), (g.y + g.h / 2).to_double())
|
|
}
|
|
|
|
///|
|
|
test "a finger on an app that listens goes to it as a touch, and no pointer is faked" {
|
|
let (comp, c, ptr, t) = touch_setup("client", true)
|
|
let (x, y) = window_middle(comp)
|
|
comp.handle_input(Touch(Down(0, x, y)), 10U)
|
|
comp.handle_input(Touch(Motion(0, x, y - 60.0)), 20U)
|
|
comp.handle_input(Touch(Down(1, x + 40.0, y)), 25U) // a second finger
|
|
comp.handle_input(Touch(Up(1)), 28U)
|
|
comp.handle_input(Touch(Up(0)), 30U)
|
|
let msgs = drain_msgs(c)
|
|
assert_eq(
|
|
msgs.iter().filter(m => m.0 == t).map(m => m.1).to_array(),
|
|
[0U, 3U, 2U, 3U, 0U, 3U, 1U, 3U, 1U, 3U], // down motion down up up, each with its frame
|
|
)
|
|
assert_false(msgs.iter().any(m => m.0 == ptr && m.1 != 1U))
|
|
// Holding still is the app's to time: no right click.
|
|
comp.handle_input(Touch(Down(0, x, y)), 40U)
|
|
@sys.sleep_ms(520)
|
|
comp.step()
|
|
let msgs = drain_msgs(c)
|
|
assert_false(msgs.iter().any(m => m.0 == ptr))
|
|
// The screen turning off (or rotating) cancels.
|
|
comp.handle_input(Touch(Cancel), 50U)
|
|
comp.handle_input(Touch(Up(0)), 51U)
|
|
let msgs = drain_msgs(c)
|
|
assert_true(has_msg(msgs, t, 4U))
|
|
assert_false(has_msg(msgs, t, 1U))
|
|
comp.close()
|
|
}
|
|
|
|
///|
|
|
test "an app that doesn't listen to touches gets the pointer: tap, drag and hold" {
|
|
let (comp, c, ptr, _) = touch_setup("pointer", false)
|
|
let (x, y) = window_middle(comp)
|
|
let buttons = fn() { drain_msgs(c).iter().filter(m => m.0 == ptr && m.1 == 3U).count() }
|
|
comp.handle_input(Touch(Down(0, x, y)), 10U)
|
|
assert_eq(buttons(), 0)
|
|
comp.handle_input(Touch(Up(0)), 20U)
|
|
assert_eq(buttons(), 2) // pressed and released
|
|
comp.handle_input(Touch(Down(0, x, y)), 30U)
|
|
comp.handle_input(Touch(Motion(0, x + 5.0, y)), 31U)
|
|
assert_eq(buttons(), 0)
|
|
comp.handle_input(Touch(Motion(0, x + 30.0, y)), 32U)
|
|
assert_eq(buttons(), 1)
|
|
comp.handle_input(Touch(Up(0)), 33U)
|
|
assert_eq(buttons(), 1)
|
|
comp.handle_input(Touch(Down(0, x, y)), 40U)
|
|
assert_true(comp.wake_timeout(5000) <= 500)
|
|
@sys.sleep_ms(520)
|
|
comp.step()
|
|
assert_eq(buttons(), 2) // the right button
|
|
comp.handle_input(Touch(Up(0)), 41U)
|
|
assert_eq(buttons(), 0)
|
|
comp.close()
|
|
}
|
|
|
|
///|
|
|
test "the panel takes a finger as before, and the seat says it has a touchscreen" {
|
|
let (comp, c, _, t) = touch_setup("panel", true)
|
|
comp.handle_input(Touch(Down(0, 20.0, 1160.0)), 10U)
|
|
comp.handle_input(Touch(Up(0)), 20U)
|
|
assert_false(drain_msgs(c).iter().any(m => m.0 == t))
|
|
let (out, ok) = comp.control_command("input-touch down 0 10")
|
|
assert_false(ok)
|
|
assert_true(out[0].has_prefix("error usage"))
|
|
comp.close()
|
|
}
|
|
|
|
///|
|
|
test "a window moved by its own title bar follows the finger that asked for it" {
|
|
let (comp, c, shm, surf, xdg, tl) = csd_setup("touchmove")
|
|
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
|
|
ignore(gtk_frame(comp, c, shm, surf, xdg, tl))
|
|
let seat = bind_global(c, 2U, "wl_seat", 7U)
|
|
let t = c.alloc_id()
|
|
let w = @wayland.WireWriter::new()
|
|
w.u32(t)
|
|
c.send(w.finish_msg(seat, 2U))
|
|
for _i = 0; _i < 4; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
let before = comp.windows.get(1UL).unwrap().geometry
|
|
let r = comp.windows.get(1UL).unwrap().client_rect()
|
|
let (px, py) = ((r.x + r.w / 2).to_double(), (r.y + 15).to_double())
|
|
comp.handle_input(Touch(Down(0, px, py)), 10U)
|
|
ignore(drain_msgs(c))
|
|
let mv = @wayland.WireWriter::new()
|
|
mv.u32(0U)
|
|
mv.u32(1U)
|
|
c.send(mv.finish_msg(tl, 5U))
|
|
for _i = 0; _i < 4; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
assert_true(comp.wm.drag is Some(_))
|
|
assert_true(has_msg(drain_msgs(c), t, 4U)) // its touch is cancelled
|
|
comp.handle_input(Touch(Motion(0, px + 60.0, py + 40.0)), 12U)
|
|
comp.handle_input(Touch(Up(0)), 13U)
|
|
let after = comp.windows.get(1UL).unwrap().geometry
|
|
assert_eq((after.x - before.x, after.y - before.y), (60, 40))
|
|
assert_true(comp.wm.drag is None)
|
|
comp.close()
|
|
}
|
|
|
|
///|
|
|
test "a finger scrolls the launcher's list: a drag moves it, a flick keeps it going, a tap launches" {
|
|
let comp = osk_comp("touchlist", enable_osk=false)
|
|
load_handset_modules(comp)
|
|
let data = "/tmp/chandra-touch-apps-" + @sys.getpid().to_string()
|
|
ignore(@sys.mkdir_p(data + "/applications"))
|
|
for i in 0..<30 {
|
|
ignore(
|
|
@sys.write_file_bytes(
|
|
data + "/applications/touch" + i.to_string() + ".desktop",
|
|
@sys.str_to_utf8_bytes(
|
|
"[Desktop Entry]\nType=Application\nName=Touch " + i.to_string() + "\nExec=true\n",
|
|
),
|
|
),
|
|
)
|
|
}
|
|
comp.shell.xdg_dirs = { ..comp.shell.xdg_dirs, data_home: data, data_dirs: [] }
|
|
comp.shell.toggle_launcher()
|
|
comp.shell.toggle_launcher()
|
|
comp.shell.toggle_launcher()
|
|
for _ in 0..<10 {
|
|
@sys.sleep_ms(30)
|
|
ignore(comp.compose_frame())
|
|
}
|
|
let pr = comp.shell.slot_popup_rect(comp.shell.slot_of("launcher"))
|
|
let st = comp.shell.launcher_state
|
|
assert_eq(comp.shell.apps.length(), 30)
|
|
let x = (pr.x + pr.w - 120).to_double()
|
|
let y = (pr.y + 300).to_double()
|
|
// Past the threshold the list follows the finger by pixels.
|
|
comp.handle_input(Touch(Down(0, x, y)), 10U)
|
|
comp.handle_input(Touch(Motion(0, x, y - 10.0)), 20U)
|
|
assert_eq((st.scroll, st.offset), (0, 0))
|
|
comp.handle_input(Touch(Motion(0, x, y - 60.0)), 30U)
|
|
assert_eq(st.scroll * 46 + st.offset, 60)
|
|
comp.handle_input(Touch(Motion(0, x, y - 50.0)), 300U)
|
|
assert_eq(st.scroll * 46 + st.offset, 50)
|
|
// Held still, then up: it stays, and nothing was launched.
|
|
comp.handle_input(Touch(Motion(0, x, y - 50.0)), 900U)
|
|
comp.handle_input(Touch(Up(0)), 910U)
|
|
assert_true(st.open)
|
|
assert_eq(st.scroll * 46 + st.offset, 50)
|
|
// A flick goes on after the lift, and a finger stops it without launching.
|
|
comp.handle_input(Touch(Down(0, x, y)), 1000U)
|
|
comp.handle_input(Touch(Motion(0, x, y - 40.0)), 1020U)
|
|
comp.handle_input(Touch(Motion(0, x, y - 80.0)), 1040U)
|
|
comp.handle_input(Touch(Up(0)), 1045U)
|
|
let at = st.scroll * 46 + st.offset
|
|
assert_eq(at, 130)
|
|
assert_true(comp.has_timed_work())
|
|
@sys.sleep_ms(30)
|
|
comp.step()
|
|
assert_true(st.scroll * 46 + st.offset > at)
|
|
comp.handle_input(Touch(Down(0, x, y)), 1100U)
|
|
let at = st.scroll * 46 + st.offset
|
|
comp.handle_input(Touch(Up(0)), 1120U)
|
|
@sys.sleep_ms(30)
|
|
comp.step()
|
|
assert_eq(st.scroll * 46 + st.offset, at)
|
|
assert_true(st.open)
|
|
// Never past the ends.
|
|
comp.handle_input(Touch(Down(0, x, y)), 2000U)
|
|
comp.handle_input(Touch(Motion(0, x, y + 5000.0)), 2010U)
|
|
comp.handle_input(Touch(Motion(0, x, y + 5000.0)), 2900U)
|
|
comp.handle_input(Touch(Up(0)), 2910U)
|
|
assert_eq((st.scroll, st.offset), (0, 0))
|
|
comp.close()
|
|
}
|
|
|
|
///|
|
|
test "on a handset apps open maximized, dialogs float above their app, and a drag leaves them be" {
|
|
let (comp, _, _, _) = touch_setup("maximized", false)
|
|
let one = comp.windows.get(1UL).unwrap()
|
|
assert_true(one.maximized)
|
|
assert_true(one.geometry.w > 500 && one.geometry.h > 900)
|
|
// Opened with its one size: the client was never asked for another.
|
|
let path = "/tmp/wayland-moon-touch-maximized-" + @sys.getpid().to_string() + ".sock"
|
|
let (c2, shm, surf, xdg, top, _) = open_and_configure_client(comp, path, "U", "u")
|
|
let two = comp.windows.get(2UL).unwrap()
|
|
assert_true(two.maximized)
|
|
assert_eq((c2.configured_w, c2.configured_h), (two.geometry.w, two.geometry.h))
|
|
commit_shm_frame(comp, c2, shm, surf, xdg, 2UL)
|
|
assert_eq(comp.wm.stacking_order(), [1UL, 2UL])
|
|
// A drag on the title bar doesn't move it.
|
|
let g = two.geometry
|
|
let (tx, ty) = ((g.x + 60).to_double(), (g.y - 12).to_double())
|
|
comp.handle_input(Touch(Down(0, tx, ty)), 10U)
|
|
comp.handle_input(Touch(Motion(0, tx, ty + 90.0)), 20U)
|
|
comp.handle_input(Touch(Up(0)), 30U)
|
|
assert_eq(two.geometry, g)
|
|
// A dialog of the second: same client, set_parent before its first commit.
|
|
let objs = fn(target : UInt, op : UInt, arg : UInt?) {
|
|
let id = c2.alloc_id()
|
|
let w = @wayland.WireWriter::new()
|
|
w.u32(id)
|
|
match arg {
|
|
Some(a) => w.u32(a)
|
|
None => ()
|
|
}
|
|
c2.send(w.finish_msg(target, op))
|
|
id
|
|
}
|
|
let reg = objs(1U, 1U, None)
|
|
let dsurf = objs(bind_global(c2, reg, "wl_compositor", 5U), 0U, None)
|
|
let dxdg = objs(bind_global(c2, reg, "xdg_wm_base", 5U), 2U, Some(dsurf))
|
|
let dtop = objs(dxdg, 1U, None)
|
|
let w = @wayland.WireWriter::new()
|
|
w.u32(top)
|
|
c2.send(w.finish_msg(dtop, 1U))
|
|
c2.send(@wayland.WireWriter::new().finish_msg(dsurf, 6U))
|
|
for _i = 0; _i < 5; _i = _i + 1 {
|
|
comp.step()
|
|
@sys.sleep_ms(2)
|
|
}
|
|
let d = comp.windows.get(3UL).unwrap()
|
|
assert_false(d.maximized)
|
|
assert_true(d.geometry.x >= 0 && d.geometry.x + d.geometry.w <= 540)
|
|
// Switching apps raises the app, and going back brings the dialog along.
|
|
ignore(comp.wm.handle_request(1UL, @wm.WindowRequest::Activate, comp.work_area))
|
|
assert_eq(comp.wm.stacking_order(), [2UL, 3UL, 1UL])
|
|
ignore(comp.wm.handle_request(2UL, @wm.WindowRequest::Activate, comp.work_area))
|
|
assert_eq(comp.wm.stacking_order(), [1UL, 2UL, 3UL])
|
|
// Restore: a floating window inside the screen.
|
|
ignore(comp.wm.handle_request(2UL, @wm.WindowRequest::Maximize(false), comp.work_area))
|
|
let r = comp.wm.windows.get(2UL).unwrap().geometry
|
|
assert_true(r.x >= 0 && r.x + r.w <= 540 && r.h < g.h)
|
|
// Under Tiling too (the windows go into the tree), the last used app is on top.
|
|
ignore(comp.wm.handle_request(2UL, @wm.WindowRequest::Maximize(true), comp.work_area))
|
|
comp.set_layout_mode(@wm.LayoutMode::Floating)
|
|
comp.set_layout_mode(@wm.LayoutMode::Tiling)
|
|
ignore(comp.wm.handle_request(1UL, @wm.WindowRequest::Activate, comp.work_area))
|
|
assert_eq(comp.wm.stacking_order(), [3UL, 2UL, 1UL])
|
|
comp.close()
|
|
}
|