Skip to content

pygame.Window.get_info() #3494

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildconfig/stubs/pygame/display.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def get_wm_info() -> dict[str, int]:
key with the value set to the system id for the current display.

.. versionaddedold:: 1.7.1
.. versionchanged:: 2.X.X added a new key ``subsystem`` used to identify windowing system - exists in most cases.
"""

def get_desktop_sizes() -> list[tuple[int, int]]:
Expand Down
13 changes: 13 additions & 0 deletions buildconfig/stubs/pygame/window.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,17 @@ class Window:

.. versionadded:: 2.5.2
"""

def get_info(self) -> dict[str, int | str]:
"""Return system-specific information about a given window.

Creates a dictionary filled with string keys. It's empty if failed to query the system
info (eg.: the window was destroyed). Otherwise it contains at least one key ``subsystem``
containing the name of the window's subsystem. The rest of values are integes.
Names of the rest keys and meaning of their values is system-dependent,
but most platforms will return a "window" key with the value
set to the system id for the current window.

.. versionadded:: 2.X.X
"""
relative_mouse: bool
7 changes: 7 additions & 0 deletions docs/reST/c_api/window.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ Header file: src_c/include/pygame.h

Will return false if *x* is not a subclass of `Window`.
This is a macro. No check is made that *x* is not *NULL*.

.. c:function:: PyObject* pgWindow_GetInfo(SDL_Window *window)

Return a python dict containing system-specific information about a window.

