Skip to content
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
3 changes: 3 additions & 0 deletions buildconfig/stubs/pygame/display.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ def set_window_position(position: Point) -> None:
still be able to move the window after this call. See also
:func:`pygame.display.get_window_position()`.

.. note:: This function is not supported on some video drivers (like wayland)
and a :exc:`pygame.error` exception may be raised in such cases.

.. versionadded:: 2.5.0
"""

Expand Down
12 changes: 11 additions & 1 deletion buildconfig/stubs/pygame/window.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ class Window:

Setting the always-on-top mode requires SDL 2.0.16+.

.. note:: Setting this property is not supported on some video drivers (like wayland)
and a :exc:`pygame.error` exception may be raised in such cases.

.. versionadded:: 2.3.1
"""

Expand Down Expand Up @@ -296,12 +299,19 @@ class Window:

The position may be a tuple of (x, y) coordinates or ``WINDOWPOS_CENTERED`` or
``WINDOWPOS_UNDEFINED``. The origin is the topleft of the main display.

.. note:: Setting this property is not supported on some video drivers (like wayland)
and a :exc:`pygame.error` exception may be raised in such cases.
"""

@position.setter
def position(self, value: Union[int, Point]) -> None: ...
opacity: float
"""Get or set the window opacity, between 0.0 (fully transparent) and 1.0 (fully opaque)."""
"""Get or set the window opacity, between 0.0 (fully transparent) and 1.0 (fully opaque).

.. note:: Setting this property is not supported on some video drivers (like wayland)
and a :exc:`pygame.error` exception may be raised in such cases.
"""

@property
def opengl(self) -> bool:
Expand Down
9 changes: 9 additions & 0 deletions test/display_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from pygame import display
from pygame.tests.test_utils import question

pygame.display.init()
is_wayland = pygame.display.get_driver() == "wayland"
pygame.display.quit()


class DisplayModuleTest(unittest.TestCase):
default_caption = "pygame window"
Expand Down Expand Up @@ -71,6 +75,7 @@ def test_get_active(self):
os.environ.get("SDL_VIDEODRIVER") == pygame.NULL_VIDEODRIVER,
"requires the SDL_VIDEODRIVER to be a non-null value",
)
@unittest.skipIf(is_wayland, "broken on wayland")
def test_get_active_iconify(self):
"""Test the get_active function after an iconify"""

Expand Down Expand Up @@ -411,6 +416,7 @@ def test_gl_set_attribute(self):
os.environ.get("SDL_VIDEODRIVER") in [pygame.NULL_VIDEODRIVER, "android"],
"iconify is only supported on some video drivers/platforms",
)
@unittest.skipIf(is_wayland, "broken on wayland")
def test_iconify(self):
pygame.display.set_mode((640, 480))

Expand Down Expand Up @@ -519,6 +525,7 @@ def test_quit__multiple(self):
pygame.version.SDL >= (2, 32, 50),
"set_gamma is removed in SDL3, does not work in sdl2-compat either",
)
@unittest.skipIf(is_wayland, "not supported on wayland")
def test_set_gamma(self):
pygame.display.set_mode((1, 1))

Expand All @@ -537,6 +544,7 @@ def test_set_gamma(self):
pygame.version.SDL >= (2, 32, 50),
"set_gamma is removed in SDL3, does not work in sdl2-compat either",
)
@unittest.skipIf(is_wayland, "not supported on wayland")
def test_set_gamma__tuple(self):
pygame.display.set_mode((1, 1))

Expand Down Expand Up @@ -690,6 +698,7 @@ def test_toggle_fullscreen(self):
(test_surf.get_width(), test_surf.get_height()), width_height
)

@unittest.skipIf(is_wayland, "not supported on wayland")
def test_get_set_window_position(self):
pygame.display.set_mode((500, 500))
pygame.display.set_window_position((420, 360))
Expand Down
10 changes: 8 additions & 2 deletions test/event_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import pygame

pygame.display.init()
is_wayland = pygame.display.get_driver() == "wayland"
pygame.display.quit()

EVENT_TYPES = (
# pygame.NOEVENT,
# pygame.ACTIVEEVENT,
Expand Down Expand Up @@ -837,8 +841,9 @@ def test_pump(self):

@unittest.skipIf(
os.environ.get("SDL_VIDEODRIVER") == pygame.NULL_VIDEODRIVER,
'requires the SDL_VIDEODRIVER to be a non-null value',
"requires the SDL_VIDEODRIVER to be a non-null value",
)
@unittest.skipIf(is_wayland, "broken on wayland")
def test_set_grab__and_get_symmetric(self):
"""Ensure event grabbing can be enabled and disabled.

