qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 1/6] gtk: check for existing grabs in gd_grab_{pointer, keyboard}
Date: Wed,  9 Sep 2015 11:28:53 +0200	[thread overview]
Message-ID: <1441790938-29042-2-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1441790938-29042-1-git-send-email-kraxel@redhat.com>

If a grab is already active for our window, do nothing.
If a grab is already active for another window, release it.

Cleanup some checks and ungrab calls in the code which are
not needed any more.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/gtk.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index df2a79e..24a1edb 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -167,6 +167,8 @@ struct GtkDisplayState {
 
 static void gd_grab_pointer(VirtualConsole *vc);
 static void gd_ungrab_pointer(GtkDisplayState *s);
+static void gd_grab_keyboard(VirtualConsole *vc);
+static void gd_ungrab_keyboard(GtkDisplayState *s);
 
 /** Utility Functions **/
 
@@ -849,7 +851,6 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
     /* implicitly grab the input at the first click in the relative mode */
     if (button->button == 1 && button->type == GDK_BUTTON_PRESS &&
         !qemu_input_is_absolute() && s->ptr_owner != vc) {
-        gd_ungrab_pointer(s);
         if (!vc->window) {
             gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(s->grab_item),
                                            TRUE);
@@ -1259,6 +1260,14 @@ static void gd_grab_devices(VirtualConsole *vc, bool grab,
 
 static void gd_grab_keyboard(VirtualConsole *vc)
 {
+    if (vc->s->kbd_owner) {
+        if (vc->s->kbd_owner == vc) {
+            return;
+        } else {
+            gd_ungrab_keyboard(vc->s);
+        }
+    }
+
 #if GTK_CHECK_VERSION(3, 0, 0)
     gd_grab_devices(vc, true, GDK_SOURCE_KEYBOARD,
                    GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
@@ -1292,6 +1301,15 @@ static void gd_ungrab_keyboard(GtkDisplayState *s)
 static void gd_grab_pointer(VirtualConsole *vc)
 {
     GdkDisplay *display = gtk_widget_get_display(vc->gfx.drawing_area);
+
+    if (vc->s->ptr_owner) {
+        if (vc->s->ptr_owner == vc) {
+            return;
+        } else {
+            gd_ungrab_pointer(vc->s);
+        }
+    }
+
 #if GTK_CHECK_VERSION(3, 0, 0)
     GdkDeviceManager *mgr = gdk_display_get_device_manager(display);
     gd_grab_devices(vc, true, GDK_SOURCE_MOUSE,
@@ -1352,9 +1370,7 @@ static void gd_menu_grab_input(GtkMenuItem *item, void *opaque)
     VirtualConsole *vc = gd_vc_find_current(s);
 
     if (gd_is_grab_active(s)) {
-        if (!gd_grab_on_hover(s)) {
-            gd_grab_keyboard(vc);
-        }
+        gd_grab_keyboard(vc);
         gd_grab_pointer(vc);
     } else {
         gd_ungrab_keyboard(s);
@@ -1415,7 +1431,6 @@ static gboolean gd_enter_event(GtkWidget *widget, GdkEventCrossing *crossing,
     GtkDisplayState *s = vc->s;
 
     if (gd_grab_on_hover(s)) {
-        gd_ungrab_keyboard(s);
         gd_grab_keyboard(vc);
         gd_update_caption(s);
     }
-- 
1.8.3.1

  reply	other threads:[~2015-09-09  9:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-09  9:28 [Qemu-devel] [PATCH 0/6] gtk: tweak grab handling, misc fixes Gerd Hoffmann
2015-09-09  9:28 ` Gerd Hoffmann [this message]
2015-09-09 14:46   ` [Qemu-devel] [PATCH 1/6] gtk: check for existing grabs in gd_grab_{pointer, keyboard} Marc-André Lureau
2015-09-09  9:28 ` [Qemu-devel] [PATCH 2/6] gtk: move gd_update_caption calls to gd_{grab, ungrab}_{pointer, keyboard} Gerd Hoffmann
2015-09-09 14:47   ` Marc-André Lureau
2015-09-09  9:28 ` [Qemu-devel] [PATCH 3/6] gtk: trace input grab reason Gerd Hoffmann
2015-09-09 14:53   ` Marc-André Lureau
2015-09-09  9:28 ` [Qemu-devel] [PATCH 4/6] gtk: set free_scale when setting zoom_fit Gerd Hoffmann
2015-09-09 14:57   ` Marc-André Lureau
2015-09-09  9:28 ` [Qemu-devel] [PATCH 5/6] gtk: don't grab input when entering fullscreen Gerd Hoffmann
2015-09-09 15:01   ` Marc-André Lureau
2015-09-09  9:28 ` [Qemu-devel] [PATCH 6/6] gtk: setlocale for LC_MESSAGES only Gerd Hoffmann
2015-09-09  9:48   ` Paolo Bonzini
2015-09-09 15:14     ` Marc-André Lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441790938-29042-2-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).