## Wayland Interaction

Wayland Interaction — Wayland backend-specific functions

## Synopsis

    #include <gdk/gdkwayland.h>

    struct wl_keyboard * gdk_wayland_device_get_wl_keyboard (GdkDevice *device);
    struct wl_pointer * gdk_wayland_device_get_wl_pointer   (GdkDevice *device);
    struct wl_seat *    gdk_wayland_device_get_wl_seat      (GdkDevice *device);
    struct wl_compositor * gdk_wayland_display_get_wl_compositor
                                                            (GdkDisplay *display);
    struct wl_display * gdk_wayland_display_get_wl_display  (GdkDisplay *display);
    struct wl_shell *   gdk_wayland_display_get_wl_shell    (GdkDisplay *display);
    struct wl_shell_surface * gdk_wayland_window_get_wl_shell_surface
                                                            (GdkWindow *window);
    struct wl_surface * gdk_wayland_window_get_wl_surface   (GdkWindow *window);
    void                gdk_wayland_window_set_use_custom_surface
                                                            (GdkWindow *window);

## Description

The functions in this section are specific to the GDK Wayland backend. To use them, you need to include the `<gdk/gdkwayland.h>` header and use the Wayland-specific pkg-config files to build your application (either `gdk-wayland-3.0` or `gtk+-wayland-3.0`).

To make your code compile with other GDK backends, guard backend-specific calls by an ifdef as follows. Since GDK may be built with multiple backends, you should also check for the backend that is in use (e.g. by using the `GDK_IS_WAYLAND_DISPLAY()` macro).

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    #ifdef GDK_WINDOWING_WAYLAND
      if (GDK_IS_WAYLAND_DISPLAY (display))
        {
          /* make Wayland-specific calls here */
        }
      else
    #endif
    #ifdef GDK_WINDOWING_X11
      if (GDK_IS_X11_DISPLAY (display))
        {
          /* make X11-specific calls here */
        }
      else
    #endif
      g_error ("Unsupported GDK backend");

## Details

### gdk_wayland_device_get_wl_keyboard ()

    struct wl_keyboard * gdk_wayland_device_get_wl_keyboard (GdkDevice *device);

Returns the Wayland wl_keyboard of a GdkDevice

`device` : | a GdkDevice. [type GdkWaylandDevice]
Returns : | a Wayland wl_keyboard. [transfer none]

Since 3.10

### gdk_wayland_device_get_wl_pointer ()

    struct wl_pointer * gdk_wayland_device_get_wl_pointer   (GdkDevice *device);

Returns the Wayland wl_pointer of a GdkDevice

`device` : | a GdkDevice. [type GdkWaylandDevice]
Returns : | a Wayland wl_pointer. [transfer none]

Since 3.10

### gdk_wayland_device_get_wl_seat ()

    struct wl_seat *    gdk_wayland_device_get_wl_seat      (GdkDevice *device);

Returns the Wayland wl_seat of a GdkDevice

`device` : | a GdkDevice. [type GdkWaylandDevice]
Returns : | a Wayland wl_seat. [transfer none]

Since 3.10

### gdk_wayland_display_get_wl_compositor ()

    struct wl_compositor * gdk_wayland_display_get_wl_compositor
                                                            (GdkDisplay *display);

Returns the Wayland global singleton compositor of a GdkDisplay

`display` : | a GdkDisplay. [type GdkWaylandDisplay]
Returns : | a Wayland wl_compositor. [transfer none]

Since 3.8

### gdk_wayland_display_get_wl_display ()

    struct wl_display * gdk_wayland_display_get_wl_display  (GdkDisplay *display);

Returns the Wayland wl_display of a GdkDisplay

`display` : | a GdkDisplay. [type GdkWaylandDisplay]
Returns : | a Wayland wl_display. [transfer none]

Since 3.8

### gdk_wayland_display_get_wl_shell ()

    struct wl_shell *   gdk_wayland_display_get_wl_shell    (GdkDisplay *display);

Returns the Wayland global singleton shell of a GdkDisplay

`display` : | a GdkDisplay. [type GdkWaylandDisplay]
Returns : | a Wayland wl_shell. [transfer none]

Since 3.8

### gdk_wayland_window_get_wl_shell_surface ()

    struct wl_shell_surface * gdk_wayland_window_get_wl_shell_surface
                                                            (GdkWindow *window);

Returns the Wayland shell surface of a GdkWindow

`window` : | a GdkWindow. [type GdkWaylandWindow]
Returns : | a Wayland wl_shell_surface. [transfer none]

Since 3.8

### gdk_wayland_window_get_wl_surface ()

    struct wl_surface * gdk_wayland_window_get_wl_surface   (GdkWindow *window);

Returns the Wayland surface of a GdkWindow

`window` : | a GdkWindow. [type GdkWaylandWindow]
Returns : | a Wayland wl_surface. [transfer none]

Since 3.8

### gdk_wayland_window_set_use_custom_surface ()

    void                gdk_wayland_window_set_use_custom_surface
                                                            (GdkWindow *window);

Marks a GdkWindow as a custom Wayland surface. The application is expected to register the surface as some type of surface using some Wayland interface.

A good example would be writing a panel or on-screen-keyboard as an out-of-process helper - as opposed to having those in the compositor process. In this case the underlying surface isn't a wl_shell surface and the panel or OSK client need to identify the wl_surface as a panel or OSK to the compositor. The assumption is that the compositor will expose a private interface to the special client that lets the client identify the wl_surface as a panel or such.

This function should be called before a GdkWindow is shown. This is best done by connecting to the "realized" signal:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    static void
    widget_realize_cb (GtkWidget *widget)
    {
      GdkWindow *window;
      struct wl_surface *surface;
      struct input_panel_surface *ip_surface;

      window = gtk_widget_get_window (widget);
      gdk_wayland_window_set_custom_surface (window);

      surface = gdk_wayland_window_get_wl_surface (window);
      ip_surface = input_panel_get_input_panel_surface (input_panel, surface);
      input_panel_surface_set_panel (ip_surface);
    }

    static void
    setup_window (GtkWindow *window)
    {
      g_signal_connect (window, "realize", G_CALLBACK (widget_realize_cb), NULL);
    }

`window` : | a GdkWindow. [type GdkWaylandWindow]

Since 3.10