Skip to content

PS4 gamepad not compatible with fullscreen (2453) #1257

Open
@GalacticEmperor1

Description

@GalacticEmperor1

Issue №2453 opened by Zell-Doost at 2021-01-17 22:14:30

When I attempt to run a program that detects controller inputs, it works fine, but if fullscreen is toggled on, then it receives no input from the gamepad.

OS: Linux 18.04.4 LTS
Python version: 3.7.9
SDL version: SDL 2.0.14
Pygame version: 2.0.1
Relevant hardware: Dualshock 4 PS4 controller
Current behaviour: When the pygame window is windowed, the program will detect controller inputs as intended, but when the window is fullscreen (as in fullscreen, not maximised), the program detects no inputs from the gamepad. It does detect inputs form the keyboard though.
Expected behaviour: The controller input detection works in fullscreen the same way it works in windowed mode.
Video example of bug:
https://user-images.githubusercontent.com/77568920/104885230-6e54c780-59b3-11eb-9d16-b0a8b93e83b4.MOV
Steps to reproduce:

  1. Run code below with a dualshock4 controller plugged in.
  2. Try pressing a button on the controller such as "x" or "circle".
  3. Press "f" key on keyboard to switch to fullscreen.
  4. Try pressing a button on the controller now, it doesn't work.
  5. Press "f" key to go back to windowed mode.
  6. Press a button on the controller, it works now.

Test code:

import pygame
import os
import sys

os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()

screen = pygame.display.set_mode((1920, 1080))
pygame.display.set_caption("game")
button = False

font = pygame.font.Font("freesansbold.ttf", 32)
button_down = False

def drawText(text, font, colour, surface, x, y):
    textobj = font.render(text, 1, colour)
    textrect = textobj.get_rect()
    textrect.topleft = (x, y)
    surface.blit(textobj, textrect)

clock = pygame.time.Clock()
#      controller init
joystick = pygame.joystick.Joystick(0)
joystick.init()

while True:


    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                pygame.quit()
                sys.exit()
            if event.key == pygame.K_f:
                pygame.display.toggle_fullscreen()
                
        if event.type == pygame.JOYBUTTONDOWN:
            button_down = True
        if event.type == pygame.JOYBUTTONUP:
            button_down = False
            
    if button_down:
        drawText("button down", font, (255, 255, 255), screen, 100, 100)
    elif not button_down:
        drawText("button up", font, (255, 255, 255), screen, 100, 100)
                    
    
    
    pygame.display.update()
    screen.fill((0, 0, 0))
    clock.tick(45)

Comments

# # Starbuck5 commented at 2021-01-18 06:50:24

Hello, thank you for the report.

I saw your post about this on reddit.

It would make it much easier to debug this if you add the information requested in the bug report template.

Especially what system you're on, and a minimal test case (using a code block, not an image, because we can't run an image).


# # Zell-Doost commented at 2021-01-18 07:46:16

I have updated the issue now with more information, I hope that this information will be useful.


# # robertpfeiffer commented at 2021-01-18 08:52:07

This might be a gampad driver problem or an X11 problem.

X11 questions: What is the native resolution of your monitor? What was the desktop resolution? Are you using Intel, AMD, or Nvidia graphics, or something else entirely? Are you using kernel mode setting, what graphics drivers are you running (free or proprietary?)? Did switching to fullscreen change the resolution of the monitor? Can you alt-tab out of your fullscreen game quickly, or does the X server take a second to change the resolution back? What happens when you use screen = pygame.display.set_mode((1280, 720), pygame.SCALED) instead of physical 1080p?

