+ int ret;
+
+#if GTK_CHECK_VERSION(3,20,0)
+ /*
+ * Grabbing the keyboard in GTK 3.20 requires the new notion of
+ * GdkSeat.
+ */
+ GdkSeat *seat;
+
+ seat = gdk_display_get_default_seat
+ (gtk_widget_get_display(ctx->dialog));
+ if (!seat)
+ return FALSE;
+
+ ctx->seat = seat;
+ ret = gdk_seat_grab(seat, gtk_widget_get_window(ctx->dialog),
+ GDK_SEAT_CAPABILITY_KEYBOARD,
+ TRUE, NULL, NULL, NULL, NULL);
+#elif GTK_CHECK_VERSION(3,0,0)
+ /*
+ * And it has to be done differently again prior to GTK 3.20.
+ */
+ GdkDeviceManager *dm;
+ GdkDevice *pointer, *keyboard;
+
+ dm = gdk_display_get_device_manager
+ (gtk_widget_get_display(ctx->dialog));
+ if (!dm)
+ return FALSE;
+
+ pointer = gdk_device_manager_get_client_pointer(dm);
+ if (!pointer)
+ return FALSE;
+ keyboard = gdk_device_get_associated_device(pointer);
+ if (!keyboard)
+ return FALSE;
+ if (gdk_device_get_source(keyboard) != GDK_SOURCE_KEYBOARD)
+ return FALSE;
+
+ ctx->keyboard = keyboard;
+ ret = gdk_device_grab(ctx->keyboard,
+ gtk_widget_get_window(ctx->dialog),
+ GDK_OWNERSHIP_NONE,
+ TRUE,
+ GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
+ NULL,
+ GDK_CURRENT_TIME);
+#else
+ /*
+ * It's much simpler in GTK 1 and 2!
+ */
+ ret = gdk_keyboard_grab(gtk_widget_get_window(ctx->dialog),
+ FALSE, GDK_CURRENT_TIME);
+#endif
+