uinput input backend and terminal-aware paste

- uinput.rs: kernel virtual keyboard + absolute pointer (Sunshine-style),
  physical evdev keycodes so the compositor's keysym lookup cannot drop
  shifted symbols (#3). Auto on Wayland/portal when /dev/uinput is
  accessible (udev uaccess rule), XTest kept on X11 (it suppresses
  autorepeat for held keys over latency). UU_INPUT_BACKEND=auto|uinput|native.
- Mac viewers send Cmd+V as Ctrl+V (verified: Cmd and Ctrl both arrive as
  VK_LCONTROL). In a focused X11 terminal Ctrl+V becomes Ctrl+Shift+V so it
  pastes instead of quoting the next key; Ctrl+C always interrupts (copy is
  Cmd+Shift+C). UU_TERMINAL_SHORTCUTS=0 disables.

Verified on the 3090 with the official Mac viewer: paste, interrupt,
uinput typing incl. underscores.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
VallierDevandClaude Opus 5.5 committed 2026-10-15 09:49:03 +08:00
1 parent ddbc75bbf6
commit 49edf1d389
4 files changed
+395 -2

No files matched your search

+42
View File
@@ -9,6 +9,8 @@
#include <sys/ipc.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <strings.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/Xfixes.h>
@@ -190,6 +192,46 @@ int x11_key_event(int keycode, int is_press) {
return 0;
}
/* ---- Terminal-aware paste (Mac viewer Cmd+V arrives as Ctrl+V) ------------------------------
* Linux terminals paste with Ctrl+Shift+V; Ctrl+V quotes the next key (a paste then shows as
* "^[[200~..."). Reports whether the focused window is a terminal emulator. Uses its own
* connection so it never races the capture/input connection. */
static Display *g_probe = NULL;
static int class_is_terminal(const char *value) {
static const char *names[] = { "gnome-terminal", "gnome-terminal-server", "org.gnome.Console", "kgx", "konsole",
"xfce4-terminal", "mate-terminal", "lxterminal", "qterminal", "terminator", "tilix", "xterm", "uxterm",
"urxvt", "rxvt", "alacritty", "kitty", "wezterm", "wezterm-gui", "foot", "st-256color", "terminology",
"guake", "tilda", "deepin-terminal", "ptyxis", "io.elementary.terminal", "cool-retro-term", NULL };
if (!value) return 0;
for (int i = 0; names[i]; i++) if (strcasecmp(value, names[i]) == 0) return 1;
return 0;
}
/* Returns 1 when the focused window belongs to a terminal emulator, else 0. */
int x11_terminal_shortcut_state(void) {
if (!g_probe && !(g_probe = XOpenDisplay(NULL))) return 0;
Window focus = 0; int revert = 0;
XGetInputFocus(g_probe, &focus, &revert);
if (focus == None || focus == PointerRoot) return 0;
Window cur = focus;
for (int depth = 0; depth < 12 && cur; depth++) {
XClassHint hint = {0};
if (XGetClassHint(g_probe, cur, &hint)) {
int terminal = class_is_terminal(hint.res_name) || class_is_terminal(hint.res_class);
if (hint.res_name) XFree(hint.res_name);
if (hint.res_class) XFree(hint.res_class);
return terminal;
}
Window root, parent, *children = NULL; unsigned int n = 0;
if (!XQueryTree(g_probe, cur, &root, &parent, &children, &n)) return 0;
if (children) XFree(children);
if (parent == root) return 0;
cur = parent;
}
return 0;
}
void x11_close() {
if (!g_display) return;
if (g_use_shm) {