From 655199da197d2c3407d4bc937c9d3d3ac4551764 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 25 Feb 2013 15:20:36 +0000 Subject: [PATCH] Conditionalize use of gdk_keyboard_grab / gdk_keyboard_ungrab On GTK3 there is support for multiple keyboard devices, so rather than using gdk_keyboard_grab / gdk_keyboard_ungrab we should iterate over all devices, grabbing each one in turn Signed-off-by: Daniel P. Berrange Message-id: 1361805646-6425-4-git-send-email-berrange@redhat.com Signed-off-by: Anthony Liguori --- ui/gtk.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/ui/gtk.c b/ui/gtk.c index 8ccd95f0e8..3826bea97c 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -758,14 +758,53 @@ static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque) static void gd_grab_keyboard(GtkDisplayState *s) { - gdk_keyboard_grab(gtk_widget_get_window(GTK_WIDGET(s->drawing_area)), +#if GTK_CHECK_VERSION(3, 0, 0) + GdkDisplay *display = gtk_widget_get_display(s->drawing_area); + GdkDeviceManager *mgr = gdk_display_get_device_manager(display); + GList *devices = gdk_device_manager_list_devices(mgr, + GDK_DEVICE_TYPE_MASTER); + GList *tmp = devices; + while (tmp) { + GdkDevice *dev = tmp->data; + if (gdk_device_get_source(dev) == GDK_SOURCE_KEYBOARD) { + gdk_device_grab(dev, + gtk_widget_get_window(s->drawing_area), + GDK_OWNERSHIP_NONE, + FALSE, + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, + NULL, + GDK_CURRENT_TIME); + } + tmp = tmp->next; + } + g_list_free(devices); +#else + gdk_keyboard_grab(gtk_widget_get_window(s->drawing_area), FALSE, GDK_CURRENT_TIME); +#endif } static void gd_ungrab_keyboard(GtkDisplayState *s) { +#if GTK_CHECK_VERSION(3, 0, 0) + GdkDisplay *display = gtk_widget_get_display(s->drawing_area); + GdkDeviceManager *mgr = gdk_display_get_device_manager(display); + GList *devices = gdk_device_manager_list_devices(mgr, + GDK_DEVICE_TYPE_MASTER); + GList *tmp = devices; + while (tmp) { + GdkDevice *dev = tmp->data; + if (gdk_device_get_source(dev) == GDK_SOURCE_KEYBOARD) { + gdk_device_ungrab(dev, + GDK_CURRENT_TIME); + } + tmp = tmp->next; + } + g_list_free(devices); +#else gdk_keyboard_ungrab(GDK_CURRENT_TIME); +#endif } static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)