- timefmt.hhmm12 + render_digital(hour12=); compositor panel shows '7:51 PM' (wasm clock component keeps 24h by default) - wp_cursor_shape_v1: server lets clients pick their cursor; nested window forwards the shape to the host. Launcher button/entries show a hand, the search field a text cursor, client windows what the client asked for. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a63f65806d
commit
59ea224d38
8 files changed
+146
-3
No files matched your search
@@ -92,6 +92,7 @@ fn main {
|
||||
for ev in n.take_input() {
|
||||
comp.handle_input(ev, now_ms)
|
||||
}
|
||||
n.set_cursor_shape(comp.desired_cursor())
|
||||
if n.frame_ready() {
|
||||
n.present(comp.present_to_gfx(gfx_ctx))
|
||||
}
|
||||
|
||||
@@ -502,3 +502,16 @@ pub fn MoonPlasmaCompositor::handle_input(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Cursor shape (wp_cursor_shape_v1 value) for the current pointer position: shell UI
|
||||
/// decides over the launcher; a client window decides inside its client area; otherwise default.
|
||||
pub fn MoonPlasmaCompositor::desired_cursor(self : MoonPlasmaCompositor) -> UInt {
|
||||
let shell_shape = self.shell.cursor_at(self.ptr_x.to_int(), self.ptr_y.to_int())
|
||||
if shell_shape != 0U {
|
||||
return shell_shape
|
||||
}
|
||||
match self.ptr_win {
|
||||
Some(w) => self.server.client_cursor_shape(w)
|
||||
None => 1U
|
||||
}
|
||||
}
|
||||
@@ -78,15 +78,36 @@ test "host input reaches the focused client and the launcher popup opens" {
|
||||
assert_true(has_msg(msgs, ptr_id, 3U)) // button
|
||||
assert_true(has_msg(msgs, kbd_id, 3U)) // wl_keyboard.key
|
||||
|
||||
// Cursor: a client that asks for a text cursor gets it inside its window...
|
||||
let shape_mgr = bind_global(c, reg_id, "wp_cursor_shape_manager_v1", 1U)
|
||||
let shape_dev = c.alloc_id()
|
||||
let w3 = @wayland.WireWriter::new()
|
||||
w3.u32(shape_dev)
|
||||
w3.u32(ptr_id)
|
||||
c.send(w3.finish_msg(shape_mgr, 1U))
|
||||
let w4 = @wayland.WireWriter::new()
|
||||
w4.u32(1U) // serial
|
||||
w4.u32(9U) // text
|
||||
c.send(w4.finish_msg(shape_dev, 1U))
|
||||
for _i = 0; _i < 5; _i = _i + 1 {
|
||||
comp.step()
|
||||
@sys.sleep_ms(2)
|
||||
}
|
||||
assert_eq(comp.desired_cursor(), 9U)
|
||||
|
||||
// Launcher: click the button -> popup opens and swallows keys.
|
||||
ignore(comp.compose_frame()) // lays out the panel
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(60.0, 700.0), 20U)
|
||||
assert_eq(comp.desired_cursor(), 4U) // ...but the launcher button always shows a hand
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 21U)
|
||||
comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 22U)
|
||||
assert_true(comp.shell.popup_open())
|
||||
comp.handle_input(@nested.InputEvent::Key(30U, true), 23U)
|
||||
let after = drain_msgs(c)
|
||||
assert_false(has_msg(after, kbd_id, 3U)) // swallowed by the launcher
|
||||
// Off the shell and off any window: default arrow.
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(1270.0, 5.0), 25U)
|
||||
assert_eq(comp.desired_cursor(), 1U)
|
||||
// Escape closes it.
|
||||
comp.handle_input(@nested.InputEvent::Key(1U, true), 24U)
|
||||
assert_false(comp.shell.popup_open())
|
||||
|
||||
@@ -17,6 +17,10 @@ pub(all) struct NestedWindow {
|
||||
fds : Array[Int]
|
||||
mut keymap : Bytes
|
||||
mut keyboard_id : UInt
|
||||
mut shape_mgr_id : UInt
|
||||
mut shape_dev_id : UInt
|
||||
mut enter_serial : UInt
|
||||
mut shape_applied : UInt
|
||||
fd : Int
|
||||
rx : Array[Byte]
|
||||
globals : Map[String, (UInt, UInt)]
|
||||
@@ -168,6 +172,14 @@ fn NestedWindow::dispatch(
|
||||
w.u32(id)
|
||||
self.send(w.finish_msg(self.seat_id, 0U))
|
||||
self.pointer_id = id
|
||||
if self.shape_mgr_id != 0U {
|
||||
let dev = self.alloc()
|
||||
let wd = @wayland.WireWriter::new()
|
||||
wd.u32(dev)
|
||||
wd.u32(id)
|
||||
self.send(wd.finish_msg(self.shape_mgr_id, 1U))
|
||||
self.shape_dev_id = dev
|
||||
}
|
||||
}
|
||||
if (caps & 2U) != 0U && self.keyboard_id == 0U {
|
||||
let id = self.alloc()
|
||||
@@ -209,7 +221,8 @@ fn NestedWindow::dispatch(
|
||||
} else if self.pointer_id != 0U && obj == self.pointer_id {
|
||||
match op {
|
||||
0U => {
|
||||
let _serial = r.u32()
|
||||
self.enter_serial = r.u32()
|
||||
self.shape_applied = 0U // host resets the cursor on enter
|
||||
let _surf = r.u32()
|
||||
self.px = r.i32().to_double() / 256.0
|
||||
self.py = r.i32().to_double() / 256.0
|
||||
@@ -282,6 +295,10 @@ pub fn NestedWindow::open(
|
||||
fds: [],
|
||||
keymap: Bytes::from_array([]),
|
||||
keyboard_id: 0U,
|
||||
shape_mgr_id: 0U,
|
||||
shape_dev_id: 0U,
|
||||
enter_serial: 0U,
|
||||
shape_applied: 0U,
|
||||
rx: [],
|
||||
globals: {},
|
||||
live_buffers: {},
|
||||
@@ -313,6 +330,7 @@ pub fn NestedWindow::open(
|
||||
self.shm_id = self.bind("wl_shm", 1U)
|
||||
self.wm_id = self.bind("xdg_wm_base", 2U)
|
||||
self.seat_id = self.bind("wl_seat", 5U)
|
||||
self.shape_mgr_id = self.bind("wp_cursor_shape_manager_v1", 1U)
|
||||
if self.comp_id == 0U || self.shm_id == 0U || self.wm_id == 0U {
|
||||
println("nested: host compositor lacks wl_compositor/wl_shm/xdg_wm_base")
|
||||
return None
|
||||
@@ -442,3 +460,16 @@ pub fn NestedWindow::close(self : NestedWindow) -> Unit {
|
||||
pub fn NestedWindow::frame_ready(self : NestedWindow) -> Bool {
|
||||
!self.frame_pending && !self.closed
|
||||
}
|
||||
|
||||
///| Ask the host to show cursor `shape` (wp_cursor_shape_v1 enum value) over our
|
||||
/// window. No-op if unchanged, unsupported by the host, or the pointer is outside.
|
||||
pub fn NestedWindow::set_cursor_shape(self : NestedWindow, shape : UInt) -> Unit {
|
||||
if self.shape_dev_id == 0U || self.enter_serial == 0U || shape == self.shape_applied {
|
||||
return
|
||||
}
|
||||
let w = @wayland.WireWriter::new()
|
||||
w.u32(self.enter_serial)
|
||||
w.u32(shape)
|
||||
self.send(w.finish_msg(self.shape_dev_id, 1U))
|
||||
self.shape_applied = shape
|
||||
}
|
||||
@@ -199,6 +199,24 @@ fn DesktopShell::launch(self : DesktopShell, id : String) -> Result[Unit, String
|
||||
}
|
||||
}
|
||||
|
||||
///| wp_cursor_shape_v1 value for the shell UI under (x, y): 4 pointer (hand) over the
|
||||
/// launcher button and popup entries, 9 text over the search field, else 0 (not shell-specific).
|
||||
pub fn DesktopShell::cursor_at(self : DesktopShell, x : Int, y : Int) -> UInt {
|
||||
if inside(self.launcher_rect, x, y) {
|
||||
4U
|
||||
} else if self.launcher_state.open && inside(self.popup_rect, x, y) {
|
||||
if self.launcher_state.hover >= 0 {
|
||||
4U
|
||||
} else if y - self.popup_rect.y < 52 {
|
||||
9U
|
||||
} else {
|
||||
1U
|
||||
}
|
||||
} else {
|
||||
0U
|
||||
}
|
||||
}
|
||||
|
||||
///| Pointer press at (x, y). Returns true when the shell consumed it.
|
||||
pub fn DesktopShell::pointer_down(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
let launch = fn(id : String) { self.launch(id) }
|
||||
@@ -275,7 +293,7 @@ pub fn DesktopShell::render(
|
||||
let size = @ui.size(p.w, p.h)
|
||||
let local : Array[@types.DrawOp] = match p.id {
|
||||
"launcher" => @launcher.render_button(size, tokens, self.launcher_state)
|
||||
"clock" => @clock.render_digital(size, tokens, now())
|
||||
"clock" => @clock.render_digital(size, tokens, now(), hour12=true)
|
||||
"layout" => [
|
||||
@ui.fill_rect(@ui.rect(0, 0, p.w, p.h), tokens.palette.surface_hover, radius=tokens.radius.reinterpret_as_int()),
|
||||
@ui.text(p.w / 2, p.h / 2, layout_label, tokens.font_size.reinterpret_as_int() - 2, tokens.palette.foreground, align=CENTER),
|
||||
|
||||
@@ -38,6 +38,8 @@ enum ObjKind {
|
||||
ObjSubsurface
|
||||
ObjDataManager
|
||||
ObjDataObj
|
||||
ObjCursorShapeMgr
|
||||
ObjCursorShapeDev
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -99,6 +101,8 @@ struct ClientConn {
|
||||
pointer_ids : Array[UInt]
|
||||
keyboard_ids : Array[UInt]
|
||||
mut seat_ver : UInt
|
||||
/// wp_cursor_shape_v1 shape the client last asked for (0 = never set).
|
||||
mut cursor_shape : UInt
|
||||
mut alive : Bool
|
||||
}
|
||||
|
||||
@@ -120,6 +124,7 @@ fn ClientConn::new(client_id : UInt, fd : Int) -> ClientConn {
|
||||
pointer_ids: [],
|
||||
keyboard_ids: [],
|
||||
seat_ver: 1U,
|
||||
cursor_shape: 0U,
|
||||
alive: true,
|
||||
}
|
||||
}
|
||||
@@ -219,6 +224,7 @@ fn emit_registry_globals(c : ClientConn, reg_id : UInt) -> Unit {
|
||||
(6U, "wl_output", 4U),
|
||||
(7U, "wl_subcompositor", 1U),
|
||||
(8U, "wl_data_device_manager", 3U),
|
||||
(9U, "wp_cursor_shape_manager_v1", 1U),
|
||||
]
|
||||
for g in globals {
|
||||
let w = WireWriter::new()
|
||||
@@ -385,6 +391,8 @@ fn WaylandServer::dispatch_msg(
|
||||
c.objects.set(new_id, ObjSeat)
|
||||
c.seat_ver = ver
|
||||
emit_seat_info(c, new_id)
|
||||
} else if iface == "wp_cursor_shape_manager_v1" {
|
||||
c.objects.set(new_id, ObjCursorShapeMgr)
|
||||
} else if iface == "wl_data_device_manager" {
|
||||
c.objects.set(new_id, ObjDataManager)
|
||||
} else if iface == "wl_subcompositor" {
|
||||
@@ -497,6 +505,22 @@ fn WaylandServer::dispatch_msg(
|
||||
c.objects.set(id, ObjDataObj)
|
||||
}
|
||||
ObjDataObj => ()
|
||||
ObjCursorShapeMgr =>
|
||||
if opcode == 1U {
|
||||
// get_pointer(cursor_shape_device: new_id, pointer)
|
||||
let id = reader.u32()
|
||||
c.objects.set(id, ObjCursorShapeDev)
|
||||
} else if opcode == 2U {
|
||||
// get_tablet_tool_v2: accepted, unused
|
||||
let id = reader.u32()
|
||||
c.objects.set(id, ObjCursorShapeDev)
|
||||
}
|
||||
ObjCursorShapeDev =>
|
||||
if opcode == 1U {
|
||||
// set_shape(serial, shape)
|
||||
let _serial = reader.u32()
|
||||
c.cursor_shape = reader.u32()
|
||||
}
|
||||
ObjSubsurface =>
|
||||
if opcode == 0U {
|
||||
c.objects.remove(obj_id)
|
||||
@@ -1059,3 +1083,12 @@ pub fn WaylandServer::keyboard_modifiers(self : WaylandServer, win_id : UInt64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Cursor shape (wp_cursor_shape_v1 enum value) the client owning `win_id` last
|
||||
/// requested; 1 (default) if it never asked for one.
|
||||
pub fn WaylandServer::client_cursor_shape(self : WaylandServer, win_id : UInt64) -> UInt {
|
||||
match self.win_client(win_id) {
|
||||
Some((c, _)) => if c.cursor_shape == 0U { 1U } else { c.cursor_shape }
|
||||
None => 1U
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user