Repository navigation
Tray: keep looking for a wireless device after its receiver comes back (dock reconnect, replaces #84) - #92
Merged
infinityInfinite merged 1 commit intoNov 21, 2026
Conversation
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.
This was referenced Nov 20, 2026
Owner
|
Merged, thanks. The shared registration in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
input.rsis the only place that callsRegisterRawInputDevices.Inputkeeps 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::wantkeeps its signature, sostudio_tickis untouched; the watch uses the newInput::watch.WM_INPUThandler.Input::readnow answers for every input from a Razer device (Seen { pid, press }), not only for presses. The handler gives a press toStudio::pressas 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 inwin.rsis gone; the handle cache isInput::pidsand the matching isparse_pid, both as they were.Inputdiffers from main's rule. A registration is noted as changed only when Windows accepted the call (if RegisterRawInputDevices(...) != 0 { *on = want; }), where main hasself.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.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, thelistcounter in/api/liveand 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 withGetRegisteredRawInputDevices.names_and_pidsalso checks the path of a DeathStalker V2 Pro receiver.Tested
x86_64-pc-windows-gnu(rustc 1.100.0, mingw-w64). 0.6.0 was installed from the release, then onlysecbird-tray.exewas replaced.input fromis the second press.found:the tray used 0.000 s of processor time over 30 s.cargo clippy --release --target x86_64-pc-windows-gnu --all-targets -- -D warningsis clean. Unit tests: 135 (core) and 7 (tray) pass on Windows, 128 and 1 pass on Linux.node --test crates/secbird-tray/tests/*.test.cjspasses. 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 undercrates/secbird-tray/tests/if it is wanted).