Gdk.Display

g GObject.Object GObject.Object Gdk.Display Gdk.Display GObject.Object->Gdk.Display

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

get_default ()

class

open (display_name)

beep ()

close ()

create_gl_context ()

device_is_grabbed (device)

flush ()

get_app_launch_context ()

get_clipboard ()

get_default_seat ()

get_monitor_at_surface (surface)

get_monitors ()

get_name ()

get_primary_clipboard ()

get_setting (name, value)

get_startup_notification_id ()

is_closed ()

is_composited ()

is_rgba ()

list_seats ()

map_keycode (keycode)

map_keyval (keyval)

notify_startup_complete (startup_id)

prepare_gl ()

put_event (event)

supports_input_shapes ()

sync ()

translate_key (keycode, state, group)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

composited

bool

r

input-shapes

bool

r

rgba

bool

r

Signals

Inherited:

GObject.Object (1)

Name

Short Description

closed

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

opened

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

seat-added

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

seat-removed

Emitted whenever a seat is removed by the windowing system.

setting-changed

Emitted whenever a setting changes its value.

Fields

Inherited:

GObject.Object (1)

Class Details

class Gdk.Display(**kwargs)
Bases:

GObject.Object

Abstract:

No

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

Output devices are represented by [class`Gdk`.Monitor] objects, which can be accessed with [method`Gdk`.Display.get_monitor_at_surface] and similar APIs.

classmethod get_default()[source]
Returns:

a GdkDisplay, or None if there is no default display

Return type:

Gdk.Display or None

Gets the default GdkDisplay.

This is a convenience function for:

Gdk.DisplayManager.get_default_display (Gdk.DisplayManager.get ())

classmethod open(display_name)[source]
Parameters:

display_name (str or None) – the name of the display to open

Returns:

a GdkDisplay

Return type:

Gdk.Display or None

Opens a display.

If opening the display fails, NULL is returned.

beep()[source]

Emits a short beep on self

close()[source]

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

This cleans up associated resources.

create_gl_context()[source]
Raises:

GLib.Error

Returns:

the newly created GdkGLContext

Return type:

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 [method`Gdk`.GLContext.make_current] or [method`Gdk`.GLContext.realize].

New in version 4.6.

device_is_grabbed(device)[source]
Parameters:

device (Gdk.Device) – a GdkDevice

Returns:

True if there is a grab in effect for device.

Return type:

bool

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

flush()[source]

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()[source]
Returns:

a new GdkAppLaunchContext for self

Return type:

Gdk.AppLaunchContext

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

get_clipboard()[source]
Returns:

the display’s clipboard

Return type:

Gdk.Clipboard

Gets the clipboard used for copy/paste operations.

get_default_seat()[source]
Returns:

the default seat.

Return type:

Gdk.Seat or 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_monitor_at_surface(surface)[source]
Parameters:

surface (Gdk.Surface) – a GdkSurface

Returns:

the monitor with the largest overlap with surface

Return type:

Gdk.Monitor or None

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

get_monitors()[source]
Returns:

a GListModel of GdkMonitor

Return type:

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 Gio.ListModel ::items-changed signal on this list to monitor changes to the monitor of this display.

get_name()[source]
Returns:

a string representing the display name. This string is owned by GDK and should not be modified or freed.

Return type:

str

Gets the name of the display.

get_primary_clipboard()[source]
Returns:

the primary clipboard

Return type:

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.

get_setting(name, value)[source]
Parameters:
  • name (str) – the name of the setting

  • value (GObject.Value) – location to store the value of the setting

Returns:

True if the setting existed and a value was stored in value, False otherwise

Return type:

bool

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

get_startup_notification_id()[source]
Returns:

the startup notification ID for self

Return type:

str or None

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

Deprecated since version 4.10.

is_closed()[source]
Returns:

True if the display is closed.

Return type:

bool

Finds out if the display has been closed.

is_composited()[source]
Returns:

Whether surfaces with RGBA visuals can reasonably be expected to have their alpha channels drawn correctly on the screen.

Return type:

bool

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

Check [method`Gdk`.Display.is_rgba] for whether the display supports an alpha channel.

On X11 this function returns whether a compositing manager is compositing on self.

