1

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]
Iskren
  • 1,301
  • 10
  • 15
  • You don't: a device manager is created by the backend. But, more importantly: why do you think you need the device manager at all? – ebassi May 19 '16 at 16:59
  • I wanted to patch a program that uses it to manage input devices, but one of the devices was disappearing, so I wanted to write a program that simply lists devices via the GdkDeviceManager to see whether it's the device manager that's losing sight of it or not. – Iskren May 19 '16 at 20:26

1 Answers1

1

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;
}
Iskren
  • 1,301
  • 10
  • 15