#include #include #include #include #include extern const char *__progname; #ifdef __NetBSD__ #include #include #include #else #include #include #include #endif #include "gl-int.h" static int kbdstate; #define KBS_CTRL 0x01 #define KBS_LSHIFT 0x02 #define KBS_RSHIFT 0x04 #define KBS_SHIFT (KBS_LSHIFT|KBS_RSHIFT) static const char *defpath = "/dev/kbd"; static int kbdfd; static int prevkbdtrans; static void qkeystroke(unsigned char updn, unsigned char keycode) { if (TSTBIT(devqueued,KEYBD)) { unsigned int c; #define TYPE 0xf0000000 #define CHARS 0x00000000 #define NOTHING 0x10000000 #define FLAG 0x20000000 #define C3(a,b,c) (CHARS+(((c)&0x1ff)<<18)+(((b)&0x1ff)<<9)+((a)&0x1ff)) #define C3a(x) (((x) )&0x1ff) #define C3b(x) (((x)>> 9)&0x1ff) #define C3c(x) (((x)>>18)&0x1ff) #define NIL 0x100 #define STD 0x101 #define FLG(x) (FLAG|(x)) c = NOTHING; switch (keycode) { case 29: c = C3('\33',NIL,NIL); break; case 30: c = C3('1','!',NIL); break; case 31: c = C3('2','@','\0'); break; case 32: c = C3('3','#',NIL); break; case 33: c = C3('4','$',NIL); break; case 34: c = C3('5','%',NIL); break; case 35: c = C3('6','^',NIL); break; case 36: c = C3('7','&',NIL); break; case 37: c = C3('8','*',NIL); break; case 38: c = C3('9','(',NIL); break; case 39: c = C3('0',')',NIL); break; case 40: c = C3('-','_','\37'); break; case 41: c = C3('=','+',NIL); break; case 42: c = C3('`','~','\36'); break; case 43: c = C3('\b',NIL,NIL); break; case 53: c = C3('\t',NIL,NIL); break; case 54: c = C3('q',STD,STD); break; case 55: c = C3('w',STD,STD); break; case 56: c = C3('e',STD,STD); break; case 57: c = C3('r',STD,STD); break; case 58: c = C3('t',STD,STD); break; case 59: c = C3('y',STD,STD); break; case 60: c = C3('u',STD,STD); break; case 61: c = C3('i',STD,STD); break; case 62: c = C3('o',STD,STD); break; case 63: c = C3('p',STD,STD); break; case 64: c = C3('[','{',STD); break; case 65: c = C3(']','}',STD); break; case 66: c = C3('\177',NIL,NIL); break; case 76: c = FLG(KBS_CTRL); break; case 77: c = C3('a',STD,STD); break; case 78: c = C3('s',STD,STD); break; case 79: c = C3('d',STD,STD); break; case 80: c = C3('f',STD,STD); break; case 81: c = C3('g',STD,STD); break; case 82: c = C3('h',STD,STD); break; case 83: c = C3('j',STD,STD); break; case 84: c = C3('k',STD,STD); break; case 85: c = C3('l',STD,STD); break; case 86: c = C3(';',':',NIL); break; case 87: c = C3('\'','"',NIL); break; case 88: c = C3('\\','|',STD); break; case 89: c = C3('\r',NIL,NIL); break; case 99: c = FLG(KBS_LSHIFT); break; case 100: c = C3('z',STD,STD); break; case 101: c = C3('x',STD,STD); break; case 102: c = C3('c',STD,STD); break; case 103: c = C3('v',STD,STD); break; case 104: c = C3('b',STD,STD); break; case 105: c = C3('n',STD,STD); break; case 106: c = C3('m',STD,STD); break; case 107: c = C3(',','<',NIL); break; case 108: c = C3('.','>',NIL); break; case 109: c = C3('/','?','\37'); break; case 110: c = FLG(KBS_RSHIFT); break; case 111: c = C3('\n',NIL,NIL); break; case 121: c = C3(' ',NIL,NIL); break; } switch (c & TYPE) { case CHARS: if (updn == 'd') { if ((kbdstate & KBS_CTRL) & (C3c(c) != NIL)) { if (C3c(c) == STD) { makeqentry(KEYBD,C3a(c)&0x1f); } else { makeqentry(KEYBD,C3c(c)); } } else if ((kbdstate & KBS_SHIFT) & (C3b(c) != NIL)) { if (C3b(c) == STD) { makeqentry(KEYBD,C3a(c)^0x20); } else { makeqentry(KEYBD,C3b(c)); } } else { makeqentry(KEYBD,C3a(c)); } } break; case NOTHING: break; case FLAG: switch (updn) { case 'u': kbdstate &= ~(c & ~TYPE); break; case 'd': kbdstate |= (c & ~TYPE); break; } break; } #undef TYPE #undef CHARS #undef NOTHING #undef FLAG #undef C3 #undef C3a #undef C3b #undef C3c #undef NIL #undef STD #undef FLG } { int bit; bit = -1; switch (keycode) { case 18: bit = F9KEY; break; case 19: bit = RIGHTCTRLKEY; break; case 29: bit = ESCKEY; break; case 30: bit = ONEKEY; break; case 31: bit = TWOKEY; break; case 32: bit = THREEKEY; break; case 33: bit = FOURKEY; break; case 34: bit = FIVEKEY; break; case 35: bit = SIXKEY; break; case 36: bit = SEVENKEY; break; case 37: bit = EIGHTKEY; break; case 38: bit = NINEKEY; break; case 39: bit = ZEROKEY; break; case 82: bit = HKEY; break; case 119: bit = LEFTCTRLKEY; break; case 120: bit = LEFTALTKEY; break; case 121: bit = SPACEKEY; break; case 122: bit = RIGHTALTKEY; break; } if ((bit >= 0) && TSTBIT(devqueued,bit)) { makeqentry(bit,updn=='d'); } } } static void x_setselect( fd_set *r, fd_set *w __attribute__((__unused__)), fd_set *x __attribute__((__unused__)), struct timeval *now __attribute__((__unused__)), struct timeval *delay __attribute__((__unused__)) ) { FD_SET(kbdfd,r); } static int x_doselect( fd_set *r, fd_set *w __attribute__((__unused__)), fd_set *x __attribute__((__unused__)) ) { if (FD_ISSET(kbdfd,r)) { struct firm_event evs[64]; int n; int i; n = read(kbdfd,&evs[0],sizeof(evs)); if (n < 0) { fprintf(stderr,"%s: keyboard read: %s\n",__progname,strerror(errno)); exit(1); } if (n == 0) exit(0); n /= sizeof(struct firm_event); for (i=0;i