Fix broken 'release-cursor' accel when not specified in --hotkeys

When the --hotkeys option is given, all hotkeys that are not explicitly
specified are disabled.  The method used to disable hotkeys is to change the
accel map entry to key=0, mods=0. However, when we decide whether to set a grab
sequence on the spice dispay widget, we simply use the return value for
gtk_accel_map_lookup_entry and assume that a TRUE value returned from this
function means that the hotkey is enabled.  In reality, this function will
return TRUE for disabled hotkeys, but the 'key' variable will be set to key=0,
mods=0. The result is that if I start virt-viewer like this:

    virt-viewer --hotkeys secure-attention=ctrl+alt+end ...

and the guest that I'm attached to uses server mouse mode, it will be impossible
to release the grab on the spice widget.  Because we will explicitly disable the
grab keys in the spice widget and handle the 'release-cursor' hotkey in
virt-viewer, but the hotkey is an empty accel key.

Instead of simply checking the return value of gtk_accel_map_lookup_entry, we
have to inspect the return value for 'key' and check whether any keys are
actually assigned.
This commit is contained in:
Jonathon Jongsma 2014-03-12 11:12:15 -05:00
parent 02fb004a8e
commit fe167a6668
2 changed files with 11 additions and 5 deletions

View File

@ -230,8 +230,11 @@ enable_accel_changed(VirtViewerApp *app,
GParamSpec *pspec G_GNUC_UNUSED,
VirtViewerDisplaySpice *self)
{
if (virt_viewer_app_get_enable_accel(app)
&& gtk_accel_map_lookup_entry("<virt-viewer>/view/release-cursor", NULL)) {
GtkAccelKey key = { 0 };
if (virt_viewer_app_get_enable_accel(app))
gtk_accel_map_lookup_entry("<virt-viewer>/view/release-cursor", &key);
if (key.accel_key || key.accel_mods) {
SpiceGrabSequence *seq = spice_grab_sequence_new(0, NULL);
/* disable default grab sequence */
spice_display_set_grab_keys(self->priv->display, seq);

View File

@ -1135,10 +1135,13 @@ virt_viewer_window_update_title(VirtViewerWindow *self)
if (priv->grabbed) {
gchar *label;
GtkAccelKey key;
GtkAccelKey key = { 0 };
if (virt_viewer_app_get_enable_accel(priv->app)
&& gtk_accel_map_lookup_entry("<virt-viewer>/view/release-cursor", &key)) {
if (virt_viewer_app_get_enable_accel(priv->app))
gtk_accel_map_lookup_entry("<virt-viewer>/view/release-cursor", &key);
if (key.accel_key || key.accel_mods) {
DEBUG_LOG("release-cursor accel key: key=%u, mods=%x, flags=%u", key.accel_key, key.accel_mods, key.accel_flags);
label = gtk_accelerator_get_label(key.accel_key, key.accel_mods);
} else {
label = g_strdup(_("Ctrl+Alt"));