pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

pygame.event.set_grab mouse border bug (linux)

Open theolaos opened this issue 2 years ago • 3 comments
trafficstars

Environment:

  • Operating system : Linux(Fedora 38)
  • Python version : 3.11.4
  • SDL version : 2.26.5
  • PyGame-ce version : 2.3, 2.3.1.dev4
  • Relevant hardware : cpu: r5 3500x, ram: 32gb, gpu: rx vega 56

Current behavior:

When the program runs, the borders of the window that should of kept the mouse in get an offset. (see the video)

Expected behavior:

When the program runs and the cursor runs over the window it should be captured. After that it should stay in, it should not be able to escape the window borders.

Video

https://youtu.be/OO23ipEZ2Is

(1: when it works, 2: what happens if it doesn't)

Steps to reproduce:

  1. Run the program and quickly move the cursor on top of the window (preferably the cursor should be on top of the window before the window appears)
  2. Check if the borders are not the same with the borders of the window

Test code

import pygame, sys
pygame.init()
screen = pygame.display.set_mode((1280,720))
clock = pygame.time.Clock()
pygame.event.set_grab(True)
# pygame.mouse.set_pos((0,0)) # this was a quick solve i thought that didn't work

while True:
    screen.fill('#71ddee')
    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()  
    print(pygame.mouse.get_pos())
    pygame.display.update()
    clock.tick(60)

More Info:

The bug in windows cannot get recreated Only in Linux apparently

theolaos avatar Aug 02 '23 13:08 theolaos

Bug still persists after updating to the newest version Pygame-CE: 2.3.2 python: 3.11.5

theolaos avatar Sep 29 '23 17:09 theolaos

I'm not clear what exactly is the bug here?

I'm on ubuntu 23.10 and the script is working as expected for me. I have to click once on the screen to focus it, and then the mouse is grabbed in the window.

ankith26 avatar Dec 30 '23 05:12 ankith26

@ankith26 the bug is that the border, when the mouse gets grabbed by the window, get's a huge offset from the actual window. You can look in the video that I took what happens exactly. The first run of the code is what happens normally, and the second run of the code what happens when it broke.

I am in Fedora 39 KDE as of today, and after I rerun the test code it seems as somehow fixed*. I am not sure as what has been fixed, or if it is a version specific bug. I have installed:

  • python 3.12.1
  • pygame-ce 2.3.2

*The bug is fixed under x11 as when I run the code the window immediately grabs the mouse, by teleporting it in the window.

Under wayland it's semi fixed as the top part of the window isn't a border, though the other parts work fine. And for the mouse to get grabbed you need to click once in the window. When it escapes through the top you need to re-click in the window.

theolaos avatar Jan 04 '24 15:01 theolaos

It seems like the problem is fixed in fedora 40 kde version 6.1 under the wayland compositor. Closing the issue.

theolaos avatar Oct 05 '24 12:10 theolaos