Q:

How to instantiate GdkDeviceManager?

I'm trying to figure out how to use GdkDeviceManager, so I wrote the following program that is supposed to print all physical input devices:
#include <stdio.h>
#include <gdk/gdk.h>

int main(int argc, char **argv) {
    GList *devices, *it;
    GdkDeviceManager mgr;

    devices = gdk_device_manager_list_devices(&mgr, GDK_DEVICE_TYPE_SLAVE);

    for (it = devices; it != NULL; it = it->next) {
        GdkDevice *dev = it->data;
        printf("Current device: %s\n", gdk_device_get_name(dev));
    }

    g_list_free(devices);
    return 0;
}

However when I try to compile it via
gcc mousetest.c $(pkg-config --libs --cflags gtk+-3.0 gdk-3.0) -Wall

I get
mousetest.c: In function ‘main’:
mousetest.c:6:22: error: storage size of ‘mgr’ isn’t known
     GdkDeviceManager mgr;
                      ^
mousetest.c:6:22: warning: unused variable ‘mgr’ [-Wunused-variable]

A:

Aparently GdkDeviceManager can't be instantiated, you need to get a pointer from it via the display. To get the display, you need to initialize Gtk+.
Working code below,
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>

int main(int argc, char **argv) {

    gtk_init(&argc, &argv);

    GList *devices, *it;
    GdkDisplay *display = gdk_display_get_default();
    GdkDeviceManager *mgr = gdk_display_get_device_manager(display);

    devices = gdk_device_manager_list_devices(mgr, GDK_DEVICE_TYPE_SLAVE);

    for (it = devices; it != NULL; it = it->next) {
        GdkDevice *dev = it->data;
        printf("Current device: %s\n", gdk_device_get_name(dev));
    }

    g_list_free(devices);
    return 0;
}

