Replaced write_event with a va_arg printf-like version

This commit is contained in:
Kris Maglione 2006-06-23 20:26:24 -04:00
parent a979c86bb2
commit 489a00c835
6 changed files with 30 additions and 48 deletions

View File

@ -57,7 +57,6 @@ create_client(Window w, XWindowAttributes *wa)
long msize;
unsigned int i;
static unsigned int id = 1;
static char buf[256];
c->id = id++;
c->win = w;
@ -98,8 +97,7 @@ create_client(Window w, XWindowAttributes *wa)
c->next = *t; /* *t == nil */
*t = c;
snprintf(buf, sizeof(buf), "CreateClient %d\n", i);
write_event(buf);
write_event("CreateClient %d\n", i);
return c;
}
@ -130,7 +128,6 @@ focus_client(Client *c, Bool restack)
Frame *f;
Client *old_in_area;
View *v;
static char buf[256];
if(!sel_screen)
return;
@ -164,8 +161,7 @@ focus_client(Client *c, Bool restack)
update_frame_widget_colors(c->sel);
draw_frame(c->sel);
XSync(blz.display, False);
snprintf(buf, sizeof(buf), "ClientFocus %d\n", idx_of_client(c));
write_event(buf);
write_event("ClientFocus %d\n", idx_of_client(c));
}
void

View File

@ -69,31 +69,22 @@ handle_buttonrelease(XEvent *e)
Client *c;
Bar *b;
XButtonPressedEvent *ev = &e->xbutton;
static char buf[32];
if(ev->window == barwin) {
for(b=lbar; b; b=b->next)
if(ispointinrect(ev->x, ev->y, &b->brush.rect)) {
snprintf(buf, sizeof(buf), "LeftBarClick %d %s\n",
if(ispointinrect(ev->x, ev->y, &b->brush.rect))
return write_event("LeftBarClick %d %s\n",
ev->button, b->name);
write_event(buf);
return;
}
for(b=rbar; b; b=b->next)
if(ispointinrect(ev->x, ev->y, &b->brush.rect)) {
snprintf(buf, sizeof(buf), "RightBarClick %d %s\n",
if(ispointinrect(ev->x, ev->y, &b->brush.rect))
return write_event("RightBarClick %d %s\n",
ev->button, b->name);
write_event(buf);
return;
}
}
else if((c = frame_of_win(ev->window)) && c->frame) {
if(ispointinrect(ev->x, ev->y, &c->sel->tagbar.rect)) {
c->sel->tagbar.curend = blitz_charof(&c->sel->tagbar, ev->x, ev->y);
draw_frame(c->sel);
}
snprintf(buf, sizeof(buf), "ClientClick %d %d\n",
idx_of_client(c), ev->button);
write_event(buf);
write_event("ClientClick %d %d\n", idx_of_client(c), ev->button);
drag = False;
}
}

View File

@ -3,6 +3,7 @@
* See LICENSE file for license details.
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -70,6 +71,9 @@ static char
/* Global Vars */
/***************/
enum { BUF_SIZE = 2048 };
static char buf[BUF_SIZE];
FileId *free_fileid = nil;
P9Req *pending_event_reads = nil;
FidLink *pending_event_fids;
@ -301,9 +305,6 @@ message_root(char *message)
char *
read_root_ctl()
{
/* XXX: There should be 1 global buffer for this */
enum { BUF_SIZE = 2048 };
static char buf[BUF_SIZE];
unsigned int i = 0;
if(sel)
i += snprintf(&buf[i], (BUF_SIZE - i), "view %s\n", sel->name);
@ -333,14 +334,18 @@ respond_event(P9Req *r) {
}
void
write_event(char *buf) {
write_event(char *format, ...) {
unsigned int len, slen;
va_list ap;
FidLink *f;
FileId *fi;
P9Req *aux;
va_start(ap, format);
vsnprintf(buf, BUF_SIZE, format, ap);
if(!(len = strlen(buf)))
return;
goto end;
for(f=pending_event_fids; f; f=f->next) {
fi = f->fid->aux;
slen = fi->buf ? strlen(fi->buf) : 0;
@ -352,6 +357,8 @@ write_event(char *buf) {
pending_event_reads = pending_event_reads->aux;
respond_event(aux);
}
end:
va_end(ap);
}
static void
@ -754,7 +761,7 @@ fs_write(P9Req *r) {
case FsFEvent:
buf = cext_emallocz(r->ifcall.count + 1);
bcopy(r->ifcall.data, buf, r->ifcall.count);
write_event(buf);
write_event("%s", buf);
free(buf);
r->ofcall.count = r->ifcall.count;
return respond(r, nil);

View File

@ -189,7 +189,6 @@ handle_key_seq(Window w, Key *done)
unsigned long mod;
KeyCode key;
Key *found;
char buf[128];
next_keystroke(&mod, &key);
@ -200,10 +199,8 @@ handle_key_seq(Window w, Key *done)
if(!found) {
XBell(blz.display, 0);
} /* grabbed but not found */
else if(!found->tnext && !found->next) {
snprintf(buf, sizeof(buf), "Key %s\n", found->name);
write_event(buf);
}
else if(!found->tnext && !found->next)
write_event("Key %s\n", found->name);
else
handle_key_seq(w, found);
}
@ -221,10 +218,8 @@ handle_key(Window w, unsigned long mod, KeyCode keycode)
if(!found) {
XBell(blz.display, 0);
} /* grabbed but not found */
else if(!found->tnext && !found->next) {
snprintf(buf, sizeof(buf), "Key %s\n", found->name);
write_event(buf);
}
else if(!found->tnext && !found->next)
write_event("Key %s\n", found->name);
else {
XGrabKeyboard(blz.display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
handle_key_seq(w, found);

View File

@ -9,19 +9,14 @@
#include "wm.h"
static char buf[256];
static void
assign_sel_view(View *v)
{
if(sel != v) {
if(sel) {
snprintf(buf, sizeof(buf), "UnfocusTag %s\n", sel->name);
write_event(buf);
}
if(sel)
write_event("UnfocusTag %s\n", sel->name);
sel = v;
snprintf(buf, sizeof(buf), "FocusTag %s\n", sel->name);
write_event(buf);
write_event("FocusTag %s\n", sel->name);
}
}
@ -40,8 +35,7 @@ create_view(const char *name)
v->next = *i;
*i = v;
snprintf(buf, sizeof(buf), "CreateTag %s\n", v->name);
write_event(buf);
write_event("CreateTag %s\n", v->name);
if(!sel)
assign_sel_view(v);
@ -67,8 +61,7 @@ destroy_view(View *v)
for(sel=view; sel; sel=sel->next)
if(sel->next == *i) break;
snprintf(buf, sizeof(buf), "DestroyTag %s\n", v->name);
write_event(buf);
write_event("DestroyTag %s\n", v->name);
free(v);
}

View File

@ -282,7 +282,7 @@ void fs_remove(P9Req *r);
void fs_stat(P9Req *r);
void fs_walk(P9Req *r);
void fs_write(P9Req *r);
void write_event(char *buf);
void write_event(char *format, ...);
/* geom.c */
BlitzAlign quadofcoord(XRectangle *rect, int x, int y);