wmii

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

commit a0d45af21557cd811033d21f073eed2d916d773d
parent 93b0e21ffbc1c4cf7c55a04483aeabc060764931
Author: Anthony Martin <ality@pbrane.org>
Date:   Thu, 23 Mar 2006 06:01:32 -0800

cleaned up formatting in view.c and wm.c


Diffstat:
cmd/wm/view.c | 23++++++++++++-----------
cmd/wm/wm.c | 389+++++++++++++++++++++++++++++++++++++++----------------------------------------
2 files changed, 205 insertions(+), 207 deletions(-)

diff --git a/cmd/wm/view.c b/cmd/wm/view.c @@ -12,7 +12,7 @@ View * alloc_view(char *name) { static unsigned short id = 1; - View *v = cext_emallocz(sizeof(View)); + View *v = cext_emallocz(sizeof(View)); v->id = id++; v->ntag = str2tags(v->tag, name); @@ -21,7 +21,7 @@ alloc_view(char *name) view = (View **)cext_array_attach((void **)view, v, sizeof(View *), &viewsz); nview++; focus_view(v); - return v; + return v; } static void @@ -35,7 +35,7 @@ destroy_view(View *v) if(sel >= nview) sel = 0; - free(v); + free(v); } int @@ -86,7 +86,8 @@ focus_view(View *v) draw_client(client[i]); } else - XMoveWindow(dpy, client[i]->framewin, 2 * rect.width + f->rect.x, f->rect.y); + XMoveWindow(dpy, client[i]->framewin, + 2 * rect.width + f->rect.x, f->rect.y); } tags2str(name, sizeof(name), v->tag, v->ntag); snprintf(buf, sizeof(buf), "FocusTag %s\n", name); @@ -98,7 +99,7 @@ focus_view(View *v) XRectangle * rectangles(View *v, Bool isfloat, unsigned int *num) { - XRectangle *result = nil; + XRectangle *result = nil; unsigned int i; *num = 0; @@ -110,7 +111,7 @@ rectangles(View *v, Bool isfloat, unsigned int *num) } if(*num) { - result = cext_emallocz(*num * sizeof(XRectangle)); + result = cext_emallocz(*num * sizeof(XRectangle)); if(isfloat) { for(i = 0; i < *num; i++) result[i] = v->area[0]->frame[0]->rect; @@ -123,7 +124,7 @@ rectangles(View *v, Bool isfloat, unsigned int *num) } } } - return result; + return result; } int @@ -195,7 +196,7 @@ select_view(char *arg) snprintf(buf, sizeof(buf), "NewTag %s\n", arg); write_event(buf, True); } - focus_view(v); + focus_view(v); /* cleanup on select */ for(i = 0; i < nview; i++) @@ -241,10 +242,10 @@ attach_toview(View *v, Client *c) if(c->trans || clienthastag(c, "~")) a = v->area[0]; else - a = v->area[v->sel]; + a = v->area[v->sel]; attach_toarea(a, c); - map_client(c); + map_client(c); XMapWindow(dpy, c->framewin); if(v == view[sel]) focus_client(c); @@ -265,7 +266,7 @@ restack_view(View *v) { unsigned int i, j, n = 0; static Window *wins = nil; - static unsigned int winssz = 0; + static unsigned int winssz = 0; if(nclient > winssz) { winssz = 2 * nclient; diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -24,8 +24,8 @@ static char version[] = "wmiiwm - " VERSION ", (C)opyright MMIV-MMVI Anselm R. G static void usage() { - fprintf(stderr, "%s", "usage: wmiiwm -a <address> [-t <default tag>] [-c] [-v]\n"); - exit(1); + fprintf(stderr, "%s", "usage: wmiiwm -a <address> [-t <default tag>] [-c] [-v]\n"); + exit(1); } Client * @@ -42,125 +42,123 @@ win2client(Window w) void scan_wins() { - int i; - unsigned int num; - Window *wins; - XWindowAttributes wa; - Window d1, d2; - - if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { - for(i = 0; i < num; i++) { - if(!XGetWindowAttributes(dpy, wins[i], &wa)) - continue; - if(wa.override_redirect - || XGetTransientForHint(dpy, wins[i], &d1)) - continue; - if(wa.map_state == IsViewable) + int i; + unsigned int num; + Window *wins; + XWindowAttributes wa; + Window d1, d2; + + if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { + for(i = 0; i < num; i++) { + if(!XGetWindowAttributes(dpy, wins[i], &wa)) + continue; + if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) + continue; + if(wa.map_state == IsViewable) manage_client(alloc_client(wins[i], &wa)); - } - } - if(wins) - XFree(wins); + } + } + if(wins) + XFree(wins); } static int win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) { - Atom real; - int format; - unsigned long res, extra; - int status; - - status = - XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, - &res, &extra, prop); - - if(status != Success || *prop == 0) { - return 0; - } - if(res == 0) { - free((void *) *prop); - } - return res; + Atom real; + int format; + unsigned long res, extra; + int status; + + status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, + &res, &extra, prop); + + if(status != Success || *prop == 0) { + return 0; + } + if(res == 0) { + free((void *) *prop); + } + return res; } int win_proto(Window w) { - Atom *protocols; - long res; - int protos = 0; - int i; - - res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, - ((unsigned char **) &protocols)); - if(res <= 0) { - return protos; - } - for(i = 0; i < res; i++) { - if(protocols[i] == wm_atom[WMDelete]) - protos |= WM_PROTOCOL_DELWIN; - } - free((char *) protocols); - return protos; + Atom *protocols; + long res; + int protos = 0; + int i; + + res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, + ((unsigned char **) &protocols)); + if(res <= 0) { + return protos; + } + for(i = 0; i < res; i++) { + if(protocols[i] == wm_atom[WMDelete]) + protos |= WM_PROTOCOL_DELWIN; + } + free((char *) protocols); + return protos; } int win_state(Window w) { - /* state hints */ - XWMHints *hints = XGetWMHints(dpy, w); - int res; + /* state hints */ + XWMHints *hints = XGetWMHints(dpy, w); + int res; - long *prop = 0; - if(win_property(w, wm_atom[WMState], wm_atom[WMState], 2L, - ((unsigned char **) &prop)) > 0) + long *prop = 0; + if(win_property(w, wm_atom[WMState], wm_atom[WMState], 2L, + ((unsigned char **) &prop)) > 0) { - res = (int) *prop; - free((long *) prop); - } else { - res = hints ? hints->initial_state : NormalState; - } - - if(hints) { - free(hints); - } - return res; + res = (int) *prop; + free((long *) prop); + } else { + res = hints ? hints->initial_state : NormalState; + } + + if(hints) { + free(hints); + } + return res; } static void init_atoms() { - wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False); - wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); - wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False); + wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); + wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); } static void init_cursors() { - cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); - cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); - cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); + cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); + cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); + cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); } static void init_screen() { - XGCValues gcv; - - gcv.subwindow_mode = IncludeInferiors; - gcv.function = GXxor; - gcv.foreground = def.sel.bg; - gcv.line_width = 4; - gcv.plane_mask = AllPlanes; - gcv.graphics_exposures = False; - xorgc = XCreateGC(dpy, root, GCForeground | GCGraphicsExposures - | GCFunction | GCSubwindowMode | GCLineWidth - | GCPlaneMask, &gcv); - rect.x = rect.y = 0; - rect.width = DisplayWidth(dpy, screen); - rect.height = DisplayHeight(dpy, screen); + XGCValues gcv; + + gcv.subwindow_mode = IncludeInferiors; + gcv.function = GXxor; + gcv.foreground = def.sel.bg; + gcv.line_width = 4; + gcv.plane_mask = AllPlanes; + gcv.graphics_exposures = False; + xorgc = XCreateGC(dpy, root, GCForeground | GCGraphicsExposures + | GCFunction | GCSubwindowMode | GCLineWidth + | GCPlaneMask, &gcv); + rect.x = rect.y = 0; + rect.width = DisplayWidth(dpy, screen); + rect.height = DisplayHeight(dpy, screen); def.snap = rect.height / 50; } @@ -174,20 +172,20 @@ init_screen() int wmii_error_handler(Display *dpy, XErrorEvent *error) { - if(error->error_code == BadWindow - || (error->request_code == X_SetInputFocus - && error->error_code == BadMatch) - || (error->request_code == X_PolyText8 - && error->error_code == BadDrawable) - || (error->request_code == X_PolyFillRectangle - && error->error_code == BadDrawable) - || (error->request_code == X_PolySegment - && error->error_code == BadDrawable) - || (error->request_code == X_ConfigureWindow - && error->error_code == BadMatch)) - return 0; - fprintf(stderr, "%s", "wmiiwm: fatal error"); - return x_error_handler(dpy, error); /* calls exit() */ + if(error->error_code == BadWindow + || (error->request_code == X_SetInputFocus + && error->error_code == BadMatch) + || (error->request_code == X_PolyText8 + && error->error_code == BadDrawable) + || (error->request_code == X_PolyFillRectangle + && error->error_code == BadDrawable) + || (error->request_code == X_PolySegment + && error->error_code == BadDrawable) + || (error->request_code == X_ConfigureWindow + && error->error_code == BadMatch)) + return 0; + fprintf(stderr, "%s", "wmiiwm: fatal error"); + return x_error_handler(dpy, error); /* calls exit() */ } /* @@ -197,8 +195,8 @@ wmii_error_handler(Display *dpy, XErrorEvent *error) static int startup_error_handler(Display * dpy, XErrorEvent * error) { - other_wm_running = 1; - return -1; + other_wm_running = 1; + return -1; } static void @@ -210,96 +208,95 @@ cleanup() c = client[i]; reparent_client(c, root, c->frame[c->sel]->rect.x, c->frame[c->sel]->rect.y); } - XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); + XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSync(dpy, False); } - int main(int argc, char *argv[]) { - int i; - int checkwm = 0; - char *address = nil, *errstr; - XSetWindowAttributes wa; + int i; + int checkwm = 0; + char *address = nil, *errstr; + XSetWindowAttributes wa; - /* command line args */ + /* command line args */ def.tag[0] = 0; - if(argc > 1) { - for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { - switch (argv[i][1]) { - case 'v': - fprintf(stdout, "%s", version); - exit(0); - break; - case 'c': - checkwm = 1; - break; + if(argc > 1) { + for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { + switch (argv[i][1]) { + case 'v': + fprintf(stdout, "%s", version); + exit(0); + break; + case 'c': + checkwm = 1; + break; case 't': cext_strlcpy(def.tag, argv[++i], sizeof(def.tag)); break; - case 'a': - if(i + 1 < argc) - address = argv[++i]; - else - usage(); - break; - default: - usage(); - break; - } - } - } - - dpy = XOpenDisplay(0); - if(!dpy) { - fprintf(stderr, "%s", "wmiiwm: cannot open display\n"); - exit(1); - } - screen = DefaultScreen(dpy); - root = RootWindow(dpy, screen); - - /* check if another WM is already running */ - other_wm_running = 0; - XSetErrorHandler(startup_error_handler); - /* this causes an error if some other WM is running */ - XSelectInput(dpy, root, SubstructureRedirectMask); - XSync(dpy, False); - - if(other_wm_running) { - fprintf(stderr, - "wmiiwm: another window manager is already running\n"); - exit(1); - } - if(checkwm) { - XCloseDisplay(dpy); - exit(0); - } + case 'a': + if(i + 1 < argc) + address = argv[++i]; + else + usage(); + break; + default: + usage(); + break; + } + } + } + + dpy = XOpenDisplay(0); + if(!dpy) { + fprintf(stderr, "%s", "wmiiwm: cannot open display\n"); + exit(1); + } + screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); + + /* check if another WM is already running */ + other_wm_running = 0; + XSetErrorHandler(startup_error_handler); + /* this causes an error if some other WM is running */ + XSelectInput(dpy, root, SubstructureRedirectMask); + XSync(dpy, False); + + if(other_wm_running) { + fprintf(stderr, + "wmiiwm: another window manager is already running\n"); + exit(1); + } + if(checkwm) { + XCloseDisplay(dpy); + exit(0); + } /* above -c is checked */ - if(!address) + if(!address) usage(); - XSetErrorHandler(0); - x_error_handler = XSetErrorHandler(wmii_error_handler); + XSetErrorHandler(0); + x_error_handler = XSetErrorHandler(wmii_error_handler); errstr = nil; i = ixp_create_sock(address, &errstr); if(i < 0) { - fprintf(stderr, "wmii: fatal: %s\n", errstr); + fprintf(stderr, "wmii: fatal: %s\n", errstr); exit(1); } /* IXP server */ ixp_server_open_conn(&srv, i, new_ixp_conn, ixp_server_close_conn); - root_qid.type = IXP_QTDIR; - root_qid.version = 0; - root_qid.path = mkqpath(FsDroot, 0, 0, 0); + root_qid.type = IXP_QTDIR; + root_qid.version = 0; + root_qid.path = mkqpath(FsDroot, 0, 0, 0); /* X server */ ixp_server_open_conn(&srv, ConnectionNumber(dpy), check_x_event, nil); - init_x_event_handler(); + init_x_event_handler(); ntag = tagsz = nview = nclient = viewsz = clientsz = sel = 0; - view = nil; + view = nil; tag = nil; client = nil; @@ -313,7 +310,7 @@ main(int argc, char *argv[]) def.keys = nil; def.keyssz = 0; def.font = strdup(BLITZ_FONT); - def.border = 2; + def.border = 2; if(!strlen(def.tag)) cext_strlcpy(def.tag, "1", sizeof(def.tag)); cext_strlcpy(def.selcolor, BLITZ_SELCOLORS, sizeof(def.selcolor)); @@ -321,46 +318,46 @@ main(int argc, char *argv[]) cext_strlcpy(def.normcolor, BLITZ_NORMCOLORS, sizeof(def.normcolor)); blitz_loadcolor(dpy, screen, def.normcolor, &def.norm); - init_atoms(); - init_cursors(); - xfont = blitz_getfont(dpy, def.font); + init_atoms(); + init_cursors(); + xfont = blitz_getfont(dpy, def.font); init_lock_modifiers(); - init_screen(); + init_screen(); wa.event_mask = SubstructureRedirectMask; wa.cursor = cursor[CurNormal]; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); - wa.override_redirect = 1; - wa.background_pixmap = ParentRelative; - wa.event_mask = ExposureMask | ButtonPressMask - | SubstructureRedirectMask | SubstructureNotifyMask; - - brect = rect; - brect.height = xfont->ascent + xfont->descent + 4; - brect.y = rect.height - brect.height; - barwin = XCreateWindow(dpy, RootWindow(dpy, screen), brect.x, brect.y, - brect.width, brect.height, 0, DefaultDepth(dpy, screen), - CopyFromParent, DefaultVisual(dpy, screen), - CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); - XSync(dpy, False); - - bargc = XCreateGC(dpy, barwin, 0, 0); - - barpmap = XCreatePixmap(dpy, barwin, brect.width, brect.height, - DefaultDepth(dpy, screen)); + wa.override_redirect = 1; + wa.background_pixmap = ParentRelative; + wa.event_mask = ExposureMask | ButtonPressMask + | SubstructureRedirectMask | SubstructureNotifyMask; + + brect = rect; + brect.height = xfont->ascent + xfont->descent + 4; + brect.y = rect.height - brect.height; + barwin = XCreateWindow(dpy, RootWindow(dpy, screen), brect.x, brect.y, + brect.width, brect.height, 0, DefaultDepth(dpy, screen), + CopyFromParent, DefaultVisual(dpy, screen), + CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); + XSync(dpy, False); + + bargc = XCreateGC(dpy, barwin, 0, 0); + + barpmap = XCreatePixmap(dpy, barwin, brect.width, brect.height, + DefaultDepth(dpy, screen)); XMapRaised(dpy, barwin); draw_bar(); - scan_wins(); + scan_wins(); - /* main event loop */ + /* main event loop */ errstr = ixp_server_loop(&srv); if(errstr) - fprintf(stderr, "wmii: fatal: %s\n", errstr); + fprintf(stderr, "wmii: fatal: %s\n", errstr); ixp_server_close(&srv); - cleanup(); - XCloseDisplay(dpy); + cleanup(); + XCloseDisplay(dpy); - return errstr ? 1 : 0; + return errstr ? 1 : 0; }