Page 1 of 1

[fixed in 6.18.x] Ren'Py loses joystick focus too readily

Posted: Mon Sep 22, 2014 11:13 pm
by Spiky Caterpillar
I got a report that one of my games wouldn't accept controller input until after the player used the keyboard or mouse - which is a problem for controller-only or controller-dominant PC-as-living-room-console setups. Poking at it, it appears that Ren'Py discards controller input when renpy.display.interface.focused is false; however, .focused only seems to be true if the mouse cursor is actually inside the SDL window. Being on the window titlebar is not enough. (Replicated on Debian stable, fvwm, sloppy focus, in both 6.17.7 and 6.12.2; original bug report was probably a SteamOS machine).

Looking at Pygame, I couldn't find any functions that checked to see if the app itself was focused, and pygame.ACTIVEEVENT seemed to be triggering on the inner SDL window rather than the WM border. At the moment I'm changing the 'if renpy.display.interface.focused:' controller-event checks to 'if pygame.key.get_focused() or renpy.display.interface.focused:' in my games, which seems to work as desired on my computer and the one that reported the bug. My question is, is this the right approach? Are there any likely gotchas?

(The included diff works on 6.12.2 and 6.17.7, haven't tested it on other versions.)

Code: Select all

*** renpy/display/joystick.py   2011-07-14 08:25:02.000000000 -0700
--- /home/renpy/renpy-6.17.7+NOPICKLES-sdk/renpy/display/joystick.py    2014-09-20 23:15:26.322397887 -0700
***************
*** 62,68 ****
  
      if ev.type == pygame.JOYAXISMOTION:
  
!         if not renpy.display.interface.focused:
              return None
  
          if ev.value >= 0.5:
--- 62,68 ----
  
      if ev.type == pygame.JOYAXISMOTION:
  
!         if (not pygame.key.get_focused()) and (not renpy.display.interface.focused):
              return None
  
          if ev.value >= 0.5:
***************
*** 96,103 ****
                                    press=press, release=release)
  
      if ev.type == pygame.JOYBUTTONDOWN:
!         
!         if not renpy.display.interface.focused:
              return None
  
          return pygame.event.Event(renpy.display.core.JOYEVENT,
--- 96,103 ----
                                    press=press, release=release)
  
      if ev.type == pygame.JOYBUTTONDOWN:
! 
!         if (not pygame.key.get_focused()) and (not renpy.display.interface.focused):
              return None
  
          return pygame.event.Event(renpy.display.core.JOYEVENT,
***************
*** 105,111 ****
                                    release=None)
      if ev.type == pygame.JOYBUTTONUP:
  
!         if not renpy.display.interface.focused:
              return None
  
          return pygame.event.Event(renpy.display.core.JOYEVENT,
--- 105,111 ----
                                    release=None)
      if ev.type == pygame.JOYBUTTONUP:
  
!         if (not pygame.key.get_focused()) and (not renpy.display.interface.focused):
              return None
  
          return pygame.event.Event(renpy.display.core.JOYEVENT,


Re: Ren'Py loses joystick focus too readily

Posted: Mon Sep 22, 2014 11:20 pm
by PyTom
Can you check out 6.18.1?

In the 6.18 series, I split focused up into mouse_focused and keyboard_focused, and made joystick based on keyboard_focused. I think this fixes this problem.

Re: Ren'Py loses joystick focus too readily

Posted: Mon Sep 22, 2014 11:55 pm
by Spiky Caterpillar
That seems to have fixed it, yes.