mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a22f576005 | ||
|
|
212e4943f9 |
No files matched your search
Generated
+1
-1
@@ -2804,7 +2804,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu-remote-linux"
|
name = "uu-remote-linux"
|
||||||
version = "0.2.50"
|
version = "0.2.51"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ab_glyph",
|
"ab_glyph",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "uu-remote-linux"
|
name = "uu-remote-linux"
|
||||||
version = "0.2.50"
|
version = "0.2.51"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
default-run = "uuremote-server"
|
default-run = "uuremote-server"
|
||||||
authors = ["uu-remote-linux contributors"]
|
authors = ["uu-remote-linux contributors"]
|
||||||
|
|||||||
+34
-60
@@ -159,37 +159,10 @@ static size_t symbols_close(const char *text) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Named keycodes the keymap gives no symbol to. Reading the compositor's own list is the only
|
/* Reusable codes for the separate text-only keyboard. Remapping real printable keys on that device
|
||||||
portable way: pressing an unmapped keycode types nothing, and uu_wl_key never matches one
|
keeps the physical-key map untouched and is the form Chromium accepts; the evdev "reserved" codes
|
||||||
because it searches by keysym. Highest first, since uu_wl_key takes the lowest match. */
|
that have no symbol are discarded by some clients. */
|
||||||
static unsigned find_spare_codes(xkb_keycode_t *out,unsigned limit) {
|
static unsigned find_spare_codes(xkb_keycode_t *out,unsigned limit) {
|
||||||
unsigned count=0;
|
|
||||||
xkb_keycode_t min=xkb_keymap_min_keycode(keymap);
|
|
||||||
for(xkb_keycode_t code=xkb_keymap_max_keycode(keymap);code>min && count<limit;code--) {
|
|
||||||
if(code<8 || code>=sizeof(held_keys) || !xkb_keymap_key_get_name(keymap,code)) continue;
|
|
||||||
int mapped=0;
|
|
||||||
for(xkb_level_index_t level=0;level<xkb_keymap_num_levels_for_key(keymap,code,0) && !mapped;level++) {
|
|
||||||
const xkb_keysym_t *syms;
|
|
||||||
if(xkb_keymap_key_get_syms_by_level(keymap,code,0,level,&syms)>0) mapped=1;
|
|
||||||
}
|
|
||||||
if(!mapped) out[count++]=code;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
/* A keycode the session keymap already produces this symbol with, unshifted. Typing through it
|
|
||||||
needs no upload, so no client can mistranslate it - and it is how plain latin text and spaces
|
|
||||||
arrive without touching the keymap at all. Spares never match: the pristine keymap leaves them
|
|
||||||
unmapped. */
|
|
||||||
static xkb_keycode_t existing_keycode(xkb_keysym_t symbol) {
|
|
||||||
for(xkb_keycode_t code=xkb_keymap_min_keycode(keymap);code<=xkb_keymap_max_keycode(keymap);code++) {
|
|
||||||
if(code<8 || code>=sizeof(held_keys)) continue;
|
|
||||||
const xkb_keysym_t *syms;
|
|
||||||
if(xkb_keymap_key_get_syms_by_level(keymap,code,0,0,&syms)==1 && syms[0]==symbol) return code;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static unsigned find_niri_text_codes(xkb_keycode_t *out,unsigned limit) {
|
|
||||||
/* Printable physical keys work in Chromium; reserved evdev codes can be discarded. */
|
|
||||||
static const xkb_keycode_t text_codes[]={24,25,26,27,28,29,30,31,32,33,38,39,40,41,42,43,44,45,46,52,53,54,55,56,57,58};
|
static const xkb_keycode_t text_codes[]={24,25,26,27,28,29,30,31,32,33,38,39,40,41,42,43,44,45,46,52,53,54,55,56,57,58};
|
||||||
unsigned count=0;
|
unsigned count=0;
|
||||||
for(unsigned i=0;i<sizeof(text_codes)/sizeof(text_codes[0]) && count<limit;i++)
|
for(unsigned i=0;i<sizeof(text_codes)/sizeof(text_codes[0]) && count<limit;i++)
|
||||||
@@ -216,8 +189,12 @@ static void release_held_keys_locked(void) {
|
|||||||
key_state and held_keys: pressed and released here. */
|
key_state and held_keys: pressed and released here. */
|
||||||
static int flush_batch(char *buffer,size_t capacity,const char names[][64],const xkb_keycode_t *codes,unsigned count,int *typed) {
|
static int flush_batch(char *buffer,size_t capacity,const char names[][64],const xkb_keycode_t *codes,unsigned count,int *typed) {
|
||||||
release_held_keys_locked();
|
release_held_keys_locked();
|
||||||
if(getenv("NIRI_SOCKET")) {if(sync_display()!=0) return -1;usleep(8000);}
|
if(sync_display()!=0) return -1;
|
||||||
else if(rekey_keyboard()!=0) return -1;
|
usleep(8000);
|
||||||
|
/* A keymap re-sent on a keyboard the client already knows is not handed to it again, so the
|
||||||
|
next batch would still decode with the previous one and repeat it. Re-attaching the text
|
||||||
|
keyboard is what makes the compositor deliver the new keymap. */
|
||||||
|
if(rekey_keyboard()!=0) return -1;
|
||||||
size_t at=keymap_insert;
|
size_t at=keymap_insert;
|
||||||
memcpy(buffer,keymap_text,at);
|
memcpy(buffer,keymap_text,at);
|
||||||
for(unsigned i=0;i<count;i++) {
|
for(unsigned i=0;i<count;i++) {
|
||||||
@@ -227,16 +204,16 @@ static int flush_batch(char *buffer,size_t capacity,const char names[][64],const
|
|||||||
}
|
}
|
||||||
memcpy(buffer+at,keymap_text+keymap_insert,keymap_text_len-keymap_insert);
|
memcpy(buffer+at,keymap_text+keymap_insert,keymap_text_len-keymap_insert);
|
||||||
if(upload_keymap(buffer,at+(keymap_text_len-keymap_insert))!=0) return -1;
|
if(upload_keymap(buffer,at+(keymap_text_len-keymap_insert))!=0) return -1;
|
||||||
if(getenv("NIRI_SOCKET")) zwp_virtual_keyboard_v1_modifiers(keyboard,0,0,0,0);
|
zwp_virtual_keyboard_v1_modifiers(keyboard,0,0,0,0);
|
||||||
if(sync_display()!=0) return -1;
|
if(sync_display()!=0) return -1;
|
||||||
if(getenv("NIRI_SOCKET")) usleep(8000);
|
usleep(8000);
|
||||||
for(unsigned i=0;i<count;i++) { press_keycode(codes[i]); (*typed)++; }
|
for(unsigned i=0;i<count;i++) { press_keycode(codes[i]); (*typed)++; }
|
||||||
if(getenv("NIRI_SOCKET")) {if(sync_display()!=0) return -1;usleep(8000);}
|
if(sync_display()!=0) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Type UTF-8 like xdotool type does on X11, but on Wayland: characters the session keymap already
|
/* Type UTF-8 like xdotool type does on X11: each character is a Unicode keysym carried by the
|
||||||
has go out as ordinary keycodes, the rest share the spares of one keymap upload (~70 KB, so one
|
text-only keyboard's printable codes, one keymap upload (~70 KB, so one batch per upload) in text
|
||||||
batch per upload), in text order. Never logs the text. */
|
order. Never logs the text. */
|
||||||
static int type_utf8_locked(const char *text) {
|
static int type_utf8_locked(const char *text) {
|
||||||
size_t capacity=keymap_text_len+(size_t)UU_TEXT_SPARE*96+64;
|
size_t capacity=keymap_text_len+(size_t)UU_TEXT_SPARE*96+64;
|
||||||
char *buffer=malloc(capacity);
|
char *buffer=malloc(capacity);
|
||||||
@@ -258,16 +235,11 @@ static int type_utf8_locked(const char *text) {
|
|||||||
if(cp=='\n') sym=0xff0d; /* Return */
|
if(cp=='\n') sym=0xff0d; /* Return */
|
||||||
else if(cp=='\t') sym=0xff09; /* Tab */
|
else if(cp=='\t') sym=0xff09; /* Tab */
|
||||||
else if(cp<0x20 || cp==0x7f || (cp>=0x80 && cp<0xa0)) continue; /* controls carry no text */
|
else if(cp<0x20 || cp==0x7f || (cp>=0x80 && cp<0xa0)) continue; /* controls carry no text */
|
||||||
else if(cp<0x100) sym=cp; /* Latin-1 keysyms equal the code point */
|
/* Every character goes out as a Unicode keysym, including ASCII: a plain Latin-1 keysym
|
||||||
else sym=(xkb_keysym_t)(0x1000000|cp); /* Unicode keysym */
|
is what a running input method composes as pinyin, so "abc" would turn into candidates
|
||||||
xkb_keycode_t existing=getenv("NIRI_SOCKET")?0:existing_keycode(sym);
|
instead of reaching the field. */
|
||||||
if(existing) {
|
else sym=(xkb_keysym_t)(0x1000000|cp);
|
||||||
if(count && flush_batch(buffer,capacity,names,codes,count,&typed)!=0) { failed=1; break; }
|
if(count==spare_count) {
|
||||||
count=0;
|
|
||||||
press_keycode(existing); typed++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(count==(getenv("NIRI_SOCKET")?spare_count:UU_TEXT_SPARE)) {
|
|
||||||
if(flush_batch(buffer,capacity,names,codes,count,&typed)!=0) { failed=1; break; }
|
if(flush_batch(buffer,capacity,names,codes,count,&typed)!=0) { failed=1; break; }
|
||||||
count=0;
|
count=0;
|
||||||
}
|
}
|
||||||
@@ -278,23 +250,25 @@ static int type_utf8_locked(const char *text) {
|
|||||||
}
|
}
|
||||||
if(!failed && count) failed=flush_batch(buffer,capacity,names,codes,count,&typed)!=0;
|
if(!failed && count) failed=flush_batch(buffer,capacity,names,codes,count,&typed)!=0;
|
||||||
free(buffer);
|
free(buffer);
|
||||||
/* Restore the pristine keymap whatever happened above, so uu_wl_key keeps its own symbol map. */
|
|
||||||
if(getenv("NIRI_SOCKET")) {if(sync_display()!=0) return -1;usleep(8000);}
|
|
||||||
else if(upload_keymap(keymap_text,keymap_text_len)!=0) return -1;
|
|
||||||
return failed && !typed?-1:typed;
|
return failed && !typed?-1:typed;
|
||||||
}
|
}
|
||||||
int uu_wl_type_utf8(const char *text) {
|
int uu_wl_type_utf8(const char *text) {
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
int typed=-1;
|
int typed=-1;
|
||||||
if(initialized && text && keymap_text && keymap_insert && spare_count) {
|
if(initialized && text && keymap_text && keymap_insert && spare_count) {
|
||||||
if(getenv("NIRI_SOCKET")) {
|
if(!keyboard_manager) { pthread_mutex_unlock(&lock); return -1; }
|
||||||
/* Only niri uses printable codes on a separate text device; preserve the Hyprland path. */
|
/* Text has its own device: remapping printable codes must not change physical-key input. */
|
||||||
release_held_keys_locked();
|
release_held_keys_locked();
|
||||||
struct zwp_virtual_keyboard_v1 *saved=keyboard;
|
/* The original device stays alive, so key-up alone must not leave its modifiers held. */
|
||||||
keyboard=zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(keyboard_manager,seat);
|
zwp_virtual_keyboard_v1_modifiers(keyboard,
|
||||||
if(keyboard) {typed=type_utf8_locked(text);sync_display();usleep(8000);if(keyboard) zwp_virtual_keyboard_v1_destroy(keyboard);}
|
xkb_state_serialize_mods(key_state,XKB_STATE_MODS_DEPRESSED),
|
||||||
keyboard=saved;
|
xkb_state_serialize_mods(key_state,XKB_STATE_MODS_LATCHED),
|
||||||
} else typed=type_utf8_locked(text);
|
xkb_state_serialize_mods(key_state,XKB_STATE_MODS_LOCKED),
|
||||||
|
xkb_state_serialize_layout(key_state,XKB_STATE_LAYOUT_EFFECTIVE));
|
||||||
|
struct zwp_virtual_keyboard_v1 *saved=keyboard;
|
||||||
|
keyboard=zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(keyboard_manager,seat);
|
||||||
|
if(keyboard) {typed=type_utf8_locked(text);sync_display();usleep(8000);if(keyboard) zwp_virtual_keyboard_v1_destroy(keyboard);}
|
||||||
|
keyboard=saved;
|
||||||
}
|
}
|
||||||
if(typed>=0 && wl_display_flush(display)<0) typed=-1;
|
if(typed>=0 && wl_display_flush(display)<0) typed=-1;
|
||||||
pthread_mutex_unlock(&lock); return typed;
|
pthread_mutex_unlock(&lock); return typed;
|
||||||
@@ -597,7 +571,7 @@ int uu_wl_init(int32_t *w,int32_t *h) {
|
|||||||
/* Text typing needs unmapped keycodes and a place to declare them. A keymap without either
|
/* Text typing needs unmapped keycodes and a place to declare them. A keymap without either
|
||||||
only costs that path - uu_wl_type_utf8 refuses and the caller keeps its own fallback. */
|
only costs that path - uu_wl_type_utf8 refuses and the caller keeps its own fallback. */
|
||||||
keymap_insert=symbols_close(keymap_text);
|
keymap_insert=symbols_close(keymap_text);
|
||||||
spare_count=getenv("NIRI_SOCKET")?find_niri_text_codes(spare_codes,UU_TEXT_SPARE):find_spare_codes(spare_codes,UU_TEXT_SPARE);
|
spare_count=find_spare_codes(spare_codes,UU_TEXT_SPARE);
|
||||||
}
|
}
|
||||||
initialized=1; *w=width; *h=height; result=0;
|
initialized=1; *w=width; *h=height; result=0;
|
||||||
end:
|
end:
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
Hyprland 等 wlroots 合成器上,手机查看端输入法打出的中文/符号文字可正常上屏。/ Phone IME text (Chinese and symbols) from mobile viewers now types correctly on Hyprland and other wlroots compositors.
|
||||||
|
|
||||||
|
### 修复 / Fixed
|
||||||
|
- **wlroots 手机输入法文字(#176,感谢 @Onekki)**:所有 wlroots 合成器统一用独立的虚拟文字键盘,每批文字重新 attach 键位表,ASCII 也按 Unicode keysym 发送;Wayland 下先走 keysym、失败再回退 uinput;输入前释放按键后同步原设备的修饰键状态,避免 Ctrl/Shift 残留。/ All wlroots compositors use a dedicated virtual text keyboard, re-attaching the keymap per batch and sending ASCII as Unicode keysyms; Wayland tries keysyms before falling back to uinput, and modifier state is re-synced to the original device so Ctrl/Shift do not stick.
|
||||||
|
|
||||||
|
### 验证范围 / Validation
|
||||||
|
单元测试与 CI;贡献者在 Hyprland 0.56.2 + fcitx5 实机验证。niri 等其他 wlroots 合成器未实测。
|
||||||
|
|
||||||
|
### 下载 / Download
|
||||||
|
`uu-remote-linux_0.2.51_<amd64|arm64>.deb`,或 `uu-remote-linux-v0.2.51-<x86_64|aarch64>-linux.tar.gz`(解压后运行 `./install.sh`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.51`(x86_64)。
|
||||||
|
|
||||||
|
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||||
+11
-4
@@ -742,14 +742,21 @@ impl InputInjector {
|
|||||||
self.emit_uinput_text(&crate::uinput::text_plan(text))
|
self.emit_uinput_text(&crate::uinput::text_plan(text))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mobile input-method text (`text_input`). uinput types the layout-mappable ASCII prefix
|
/// Mobile input-method text (`text_input`). X11 types directly. Native Wayland uses the text
|
||||||
/// without clipboard access. X11 types directly; native Wayland re-maps a spare
|
/// keyboard's Unicode keysyms first: uinput sends physical keycodes, which a running input
|
||||||
/// keycode in the virtual keyboard's keymap. Portal and other Wayland environments inject
|
/// method composes as pinyin, so "hello" would become candidates instead of text. uinput stays
|
||||||
/// via clipboard paste (Shift+Insert). Set UU_WAYLAND_TEXT=0 to disable Wayland text injection.
|
/// as the fallback when the keymap path is unavailable. Portal and other Wayland environments
|
||||||
|
/// inject via clipboard paste (Shift+Insert).
|
||||||
|
/// Set UU_WAYLAND_TEXT=0 to disable Wayland text injection.
|
||||||
pub fn text_input(&self, text: &str) {
|
pub fn text_input(&self, text: &str) {
|
||||||
let _serial=self.serial.lock().unwrap();
|
let _serial=self.serial.lock().unwrap();
|
||||||
if self.backend != crate::desktop_backend::DesktopBackend::X11 {
|
if self.backend != crate::desktop_backend::DesktopBackend::X11 {
|
||||||
if std::env::var("UU_WAYLAND_TEXT").is_ok_and(|v| v == "0") { return; }
|
if std::env::var("UU_WAYLAND_TEXT").is_ok_and(|v| v == "0") { return; }
|
||||||
|
if self.backend == crate::desktop_backend::DesktopBackend::Wayland
|
||||||
|
&& crate::wayland::type_utf8(text) >= 0 {
|
||||||
|
log::info!("Desktop text input: chars={} result=keysyms", text.chars().count());
|
||||||
|
return;
|
||||||
|
}
|
||||||
let typed = self.type_uinput_text(text);
|
let typed = self.type_uinput_text(text);
|
||||||
if typed > 0 { log::info!("Desktop text input (uinput): chars={typed}"); }
|
if typed > 0 { log::info!("Desktop text input (uinput): chars={typed}"); }
|
||||||
if typed == text.len() { return; }
|
if typed == text.len() { return; }
|
||||||
|
|||||||
Reference in new issue
Block a user