From edb6ac714c6040ccd9a2f729ba636b63e2f35e9e Mon Sep 17 00:00:00 2001
From: Jonathon Jongsma <jjongsma@redhat.com>
Date: Wed, 12 Mar 2014 11:12:15 -0500
Subject: [PATCH] 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.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1029108
(cherry picked from commit fe167a6668a131c6182f749c826e52046607cb6f)
---
src/virt-viewer-display-spice.c | 7 +++++--
src/virt-viewer-window.c | 9 ++++++---
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
index 0450b5b..2ce42cf 100644
--- a/src/virt-viewer-display-spice.c
+++ b/src/virt-viewer-display-spice.c
@@ -234,8 +234,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);
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 1ad896c..6f6f9a4 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -1141,10 +1141,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"));