Skip to content

Commit 90788f9

Browse files
committed
fix bug which caused old devices to not be removed
1 parent e349dac commit 90788f9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/hhd/controller/virtual/uinput/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
logger = logging.getLogger(__name__)
1414

1515

16+
# Monkey patch Uinput device to avoid issues
17+
# _find_device() may crash when controllers
18+
# disconnect. We dont use the produced device anyway.
19+
def _patch(*args, **kwargs):
20+
pass
21+
22+
23+
UInput._find_device = _patch
24+
25+
1626
class UInputDevice(Consumer, Producer):
1727
def __init__(
1828
self,
@@ -58,6 +68,7 @@ def open(self) -> Sequence[int]:
5868
def close(self, exit: bool) -> bool:
5969
if self.dev:
6070
self.dev.close()
71+
self.dev = None
6172
self.input = None
6273
self.fd = None
6374
return True

src/hhd/device/legion_go/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ def controller_loop_rest(mode: str, pid: int, conf: Config, should_exit: TEvent)
182182
logger.info(evs)
183183
d_uinput.consume(evs)
184184
finally:
185+
d_uinput.close(True)
185186
d_shortcuts.close(True)
186187
d_raw.close(True)
187-
d_uinput.close(True)
188188

189189

190190
def controller_loop_xinput(conf: Config, should_exit: TEvent):
@@ -311,8 +311,8 @@ def controller_loop_xinput(conf: Config, should_exit: TEvent):
311311
fd_to_dev = {}
312312

313313
def prepare(m):
314-
fs = m.open()
315314
devs.append(m)
315+
fs = m.open()
316316
fds.extend(fs)
317317
for f in fs:
318318
fd_to_dev[f] = m

0 commit comments

Comments
 (0)