aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-11-09 21:58:30 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-11-09 21:58:30 +0000
commit20cc4b17019b1802b77b85892e1622a899ebdca8 (patch)
tree376bb67d1b099f8ac1f96e5bffab60e30dd05f45
parentfd2466c4ce667fb461361b1c7266eb6db5470cbf (diff)
downloadtermo-20cc4b17019b1802b77b85892e1622a899ebdca8.tar.gz
termo-20cc4b17019b1802b77b85892e1622a899ebdca8.tar.xz
termo-20cc4b17019b1802b77b85892e1622a899ebdca8.zip
When debugging, also print details of a key event when applicable
-rw-r--r--termkey.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/termkey.c b/termkey.c
index 182774c..0294e26 100644
--- a/termkey.c
+++ b/termkey.c
@@ -546,6 +546,28 @@ static void print_buffer(termkey_t *tk)
fprintf(stderr, "...");
}
+static void print_key(termkey_t *tk, termkey_key *key)
+{
+ switch(key->type) {
+ case TERMKEY_TYPE_UNICODE:
+ fprintf(stderr, "Unicode codepoint=U+%04lx utf8='%s'", key->code.codepoint, key->utf8);
+ break;
+ case TERMKEY_TYPE_FUNCTION:
+ fprintf(stderr, "Function F%d", key->code.number);
+ break;
+ case TERMKEY_TYPE_KEYSYM:
+ fprintf(stderr, "Keysym sym=%d(%s)", key->code.sym, termkey_get_keyname(tk, key->code.sym));
+ break;
+ }
+
+ int m = key->modifiers;
+ fprintf(stderr, " mod=%s%s%s+%02x",
+ (m & TERMKEY_KEYMOD_CTRL ? "C" : ""),
+ (m & TERMKEY_KEYMOD_ALT ? "A" : ""),
+ (m & TERMKEY_KEYMOD_SHIFT ? "S" : ""),
+ m & ~(TERMKEY_KEYMOD_CTRL|TERMKEY_KEYMOD_ALT|TERMKEY_KEYMOD_SHIFT));
+}
+
static const char *res2str(termkey_result res)
{
switch(res) {
@@ -584,6 +606,10 @@ termkey_result termkey_getkey(termkey_t *tk, termkey_key *key)
switch(ret) {
case TERMKEY_RES_KEY:
+#ifdef DEBUG
+ print_key(tk, key); fprintf(stderr, "\n");
+#endif
+ /* fallthrough */
case TERMKEY_RES_EOF:
return ret;
@@ -602,6 +628,9 @@ termkey_result termkey_getkey(termkey_t *tk, termkey_key *key)
#ifdef DEBUG
fprintf(stderr, "getkey_simple(force=0) yields %s\n", res2str(ret));
+ if(ret == TERMKEY_RES_KEY) {
+ print_key(tk, key); fprintf(stderr, "\n");
+ }
#endif
return ret;
@@ -626,6 +655,10 @@ termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key)
switch(ret) {
case TERMKEY_RES_KEY:
+#ifdef DEBUG
+ print_key(tk, key); fprintf(stderr, "\n");
+#endif
+ /* fallthrough */
case TERMKEY_RES_EOF:
return ret;
@@ -639,6 +672,9 @@ termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key)
#ifdef DEBUG
fprintf(stderr, "getkey_simple(force=1) yields %s\n", res2str(ret));
+ if(ret == TERMKEY_RES_KEY) {
+ print_key(tk, key); fprintf(stderr, "\n");
+ }
#endif
return ret;