:right-sidebar: True Display =================================================================== .. currentmodule:: gi.repository.Gdk .. class:: Display(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` ``GdkDisplay`` objects are the GDK representation of a workstation. Their purpose are two-fold: - To manage and provide information about input devices (pointers, keyboards, etc) - To manage and provide information about output devices (monitors, projectors, etc) Most of the input device handling has been factored out into separate :obj:`~gi.repository.Gdk.Seat` objects. Every display has a one or more seats, which can be accessed with :obj:`~gi.repository.Gdk.Display.get_default_seat` and :obj:`~gi.repository.Gdk.Display.list_seats`. Output devices are represented by :obj:`~gi.repository.Gdk.Monitor` objects, which can be accessed with :obj:`~gi.repository.Gdk.Display.get_monitor_at_surface` and similar APIs. Methods ------- .. rst-class:: interim-class .. class:: Display :no-index: .. method:: beep() -> None Emits a short beep on ``display`` .. method:: close() -> None Closes the connection to the windowing system for the given display. This cleans up associated resources. .. method:: create_gl_context() -> ~gi.repository.Gdk.GLContext Creates a new ``GdkGLContext`` for the ``GdkDisplay``. The context is disconnected from any particular surface or surface and cannot be used to draw to any surface. It can only be used to draw to non-surface framebuffers like textures. If the creation of the ``GdkGLContext`` failed, ``error`` will be set. Before using the returned ``GdkGLContext``, you will need to call :obj:`~gi.repository.Gdk.GLContext.make_current` or :obj:`~gi.repository.Gdk.GLContext.realize`. .. versionadded:: 4.6 .. method:: device_is_grabbed(device: ~gi.repository.Gdk.Device) -> bool Returns :const:`True` if there is an ongoing grab on ``device`` for ``display``. :param device: a ``GdkDevice`` .. method:: flush() -> None Flushes any requests queued for the windowing system. This happens automatically when the main loop blocks waiting for new events, but if your application is drawing without returning control to the main loop, you may need to call this function explicitly. A common case where this function needs to be called is when an application is executing drawing commands from a thread other than the thread where the main loop is running. This is most useful for X11. On windowing systems where requests are handled synchronously, this function will do nothing. .. method:: get_app_launch_context() -> ~gi.repository.Gdk.AppLaunchContext Returns a ``GdkAppLaunchContext`` suitable for launching applications on the given display. .. method:: get_clipboard() -> ~gi.repository.Gdk.Clipboard Gets the clipboard used for copy/paste operations. .. method:: get_default() -> ~gi.repository.Gdk.Display | None Gets the default ``GdkDisplay``. This is a convenience function for: gdk_display_manager_get_default_display (gdk_display_manager_get ()) .. method:: get_default_seat() -> ~gi.repository.Gdk.Seat | None Returns the default ``GdkSeat`` for this display. Note that a display may not have a seat. In this case, this function will return :const:`None`. .. method:: get_dmabuf_formats() -> ~gi.repository.Gdk.DmabufFormats Returns the dma-buf formats that are supported on this display. GTK may use OpenGL or Vulkan to support some formats. Calling this function will then initialize them if they aren't yet. The formats returned by this function can be used for negotiating buffer formats with producers such as v4l, pipewire or GStreamer. To learn more about dma-bufs, see :obj:`~gi.repository.Gdk.DmabufTextureBuilder`. .. versionadded:: 4.14 .. method:: get_monitor_at_surface(surface: ~gi.repository.Gdk.Surface) -> ~gi.repository.Gdk.Monitor | None Gets the monitor in which the largest area of ``surface`` resides. :param surface: a ``GdkSurface`` .. method:: get_monitors() -> ~gi.repository.Gio.ListModel Gets the list of monitors associated with this display. Subsequent calls to this function will always return the same list for the same display. You can listen to the GListModel::items-changed signal on this list to monitor changes to the monitor of this display. .. method:: get_name() -> str Gets the name of the display. .. method:: get_primary_clipboard() -> ~gi.repository.Gdk.Clipboard Gets the clipboard used for the primary selection. On backends where the primary clipboard is not supported natively, GDK emulates this clipboard locally. .. method:: get_setting(name: str, value: ~typing.Any) -> bool Retrieves a desktop-wide setting such as double-click time for the ``display``. :param name: the name of the setting :param value: location to store the value of the setting .. method:: get_startup_notification_id() -> str | None Gets the startup notification ID for a Wayland display, or :const:`None` if no ID has been defined. .. deprecated:: 4.10 Please do not use it in newly written code .. method:: is_closed() -> bool Finds out if the display has been closed. .. method:: is_composited() -> bool Returns whether surfaces can reasonably be expected to have their alpha channel drawn correctly on the screen. Check :obj:`~gi.repository.Gdk.Display.is_rgba` for whether the display supports an alpha channel. On X11 this function returns whether a compositing manager is compositing on ``display``. On modern displays, this value is always :const:`True`. .. method:: is_rgba() -> bool Returns whether surfaces on this ``display`` are created with an alpha channel. Even if a :const:`True` is returned, it is possible that the surface’s alpha channel won’t be honored when displaying the surface on the screen: in particular, for X an appropriate windowing manager and compositing manager must be running to provide appropriate display. Use :obj:`~gi.repository.Gdk.Display.is_composited` to check if that is the case. On modern displays, this value is always :const:`True`. .. method:: list_seats() -> list[~gi.repository.Gdk.Seat] Returns the list of seats known to ``display``. .. method:: map_keycode(keycode: int) -> tuple[bool, list[~gi.repository.Gdk.KeymapKey], list[int]] Returns the keyvals bound to ``keycode``. The Nth ``GdkKeymapKey`` in ``keys`` is bound to the Nth keyval in ``keyvals``. When a keycode is pressed by the user, the keyval from this list of entries is selected by considering the effective keyboard group and level. Free the returned arrays with :func:`~gi.repository.GLib.free`. :param keycode: a keycode .. method:: map_keyval(keyval: int) -> tuple[bool, list[~gi.repository.Gdk.KeymapKey]] Obtains a list of keycode/group/level combinations that will generate ``keyval``. Groups and levels are two kinds of keyboard mode; in general, the level determines whether the top or bottom symbol on a key is used, and the group determines whether the left or right symbol is used. On US keyboards, the shift key changes the keyboard level, and there are no groups. A group switch key might convert a keyboard between Hebrew to English modes, for example. ``GdkEventKey`` contains a ``%group`` field that indicates the active keyboard group. The level is computed from the modifier mask. The returned array should be freed with :func:`~gi.repository.GLib.free`. :param keyval: a keyval, such as :const:`~gi.repository.Gdk.KEY_A`, :const:`~gi.repository.Gdk.KEY_UP`, :const:`~gi.repository.Gdk.KEY_RETURN`, etc. .. method:: notify_startup_complete(startup_id: str) -> None Indicates to the GUI environment that the application has finished loading, using a given identifier. GTK will call this function automatically for `GtkWindow <../gtk4/class.Window.html>`_ with custom startup-notification identifier unless `gtk_window_set_auto_startup_notification() <../gtk4/method.Window.set_auto_startup_notification.html>`_ is called to disable that feature. .. deprecated:: 4.10 Using :obj:`~gi.repository.Gdk.Toplevel.set_startup_id` is sufficient :param startup_id: a startup-notification identifier, for which notification process should be completed .. method:: open(display_name: str | None = None) -> ~gi.repository.Gdk.Display | None Opens a display. If opening the display fails, ``NULL`` is returned. :param display_name: the name of the display to open .. method:: prepare_gl() -> bool Checks that OpenGL is available for ``self`` and ensures that it is properly initialized. When this fails, an ``error`` will be set describing the error and this function returns :const:`False`. Note that even if this function succeeds, creating a ``GdkGLContext`` may still fail. This function is idempotent. Calling it multiple times will just return the same value or error. You never need to call this function, GDK will call it automatically as needed. But you can use it as a check when setting up code that might make use of OpenGL. .. versionadded:: 4.4 .. method:: put_event(event: ~gi.repository.Gdk.Event) -> None Adds the given event to the event queue for ``display``. .. deprecated:: 4.10 This function is only useful in very special situations and should not be used by applications. :param event: a ``GdkEvent`` .. method:: supports_input_shapes() -> bool Returns :const:`True` if the display supports input shapes. This means that :obj:`~gi.repository.Gdk.Surface.set_input_region` can be used to modify the input shape of surfaces on ``display``. On modern displays, this value is always :const:`True`. .. method:: supports_shadow_width() -> bool Returns whether it's possible for a surface to draw outside of the window area. If :const:`True` is returned the application decides if it wants to draw shadows. If :const:`False` is returned, the compositor decides if it wants to draw shadows. .. versionadded:: 4.14 .. method:: sync() -> None Flushes any requests queued for the windowing system and waits until all requests have been handled. This is often used for making sure that the display is synchronized with the current state of the program. Calling :obj:`~gi.repository.Gdk.Display.sync` before :obj:`~gi.repository.GdkX11.Display.error_trap_pop` makes sure that any errors generated from earlier requests are handled before the error trap is removed. This is most useful for X11. On windowing systems where requests are handled synchronously, this function will do nothing. .. method:: translate_key(keycode: int, state: ~gi.repository.Gdk.ModifierType, group: int) -> tuple[bool, int, int, int, ~gi.repository.Gdk.ModifierType] Translates the contents of a ``GdkEventKey`` into a keyval, effective group, and level. Modifiers that affected the translation and are thus unavailable for application use are returned in ``consumed_modifiers``. The ``effective_group`` is the group that was actually used for the translation; some keys such as Enter are not affected by the active keyboard group. The ``level`` is derived from ``state``. ``consumed_modifiers`` gives modifiers that should be masked out from ``state`` when comparing this key press to a keyboard shortcut. For instance, on a US keyboard, the ``plus`` symbol is shifted, so when comparing a key press to a ``plus`` accelerator ```` should be masked out. This function should rarely be needed, since ``GdkEventKey`` already contains the translated keyval. It is exported for the benefit of virtualized test environments. :param keycode: a keycode :param state: a modifier state :param group: active keyboard group Properties ---------- .. rst-class:: interim-class .. class:: Display :no-index: .. attribute:: props.composited :type: bool :const:`True` if the display properly composites the alpha channel. .. attribute:: props.dmabuf_formats :type: ~gi.repository.Gdk.DmabufFormats The dma-buf formats that are supported on this display .. versionadded:: 4.14 .. attribute:: props.input_shapes :type: bool :const:`True` if the display supports input shapes. .. attribute:: props.rgba :type: bool :const:`True` if the display supports an alpha channel. .. attribute:: props.shadow_width :type: bool :const:`True` if the display supports extensible frames. .. versionadded:: 4.14 Signals ------- .. rst-class:: interim-class .. class:: Display.signals :no-index: .. method:: closed(is_error: bool) -> None Emitted when the connection to the windowing system for ``display`` is closed. :param is_error: :const:`True` if the display was closed due to an error .. method:: opened() -> None Emitted when the connection to the windowing system for ``display`` is opened. .. method:: seat_added(seat: ~gi.repository.Gdk.Seat) -> None Emitted whenever a new seat is made known to the windowing system. :param seat: the seat that was just added .. method:: seat_removed(seat: ~gi.repository.Gdk.Seat) -> None Emitted whenever a seat is removed by the windowing system. :param seat: the seat that was just removed .. method:: setting_changed(setting: str) -> None Emitted whenever a setting changes its value. :param setting: the name of the setting that changed