diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-06-12 12:33:38 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-06-12 12:33:38 -0700 |
commit | a79d1edc9ef2e29597faa723a05088a5d19ea8aa (patch) | |
tree | 0ca99e37b46750316b5db2ea3e6a2cdeb4aec5fd /sys/cmd/dvtm/events.c | |
parent | e41eb5691417ecacade402759231f64778e3147f (diff) |
checkin: going to flesh out your own api
Diffstat (limited to 'sys/cmd/dvtm/events.c')
-rw-r--r-- | sys/cmd/dvtm/events.c | 180 |
1 files changed, 15 insertions, 165 deletions
diff --git a/sys/cmd/dvtm/events.c b/sys/cmd/dvtm/events.c index 12b0518..c4f544b 100644 --- a/sys/cmd/dvtm/events.c +++ b/sys/cmd/dvtm/events.c @@ -1,133 +1,14 @@ -#include <u.h> -#include <libn.h> -#include <poll.h> -#include <termios.h> +#include "term.h" -#include <vendor/unibilium.h> +#include <poll.h> -#define iota(x) 1 << (x) #define bufcount(in) in->buf.c - in->buf.b -/* symbols */ -enum -{ - SymUnknown = -1, - SymNone = 0, - - /* special names in c0 */ - SymBackspace, SymTab, SymEnter, SymEscape, - - /* special names in g0 */ - SymSpace, SymDel, - - /* special keys */ - SymUp, SymDown, SymLeft, SymRight, SymBegin, SymFind, SymInsert, - SymDelete, SymSelect, SymPageup, SymPagedown, SymHome, SymEnd, - - /* special keys from terminfo */ - SymCancel, SymClear, SymClose, SymCommand, SymCopy, SymExit, - SymHelp, SymMark, SymMessage, SymMove, SymOpen, SymOptions, - SymPrint, SymRedo, SymReference, SymRefresh, SymReplace, - SymRestart, SymResume, SymSave, SymSuspend, SymUndo, - - /* numeric keypad special keys */ - SymKp0, SymKp1, SymKp2, SymKp3, SymKp4, SymKp5, SymKp6, SymKp7, SymKp8, - SymKp9, SymKpenter, SymKpplus, SymKpminus, SymKpmult, SymKpdiv, SymKpcomma, - SymKpperiod, SymKpequals, - - /* et cetera ad nauseum */ - NumSyms -}; - -/* key type */ -enum -{ - KeyUnicode, - KeyFunc, - KeySym, - KeyMouse, - KeyPosition, - KeyModeReport, - KeyDCS, - KeyOSC, - /* add other recognised types here */ - - KeyUnknownCSI = -1 -}; - -/* key events */ -enum KeyEvent -{ - EvNil, - EvKey, - EvEOF, - EvAgain, - EvErr, -}; - -enum MouseEvent -{ - MouseNil, - MousePress, - MouseDrag, - MouseRelease, -}; - -enum -{ - ModShift = iota(0), - ModAlt = iota(1), - ModCtrl = iota(2), -}; - -enum -{ - FlagNoInterpret = iota(0), - FlagConvertKP = iota(1), - FlagRaw = iota(2), - FlagUTF8 = iota(3), - FlagNoTermIOS = iota(4), - FlagSpaceSymbol = iota(5), - FlagCtrlC = iota(6), - FlagEintr = iota(7), -}; - -enum -{ - HarmonizeSpace = iota(0), - HarmonizeDelBS = iota(1), -}; - enum { NodeKey, NodeArr, }; -typedef struct Key Key; -typedef struct Node Node; -typedef struct Input Input; - -struct Key -{ - int type; - int mods; - uchar utf8[UTFmax+1]; - union { - rune pt; - int num; - int sym; - char mouse[4]; - } code; -}; - -struct KeyInfo -{ - int type; - int sym; - int modmask; - int modset; -}; - struct Node { int type; @@ -136,7 +17,7 @@ struct Node struct KeyNode { struct Node; - struct KeyInfo key; + struct KeyInfo key; }; struct ArrNode @@ -146,37 +27,6 @@ struct ArrNode Node *arr[]; }; -struct Input -{ - int fd; - int flags; - int hflag; - int wait; /* in ms */ - - struct termios oldterm; - - /* buffer */ - struct { - long off; - uchar *b, *c, *e, bytes[256]; - } buf; - - /* modifiers */ - char closed : 1; - char started : 1; - char hasold : 1; - - /* key data */ - Node *keys; - struct KeyInfo c0[32]; - - char **keynm; - int nkeynm; - - int nsavedcsi; - char *savedcsi; -}; - // ----------------------------------------------------------------------- // loads data into trie @@ -589,11 +439,11 @@ inline void getpos(Key *key, int *row, int *col) { - if(col) - *col = (uchar)key->code.mouse[1] | ((uchar)key->code.mouse[3] & 0x0f) << 8; + if (col) + *col = ((uchar)key->code.mouse[1] | ((uchar)key->code.mouse[3] & 0x0f) << 8) - 1; - if(row) - *row = (uchar)key->code.mouse[2] | ((uchar)key->code.mouse[3] & 0x70) << 4; + if (row) + *row = ((uchar)key->code.mouse[2] | ((uchar)key->code.mouse[3] & 0x70) << 4) - 1; } // ----------------------------------------------------------------------- @@ -621,8 +471,8 @@ do_csi_full(Input *in, Key *key, int cmd, int narg, long *arg) key->type = csiss3[cmd - 0x40].type; key->code.sym = csiss3[cmd - 0x40].sym; - key->mods &= ~(csiss3[cmd - 0x40].modmask); - key->mods |= csiss3[cmd - 0x40].modset; + key->mods &= ~(csiss3[cmd - 0x40].modmask); + key->mods |= csiss3[cmd - 0x40].modset; if(key->code.sym == SymUnknown) return EvNil; @@ -1577,7 +1427,7 @@ demandkey(Input *in, Key *key) } enum KeyEvent -readkey(Input *in) +isreadablekey(Input *in) { int n; if (in->fd == -1) { @@ -1628,7 +1478,7 @@ waitkey(Input *in, Key *key) case EvKey: case EvEOF: case EvErr: return ev; case EvNil: - ev = readkey(in); + ev = isreadablekey(in); if (ev == EvErr) return ev; break; @@ -1648,7 +1498,7 @@ waitkey(Input *in, Key *key) } if (p.revents & (POLLIN|POLLHUP|POLLERR)) - ev = readkey(in); + ev = isreadablekey(in); else ev = EvNil; @@ -1665,10 +1515,10 @@ waitkey(Input *in, Key *key) enum KeyEvent decodemouse(Input *in, Key *key, enum MouseEvent *ev, int *button, int *row, int *col) { - if (key->type != KeyMouse) + if(key->type != KeyMouse) return EvNil; - if (button) + if(button) *button = 0; getpos(key, row, col); @@ -1676,7 +1526,7 @@ decodemouse(Input *in, Key *key, enum MouseEvent *ev, int *button, int *row, int if(!ev) return EvKey; - int btn = 0; + int btn = 0; int code = key->code.mouse[0]; int drag = code & 0x20; code &= ~0x3c; |