Grab keyboard based on session focus.

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 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_has_focus and mouse_has_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

Acked-by: Pavel Grunt <pgrunt@redhat.com>
This commit is contained in:
snir sheriber 2015-12-20 12:00:29 +02:00 committed by Pavel Grunt
parent f1e504f02b
commit 143ebfdf27
3 changed files with 44 additions and 2 deletions

View File

@ -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_has_focus(SpiceGtkSession *self, gboolean keyboard_has_focus);
void spice_gtk_session_set_mouse_has_pointer(SpiceGtkSession *self, gboolean mouse_has_pointer);
gboolean spice_gtk_session_get_keyboard_has_focus(SpiceGtkSession *self);
gboolean spice_gtk_session_get_mouse_has_pointer(SpiceGtkSession *self);
G_END_DECLS

View File

@ -64,6 +64,8 @@ struct _SpiceGtkSessionPrivate {
gboolean auto_usbredir_enable;
int auto_usbredir_reqs;
gboolean pointer_grabbed;
gboolean keyboard_has_focus;
gboolean mouse_has_pointer;
};
/**
@ -1227,3 +1229,36 @@ gboolean spice_gtk_session_get_pointer_grabbed(SpiceGtkSession *self)
return self->priv->pointer_grabbed;
}
G_GNUC_INTERNAL
void spice_gtk_session_set_keyboard_has_focus(SpiceGtkSession *self,
gboolean keyboard_has_focus)
{
g_return_if_fail(SPICE_IS_GTK_SESSION(self));
self->priv->keyboard_has_focus = keyboard_has_focus;
}
G_GNUC_INTERNAL
void spice_gtk_session_set_mouse_has_pointer(SpiceGtkSession *self,
gboolean mouse_has_pointer)
{
g_return_if_fail(SPICE_IS_GTK_SESSION(self));
self->priv->mouse_has_pointer = mouse_has_pointer;
}
G_GNUC_INTERNAL
gboolean spice_gtk_session_get_keyboard_has_focus(SpiceGtkSession *self)
{
g_return_val_if_fail(SPICE_IS_GTK_SESSION(self), FALSE);
return self->priv->keyboard_has_focus;
}
G_GNUC_INTERNAL
gboolean spice_gtk_session_get_mouse_has_pointer(SpiceGtkSession *self)
{
g_return_val_if_fail(SPICE_IS_GTK_SESSION(self), FALSE);
return self->priv->mouse_has_pointer;
}

View File

@ -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_has_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_has_focus(d->gtk_session))
return;
if (!d->mouse_have_pointer)
if (!spice_gtk_session_get_mouse_has_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_has_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_has_pointer(d->gtk_session, false);
try_keyboard_ungrab(display);
return true;