Skip to content

Gdk.DisplayManager

class — extends GObject.Object

Offers notification when displays appear or disappear.

GdkDisplayManager is a singleton object.

You can use DisplayManager.get to obtain the GdkDisplayManager singleton, but that should be rarely necessary. Typically, initializing GTK opens a display that you can work with without ever accessing the GdkDisplayManager.

The GDK library can be built with support for multiple backends. The GdkDisplayManager object determines which backend is used at runtime.

In the rare case that you need to influence which of the backends is being used, you can use set_allowed_backends. Note that you need to call this function before initializing GTK.

Backend-specific code

When writing backend-specific code that is supposed to work with multiple GDK backends, you have to consider both compile time and runtime. At compile time, use the GDK_WINDOWING_X11, GDK_WINDOWING_WIN32 macros, etc. to find out which backends are present in the GDK library you are building your application against. At runtime, use type-check macros like GDK_IS_X11_DISPLAY() to find out which backend is in use:

#ifdef GDK_WINDOWING_X11
  if (GDK_IS_X11_DISPLAY (display))
    {
      // make X11-specific calls here
    }
  else
#endif
#ifdef GDK_WINDOWING_MACOS
  if (GDK_IS_MACOS_DISPLAY (display))
    {
      // make Quartz-specific calls here
    }
  else
#endif
  g_error ("Unsupported GDK backend");

Methods

get_default_display

def get_default_display(self) -> Display | None

Gets the default GdkDisplay.

list_displays

def list_displays(self) -> list[Display]

List all currently open displays.

open_display

def open_display(self, name: str | None = ...) -> Display | None

Opens a display.

Parameters:

  • name — the name of the display to open

set_default_display

def set_default_display(self, display: Display) -> None

Sets display as the default display.

Parameters:

  • display — a GdkDisplay

Static functions

get

@staticmethod
def get() -> DisplayManager

Gets the singleton GdkDisplayManager object.

When called for the first time, this function consults the GDK_BACKEND environment variable to find out which of the supported GDK backends to use (in case GDK has been compiled with multiple backends).

Applications can use set_allowed_backends to limit what backends will be used.

Properties

default_display

default_display: Display  # read/write

The default display.

Signals

display-opened

def on_display_opened(self, display: Display) -> None: ...

Emitted when a display is opened.