.. seealso::
:py:func:`pygame.window.Window.get_info`
2 changes: 1 addition & 1 deletion src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ typedef enum {
#define PYGAMEAPI_MATH_NUMSLOTS 2
#define PYGAMEAPI_BASE_NUMSLOTS 30
#define PYGAMEAPI_EVENT_NUMSLOTS 10
#define PYGAMEAPI_WINDOW_NUMSLOTS 1
#define PYGAMEAPI_WINDOW_NUMSLOTS 2
#define PYGAMEAPI_RENDER_NUMSLOTS 3
#define PYGAMEAPI_GEOMETRY_NUMSLOTS 2
#define PYGAMEAPI_BUFFERPROXY_NUMSLOTS 4
Expand Down
115 changes: 1 addition & 114 deletions src_c/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,122 +467,9 @@ pgInfo(PyObject *self, PyObject *_null)
static PyObject *
pg_get_wm_info(PyObject *self, PyObject *_null)
{
PyObject *dict;
PyObject *tmp;
SDL_SysWMinfo info;
SDL_Window *win;

VIDEO_INIT_CHECK();

SDL_VERSION(&(info.version))
dict = PyDict_New();
if (!dict) {
return NULL;
}

win = pg_GetDefaultWindow();
if (!win) {
return dict;
}
if (!SDL_GetWindowWMInfo(win, &info)) {
return dict;
}

(void)tmp;
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
tmp = PyLong_FromLongLong((long long)info.info.win.window);
PyDict_SetItemString(dict, "window", tmp);
Py_DECREF(tmp);

tmp = PyLong_FromLongLong((long long)info.info.win.hdc);
PyDict_SetItemString(dict, "hdc", tmp);
Py_DECREF(tmp);
tmp = PyLong_FromLongLong((long long)info.info.win.hinstance);
PyDict_SetItemString(dict, "hinstance", tmp);
Py_DECREF(tmp);
#endif
#if defined(SDL_VIDEO_DRIVER_WINRT)
tmp = PyCapsule_New(info.info.winrt.window, "window", NULL);
PyDict_SetItemString(dict, "window", tmp);
Py_DECREF(tmp);
#endif
#if defined(SDL_VIDEO_DRIVER_X11)
tmp = PyLong_FromLong(info.info.x11.window);
PyDict_SetItemString(dict, "window", tmp);
Py_DECREF(tmp);

tmp = PyCapsule_New(info.info.x11.display, "display", NULL);
PyDict_SetItemString(dict, "display", tmp);
Py_DECREF(tmp);
#endif
#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
tmp = PyCapsule_New(info.info.dfb.dfb, "dfb", NULL);
PyDict_SetItemString(dict, "dfb", tmp);
Py_DECREF(tmp);

tmp = PyCapsule_New(info.info.dfb.window, "window", NULL);
PyDict_SetItemString(dict, "window", tmp);
Py_DECREF(tmp);

tmp = PyCapsule_New(info.info.dfb.surface, "surface", NULL);
PyDict_SetItemString(dict, "surface", tmp);
Py_DECREF(tmp);
#endif
#if defined(SDL_VIDEO_DRIVER_COCOA)
tmp = PyCapsule_New(info.info.cocoa.window, "window", NULL);
PyDict_SetItemString(dict, "window", tmp);
Py_DECREF(tmp);
#endif
#if defined(SDL_VIDEO_DRIVER_UIKIT)
tmp = PyCapsule_New(info.info.uikit.window, "window", NULL);
PyDict_SetItemString(dict, "window", tmp);
Py_DECREF(tmp);

tmp = PyLong_FromLong(info.info.uikit.framebuffer);
PyDict_SetItemString(dict, "framebuffer", tmp);
Py_DECREF(tmp);

tmp = PyLong_FromLong(info.info.uikit.colorbuffer);
PyDict_SetItemString(dict, "colorbuffer", tmp);
Py_DECREF(tmp);

tmp = PyLong_FromLong(info.info.uikit.resolveFramebuffer);
PyDict_SetItemString(dict, "resolveFramebuffer", tmp);
Py_DECREF(tmp);
#endif
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
tmp = PyCapsule_New(info.info.wl.display, "display", NULL);
PyDict_SetItemString(dict, "display", tmp);
Py_DECREF(tmp);

tmp = PyCapsule_New(info.info.wl.surface, "surface", NULL);
PyDict_SetItemString(dict, "surface", tmp);
Py_DECREF(tmp);

tmp = PyCapsule_New(info.info.wl.shell_surface, "shell_surface", NULL);
PyDict_SetItemString(dict, "shell_surface", tmp);
Py_DECREF(tmp);
#endif
#if defined(SDL_VIDEO_DRIVER_ANDROID)
tmp = PyCapsule_New(info.info.android.window, "window", NULL);
PyDict_SetItemString(dict, "window", tmp);
Py_DECREF(tmp);

tmp = PyLong_FromLong((long)info.info.android.surface);
PyDict_SetItemString(dict, "surface", tmp);
Py_DECREF(tmp);
#endif
#if defined(SDL_VIDEO_DRIVER_VIVANTE)
tmp = PyLong_FromLong((long)info.info.vivante.display);
PyDict_SetItemString(dict, "display", tmp);
Py_DECREF(tmp);

tmp = PyLong_FromLong((long)info.info.vivante.window);
PyDict_SetItemString(dict, "window", tmp);
Py_DECREF(tmp);
#endif

return dict;
return pgWindow_GetInfo(pg_GetDefaultWindow());
}

/* display functions */
Expand Down
1 change: 1 addition & 0 deletions src_c/doc/window_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
#define DOC_WINDOW_SETICON "set_icon(icon, /) -> None\nSet the window icon."
#define DOC_WINDOW_SETMODALFOR "set_modal_for(parent, /) -> None\nSet the window as a modal for a parent window."
#define DOC_WINDOW_FLASH "flash(operation, /) -> None\nFlash a window to demand attention from the user."
#define DOC_WINDOW_GETINFO "get_info() -> dict[str, int | str]\nReturn system-specific information about a given window."
2 changes: 2 additions & 0 deletions src_c/include/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ typedef struct {
#define pgWindow_Check(x) \
(PyObject_IsInstance((x), (PyObject *)&pgWindow_Type))
#define import_pygame_window() IMPORT_PYGAME_MODULE(window)
#define pgWindow_GetInfo \
(*(PyObject * (*)(SDL_Window *)) PYGAMEAPI_GET_SLOT(window, 1))
#endif

typedef struct pgTextureObject pgTextureObject;
Expand Down
Loading
Loading