-
-
Notifications
You must be signed in to change notification settings - Fork 51
fix: restart gamepad listener when its threads die #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,10 +43,24 @@ def _check_listeners(self): | |
|
|
||
| See: https://github.com/ActivityWatch/aw-watcher-afk/issues/27 | ||
| """ | ||
| if not self.mouseListener.is_alive() or not self.keyboardListener.is_alive(): | ||
| self.logger.warning( | ||
| "Input listeners died (X server restart?), reinitializing..." | ||
| ) | ||
| # Only restart the gamepad listener if it was actually running before | ||
| # and all its threads died (e.g. device unplugged). Without this guard, | ||
| # systems without a gamepad would trigger a restart on every poll, | ||
| # since is_alive() is always False when start() returned early. | ||
| gamepad_died = self.gamepadListener.needs_restart() | ||
| if ( | ||
| not self.mouseListener.is_alive() | ||
| or not self.keyboardListener.is_alive() | ||
| or gamepad_died | ||
| ): | ||
| if gamepad_died: | ||
| self.logger.warning( | ||
| "Gamepad listener died (device removed?), reinitializing..." | ||
| ) | ||
| else: | ||
| self.logger.warning( | ||
| "Input listeners died (X server restart?), reinitializing..." | ||
| ) | ||
|
Comment on lines
+56
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The current branching logs only the gamepad message when |
||
| # Stop any still-running listeners before creating new ones | ||
| # to avoid duplicate listener instances (e.g. if only one died) | ||
| self._stop_listeners() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_alive()usesany(t.is_alive() for t in self._threads), so when a system has two gamepads and only one is unplugged, one thread dies butis_alive()staysTrue.needs_restart()therefore returnsFalse, and the disconnected gamepad is never re-discovered on reconnect. The watcher silently tracks one fewer device until the remaining gamepad is also unplugged. This is a narrow edge case but worth noting, especially since the PR description specifically calls out multi-device USB scenarios.