-
-
Notifications
You must be signed in to change notification settings - Fork 185
Support SDL_WINDOWID
#1953
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
Support SDL_WINDOWID
#1953
Conversation
For the purposes of issue #1943 I was hoping for a more limited PR. This adds another parameter to set_mode and has complex looking handling of cases where that intersects with OpenGL and different versions of SDL, which I don't understand without doing more research. |
It's limited now. The rest of contents would be another PR |
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.
LGTM 👍
Hmmm, this may actually be a more complex issue. On my ubuntu machine, the pygame window does embed inside the tk one after this PR, but the application doesn't work as expected (pygame doesn't get any of the events apart from "keymapchanged") |
Dang. This prompted me to go check events on this PR versus pygame 1.9.6 (when this last worked). On Windows1.9.6
1.9.6 just didn't have as many events as now. This PR
|
I also just checked, and I could trigger every event I tried except keyboard inputs |
I solved this by adding two lines to the test code (on Windows). import tkinter
import threading
import os
root=tkinter.Tk()
root.geometry("640x480")
btn=tkinter.Button(root,text="HelloWorld")
btn.pack()
cv=tkinter.Canvas(root)
cv.pack()
off=0
def pg_loop(hwnd):
import pygame
from pygame._sdl2 import video
os.environ['SDL_WINDOWID']=str(hwnd)
pygame.display.init()
sf=pygame.display.set_mode()
# ========== Added here ===========
win=video.Window.from_display_module()
win.focus()
# =================================
pos=(20,20)
while not off:
sf.fill((0,0,0))
pygame.draw.rect(sf,(255,0,0),(*pos,10,10))
pygame.display.update()
for event in pygame.event.get():
if event.type==1024:#MOUSEMOTION
pos=event.pos
else:
print(event)
if __name__ == "__main__":
hwnd=cv.winfo_id()
threading.Thread(target=pg_loop,args=(hwnd,)).start()
root.mainloop()
off=1
|
It works, until you click out of the tkinter window and back in or press "Tab" |
Rerun CI |
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.
So it doesn't "work," and it's an overdue attempt to regain backwards compatibility with a questionable pygame 1 development strategy.
I'm not excited about it, but it looks like we should have this code attempt of compat in here for parity. I don't think there's anything else we can do with the code to make it better. Thank you yunline for working on this!
Issue: #1943
Test code: