Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for keyboard grab without mouse grab (expose SDL_GetWindowKeyboardGrab)#3843

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
illume merged 1 commit intopygame:mainfromYannik:keyboard-grab
May 14, 2023

Conversation

@Yannik
Copy link

@YannikYannik commentedMay 10, 2023
edited
Loading

Currently, onlySDL_SetWindowGrab is exposed in pygame, which grabs the mouse, and, optionally, the keyboard.

In situations where you only need to grab the keyboard, always being forced to grab the mouse may be undesirable. (Atleast it is in an application I am developing).

To fix this, I am exposing theSDL_SetWindowKeyboardGrab andSDL_GetWindowKeyboardGrab methods aspygame.event.set_keyboard_grab(bool) andpygame.event.get_keyboard_grab() in this PR.

illume and Zireael07 reacted with thumbs up emojiillume reacted with hooray emoji
@YannikYannikforce-pushed thekeyboard-grab branch 2 times, most recently from72fd48e tof616310CompareMay 10, 2023 12:55
@Yannik
Copy link
Author

@illume Would you be able to give feedback on why the CI builds are still failing? I fixed the obvious problems (e.g. clang linter), but don't know what else to do now. Locally, this builds and works for me.

@illume
Copy link
Member

illume commentedMay 10, 2023
edited
Loading

Hey,

Click on the details links for the checks that are failing. There's a bunch of noise, but in there you should be able to see what is happening.

https://github.com/pygame/pygame/actions/runs/4937250903/jobs/8831461651?pr=3843#step:5:327

Generating docs caused changes. Please check them in.You may need to run: python3 setup.py docs --fullgeneration M src_c/doc/event_doc.h

This one meansdocs/reST/ref/key.rst needs to have the docs put in there. Then runningpython setup.py docs will generate the .h file.

https://ci.appveyor.com/project/pygame/pygame/builds/47008471/job/el4cuexts8uj4oqq

src_c/event.c(2255):errorC2065:'DOC_PYGAMEEVENTSETKEYBOARDGRAB':undeclaredidentifierCreatinglibrarybuild\temp.win-amd64-3.9\Release\src_c\key.cp39-win_amd64.libandobjectbuild\temp.win-amd64-3.9\Release\src_c\key.cp39-win_amd64.expGeneratingcodesrc_c/event.c(2257):errorC2065:'DOC_PYGAMEEVENTGETKEYBOARDGRAB':undeclaredidentifierFinishedgeneratingcodesrc_c/event.c(2254):errorC2099:initializerisnotaconstantFinishedgeneratingcodebuilding 'pygame.rect'extension

https://github.com/pygame/pygame/actions/runs/4937250895/jobs/8831457863?pr=3843#step:3:1167

src_c/event.c:2255:6:error: ‘DOC_PYGAMEEVENTSETKEYBOARDGRABundeclaredhere (notinafunction);didyoumeanDOC_PYGAMEEVENTSETGRAB’?2255 |DOC_PYGAMEEVENTSETKEYBOARDGRAB},          |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~          |DOC_PYGAMEEVENTSETGRABsrc_c/event.c:2257:6:error: ‘DOC_PYGAMEEVENTGETKEYBOARDGRABundeclaredhere (notinafunction);didyoumeanDOC_PYGAMEEVENTGETGRAB’?2257 |DOC_PYGAMEEVENTGETKEYBOARDGRAB},          |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~          |DOC_PYGAMEEVENTGETGRAB

@Yannik
Copy link
Author

@illume Ah, I see. I did not know thatevent_doc.h was autogenerated from reST. Thanks for the explanation.
I have fixed that and added the SDL version check.

illume reacted with thumbs up emoji

@illume
Copy link
Member

Hi again.

Probably we need to add a couple more things here to finish it off.

  • .. versionadded:: 2.5.0 to the docs. See other docs.
  • A basic unit test that calls the functions. It should only run if at least SDL 2.0.16
  • Bonus points for an interactive test. (optional)

The test needs to be marked with this:

@unittest.skipIf(pygame.get_sdl_version()< (2,0,16) ,"Needs at least SDL 2.0.16")

@Yannik
Copy link
Author

Hi@illume

I have updated my PR withversionadded and a test. It tests both set and get in a single test (calling set and then verifying the state with get), which made the most sense to me.

illume reacted with hooray emoji

@YannikYannikforce-pushed thekeyboard-grab branch 3 times, most recently from25451c5 tod166279CompareMay 14, 2023 14:03
@Yannik
Copy link
Author

I cannot figure out why the test is failing.

I have tried this locally:

import pygamepygame.init()surf = pygame.display.set_mode((10, 10))pygame.event.set_keyboard_grab(True)print(pygame.event.get_keyboard_grab())pygame.event.set_keyboard_grab(False)print(pygame.event.get_keyboard_grab())

and it results in the correct

TrueFalse

@illume Could you have a look?

@illume
Copy link
Member

I think it's because the 'dummy' video driver doesn't implement it correctly. It seems to just ignore it.

So we can skip it when running under the dummy driver:

@unittest.skipIf(os.environ.get("SDL_VIDEODRIVER")=="dummy","requires the SDL_VIDEODRIVER to be a non dummy value",    )

@Yannik
Copy link
Author

@illume Nope, this does not work. Maybe it suffers from the same problems as thetest_get_grab test (which is always skipped)?

Copy link
Member

@illumeillume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍 thanks

@illumeillume merged commitdf17cb6 intopygame:mainMay 14, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@illumeillumeillume approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@Yannik@illume

[8]ページ先頭

©2009-2025 Movatter.jp