On modern displays, this value is always True.

is_rgba()[source]
Returns:

True if surfaces are created with an alpha channel or False if the display does not support this functionality.

Return type:

bool

Returns whether surfaces on this self 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 [method`Gdk`.Display.is_composited] to check if that is the case.

On modern displays, this value is always True.

list_seats()[source]
Returns:

the list of seats known to the GdkDisplay

Return type:

[Gdk.Seat]

Returns the list of seats known to self.

map_keycode(keycode)[source]
Parameters:

keycode (int) – a keycode

Returns:

True if there were any entries

keys:

return location for array of GdkKeymapKey

keyvals:

return location for array of keyvals

Return type:

(bool, keys: [Gdk.KeymapKey], keyvals: [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().

map_keyval(keyval)[source]
Parameters:

keyval (int) – a keyval, such as Gdk.KEY_a, Gdk.KEY_Up, Gdk.KEY_Return, etc.

Returns:

True if keys were found and returned

keys:

return location for an array of GdkKeymapKey

Return type:

(bool, keys: [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 GLib.free().

notify_startup_complete(startup_id)[source]
Parameters:

startup_id (str) – a startup-notification identifier, for which notification process should be completed

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.

Deprecated since version 4.10: Using [method`Gdk`.Toplevel.set_startup_id] is sufficient

prepare_gl()[source]
Raises:

GLib.Error

Returns:

True if the display supports OpenGL

Return type:

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.

New in version 4.4.

put_event(event)[source]
Parameters:

event (Gdk.Event) – a GdkEvent

Adds the given event to the event queue for self.

Deprecated since version 4.10: This function is only useful in very special situations and should not be used by applications.

supports_input_shapes()[source]
Returns:

True if surfaces with modified input shape are supported

Return type:

bool

Returns True if the display supports input shapes.

This means that [method`Gdk`.Surface.set_input_region] can be used to modify the input shape of surfaces on self.

On modern displays, this value is always True.

sync()[source]

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 [method`Gdk`.Display.sync] before [method`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(keycode, state, group)[source]
Parameters:
  • keycode (int) – a keycode

  • state (Gdk.ModifierType) – a modifier state

  • group (int) – active keyboard group

Returns:

True if there was a keyval bound to keycode/state/group.

keyval:

return location for keyval

effective_group:

return location for effective group

level:

return location for level

consumed:

return location for modifiers that were used to determine the group or level

Return type:

(bool, keyval: int, effective_group: int, level: int, consumed: 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 <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.

Signal Details

Gdk.Display.signals.closed(display, is_error)
Signal Name:

closed

Flags:

RUN_LAST

Parameters:
  • display (Gdk.Display) – The object which received the signal

  • is_error (bool) – True if the display was closed due to an error

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

Gdk.Display.signals.opened(display)
Signal Name:

opened

Flags:

RUN_LAST

Parameters:

display (Gdk.Display) – The object which received the signal

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

Gdk.Display.signals.seat_added(display, seat)
Signal Name:

seat-added

Flags:

RUN_LAST

Parameters:
  • display (Gdk.Display) – The object which received the signal

  • seat (Gdk.Seat) – the seat that was just added

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

Gdk.Display.signals.seat_removed(display, seat)
Signal Name:

seat-removed

Flags:

RUN_LAST

Parameters:
  • display (Gdk.Display) – The object which received the signal

  • seat (Gdk.Seat) – the seat that was just removed

Emitted whenever a seat is removed by the windowing system.

Gdk.Display.signals.setting_changed(display, setting)
Signal Name:

setting-changed

Flags:

RUN_LAST

Parameters:
  • display (Gdk.Display) – The object which received the signal

  • setting (str) – the name of the setting that changed

Emitted whenever a setting changes its value.

Property Details

Gdk.Display.props.composited
Name:

composited

Type:

bool

Default Value:

True

Flags:

READABLE

True if the display properly composites the alpha channel.

Gdk.Display.props.input_shapes
Name:

input-shapes

Type:

bool

Default Value:

True

Flags:

READABLE

True if the display supports input shapes.

Gdk.Display.props.rgba
Name:

rgba

Type:

bool

Default Value:

True

Flags:

READABLE

True if the display supports an alpha channel.