implemented event queueing and fixed a bug in rule.c reported by usa

This commit is contained in:
Anselm R. Garbe 2006-03-23 08:43:26 +01:00
parent 38cb6fdc0d
commit cc572f14f1
6 changed files with 32 additions and 17 deletions

View File

@ -64,7 +64,7 @@ handle_buttonpress(XEvent *e)
for(i = 0; i < nlabel; i++) for(i = 0; i < nlabel; i++)
if(blitz_ispointinrect(ev->x, ev->y, &label[i]->rect)) { if(blitz_ispointinrect(ev->x, ev->y, &label[i]->rect)) {
snprintf(buf, sizeof(buf), "LabelClick %s %d\n", label[i]->name, ev->button); snprintf(buf, sizeof(buf), "LabelClick %s %d\n", label[i]->name, ev->button);
write_event(buf); write_event(buf, True);
return; return;
} }
} }
@ -77,7 +77,7 @@ handle_buttonpress(XEvent *e)
} }
if(c->nframe) { if(c->nframe) {
snprintf(buf, sizeof(buf), "ClientClick %d %d\n", frame2index(c->frame[c->sel]) + 1, ev->button); snprintf(buf, sizeof(buf), "ClientClick %d %d\n", frame2index(c->frame[c->sel]) + 1, ev->button);
write_event(buf); write_event(buf, True);
} }
} }
else if((c = win2client(ev->window))) { else if((c = win2client(ev->window))) {
@ -104,7 +104,7 @@ handle_buttonpress(XEvent *e)
if(c->nframe) { if(c->nframe) {
snprintf(buf, sizeof(buf), "ClientClick %d %d\n", frame2index(c->frame[c->sel]) + 1, ev->button); snprintf(buf, sizeof(buf), "ClientClick %d %d\n", frame2index(c->frame[c->sel]) + 1, ev->button);
write_event(buf); write_event(buf, True);
} }
} }

View File

@ -27,6 +27,8 @@ static char Enofunc[] = "function not supported";
static char Enocommand[] = "command not supported"; static char Enocommand[] = "command not supported";
static char Ebadvalue[] = "bad value"; static char Ebadvalue[] = "bad value";
static char **queue = nil;
static unsigned int nqueue = 0, queuesz = 0;
#define WMII_IOUNIT 2048 #define WMII_IOUNIT 2048
/* /*
@ -839,6 +841,12 @@ xread(IXPConn *c, Fcall *fcall)
case FsFevent: case FsFevent:
memcpy(&c->pending, fcall, sizeof(Fcall)); memcpy(&c->pending, fcall, sizeof(Fcall));
c->is_pending = 1; c->is_pending = 1;
if(nqueue) {
char *event = queue[0];
cext_array_detach((void **)queue, event, &queuesz);
nqueue--;
write_event(event, False);
}
return nil; return nil;
break; break;
case FsFkeys: case FsFkeys:
@ -1396,7 +1404,7 @@ xwrite(IXPConn *c, Fcall *fcall)
if(fcall->count) { if(fcall->count) {
memcpy(buf, fcall->data, fcall->count); memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0; buf[fcall->count] = 0;
write_event(buf); write_event(buf, False);
} }
break; break;
default: default:
@ -1453,28 +1461,34 @@ do_fcall(IXPConn *c)
} }
void void
write_event(char *event) write_event(char *event, Bool enqueue)
{ {
unsigned int i; unsigned int i, written = 0;
for(i = 0; (i < srv.connsz) && srv.conn[i]; i++) { for(i = 0; (i < srv.connsz) && srv.conn[i]; i++) {
IXPConn *c = srv.conn[i]; IXPConn *c = srv.conn[i];
if(c->is_pending) { if(c->is_pending) {
/* pending reads on /event only, no qid checking */ /* pending reads on /event only, no qid checking */
IXPMap *m = ixp_server_fid2map(c, c->pending.fid); IXPMap *m = ixp_server_fid2map(c, c->pending.fid);
unsigned char *p = c->pending.data;
if(!m) { if(!m) {
if(ixp_server_respond_error(c, &c->pending, Enofile)) if(ixp_server_respond_error(c, &c->pending, Enofile))
break; return;
} }
else if(qpath_type(m->qid.path) == FsFevent) { else if(qpath_type(m->qid.path) == FsFevent) {
/* pending reads on /event only, no qid checking */
c->pending.count = strlen(event); c->pending.count = strlen(event);
memcpy(p, event, c->pending.count); memcpy(c->pending.data, event, c->pending.count);
c->pending.id = RREAD; c->pending.id = RREAD;
if(ixp_server_respond_fcall(c, &c->pending)) if(ixp_server_respond_fcall(c, &c->pending))
break; return;
} }
written++;
} }
} }
if(!written) {
queue = (char **)cext_array_attach((void **)queue, event, sizeof(char *), &queuesz);
nqueue++;
}
} }
void void

