[Spice-devel] [PATCH spice-gtk 3/3] Check for the disable inputs sequence

Pavel Grunt pgrunt at redhat.com
Fri Nov 7 06:28:54 PST 2014


Change a value of the disable-inputs property when the sequence is pressed.
---
 gtk/spice-widget-priv.h |  2 ++
 gtk/spice-widget.c      | 66 +++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 55 insertions(+), 13 deletions(-)

diff --git a/gtk/spice-widget-priv.h b/gtk/spice-widget-priv.h
index 9c38e2e..2ecc910 100644
--- a/gtk/spice-widget-priv.h
+++ b/gtk/spice-widget-priv.h
@@ -109,6 +109,8 @@ struct _SpiceDisplayPrivate {
     guint                   key_delayed_id;
     SpiceGrabSequence         *grabseq; /* the configured key sequence */
     gboolean                *activeseq; /* the currently pressed keys */
+    SpiceGrabSequence       *inputs_seq; /* the configured keys for disable inputs sequence */
+    gboolean                *active_inputs_seq;
     gint                    mark;
 #ifdef WIN32
     HHOOK                   keyboard_hook;
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index ae11073..2e45657 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -431,6 +431,13 @@ static void spice_display_finalize(GObject *obj)
     g_free(d->activeseq);
     d->activeseq = NULL;
 
+    if (d->inputs_seq) {
+        spice_grab_sequence_free(d->inputs_seq);
+        d->inputs_seq = NULL;
+    }
+    g_free(d->active_inputs_seq);
+    d->active_inputs_seq = NULL;
+
     if (d->show_cursor) {
         gdk_cursor_unref(d->show_cursor);
         d->show_cursor = NULL;
@@ -525,6 +532,22 @@ static void grab_notify(SpiceDisplay *display, gboolean was_grabbed)
         release_keys(display);
 }
 
+static void set_disable_inputs_sequence(SpiceDisplay *display)
+{
+    SpiceDisplayPrivate *d = display->priv;
+
+    gchar *sequence;
+
+    g_object_get(d->session, "disable-inputs-sequence", &sequence, NULL);
+    if (sequence != NULL) {
+        d->inputs_seq = spice_grab_sequence_new_from_string(sequence);
+        d->active_inputs_seq = g_new0(gboolean, d->inputs_seq->nkeysyms);
+    }
+
+    g_free(sequence);
+
+}
+
 static void spice_display_init(SpiceDisplay *display)
 {
     GtkWidget *widget = GTK_WIDGET(display);
@@ -612,6 +635,8 @@ spice_display_constructor(GType                  gtype,
                                   G_CALLBACK(session_inhibit_keyboard_grab_changed),
                                   display, 0);
 
+    set_disable_inputs_sequence(display);
+
     return obj;
 }
 
@@ -1259,31 +1284,30 @@ static void release_keys(SpiceDisplay *display)
     }
 }
 
-static gboolean check_for_grab_key(SpiceDisplay *display, int type, int keyval)
+static gboolean check_for_sequence(SpiceGrabSequence *sequence, gboolean *activeseq,
+                                   int type, int keyval)
 {
-    SpiceDisplayPrivate *d = display->priv;
     int i;
-
-    if (!d->grabseq->nkeysyms)
+    if (!sequence || !sequence->nkeysyms)
         return FALSE;
 
     if (type == GDK_KEY_PRESS) {
         /* Record the new key press */
-        for (i = 0 ; i < d->grabseq->nkeysyms ; i++)
-            if (d->grabseq->keysyms[i] == keyval)
-                d->activeseq[i] = TRUE;
+        for (i = 0 ; i < sequence->nkeysyms ; i++)
+            if (sequence->keysyms[i] == keyval)
+                activeseq[i] = TRUE;
 
         /* Return if any key is not pressed */
-        for (i = 0 ; i < d->grabseq->nkeysyms ; i++)
-            if (d->activeseq[i] == FALSE)
+        for (i = 0 ; i < sequence->nkeysyms ; i++)
+            if (activeseq[i] == FALSE)
                 return FALSE;
 
-        /* resets the whole grab sequence on success */
-        memset(d->activeseq, 0, sizeof(gboolean) * d->grabseq->nkeysyms);
+        /* resets the whole sequence on success */
+        memset(activeseq, 0, sizeof(gboolean) * sequence->nkeysyms);
         return TRUE;
     } else if (type == GDK_KEY_RELEASE) {
-        /* Any key release resets the whole grab sequence */
-        memset(d->activeseq, 0, sizeof(gboolean) * d->grabseq->nkeysyms);
+        /* Any key release resets the whole sequence */
+        memset(activeseq, 0, sizeof(gboolean) * sequence->nkeysyms);
         return FALSE;
     } else
         g_warn_if_reached();
@@ -1291,6 +1315,18 @@ static gboolean check_for_grab_key(SpiceDisplay *display, int type, int keyval)
     return FALSE;
 }
 
+static gboolean check_for_grab_key(SpiceDisplay *display, int type, int keyval)
+{
+    SpiceDisplayPrivate *d = display->priv;
+    return check_for_sequence(d->grabseq, d->activeseq, type, keyval);
+}
+
+static gboolean check_for_disable_inputs_sequence(SpiceDisplay *display, int type, int keyval)
+{
+    SpiceDisplayPrivate *d = display->priv;
+    return check_for_sequence(d->inputs_seq, d->active_inputs_seq, type, keyval);
+}
+
 static void update_display(SpiceDisplay *display)
 {
 #ifdef G_OS_WIN32
@@ -1332,6 +1368,10 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key)
         }
     }
 
+    if (check_for_disable_inputs_sequence(display, key->type, key->keyval)) {
+        g_object_set(display, "disable-inputs", !d->disable_inputs, NULL);
+    }
+
     if (!d->inputs)
         return true;
 
-- 
1.9.3



More information about the Spice-devel mailing list