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 <berrange@redhat.com>
Message-id: 1361805646-6425-4-git-send-email-berrange@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Daniel P. Berrange 2013-02-25 15:20:36 +00:00 committed by Anthony Liguori
parent 66962f1437
commit 655199da19

View File

@ -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)