[Spice-devel] [spice-gtk PATCH v4] Grab keyboard based on session focus
Snir Sheriber
ssheribe at redhat.com
Sun Dec 13 00:40:40 PST 2015
When using multiple monitors moving mouse between monitors releases
keyboard grab.
Reproduce bug
-Open multiple monitors remote-viewer session
-Click on one of the monitors to get focus & keyboard-grab
-Move mouse to another monitor and try any keyboard command (do not click)
At this point all keyboard commands are being executed on the client machine
instead of the remote machine
I added keyboard_have_focus and mouse_have_pointer variables at the session
and
now these properties are being tested for the session instead for the current
widget (works also when using alt-tab).
Resolves: rhbz#1275231
---
No GObject properties were set
---
src/spice-gtk-session-priv.h | 4 ++++
src/spice-gtk-session.c | 36 ++++++++++++++++++++++++++++++++++++
src/spice-widget.c | 7 +++++--
3 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/src/spice-gtk-session-priv.h b/src/spice-gtk-session-priv.h
index 91304b2..bd737d8 100644
--- a/src/spice-gtk-session-priv.h
+++ b/src/spice-gtk-session-priv.h
@@ -28,6 +28,10 @@ gboolean spice_gtk_session_get_read_only(SpiceGtkSession *self);
void spice_gtk_session_sync_keyboard_modifiers(SpiceGtkSession *self);
void spice_gtk_session_set_pointer_grabbed(SpiceGtkSession *self, gboolean grabbed);
gboolean spice_gtk_session_get_pointer_grabbed(SpiceGtkSession *self);
+void spice_gtk_session_set_keyboard_have_focus(SpiceGtkSession *self, gboolean grabbed);
+void spice_gtk_session_set_mouse_have_pointer(SpiceGtkSession *self, gboolean grabbed);
+gboolean spice_gtk_session_get_keyboard_have_focus(SpiceGtkSession *self);
+gboolean spice_gtk_session_get_mouse_have_pointer(SpiceGtkSession *self);
G_END_DECLS
diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index 5abb16c..0218bdc 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -64,6 +64,8 @@ struct _SpiceGtkSessionPrivate {
gboolean auto_usbredir_enable;
int auto_usbredir_reqs;
gboolean pointer_grabbed;
+ gboolean keyboard_have_focus;
+ gboolean mouse_have_pointer;
};
/**
@@ -1227,3 +1229,37 @@ gboolean spice_gtk_session_get_pointer_grabbed(SpiceGtkSession *self)
return self->priv->pointer_grabbed;
}
+
+G_GNUC_INTERNAL
+void spice_gtk_session_set_keyboard_have_focus(SpiceGtkSession *self,
+gboolean grabbed)
+{
+ g_return_if_fail(SPICE_IS_GTK_SESSION(self));
+
+ self->priv->keyboard_have_focus = grabbed;
+}
+
+G_GNUC_INTERNAL
+void spice_gtk_session_set_mouse_have_pointer(SpiceGtkSession *self, gboolean
+grabbed)
+ {
+ g_return_if_fail(SPICE_IS_GTK_SESSION(self));
+
+ self->priv->mouse_have_pointer = grabbed;
+ }
+
+ G_GNUC_INTERNAL
+gboolean spice_gtk_session_get_keyboard_have_focus(SpiceGtkSession *self)
+{
+ g_return_val_if_fail(SPICE_IS_GTK_SESSION(self), FALSE);
+
+ return self->priv->keyboard_have_focus;
+}
+
+G_GNUC_INTERNAL
+gboolean spice_gtk_session_get_mouse_have_pointer(SpiceGtkSession *self)
+{
+ g_return_val_if_fail(SPICE_IS_GTK_SESSION(self), FALSE);
+
+ return self->priv->mouse_have_pointer;
+}
diff --git a/src/spice-widget.c b/src/spice-widget.c
index 503f82a..ffb2c00 100644
--- a/src/spice-widget.c
+++ b/src/spice-widget.c
@@ -208,6 +208,7 @@ static void update_keyboard_focus(SpiceDisplay *display, gboolean state)
SpiceDisplayPrivate *d = display->priv;
d->keyboard_have_focus = state;
+ spice_gtk_session_set_keyboard_have_focus(d->gtk_session, state);
/* keyboard grab gets inhibited by usb-device-manager when it is
in the process of redirecting a usb-device (as this may show a
@@ -737,9 +738,9 @@ static void try_keyboard_grab(SpiceDisplay *display)
return;
if (d->keyboard_grab_active)
return;
- if (!d->keyboard_have_focus)
+ if (!spice_gtk_session_get_keyboard_have_focus(d->gtk_session))
return;
- if (!d->mouse_have_pointer)
+ if (!spice_gtk_session_get_mouse_have_pointer(d->gtk_session))
return;
if (d->keyboard_grab_released)
return;
@@ -1465,6 +1466,7 @@ static gboolean enter_event(GtkWidget *widget, GdkEventCrossing *crossing G_GNUC
SPICE_DEBUG("%s", __FUNCTION__);
d->mouse_have_pointer = true;
+ spice_gtk_session_set_mouse_have_pointer(d->gtk_session, true);
try_keyboard_grab(display);
update_display(display);
@@ -1482,6 +1484,7 @@ static gboolean leave_event(GtkWidget *widget, GdkEventCrossing *crossing G_GNUC
return true;
d->mouse_have_pointer = false;
+ spice_gtk_session_set_mouse_have_pointer(d->gtk_session, false);
try_keyboard_ungrab(display);
return true;
--
2.4.3
More information about the Spice-devel
mailing list