Gamepad questions: How did you connect the gamepad (wired or bluetooth)? Can you post the GUID reported by Joystick.get_guid() (http://www.pygame.org/docs/ref/joystick.html# pygame.joystick.Joystick.get_guid)? If you connected via USB, can you post the usb ID reported via lsusb?

Either of these lines of inquiry might be a waste of time if the other leads us to the answer, but I do not have my own PS4 gamepad to investigate and narrow it down before asking.


# # Zell-Doost commented at 2021-01-19 00:07:43

X11 questions:
The resolution of my monitor and my desktop is 1920x1080.

The computer is an intel nuc, so I assume that it's intel graphics.

Switching to fullscreen did not change the resolution of the monitor.

When it's in fullscreen, then I can't alt-tab at all.

When I use screen = pygame.display.set_mode((1280, 720), pygame.SCALED), then it displays a 1280x720 window, when it goes fullscreen, the resolution doesn't fit my monitor, so I can't see the text that says "button up" and "button down".

Gamepad questions:
The gamepad was connected with a USB.

When I print out the GUID using pygame.joystick.Joystick.get_guid() it returns and prints:
<built-in method get_guid of Joystick object at 0x7f6cfb185f30>

When I type lsusb into the terminal, the line that corresponds with the gamepad says:
Bus 001 Device 006: ID 054c:09cc Sony Corp.

If there were any questions I didn't answer, it is because I don't know how to.


# # robertpfeiffer commented at 2021-01-19 07:16:29

I think you forgot the parentheses for a function call in get_guid(), but it probably doesn't matter. Something weird is going on with X11, not your controller driver. I suspect the same thing would happen with different controllers. I don't know what it is though.

Can you post the output of: glxinfo |grep OpenGL? (in a terminal)

Does your code run under wayland?

Does the same thing happen with a different (wired, let's not complicate things here) game controller, like an xbox 360 controller? I strongly suspect that any knockoff USB controller would have the same problems.

When I use screen = pygame.display.set_mode((1280, 720), pygame.SCALED), then it displays a 1280x720 window, when it goes fullscreen, the resolution doesn't fit my monitor, so I can't see the text that says "button up" and "button down".

Can you post a video of that? That looks like a bug in SCALED?


# # Zell-Doost commented at 2021-01-19 23:33:08

You are right, I did forget the parentheses in get_guid(), so the output with parentheses is:
030000004c050000cc09000011810000

The output of glxinfo |grep OpenGL shows this:

OpenGL renderer string: Mesa DRI Intel(R) UHD Graphics 600 (Geminilake 2x6) 
OpenGL core profile version string: 4.5 (Core Profile) Mesa 19.2.8
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 19.2.8
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 19.2.8
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

Unfortunately, for the next 2 questions, I cannot answer them. This is as I do not know how to run the code under wayland. I also do not own an xbox controller. I do however own a nintendo switch pro controller, but I do not know if that is compatible with pygame.

Edit: I just realised that the video wont show, so I'll send 2 pictures to show the difference:
IMG_0200
IMG_0201


# # MyreMylar commented at 2021-01-20 10:12:38

Try adding some print statements to your program like this:

import pygame
import os
import sys

os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()

screen = pygame.display.set_mode((1920, 1080))
pygame.display.set_caption("game")
button = False

font = pygame.font.Font("freesansbold.ttf", 32)
button_down = False
button_state_fresh = False

def drawText(text, font, colour, surface, x, y):
    textobj = font.render(text, 1, colour)
    textrect = textobj.get_rect()
    textrect.topleft = (x, y)
    surface.blit(textobj, textrect)

clock = pygame.time.Clock()
#      controller init
joystick = pygame.joystick.Joystick(0)
joystick.init()

while True:


    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                pygame.quit()
                sys.exit()
            if event.key == pygame.K_f:
                pygame.display.toggle_fullscreen()
                
        if event.type == pygame.JOYBUTTONDOWN:
            button_down = True
            button_state_fresh = True
        if event.type == pygame.JOYBUTTONUP:
            button_down = False
            button_state_fresh = True
            
    if button_down:
        drawText("button down", font, (255, 255, 255), screen, 100, 100)
        if button_state_fresh:
            print("button down") 
            button_state_fresh = False
    elif not button_down:
        drawText("button up", font, (255, 255, 255), screen, 100, 100)
        if button_state_fresh:
            print("button up") 
            button_state_fresh = False
                    
    
    
    pygame.display.update()
    screen.fill((0, 0, 0))
    clock.tick(45)

My suspicion here is that there may be a problem with the text drawing after toggling to full screen on some flavours of linux, as I recall seeing something similar in the past reported with keyboard input.


# # MyreMylar commented at 2021-01-20 10:16:17

I wonder if adding a screen = pygame.display.get_surface() after pygame.display.toggle_fullscreen() would help in these cases.


# # robertpfeiffer commented at 2021-01-20 16:17:27

I wonder if adding a screen = pygame.display.get_surface() after pygame.display.toggle_fullscreen() would help in these cases.

If it helped, that would indicate a bug. But toggling fullscreen should just work with SCALED, because the display surface is never changed.

Could the problem be caused by libGL incompatibilities between newer mesa and the manylinux build, similarly to nvidia libGL problems that disappear completely when you compile pygame from source?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions