How do I use the GDK Wayland interop functions?

I’d like to use gdk_wayland_monitor_get_wl_output to get some extended information from the Wayland backend. However, the problem I’m having is that wl_output is an incomplete type, and I can’t find a definition of it anywhere. I’m just getting to grips with the Wayland architecture so I’m sure I must be misunderstanding something somewhere.

Code snippet:

#include <gtk/gtk.h>
#include <gdk/wayland/gdkwayland.h>

static void
activate (GtkApplication *app,
         gpointer        user_data)
    wl_output *output;
    GdkDisplayManager *display_manager;
    GdkDisplay *default_display;
    GListModel *monitors;
    GdkMonitor *monitor;

    display_manager = gdk_display_manager_get();
    default_display = gdk_display_manager_get_default_display(display_manager);
    monitors = gdk_display_get_monitors(default_display);
    monitor = (GdkMonitor *) g_list_model_get_item(monitors, 0);

    output = gdk_wayland_monitor_get_wl_output(monitor);
    printf(output->name); // fails because `wl_output` is incomplete

main (int    argc,
     char **argv)
    GtkApplication *app;
    int status;

    app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
    status = g_application_run (G_APPLICATION (app), argc, argv);
    g_object_unref (app);

    return status;
1 Like

The wl_output type is just a Wayland proxy object - it’s a reference to the object that can be used with Wayland API. By itself, it doesn’t have any information about outputs, instead events containing this information is sent and certain points in time to the owner of it. In this case, the owner is GDK.

To yourself get all the information that is sent to a wl_output object, you need to create your own, and listen for the associated events, using the regular Wayland API. To do this for a Wayland connection managed by GDK, first get the wl_display using gdk_wayland_display_get_wl_display(), get a new registry (wl_dispaly_get_registry()), add a registry listener, listen for all "wl_output" globals, bind them all, and then listen to the events sent to the bound output objects.

Thans @jadahl , that’s really helpful.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.