View File

@ -220,7 +220,7 @@ handle_key_seq(Window w, Key **done, unsigned int ndone)
case 1: case 1:
if(!found[0]->next) { if(!found[0]->next) {
snprintf(buf, sizeof(buf), "Key %s\n", found[0]->name); snprintf(buf, sizeof(buf), "Key %s\n", found[0]->name);
write_event(buf); write_event(buf, True);
break; break;
} }
default: default:
@ -244,7 +244,7 @@ handle_key(Window w, unsigned long mod, KeyCode keycode)
case 1: case 1:
if(!found[0]->next) { if(!found[0]->next) {
snprintf(buf, sizeof(buf), "Key %s\n", found[0]->name); snprintf(buf, sizeof(buf), "Key %s\n", found[0]->name);
write_event(buf); write_event(buf, True);
break; break;
} }
default: default:

View File

@ -63,6 +63,7 @@ parse(char *data, unsigned int *n)
} }
else if(*p == '>') { else if(*p == '>') {
mode = TAGS; mode = TAGS;
tags[0] = 0;
t = tags; t = tags;
} }
break; break;

View File

@ -102,7 +102,7 @@ focus_tag(Tag *t)
} }
tags2str(name, sizeof(name), t->tag, t->ntag); tags2str(name, sizeof(name), t->tag, t->ntag);
snprintf(buf, sizeof(buf), "FocusTag %s\n", name); snprintf(buf, sizeof(buf), "FocusTag %s\n", name);
write_event(buf); write_event(buf, True);
XSync(dpy, False); XSync(dpy, False);
XUngrabServer(dpy); XUngrabServer(dpy);
} }
@ -205,7 +205,7 @@ select_tag(char *arg)
sizeof(char *), &ctagsz); sizeof(char *), &ctagsz);
nctag++; nctag++;
snprintf(buf, sizeof(buf), "NewTag %s\n", arg); snprintf(buf, sizeof(buf), "NewTag %s\n", arg);
write_event(buf); write_event(buf, True);
} }
focus_tag(t); focus_tag(t);
@ -290,12 +290,12 @@ update_tags()
for(i = 0; i < nnewctag; i++) for(i = 0; i < nnewctag; i++)
if(!istag(ctag, nctag, newctag[i])) { if(!istag(ctag, nctag, newctag[i])) {
snprintf(buf, sizeof(buf), "NewTag %s\n", newctag[i]); snprintf(buf, sizeof(buf), "NewTag %s\n", newctag[i]);
write_event(buf); write_event(buf, True);
} }
for(i = 0; i < nctag; i++) { for(i = 0; i < nctag; i++) {
if(!istag(newctag, nnewctag, ctag[i])) { if(!istag(newctag, nnewctag, ctag[i])) {
snprintf(buf, sizeof(buf), "RemoveTag %s\n", ctag[i]); snprintf(buf, sizeof(buf), "RemoveTag %s\n", ctag[i]);
write_event(buf); write_event(buf, True);
} }
free(ctag[i]); free(ctag[i]);
} }

View File

@ -264,7 +264,7 @@ Client *win2clientframe(Window w);
/* fs.c */ /* fs.c */
unsigned long long mkqpath(unsigned char type, unsigned short pg, unsigned long long mkqpath(unsigned char type, unsigned short pg,
unsigned short area, unsigned short cl); unsigned short area, unsigned short cl);
void write_event(char *event); void write_event(char *event, Bool enqueue);
void new_ixp_conn(IXPConn *c); void new_ixp_conn(IXPConn *c);
/* kb.c */ /* kb.c */