Windows: on a handset, apps open maximized and dialogs float above
Deploy to the handset / build-and-deploy (push) Successful in 2m7s
CI / test (push) Failing after 2m42s

- 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.
This commit is contained in:
nandi committed 2026-11-29 23:11:34 -08:00
1 parent 7029c92e6e
commit 5c83cdaa22
5 files changed
+148 -10

No files matched your search

+26 -3
View File
@@ -780,6 +780,12 @@ fn ChandraCompositor::configure_window(self : ChandraCompositor, win : HostWindo
)
}
///| A phone's screen: a touchscreen, and the short side (whichever way it is turned) too narrow
/// for windows side by side.
fn ChandraCompositor::is_handset(self : ChandraCompositor) -> Bool {
self.server.touch && self.output_w.min(self.output_h) < 720
}
///|
pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
self.flush_configures()
@@ -811,8 +817,17 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
geo_y: 0,
}
self.windows.set(wid, win)
// On a handset apps open maximized, and float so the last used one is on top. Dialogs
// float above their app.
let handset = self.is_handset()
let dialog = self.server.toplevel_has_parent(wid)
match self.server.toplevel_parent(wid) {
Some(p) => self.wm.transient_for.set(wid, p)
None => ()
}
win.maximized = handset && !dialog
// An app whose window was last left somewhere reopens there, floating, kept on screen.
let saved = self.shell.saved_window(app_id)
let saved = if handset && dialog { None } else { self.shell.saved_window(app_id) }
let g : @wm.Rect = match saved {
Some((sx, sy, sw, sh)) => {
let w = if sw > self.output_w { self.output_w } else { sw }
@@ -823,6 +838,14 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
}
None => { x: 100, y: 100, w: 640, h: 480 }
}
// (Maximized, this is the size Restore goes back to.)
let g = if handset {
let a = self.wm.inner_work_area(self.work_area)
let r = @wm.fit_rect(g, a)
if dialog { { ..r, x: a.x + (a.w - r.w) / 2, y: a.y + (a.h - r.h) / 2 } } else { r }
} else {
g
}
win.geometry = @scene.Rect::new(g.x, g.y, g.w, g.h)
let rec : @wm.WindowRecord = {
id: wid,
@@ -833,10 +856,10 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
min_size: { w: min_w, h: min_h },
max_size: None,
focused: true,
maximized: false,
maximized: win.maximized,
fullscreen: false,
minimized: false,
is_floating: saved is Some(_),
is_floating: handset || saved is Some(_),
workspace: 0U,
can_move: true,
can_resize: true,
+66
View File
@@ -205,3 +205,69 @@ test "a finger scrolls the launcher's list: a drag moves it, a flick keeps it go
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()
}
+22 -1
View File
@@ -175,6 +175,8 @@ struct ToplevelState {
mut opened_sent : Bool
/// xdg_toplevel.set_parent named another toplevel: a dialog or tool window of its app.
mut has_parent : Bool
/// That toplevel's window.
mut parent_win : UInt64?
/// Set for xdg_popup surfaces (they live in `toplevels` so input routing is shared).
popup_parent : UInt64?
/// The last xdg_toplevel.configure sent: size, states and its xdg_surface serial (0 = none).
@@ -1310,6 +1312,7 @@ fn WaylandServer::dispatch_msg(
min_h: 120,
opened_sent: false,
has_parent: false,
parent_win: None,
popup_parent: None,
cfg_w: 0,
cfg_h: 0,
@@ -1378,6 +1381,7 @@ fn WaylandServer::dispatch_msg(
min_h: 1,
opened_sent: true,
has_parent: true,
parent_win: Some(parent_wid),
popup_parent: Some(parent_wid),
cfg_w: 0,
cfg_h: 0,
@@ -1481,7 +1485,12 @@ fn WaylandServer::dispatch_msg(
events.push(ToplevelClosed(wid))
} else if opcode == 1U {
// set_parent(parent: object or null)
tl.has_parent = reader.u32() != 0U
let parent = reader.u32()
tl.has_parent = parent != 0U
tl.parent_win = match c.objects.get(parent) {
Some(ObjXdgToplevel(w)) => Some(w)
_ => None
}
} else if opcode == 2U {
// set_title
tl.title = reader.str()
@@ -1767,6 +1776,18 @@ pub fn WaylandServer::toplevel_has_parent(self : WaylandServer, win_id : UInt64)
}
}
///| The window a dialog belongs to (xdg_toplevel.set_parent).
pub fn WaylandServer::toplevel_parent(self : WaylandServer, win_id : UInt64) -> UInt64? {
match self.win_client(win_id) {
Some((c, _)) =>
match c.toplevels.get(win_id) {
Some(tl) => tl.parent_win
None => None
}
None => None
}
}
///| Send xdg_toplevel.configure + xdg_surface.configure to a client window.
pub fn WaylandServer::send_toplevel_configure(
self : WaylandServer,
+4
View File
@@ -12,6 +12,10 @@ Chandra includes KMS/libinput/compositor adaptations tailored for mainline Linux
- **Icon desktop default:** Portrait handset layouts prioritize the touch-friendly icon desktop launcher aesthetic.
- **Compact panel layout:** Panel items (`launcher`, `dock`, `session-settings`, `network`, `battery`, `clock-digital`, `screenshot`, `rotate`, `osk`) size compactly so all controls fit cleanly within `540px` portrait width without clipping, with fuel-gauge support (e.g. `bq27411-0`).
## Windows
- **Apps open maximized** on a handset (a touchscreen whose short side is under `720` logical pixels). Restore gives a floating window that fits the screen. Dialogs open floating, centered, and stay above their app. A maximized window can't be dragged out of place.
## Touch Input & On-Screen Keyboard
- **Touch goes to apps as touch (`wl_touch`):** a finger on an app's own content is the app's: it scrolls with a thumb, flings, pinches and long-presses as that app does ([`compositor/host/touch.mbt`](../compositor/host/touch.mbt)). The seat only says it has a touchscreen when libinput finds one. If the app answers a touch with a window move, resize or drag and drop, its touch is cancelled and the finger drags from there.
+30 -6
View File
@@ -143,6 +143,8 @@ pub(all) struct WmState {
mut border_w : Int
mut cascade_step : Int
mut drag : DragSession?
/// Dialogs and the window each belongs to: a floating dialog is raised with its window.
transient_for : Map[UInt64, UInt64]
}
///|
@@ -163,6 +165,7 @@ pub fn WmState::new(
border_w,
cascade_step: 0,
drag: None,
transient_for: {},
}
}
@@ -385,7 +388,7 @@ fn push_top(arr : Array[UInt64], id : UInt64) -> Unit {
}
///|
fn WmState::inner_work_area(self : WmState, work_area : Rect) -> Rect {
pub fn WmState::inner_work_area(self : WmState, work_area : Rect) -> Rect {
let g = self.outer_gap
let w = if work_area.w > 2 * g { work_area.w - 2 * g } else { work_area.w }
let h = if work_area.h > 2 * g { work_area.h - 2 * g } else { work_area.h }
@@ -509,6 +512,18 @@ fn WmState::set_focus(self : WmState, id : UInt64?) -> Array[WmAction] {
push_mru_front(ws.mru, nid)
if w.is_floating {
push_top(ws.floating, nid)
// Its dialogs stay above it. One pass over the order as it was, so a client naming
// dialogs in a circle can't loop.
let raised = [nid]
for id in ws.floating.copy() {
match self.transient_for.get(id) {
Some(p) if id != nid && raised.contains(p) => {
push_top(ws.floating, id)
raised.push(id)
}
_ => ()
}
}
}
actions.push(Focus(nid))
actions.push(Raise(nid))
@@ -561,7 +576,8 @@ pub fn WmState::open_window(
}
push_mru_front(ws.mru, win.id)
let actions : Array[WmAction] = []
if auto_float {
// A window that opens maximized gets its one size from the relayout.
if auto_float && !win.maximized {
actions.push(SetGeometry(win.id, win.geometry))
}
for a in self.relayout(win.workspace, work_area) {
@@ -586,6 +602,7 @@ pub fn WmState::close_window(
let ws_id = win.workspace
let ws = self.ensure_workspace(ws_id)
ignore(self.windows.remove(id))
self.transient_for.remove(id)
ws.tree = remove_leaf(ws.tree, id)
remove_id(ws.floating, id)
remove_id(ws.mru, id)
@@ -803,7 +820,7 @@ pub fn WmState::stacking_order(self : WmState) -> Array[UInt64] {
}
collect_tree(ws.tree, order, ws.fullscreen, self.windows)
// Maximized tiled windows are drawn above their neighbours.
// Maximized tiled windows are drawn above their neighbours, the last used one on top.
let below : Array[UInt64] = []
let above : Array[UInt64] = []
for id in order {
@@ -812,6 +829,13 @@ pub fn WmState::stacking_order(self : WmState) -> Array[UInt64] {
None => below.push(id)
}
}
let rank = fn(id : UInt64) {
match ws.mru.search(id) {
Some(i) => -i
None => -ws.mru.length()
}
}
above.sort_by((a, b) => rank(a).compare(rank(b)))
order.clear()
order.append(below)
order.append(above)
@@ -903,7 +927,7 @@ pub fn WmState::float_window(
}
}
///|
///| Start moving or resizing a window. A maximized or fullscreen window stays where it is.
pub fn WmState::start_drag(
self : WmState,
win_id : UInt64,
@@ -913,7 +937,7 @@ pub fn WmState::start_drag(
) -> Bool {
match self.windows.get(win_id) {
Some(win) =>
if !win.fullscreen {
if !win.fullscreen && !win.maximized {
self.drag = Some({
win_id,
mode,
@@ -1090,7 +1114,7 @@ test "split handles: divider position, drag, and row gap leaves room for the tit
}
///| Keep a floating rectangle inside `area`: shrunk to fit, then moved back on screen.
fn fit_rect(r : Rect, area : Rect) -> Rect {
pub fn fit_rect(r : Rect, area : Rect) -> Rect {
let w = if r.w > area.w { area.w } else { r.w }
let h = if r.h > area.h { area.h } else { r.h }
let x = clamp_int(r.x, area.x, area.x + area.w - w)