Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(appshot): record the appshot shortcuts and default the area to both Shift keys
rubenluetke10-beep7bd2d47b56a3
diff --git a/docs/appshots.md b/docs/appshots.mdindex ce5c503bd4..f1b852262a 100644--- a/docs/appshots.md+++ b/docs/appshots.md@@ -10,7 +10,7 @@ text — and hands it to the conversation as context. Settings live under| Trigger | What happens ||---|---|| **Window shortcut** — both Alt keys at once by default (both Option keys on a Mac) | The front window is captured and delivered per **Appshot destination**. |-| **Area shortcut** — Alt+Win+A by default (Option+Command+A on a Mac) | Every screen dims; drag a rectangle and exactly that part is captured and delivered the same way. Esc or a right-click cancels and sends nothing. |+| **Area shortcut** — both Shift keys at once by default | Every screen dims; drag a rectangle and exactly that part is captured and delivered the same way. Esc or a right-click cancels and sends nothing. || **Voice or chat** — "take an appshot", "mach einen Appshot", "haz un appshot" | The turn that asked captures the front window and answers with it. Only an explicit request for the whole screen ("an appshot of my full screen") captures the monitor the cursor is on instead — the live model's `take_appshot` passes `scope: "screen"` for it. || **Try it** buttons on the Appshots page | "Take appshot in 3 s" waits three seconds so you can switch windows; "Select area" opens the area picker at once. Both then behave like the shortcuts. |@@ -94,8 +94,16 @@ and served with `Cache-Control: no-store`.| Key | Default | Meaning ||---|---|---|-| `hotkey` | `"alt+alt"` | Window appshot. `alt+alt` = both Alt keys; any other combo in the shared hotkey syntax; `""` = off |-| `region_hotkey` | `"alt+win+a"` | Area appshot, same syntax. Must differ from `hotkey` (the app refuses one key for both) |+| `hotkey` | `"alt+alt"` | Window appshot. `alt+alt` / `shift+shift` / `ctrl+ctrl` = both keys of that pair; any other combo in the shared hotkey syntax; `""` = off |+| `region_hotkey` | `"shift+shift"` | Area appshot, same syntax. Must differ from `hotkey` (the app refuses one key for both) |++Both shortcuts are changed on the Appshots page: **Change** records the next+key gesture (hold the keys, then let go; Esc cancels), the X turns the+shortcut off. Pressing the same modifier on both sides records the matching+two-sided gesture. For Shift and Ctrl, which are held all the time while+typing, the second key has to follow the first within half a second, so a+capital letter typed with one Shift never fires it; both-Alt keeps its+original any-order behaviour.| `target` | `"auto"` | `auto` · `message` · `voice` (table above) || `sound` | `true` | Shutter sound; also needs `[ui].sound_effects` || `effect` | `true` | Flash and corner thumbnail |diff --git a/docs/os-parity.md b/docs/os-parity.mdindex 563aeac0d4..323a9b1884 100644--- a/docs/os-parity.md+++ b/docs/os-parity.md@@ -640,7 +640,7 @@ implementations, not stubs.|---|---|| Computer-Use / desktop actions (click, type, hotkey, scroll, drag, windows, apps, screenshots, UI trees) | Full per-OS backends (Win32/UIA, Quartz/AX, xdotool/AT-SPI); honest degradation on Wayland/headless/missing TCC grants || On-demand Screen Context | One-shot capture is wired into the production brain on Windows, macOS, and Linux/X11; UIA/AX/AT-SPI text is source-filtered, the indicator precedes capture, and Wayland/headless/missing grants refuse honestly |-| Appshots (front-window capture on a shortcut, button or request) | Capture, privacy and delivery are OS-neutral (Screen Context engine, `jarvis/appshot`). The both-Alt shortcut reads key state per OS: Windows `GetAsyncKeyState`, macOS `CGEventSourceKeyState` (Input Monitoring grant), Linux/X11 `XQueryKeymap`; Wayland/headless report it unavailable on the Appshots page. The flash and the area picker (Alt+Win+A, drag a rectangle) are PySide6 overlays where one can run; Wayland/headless report the area picker unavailable. Verified live on Windows only; see `docs/appshots.md` |+| Appshots (front-window capture on a shortcut, button or request) | Capture, privacy and delivery are OS-neutral (Screen Context engine, `jarvis/appshot`). The two-sided shortcuts (both Alt, both Shift, both Ctrl) read key state per OS: Windows `GetAsyncKeyState`, macOS `CGEventSourceKeyState` (Input Monitoring grant), Linux/X11 `XQueryKeymap`; Wayland/headless report it unavailable on the Appshots page. The flash and the area picker (both Shift keys, drag a rectangle) are PySide6 overlays where one can run; Wayland/headless report the area picker unavailable. Verified live on Windows only; see `docs/appshots.md` || Voice / audio (capture, playback, VAD, wake, STT, TTS, realtime) | Clean; headless disables voice honestly; WASAPI logic is inert-by-data off Windows || Core (launcher, config, keyring, restart, autostart, tray, elevation, paths) | Clean; per-OS autostart (Registry / LaunchAgent / XDG `.desktop`), keyring falls back to a 0600 file on headless hosts || Data / agents (wiki, contacts, telephony, sessions, missions, skills, self-mod, channels, MCP) | Clean; mission workers run on POSIX with a real process-group reaper |diff --git a/jarvis/appshot/gesture.py b/jarvis/appshot/gesture.pyindex 21bd2318e6..234ff1c320 100644--- a/jarvis/appshot/gesture.py+++ b/jarvis/appshot/gesture.py@@ -1,18 +1,23 @@-"""The "both Alt keys at once" gesture.--The shared hotkey backends fold left and right Alt into one token (the-Windows library knows no difference), so a chord of the two Alt keys cannot be-expressed there. This module watches exactly that gesture with the cheapest-primitive each OS offers — a key-state read every 50 ms, no hook, no tap:--* Windows: ``GetAsyncKeyState`` on ``VK_LMENU`` / ``VK_RMENU`` (AltGr raises- ``VK_RMENU`` too, so the gesture works on AltGr layouts).-* macOS: ``CGEventSourceKeyState`` on the left/right Option key codes. Needs- the same Input Monitoring grant as every other global shortcut; without it- the read stays false and nothing fires.+"""The "both X keys at once" gestures: both Alt, both Shift, both Ctrl.++The shared hotkey backends fold the left and right modifier into one token+(the Windows library knows no difference), so a chord of the two Alt (or+Shift, or Ctrl) keys cannot be expressed there. This module watches exactly+that gesture with the cheapest primitive each OS offers — a key-state read+every 50 ms, no hook, no tap:++* Windows: ``GetAsyncKeyState`` on the left/right virtual keys (AltGr raises+ ``VK_RMENU`` too, so the Alt gesture works on AltGr layouts).+* macOS: ``CGEventSourceKeyState`` on the left/right key codes (Option, Shift,+ Control). Needs the same Input Monitoring grant as every other global+ shortcut; without it the read stays false and nothing fires.* Linux/X11: ``XQueryKeymap`` through python-xlib (pynput's own dependency).* Wayland, headless, missing packages: :func:`make_probe` returns ``None``with the reason, and the caller reports the shortcut as unavailable.++Shift and Ctrl are held constantly while typing, so for them the second key+must follow the first within :data:`TOGETHER_S` — a deliberate press of both,+not a capital letter typed with one Shift while the other hand reaches over."""from __future__ import annotations@@ -27,50 +32,62 @@ log = logging.getLogger(__name__)POLL_S = 0.05#: A second gesture within this window is the same press, not a new one._REFIRE_GUARD_S = 0.6+#: Shift/Ctrl: both keys must go down within this long of each other.+TOGETHER_S = 0.5++#: Gesture spelling → the modifier family it watches.+GESTURES: dict[str, str] = {"alt+alt": "alt", "shift+shift": "shift", "ctrl+ctrl": "ctrl"}Probe = Callable[[], tuple[bool, bool] | None]+# (left, right) virtual keys / key codes per family.+_WIN_VK = {"alt": (0xA4, 0xA5), "shift": (0xA0, 0xA1), "ctrl": (0xA2, 0xA3)}+_MAC_KEYCODES = {"alt": (58, 61), "shift": (56, 60), "ctrl": (59, 62)}+_X11_KEYSYMS = {+ "alt": ("Alt_L", ("Alt_R", "ISO_Level3_Shift")),+ "shift": ("Shift_L", ("Shift_R",)),+ "ctrl": ("Control_L", ("Control_R",)),+}-def _windows_probe() -> Probe | None:++def _windows_probe(family: str) -> Probe | None:import ctypes # noqa: PLC0415user32 = ctypes.WinDLL("user32", use_last_error=True)get_state = user32.GetAsyncKeyStateget_state.argtypes = [ctypes.c_int]get_state.restype = ctypes.c_short- vk_lmenu, vk_rmenu = 0xA4, 0xA5+ left_vk, right_vk = _WIN_VK[family]def probe() -> tuple[bool, bool]:- return bool(get_state(vk_lmenu) & 0x8000), bool(get_state(vk_rmenu) & 0x8000)+ return bool(get_state(left_vk) & 0x8000), bool(get_state(right_vk) & 0x8000)return probe-def _macos_probe() -> Probe | None:+def _macos_probe(family: str) -> Probe | None:import Quartz # type: ignore[import-untyped] # noqa: PLC0415source = Quartz.kCGEventSourceStateHIDSystemStatekey_state = Quartz.CGEventSourceKeyState- left_option, right_option = 58, 61+ left_code, right_code = _MAC_KEYCODES[family]def probe() -> tuple[bool, bool]:- return bool(key_state(source, left_option)), bool(key_state(source, right_option))+ return bool(key_state(source, left_code)), bool(key_state(source, right_code))return probe-def _x11_probe() -> Probe | None:+def _x11_probe(family: str) -> Probe | None:from Xlib import XK # type: ignore[import-untyped] # noqa: PLC0415from Xlib.display import Display # type: ignore[import-untyped] # noqa: PLC0415display = Display()- left = display.keysym_to_keycode(XK.XK_Alt_L)+ left_name, right_names = _X11_KEYSYMS[family]+ left = display.keysym_to_keycode(XK.string_to_keysym(left_name))rights = {code- for code in (- display.keysym_to_keycode(XK.XK_Alt_R),- display.keysym_to_keycode(XK.string_to_keysym("ISO_Level3_Shift")),- )+ for code in (display.keysym_to_keycode(XK.string_to_keysym(n)) for n in right_names)if code}if not left or not rights:@@ -87,27 +104,27 @@ def _x11_probe() -> Probe | None:return probe-def make_probe() -> tuple[Probe | None, str]:- """The key-state reader for this host, or ``None`` and why not."""+def make_probe(family: str = "alt") -> tuple[Probe | None, str]:+ """The key-state reader for ``family`` on this host, or ``None`` and why not."""from jarvis.platform import detect_platform # noqa: PLC0415from jarvis.platform.probes import display_present, is_wayland # noqa: PLC0415platform = detect_platform()try:if platform == "win32":- return _windows_probe(), ""+ return _windows_probe(family), ""if not display_present():return None, "No display on this computer, so there is no keyboard to watch."if platform == "darwin":- return _macos_probe(), ""+ return _macos_probe(family), ""if is_wayland():return None, ("Wayland does not let apps watch global keys. Pick a different ""shortcut in an X11 session, or ask for an appshot by voice.")- probe = _x11_probe()+ probe = _x11_probe(family)if probe is None:- return None, "This keyboard layout has no second Alt key."+ return None, "This keyboard layout has no second key of that kind."return probe, ""except ImportError as exc: # the missing package IS the answer; the caller shows itreturn None, f"The key reader is not installed ({exc.name})."@@ -116,8 +133,8 @@ def make_probe() -> tuple[Probe | None, str]:return None, f"The keyboard could not be read ({type(exc).__name__})."-class BothAltWatcher:- """Calls ``on_fire`` once each time both Alt keys go down together."""+class BothKeysWatcher:+ """Calls ``on_fire`` once each time both keys of a pair go down together."""def __init__(self,@@ -126,6 +143,7 @@ class BothAltWatcher:probe: Probe,poll_s: float = POLL_S,clock: Callable[[], float] | None = None,+ together_s: float | None = None,) -> None:import time # noqa: PLC0415@@ -133,16 +151,18 @@ class BothAltWatcher:self._probe = probeself._poll_s = poll_sself._clock = clock or time.monotonic+ self._together_s = together_sself._stop = threading.Event()self._thread: threading.Thread | None = Noneself._armed = Trueself._last_fire = float("-inf")+ self._first_down: float | None = Nonedef start(self) -> None:if self._thread is not None and self._thread.is_alive():returnself._stop.clear()- self._thread = threading.Thread(target=self._run, name="appshot-alt-alt", daemon=True)+ self._thread = threading.Thread(target=self._run, name="appshot-both-keys", daemon=True)self._thread.start()def stop(self) -> None:@@ -159,10 +179,15 @@ class BothAltWatcher:left, right = stateif not (left or right):self._armed = True+ self._first_down = Nonereturn False+ now = self._clock()+ if self._first_down is None:+ self._first_down = nowif left and right and self._armed:self._armed = False- now = self._clock()+ if self._together_s is not None and now - self._first_down > self._together_s:+ return False # one key held for a while, the other joined: typingif now - self._last_fire < _REFIRE_GUARD_S:return Falsefrom jarvis.platform.self_input import synthetic_input_recent # noqa: PLC0415@@ -182,4 +207,21 @@ class BothAltWatcher:log.debug("appshot: key-state read failed", exc_info=True)-__all__ = ["POLL_S", "BothAltWatcher", "make_probe"]+#: The original name; the both-Alt gesture is the same watcher.+BothAltWatcher = BothKeysWatcher+++def together_window(family: str) -> float | None:+ """Alt keeps its original any-order behaviour; Shift/Ctrl need a joint press."""+ return None if family == "alt" else TOGETHER_S+++__all__ = [+ "GESTURES",+ "POLL_S",+ "TOGETHER_S",+ "BothAltWatcher",+ "BothKeysWatcher",+ "make_probe",+ "together_window",+]diff --git a/jarvis/appshot/hotkey.py b/jarvis/appshot/hotkey.pyindex 30717f07c3..03511e2c75 100644--- a/jarvis/appshot/hotkey.py+++ b/jarvis/appshot/hotkey.py@@ -5,11 +5,12 @@ Two shortcuts, one per scope:* ``[appshot].hotkey`` takes the front window;* ``[appshot].region_hotkey`` first lets the user drag out an area.-Each is either ``alt+alt`` (both Alt keys, watched by-:mod:`jarvis.appshot.gesture`), any combo in the shared hotkey syntax (armed-through the regular per-OS :class:`~jarvis.trigger.hotkey.HotkeyTrigger`), or-empty (off). Only the instance that owns ambient duties arms them — a dev app-beside the live one would otherwise take every appshot twice.+Each is either a both-keys gesture — ``alt+alt``, ``shift+shift`` or+``ctrl+ctrl``, watched by :mod:`jarvis.appshot.gesture` — any combo in the+shared hotkey syntax (armed through the regular per-OS+:class:`~jarvis.trigger.hotkey.HotkeyTrigger`), or empty (off). Only the+instance that owns ambient duties arms them — a dev app beside the live one+would otherwise take every appshot twice."""from __future__ import annotations@@ -23,6 +24,26 @@ from typing import Anylog = logging.getLogger(__name__)BOTH_ALT = "alt+alt"+BOTH_SHIFT = "shift+shift"+BOTH_CTRL = "ctrl+ctrl"+#: Spellings of the two-sided gestures that fold onto their canonical form.+_GESTURE_ALIASES: dict[str, str] = {+ "alt+alt": BOTH_ALT,+ "left_alt+right_alt": BOTH_ALT,+ "right_alt+left_alt": BOTH_ALT,+ "alt+altgr": BOTH_ALT,+ "altgr+alt": BOTH_ALT,+ "alt+right_alt": BOTH_ALT,+ "right_alt+alt": BOTH_ALT,+ "shift+shift": BOTH_SHIFT,+ "left_shift+right_shift": BOTH_SHIFT,+ "right_shift+left_shift": BOTH_SHIFT,+ "ctrl+ctrl": BOTH_CTRL,+ "left_ctrl+right_ctrl": BOTH_CTRL,+ "right_ctrl+left_ctrl": BOTH_CTRL,+ "ctrl+right_ctrl": BOTH_CTRL,+ "right_ctrl+ctrl": BOTH_CTRL,+}#: Scope → the ``[appshot]`` key holding its shortcut.SCOPE_KEYS: dict[str, str] = {"window": "hotkey", "region": "region_hotkey"}@@ -41,11 +62,16 @@ class ShortcutStatus:def normalize_hotkey(value: str) -> str:- """Canonical spelling: lower case, no spaces, both-Alt aliases folded."""+ """Canonical spelling: lower case, no spaces, both-keys aliases folded."""combo = "+".join(part.strip().lower() for part in str(value or "").split("+") if part.strip())- if combo in {"alt+alt", "left_alt+right_alt", "right_alt+left_alt", "alt+altgr", "altgr+alt"}:- return BOTH_ALT- return combo+ return _GESTURE_ALIASES.get(combo, combo)+++def is_gesture(hotkey: str) -> bool:+ """A both-keys gesture, not a combo for the shared hotkey backends."""+ from jarvis.appshot.gesture import GESTURES # noqa: PLC0415++ return hotkey in GESTURESdef configured_hotkeys(block: Any) -> dict[str, str]:@@ -62,7 +88,7 @@ class AppshotShortcut:def __init__(self, bus: Any) -> None:self._bus = busself._loop: asyncio.AbstractEventLoop | None = None- self._watcher: Any | None = None+ self._watchers: list[Any] = []self._trigger_task: asyncio.Task[None] | None = Noneself._busy = Falsenot_started = ShortcutStatus(hotkey="", armed=False, detail="Not started yet.")@@ -113,8 +139,8 @@ class AppshotShortcut:self._statuses[scope] = ShortcutStatus(hotkey, False, "This is already the shortcut for the front window.")- elif hotkey == BOTH_ALT:- self._statuses[scope] = await self._arm_both_alt(scope)+ elif is_gesture(hotkey):+ self._statuses[scope] = await self._arm_gesture(scope, hotkey)else:self._statuses[scope] = self._check_combo(hotkey)if self._statuses[scope].armed:@@ -142,8 +168,8 @@ class AppshotShortcut:return self.statusasync def stop(self) -> None:- watcher, self._watcher = self._watcher, None- if watcher is not None:+ watchers, self._watchers = self._watchers, []+ for watcher in watchers:await asyncio.to_thread(watcher.stop)task, self._trigger_task = self._trigger_task, Noneif task is not None and not task.done():@@ -151,16 +177,26 @@ class AppshotShortcut:with contextlib.suppress(asyncio.CancelledError):await task- async def _arm_both_alt(self, scope: str) -> ShortcutStatus:- from jarvis.appshot.gesture import BothAltWatcher, make_probe # noqa: PLC0415+ async def _arm_gesture(self, scope: str, hotkey: str) -> ShortcutStatus:+ from jarvis.appshot.gesture import ( # noqa: PLC0415+ GESTURES,+ BothKeysWatcher,+ make_probe,+ together_window,+ )- probe, reason = await asyncio.to_thread(make_probe)+ family = GESTURES[hotkey]+ probe, reason = await asyncio.to_thread(make_probe, family)if probe is None:- return ShortcutStatus(hotkey=BOTH_ALT, armed=False, detail=reason)- watcher = BothAltWatcher(lambda: self._fire_threadsafe(scope), probe=probe)+ return ShortcutStatus(hotkey=hotkey, armed=False, detail=reason)+ watcher = BothKeysWatcher(+ lambda: self._fire_threadsafe(scope),+ probe=probe,+ together_s=together_window(family),+ )watcher.start()- self._watcher = watcher- return ShortcutStatus(hotkey=BOTH_ALT, armed=True)+ self._watchers.append(watcher)+ return ShortcutStatus(hotkey=hotkey, armed=True)@staticmethoddef _check_combo(hotkey: str) -> ShortcutStatus:@@ -266,10 +302,13 @@ async def start_appshot_shortcut(bus: Any) -> AppshotShortcut:__all__ = ["BOTH_ALT",+ "BOTH_CTRL",+ "BOTH_SHIFT","SCOPE_KEYS","AppshotShortcut","ShortcutStatus","configured_hotkeys",+ "is_gesture","get_shortcut","normalize_hotkey","start_appshot_shortcut",diff --git a/jarvis/core/config.py b/jarvis/core/config.pyindex 8abfebe29a..8bbf3d34f6 100644--- a/jarvis/core/config.py+++ b/jarvis/core/config.py@@ -2690,16 +2690,18 @@ class AppshotConfig(BaseModel):model_config = {"extra": "allow"}- #: Global shortcut. ``alt+alt`` means both Alt keys pressed together (read- #: by ``jarvis.appshot.gesture``); any other value is an ordinary combo in- #: the shared hotkey syntax; an empty string switches the shortcut off.+ #: Global shortcut. ``alt+alt`` / ``shift+shift`` / ``ctrl+ctrl`` mean both+ #: keys of that pair pressed together (read by ``jarvis.appshot.gesture``);+ #: any other value is an ordinary combo in the shared hotkey syntax; an+ #: empty string switches the shortcut off.hotkey: str = "alt+alt"#: Global shortcut for an AREA appshot: the screens dim, the user drags a#: rectangle, and exactly that part is captured (``jarvis.appshot.region``).- #: Same syntax as ``hotkey``; an empty string switches it off. Alt+Win+A- #: (A for area) collides with no OS screenshot key and no Jarvis default.- region_hotkey: str = "alt+win+a"+ #: Same syntax as ``hotkey``; an empty string switches it off. Both Shift+ #: keys pairs with both-Alt for the window, exists on every keyboard and+ #: collides with no app or OS shortcut.+ region_hotkey: str = "shift+shift"#: Where a shortcut appshot goes. ``auto``: into the running voice call,#: otherwise onto the next message. ``message``: always onto the nextdiff --git a/jarvis/ui/web/appshot_routes.py b/jarvis/ui/web/appshot_routes.pyindex b090202af8..4ba227ac6d 100644--- a/jarvis/ui/web/appshot_routes.py+++ b/jarvis/ui/web/appshot_routes.py@@ -116,9 +116,9 @@ async def get_settings() -> dict[str, Any]:async def put_settings(request: Request, patch: SettingsPatch) -> dict[str, Any]:"""Write the changed switches, then re-arm the shortcut in place."""from jarvis.appshot.hotkey import ( # noqa: PLC0415- BOTH_ALT,configured_hotkeys,get_shortcut,+ is_gesture,normalize_hotkey,)from jarvis.core.config import load_config # noqa: PLC0415@@ -135,7 +135,7 @@ async def put_settings(request: Request, patch: SettingsPatch) -> dict[str, Any]if key not in changes:continuechanges[key] = normalize_hotkey(changes[key])- if changes[key] and changes[key] != BOTH_ALT:+ if changes[key] and not is_gesture(changes[key]):from jarvis.trigger.hotkey import validate_hotkey # noqa: PLC0415verdict = validate_hotkey(changes[key])diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.jsonindex f4ad1eaae7..d5bfaa3b54 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json@@ -5969,6 +5969,14 @@"region_shortcut_label": "Kürzel für einen Bereich","region_shortcut_hint": "Drücke {0} und ziehe dann über den Teil des Bildschirms, den du zeigen willst.","region_shortcut_hint_off": "Kein Kürzel. Nutze unten „Bereich wählen“.",+ "shortcut_change": "Ändern",+ "shortcut_cancel": "Abbrechen",+ "shortcut_clear": "Dieses Kürzel ausschalten",+ "shortcut_recording": "Neue Tasten drücken…",+ "shortcut_recording_hint": "Tasten halten, dann loslassen. Beide Alt-, beide Shift- oder beide Strg-Tasten zusammen gehen auch. Esc bricht ab.",+ "shortcut_modifier_only": "Eine Sondertaste allein ist kein Kürzel. Nimm einen Buchstaben dazu oder drücke dieselbe Taste auf beiden Seiten der Tastatur.",+ "shortcut_both_keys_hint": "Drücke beide {0}-Tasten gleichzeitig",+ "region_shortcut_both_keys_hint": "Drücke beide {0}-Tasten zusammen und ziehe dann über den Teil des Bildschirms, den du zeigen willst.","target_label": "Appshot-Ziel","target_auto": "Automatisch","target_message": "Nächste Nachricht",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.jsonindex dfe8b484c1..3c95824533 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json@@ -6002,6 +6002,14 @@"region_shortcut_label": "Area shortcut","region_shortcut_hint": "Press {0}, then drag over the part of the screen you want to show.","region_shortcut_hint_off": "No shortcut. Use \"Select area\" below instead.",+ "shortcut_change": "Change",+ "shortcut_cancel": "Cancel",+ "shortcut_clear": "Turn this shortcut off",+ "shortcut_recording": "Press the new keys…",+ "shortcut_recording_hint": "Hold the keys, then let go. Both Alt, both Shift or both Ctrl keys together work too. Esc cancels.",+ "shortcut_modifier_only": "One modifier key alone is not a shortcut. Add a letter, or press the same key on both sides of the keyboard.",+ "shortcut_both_keys_hint": "Press both {0} keys at the same time",+ "region_shortcut_both_keys_hint": "Press both {0} keys together, then drag over the part of the screen you want to show.","target_label": "Appshot destination","target_auto": "Automatic","target_message": "Next message",diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.jsonindex 51b7d88c06..9870a7ed65 100644--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json@@ -5969,6 +5969,14 @@"region_shortcut_label": "Atajo para una zona","region_shortcut_hint": "Pulsa {0} y arrastra sobre la parte de la pantalla que quieres mostrar.","region_shortcut_hint_off": "Sin atajo. Usa «Elegir zona» más abajo.",+ "shortcut_change": "Cambiar",+ "shortcut_cancel": "Cancelar",+ "shortcut_clear": "Desactivar este atajo",+ "shortcut_recording": "Pulsa las nuevas teclas…",+ "shortcut_recording_hint": "Mantén las teclas y suéltalas. También sirven las dos Alt, las dos Mayús o las dos Ctrl a la vez. Esc cancela.",+ "shortcut_modifier_only": "Una tecla modificadora sola no es un atajo. Añade una letra o pulsa la misma tecla a ambos lados del teclado.",+ "shortcut_both_keys_hint": "Pulsa las dos teclas {0} a la vez",+ "region_shortcut_both_keys_hint": "Pulsa las dos teclas {0} a la vez y arrastra sobre la parte de la pantalla que quieres mostrar.","target_label": "Destino del appshot","target_auto": "Automático","target_message": "Siguiente mensaje",diff --git a/jarvis/ui/web/frontend/src/lib/appshotApi.ts b/jarvis/ui/web/frontend/src/lib/appshotApi.tsindex a67882497f..323dda617d 100644--- a/jarvis/ui/web/frontend/src/lib/appshotApi.ts+++ b/jarvis/ui/web/frontend/src/lib/appshotApi.ts@@ -122,7 +122,7 @@ export async function claimPendingAppshot(meta: AppshotMeta): Promise<File | nulreturn new File([blob], `appshot-${stamp}.${extension}`, { type: blob.type || "image/jpeg" });}-/** "alt+alt" → "Alt + Alt" (⌥ on a Mac); any other combo, title-cased. */+/** "alt+alt" → "Alt + Alt" (⌥ on a Mac), "shift+shift" → "Shift + Shift"; any other combo, title-cased. */export function formatAppshotHotkey(hotkey: string, isMac: boolean): string {if (!hotkey) return "";if (hotkey === "alt+alt") return isMac ? "⌥ + ⌥" : "Alt + Alt";@@ -133,6 +133,7 @@ export function formatAppshotHotkey(hotkey: string, isMac: boolean): string {if (key === "ctrl") return isMac ? "⌃" : "Ctrl";if (key === "alt") return isMac ? "⌥" : "Alt";if (key === "shift") return isMac ? "⇧" : "Shift";+ if (key === "right_alt") return isMac ? "⌥" : "AltGr";if (key === "win" || key === "cmd" || key === "super") return isMac ? "⌘" : "Win";return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);})diff --git a/jarvis/ui/web/frontend/src/lib/appshotChord.test.ts b/jarvis/ui/web/frontend/src/lib/appshotChord.test.tsnew file mode 100644index 0000000000..9b930b347e--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/appshotChord.test.ts@@ -0,0 +1,29 @@+import { describe, expect, it } from "vitest";++import { chordFromCodes, gestureFamily } from "@/lib/appshotChord";++describe("chordFromCodes", () => {+ it("records both keys of a pair as the two-sided gesture", () => {+ expect(chordFromCodes(["ShiftLeft", "ShiftRight"])).toEqual({ combo: "shift+shift" });+ expect(chordFromCodes(["ControlRight", "ControlLeft"])).toEqual({ combo: "ctrl+ctrl" });+ expect(chordFromCodes(["AltLeft", "AltRight"])).toEqual({ combo: "alt+alt" });+ });++ it("records an ordinary combo with modifiers first", () => {+ expect(chordFromCodes(["KeyS", "ShiftLeft", "ControlLeft"])).toEqual({+ combo: "ctrl+shift+s",+ });+ expect(chordFromCodes(["F9"])).toEqual({ combo: "f9" });+ });++ it("refuses a lone modifier and ignores Escape", () => {+ expect(chordFromCodes(["ShiftLeft"])).toEqual({ problem: "modifier_only" });+ expect(chordFromCodes(["ShiftLeft", "ControlLeft"])).toEqual({ problem: "modifier_only" });+ expect(chordFromCodes(["Escape"])).toEqual({ problem: "empty" });+ });++ it("names the family of a gesture and nothing else", () => {+ expect(gestureFamily("shift+shift")).toBe("shift");+ expect(gestureFamily("ctrl+shift+s")).toBeNull();+ });+});diff --git a/jarvis/ui/web/frontend/src/lib/appshotChord.ts b/jarvis/ui/web/frontend/src/lib/appshotChord.tsnew file mode 100644index 0000000000..a66a3f5651--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/appshotChord.ts@@ -0,0 +1,50 @@+/**+ * Turn the physical keys of one recorded gesture into an appshot shortcut.+ *+ * Besides ordinary combos ("ctrl+shift+s") the appshot shortcuts accept the+ * two-sided gestures the backend watches itself (`jarvis/appshot/gesture.py`):+ * both Alt, both Shift or both Ctrl keys pressed together. Those are told+ * apart by `event.code` (left vs right), which the shared combo helpers fold+ * into one modifier token.+ */+import {+ codeToKeyToken,+ codeToModifierToken,+ composeCombo,+ isModifierToken,+} from "@/hooks/useHotkey";++export type ChordResult = { combo: string } | { problem: "modifier_only" | "empty" };++const GESTURES: ReadonlyArray<[string, string, string]> = [+ ["AltLeft", "AltRight", "alt+alt"],+ ["ShiftLeft", "ShiftRight", "shift+shift"],+ ["ControlLeft", "ControlRight", "ctrl+ctrl"],+];++/** Every key that was down during the gesture → the shortcut it means. */+export function chordFromCodes(codes: Iterable<string>): ChordResult {+ const set = new Set(codes);+ set.delete("Escape");+ if (set.size === 0) return { problem: "empty" };+ if (set.size === 2) {+ for (const [left, right, gesture] of GESTURES) {+ if (set.has(left) && set.has(right)) return { combo: gesture };+ }+ }+ const tokens = new Set<string>();+ for (const code of set) {+ const token = codeToModifierToken(code) ?? codeToKeyToken(code);+ if (token) tokens.add(token);+ }+ if (![...tokens].some((token) => !isModifierToken(token))) return { problem: "modifier_only" };+ return { combo: composeCombo(tokens) };+}++/** "shift+shift" → "shift", for the "press both … keys" hints. */+export function gestureFamily(hotkey: string): "alt" | "shift" | "ctrl" | null {+ if (hotkey === "alt+alt") return "alt";+ if (hotkey === "shift+shift") return "shift";+ if (hotkey === "ctrl+ctrl") return "ctrl";+ return null;+}diff --git a/jarvis/ui/web/frontend/src/views/AppshotShortcutField.tsx b/jarvis/ui/web/frontend/src/views/AppshotShortcutField.tsxnew file mode 100644index 0000000000..feec71e3d9--- /dev/null+++ b/jarvis/ui/web/frontend/src/views/AppshotShortcutField.tsx@@ -0,0 +1,159 @@+import { Fragment, useCallback, useEffect, useRef, useState } from "react";+import { Loader2, X } from "lucide-react";++import { Button } from "@/components/ui/button";+import { useT } from "@/i18n";+import { formatAppshotHotkey } from "@/lib/appshotApi";+import { chordFromCodes } from "@/lib/appshotChord";+import { cn } from "@/lib/utils";++/**+ * One appshot shortcut: the current keys as keycaps, a Change button that+ * records the next key gesture, and an off switch (X).+ *+ * Recording listens on `window` in the capture phase, so the keys never reach+ * the rest of the app, and commits when every key is let go — "hold your keys,+ * then let go", like the voice keybinds. Both Alt / both Shift / both Ctrl keys+ * on their own record as the two-sided gestures the backend watches. Esc (on+ * its own) or leaving the window cancels and keeps the old shortcut.+ */+export function AppshotShortcutField({+ value,+ isMac,+ disabled,+ testId,+ onSave,+}: {+ value: string;+ isMac: boolean;+ disabled: boolean;+ testId: string;+ onSave: (hotkey: string) => Promise<void>;+}) {+ const t = useT();+ const [recording, setRecording] = useState(false);+ const [saving, setSaving] = useState(false);+ const [problem, setProblem] = useState("");+ const onSaveRef = useRef(onSave);+ onSaveRef.current = onSave;++ const commit = useCallback(async (hotkey: string) => {+ setSaving(true);+ try {+ await onSaveRef.current(hotkey);+ } finally {+ setSaving(false);+ }+ }, []);++ useEffect(() => {+ if (!recording) return;+ const pressed = new Set<string>();+ const seen = new Set<string>();++ const stop = () => setRecording(false);+ const onKeyDown = (event: KeyboardEvent) => {+ event.preventDefault();+ event.stopPropagation();+ if (event.repeat) return;+ if (event.code === "Escape" && seen.size === 0) {+ stop();+ return;+ }+ pressed.add(event.code);+ seen.add(event.code);+ };+ const onKeyUp = (event: KeyboardEvent) => {+ event.preventDefault();+ event.stopPropagation();+ pressed.delete(event.code);+ if (pressed.size > 0 || seen.size === 0) return;+ stop();+ const result = chordFromCodes(seen);+ if ("combo" in result) {+ setProblem("");+ if (result.combo !== value) void commit(result.combo);+ } else if (result.problem === "modifier_only") {+ setProblem(t("appshots.shortcut_modifier_only"));+ }+ };++ window.addEventListener("keydown", onKeyDown, true);+ window.addEventListener("keyup", onKeyUp, true);+ window.addEventListener("blur", stop);+ return () => {+ window.removeEventListener("keydown", onKeyDown, true);+ window.removeEventListener("keyup", onKeyUp, true);+ window.removeEventListener("blur", stop);+ };+ }, [recording, value, commit, t]);++ const keys = value ? formatAppshotHotkey(value, isMac).split(" + ") : [];++ return (+ <div className="flex flex-col items-end gap-1" data-testid={testId}>+ <div className="flex items-center gap-2">+ <div+ className={cn(+ "flex min-h-8 min-w-28 items-center justify-end gap-1 rounded-md px-2",+ recording && "bg-accent/10 ring-1 ring-accent",+ )}+ aria-live="polite"+ >+ {recording ? (+ <span className="text-sm text-foreground">{t("appshots.shortcut_recording")}</span>+ ) : keys.length > 0 ? (+ keys.map((key, i) => (+ <Fragment key={`${key}-${i}`}>+ {i > 0 && <span className="text-xs text-muted-foreground/60">+</span>}+ <kbd className="rounded border border-border bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground shadow-[inset_0_-1px_0_rgba(0,0,0,0.25)]">+ {key}+ </kbd>+ </Fragment>+ ))+ ) : (+ <span className="text-sm text-muted-foreground">{t("appshots.shortcut_off")}</span>+ )}+ </div>+ <Button+ type="button"+ variant="secondary"+ size="sm"+ disabled={disabled || saving}+ onClick={() => {+ setProblem("");+ setRecording((on) => !on);+ }}+ data-testid={`${testId}-change`}+ >+ {saving && <Loader2 className="animate-spin" aria-hidden />}+ {recording ? t("appshots.shortcut_cancel") : t("appshots.shortcut_change")}+ </Button>+ {value && !recording && (+ <Button+ type="button"+ variant="ghost"+ size="sm"+ disabled={disabled || saving}+ aria-label={t("appshots.shortcut_clear")}+ title={t("appshots.shortcut_clear")}+ onClick={() => void commit("")}+ data-testid={`${testId}-clear`}+ >+ <X aria-hidden />+ </Button>+ )}+ </div>+ {recording && (+ <p className="max-w-72 text-right text-xs text-muted-foreground">+ {t("appshots.shortcut_recording_hint")}+ </p>+ )}+ {!recording && problem && (+ <p className="max-w-72 text-right text-xs text-destructive" role="alert">+ {problem}+ </p>+ )}+ </div>+ );+}diff --git a/jarvis/ui/web/frontend/src/views/AppshotsView.test.tsx b/jarvis/ui/web/frontend/src/views/AppshotsView.test.tsxindex 256def2853..6b81a09bdc 100644--- a/jarvis/ui/web/frontend/src/views/AppshotsView.test.tsx+++ b/jarvis/ui/web/frontend/src/views/AppshotsView.test.tsx@@ -159,6 +159,68 @@ describe("AppshotsView area appshots", () => {});});+describe("AppshotsView shortcut recorder", () => {+ let fetchMock: ReturnType<typeof vi.fn>;++ beforeEach(() => {+ useEventStore.setState({ events: [], toasts: [], assistantName: "Jarvis" });+ fetchMock = vi.fn(async (url: string, init?: RequestInit) => {+ if (url === "/api/appshot/settings" && init?.method === "PUT") {+ return json({ ...SETTINGS, ...JSON.parse(String(init.body)) });+ }+ if (url === "/api/appshot/settings") return json(SETTINGS);+ return json({ appshot: null });+ });+ vi.stubGlobal("fetch", fetchMock);+ });++ afterEach(() => {+ cleanup();+ vi.unstubAllGlobals();+ });++ const puts = () =>+ fetchMock.mock.calls+ .filter(([url, init]) => url === "/api/appshot/settings" && init?.method === "PUT")+ .map(([, init]) => JSON.parse(String(init.body)));++ function press(codes: string[]) {+ for (const code of codes) fireEvent.keyDown(window, { code, key: code });+ for (const code of [...codes].reverse()) fireEvent.keyUp(window, { code, key: code });+ }++ it("records both Shift keys as the area shortcut", async () => {+ render(<AppshotsView />);+ fireEvent.click(await screen.findByTestId("appshots-region-hotkey-change"));+ press(["ShiftLeft", "ShiftRight"]);+ await waitFor(() => expect(puts()).toEqual([{ region_hotkey: "shift+shift" }]));+ });++ it("records an ordinary combo for the window shortcut", async () => {+ render(<AppshotsView />);+ fireEvent.click(await screen.findByTestId("appshots-hotkey-change"));+ press(["ControlLeft", "ShiftLeft", "KeyS"]);+ await waitFor(() => expect(puts()).toEqual([{ hotkey: "ctrl+shift+s" }]));+ });++ it("Esc cancels without saving, and a lone modifier explains itself", async () => {+ render(<AppshotsView />);+ const change = await screen.findByTestId("appshots-hotkey-change");+ fireEvent.click(change);+ press(["Escape"]);+ fireEvent.click(change);+ press(["ShiftLeft"]);+ await screen.findByRole("alert");+ expect(puts()).toEqual([]);+ });++ it("the X turns a shortcut off", async () => {+ render(<AppshotsView />);+ fireEvent.click(await screen.findByTestId("appshots-region-hotkey-clear"));+ await waitFor(() => expect(puts()).toEqual([{ region_hotkey: "" }]));+ });+});+describe("formatAppshotHotkey", () => {it("names the both-Alt gesture per platform", () => {expect(formatAppshotHotkey("alt+alt", false)).toBe("Alt + Alt");diff --git a/jarvis/ui/web/frontend/src/views/AppshotsView.tsx b/jarvis/ui/web/frontend/src/views/AppshotsView.tsxindex f069db5c6c..1fda7ece06 100644--- a/jarvis/ui/web/frontend/src/views/AppshotsView.tsx+++ b/jarvis/ui/web/frontend/src/views/AppshotsView.tsx@@ -18,7 +18,9 @@ import {type AppshotSettings,type AppshotSettingsPatch,} from "@/lib/appshotApi";+import { gestureFamily } from "@/lib/appshotChord";import { cn } from "@/lib/utils";+import { AppshotShortcutField } from "@/views/AppshotShortcutField";import { useEventStore } from "@/store/events";/**@@ -34,8 +36,13 @@ import { useEventStore } from "@/store/events";*/const IS_MAC = typeof navigator !== "undefined" && /Mac/i.test(navigator.platform || "");-const PRESET_HOTKEYS = ["alt+alt", "ctrl+alt+a", ""] as const;-const REGION_PRESET_HOTKEYS = ["alt+win+a", "ctrl+alt+s", ""] as const;++/** The key a two-sided gesture is made of, as printed on this keyboard. */+function gestureKeyName(family: "alt" | "shift" | "ctrl"): string {+ if (family === "alt") return IS_MAC ? "Option" : "Alt";+ if (family === "ctrl") return IS_MAC ? "Control" : "Ctrl";+ return "Shift";+}const TRY_DELAY_S = 3;export function AppshotGlyph({ className }: { className?: string }) {@@ -122,21 +129,6 @@ function PreviewDemo() {);}-function shortcutOptions(- presets: readonly string[],- current: string,- offLabel: string,-): BrandedSelectOption[] {- const options: BrandedSelectOption[] = presets.map((value) => ({- value: value || "off",- label: value ? formatAppshotHotkey(value, IS_MAC) : offLabel,- }));- if (current && !presets.includes(current)) {- options.unshift({ value: current, label: formatAppshotHotkey(current, IS_MAC) });- }- return options;-}-function deliveredLabel(t: (key: string) => string, deliveredTo: string): string {switch (deliveredTo) {case "voice":@@ -292,19 +284,6 @@ export function AppshotsView() {}}, [pushToast]);- const hotkeyOptions = useMemo(- () => shortcutOptions(PRESET_HOTKEYS, settings?.hotkey ?? "", t("appshots.shortcut_off")),- [settings?.hotkey, t],- );- const regionHotkeyOptions = useMemo(- () =>- shortcutOptions(- REGION_PRESET_HOTKEYS,- settings?.region_hotkey ?? "",- t("appshots.shortcut_off"),- ),- [settings?.region_hotkey, t],- );const targetOptions = useMemo<BrandedSelectOption[]>(() => [@@ -324,6 +303,10 @@ export function AppshotsView() {if (settings.hotkey === "alt+alt") {return IS_MAC ? t("appshots.shortcut_both_option_hint") : t("appshots.shortcut_both_alt_hint");}+ const family = gestureFamily(settings.hotkey);+ if (family) {+ return t("appshots.shortcut_both_keys_hint").replace("{0}", gestureKeyName(family));+ }return t("appshots.shortcut_combo_hint").replace("{0}",formatAppshotHotkey(settings.hotkey, IS_MAC),@@ -343,6 +326,10 @@ export function AppshotsView() {if (settings.enabled && !settings.region_shortcut.armed && settings.region_shortcut.detail) {return t("appshots.shortcut_unavailable").replace("{0}", settings.region_shortcut.detail);}+ const family = gestureFamily(settings.region_hotkey);+ if (family) {+ return t("appshots.region_shortcut_both_keys_hint").replace("{0}", gestureKeyName(family));+ }return t("appshots.region_shortcut_hint").replace("{0}",formatAppshotHotkey(settings.region_hotkey, IS_MAC),@@ -400,14 +387,12 @@ export function AppshotsView() {label={t("appshots.shortcut_label")}hint={shortcutHint}control={- <BrandedSelect- value={settings.hotkey || "off"}- options={hotkeyOptions}- ariaLabel={t("appshots.shortcut_label")}+ <AppshotShortcutField+ value={settings.hotkey}+ isMac={IS_MAC}disabled={disabled || saving}testId="appshots-hotkey"- className="w-44"- onValueChange={(value) => void save({ hotkey: value === "off" ? "" : value })}+ onSave={(hotkey) => save({ hotkey })}/>}/>@@ -416,16 +401,12 @@ export function AppshotsView() {label={t("appshots.region_shortcut_label")}hint={regionShortcutHint}control={- <BrandedSelect- value={settings.region_hotkey || "off"}- options={regionHotkeyOptions}- ariaLabel={t("appshots.region_shortcut_label")}+ <AppshotShortcutField+ value={settings.region_hotkey}+ isMac={IS_MAC}disabled={disabled || saving}testId="appshots-region-hotkey"- className="w-44"- onValueChange={(value) =>- void save({ region_hotkey: value === "off" ? "" : value })- }+ onSave={(regionHotkey) => save({ region_hotkey: regionHotkey })}/>}/>diff --git a/tests/unit/appshot/test_appshot_region.py b/tests/unit/appshot/test_appshot_region.pyindex 5c8ac42af8..32b5fc43d5 100644--- a/tests/unit/appshot/test_appshot_region.py+++ b/tests/unit/appshot/test_appshot_region.py@@ -502,3 +502,157 @@ def test_window_rects_land_on_the_picker_screen_in_logical_pixels() -> None:def test_no_monitors_means_no_snap_targets() -> None:screen = {"x": 0, "y": 0, "w": 100, "h": 100, "dpr": 1}assert region.snap_rects_on_screen(screen, (100, 100), [], [[0, 0, 50, 50]], min_px=1) == []+++# ---------------------------------------------------------- two-sided gestures+++ ("raw", "expected"),+ [+ ("Shift+Shift", "shift+shift"),+ ("left_shift + right_shift", "shift+shift"),+ ("right_ctrl+left_ctrl", "ctrl+ctrl"),+ ("ctrl+right_ctrl", "ctrl+ctrl"),+ ("alt+right_alt", "alt+alt"),+ ("ctrl+shift+s", "ctrl+shift+s"),+ ],+)+def test_two_sided_gestures_fold_to_one_spelling(raw: str, expected: str) -> None:+ from jarvis.appshot.hotkey import is_gesture, normalize_hotkey++ assert normalize_hotkey(raw) == expected+ assert is_gesture(expected) == (expected != "ctrl+shift+s")+++class _Keys:+ def __init__(self) -> None:+ self.state = (False, False)++ def __call__(self):+ return self.state+++class _Clock:+ def __init__(self) -> None:+ self.now = 10.0++ def __call__(self) -> float:+ return self.now+++def _watcher(monkeypatch, together_s):+ import jarvis.platform.self_input as self_input+ from jarvis.appshot.gesture import BothKeysWatcher++ monkeypatch.setattr(self_input, "synthetic_input_recent", lambda *a, **k: False)+ keys, clock, fired = _Keys(), _Clock(), []+ watcher = BothKeysWatcher(+ lambda: fired.append(1), probe=keys, clock=clock, together_s=together_s+ )+ return watcher, keys, clock, fired+++def test_both_shift_pressed_together_fires(monkeypatch) -> None:+ watcher, keys, clock, fired = _watcher(monkeypatch, 0.5)+ keys.state = (True, False)+ watcher.step()+ clock.now += 0.1+ keys.state = (True, True)+ assert watcher.step()+ assert fired == [1]+++def test_holding_one_shift_while_typing_then_the_other_does_not_fire(monkeypatch) -> None:+ watcher, keys, clock, fired = _watcher(monkeypatch, 0.5)+ keys.state = (True, False)+ watcher.step()+ clock.now += 1.5 # typing capitals with the left Shift+ keys.state = (True, True)+ assert not watcher.step()+ keys.state = (False, False)+ watcher.step()+ clock.now += 1.0+ keys.state = (True, True)+ assert watcher.step(), "after letting go, a real joint press works again"+ assert fired == [1]+++def test_alt_keeps_its_any_order_behaviour(monkeypatch) -> None:+ watcher, keys, clock, fired = _watcher(monkeypatch, None)+ keys.state = (True, False)+ watcher.step()+ clock.now += 2.0+ keys.state = (True, True)+ assert watcher.step()+++async def test_two_gestures_arm_two_watchers(monkeypatch) -> None:+ import jarvis.appshot.gesture as gesture+ import jarvis.appshot.hotkey as hotkey_module+ import jarvis.core.config as config_module+ import jarvis.core.instance as instance_module++ class Cfg:+ class appshot: # noqa: N801+ hotkey = "alt+alt"+ region_hotkey = "shift+shift"++ families: list = []+ started: list = []++ def make_probe(family="alt"):+ families.append(family)+ return (lambda: (False, False)), ""++ class Watcher:+ def __init__(self, on_fire, *, probe, together_s=None):+ self.together_s = together_s++ def start(self):+ started.append(self.together_s)++ def stop(self):+ started.remove(self.together_s)++ monkeypatch.setattr(config_module, "load_config", lambda: Cfg)+ monkeypatch.setattr(instance_module, "current_instance", lambda: _Instance())+ monkeypatch.setattr(gesture, "make_probe", make_probe)+ monkeypatch.setattr(gesture, "BothKeysWatcher", Watcher)++ shortcut = hotkey_module.AppshotShortcut(bus=object())+ await shortcut.reload()++ assert families == ["alt", "shift"]+ assert sorted(started, key=str) == [0.5, None]+ assert shortcut.status_for("window").armed and shortcut.status_for("region").armed+ await shortcut.stop()+ assert started == []+++def test_a_gesture_passes_the_settings_route(client, monkeypatch) -> None:+ import jarvis.core.config as config_module+ import jarvis.core.config_writer as writer++ class Cfg:+ class appshot: # noqa: N801+ hotkey = "alt+alt"+ region_hotkey = "alt+win+a"+ target = "auto"+ sound = True+ effect = True++ class screen_context: # noqa: N801+ enabled = True++ class ui: # noqa: N801+ sound_effects = True++ writes: list = []+ monkeypatch.setattr(config_module, "load_config", lambda: Cfg)+ monkeypatch.setattr(writer, "set_appshot_settings", lambda values: writes.append(values))++ response = client.put("/api/appshot/settings", json={"region_hotkey": "Left_Shift+Right_Shift"})++ assert response.status_code == 200, response.text+ assert writes == [{"region_hotkey": "shift+shift"}]