[virt-tools-list] [PATCH virt-viewer 3/4] Display correct key bindings to release cursor
Marc-André Lureau
marcandre.lureau at gmail.com
Sun Mar 18 18:59:16 UTC 2012
If the accels are enabled (with Spice controller custom bindings),
show the configured keybinding in the title bar.
---
src/virt-viewer-display-spice.c | 18 ++++++++++++++++++
src/virt-viewer-window.c | 19 ++++++++++++++++---
2 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
index a5aa075..981fb57 100644
--- a/src/virt-viewer-display-spice.c
+++ b/src/virt-viewer-display-spice.c
@@ -181,6 +181,19 @@ virt_viewer_display_spice_size_allocate(VirtViewerDisplaySpice *self,
0, 0, dw, dh);
}
+static void
+enable_accel_changed(VirtViewerApp *app,
+ GParamSpec *pspec G_GNUC_UNUSED,
+ VirtViewerDisplaySpice *self)
+{
+ if (virt_viewer_app_get_enable_accel(app)) {
+ /* disable default grab sequence */
+ spice_display_set_grab_keys(self->priv->display,
+ spice_grab_sequence_new(0, NULL));
+ } else {
+ spice_display_set_grab_keys(self->priv->display, NULL);
+ }
+}
GtkWidget *
virt_viewer_display_spice_new(VirtViewerSessionSpice *session,
@@ -188,6 +201,7 @@ virt_viewer_display_spice_new(VirtViewerSessionSpice *session,
SpiceDisplay *display)
{
VirtViewerDisplaySpice *self;
+ VirtViewerApp *app;
gint channelid;
g_return_val_if_fail(SPICE_IS_DISPLAY_CHANNEL(channel), NULL);
@@ -227,6 +241,10 @@ virt_viewer_display_spice_new(VirtViewerSessionSpice *session,
G_CALLBACK(virt_viewer_display_spice_size_allocate), self);
+ app = virt_viewer_session_get_app(VIRT_VIEWER_SESSION(session));
+ g_signal_connect(app, "notify::enable-accel", G_CALLBACK(enable_accel_changed), self);
+ enable_accel_changed(app, NULL, self);
+
return GTK_WIDGET(self);
}
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 62b6052..ec96532 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -943,10 +943,22 @@ virt_viewer_window_update_title(VirtViewerWindow *self)
{
VirtViewerWindowPrivate *priv = self->priv;
char *title;
- const char *ungrab = NULL;
+ gchar *ungrab = NULL;
- if (priv->grabbed)
- ungrab = _("(Press Ctrl+Alt to release pointer)");
+ if (priv->grabbed) {
+ gchar *label;
+
+ if (virt_viewer_app_get_enable_accel(priv->app)) {
+ GtkAccelKey key;
+ gtk_accel_map_lookup_entry("<virt-viewer>/view/release-cursor", &key);
+ label = gtk_accelerator_get_label(key.accel_key, key.accel_mods);
+ } else {
+ label = g_strdup(_("Ctrl+Alt"));
+ }
+
+ ungrab = g_strdup_printf(_("(Press %s to release pointer)"), label);
+ g_free(label);
+ }
if (!ungrab && !priv->subtitle)
title = g_strdup(g_get_application_name());
@@ -966,6 +978,7 @@ virt_viewer_window_update_title(VirtViewerWindow *self)
gtk_window_set_title(GTK_WINDOW(priv->window), title);
g_free(title);
+ g_free(ungrab);
}
void
--
1.7.7.6
More information about the virt-tools-list
mailing list