kbdfs: cleanup

front
cinap_lenrek 2012-02-25 17:42:08 +01:00
parent ce6b942ff1
commit 612d666d54
1 changed files with 17 additions and 24 deletions

View File

@ -29,9 +29,8 @@ typedef struct Scan Scan;
struct Key { struct Key {
int down; int down;
int c; Rune b; /* button, unshifted key */
Rune r; Rune r; /* rune, shifted key */
Rune b;
}; };
struct Scan { struct Scan {
@ -241,21 +240,21 @@ kbdputsc(Scan *scan, int c)
} }
key.down = (c & 0x80) == 0; key.down = (c & 0x80) == 0;
key.c = c & 0x7f; c &= 0x7f;
if(key.c >= Nscan) if(c >= Nscan)
return; return;
if(scan->esc1) if(scan->esc1)
key.r = kbtabesc1[key.c]; key.r = kbtabesc1[c];
else if(scan->shift) else if(scan->shift)
key.r = kbtabshift[key.c]; key.r = kbtabshift[c];
else if(scan->altgr) else if(scan->altgr)
key.r = kbtabaltgr[key.c]; key.r = kbtabaltgr[c];
else if(scan->ctl) else if(scan->ctl)
key.r = kbtabctl[key.c]; key.r = kbtabctl[c];
else else
key.r = kbtab[key.c]; key.r = kbtab[c];
switch(key.r){ switch(key.r){
case Spec|0x60: case Spec|0x60:
@ -272,7 +271,7 @@ kbdputsc(Scan *scan, int c)
if(scan->esc1) if(scan->esc1)
key.b = key.r; key.b = key.r;
else else
key.b = kbtab[key.c]; key.b = kbtab[c];
if(scan->caps && key.r<='z' && key.r>='a') if(scan->caps && key.r<='z' && key.r>='a')
key.r += 'A' - 'a'; key.r += 'A' - 'a';
@ -363,8 +362,7 @@ utfconv(Rune *r, int n)
void void
keyproc(void *) keyproc(void *)
{ {
Rune rb[Nscan*2+1]; Rune rb[Nscan+1];
int cb[Nscan];
Key key; Key key;
int i, nb; int i, nb;
char *s; char *s;
@ -374,19 +372,16 @@ keyproc(void *)
nb = 0; nb = 0;
while(recv(keychan, &key) > 0){ while(recv(keychan, &key) > 0){
rb[0] = 0; rb[0] = 0;
for(i=0; i<nb && cb[i] != key.c; i++) for(i=0; i<nb && rb[i+1] != key.b; i++)
; ;
if(!key.down){ if(!key.down){
while(i < nb && cb[i] == key.c){ while(i < nb && rb[i+1] == key.b){
memmove(cb+i, cb+i+1, (nb-i+1) * sizeof(cb[0]));
memmove(rb+i+1, rb+i+2, (nb-i+1) * sizeof(rb[0])); memmove(rb+i+1, rb+i+2, (nb-i+1) * sizeof(rb[0]));
nb--; nb--;
rb[0] = 'K'; rb[0] = 'K';
} }
} else if(i == nb && nb < nelem(cb) && key.b){ } else if(i == nb && nb < nelem(rb)-1 && key.b){
cb[nb] = key.c; rb[++nb] = key.b;
rb[nb+1] = key.b;
nb++;
rb[0] = 'k'; rb[0] = 'k';
} }
if(rb[0]){ if(rb[0]){
@ -1148,7 +1143,6 @@ fswrite(Req *r)
if(k.r == 0) if(k.r == 0)
break; break;
k.b = k.r; k.b = k.r;
k.c = 0x100 + k.r; /* fake */
k.down = (p[0] == 'r'); k.down = (p[0] == 'r');
if(f->aux == nil){ if(f->aux == nil){
f->aux = emalloc9p(sizeof(Scan)); f->aux = emalloc9p(sizeof(Scan));
@ -1156,12 +1150,11 @@ fswrite(Req *r)
} }
a = f->aux; a = f->aux;
/* /*
* handle ^X forms according to keymap, * handle ^X forms according to keymap and
* assign base and scancode if any * assign button.
*/ */
for(i=0; i<Nscan; i++){ for(i=0; i<Nscan; i++){
if((a->shift && kbtabshift[i] == k.r) || (kbtab[i] == k.r)){ if((a->shift && kbtabshift[i] == k.r) || (kbtab[i] == k.r)){
k.c = i;
k.b = kbtab[i]; k.b = kbtab[i];
if(a->shift) if(a->shift)
k.r = kbtabshift[i]; k.r = kbtabshift[i];