ignore \0 bytes, disable navigation keys when /dev/kbd is open

This commit is contained in:
cinap_lenrek 2011-05-11 09:23:01 +00:00
parent 294e4f1097
commit d831a028dc
3 changed files with 32 additions and 44 deletions

View file

@ -400,7 +400,8 @@ consproc(void *)
x = buf + n; x = buf + n;
while(p < x && fullrune(p, x - p)){ while(p < x && fullrune(p, x - p)){
p += chartorune(&r, p); p += chartorune(&r, p);
send(rawchan, &r); if(r)
send(rawchan, &r);
} }
n = x - p; n = x - p;
if(n > 0){ if(n > 0){

View file

@ -337,6 +337,7 @@ keyboardthread(void*)
char *s; char *s;
threadsetname("keyboardthread"); threadsetname("keyboardthread");
while(s = recvp(kbdchan)){ while(s = recvp(kbdchan)){
if(input == nil || sendp(input->ck, s) <= 0) if(input == nil || sendp(input->ck, s) <= 0)
free(s); free(s);
@ -360,8 +361,10 @@ keyboardsend(char *s, int cnt)
r = runemalloc(cnt); r = runemalloc(cnt);
cvttorunes(s, cnt, r, &nb, &nr, nil); cvttorunes(s, cnt, r, &nb, &nr, nil);
for(i=0; i<nr; i++){ for(i=0; i<nr; i++){
chanprint(kbdchan, "%C", r[i]); if(r[i]){
chanprint(kbdchan, ""); chanprint(kbdchan, "%C", r[i]);
chanprint(kbdchan, "");
}
} }
free(r); free(r);
} }
@ -1191,13 +1194,13 @@ new(Image *i, int hideit, int scrollit, int pid, char *dir, char *cmd, char **ar
} }
static void static void
kbdioproc(void *arg) kbdproc(void *arg)
{ {
Channel *c = arg; Channel *c = arg;
char buf[128], *p, *e; char buf[128], *p, *e;
int fd, cfd, kfd, n; int fd, cfd, kfd, n;
threadsetname("kbdioproc"); threadsetname("kbdproc");
if((fd = open("/dev/cons", OREAD)) < 0){ if((fd = open("/dev/cons", OREAD)) < 0){
chanprint(c, "%r"); chanprint(c, "%r");
@ -1234,8 +1237,10 @@ kbdioproc(void *arg)
e = p + n; e = p + n;
while(p < e && fullrune(p, e - p)){ while(p < e && fullrune(p, e - p)){
p += chartorune(&r, p); p += chartorune(&r, p);
chanprint(c, "%C", r); if(r){
chanprint(c, ""); chanprint(c, "%C", r);
chanprint(c, "");
}
} }
n = e - p; n = e - p;
if(n > 0){ if(n > 0){
@ -1252,15 +1257,15 @@ Channel*
initkbd(void) initkbd(void)
{ {
Channel *c; Channel *c;
char *err; char *e;
c = chancreate(sizeof(char*), 16); c = chancreate(sizeof(char*), 16);
proccreate(kbdioproc, c, STACK); proccreate(kbdproc, c, STACK);
if(err = recvp(c)){ if(e = recvp(c)){
chanfree(c); chanfree(c);
werrstr(err); c = nil;
free(err); werrstr(e);
return nil; free(e);
} }
return c; return c;
} }

View file

@ -23,7 +23,6 @@ enum
static int topped; static int topped;
static int id; static int id;
static int reverse;
static Image *cols[NCOL]; static Image *cols[NCOL];
static Image *grey; static Image *grey;
@ -31,7 +30,6 @@ static Image *darkgrey;
static Cursor *lastcursor; static Cursor *lastcursor;
static Image *titlecol; static Image *titlecol;
static Image *lighttitlecol; static Image *lighttitlecol;
static Image *dholdcol;
static Image *holdcol; static Image *holdcol;
static Image *lightholdcol; static Image *lightholdcol;
static Image *paleholdcol; static Image *paleholdcol;
@ -43,36 +41,19 @@ wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
Rectangle r; Rectangle r;
if(cols[0] == nil){ if(cols[0] == nil){
/* there are no pastel paints in the dungeons and dragons world
* - rob pike
*/
reverse = 0;
if(getenv("reverse") != nil)
reverse = ~0xFF;
/* greys are multiples of 0x11111100+0xFF, 14* being palest */ /* greys are multiples of 0x11111100+0xFF, 14* being palest */
grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF^reverse); grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF);
darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse); darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF);
cols[BACK] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xFFFFFFFF^reverse); cols[BACK] = display->white;
cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF^reverse); cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF);
cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x999999FF); cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x999999FF);
cols[TEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse); cols[TEXT] = display->black;
cols[HTEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse); cols[HTEXT] = display->black;
if(reverse == 0) { titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygreen);
titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygreen); lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreygreen);
lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreygreen); holdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue);
} else {
titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPurpleblue);
lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse);
}
dholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue);
lightholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreyblue); lightholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreyblue);
paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreyblue); paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreyblue);
if(reverse == 0)
holdcol = dholdcol;
else
holdcol = paleholdcol;
} }
w = emalloc(sizeof(Window)); w = emalloc(sizeof(Window));
w->screenr = i->r; w->screenr = i->r;
@ -623,8 +604,8 @@ wkeyctl(Window *w, Rune r)
if(w->deleted) if(w->deleted)
return; return;
/* navigation keys work only when mouse is not open */ /* navigation keys work only when mouse and kbd is not open */
if(!w->mouseopen) if(!w->mouseopen && !w->kbdopen)
switch(r){ switch(r){
case Kdown: case Kdown:
n = w->maxlines/3; n = w->maxlines/3;
@ -759,7 +740,7 @@ wsetcols(Window *w)
w->cols[TEXT] = w->cols[HTEXT] = lightholdcol; w->cols[TEXT] = w->cols[HTEXT] = lightholdcol;
else else
if(w == input) if(w == input)
w->cols[TEXT] = w->cols[HTEXT] = cols[TEXT]; w->cols[TEXT] = w->cols[HTEXT] = display->black;
else else
w->cols[TEXT] = w->cols[HTEXT] = darkgrey; w->cols[TEXT] = w->cols[HTEXT] = darkgrey;
} }
@ -1360,6 +1341,7 @@ wclosewin(Window *w)
if(hidden[i] == w){ if(hidden[i] == w){
--nhidden; --nhidden;
memmove(hidden+i, hidden+i+1, (nhidden-i)*sizeof(hidden[0])); memmove(hidden+i, hidden+i+1, (nhidden-i)*sizeof(hidden[0]));
hidden[nhidden] = nil;
break; break;
} }
for(i=0; i<nwindow; i++) for(i=0; i<nwindow; i++)