ignore \0 bytes, disable navigation keys when /dev/kbd is open
This commit is contained in:
parent
294e4f1097
commit
d831a028dc
3 changed files with 32 additions and 44 deletions
|
@ -400,6 +400,7 @@ consproc(void *)
|
|||
x = buf + n;
|
||||
while(p < x && fullrune(p, x - p)){
|
||||
p += chartorune(&r, p);
|
||||
if(r)
|
||||
send(rawchan, &r);
|
||||
}
|
||||
n = x - p;
|
||||
|
|
|
@ -337,6 +337,7 @@ keyboardthread(void*)
|
|||
char *s;
|
||||
|
||||
threadsetname("keyboardthread");
|
||||
|
||||
while(s = recvp(kbdchan)){
|
||||
if(input == nil || sendp(input->ck, s) <= 0)
|
||||
free(s);
|
||||
|
@ -360,9 +361,11 @@ keyboardsend(char *s, int cnt)
|
|||
r = runemalloc(cnt);
|
||||
cvttorunes(s, cnt, r, &nb, &nr, nil);
|
||||
for(i=0; i<nr; i++){
|
||||
if(r[i]){
|
||||
chanprint(kbdchan, "%C", r[i]);
|
||||
chanprint(kbdchan, "");
|
||||
}
|
||||
}
|
||||
free(r);
|
||||
}
|
||||
}
|
||||
|
@ -1191,13 +1194,13 @@ new(Image *i, int hideit, int scrollit, int pid, char *dir, char *cmd, char **ar
|
|||
}
|
||||
|
||||
static void
|
||||
kbdioproc(void *arg)
|
||||
kbdproc(void *arg)
|
||||
{
|
||||
Channel *c = arg;
|
||||
char buf[128], *p, *e;
|
||||
int fd, cfd, kfd, n;
|
||||
|
||||
threadsetname("kbdioproc");
|
||||
threadsetname("kbdproc");
|
||||
|
||||
if((fd = open("/dev/cons", OREAD)) < 0){
|
||||
chanprint(c, "%r");
|
||||
|
@ -1234,9 +1237,11 @@ kbdioproc(void *arg)
|
|||
e = p + n;
|
||||
while(p < e && fullrune(p, e - p)){
|
||||
p += chartorune(&r, p);
|
||||
if(r){
|
||||
chanprint(c, "%C", r);
|
||||
chanprint(c, "");
|
||||
}
|
||||
}
|
||||
n = e - p;
|
||||
if(n > 0){
|
||||
memmove(buf, p, n);
|
||||
|
@ -1252,15 +1257,15 @@ Channel*
|
|||
initkbd(void)
|
||||
{
|
||||
Channel *c;
|
||||
char *err;
|
||||
char *e;
|
||||
|
||||
c = chancreate(sizeof(char*), 16);
|
||||
proccreate(kbdioproc, c, STACK);
|
||||
if(err = recvp(c)){
|
||||
proccreate(kbdproc, c, STACK);
|
||||
if(e = recvp(c)){
|
||||
chanfree(c);
|
||||
werrstr(err);
|
||||
free(err);
|
||||
return nil;
|
||||
c = nil;
|
||||
werrstr(e);
|
||||
free(e);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ enum
|
|||
|
||||
static int topped;
|
||||
static int id;
|
||||
static int reverse;
|
||||
|
||||
static Image *cols[NCOL];
|
||||
static Image *grey;
|
||||
|
@ -31,7 +30,6 @@ static Image *darkgrey;
|
|||
static Cursor *lastcursor;
|
||||
static Image *titlecol;
|
||||
static Image *lighttitlecol;
|
||||
static Image *dholdcol;
|
||||
static Image *holdcol;
|
||||
static Image *lightholdcol;
|
||||
static Image *paleholdcol;
|
||||
|
@ -43,36 +41,19 @@ wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
|
|||
Rectangle r;
|
||||
|
||||
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 */
|
||||
grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF^reverse);
|
||||
darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF^reverse);
|
||||
cols[BACK] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xFFFFFFFF^reverse);
|
||||
cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF^reverse);
|
||||
grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF);
|
||||
darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF);
|
||||
cols[BACK] = display->white;
|
||||
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[TEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse);
|
||||
cols[HTEXT] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x000000FF^reverse);
|
||||
if(reverse == 0) {
|
||||
cols[TEXT] = display->black;
|
||||
cols[HTEXT] = display->black;
|
||||
titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygreen);
|
||||
lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreygreen);
|
||||
} 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);
|
||||
holdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue);
|
||||
lightholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreyblue);
|
||||
paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPalegreyblue);
|
||||
|
||||
if(reverse == 0)
|
||||
holdcol = dholdcol;
|
||||
else
|
||||
holdcol = paleholdcol;
|
||||
}
|
||||
w = emalloc(sizeof(Window));
|
||||
w->screenr = i->r;
|
||||
|
@ -623,8 +604,8 @@ wkeyctl(Window *w, Rune r)
|
|||
|
||||
if(w->deleted)
|
||||
return;
|
||||
/* navigation keys work only when mouse is not open */
|
||||
if(!w->mouseopen)
|
||||
/* navigation keys work only when mouse and kbd is not open */
|
||||
if(!w->mouseopen && !w->kbdopen)
|
||||
switch(r){
|
||||
case Kdown:
|
||||
n = w->maxlines/3;
|
||||
|
@ -759,7 +740,7 @@ wsetcols(Window *w)
|
|||
w->cols[TEXT] = w->cols[HTEXT] = lightholdcol;
|
||||
else
|
||||
if(w == input)
|
||||
w->cols[TEXT] = w->cols[HTEXT] = cols[TEXT];
|
||||
w->cols[TEXT] = w->cols[HTEXT] = display->black;
|
||||
else
|
||||
w->cols[TEXT] = w->cols[HTEXT] = darkgrey;
|
||||
}
|
||||
|
@ -1360,6 +1341,7 @@ wclosewin(Window *w)
|
|||
if(hidden[i] == w){
|
||||
--nhidden;
|
||||
memmove(hidden+i, hidden+i+1, (nhidden-i)*sizeof(hidden[0]));
|
||||
hidden[nhidden] = nil;
|
||||
break;
|
||||
}
|
||||
for(i=0; i<nwindow; i++)
|
||||
|
|
Loading…
Reference in a new issue