diff --git a/wlroots/wlr_types/compositor.py b/wlroots/wlr_types/compositor.py index 8f3232d9..acfdd524 100644 --- a/wlroots/wlr_types/compositor.py +++ b/wlroots/wlr_types/compositor.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Final from weakref import WeakKeyDictionary from pywayland.protocol.wayland import WlOutput @@ -19,7 +19,7 @@ from wlroots.renderer import Renderer -COMPOSITOR_VERSION = 5 +_MAX_COMPOSITOR_VERSION: Final = 5 class Compositor(Ptr): @@ -35,9 +35,9 @@ def __init__( :param renderer: The wlroots renderer to attach the compositor to. """ - if not version <= COMPOSITOR_VERSION: + if not 0 < version <= _MAX_COMPOSITOR_VERSION: raise ValueError( - f"Compositor version must be less than or equal to {COMPOSITOR_VERSION}" + f"Invalid compositor version, should be a value between 1 (inclusive) and {_MAX_COMPOSITOR_VERSION} (inclusive), got: {version}" ) if renderer is None: self._ptr = lib.wlr_compositor_create(display._ptr, version, ffi.NULL) diff --git a/wlroots/wlr_types/layer_shell_v1.py b/wlroots/wlr_types/layer_shell_v1.py index f3f19074..ec8c75af 100644 --- a/wlroots/wlr_types/layer_shell_v1.py +++ b/wlroots/wlr_types/layer_shell_v1.py @@ -3,7 +3,7 @@ import enum from dataclasses import dataclass -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Final from weakref import WeakKeyDictionary from pywayland.server import Signal @@ -197,14 +197,16 @@ def surface_at(self, sx: float, sy: float) -> tuple[Surface | None, float, float return Surface(surface_ptr), sub_x_data[0], sub_y_data[0] -LAYER_SHELL_VERSION = 4 +_MAX_LAYER_SHELL_VERSION: Final = 4 class LayerShellV1(PtrHasData): def __init__(self, display: Display, version: int) -> None: """Create an wlr_xdg_output_manager_v1""" - if not 0 < version <= LAYER_SHELL_VERSION: - raise ValueError("Invalid layer shell version.") + if not 0 < version <= _MAX_LAYER_SHELL_VERSION: + raise ValueError( + f"Invalid layer shell version, should be a value between 1 (inclusive) and {_MAX_LAYER_SHELL_VERSION} (inclusive), got: {version}" + ) self._ptr = lib.wlr_layer_shell_v1_create(display._ptr, version)