Skip to content

Commit 06cf5f3

Browse files
authored
Merge pull request #3226 from gresm/window-no-taskbar
Utility Window implementation.
2 parents fbdf90a + 731db17 commit 06cf5f3

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

buildconfig/stubs/pygame/window.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class Window:
7070
def position(self, value: Union[int, Point]) -> None: ...
7171
@property
7272
def opengl(self) -> bool: ...
73+
@property
74+
def utility(self) -> bool: ...
7375
@classmethod
7476
@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")
7577
def from_display_module(cls) -> Window: ...

docs/reST/ref/window.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
(unrelated to INPUT_GRABBED).
4444
:param bool always_on_top: Create a window that is always presented above
4545
others.
46+
:param bool utility: Create a window that doesn't appear in the task bar.
4647

4748
Event behavior if one Window is created: When the close button is pressed,
4849
the ``QUIT`` event will be sent to the event queue.
@@ -289,6 +290,16 @@
289290

290291
.. versionadded:: 2.5.0
291292

293+
.. attribute:: utility
294+
295+
| :sl:`Get if the windos is an utility window (**read-only**)`
296+
| :sg:`utility -> bool`
297+
298+
``True`` if the window doesn't appear in the task bar, ``False`` otherwise.
299+
This only works for X11 and Windows, for other platforms, creating ``Window(utility=True)`` won't change anything.
300+
301+
.. versionadded:: 2.5.3
302+
292303
.. classmethod:: from_display_module
293304

294305
| :sl:`Create a Window object using window data from display module`

src_c/doc/window_doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define DOC_WINDOW_POSITION "position -> (int, int) or WINDOWPOS_CENTERED or WINDOWPOS_UNDEFINED\nGet or set the window position in screen coordinates"
1818
#define DOC_WINDOW_OPACITY "opacity -> float\nGet or set the window opacity, between 0.0 (fully transparent) and 1.0 (fully opaque)"
1919
#define DOC_WINDOW_OPENGL "opengl -> bool\nGet if the window supports OpenGL"
20+
#define DOC_WINDOW_UTILITY "utility -> bool\nGet if the windos is an utility window (**read-only**)"
2021
#define DOC_WINDOW_FROMDISPLAYMODULE "from_display_module() -> Window\nCreate a Window object using window data from display module"
2122
#define DOC_WINDOW_GETSURFACE "get_surface() -> Surface\nGet the window surface"
2223
#define DOC_WINDOW_FLIP "flip() -> None\nUpdate the display surface to the window."

src_c/window.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,13 @@ window_get_opengl(pgWindowObject *self, void *v)
779779
return PyBool_FromLong(hasGL);
780780
}
781781

782+
static PyObject *
783+
window_get_utility(pgWindowObject *self, void *v)
784+
{
785+
return PyBool_FromLong(SDL_GetWindowFlags(self->_win) &
786+
SDL_WINDOW_UTILITY);
787+
}
788+
782789
static void
783790
window_dealloc(pgWindowObject *self, PyObject *_null)
784791
{
@@ -944,6 +951,14 @@ window_init(pgWindowObject *self, PyObject *args, PyObject *kwargs)
944951
if (_value_bool)
945952
flags |= SDL_WINDOW_VULKAN;
946953
}
954+
else if (!strcmp(_key_str, "utility")) {
955+
if (_value_bool) {
956+
flags |= SDL_WINDOW_UTILITY;
957+
#if !SDL_VERSION_ATLEAST(3, 0, 0)
958+
flags |= SDL_WINDOW_SKIP_TASKBAR;
959+
#endif
960+
}
961+
}
947962
else {
948963
PyErr_Format(PyExc_TypeError,
949964
"__init__ got an unexpected flag \'%s\'",
@@ -1195,6 +1210,7 @@ static PyGetSetDef _window_getset[] = {
11951210
DOC_WINDOW_OPACITY, NULL},
11961211
{"id", (getter)window_get_window_id, NULL, DOC_WINDOW_ID, NULL},
11971212
{"opengl", (getter)window_get_opengl, NULL, DOC_WINDOW_OPENGL, NULL},
1213+
{"utility", (getter)window_get_utility, NULL, DOC_WINDOW_UTILITY, NULL},
11981214
{NULL, 0, NULL, NULL, NULL} /* Sentinel */
11991215
};
12001216

test/window_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ def test_init_flags(self):
290290
self.assertTrue(win.resizable)
291291
win.destroy()
292292

293+
# test utility
294+
win = Window(utility=True)
295+
self.assertTrue(win.utility)
296+
win.destroy()
297+
293298
# should raise a TypeError if keyword is random
294299
self.assertRaises(TypeError, lambda: Window(aaa=True))
295300
self.assertRaises(TypeError, lambda: Window(aaa=False))

0 commit comments

Comments
 (0)