diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-09-06 22:49:05 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-09-06 22:49:05 +0100 |
commit | 8f32ac525f34aa32cd6dab4d13d0cfe84bf30879 (patch) | |
tree | 5406e7ba3016691d03afa9bf6730b86478918a03 /termkey.c | |
parent | 3008ed29d195ecff454a160c153bcbb9d651cc68 (diff) | |
download | termo-8f32ac525f34aa32cd6dab4d13d0cfe84bf30879.tar.gz termo-8f32ac525f34aa32cd6dab4d13d0cfe84bf30879.tar.xz termo-8f32ac525f34aa32cd6dab4d13d0cfe84bf30879.zip |
Canonicalise (a local copy of) the key structures given to termkey_keycmp() before comparing them
Diffstat (limited to 'termkey.c')
-rw-r--r-- | termkey.c | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -1244,28 +1244,34 @@ char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyForm return (char *)str; } -int termkey_keycmp(TermKey *tk, const TermKeyKey *key1, const TermKeyKey *key2) +int termkey_keycmp(TermKey *tk, const TermKeyKey *key1p, const TermKeyKey *key2p) { - if(key1->type != key2->type) - return key1->type - key2->type; + /* Copy the key structs since we'll be modifying them */ + TermKeyKey key1 = *key1p, key2 = *key2p; - switch(key1->type) { + termkey_canonicalise(tk, &key1); + termkey_canonicalise(tk, &key2); + + if(key1.type != key2.type) + return key1.type - key2.type; + + switch(key1.type) { case TERMKEY_TYPE_UNICODE: - if(key1->code.codepoint != key2->code.codepoint) - return key1->code.codepoint - key2->code.codepoint; + if(key1.code.codepoint != key2.code.codepoint) + return key1.code.codepoint - key2.code.codepoint; case TERMKEY_TYPE_KEYSYM: - if(key1->code.sym != key2->code.sym) - return key1->code.sym - key2->code.sym; + if(key1.code.sym != key2.code.sym) + return key1.code.sym - key2.code.sym; case TERMKEY_TYPE_FUNCTION: - if(key1->code.number != key2->code.number) - return key1->code.number - key2->code.number; + if(key1.code.number != key2.code.number) + return key1.code.number - key2.code.number; case TERMKEY_TYPE_MOUSE: { - int cmp = strncmp(key1->code.mouse, key2->code.mouse, 4); + int cmp = strncmp(key1.code.mouse, key2.code.mouse, 4); if(cmp != 0) return cmp; } } - return key1->modifiers - key2->modifiers; + return key1.modifiers - key2.modifiers; } |