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

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
Spiky Caterpillar
Veteran
Posts: 253
Joined: Fri Nov 14, 2008 7:59 pm
Completed: Lots.
Projects: Black Closet
Organization: Slipshod
Location: Behind you.
Contact:

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

#1 Post 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,

Last edited by Spiky Caterpillar on Mon Sep 22, 2014 11:56 pm, edited 2 times in total.
Nom nom nom nom nom LEAVES.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Ren'Py loses joystick focus too readily

#2 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Spiky Caterpillar
Veteran
Posts: 253
Joined: Fri Nov 14, 2008 7:59 pm
Completed: Lots.
Projects: Black Closet
Organization: Slipshod
Location: Behind you.
Contact:

Re: Ren'Py loses joystick focus too readily

#3 Post by Spiky Caterpillar »

That seems to have fixed it, yes.
Nom nom nom nom nom LEAVES.

Post Reply

Who is online

Users browsing this forum: No registered users