aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2014-05-06 11:01:31 +0200
committerGerd Hoffmann <kraxel@redhat.com>2014-05-26 08:41:03 +0200
commit4c638e2e4ba03cc9c1bca4400f4c68870208afe3 (patch)
tree34d0bfb1a67023e34033cdc68cb0c37f5fd035be /ui
parent1c856da57b29e41c73701f6f798589d50274b368 (diff)
gtk: keep track of grab owner
Simplifies grab state tracking and makes ungrab more reliable. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/ui/gtk.c b/ui/gtk.c
index 0e35abfea3..d87bd1bfeb 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -185,6 +185,8 @@ struct GtkDisplayState {
int last_y;
int grab_x_root;
int grab_y_root;
+ VirtualConsole *kbd_owner;
+ VirtualConsole *ptr_owner;
gboolean full_screen;
@@ -1058,11 +1060,19 @@ static void gd_grab_keyboard(VirtualConsole *vc)
FALSE,
GDK_CURRENT_TIME);
#endif
+ vc->s->kbd_owner = vc;
trace_gd_grab(vc->label, "kbd", true);
}
-static void gd_ungrab_keyboard(VirtualConsole *vc)
+static void gd_ungrab_keyboard(GtkDisplayState *s)
{
+ VirtualConsole *vc = s->kbd_owner;
+
+ if (vc == NULL) {
+ return;
+ }
+ s->kbd_owner = NULL;
+
#if GTK_CHECK_VERSION(3, 0, 0)
GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
@@ -1127,11 +1137,19 @@ static void gd_grab_pointer(VirtualConsole *vc)
gdk_display_get_pointer(display, NULL,
&vc->s->grab_x_root, &vc->s->grab_y_root, NULL);
#endif
+ vc->s->ptr_owner = vc;
trace_gd_grab(vc->label, "ptr", true);
}
-static void gd_ungrab_pointer(VirtualConsole *vc)
+static void gd_ungrab_pointer(GtkDisplayState *s)
{
+ VirtualConsole *vc = s->ptr_owner;
+
+ if (vc == NULL) {
+ return;
+ }
+ s->ptr_owner = NULL;
+
GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
#if GTK_CHECK_VERSION(3, 0, 0)
GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
@@ -1168,8 +1186,8 @@ static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
gd_grab_keyboard(vc);
gd_grab_pointer(vc);
} else {
- gd_ungrab_keyboard(vc);
- gd_ungrab_pointer(vc);
+ gd_ungrab_keyboard(s);
+ gd_ungrab_pointer(s);
}
gd_update_caption(s);
@@ -1227,7 +1245,7 @@ static gboolean gd_leave_event(GtkWidget *widget, GdkEventCrossing *crossing,
GtkDisplayState *s = vc->s;
if (!gd_is_grab_active(s) && gd_grab_on_hover(s)) {
- gd_ungrab_keyboard(vc);
+ gd_ungrab_keyboard(s);
}
return TRUE;