From c7390363017d6192ade515a221975202625fd95f Mon Sep 17 00:00:00 2001 From: ossSB <47635292+clionertr@users.noreply.github.com> Date: Wed, 21 Oct 2026 16:29:19 +0800 Subject: [PATCH] Wayland: virtual pointer and keyboard are optional; capture still starts (#72, #73) Compositors without wlr-virtual-pointer, or that restrict the virtual keyboard to their input method (Denial), now bring up capture and fall back to uinput for input. UU_WAYLAND_NO_VIRTUAL_KEYBOARD=1 skips the virtual keyboard. Co-Authored-By: Claude Opus 5.5 --- c_engine/wayland_engine.c | 89 ++++++++++++++++++++++++--------------- src/input.rs | 7 ++- 2 files changed, 61 insertions(+), 35 deletions(-) diff --git a/c_engine/wayland_engine.c b/c_engine/wayland_engine.c index 1551fc9..e574525 100644 --- a/c_engine/wayland_engine.c +++ b/c_engine/wayland_engine.c @@ -535,7 +535,10 @@ int uu_wl_init(int32_t *w,int32_t *h) { wl_registry_add_listener(registry,®istry_listener,NULL); if(sync_display()!=0 || sync_display()!=0) goto end; dma_init(); - if(!shm || !seat || !copy_manager || !pointer_manager || !keyboard_manager || !output_count) goto end; + /* wlr-virtual-pointer is an optional input path. When the compositor does not + advertise it, pointer injection is skipped and the caller may drive input + through uinput; screencopy + virtual keyboard are still enough to capture. */ + if(!shm || !seat || !copy_manager || !output_count) goto end; const char *name=getenv("UU_WAYLAND_OUTPUT"); selected=0; if(name && *name) { for(selected=0;selected16384 || h>16384 || (uint64_t)w*h*4>256*1024*1024) goto end; - struct zwlr_virtual_pointer_v1 *next=zwlr_virtual_pointer_manager_v1_create_virtual_pointer_with_output(pointer_manager,seat,outputs[target].handle); - if(!next) goto end; - if(sync_display()!=0) {zwlr_virtual_pointer_v1_destroy(next);goto end;} + struct zwlr_virtual_pointer_v1 *next=NULL; + if(pointer_manager) { + next=zwlr_virtual_pointer_manager_v1_create_virtual_pointer_with_output(pointer_manager,seat,outputs[target].handle); + if(!next) goto end; + if(sync_display()!=0) {zwlr_virtual_pointer_v1_destroy(next);goto end;} + } for(unsigned i=0;i<2;i++) { frame_clear(&frames[i]); dma_clear(&frames[i]); shm_clear(&frames[i]); } pending=0; if(pointer) zwlr_virtual_pointer_v1_destroy(pointer); @@ -654,6 +670,7 @@ end: } int uu_wl_move(int32_t x,int32_t y,int relative) { pthread_mutex_lock(&lock); int result=-1; + if(initialized && !pointer) { goto end; } /* no virtual pointer: report failure so the caller falls back to uinput */ if(initialized) { if(relative) { /* UU reports pixels (source DPR=1); Wayland motion is in logical points. */ @@ -668,6 +685,7 @@ end: pthread_mutex_unlock(&lock); return result; } int uu_wl_button(int button,int pressed) { pthread_mutex_lock(&lock); int result=-1; + if(initialized && !pointer) { goto end; } /* no virtual pointer: report failure so the caller falls back to uinput */ if(initialized) { if(button>=4 && button<=7) { if(pressed) { @@ -687,6 +705,7 @@ end: pthread_mutex_unlock(&lock); return result; } int uu_wl_key(uint64_t symbol,int pressed) { pthread_mutex_lock(&lock); int result=-1; + if(initialized && !keyboard) { pthread_mutex_unlock(&lock); return -1; } /* no virtual keyboard: caller falls back to uinput */ if(initialized) { for(xkb_keycode_t code=xkb_keymap_min_keycode(keymap);code<=xkb_keymap_max_keycode(keymap);code++) { int matches=0; @@ -717,20 +736,24 @@ int uu_wl_release_all(void) { if(initialized) { /* Sweep this client's virtual keyboard directly: a keysym lookup can fail for unmapped OEM/keypad symbols before reaching held modifiers. */ - for(xkb_keycode_t code=xkb_keymap_min_keycode(keymap);code<=xkb_keymap_max_keycode(keymap);code++) { - if(code<8 || code>=sizeof(held_keys) || !xkb_keymap_key_get_name(keymap,code)) continue; - zwp_virtual_keyboard_v1_key(keyboard,timestamp(),code-8,WL_KEYBOARD_KEY_STATE_RELEASED); - if(held_keys[code]) xkb_state_update_key(key_state,code,XKB_KEY_UP); + if(keyboard) { + for(xkb_keycode_t code=xkb_keymap_min_keycode(keymap);code<=xkb_keymap_max_keycode(keymap);code++) { + if(code<8 || code>=sizeof(held_keys) || !xkb_keymap_key_get_name(keymap,code)) continue; + zwp_virtual_keyboard_v1_key(keyboard,timestamp(),code-8,WL_KEYBOARD_KEY_STATE_RELEASED); + if(held_keys[code]) xkb_state_update_key(key_state,code,XKB_KEY_UP); + } + zwp_virtual_keyboard_v1_modifiers(keyboard, + xkb_state_serialize_mods(key_state,XKB_STATE_MODS_DEPRESSED), + xkb_state_serialize_mods(key_state,XKB_STATE_MODS_LATCHED), + xkb_state_serialize_mods(key_state,XKB_STATE_MODS_LOCKED), + xkb_state_serialize_layout(key_state,XKB_STATE_LAYOUT_EFFECTIVE)); } memset(held_keys,0,sizeof(held_keys)); - zwp_virtual_keyboard_v1_modifiers(keyboard, - xkb_state_serialize_mods(key_state,XKB_STATE_MODS_DEPRESSED), - xkb_state_serialize_mods(key_state,XKB_STATE_MODS_LATCHED), - xkb_state_serialize_mods(key_state,XKB_STATE_MODS_LOCKED), - xkb_state_serialize_layout(key_state,XKB_STATE_LAYOUT_EFFECTIVE)); - for(unsigned code=0x110;code<=0x114;code++) - zwlr_virtual_pointer_v1_button(pointer,timestamp(),code,WL_POINTER_BUTTON_STATE_RELEASED); - zwlr_virtual_pointer_v1_frame(pointer); + if(pointer) { + for(unsigned code=0x110;code<=0x114;code++) + zwlr_virtual_pointer_v1_button(pointer,timestamp(),code,WL_POINTER_BUTTON_STATE_RELEASED); + zwlr_virtual_pointer_v1_frame(pointer); + } result=wl_display_flush(display)<0?-1:0; } pthread_mutex_unlock(&lock);return result; diff --git a/src/input.rs b/src/input.rs index 09ca651..a3e4916 100644 --- a/src/input.rs +++ b/src/input.rs @@ -328,9 +328,12 @@ impl InputInjector { // uinput ABS axes span the compositor's whole desktop. A captured output // uses its own pixel space; bind absolute motion to that Wayland output, // including when uinput remains in use for keyboard/buttons/relative input. - if !relative && self.backend==crate::desktop_backend::DesktopBackend::Wayland { - return crate::wayland::move_pointer(x,y,false); + if !relative && self.backend==crate::desktop_backend::DesktopBackend::Wayland + && crate::wayland::move_pointer(x,y,false)==0 { + return 0; } + // Compositors without wlr-virtual-pointer reject absolute motion here; fall + // through to the uinput absolute pointer instead of reporting a phantom success. if let Some(uinput)=&self.uinput { if relative { return Self::uinput_result(uinput.move_relative(x,y)); } let (w,h)=*self.screen.lock().unwrap();