wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 489a00c8358b4822ad8ca859682215ae0841cd06
parent a979c86bb24d0b9f47a6716af07e676b34fddfa9
Author: Kris Maglione <bsdaemon@wmii.de>
Date:   Fri, 23 Jun 2006 20:26:24 -0400

Replaced write_event with a va_arg printf-like version


Diffstat:
cmd/wm/client.c | 8++------
cmd/wm/event.c | 19+++++--------------
cmd/wm/fs.c | 19+++++++++++++------
cmd/wm/key.c | 13++++---------
cmd/wm/view.c | 17+++++------------
cmd/wm/wm.h | 2+-
6 files changed, 30 insertions(+), 48 deletions(-)

diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -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 diff --git a/cmd/wm/event.c b/cmd/wm/event.c @@ -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; } } diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c @@ -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); diff --git a/cmd/wm/key.c b/cmd/wm/key.c @@ -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); diff --git a/cmd/wm/view.c b/cmd/wm/view.c @@ -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); } diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -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);