You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/01/30 19:08:31 UTC

[03/11] guacamole-server git commit: GUACAMOLE-313: Separate naming logic for keysyms. Align previously-pressed keys.

GUACAMOLE-313: Separate naming logic for keysyms. Align previously-pressed keys.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-server/commit/df29735c
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-server/tree/df29735c
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-server/diff/df29735c

Branch: refs/heads/master
Commit: df29735c83c210900ba55d60c1e1a29b3c3ef03e
Parents: d39757b
Author: Michael Jumper <mj...@apache.org>
Authored: Sun Nov 26 18:00:29 2017 -0800
Committer: Michael Jumper <mj...@apache.org>
Committed: Fri Jan 26 16:24:43 2018 -0800

----------------------------------------------------------------------
 src/guaclog/Makefile.am |  2 ++
 src/guaclog/key-name.c  | 43 +++++++++++++++++++++++++++++++++++++
 src/guaclog/key-name.h  | 50 ++++++++++++++++++++++++++++++++++++++++++++
 src/guaclog/state.c     | 22 +++++++++++++++----
 4 files changed, 113 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/df29735c/src/guaclog/Makefile.am
----------------------------------------------------------------------
diff --git a/src/guaclog/Makefile.am b/src/guaclog/Makefile.am
index f1ad152..5007708 100644
--- a/src/guaclog/Makefile.am
+++ b/src/guaclog/Makefile.am
@@ -28,6 +28,7 @@ noinst_HEADERS =   \
     guaclog.h      \
     instructions.h \
     interpret.h    \
+    key-name.h     \
     log.h          \
     state.h
 
@@ -36,6 +37,7 @@ guaclog_SOURCES =     \
     instructions.c    \
     instruction-key.c \
     interpret.c       \
+    key-name.c        \
     log.c             \
     state.c
 

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/df29735c/src/guaclog/key-name.c
----------------------------------------------------------------------
diff --git a/src/guaclog/key-name.c b/src/guaclog/key-name.c
new file mode 100644
index 0000000..ffb622d
--- /dev/null
+++ b/src/guaclog/key-name.c
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "config.h"
+#include "key-name.h"
+#include "log.h"
+
+#include <stdio.h>
+
+int guaclog_key_name(char* key_name, int keysym) {
+
+    /* Fallback to using hex keysym as name */
+    int name_length = snprintf(key_name, GUACLOG_MAX_KEY_NAME_LENGTH,
+            "0x%X", keysym);
+
+    /* Truncate name if necessary */
+    if (name_length >= GUACLOG_MAX_KEY_NAME_LENGTH) {
+        name_length = GUACLOG_MAX_KEY_NAME_LENGTH - 1;
+        key_name[name_length] = '\0';
+        guaclog_log(GUAC_LOG_DEBUG, "Name for key 0x%X was "
+                "truncated.", keysym);
+    }
+
+    return name_length;
+
+}
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/df29735c/src/guaclog/key-name.h
----------------------------------------------------------------------
diff --git a/src/guaclog/key-name.h b/src/guaclog/key-name.h
new file mode 100644
index 0000000..a033b36
--- /dev/null
+++ b/src/guaclog/key-name.h
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef GUACLOG_KEY_NAME_H
+#define GUACLOG_KEY_NAME_H
+
+#include "config.h"
+
+/**
+ * The maximum size of the name of any key, in bytes.
+ */
+#define GUACLOG_MAX_KEY_NAME_LENGTH 64
+
+/**
+ * Copies the name of the key having the given keysym into the given buffer,
+ * which must be at least GUACLOG_MAX_KEY_NAME_LENGTH bytes long. This function
+ * always succeeds, ultimately resorting to using the hex value of the keysym
+ * as the name if no other human-readable name is known.
+ *
+ * @param key_name
+ *     The buffer to copy the key name into, which must be at least
+ *     GUACLOG_MAX_KEY_NAME_LENGTH.
+ *
+ * @param keysym
+ *     The X11 keysym of the key whose name should be stored in
+ *     key_name.
+ *
+ * @return
+ *     The length of the name, in bytes, excluding null terminator.
+ */
+int guaclog_key_name(char* key_name, int keysym);
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/guacamole-server/blob/df29735c/src/guaclog/state.c
----------------------------------------------------------------------
diff --git a/src/guaclog/state.c b/src/guaclog/state.c
index cc6f763..616d043 100644
--- a/src/guaclog/state.c
+++ b/src/guaclog/state.c
@@ -18,6 +18,7 @@
  */
 
 #include "config.h"
+#include "key-name.h"
 #include "log.h"
 #include "state.h"
 
@@ -174,15 +175,28 @@ int guaclog_state_update_key(guaclog_state* state, int keysym, bool pressed) {
     /* Output new log entries only when keys are pressed */
     if (pressed) {   
 
-        /* STUB: Output raw hex log entry */
+        /* Compose log entry by inspecting the state of each tracked key */
         for (i = 0; i < state->active_keys; i++) {
 
+            guaclog_key_state* key = &state->key_states[i];
+
+            /* Translate keysym into human-readable name */
+            char key_name[GUACLOG_MAX_KEY_NAME_LENGTH];
+            int name_length = guaclog_key_name(key_name, key->keysym);
+
+            /* If not the final key, omit the name (it was printed earlier) */
+            if (i < state->active_keys - 1) {
+                memset(key_name, ' ', name_length);
+                if (key->pressed)
+                    key_name[name_length / 2] = '*';
+            }
+
+            /* Separate each key by a single space */
             if (i != 0)
                 fprintf(state->output, " ");
 
-            guaclog_key_state* key = &state->key_states[i];
-            fprintf(state->output, "0x%X:%s", key->keysym,
-                    key->pressed ? "*" : " ");
+            /* Print name of key */
+            fprintf(state->output, "%s", key_name);
 
         }