Expand Down Expand Up @@ -905,8 +910,9 @@ def test_get_blocked__event_sequence(self):

@unittest.skipIf(
os.environ.get("SDL_VIDEODRIVER") == pygame.NULL_VIDEODRIVER,
'requires the SDL_VIDEODRIVER to be a non-null value',
"requires the SDL_VIDEODRIVER to be a non-null value",
)
@unittest.skipIf(is_wayland, "broken on wayland")
def test_get_grab(self):
"""Ensure get_grab() works as expected"""
surf = pygame.display.set_mode((10, 10))
Expand Down
10 changes: 10 additions & 0 deletions test/surface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ def test_subsurface_rle2(self):
self.assertTrue(s1.get_flags() & pygame.RLEACCELOK)
self.assertTrue(not s2.get_flags() & pygame.RLEACCELOK)

@unittest.skipIf(
pygame.version.SDL >= (2, 32, 50),
"fails on SDL3, does not work in sdl2-compat either. See: "
"https://github.com/libsdl-org/sdl2-compat/issues/476",
)
def test_solarwolf_rle_usage(self):
"""Test for error/crash when calling set_colorkey() followed
by convert twice in succession. Code originally taken
Expand Down Expand Up @@ -404,6 +409,11 @@ def optimize(img):
finally:
pygame.display.quit()

@unittest.skipIf(
pygame.version.SDL >= (2, 32, 50),
"fails on SDL3, does not work in sdl2-compat either. See: "
"https://github.com/libsdl-org/sdl2-compat/issues/476",
)
def test_solarwolf_rle_usage_2(self):
"""Test for RLE status after setting alpha"""

Expand Down
11 changes: 9 additions & 2 deletions test/window_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

IS_PYPY = "PyPy" == platform.python_implementation()

pygame.display.init()
is_wayland = pygame.display.get_driver() == "wayland"
pygame.display.quit()


class WindowTypeTest(unittest.TestCase):
DEFAULT_TITLE = "pygame window"
Expand Down Expand Up @@ -102,6 +106,7 @@ def test_always_on_top(self):
SDL < (2, 0, 16),
"requires SDL 2.0.16+",
)
@unittest.skipIf(is_wayland, "not supported on wayland")
def test_always_on_top_set(self):
self.win.always_on_top = True
self.assertTrue(self.win.always_on_top)
Expand Down Expand Up @@ -149,6 +154,7 @@ def test_size(self):

self.win.size = (640, 480)

@unittest.skipIf(is_wayland, "not supported on wayland")
def test_position(self):
new_pos = (self.win.position[0] + 20, self.win.position[1] + 10)
self.win.position = new_pos
Expand All @@ -160,8 +166,8 @@ def test_position(self):
self.assertRaises(TypeError, lambda: setattr(self.win, "position", 123))

# test set position when init
win = Window(position=(20, 48))
self.assertTupleEqual((20, 48), win.position)
win = Window(position=new_pos)
self.assertTupleEqual(new_pos, win.position)
win.destroy()

self.assertRaises(TypeError, lambda: Window(position=123))
Expand Down Expand Up @@ -255,6 +261,7 @@ def test_opacity(self):
os.environ.get("SDL_VIDEODRIVER") == pygame.NULL_VIDEODRIVER,
"requires the SDL_VIDEODRIVER to be a non-null value",
)
@unittest.skipIf(is_wayland, "not supported on wayland")
def test_opacity_set(self):
self.win.opacity = 0.5
self.assertEqual(self.win.opacity, 0.5)
Expand Down
Loading