aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-04-07 23:31:43 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-04-07 23:31:43 +0100
commit03371bdd04e25960149946ff7e8b9d5e921b6dc3 (patch)
tree41a5e825b76b7bc21cbb84dc79bd8accec8d2301
parent0a101ff71eb1133889b5f1b28b7779832eddb013 (diff)
downloadtermo-03371bdd04e25960149946ff7e8b9d5e921b6dc3.tar.gz
termo-03371bdd04e25960149946ff7e8b9d5e921b6dc3.tar.xz
termo-03371bdd04e25960149946ff7e8b9d5e921b6dc3.zip
Bugfix to termkey_keycmp - implement sense in correct direction
-rw-r--r--t/13cmpkey.c16
-rw-r--r--termkey.c12
2 files changed, 14 insertions, 14 deletions
diff --git a/t/13cmpkey.c b/t/13cmpkey.c
index 75f5ad7..90ff9e1 100644
--- a/t/13cmpkey.c
+++ b/t/13cmpkey.c
@@ -24,25 +24,25 @@ int main(int argc, char *argv[])
key2.modifiers = TERMKEY_KEYMOD_CTRL;
- ok(termkey_keycmp(tk, &key1, &key2) > 0, "cmpkey orders CTRL after nomod");
- ok(termkey_keycmp(tk, &key2, &key1) < 0, "cmpkey orders nomod before CTRL");
+ ok(termkey_keycmp(tk, &key1, &key2) < 0, "cmpkey orders CTRL after nomod");
+ ok(termkey_keycmp(tk, &key2, &key1) > 0, "cmpkey orders nomod before CTRL");
key2.code.codepoint = 'B';
key2.modifiers = 0;
- ok(termkey_keycmp(tk, &key1, &key2) > 0, "cmpkey orders 'B' after 'A'");
- ok(termkey_keycmp(tk, &key2, &key1) < 0, "cmpkey orders 'A' before 'B'");
+ ok(termkey_keycmp(tk, &key1, &key2) < 0, "cmpkey orders 'B' after 'A'");
+ ok(termkey_keycmp(tk, &key2, &key1) > 0, "cmpkey orders 'A' before 'B'");
key1.modifiers = TERMKEY_KEYMOD_CTRL;
- ok(termkey_keycmp(tk, &key1, &key2) > 0, "cmpkey orders nomod 'B' after CTRL 'A'");
- ok(termkey_keycmp(tk, &key2, &key1) < 0, "cmpkey orders CTRL 'A' before nomod 'B'");
+ ok(termkey_keycmp(tk, &key1, &key2) < 0, "cmpkey orders nomod 'B' after CTRL 'A'");
+ ok(termkey_keycmp(tk, &key2, &key1) > 0, "cmpkey orders CTRL 'A' before nomod 'B'");
key2.type = TERMKEY_TYPE_KEYSYM;
key2.code.sym = TERMKEY_SYM_UP;
- ok(termkey_keycmp(tk, &key1, &key2) > 0, "cmpkey orders KEYSYM after UNICODE");
- ok(termkey_keycmp(tk, &key2, &key1) < 0, "cmpkey orders UNICODE before KEYSYM");
+ ok(termkey_keycmp(tk, &key1, &key2) < 0, "cmpkey orders KEYSYM after UNICODE");
+ ok(termkey_keycmp(tk, &key2, &key1) > 0, "cmpkey orders UNICODE before KEYSYM");
termkey_destroy(tk);
diff --git a/termkey.c b/termkey.c
index 83d784d..48ec164 100644
--- a/termkey.c
+++ b/termkey.c
@@ -1148,25 +1148,25 @@ char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyForm
int termkey_keycmp(TermKey *tk, const TermKeyKey *key1, const TermKeyKey *key2)
{
if(key1->type != key2->type)
- return key2->type - key1->type;
+ return key1->type - key2->type;
switch(key1->type) {
case TERMKEY_TYPE_UNICODE:
if(key1->code.codepoint != key2->code.codepoint)
- return key2->code.codepoint - key1->code.codepoint;
+ return key1->code.codepoint - key2->code.codepoint;
case TERMKEY_TYPE_KEYSYM:
if(key1->code.sym != key2->code.sym)
- return key2->code.sym - key1->code.sym;
+ return key1->code.sym - key2->code.sym;
case TERMKEY_TYPE_FUNCTION:
if(key1->code.number != key2->code.number)
- return key2->code.number - key1->code.number;
+ return key1->code.number - key2->code.number;
case TERMKEY_TYPE_MOUSE:
{
- int cmp = strncmp(key2->code.mouse, key1->code.mouse, 4);
+ int cmp = strncmp(key1->code.mouse, key2->code.mouse, 4);
if(cmp != 0)
return cmp;
}
}
- return key2->modifiers - key1->modifiers;
+ return key1->modifiers - key2->modifiers;
}