@@ -167,7 +167,6 @@ def plugin_run(
167167 should_exit : TEvent ,
168168 updated : TEvent ,
169169 dconf : dict ,
170- woke_up : TEvent ,
171170):
172171 first = True
173172 first_disabled = True
@@ -223,7 +222,7 @@ def plugin_run(
223222 logger .info ("Launching emulated controller." )
224223 updated .clear ()
225224 init = time .perf_counter ()
226- controller_loop (conf .copy (), should_exit , updated , dconf , emit , woke_up )
225+ controller_loop (conf .copy (), should_exit , updated , dconf , emit )
227226 repeated_fail = False
228227 except Exception as e :
229228 failed_fast = init + LONGER_ERROR_MARGIN > time .perf_counter ()
@@ -252,7 +251,6 @@ def controller_loop(
252251 updated : TEvent ,
253252 dconf : dict ,
254253 emit : Emitter ,
255- woke_up : TEvent ,
256254):
257255 debug = DEBUG_MODE
258256
@@ -366,6 +364,7 @@ def prepare(m):
366364 prepare (d_vend )
367365
368366 logger .info ("Emulated controller launched, have fun!" )
367+ prev = 0
369368 while not should_exit .is_set () and not updated .is_set ():
370369 start = time .perf_counter ()
371370 # Add timeout to call consumers a minimum amount of times per second
@@ -379,9 +378,17 @@ def prepare(m):
379378 if id (d ) in to_run :
380379 evs .extend (d .produce (r ))
381380
382- if woke_up .is_set ():
383- woke_up .clear ()
381+ if start - prev > 1 :
382+ # After wakeup, the controller waits a bit until it
383+ # realizes it woke up and switches to desktop mode.
384+ # Therefore we need to wait otherwise we race it and
385+ # end up stuck in desktop mode.
386+ time .sleep (2 )
387+ logger .info ("Setting controller to dinput mode." )
384388 d_vend .set_dinput_mode ()
389+ prev = time .perf_counter ()
390+ else :
391+ prev = start
385392
386393 evs = multiplexer .process (evs )
387394 if evs :
0 commit comments