Touch: fingers reach apps as wl_touch, so a thumb scrolls
Every touch was turned into a mouse drag in the seat code, which selects text instead of scrolling. The seat now reports raw touches and the compositor routes them: to the app as wl_touch on its own content, and to the pointer (tap, drag, hold for right click, as before) everywhere else and for apps that don't listen to touches. The cursor is hidden while fingers are in use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
98a99aaa36
commit
e30d9cc71f
17 files changed
+786
-126
No files matched your search
@@ -226,6 +226,7 @@ struct ClientConn {
|
||||
toplevels : Map[UInt64, ToplevelState]
|
||||
positioners : Map[UInt, PosState]
|
||||
pointer_ids : Array[UInt]
|
||||
touch_ids : Array[UInt]
|
||||
keyboard_ids : Array[UInt]
|
||||
mut seat_ver : UInt
|
||||
/// xdg_wm_base version the client bound (`wm_capabilities` arrived in v5).
|
||||
@@ -269,6 +270,7 @@ fn ClientConn::new(client_id : UInt, fd : Int) -> ClientConn {
|
||||
toplevels: {},
|
||||
positioners: {},
|
||||
pointer_ids: [],
|
||||
touch_ids: [],
|
||||
keyboard_ids: [],
|
||||
seat_ver: 1U,
|
||||
xdg_ver: 1U,
|
||||
@@ -348,6 +350,8 @@ pub(all) struct WaylandServer {
|
||||
mut next_win_id : UInt64
|
||||
mut next_serial : UInt
|
||||
mut keymap : Bytes
|
||||
/// The seat has a touchscreen (wl_seat's capabilities).
|
||||
mut touch : Bool
|
||||
/// Clipboard owner: (client id, wl_data_source id).
|
||||
mut selection : (UInt, UInt)?
|
||||
/// Primary selection owner (the last text selected in any app): (client id, source id).
|
||||
@@ -394,6 +398,7 @@ pub fn WaylandServer::listen(
|
||||
socket_path,
|
||||
listen_fd: fd,
|
||||
output_w,
|
||||
touch: false,
|
||||
output_h,
|
||||
clients: [],
|
||||
win_to_client: {},
|
||||
@@ -499,10 +504,15 @@ fn emit_shm_formats(c : ClientConn, shm_id : UInt) -> Unit {
|
||||
}
|
||||
|
||||
///|
|
||||
fn emit_seat_info(c : ClientConn, seat_id : UInt, ver : UInt) -> Unit {
|
||||
let w1 = WireWriter::new()
|
||||
w1.u32(3U) // pointer (1) | keyboard (2)
|
||||
c.send_msg(w1.finish_msg(seat_id, 0U))
|
||||
fn emit_seat_caps(c : ClientConn, seat_id : UInt, touch : Bool) -> Unit {
|
||||
let w = WireWriter::new()
|
||||
w.u32(if touch { 7U } else { 3U }) // pointer (1) | keyboard (2) | touch (4)
|
||||
c.send_msg(w.finish_msg(seat_id, 0U))
|
||||
}
|
||||
|
||||
///|
|
||||
fn emit_seat_info(c : ClientConn, seat_id : UInt, ver : UInt, touch : Bool) -> Unit {
|
||||
emit_seat_caps(c, seat_id, touch)
|
||||
|
||||
// wl_seat.name is since version 2: a v1 client (vkcube) aborts on an event it has no handler for.
|
||||
if ver >= 2U {
|
||||
@@ -691,7 +701,7 @@ fn WaylandServer::dispatch_msg(
|
||||
} else if iface == "wl_seat" {
|
||||
c.objects.set(new_id, ObjSeat)
|
||||
c.seat_ver = ver
|
||||
emit_seat_info(c, new_id, ver)
|
||||
emit_seat_info(c, new_id, ver, self.touch)
|
||||
} else if iface == "wp_cursor_shape_manager_v1" {
|
||||
c.objects.set(new_id, ObjCursorShapeMgr)
|
||||
} else if iface == "wl_data_device_manager" {
|
||||
@@ -1598,6 +1608,13 @@ fn WaylandServer::dispatch_msg(
|
||||
} else if opcode == 2U {
|
||||
let tid = reader.u32()
|
||||
c.objects.set(tid, ObjTouch)
|
||||
c.touch_ids.push(tid)
|
||||
}
|
||||
ObjTouch =>
|
||||
if opcode == 0U { // release
|
||||
c.touch_ids.retain(id => id != obj_id)
|
||||
c.objects.remove(obj_id)
|
||||
send_delete_id(c, obj_id)
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
@@ -2100,6 +2117,102 @@ fn WaylandServer::pointer_frame(_self : WaylandServer, c : ClientConn, pid : UIn
|
||||
}
|
||||
}
|
||||
|
||||
///| The seat has a touchscreen: clients are told, also those already connected.
|
||||
pub fn WaylandServer::set_touch(self : WaylandServer) -> Unit {
|
||||
if self.touch {
|
||||
return
|
||||
}
|
||||
self.touch = true
|
||||
for c in self.clients {
|
||||
if c.alive {
|
||||
for id, obj in c.objects {
|
||||
if obj is ObjSeat {
|
||||
emit_seat_caps(c, id, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Whether the client of window or popup `win_id` listens to touches.
|
||||
pub fn WaylandServer::takes_touch(self : WaylandServer, win_id : UInt64) -> Bool {
|
||||
match self.win_client(win_id) {
|
||||
Some((c, _)) => c.touch_ids.length() > 0
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
///| wl_touch.down of finger `id` at surface-local (x, y) of `sub`, the window's subsurface (its
|
||||
/// wl_surface id), 0 for the window itself.
|
||||
pub fn WaylandServer::touch_down(
|
||||
self : WaylandServer,
|
||||
win_id : UInt64,
|
||||
time_ms : UInt,
|
||||
id : Int,
|
||||
x : Double,
|
||||
y : Double,
|
||||
sub? : UInt = 0U,
|
||||
) -> Unit {
|
||||
guard self.win_client(win_id) is Some((c, tl)) else { return }
|
||||
let target = if sub != 0U && c.surfaces.contains(sub) { sub } else { tl.wl_surface_id }
|
||||
if !c.surfaces.contains(target) {
|
||||
return
|
||||
}
|
||||
for tid in c.touch_ids {
|
||||
let w = WireWriter::new()
|
||||
w.u32(self.next_serial())
|
||||
w.u32(time_ms)
|
||||
w.u32(target)
|
||||
w.i32(id)
|
||||
w.i32(fixed(x))
|
||||
w.i32(fixed(y))
|
||||
c.send_msg(w.finish_msg(tid, 0U))
|
||||
c.send_msg(WireWriter::new().finish_msg(tid, 3U)) // frame
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn WaylandServer::touch_up(self : WaylandServer, win_id : UInt64, time_ms : UInt, id : Int) -> Unit {
|
||||
guard self.win_client(win_id) is Some((c, _)) else { return }
|
||||
for tid in c.touch_ids {
|
||||
let w = WireWriter::new()
|
||||
w.u32(self.next_serial())
|
||||
w.u32(time_ms)
|
||||
w.i32(id)
|
||||
c.send_msg(w.finish_msg(tid, 1U))
|
||||
c.send_msg(WireWriter::new().finish_msg(tid, 3U))
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn WaylandServer::touch_motion(
|
||||
self : WaylandServer,
|
||||
win_id : UInt64,
|
||||
time_ms : UInt,
|
||||
id : Int,
|
||||
x : Double,
|
||||
y : Double,
|
||||
) -> Unit {
|
||||
guard self.win_client(win_id) is Some((c, _)) else { return }
|
||||
for tid in c.touch_ids {
|
||||
let w = WireWriter::new()
|
||||
w.u32(time_ms)
|
||||
w.i32(id)
|
||||
w.i32(fixed(x))
|
||||
w.i32(fixed(y))
|
||||
c.send_msg(w.finish_msg(tid, 2U))
|
||||
c.send_msg(WireWriter::new().finish_msg(tid, 3U))
|
||||
}
|
||||
}
|
||||
|
||||
///| wl_touch.cancel: the compositor took the gesture.
|
||||
pub fn WaylandServer::touch_cancel(self : WaylandServer, win_id : UInt64) -> Unit {
|
||||
guard self.win_client(win_id) is Some((c, _)) else { return }
|
||||
for tid in c.touch_ids {
|
||||
c.send_msg(WireWriter::new().finish_msg(tid, 4U))
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn WaylandServer::keyboard_enter(self : WaylandServer, win_id : UInt64) -> Unit {
|
||||
match self.win_client(win_id) {
|
||||
|
||||
Reference in new issue
Block a user