[hackers] wmii: new tip (= 1755)

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Tue, 06 Feb 2007 04:00:07 +0100

changeset: 1755:ffc344dfb268
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Mon Feb 05 21:56:03 2007 -0500
files: area.c bar.c draw.c frame.c main.c
description:
Misc cleanup.

diff -r 266fcc08814f -r ffc344dfb268 area.c
--- a/area.c Mon Feb 05 21:27:54 2007 -0500
+++ b/area.c Mon Feb 05 21:56:03 2007 -0500
@@ -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
 
         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 -r 266fcc08814f -r ffc344dfb268 bar.c
--- a/bar.c Mon Feb 05 21:27:54 2007 -0500
+++ b/bar.c Mon Feb 05 21:56:03 2007 -0500
@@ -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 @@ destroy_bar(Bar **b_link, Bar *b) {
 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 *nam
         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 -r 266fcc08814f -r ffc344dfb268 draw.c
--- a/draw.c Mon Feb 05 21:27:54 2007 -0500
+++ b/draw.c Mon Feb 05 21:56:03 2007 -0500
@@ -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 -r 266fcc08814f -r ffc344dfb268 frame.c
--- a/frame.c Mon Feb 05 21:27:54 2007 -0500
+++ b/frame.c Mon Feb 05 21:56:03 2007 -0500
@@ -52,7 +52,8 @@ insert_frame(Frame *pos, Frame *f, Bool
 
         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 -r 266fcc08814f -r ffc344dfb268 main.c
--- a/main.c Mon Feb 05 21:27:54 2007 -0500
+++ b/main.c Mon Feb 05 21:56:03 2007 -0500
@@ -25,8 +25,7 @@ static char version[] = "wmiiwm - " VERS
 
 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;
+}
Received on Tue Feb 06 2007 - 04:00:07 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:54:55 UTC