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

Utility Window implementation. #3226

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions buildconfig/stubs/pygame/window.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Window:
def position(self, value: Union[int, Point]) -> None: ...
@property
def opengl(self) -> bool: ...
@property
def utility(self) -> bool: ...
@classmethod
@deprecated("since 2.4.0. Use either the display module or the Window class with get_surface and flip. Try not to mix display and Window")
def from_display_module(cls) -> Window: ...
10 changes: 10 additions & 0 deletions docs/reST/ref/window.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
(unrelated to INPUT_GRABBED).
:param bool always_on_top: Create a window that is always presented above
others.
:param bool utility: Create a window that doesn't appear in the task-bar .
gresm marked this conversation as resolved.
Show resolved Hide resolved

Event behavior if one Window is created: When the close button is pressed,
the ``QUIT`` event will be sent to the event queue.
Expand Down Expand Up @@ -289,6 +290,15 @@

.. versionadded:: 2.5.0

.. attribute:: utility

| :sl:`Get if the windos is an utility window`
gresm marked this conversation as resolved.
Show resolved Hide resolved
| :sg:`utility -> bool`

``True`` if the window doesn't appear in the task bar, ``False`` otherwise
gresm marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: TBD
gresm marked this conversation as resolved.
Show resolved Hide resolved

.. classmethod:: from_display_module

| :sl:`Create a Window object using window data from display module`
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 @@ -17,6 +17,7 @@
#define DOC_WINDOW_POSITION "position -> (int, int) or WINDOWPOS_CENTERED or WINDOWPOS_UNDEFINED\nGet or set the window position in screen coordinates"
#define DOC_WINDOW_OPACITY "opacity -> float\nGet or set the window opacity, between 0.0 (fully transparent) and 1.0 (fully opaque)"
#define DOC_WINDOW_OPENGL "opengl -> bool\nGet if the window supports OpenGL"
#define DOC_WINDOW_UTILITY "utility -> bool\nGet if the windos is an utility window"
#define DOC_WINDOW_FROMDISPLAYMODULE "from_display_module() -> Window\nCreate a Window object using window data from display module"
#define DOC_WINDOW_GETSURFACE "get_surface() -> Surface\nGet the window surface"
#define DOC_WINDOW_FLIP "flip() -> None\nUpdate the display surface to the window."
Expand Down
16 changes: 16 additions & 0 deletions src_c/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,13 @@ window_get_opengl(pgWindowObject *self, void *v)
return PyBool_FromLong(hasGL);
}

static PyObject *
window_get_utility(pgWindowObject *self, void *v)
{
return PyBool_FromLong(SDL_GetWindowFlags(self->_win) &
SDL_WINDOW_UTILITY);
}

static void
window_dealloc(pgWindowObject *self, PyObject *_null)
{
Expand Down Expand Up @@ -944,6 +951,14 @@ window_init(pgWindowObject *self, PyObject *args, PyObject *kwargs)
if (_value_bool)
flags |= SDL_WINDOW_VULKAN;
}
else if (!strcmp(_key_str, "utility")) {
if (_value_bool) {
flags |= SDL_WINDOW_UTILITY;
#if !SDL_VERSION_ATLEAST(3, 0, 0)
flags |= SDL_WINDOW_SKIP_TASKBAR;
#endif
}
}
else {
PyErr_Format(PyExc_TypeError,
"__init__ got an unexpected flag \'%s\'",
Expand Down Expand Up @@ -1195,6 +1210,7 @@ static PyGetSetDef _window_getset[] = {
DOC_WINDOW_OPACITY, NULL},
{"id", (getter)window_get_window_id, NULL, DOC_WINDOW_ID, NULL},
{"opengl", (getter)window_get_opengl, NULL, DOC_WINDOW_OPENGL, NULL},
{"utility", (getter)window_get_utility, NULL, DOC_WINDOW_UTILITY, NULL},
{NULL, 0, NULL, NULL, NULL} /* Sentinel */
};

Expand Down
7 changes: 7 additions & 0 deletions test/window_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from math import trunc
from re import S
import unittest
import pygame
import os
Expand Down Expand Up @@ -290,6 +292,11 @@ def test_init_flags(self):
self.assertTrue(win.resizable)
win.destroy()

# test utility
win = Window(utility=True)
self.assertTrue(win.utility)
win.destroy()

# should raise a TypeError if keyword is random
self.assertRaises(TypeError, lambda: Window(aaa=True))
self.assertRaises(TypeError, lambda: Window(aaa=False))
Expand Down
Loading