hex/scripts/test-wayland-paste.sh
Dax Raad 1577c19b52 feat(linux): portal shortcuts and hex commands replace raw Wayland input
Wayland shortcuts no longer read /dev/input. One state machine in
linux_input now serves every source:

- X11: the existing key grabs, with auto-repeat filtering split out and
  tested, and the inline gesture flags replaced by the shared rules.
- Wayland with the GlobalShortcuts portal: Register("hex"), one session for
  dictation, Paste Last, and Voice Action, and a second session that binds
  Escape (also with the held shortcut's modifiers) only while recording.
  Activated/Deactivated are press/release; refused shortcuts and the
  trigger the desktop actually granted show in Settings; a closed session
  cancels and stops the listener with an error.
- Everywhere: `hex dictation start|stop|toggle|cancel`,
  `hex voice-action start|stop|toggle`, and `hex paste-last` talk to the
  running service over its socket for desktops without the portal. They
  are idempotent, never start the service, and fail clearly when it is
  missing or not listening.

Settings records shortcuts from its own key events on Wayland too, lists
the granted triggers, or, without the portal, hides the shortcut rows and
lists the commands. Wayland paste no longer waits for held modifiers:
wtype's virtual keyboard sends its own, and the Wayland paste smoke now
pastes while another keyboard holds Ctrl and Alt.

Removes linux_wayland_input.rs, the evdev and udev crates, libudev-dev in
CI, and every input-group requirement from the docs. Also gates
AppWindowPreview::pane to macOS, whose only callers broke the Linux
Clippy build.
2026-10-22 01:13:07 -04:00

134 lines
5.1 KiB
Shell
Executable file

#!/usr/bin/env bash
set -euo pipefail
if [[ "${1:-}" == --inside ]]; then
target=
keyboard=
app=
service=
finish() {
status=$?
trap - EXIT
if [[ -n "$target" ]]; then kill "$target" 2>/dev/null || true; fi
if [[ -n "$keyboard" ]]; then kill "$keyboard" 2>/dev/null || true; fi
if [[ -n "$app" ]]; then kill "$app" 2>/dev/null || true; fi
if [[ -n "$service" ]]; then kill "$service" 2>/dev/null || true; wait "$service" 2>/dev/null || true; fi
printf '%s\n' "$status" > "$HEX_WAYLAND_TEST_RESULT"
swaymsg exit >/dev/null 2>&1 || true
exit "$status"
}
trap finish EXIT
# Seed the isolated compositor's keyboard state before any window exists,
# and keep Ctrl and Alt held on it as a user still holding a shortcut would:
# wtype's own keyboard must paste plain Ctrl+V without waiting for them.
wtype -k v -M ctrl -M alt -p VoidSymbol -s 60000 &
keyboard=$!
for ((attempt = 0; attempt < 100; attempt++)); do
if swaymsg -t get_inputs -r | grep -q wlr_virtual_keyboard; then break; fi
sleep 0.05
done
"$HEX_WAYLAND_TEST_TARGET" "$HEX_WAYLAND_PASTE_OUTPUT" &
target=$!
for ((attempt = 0; attempt < 100; attempt++)); do
if [[ -f "$HEX_WAYLAND_PASTE_OUTPUT.ready" ]]; then break; fi
sleep 0.05
done
test -f "$HEX_WAYLAND_PASTE_OUTPUT.ready"
"$HEX_WAYLAND_TEST_BINARY" --exact linux_paste::tests::native_wayland_clipboard_shortcut \
--ignored --nocapture --test-threads=1
kill "$target"
wait "$target" 2>/dev/null || true
target=
# The app-window check uses compositor IPC, not keyboard input. Remove the
# synthetic seat first rather than expose a transient, keymap-less keyboard.
kill "$keyboard"
wait "$keyboard" 2>/dev/null || true
keyboard=
for ((attempt = 0; attempt < 100; attempt++)); do
if ! swaymsg -t get_inputs -r | grep wlr_virtual_keyboard >/dev/null; then break; fi
sleep 0.05
done
"$HEX_WAYLAND_APP_BINARY" service >"$HEX_WAYLAND_APP_LOG.service" 2>&1 &
service=$!
for ((attempt = 0; attempt < 100; attempt++)); do
if "$HEX_WAYLAND_APP_BINARY" status >/dev/null 2>&1; then break; fi
sleep 0.05
done
"$HEX_WAYLAND_APP_BINARY" status >/dev/null
"$HEX_WAYLAND_APP_BINARY" app >"$HEX_WAYLAND_APP_LOG" 2>&1 &
app=$!
for ((attempt = 0; attempt < 200; attempt++)); do
kill -0 "$app"
if swaymsg -t get_tree -r | grep '"name": "Hex"' >/dev/null; then break; fi
sleep 0.05
done
swaymsg -t get_tree -r | grep '"name": "Hex"' >/dev/null
# Keep GPUI connected while the paste helper creates a virtual keyboard.
export HEX_WAYLAND_PASTE_OUTPUT="$HEX_WAYLAND_PASTE_OUTPUT-coexist"
"$HEX_WAYLAND_TEST_TARGET" "$HEX_WAYLAND_PASTE_OUTPUT" &
target=$!
for ((attempt = 0; attempt < 100; attempt++)); do
if swaymsg -t get_tree -r | grep '"name": "Hex Wayland Test"' >/dev/null; then break; fi
sleep 0.05
done
swaymsg -t get_tree -r | grep '"name": "Hex Wayland Test"' >/dev/null
wtype -p v -p VoidSymbol -s 60000 &
keyboard=$!
for ((attempt = 0; attempt < 100; attempt++)); do
if [[ -f "$HEX_WAYLAND_PASTE_OUTPUT.ready" ]]; then break; fi
sleep 0.05
done
test -f "$HEX_WAYLAND_PASTE_OUTPUT.ready"
"$HEX_WAYLAND_TEST_BINARY" --exact linux_paste::tests::native_wayland_clipboard_shortcut \
--ignored --nocapture --test-threads=1
kill -0 "$app"
kill "$target"
wait "$target" 2>/dev/null || true
target=
swaymsg '[app_id="hex"] kill' >/dev/null
wait "$app"
app=
kill -0 "$service"
"$HEX_WAYLAND_APP_BINARY" status >/dev/null
exit 0
fi
if [[ $# != 2 || $(id -u) == 0 ]]; then
echo "Usage: $0 /path/to/compiled-test /path/to/voice-control (run as an unprivileged user)" >&2
exit 1
fi
for command in cc pkg-config sway swaymsg wtype wl-copy dbus-run-session timeout; do
command -v "$command" >/dev/null
done
root=$(cd -- "$(dirname -- "$0")/.." && pwd)
work=$(mktemp -d)
trap 'rm -rf -- "$work"' EXIT
export HEX_WAYLAND_TEST_BINARY
HEX_WAYLAND_TEST_BINARY=$(realpath -- "$1")
export HEX_WAYLAND_APP_BINARY
HEX_WAYLAND_APP_BINARY=$(realpath -- "$2")
export HEX_WAYLAND_TEST_SCRIPT="$root/scripts/test-wayland-paste.sh"
export HEX_WAYLAND_TEST_TARGET="$work/target"
export HEX_WAYLAND_PASTE_OUTPUT="$work/pasted.txt"
export HEX_WAYLAND_TEST_RESULT="$work/result"
export HEX_WAYLAND_APP_LOG="$work/hex.log"
export XDG_RUNTIME_DIR="$work/runtime"
export XDG_DATA_HOME="$work/data"
export HEX_APPLICATION_SUPPORT_DIR="$work/support"
export ALSA_CONFIG_PATH="$work/alsa.conf"
printf '# No physical audio devices in this fixture.\n' > "$ALSA_CONFIG_PATH"
mkdir -m 700 "$XDG_RUNTIME_DIR"
cc "$root/tests/fixtures/wayland-paste-target.c" $(pkg-config --cflags --libs gtk+-3.0) -o "$HEX_WAYLAND_TEST_TARGET"
unset DISPLAY WAYLAND_DISPLAY SWAYSOCK
export WLR_BACKENDS=headless WLR_RENDERER=pixman WLR_LIBINPUT_NO_DEVICES=1 GDK_BACKEND=wayland
if ! timeout 25 dbus-run-session -- sway --config "$root/tests/fixtures/wayland-paste.conf" >"$work/compositor.log" 2>&1 \
|| [[ ! -f "$work/result" || $(<"$work/result") != 0 ]]; then
cat "$work/compositor.log"
if [[ -f "$work/hex.log" ]]; then cat "$work/hex.log"; fi
exit 1
fi
echo "Native Wayland clipboard insertion and independent Settings/service checks passed."