Skip to content

New display information management: pygame.Display et al. #3715

@Matiiss

Description

@Matiiss

With the advent of SDL3... I mean, it's been there for a while now

Note for SDL2, some of this functionality can be recreated with existing API and that should be done whenever possible
For example: #3530 (#3530 (comment))

A bunch of new API stuff relating to displays has been introduced, as of right now, the below should be an exhaustive list of all the related functions (the section names are meant to represent the Python interface) (the checkboxes are meant to help track what has been implemented):

Meta:

Instance methods:

Class methods:

Auxiliary methods (potentially class methods):

This might live under pygame.display (e.g., pygame.display.Display, but, of course, aliased to pygame.Display)

Tentative Python signatures:

from __future__ import annotations

from enum import Enum
from fractions import Fraction
from typing import Self

from pygame import Rect, Window
from pygame.typing import Point


# https://wiki.libsdl.org/SDL3/SDL_DisplayOrientation
class DisplayOrientation(Enum): ...


# https://wiki.libsdl.org/SDL3/SDL_DisplayMode
class DisplayMode:
    @property
    def display_id(self) -> int: ...
    # AND/OR
    @property
    def display(self) -> Display: ...

    @property
    # OR `pixel_format`
    # this requires a PixelFormat enum which is out of scope for this issue
    def format(self) -> ...: ...

    @property
    # OR `width`
    def w(self) -> int: ...

    @property
    # OR `height`
    def h(self) -> int: ...

    @property
    def pixel_density(self) -> float: ...

    # @property
    # def refresh_rate(self) -> float: ...
    # @property
    # def refresh_rate_numerator(self) -> int: ...
    # @property
    # def refresh_rate_denominator(self) -> int: ...
    # OR (better yet)
    @property
    def refresh_rate(self) -> Fraction: ...


class Display:
    # https://wiki.libsdl.org/SDL3/SDL_DisplayID
    @property
    def id(self) -> int: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplayName
    @property
    def name(self) -> str: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplayBounds
    @property
    def bounds(self) -> Rect: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplayUsableBounds
    @property
    def usable_bounds(self) -> Rect: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplayContentScale
    @property
    def content_scale(self) -> float: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetCurrentDisplayMode
    @property
    def current_display_mode(self) -> DisplayMode: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDesktopDisplayMode
    @property
    def desktop_display_mode(self) -> DisplayMode: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetFullscreenDisplayModes
    @property
    def fullscreen_display_modes(self) -> list[DisplayMode]: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetCurrentDisplayOrientation
    @property
    def current_display_orientation(self) -> DisplayOrientation: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetNaturalDisplayOrientation
    @property
    def natural_display_orientation(self) -> DisplayOrientation: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplayProperties
    # this needs a whole Property type that seems wayyy out of scope of this issue
    # for more information read https://wiki.libsdl.org/SDL3/CategoryProperties
    @property
    def properties(self) -> ...: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetClosestFullscreenDisplayMode
    def get_closest_fullscreen_display_mode(
        self,
        width: int,
        height: int,
        refresh_rate: float = 0.0,
        include_hight_density_modes: bool = True,  # or default False?
    ) -> DisplayMode: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplayForPoint
    @classmethod
    def from_point(cls, point: Point) -> Self: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplayForRect
    @classmethod
    def from_rect(cls, rect: Rect) -> Self: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplayForWindow
    @classmethod
    def from_window(cls, window: Window) -> Self: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetDisplays
    @classmethod
    def get_all(cls) -> list[Self]: ...

    # https://wiki.libsdl.org/SDL3/SDL_GetPrimaryDisplay
    @classmethod
    def get_primary(cls) -> Self: ...


# https://wiki.libsdl.org/SDL3/SDL_GetDisplays
def get_displays() -> list[Display]: ...


# https://wiki.libsdl.org/SDL3/SDL_GetPrimaryDisplay
def get_primary_display() -> Display: ...

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions