-
-
Notifications
You must be signed in to change notification settings - Fork 193
Fix windowevent and key repeat in sdl2-compat #3470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
eaa6ee8
to
3116fe6
Compare
54cd49c
to
b5843fc
Compare
from @Starbuck5 in #3287
This PR should fix the issue. |
b5843fc
to
36e0989
Compare
import pygame
import sys
pygame.init()
screen = pygame.display.set_mode((400, 200), pygame.RESIZABLE)
pygame.display.set_caption("Key Repeat & Block Test")
clock = pygame.time.Clock()
font = pygame.font.Font(None, 36)
counter = 0
key_repeat_on = True
key_blocked_on = False
pygame.key.set_repeat(300, 100)
running = True
while running:
screen.fill((30, 30, 30))
text = font.render(f"Counter: {counter}", True, (255, 255, 255))
info1 = font.render(f"Repeat: {'ON' if key_repeat_on else 'OFF'}", True, (180, 180, 180))
info2 = font.render(f"Blocked: {'YES' if key_blocked_on else 'NO'}", True, (180, 180, 180))
screen.blit(text, (50, 40))
screen.blit(info1, (50, 90))
screen.blit(info2, (50, 130))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
print(f"KEYDOWN: {pygame.key.name(event.key)}")
if event.key == pygame.K_SPACE:
counter += 1
elif event.key == pygame.K_r:
key_repeat_on = not key_repeat_on
if key_repeat_on:
pygame.key.set_repeat(300, 100)
else:
pygame.key.set_repeat()
elif event.type == pygame.MOUSEBUTTONDOWN:
key_blocked_on = not key_blocked_on
if key_blocked_on:
pygame.event.set_blocked(pygame.KEYDOWN)
else:
pygame.event.set_allowed(pygame.KEYDOWN)
elif event.type >= pygame.WINDOWSHOWN and event.type <= pygame.WINDOWDISPLAYCHANGED:
print(event)
clock.tick(60)
pygame.quit()
sys.exit() test script for this PR |
I tested with your script and SDL2 compat and key repeat doesn't seem to work. |
It doesn't in my testing. I'm using the latest SDL 2.32.56 release from them. |
hmm, it works for me. Are you sure you are on this branch? Also, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay on further testing it actually does work, I was having an unknown problem getting the code to update in my site-packages directory, even though the timestamps updated apparently the code wasn't. I had to delete a few cache directories to get everything building properly again.
WINDOWEVENT translation was broken when compiled with sdl2-compat.
The issue was in our
_pg_translate_windowevent
function. The current code was directly modifying the event type there but it seems like it is simply an implementation detail that we were relying on, and one isn't supposed to actually modify events inSDL_FilterEvents
based filtering. Plus, this is easier to fix on our side than fix on sdl2-compat side.I also took the opportunity to improve the comments while I was giving the implementation a good think.
This fixes a failing unit test so I don't see the need to add more tests here.
UPDATE: key repeat was broken and for similar reasons, I have fixed that here as well.