wmii

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

commit 06669775f73ad94f73abdb69258f45d72b828ccf
parent 7aade32fff4a348a9f2573958b1662da7c51d28a
Author: Kris Maglione <jg@suckless.org>
Date:   Mon,  5 Feb 2007 21:56:03 -0500

Misc cleanup.


Diffstat:
area.c | 9++++++---
bar.c | 30++++++++++++++++--------------
draw.c | 8+++-----
frame.c | 3++-
main.c | 29++++++++++++++++++++---------
5 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/area.c b/area.c @@ -16,7 +16,9 @@ max(int a, int b) { Client * sel_client_of_area(Area *a) { - return a && a->sel ? a->sel->client : nil; + if(a && a->sel) + return a->sel->client; + return nil; } Area * @@ -31,7 +33,7 @@ create_area(View *v, Area *pos, unsigned int w) { area_num = 0; i = 0; - for(a = v->area; a && a != *p; a = a->next) + for(a = v->area; a != *p; a = a->next) area_num++, i++; for(; a; a = a->next) area_num++; @@ -255,7 +257,8 @@ detach_from_area(Area *a, Frame *f) { if(v->area->next->next) destroy_area(a); else if(!a->frame && v->area->frame) { - v->sel = v->area; /* focus floating area if it contains something */ + /* focus floating area if it contains something */ + v->sel = v->area; write_event("FocusFloating\n"); } arrange_view(v); diff --git a/bar.c b/bar.c @@ -26,7 +26,7 @@ create_bar(Bar **b_link, char *name) { strncpy(b->name, name, sizeof(b->name)); b->brush = screen->bbrush; b->brush.color = def.normcolor; - for(i=b_link; *i; i=&(*i)->next) + for(i = b_link; *i; i = &(*i)->next) if(strcmp((*i)->name, name) >= 0) break; b->next = *i; @@ -39,7 +39,8 @@ void destroy_bar(Bar **b_link, Bar *b) { Bar **p; - for(p=b_link; *p && *p != b; p=&(*p)->next); + for(p = b_link; *p; p = &(*p)->next) + if(*p == b) break; *p = b->next; b->next = free_bars; free_bars = b; @@ -55,7 +56,7 @@ resize_bar(WMScreen *s) { XMoveResizeWindow(blz.dpy, s->barwin, s->brect.x, s->brect.y, s->brect.width, s->brect.height); XSync(blz.dpy, False); draw_bar(s); - for(v=view; v; v=v->next) + for(v = view; v; v = v->next) arrange_view(v); } @@ -70,7 +71,7 @@ draw_bar(WMScreen *s) { goto MapBar; largest = b = tb = nil; tw = width = nb = size = 0; - for(b=s->lbar, nb=2 ;nb; --nb && (b = s->rbar)) + for(b = s->lbar, nb = 2 ;nb; --nb && (b = s->rbar)) for(; b; b=b->next) { b->brush.rect.x = b->brush.rect.y = 0; b->brush.rect.width = def.font.height & ~1; @@ -81,14 +82,15 @@ draw_bar(WMScreen *s) { } /* Not enough room. Shrink bars until they all fit */ if(width > s->brect.width) { - for(b=s->lbar, nb=2 ;nb; --nb && (b = s->rbar)) - for(; b; b=b->next) { - for(pb=&largest; *pb; pb=&(*pb)->smaller) - if((*pb)->brush.rect.width < b->brush.rect.width) break; + for(b = s->lbar, nb = 2 ;nb; --nb && (b = s->rbar)) + for(; b; b = b->next) { + for(pb = &largest; *pb; pb = &(*pb)->smaller) + if((*pb)->brush.rect.width < b->brush.rect.width) + break; b->smaller = *pb; *pb = b; } - for(tb=largest; tb; tb=tb->smaller) { + for(tb = largest; tb; tb = tb->smaller) { width -= tb->brush.rect.width; tw += tb->brush.rect.width; shrink = (s->brect.width - width) / (float)tw; @@ -97,13 +99,13 @@ draw_bar(WMScreen *s) { break; } if(tb) - for(b=largest; b != tb->smaller; b=b->smaller) + for(b = largest; b != tb->smaller; b = b->smaller) b->brush.rect.width = floor(b->brush.rect.width * shrink); width += tw * shrink; - tb=nil; + tb = nil; } - for(b=s->lbar, nb=2 ;nb; b=s->rbar, nb--) - for(; b; tb = b, b=b->next) { + for(b = s->lbar, nb = 2 ;nb; b = s->rbar, nb--) + for(; b; tb = b, b = b->next) { if(b == s->rbar) { b->brush.align = EAST; s->rbar->brush.rect.width += (s->brect.width - width); @@ -126,7 +128,7 @@ bar_of_name(Bar *b_link, const char *name) { Bar *b; strncpy(buf, name, sizeof(buf)); - for(b=b_link; b; b=b->next) + for(b = b_link; b; b = b->next) if(!strncmp(b->name, name, sizeof(b->name))) break; return b; } diff --git a/draw.c b/draw.c @@ -32,7 +32,7 @@ loadfont(Blitz *blitz, BlitzFont *font) { font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def); if(missing) { while(n--) - fprintf(stderr, "wmii: missing fontset: %s\n", missing[n]); + fprintf(stderr, "wmiiwm: missing fontset: %s\n", missing[n]); XFreeStringList(missing); } if(font->set) { @@ -57,11 +57,9 @@ loadfont(Blitz *blitz, BlitzFont *font) { font->xfont = nil; font->xfont = XLoadQueryFont(blitz->dpy, fontname); if (!font->xfont) { - if(!strncmp(fontname, BLITZ_FONT, sizeof(BLITZ_FONT))) { - fprintf(stderr, "wmii: error, cannot load '%s' font\n", + if(!strncmp(fontname, BLITZ_FONT, sizeof(BLITZ_FONT))) + ixp_eprint("wmiiwm: error, cannot load '%s' font\n", BLITZ_FONT); - exit(1); - } free(font->fontstr); font->fontstr = ixp_estrdup(BLITZ_FONT); return loadfont(blitz, font); diff --git a/frame.c b/frame.c @@ -52,7 +52,8 @@ insert_frame(Frame *pos, Frame *f, Bool before) { if(before) { Frame *ft; - for(ft=a->frame; ft && ft->anext != pos; ft=ft->anext); + for(ft=a->frame; ft; ft=ft->anext) + if(ft->anext == pos) break; pos=ft; } Frame **p = pos ? &pos->anext : &a->frame; diff --git a/main.c b/main.c @@ -25,8 +25,7 @@ static char version[] = "wmiiwm - " VERSION ", (C)opyright MMIV-MMVI Anselm R. G static void usage() { - fputs("usage: wmiiwm -a <address> [-r <wmiirc>] [-v]\n", stderr); - exit(1); + ixp_eprint("usage: wmiiwm -a <address> [-r <wmiirc>] [-v]\n"); } static void @@ -226,13 +225,18 @@ main(int argc, char *argv[]) { break; } } - starting = True; + + if(!address) + usage(); + setlocale(LC_CTYPE, ""); + blz.dpy = XOpenDisplay(0); if(!blz.dpy) ixp_eprint("wmiiwm: cannot open dpy\n"); blz.screen = DefaultScreen(blz.dpy); blz.root = RootWindow(blz.dpy, blz.screen); + /* check if another WM is already running */ other_wm_running = 0; XSetErrorHandler(startup_error_handler); @@ -241,8 +245,7 @@ main(int argc, char *argv[]) { XSync(blz.dpy, False); if(other_wm_running) ixp_eprint("wmiiwm: another window manager is already running\n"); - if(!address) - usage(); + /* Check namespace permissions */ if(!strncmp(address, "unix!", 5)) { struct stat st; @@ -254,7 +257,8 @@ main(int argc, char *argv[]) { ixp_eprint("wmiiwm: can't stat namespace directory \"%s\": %s\n", namespace, strerror(errno)); if(getuid() != st.st_uid) - ixp_eprint("wmiiwm: namespace directory \"%s\" exists, but is not owned by you", + ixp_eprint("wmiiwm: namespace directory \"%s\" exists, " + "but is not owned by you", namespace); if(st.st_mode & 077) ixp_eprint("wmiiwm: namespace directory \"%s\" exists, " @@ -262,6 +266,7 @@ main(int argc, char *argv[]) { namespace); free(namespace); } + XSetErrorHandler(0); x_error_handler = XSetErrorHandler(wmii_error_handler); errstr = nil; @@ -277,7 +282,7 @@ main(int argc, char *argv[]) { switch(fork()) { case 0: if(setsid() == -1) - ixp_eprint("wmiim: can't setsid: %s\n", strerror(errno)); + ixp_eprint("wmiiwm: can't setsid: %s\n", strerror(errno)); close(i); close(ConnectionNumber(blz.dpy)); snprintf(execstr, name_len, "exec %s", wmiirc); @@ -294,6 +299,7 @@ main(int argc, char *argv[]) { ixp_server_open_conn(&srv, i, &p9srv, serve_9pcon, nil); /* X server */ ixp_server_open_conn(&srv, ConnectionNumber(blz.dpy), nil, check_x_event, nil); + view = nil; client = nil; key = nil; @@ -359,6 +365,8 @@ main(int argc, char *argv[]) { } screen = &screens[0]; + + starting = True; scan_wins(); update_views(); starting = False; @@ -366,9 +374,12 @@ main(int argc, char *argv[]) { /* main event loop */ errstr = ixp_server_loop(&srv); if(errstr) - fprintf(stderr, "wmii: fatal: %s\n", errstr); + fprintf(stderr, "wmiiwm: fatal: %s\n", errstr); + cleanup(); XCloseDisplay(blz.dpy); ixp_server_close(&srv); - return errstr ? 1 : 0; + if(errstr) + return 1; + return 0; }