Skip to content

Gdk.Display

class — extends GObject.Object

A 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 Seat objects. Every display has a one or more seats, which can be accessed with Display.get_default_seat and Display.list_seats.

Output devices are represented by Monitor objects, which can be accessed with Display.get_monitor_at_surface and similar APIs.

Methods

beep

def beep(self) -> None

Emits a short beep on display

close

def close(self) -> None

Closes the connection to the windowing system for the given display.

This cleans up associated resources.

create_gl_context

def create_gl_context(self) -> 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 GLContext.make_current or GLContext.realize.

device_is_grabbed

def device_is_grabbed(self, device: Device) -> bool

Returns True if there is an ongoing grab on device for display.

Parameters:

  • device — a GdkDevice

flush

def flush(self) -> 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.

get_app_launch_context

def get_app_launch_context(self) -> AppLaunchContext

Returns a GdkAppLaunchContext suitable for launching applications on the given display.

get_clipboard

def get_clipboard(self) -> Clipboard

Gets the clipboard used for copy/paste operations.

get_default_seat

def get_default_seat(self) -> 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 None.

get_dmabuf_formats

def get_dmabuf_formats(self) -> 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 DmabufTextureBuilder.

This function is threadsafe. It can be called from any thread.

get_monitor_at_surface

def get_monitor_at_surface(self, surface: Surface) -> Monitor | None

Gets the monitor in which the largest area of surface resides.

Parameters:

  • surface — a GdkSurface

get_monitors

def get_monitors(self) -> 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.

get_name

def get_name(self) -> str

Gets the name of the display.

get_primary_clipboard

def get_primary_clipboard(self) -> Clipboard

Gets the clipboard used for the primary selection.

On backends where the primary clipboard is not supported natively, GDK emulates this clipboard locally.

get_setting

def get_setting(self, name: str, value: GObject.Value) -> bool

Retrieves a desktop-wide setting such as double-click time for the display.

Parameters:

  • name — the name of the setting
  • value — location to store the value of the setting

get_startup_notification_id

def get_startup_notification_id(self) -> str | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the startup notification ID for a Wayland display, or None if no ID has been defined.

is_closed

def is_closed(self) -> bool

Finds out if the display has been closed.

is_composited

def is_composited(self) -> bool

Returns whether surfaces can reasonably be expected to have their alpha channel drawn correctly on the screen.

Check 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 True.

is_rgba

def is_rgba(self) -> bool

Returns whether surfaces on this display are created with an alpha channel.

Even if a 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 Display.is_composited to check if that is the case.

On modern displays, this value is always True.

list_seats

def list_seats(self) -> list[Seat]

Returns the list of seats known to display.

map_keycode

def map_keycode(self, keycode: int) -> tuple[bool, list[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 GLib.free.

Parameters:

  • keycode — a keycode

map_keyval

def map_keyval(self, keyval: int) -> tuple[bool, list[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 GLib.free.

Parameters:

notify_startup_complete

def notify_startup_complete(self, startup_id: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Indicates to the GUI environment that the application has finished loading, using a given identifier.

GTK will call this function automatically for GtkWindow with custom startup-notification identifier unless Gtk.Window.set_auto_startup_notification is called to disable that feature.

Parameters:

  • startup_id — a startup-notification identifier, for which notification process should be completed

prepare_gl

def prepare_gl(self) -> 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 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.

put_event

def put_event(self, event: Event) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Adds the given event to the event queue for display.

Parameters:

  • event — a GdkEvent

supports_input_shapes

def supports_input_shapes(self) -> bool

Returns True if the display supports input shapes.

This means that Surface.set_input_region can be used to modify the input shape of surfaces on display.

On modern displays, this value is always True.

supports_shadow_width

def supports_shadow_width(self) -> bool

Returns whether it's possible for a surface to draw outside of the window area.

If True is returned the application decides if it wants to draw shadows. If False is returned, the compositor decides if it wants to draw shadows.

sync

def sync(self) -> 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 Display.sync before 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.

translate_key

def translate_key(self, keycode: int, state: ModifierType | int, group: int) -> tuple[bool, int, int, int, ModifierType | int]

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 <Control>plus accelerator <Shift> 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.

Parameters:

  • keycode — a keycode
  • state — a modifier state
  • group — active keyboard group

Static functions

get_default

@staticmethod
def get_default() -> Display | None

Gets the default GdkDisplay.

This is a convenience function for:

[`DisplayManager.get_default_display`](./DisplayManager.md#method-get_default_display) ([`DisplayManager.get`](./DisplayManager.md#static-get))

open

@staticmethod
def open(display_name: str | None = ...) -> Display | None

Opens a display.

If opening the display fails, NULL is returned.

Parameters:

  • display_name — the name of the display to open

Properties

composited

composited: bool  # read-only

True if the display properly composites the alpha channel.

dmabuf_formats

dmabuf_formats: DmabufFormats  # read-only

The dma-buf formats that are supported on this display

input_shapes

input_shapes: bool  # read-only

True if the display supports input shapes.

rgba

rgba: bool  # read-only

True if the display supports an alpha channel.

shadow_width

shadow_width: bool  # read-only

True if the display supports extensible frames.

Signals

closed

def on_closed(self, is_error: bool) -> None: ...

Emitted when the connection to the windowing system for display is closed.

opened

def on_opened(self) -> None: ...

Emitted when the connection to the windowing system for display is opened.

seat-added

def on_seat_added(self, seat: Seat) -> None: ...

Emitted whenever a new seat is made known to the windowing system.

seat-removed

def on_seat_removed(self, seat: Seat) -> None: ...

Emitted whenever a seat is removed by the windowing system.

setting-changed

def on_setting_changed(self, setting: str) -> None: ...

Emitted whenever a setting changes its value.