Skip to content

Tray: keep looking for a wireless device after its receiver comes back (dock reconnect, replaces #84) - #92

Merged
infinityInfinite merged 1 commit into
infinityInfinite:mainfrom
a3k7dotmd:dock-reconnect-one-raw-input
Nov 21, 2026
Merged

infinityInfinite merged 1 commit into
infinityInfinite:mainfrom
a3k7dotmd:dock-reconnect-one-raw-input

Conversation

@a3k7dotmd

Copy link
Copy Markdown
Contributor

Replaces #84: the same fix rebuilt on main (0.6.0), with the two changes you asked for there. Text below and fix is by Fable 5.2 reviewed by GPT-6 Astra. Deployment tested working by me.

Problem

A wireless keyboard whose receiver sits on a Thunderbolt dock stops being managed after the dock is unplugged and plugged back in. The receiver is back within seconds, but the keyboard behind it doesn't answer until its next key press. The tray looks once, 1.5 s after the arrival, finds the keyboard silent, and never looks again. The editor lists it under "Connected, not controllable yet" until Rescan is clicked. The evidence is in #84.

What changed since #84

  • Raw input has one owner. input.rs is the only place that calls RegisterRawInputDevices. Input keeps who needs input (the Studio, and the watch for a device that is asleep, by its kind) and what is registered, and registers what the two need together, one usage at a time: keyboards while the Studio or a keyboard watch needs them, mice while the Studio or a mouse watch needs them. One of the two stopping never drops what the other uses. Input::want keeps its signature, so studio_tick is untouched; the watch uses the new Input::watch.
  • One WM_INPUT handler. Input::read now answers for every input from a Razer device (Seen { pid, press }), not only for presses. The handler gives a press to Studio::press as before, then the product id to the watch. While the Studio doesn't listen, only the header is read (RID_HEADER): which device sent it, never what it sent. The fix's own raw input code in win.rs is gone; the handle cache is Input::pids and the matching is parse_pid, both as they were.
  • Retries only while a device is asleep. A Razer arrival no longer starts the retries. It is followed by the one rescan it had before, and the retries start only if that look still finds a known wireless device asleep. The same goes for input from a sleeping device. Retries started this way end as soon as nothing is asleep, without another rescan. So with nothing asleep an arrival costs exactly what it costs on main, and in the dock case no rescan runs after the key press found the keyboard. The retries after tray start and wake are unchanged.
  • One line of Input differs from main's rule. A registration is noted as changed only when Windows accepted the call (if RegisterRawInputDevices(...) != 0 { *on = want; }), where main has self.on = on && ok. A refused registration is asked for again on the next tick, as before. A refused removal now is too, instead of being taken as done: with two users of the registration, a removal that didn't happen would leave input coming in for nobody.
  • The editor leaves the Settings page alone. The automatic refresh already waited while an editor panel was open. It now also waits while Settings is open, and shows the change once it is closed: drawing Settings again dropped a battery level being typed and the result of "Check now". A backup import clears the page's note of which list it shows, since it takes only the devices of its answer; the next tick fetches the whole list.

Kept from #84 as it was: the 5-wake limit and the flood cut-off, the retry counter outside App, the message to the tray after the server's own rescans, the list counter in /api/live and in the state, and the log lines.

New tests

  • input::tests::the_studio_and_the_watch_need_one_registration: what is registered for each combination of the two.
  • input::tests::one_listener_stopping_keeps_the_other_registered: the same against Windows itself. It creates a message-only window, starts and stops the Studio and the watch in the orders that clashed, and reads the process's registrations back with GetRegisteredRawInputDevices.
  • names_and_pids also checks the path of a DeathStalker V2 Pro receiver.

Tested

  • Setup: Windows 11 26H2, 20 Nov 2026. DeathStalker V2 Pro (Wireless, 0290), its receiver on a Thunderbolt dock, sleeping off, Synapse not installed.
  • Build: this branch (0.6.0), cross-built on Linux for x86_64-pc-windows-gnu (rustc 1.100.0, mingw-w64). 0.6.0 was installed from the release, then only secbird-tray.exe was replaced.
  • Dock unplugged and plugged back in, then keys pressed. Windows logged the receiver's removal at 16:47:34 and its arrival at 16:47:48 (UTC); the tray's log:
    2026-11-20 16:47:36Z gone: DeathStalker V2 Pro (Wireless)
    2026-11-20 16:47:50Z not answering: DeathStalker V2 Pro (Wireless) (asleep?), looking again at its next key press or movement
    2026-11-20 16:48:00Z input from DeathStalker V2 Pro (Wireless): looking for it again
    2026-11-20 16:48:01Z found: DeathStalker V2 Pro (Wireless)
    
    The look after the arrival found the keyboard silent; the key press found it 1 s later. This keyboard's first key press after a reconnect only wakes its radio link and never reaches Windows, so input from is the second press.
  • Idle cost: after found: the tray used 0.000 s of processor time over 30 s.
  • Checks: cargo clippy --release --target x86_64-pc-windows-gnu --all-targets -- -D warnings is clean. Unit tests: 135 (core) and 7 (tray) pass on Windows, 128 and 1 pass on Linux. node --test crates/secbird-tray/tests/*.test.cjs passes. The page's refresh logic passes 31 checks against a fake tray API in Node (a small script outside this change; I can add it under crates/secbird-tray/tests/ if it is wanted).

A receiver that is plugged back in (its Thunderbolt dock was reconnected)
answers within seconds, but the keyboard or mouse behind it stays silent
until its next key press. A device arrival got one rescan 1.5 s later and
no retries, so the device stayed under "Connected, not controllable yet"
until Rescan was clicked in the editor.

This is infinityInfinite#84 rebuilt on 0.6.0, with the two changes asked for there.

- Raw input has one owner, `input.rs`. It registers keyboards and mice
  while the Studio (Reactive, Ripple) or the watch for a device that is
  asleep needs them, one kind at a time, so one of the two stopping never
  drops what the other uses. One `WM_INPUT` handler gives each input to
  both: the press to the Studio, the sender to the watch.
- While a known wireless device is asleep, the watch asks for input of its
  kind (keyboards and keypads, or mice). Only which device sent it is read
  while the Studio doesn't listen. Input from the sleeping device starts a
  look for it, however long it slept; at most 5 times until it answers.
- A Razer arrival, or input from a sleeping device, is followed by one
  look. The retries (4 s, 15 s, 45 s, then once a minute for half an hour)
  start only if that look still finds a known wireless device asleep, and
  end as soon as none is. With nothing asleep an arrival costs the one
  rescan it cost before. The retries after tray start and wake are as they
  were.
- The retry counter is no longer part of `App`, so a wake that comes in
  while `App` is borrowed still starts the retries over, and a retry that
  comes in at such a moment is tried again instead of dropped.
- `Input` notes a registration as changed only when Windows accepted the
  call, so a refused removal is asked for again.
- The editor's server tells the tray when it rescanned by itself, and an
  open editor shows a device the tray found or lost without a click on
  Rescan (a list counter in /api/live and in the state). An open editor
  panel and the Settings page are left alone and the change is shown once
  they are closed.
- Log: "gone: <names>", "not answering: <names> (asleep?), looking again
  at its next key press or movement", "input from <name>: looking for it
  again".

Tested on a DeathStalker V2 Pro (Wireless, 0290) whose receiver sits on a
Thunderbolt dock: found 1 s after the first key press that reached Windows.
@infinityInfinite
infinityInfinite merged commit eee379c into infinityInfinite:main Nov 21, 2026
3 checks passed
@infinityInfinite

Copy link
Copy Markdown
Owner

Merged, thanks. The shared registration in input.rs is the right fix, and the test against GetRegisteredRawInputDevices is the check I wanted. I ran it with #93 on 0.6.0 + the Chinese editor: clippy clean, all tests pass, and Reactive on a Basilisk V3 still reacts to every click with the watch code in. It goes out in 0.6.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants