aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-04-02 15:07:30 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-04-02 15:07:30 +0100
commitad7d31ead8ff9c34bb63172754d3e7d15d803bde (patch)
tree0d8b179d1d97c74223e117748420f49ef5ca9c38 /termkey.c
parent04683553896358b7c3115fa646f88762ee4a8212 (diff)
downloadtermo-ad7d31ead8ff9c34bb63172754d3e7d15d803bde.tar.gz
termo-ad7d31ead8ff9c34bb63172754d3e7d15d803bde.tar.xz
termo-ad7d31ead8ff9c34bb63172754d3e7d15d803bde.zip
Provide termkey_keycmp() for sorting purposes
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/termkey.c b/termkey.c
index 7995871..384b5a4 100644
--- a/termkey.c
+++ b/termkey.c
@@ -1144,3 +1144,29 @@ 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)
+{
+ if(key1->type != key2->type)
+ return key2->type - key1->type;
+
+ switch(key1->type) {
+ case TERMKEY_TYPE_UNICODE:
+ if(key1->code.codepoint != key2->code.codepoint)
+ return key2->code.codepoint - key1->code.codepoint;
+ case TERMKEY_TYPE_KEYSYM:
+ if(key1->code.sym != key2->code.sym)
+ return key2->code.sym - key1->code.sym;
+ case TERMKEY_TYPE_FUNCTION:
+ if(key1->code.number != key2->code.number)
+ return key2->code.number - key1->code.number;
+ case TERMKEY_TYPE_MOUSE:
+ {
+ int cmp = strncmp(key2->code.mouse, key1->code.mouse, 4);
+ if(cmp != 0)
+ return cmp;
+ }
+ }
+
+ return key2->modifiers - key1->modifiers;
+}