From f33513282a2fb5e55101ef1e0c8d4387d351e42d Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Tue, 24 Apr 2012 15:25:17 +0100 Subject: Created abstract accessors for getting/setting key event line/col counts --- driver-csi.c | 24 ++---------------------- termkey-internal.h | 22 ++++++++++++++++++++++ termkey.c | 6 +----- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/driver-csi.c b/driver-csi.c index 09c7dd7..25932a2 100644 --- a/driver-csi.c +++ b/driver-csi.c @@ -288,17 +288,7 @@ static TermKeyResult peekkey_csi(TermKey *tk, TermKeyCsi *csi, size_t introlen, key->modifiers = (key->code.mouse[0] & 0x1c) >> 2; key->code.mouse[0] &= ~0x1c; - key->code.mouse[3] = 0; - - if(arg[1] > 0xfff) - arg[1] = 0xfff; - key->code.mouse[1] = (arg[1] & 0x0ff); - key->code.mouse[3] |= (arg[1] & 0xf00) >> 8; - - if(arg[2] > 0x7ff) - arg[1] = 0x7ff; - key->code.mouse[2] = (arg[2] & 0x0ff); - key->code.mouse[3] |= (arg[2] & 0x300) >> 4; + termkey_key_set_linecol(key, arg[1], arg[2]); *nbytep = csi_len; return TERMKEY_RES_KEY; @@ -310,17 +300,7 @@ static TermKeyResult peekkey_csi(TermKey *tk, TermKeyCsi *csi, size_t introlen, key->modifiers = (key->code.mouse[0] & 0x1c) >> 2; key->code.mouse[0] &= ~0x1c; - key->code.mouse[3] = 0; - - if(arg[1] > 0xfff) - arg[1] = 0xfff; - key->code.mouse[1] = (arg[1] & 0x0ff); - key->code.mouse[3] |= (arg[1] & 0xf00) >> 8; - - if(arg[2] > 0x7ff) - arg[1] = 0x7ff; - key->code.mouse[2] = (arg[2] & 0x0ff); - key->code.mouse[3] |= (arg[2] & 0x300) >> 4; + termkey_key_set_linecol(key, arg[1], arg[2]); if(cmd == 'm') // release key->code.mouse[3] |= 0x80; diff --git a/termkey-internal.h b/termkey-internal.h index d23f68c..1ebdecb 100644 --- a/termkey-internal.h +++ b/termkey-internal.h @@ -64,6 +64,28 @@ struct TermKey { } method; }; +static inline void termkey_key_get_linecol(const TermKeyKey *key, int *line, int *col) +{ + if(col) + *col = (unsigned char)key->code.mouse[1] | ((unsigned char)key->code.mouse[3] & 0x0f) << 8; + + if(line) + *line = (unsigned char)key->code.mouse[2] | ((unsigned char)key->code.mouse[3] & 0x70) << 4; +} + +static inline void termkey_key_set_linecol(TermKeyKey *key, int line, int col) +{ + if(line > 0xfff) + line = 0xfff; + + if(col > 0x7ff) + col = 0x7ff; + + key->code.mouse[1] = (line & 0x0ff); + key->code.mouse[2] = (col & 0x0ff); + key->code.mouse[3] = (line & 0xf00) >> 8 | (col & 0x300) >> 4; +} + extern struct TermKeyDriver termkey_driver_csi; extern struct TermKeyDriver termkey_driver_ti; diff --git a/termkey.c b/termkey.c index 6664151..ade90a8 100644 --- a/termkey.c +++ b/termkey.c @@ -911,11 +911,7 @@ TermKeyResult termkey_interpret_mouse(TermKey *tk, const TermKeyKey *key, TermKe if(button) *button = 0; - if(col) - *col = (unsigned char)key->code.mouse[1] | ((unsigned char)key->code.mouse[3] & 0x0f) << 8; - - if(line) - *line = (unsigned char)key->code.mouse[2] | ((unsigned char)key->code.mouse[3] & 0x70) << 4; + termkey_key_get_linecol(key, line, col); if(!event) return TERMKEY_RES_KEY; -- cgit v1.2.3-70-g09d2