Skip to content
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

Add Window.wm_info #3219

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

damusss
Copy link
Member

@damusss damusss commented Nov 10, 2024

Window manager information and especially the window handle were only accessible to the display module. I feel like you should know the window handle of any window, so I added the property. The return value almost perfectly mimics the display one, but it can change of course since this would be new api.

MRE:

import pygame

D = False
if D:
    screen = pygame.display.set_mode((300, 300))
else:
    win = pygame.Window("test", (300, 300))
    win2 = pygame.Window("tes2", (150, 150))

while True:
    for e in pygame.event.get():
        if e.type == pygame.QUIT or e.type == pygame.WINDOWCLOSE:
            pygame.quit()
            raise SystemExit

        if e.type == pygame.KEYDOWN:
            if D:
                print(pygame.display.get_wm_info())
            else:
                print(win.wm_info, win2.wm_info)

    if D:
        screen.fill(0)
        pygame.display.flip()
    else:
        win.get_surface().fill(0)
        win2.get_surface().fill(0)
        win.flip()
        win2.flip()

@damusss damusss added New API This pull request may need extra debate as it adds a new class or function to pygame window pygame.Window labels Nov 10, 2024
@damusss damusss requested a review from a team as a code owner November 10, 2024 15:17
Copy link
Member

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

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

SDL_syswm.h header is removed in SDL3. The way to access the wm info has also changed, and I believe that also changes what values are exported by the SDL side.

I think that going forward any new API added should be SDL3 style, and any thing in the grey area should not be exported at all.

@damusss
Copy link
Member Author

damusss commented Nov 10, 2024

SDL_syswm.h header is removed in SDL3. The way to access the wm info has also changed, and I believe that also changes what values are exported by the SDL side.

I think that going forward any new API added should be SDL3 style, and any thing in the grey area should not be exported at all.

Alright, good to know. I'll study the new system that SDL3 uses and adjust the Window code for it. I believe I should keep the SDL2 version (unless it has more dictionary keys than sdl3 will support) so it can be added before pygame 3.

@damusss
Copy link
Member Author

damusss commented Nov 10, 2024

@ankith26 @Starbuck5
the most recent commit adds a codepath for SDL3. I removed the dictionary keys from the SDL2 codepath that weren't accessible in SDL3. My only limitations:

  • I have no idea on how to test the SDL3 codepath
  • I got confused sometimes. because I tried to be close to the sdl2 codepath, but sometimes PyLong_FromLong was used when the returned value was a pointer, instead of using PyCapsule_New. So I'd like to know if what I did is correct, as I assume the checks won't tell me anything

@damusss damusss added the sdl3 label Nov 18, 2024
@ankith26
Copy link
Member

Perhaps this PR should wait for the "port window to SDL3" PR to be made and merged first

@damusss
Copy link
Member Author

damusss commented Nov 18, 2024

Perhaps this PR should wait for the "port window to SDL3" PR to be made and merged first

I suppose that makes sense. Do you need special competence to pull off one of those PRs, or is it just about following the migration guide (and making different codepaths/creating compat macros)? (if so, I could even try to make it, otherwise I'll wait for you or starbuck). :)

Almost forgot, do you guys test your PR to actually compile with SDL3 locally, or do you just trust yourselves? About the first option (more likely), how do you do it? My WSL technically counts as linux if that helps

@damusss damusss requested a review from ankith26 November 21, 2024 09:38
@ankith26
Copy link
Member

We do test that the patch compiles on SDL3. It can be done locally, but you have to compile SDL3 from source if you are gonna go the WSL way (don't worry, it's not that hard). BTW, we also have SDL3 CI now that can do the testing on windows+mac+linux.

Basically the thing is we are yet to figure how to properly deal with the pixelformat changes uniformly, once that is done we can apply the same strategy everywhere and port the next wave of modules

@ankith26
Copy link
Member

Well actually, Window is not blocked by pixelformat changes, I am working on porting it to SDL3 rn

@damusss
Copy link
Member Author

damusss commented Nov 22, 2024

Alright then, nice, thanks

@Starbuck5
Copy link
Member

So even if this code works great on SDL3, why should we expose new API in the SDL2 style?

@damusss
Copy link
Member Author

damusss commented Dec 20, 2024

So even if this code works great on SDL3, why should we expose new API in the SDL2 style?

We don't have to expose it in a SDL2 style, but the window manager information is very dependent on the os so how would you provide the info without a dictionary?

@Starbuck5
Copy link
Member

Having something called "wm info" is clearly an SDL2 construction. Well, looking at the SDL code you have it looks like they expose it now as properties on the window object itself.

@Starbuck5 Starbuck5 marked this pull request as draft December 20, 2024 08:31
@Starbuck5
Copy link
Member

I have marked as a draft, because with uncertainty about API as well as merge conflicts this is not ready to merge.

@damusss
Copy link
Member Author

damusss commented Dec 20, 2024

Having something called "wm info" is clearly an SDL2 construction. Well, looking at the SDL code you have it looks like they expose it now as properties on the window object itself.

That's true, but each property is going to exist or not based on the OS and window manager. They are not generic properties that belong to almost every window like a position and a size. The dictionary reflects how uncertain the attributes are to exist. plus they are all very low level, so putting them besides common attributes would look "ugly" imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New API This pull request may need extra debate as it adds a new class or function to pygame sdl3 window pygame.Window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants