From b23fad398789ed8d7412813e5b178a38a6667ee7 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 11 Jul 2008 14:21:28 +0000 Subject: spacing, declaration lineup to be consistent throughout cwm, readability, and a bit of knf. ok oga@ --- calmwm.c | 38 ++++++++++---------- calmwm.h | 4 +-- client.c | 115 +++++++++++++++++++++++++++++++----------------------------- conf.c | 33 ++++++++--------- font.c | 11 +++--- grab.c | 43 +++++++++++------------ group.c | 37 +++++++++---------- input.c | 2 +- kbfunc.c | 58 ++++++++++++++++-------------- menu.c | 15 ++++---- mousefunc.c | 20 ++++++----- screen.c | 12 ++++--- search.c | 31 +++++++++------- util.c | 5 ++- xevents.c | 97 ++++++++++++++++++++++++++------------------------ xmalloc.c | 6 ++-- xutil.c | 28 ++++++++------- 17 files changed, 292 insertions(+), 263 deletions(-) diff --git a/calmwm.c b/calmwm.c index 9fb49ec..31d8cef 100644 --- a/calmwm.c +++ b/calmwm.c @@ -44,16 +44,14 @@ struct conf Conf; #define gray_height 2 static char gray_bits[] = {0x02, 0x01}; - static void _sigchld_cb(int); int main(int argc, char **argv) { - int ch; - const char *conf_file = NULL; - - char *display_name = NULL; + const char *conf_file = NULL; + char *display_name = NULL; + int ch; while ((ch = getopt(argc, argv, "c:d:")) != -1) { switch (ch) { @@ -110,8 +108,8 @@ main(int argc, char **argv) void x_setup(char *display_name) { - int i; - struct screen_ctx *sc; + struct screen_ctx *sc; + int i; TAILQ_INIT(&Screenq); @@ -140,13 +138,13 @@ x_setup(char *display_name) void x_setupscreen(struct screen_ctx *sc, u_int which) { - XColor tmp; - XGCValues gv; - Window *wins, w0, w1; - u_int nwins, i = 0; - XWindowAttributes winattr; - XSetWindowAttributes rootattr; - struct keybinding *kb; + XColor tmp; + XGCValues gv; + Window *wins, w0, w1; + XWindowAttributes winattr; + XSetWindowAttributes rootattr; + struct keybinding *kb; + u_int nwins, i; Curscreen = sc; @@ -247,8 +245,8 @@ x_setupscreen(struct screen_ctx *sc, u_int which) char * x_screenname(int which) { - char *cp, *dstr, *sn; - size_t snlen; + char *cp, *dstr, *sn; + size_t snlen; if (which > 9) errx(1, "Can't handle more than 9 screens. If you need it, " @@ -298,9 +296,9 @@ x_errorhandler(Display *dpy, XErrorEvent *e) static void _sigchld_cb(int which) { - pid_t pid; - int save_errno = errno; - int status; + pid_t pid; + int save_errno = errno; + int status; /* Collect dead children. */ while ((pid = waitpid(-1, &status, WNOHANG)) > 0 || @@ -313,7 +311,7 @@ _sigchld_cb(int which) __dead void usage(void) { - extern char *__progname; + extern char *__progname; fprintf(stderr, "usage: %s [-c file] [-d display]\n", __progname); exit(1); diff --git a/calmwm.h b/calmwm.h index 3844fd8..3f82c70 100644 --- a/calmwm.h +++ b/calmwm.h @@ -83,8 +83,8 @@ TAILQ_HEAD(screen_ctx_q, screen_ctx); struct winname { - TAILQ_ENTRY(winname) entry; - char *name; + TAILQ_ENTRY(winname) entry; + char *name; }; TAILQ_HEAD(winname_q, winname); diff --git a/client.c b/client.c index 92a46ca..7ddb0e9 100644 --- a/client.c +++ b/client.c @@ -36,7 +36,7 @@ client_setup(void) struct client_ctx * client_find(Window win) { - struct client_ctx *cc; + struct client_ctx *cc; TAILQ_FOREACH(cc, &Clientq, entry) if (cc->pwin == win || cc->win == win) @@ -48,12 +48,12 @@ client_find(Window win) struct client_ctx * client_new(Window win, struct screen_ctx *sc, int mapped) { - struct client_ctx *cc; - long tmp; - XSetWindowAttributes pxattr; - XWindowAttributes wattr; - int x, y, height, width, state; - XWMHints *wmhints; + struct client_ctx *cc; + XSetWindowAttributes pxattr; + XWindowAttributes wattr; + XWMHints *wmhints; + long tmp; + int x, y, height, width, state; if (win == None) return (NULL); @@ -127,7 +127,6 @@ client_new(Window win, struct screen_ctx *sc, int mapped) width += (cc->bwidth)*2; height += (cc->bwidth)*2; } - pxattr.override_redirect = True; pxattr.background_pixel = sc->bgcolor.pixel; pxattr.event_mask = ChildMask | ButtonPressMask | ButtonReleaseMask | @@ -176,8 +175,8 @@ void client_do_shape(struct client_ctx *cc) { /* Windows not rectangular require more effort */ - XRectangle *r; - int n, tmp; + XRectangle *r; + int n, tmp; if (Doshape) { XShapeSelectInput(X_Dpy, cc->win, ShapeNotifyMask); @@ -196,15 +195,15 @@ client_do_shape(struct client_ctx *cc) int client_delete(struct client_ctx *cc, int sendevent, int ignorewindow) { - struct screen_ctx *sc = CCTOSC(cc); - struct winname *wn; + struct screen_ctx *sc = CCTOSC(cc); + struct winname *wn; if (cc->state == IconicState && !sendevent) return (1); group_client_delete(cc); - XGrabServer(X_Dpy); + XGrabServer(X_Dpy); xu_setstate(cc, WithdrawnState); XRemoveFromSaveSet(X_Dpy, cc->win); @@ -245,21 +244,21 @@ client_delete(struct client_ctx *cc, int sendevent, int ignorewindow) void client_leave(struct client_ctx *cc) { - struct screen_ctx *sc; + struct screen_ctx *sc; if (cc == NULL) cc = _curcc; if (cc == NULL) return; - sc = CCTOSC(cc); + sc = CCTOSC(cc); xu_btn_ungrab(sc->rootwin, AnyModifier, Button1); } void client_setactive(struct client_ctx *cc, int fg) { - struct screen_ctx* sc; + struct screen_ctx *sc; if (cc == NULL) cc = _curcc; @@ -300,9 +299,9 @@ client_current(void) void client_gravitate(struct client_ctx *cc, int yes) { - int dx = 0, dy = 0, mult = yes ? 1 : -1; - int gravity = (cc->size->flags & PWinGravity) ? - cc->size->win_gravity : NorthWestGravity; + int dx = 0, dy = 0, mult = yes ? 1 : -1; + int gravity = (cc->size->flags & PWinGravity) ? + cc->size->win_gravity : NorthWestGravity; switch (gravity) { case NorthWestGravity: @@ -315,8 +314,8 @@ client_gravitate(struct client_ctx *cc, int yes) break; } - cc->geom.x += mult*dx; - cc->geom.y += mult*dy; + cc->geom.x += mult * dx; + cc->geom.y += mult * dy; } void @@ -388,7 +387,7 @@ client_raise(struct client_ctx *cc) void client_ptrwarp(struct client_ctx *cc) { - int x = cc->ptr.x, y = cc->ptr.y; + int x = cc->ptr.x, y = cc->ptr.y; if (x == -1 || y == -1) { x = cc->geom.width / 2; @@ -406,7 +405,7 @@ client_ptrwarp(struct client_ctx *cc) void client_ptrsave(struct client_ctx *cc) { - int x, y; + int x, y; xu_ptr_getpos(cc->pwin, &x, &y); if (_inwindowbounds(cc, x, y)) { @@ -442,7 +441,7 @@ client_unhide(struct client_ctx *cc) void client_draw_border(struct client_ctx *cc) { - struct screen_ctx *sc = CCTOSC(cc); + struct screen_ctx *sc = CCTOSC(cc); if (cc->active) { XSetWindowBackground(X_Dpy, cc->pwin, client_bg_pixel(cc)); @@ -464,8 +463,8 @@ client_draw_border(struct client_ctx *cc) u_long client_bg_pixel(struct client_ctx *cc) { - struct screen_ctx *sc = CCTOSC(cc); - u_long pixl; + struct screen_ctx *sc = CCTOSC(cc); + u_long pixl; switch (cc->highlight) { case CLIENT_HIGHLIGHT_BLUE: @@ -485,8 +484,8 @@ client_bg_pixel(struct client_ctx *cc) Pixmap client_bg_pixmap(struct client_ctx *cc) { - struct screen_ctx *sc = CCTOSC(cc); - Pixmap pix; + struct screen_ctx *sc = CCTOSC(cc); + Pixmap pix; switch (cc->highlight) { case CLIENT_HIGHLIGHT_BLUE: @@ -506,9 +505,9 @@ client_bg_pixmap(struct client_ctx *cc) void client_update(struct client_ctx *cc) { - Atom *p, wm_delete, wm_protocols, wm_take_focus; - int i; - long n; + Atom *p, wm_delete, wm_protocols, wm_take_focus; + int i; + long n; /* XXX cache these. */ wm_delete = XInternAtom(X_Dpy, "WM_DELETE_WINDOW", False); @@ -531,7 +530,7 @@ client_update(struct client_ctx *cc) void client_send_delete(struct client_ctx *cc) { - Atom wm_delete, wm_protocols; + Atom wm_delete, wm_protocols; /* XXX - cache */ wm_delete = XInternAtom(X_Dpy, "WM_DELETE_WINDOW", False); @@ -546,8 +545,8 @@ client_send_delete(struct client_ctx *cc) void client_setname(struct client_ctx *cc) { - char *newname; - struct winname *wn; + struct winname *wn; + char *newname; XFetchName(X_Dpy, cc->win, &newname); if (newname == NULL) @@ -586,10 +585,13 @@ match: struct client_ctx * client_cycle(int reverse) { - struct client_ctx *oldcc = client_current(), *newcc; - struct screen_ctx *sc = screen_current(); + struct client_ctx *oldcc, *newcc; + struct screen_ctx *sc; int again = 1; + oldcc = client_current(); + sc = screen_current(); + /* If no windows then you cant cycle */ if (TAILQ_EMPTY(&sc->mruq)) return (NULL); @@ -629,8 +631,8 @@ client_cycle(int reverse) struct client_ctx * client_mrunext(struct client_ctx *cc) { - struct screen_ctx *sc = CCTOSC(cc); - struct client_ctx *ccc; + struct screen_ctx *sc = CCTOSC(cc); + struct client_ctx *ccc; return ((ccc = TAILQ_NEXT(cc, mru_entry)) != NULL ? ccc : TAILQ_FIRST(&sc->mruq)); @@ -639,8 +641,8 @@ client_mrunext(struct client_ctx *cc) struct client_ctx * client_mruprev(struct client_ctx *cc) { - struct screen_ctx *sc = CCTOSC(cc); - struct client_ctx *ccc; + struct screen_ctx *sc = CCTOSC(cc); + struct client_ctx *ccc; return ((ccc = TAILQ_PREV(cc, cycle_entry_q, mru_entry)) != NULL ? ccc : TAILQ_LAST(&sc->mruq, cycle_entry_q)); @@ -649,16 +651,16 @@ client_mruprev(struct client_ctx *cc) void client_placecalc(struct client_ctx *cc) { - struct screen_ctx *sc = CCTOSC(cc); - int yslack, xslack, xmouse, ymouse; + struct screen_ctx *sc = CCTOSC(cc); + int yslack, xslack, xmouse, ymouse; yslack = sc->ymax - cc->geom.height - cc->bwidth; xslack = sc->xmax - cc->geom.width - cc->bwidth; xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse); - xmouse = MAX(xmouse, cc->bwidth) - cc->geom.width/2; - ymouse = MAX(ymouse, cc->bwidth) - cc->geom.height/2; + xmouse = MAX(xmouse, cc->bwidth) - cc->geom.width / 2; + ymouse = MAX(ymouse, cc->bwidth) - cc->geom.height / 2; xmouse = MAX(xmouse, (int)cc->bwidth); ymouse = MAX(ymouse, (int)cc->bwidth); @@ -700,9 +702,11 @@ client_vertmaximize(struct client_ctx *cc) if (cc->flags & CLIENT_VMAXIMIZED) { cc->geom = cc->savegeom; } else { - struct screen_ctx *sc = CCTOSC(cc); - int display_height = DisplayHeight(X_Dpy, sc->which) - - cc->bwidth*2; + struct screen_ctx *sc = CCTOSC(cc); + int display_height; + + display_height = DisplayHeight(X_Dpy, sc->which) - + cc->bwidth * 2; if (!(cc->flags & CLIENT_MAXIMIZED)) cc->savegeom = cc->geom; @@ -718,7 +722,7 @@ client_vertmaximize(struct client_ctx *cc) void client_mtf(struct client_ctx *cc) { - struct screen_ctx *sc; + struct screen_ctx *sc; if (cc == NULL) cc = _curcc; @@ -735,11 +739,11 @@ client_mtf(struct client_ctx *cc) void client_gethints(struct client_ctx *cc) { - XClassHint xch; - int argc; - char **argv; - Atom mha; - struct mwm_hints *mwmh; + XClassHint xch; + int argc; + char **argv; + Atom mha; + struct mwm_hints *mwmh; if (XGetClassHint(X_Dpy, cc->win, &xch)) { if (xch.res_name != NULL) @@ -758,9 +762,8 @@ client_gethints(struct client_ctx *cc) if (XGetCommand(X_Dpy, cc->win, &argv, &argc)) { #define MAX_ARGLEN 512 #define ARG_SEP_ " " - int len = MAX_ARGLEN; - int i, o; - char *buf; + int i, o, len = MAX_ARGLEN; + char *buf; buf = xmalloc(len); buf[0] = '\0'; diff --git a/conf.c b/conf.c index 94ea914..e586770 100644 --- a/conf.c +++ b/conf.c @@ -53,7 +53,9 @@ conf_cmd_add(struct conf *c, char *image, char *label, int flags) void conf_font(struct conf *c) { - struct screen_ctx *sc = screen_current(); + struct screen_ctx *sc; + + sc = screen_current(); c->DefaultFont = font_make(sc, Conf.DefaultFontName); c->FontHeight = font_ascent() + font_descent() + 1; @@ -62,9 +64,9 @@ conf_font(struct conf *c) int conf_changed(char *path) { - static struct timespec old_ts; - struct stat sb; - int changed; + static struct timespec old_ts; + struct stat sb; + int changed; /* If the file does not exist we pretend that nothing changed */ if (stat(path, &sb) == -1 || !(sb.st_mode & S_IFREG)) @@ -178,7 +180,7 @@ conf_init(struct conf *c) void conf_setup(struct conf *c, const char *conf_file) { - struct stat sb; + struct stat sb; if (conf_file == NULL) { char *home = getenv("HOME"); @@ -310,9 +312,9 @@ struct { void conf_bindname(struct conf *c, char *name, char *binding) { - int iter; - struct keybinding *current_binding; - char *substring; + struct keybinding *current_binding; + char *substring; + int iter; XCALLOC(current_binding, struct keybinding); @@ -356,7 +358,7 @@ conf_bindname(struct conf *c, char *name, char *binding) /* We now have the correct binding, remove duplicates. */ conf_unbind(c, current_binding); - if (strcmp("unmap",binding) == 0) + if (strcmp("unmap", binding) == 0) return; for (iter = 0; name_to_kbfunc[iter].tag != NULL; iter++) { @@ -379,7 +381,7 @@ conf_bindname(struct conf *c, char *name, char *binding) void conf_unbind(struct conf *c, struct keybinding *unbind) { - struct keybinding *key = NULL, *keynxt; + struct keybinding *key = NULL, *keynxt; for (key = TAILQ_FIRST(&c->keybindingq); key != TAILQ_END(&c->keybindingq); key = keynxt) { @@ -417,10 +419,10 @@ struct { void conf_mousebind(struct conf *c, char *name, char *binding) { - int iter; - struct mousebinding *current_binding; - char *substring; - const char *errstr; + struct mousebinding *current_binding; + char *substring; + const char *errstr; + int iter; XCALLOC(current_binding, struct mousebinding); @@ -468,7 +470,7 @@ conf_mousebind(struct conf *c, char *name, char *binding) void conf_mouseunbind(struct conf *c, struct mousebinding *unbind) { - struct mousebinding *mb = NULL, *mbnxt; + struct mousebinding *mb = NULL, *mbnxt; for (mb = TAILQ_FIRST(&c->mousebindingq); mb != TAILQ_END(&c->mousebindingq); mb = mbnxt) { @@ -492,7 +494,6 @@ conf_grab_mouse(struct client_ctx *cc) { struct mousebinding *mb; int button; - TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { if (mb->context != MOUSEBIND_CTX_WIN) diff --git a/font.c b/font.c index 85f54e5..ea200e5 100644 --- a/font.c +++ b/font.c @@ -22,7 +22,7 @@ void font_init(struct screen_ctx *sc) { - XColor xcolor, tmp; + XColor xcolor, tmp; sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which)); @@ -43,7 +43,8 @@ font_init(struct screen_ctx *sc) int font_width(const char *text, int len) { - XGlyphInfo extents; + XGlyphInfo extents; + XftTextExtents8(X_Dpy, Conf.DefaultFont, (const XftChar8*)text, len, &extents); @@ -63,9 +64,9 @@ font_draw(struct screen_ctx *sc, const char *text, int len, XftFont * font_make(struct screen_ctx *sc, const char *name) { - XftFont *fn = NULL; - FcPattern *pat, *patx; - XftResult res; + XftFont *fn = NULL; + FcPattern *pat, *patx; + XftResult res; if ((pat = FcNameParse(name)) == NULL) return (NULL); diff --git a/grab.c b/grab.c index 9cc1ec6..2a7f7df 100644 --- a/grab.c +++ b/grab.c @@ -29,10 +29,10 @@ static int _sweepcalc(struct client_ctx *, int, int, int, int); void grab_sweep_draw(struct client_ctx *cc, int dx, int dy) { - struct screen_ctx *sc = CCTOSC(cc); - int x0 = cc->geom.x, y0 = cc->geom.y; - char asize[10]; /* fits "nnnnxnnnn\0" */ - int wide, height, wide_size, wide_name; + struct screen_ctx *sc = CCTOSC(cc); + char asize[10]; /* fits "nnnnxnnnn\0" */ + int wide, height, wide_size, wide_name; + int x = cc->geom.x, y = cc->geom.y; snprintf(asize, sizeof(asize), "%dx%d", ADJUST_WIDTH(cc, dx), ADJUST_HEIGHT(cc, dy)); @@ -41,23 +41,22 @@ grab_sweep_draw(struct client_ctx *cc, int dx, int dy) wide = MAX(wide_size, wide_name); height = font_ascent() + font_descent() + 1; - XMoveResizeWindow(X_Dpy, sc->menuwin, x0, y0, wide, height * 2); + XMoveResizeWindow(X_Dpy, sc->menuwin, x, y, wide, height * 2); XMapWindow(X_Dpy, sc->menuwin); XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); XClearWindow(X_Dpy, sc->menuwin); font_draw(sc, cc->name, strlen(cc->name), sc->menuwin, 2, font_ascent() + 1); font_draw(sc, asize, strlen(asize), sc->menuwin, - wide/2 - wide_size/2, height + font_ascent() + 1); + wide / 2 - wide_size / 2, height + font_ascent() + 1); } void grab_sweep(struct client_ctx *cc) { - XEvent ev; - struct screen_ctx *sc = CCTOSC(cc); - int x0 = cc->geom.x, y0 = cc->geom.y; - int dx, dy; + XEvent ev; + struct screen_ctx *sc = CCTOSC(cc); + int x = cc->geom.x, y = cc->geom.y, dx, dy; dx = MAX(1, cc->size->width_inc); dy = MAX(1, cc->size->height_inc); @@ -80,7 +79,7 @@ grab_sweep(struct client_ctx *cc) client_draw_border(cc); break; case MotionNotify: - if (_sweepcalc(cc, x0, y0, ev.xmotion.x, ev.xmotion.y)) + if (_sweepcalc(cc, x, y, ev.xmotion.x, ev.xmotion.y)) /* Recompute window output */ grab_sweep_draw(cc, dx, dy); @@ -116,9 +115,9 @@ grab_sweep(struct client_ctx *cc) void grab_drag(struct client_ctx *cc) { - int x0 = cc->geom.x, y0 = cc->geom.y, xm, ym; - struct screen_ctx *sc = CCTOSC(cc); - XEvent ev; + XEvent ev; + struct screen_ctx *sc = CCTOSC(cc); + int x = cc->geom.x, y = cc->geom.y, xm, ym; client_raise(cc); @@ -135,8 +134,8 @@ grab_drag(struct client_ctx *cc) client_draw_border(cc); break; case MotionNotify: - cc->geom.x = x0 + (ev.xmotion.x - xm); - cc->geom.y = y0 + (ev.xmotion.y - ym); + cc->geom.x = x + (ev.xmotion.x - xm); + cc->geom.y = y + (ev.xmotion.y - ym); XMoveWindow(X_Dpy, cc->pwin, cc->geom.x - cc->bwidth, cc->geom.y - cc->bwidth); @@ -151,15 +150,15 @@ grab_drag(struct client_ctx *cc) } static int -_sweepcalc(struct client_ctx *cc, int x0, int y0, int motionx, int motiony) +_sweepcalc(struct client_ctx *cc, int x, int y, int motionx, int motiony) { - int width, height; + int width, height; width = cc->geom.width; height = cc->geom.height; - cc->geom.width = abs(x0 - motionx); - cc->geom.height = abs(y0 - motiony); + cc->geom.width = abs(x - motionx); + cc->geom.height = abs(y - motiony); if (cc->size->flags & PResizeInc) { cc->geom.width -= @@ -178,8 +177,8 @@ _sweepcalc(struct client_ctx *cc, int x0, int y0, int motionx, int motiony) cc->geom.height = MIN(cc->geom.height, cc->size->max_height); } - cc->geom.x = x0 <= motionx ? x0 : x0 - cc->geom.width; - cc->geom.y = y0 <= motiony ? y0 : y0 - cc->geom.height; + cc->geom.x = x <= motionx ? x : x - cc->geom.width; + cc->geom.y = y <= motiony ? y : y - cc->geom.height; return (width != cc->geom.width || height != cc->geom.height); } diff --git a/group.c b/group.c index ee6af0a..c44b80f 100644 --- a/group.c +++ b/group.c @@ -58,7 +58,7 @@ _group_remove(struct client_ctx *cc) static void _group_hide(struct group_ctx *gc) { - struct client_ctx *cc; + struct client_ctx *cc; screen_updatestackingorder(); @@ -76,10 +76,10 @@ _group_hide(struct group_ctx *gc) static void _group_show(struct group_ctx *gc) { - struct client_ctx *cc; - Window *winlist; - u_int i; - int lastempty = -1; + struct client_ctx *cc; + Window *winlist; + u_int i; + int lastempty = -1; winlist = (Window *) xcalloc(sizeof(*winlist), (gc->highstack + 1)); @@ -113,7 +113,7 @@ _group_show(struct group_ctx *gc) void group_init(void) { - int i; + int i; TAILQ_INIT(&Groupq); @@ -133,7 +133,9 @@ group_init(void) void group_sticky_toggle_enter(struct client_ctx *cc) { - struct group_ctx *gc = Group_active; + struct group_ctx *gc; + + gc = Group_active; if (gc == cc->group) { _group_remove(cc); @@ -162,8 +164,8 @@ group_sticky_toggle_exit(struct client_ctx *cc) void _group_fix_hidden_state(struct group_ctx *gc) { - struct client_ctx *cc; - int same = 0; + struct client_ctx *cc; + int same = 0; TAILQ_FOREACH(cc, &gc->clients, group_entry) { if (gc->hidden == ((cc->flags & CLIENT_HIDDEN) ? 1 : 0)) @@ -177,7 +179,7 @@ _group_fix_hidden_state(struct group_ctx *gc) void group_hidetoggle(int idx) { - struct group_ctx *gc; + struct group_ctx *gc; if (idx < 0 || idx >= CALMWM_NGROUPS) err(1, "group_hidetoggle: index out of range (%d)", idx); @@ -201,11 +203,10 @@ group_hidetoggle(int idx) void group_cycle(int reverse) { - struct group_ctx *gc, *showgroup = NULL; + struct group_ctx *gc, *showgroup = NULL; assert(Group_active != NULL); - gc = Group_active; for (;;) { gc = reverse ? TAILQ_PREV(gc, group_ctx_q, entry) : TAILQ_NEXT(gc, entry); @@ -246,10 +247,10 @@ group_client_delete(struct client_ctx *cc) void group_menu(XButtonEvent *e) { - struct menu_q menuq; + struct group_ctx *gc; struct menu *mi; + struct menu_q menuq; int i; - struct group_ctx *gc; TAILQ_INIT(&menuq); @@ -295,7 +296,7 @@ cleanup: void group_alltoggle(void) { - int i; + int i; for (i = 0; i < CALMWM_NGROUPS; i++) { if (Grouphideall) @@ -313,9 +314,9 @@ group_alltoggle(void) void group_autogroup(struct client_ctx *cc) { - struct autogroupwin *aw; - struct group_ctx *gc; - char group[CALMWM_MAXNAMELEN]; + struct autogroupwin *aw; + struct group_ctx *gc; + char group[CALMWM_MAXNAMELEN]; if (cc->app_class == NULL || cc->app_name == NULL) return; diff --git a/input.c b/input.c index 8d1649c..b94c968 100644 --- a/input.c +++ b/input.c @@ -24,7 +24,7 @@ int input_keycodetrans(KeyCode kc, u_int state, enum ctltype *ctl, char *chr) { - int ks; + int ks; *ctl = CTL_NONE; *chr = '\0'; diff --git a/kbfunc.c b/kbfunc.c index afea8aa..e52d7e5 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -46,10 +46,11 @@ kbfunc_client_raise(struct client_ctx *cc, void *arg) void kbfunc_moveresize(struct client_ctx *cc, void *arg) { - struct screen_ctx *sc = screen_current(); + struct screen_ctx *sc; int x, y, flags, amt; u_int mx, my; + sc = screen_current(); mx = my = 0; flags = (int)arg; @@ -121,15 +122,16 @@ kbfunc_moveresize(struct client_ctx *cc, void *arg) default: warnx("invalid flags passed to kbfunc_client_moveresize"); } - } void kbfunc_client_search(struct client_ctx *scratch, void *arg) { - struct menu_q menuq; - struct client_ctx *cc, *old_cc = client_current(); + struct client_ctx *cc, *old_cc; struct menu *mi; + struct menu_q menuq; + + old_cc = client_current(); TAILQ_INIT(&menuq); @@ -160,9 +162,9 @@ kbfunc_client_search(struct client_ctx *scratch, void *arg) void kbfunc_menu_search(struct client_ctx *scratch, void *arg) { - struct menu_q menuq; - struct menu *mi; struct cmd *cmd; + struct menu *mi; + struct menu_q menuq; TAILQ_INIT(&menuq); @@ -187,7 +189,9 @@ kbfunc_menu_search(struct client_ctx *scratch, void *arg) void kbfunc_client_cycle(struct client_ctx *scratch, void *arg) { - struct screen_ctx *sc = screen_current(); + struct screen_ctx *sc; + + sc = screen_current(); /* XXX for X apps that ignore events */ XGrabKeyboard(X_Dpy, sc->rootwin, True, @@ -226,16 +230,16 @@ void kbfunc_exec(struct client_ctx *scratch, void *arg) { #define NPATHS 256 - char **ap, *paths[NPATHS], *path, *pathcpy, tpath[MAXPATHLEN]; - int l, i, j, ngroups; - gid_t mygroups[NGROUPS_MAX]; - uid_t ruid, euid, suid; - DIR *dirp; - struct dirent *dp; - struct stat sb; - struct menu_q menuq; - struct menu *mi; - char *label; + char **ap, *paths[NPATHS], *path, *pathcpy, *label; + char tpath[MAXPATHLEN]; + int l, i, j, ngroups; + gid_t mygroups[NGROUPS_MAX]; + uid_t ruid, euid, suid; + DIR *dirp; + struct dirent *dp; + struct menu *mi; + struct menu_q menuq; + struct stat sb; int cmd = (int)arg; switch (cmd) { @@ -308,7 +312,7 @@ kbfunc_exec(struct client_ctx *scratch, void *arg) strlcpy(mi->text, dp->d_name, sizeof(mi->text)); TAILQ_INSERT_TAIL(&menuq, mi, entry); } - (void) closedir(dirp); + (void)closedir(dirp); } xfree(path); @@ -339,13 +343,14 @@ kbfunc_exec(struct client_ctx *scratch, void *arg) void kbfunc_ssh(struct client_ctx *scratch, void *arg) { - struct menu_q menuq; - struct menu *mi; - FILE *fp; - size_t len; - char *buf, *lbuf, *p, *home; - char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN], cmd[256]; - int l; + struct menu *mi; + struct menu_q menuq; + FILE *fp; + char *buf, *lbuf, *p, *home; + char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN]; + char cmd[256]; + int l; + size_t len; if ((home = getenv("HOME")) == NULL) return; @@ -386,7 +391,6 @@ kbfunc_ssh(struct client_ctx *scratch, void *arg) xfree(lbuf); fclose(fp); - if ((mi = menu_filter(&menuq, "ssh", NULL, 1, search_match_exec, NULL)) != NULL) { conf_reload(&Conf); @@ -408,8 +412,8 @@ void kbfunc_client_label(struct client_ctx *cc, void *arg) { struct menu *mi; - char *current; struct menu_q menuq; + char *current; TAILQ_INIT(&menuq); diff --git a/menu.c b/menu.c index 6db9a53..5b60b67 100644 --- a/menu.c +++ b/menu.c @@ -67,7 +67,7 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy, void (*match)(struct menu_q *, struct menu_q *, char *), void (*print)(struct menu *, int)) { - struct screen_ctx *sc = screen_current(); + struct screen_ctx *sc; struct menu_ctx mc; struct menu_q resultq; struct menu *mi = NULL; @@ -75,6 +75,8 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy, Window focuswin; int Mask, focusrevert; + sc = screen_current(); + TAILQ_INIT(&resultq); bzero(&mc, sizeof(mc)); @@ -255,10 +257,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) { struct menu *mi; - int n = 0; - int dy; - int xsave, ysave; - int warp; + int n, dy, xsave, ysave; if (mc->list) { if (TAILQ_EMPTY(resultq) && mc->list) { @@ -388,10 +387,12 @@ menu_handle_release(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc, static int menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y) { - int entry = y / font_height(); + int entry; + + entry = y / font_height(); /* in bounds? */ - if (x < 0 || x > mc->width || y < 0 || y > font_height()*mc->num || + if (x < 0 || x > mc->width || y < 0 || y > font_height() * mc->num || entry < 0 || entry >= mc->num) entry = -1; diff --git a/mousefunc.c b/mousefunc.c index af331d5..e7efacd 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -63,10 +63,12 @@ mousefunc_menu_group(struct client_ctx *cc, void *arg) void mousefunc_menu_unhide(struct client_ctx *cc, void *arg) { - struct menu *mi; - struct menu_q menuq; - char *wname; - struct client_ctx *old_cc = client_current(); + struct client_ctx *old_cc; + struct menu *mi; + struct menu_q menuq; + char *wname; + + old_cc = client_current(); TAILQ_INIT(&menuq); TAILQ_FOREACH(cc, &Clientq, entry) @@ -96,19 +98,21 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg) if (old_cc != NULL) client_ptrsave(old_cc); client_ptrwarp(cc); - } else + } else { while ((mi = TAILQ_FIRST(&menuq)) != NULL) { TAILQ_REMOVE(&menuq, mi, entry); xfree(mi); } + } } void mousefunc_menu_cmd(struct client_ctx *cc, void *arg) { - struct menu *mi; - struct menu_q menuq; - struct cmd *cmd; + struct menu *mi; + struct menu_q menuq; + struct cmd *cmd; + conf_reload(&Conf); TAILQ_INIT(&menuq); diff --git a/screen.c b/screen.c index 02d92b2..6ab0471 100644 --- a/screen.c +++ b/screen.c @@ -27,7 +27,7 @@ extern struct screen_ctx *Curscreen; struct screen_ctx * screen_fromroot(Window rootwin) { - struct screen_ctx *sc; + struct screen_ctx *sc; TAILQ_FOREACH(sc, &Screenq, entry) if (sc->rootwin == rootwin) @@ -46,10 +46,12 @@ screen_current(void) void screen_updatestackingorder(void) { - Window *wins, w0, w1; - struct screen_ctx *sc = screen_current(); - u_int nwins, i, s; - struct client_ctx *cc; + Window *wins, w0, w1; + struct screen_ctx *sc; + struct client_ctx *cc; + u_int nwins, i, s; + + sc = screen_current(); if (!XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins)) return; diff --git a/search.c b/search.c index ac108d9..c09a010 100644 --- a/search.c +++ b/search.c @@ -31,9 +31,11 @@ static int _strsubmatch(char *, char *, int); void search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) { - struct winname *wn; - struct menu *mi, *tierp[4], *before = NULL; - int ntiers = sizeof(tierp)/sizeof(tierp[0]); + struct winname *wn; + struct menu *mi, *tierp[4], *before = NULL; + int ntiers; + + ntiers = sizeof(tierp) / sizeof(tierp[0]); TAILQ_INIT(resultq); @@ -119,8 +121,10 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) void search_print_client(struct menu *mi, int list) { - struct client_ctx *cc = mi->ctx; - char flag = ' '; + struct client_ctx *cc; + char flag = ' '; + + cc = mi->ctx; if (cc == client_current()) flag = '!'; @@ -134,9 +138,11 @@ search_print_client(struct menu *mi, int list) if (!list && cc->matchname != cc->name && strlen(mi->print) < sizeof(mi->print) - 1) { - int diff = sizeof(mi->print) - 1 - strlen(mi->print); - const char *marker = ""; - char buf[MENU_MAXENTRY + 1]; + const char *marker = ""; + char buf[MENU_MAXENTRY + 1]; + int diff; + + diff = sizeof(mi->print) - 1 - strlen(mi->print); /* One for the ':' */ diff -= 1; @@ -157,7 +163,7 @@ search_print_client(struct menu *mi, int list) void search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search) { - struct menu *mi; + struct menu *mi; TAILQ_INIT(resultq); @@ -169,7 +175,7 @@ search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search) void search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search) { - struct menu *mi; + struct menu *mi; TAILQ_INIT(resultq); @@ -181,8 +187,8 @@ search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search) static int _strsubmatch(char *sub, char *str, int zeroidx) { - size_t len, sublen; - u_int n, flen; + size_t len, sublen; + u_int n, flen; if (sub == NULL || str == NULL) return (0); @@ -197,6 +203,7 @@ _strsubmatch(char *sub, char *str, int zeroidx) flen = len - sublen; else flen = 0; + for (n = 0; n <= flen; n++) if (strncasecmp(sub, str + n, sublen) == 0) return (1); diff --git a/util.c b/util.c index f7ef353..ac7e2f4 100644 --- a/util.c +++ b/util.c @@ -44,9 +44,8 @@ u_spawn(char *argstr) void u_exec(char *argstr) { - char *args[MAXARGLEN], **ap = args; - char **end = &args[MAXARGLEN - 1]; - char *tmp; + char *args[MAXARGLEN], **ap = args; + char **end = &args[MAXARGLEN - 1], *tmp; while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL) { if (**ap == '\0') diff --git a/xevents.c b/xevents.c index 0dbf99a..0da23d7 100644 --- a/xevents.c +++ b/xevents.c @@ -35,15 +35,16 @@ void xev_handle_maprequest(struct xevent *xev, XEvent *ee) { - XMapRequestEvent *e = &ee->xmaprequest; - struct client_ctx *cc = NULL, *old_cc = client_current(); - XWindowAttributes xattr; - struct screen_ctx *sc; + XMapRequestEvent *e = &ee->xmaprequest; + XWindowAttributes xattr; + struct client_ctx *cc = NULL, *old_cc; + struct screen_ctx *sc; + #ifdef notyet int state; #endif - if (old_cc != NULL) + if ((old_cc = client_current()) != NULL) client_ptrsave(old_cc); if ((cc = client_find(e->window)) == NULL) { @@ -66,8 +67,8 @@ xev_handle_maprequest(struct xevent *xev, XEvent *ee) void xev_handle_unmapnotify(struct xevent *xev, XEvent *ee) { - XUnmapEvent *e = &ee->xunmap; - struct client_ctx *cc; + XUnmapEvent *e = &ee->xunmap; + struct client_ctx *cc; if ((cc = client_find(e->window)) != NULL) client_delete(cc, e->send_event, 0); @@ -78,8 +79,8 @@ xev_handle_unmapnotify(struct xevent *xev, XEvent *ee) void xev_handle_destroynotify(struct xevent *xev, XEvent *ee) { - XDestroyWindowEvent *e = &ee->xdestroywindow; - struct client_ctx *cc; + XDestroyWindowEvent *e = &ee->xdestroywindow; + struct client_ctx *cc; if ((cc = client_find(e->window)) != NULL) client_delete(cc, 1, 1); @@ -90,10 +91,10 @@ xev_handle_destroynotify(struct xevent *xev, XEvent *ee) void xev_handle_configurerequest(struct xevent *xev, XEvent *ee) { - XConfigureRequestEvent *e = &ee->xconfigurerequest; - struct client_ctx *cc; - struct screen_ctx *sc; - XWindowChanges wc; + XConfigureRequestEvent *e = &ee->xconfigurerequest; + struct client_ctx *cc; + struct screen_ctx *sc; + XWindowChanges wc; if ((cc = client_find(e->window)) != NULL) { sc = CCTOSC(cc); @@ -146,9 +147,9 @@ xev_handle_configurerequest(struct xevent *xev, XEvent *ee) void xev_handle_propertynotify(struct xevent *xev, XEvent *ee) { - XPropertyEvent *e = &ee->xproperty; - struct client_ctx *cc; - long tmp; + XPropertyEvent *e = &ee->xproperty; + struct client_ctx *cc; + long tmp; if ((cc = client_find(e->window)) != NULL) { switch (e->atom) { @@ -170,7 +171,7 @@ xev_handle_propertynotify(struct xevent *xev, XEvent *ee) void xev_reconfig(struct client_ctx *cc) { - XConfigureEvent ce; + XConfigureEvent ce; ce.type = ConfigureNotify; ce.event = cc->win; @@ -189,8 +190,8 @@ xev_reconfig(struct client_ctx *cc) void xev_handle_enternotify(struct xevent *xev, XEvent *ee) { - XCrossingEvent *e = &ee->xcrossing; - struct client_ctx *cc; + XCrossingEvent *e = &ee->xcrossing; + struct client_ctx *cc; if ((cc = client_find(e->window)) == NULL) { /* @@ -222,10 +223,11 @@ xev_handle_buttonpress(struct xevent *xev, XEvent *ee) { XButtonEvent *e = &ee->xbutton; struct client_ctx *cc; - struct screen_ctx *sc = screen_fromroot(e->root); + struct screen_ctx *sc; struct mousebinding *mb; char *wname; + sc = screen_fromroot(e->root); cc = client_find(e->window); /* Ignore caps lock and numlock */ @@ -256,9 +258,9 @@ out: void xev_handle_buttonrelease(struct xevent *xev, XEvent *ee) { - struct client_ctx *cc = client_current(); + struct client_ctx *cc; - if (cc != NULL) + if ((cc = client_current()) != NULL) group_sticky_toggle_exit(cc); xev_register(xev); @@ -267,11 +269,11 @@ xev_handle_buttonrelease(struct xevent *xev, XEvent *ee) void xev_handle_keypress(struct xevent *xev, XEvent *ee) { - XKeyEvent *e = &ee->xkey; - struct client_ctx *cc = NULL; /* Make gcc happy. */ - struct keybinding *kb; - KeySym keysym, skeysym; - int modshift; + XKeyEvent *e = &ee->xkey; + struct client_ctx *cc = NULL; + struct keybinding *kb; + KeySym keysym, skeysym; + int modshift; keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0); skeysym = XKeycodeToKeysym(X_Dpy, e->keycode, 1); @@ -315,10 +317,13 @@ out: void xev_handle_keyrelease(struct xevent *xev, XEvent *ee) { - XKeyEvent *e = &ee->xkey; - struct screen_ctx *sc = screen_fromroot(e->root); - struct client_ctx *cc = client_current(); - int keysym; + XKeyEvent *e = &ee->xkey; + struct screen_ctx *sc; + struct client_ctx *cc; + int keysym; + + sc = screen_fromroot(e->root); + cc = client_current(); keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0); if (keysym != XK_Alt_L && keysym != XK_Alt_R) @@ -344,11 +349,13 @@ out: void xev_handle_clientmessage(struct xevent *xev, XEvent *ee) { - XClientMessageEvent *e = &ee->xclient; - struct client_ctx *cc = client_find(e->window); - Atom xa_wm_change_state = XInternAtom(X_Dpy, "WM_CHANGE_STATE", False); + XClientMessageEvent *e = &ee->xclient; + Atom xa_wm_change_state; + struct client_ctx *cc; - if (cc == NULL) + xa_wm_change_state = XInternAtom(X_Dpy, "WM_CHANGE_STATE", False); + + if ((cc = client_find(e->window)) == NULL) goto out; if (e->message_type == xa_wm_change_state && e->format == 32 && @@ -361,8 +368,8 @@ out: void xev_handle_shape(struct xevent *xev, XEvent *ee) { - XShapeEvent *sev = (XShapeEvent *) ee; - struct client_ctx *cc; + XShapeEvent *sev = (XShapeEvent *) ee; + struct client_ctx *cc; if ((cc = client_find(sev->window)) != NULL) client_do_shape(cc); @@ -387,7 +394,7 @@ struct xevent * xev_new(Window *win, Window *root, int type, void (*cb)(struct xevent *, XEvent *), void *arg) { - struct xevent *xev; + struct xevent *xev; XMALLOC(xev, struct xevent); xev->xev_win = win; @@ -402,7 +409,7 @@ xev_new(Window *win, Window *root, void xev_register(struct xevent *xev) { - struct xevent_q *xq; + struct xevent_q *xq; xq = _xev_q_lock ? &_xevq_putaway : &_xevq; TAILQ_INSERT_TAIL(xq, xev, entry); @@ -411,7 +418,7 @@ xev_register(struct xevent *xev) void _xev_reincorporate(void) { - struct xevent *xev; + struct xevent *xev; while ((xev = TAILQ_FIRST(&_xevq_putaway)) != NULL) { TAILQ_REMOVE(&_xevq_putaway, xev, entry); @@ -422,8 +429,8 @@ _xev_reincorporate(void) void xev_handle_expose(struct xevent *xev, XEvent *ee) { - XExposeEvent *e = &ee->xexpose; - struct client_ctx *cc; + XExposeEvent *e = &ee->xexpose; + struct client_ctx *cc; if ((cc = client_find(e->window)) != NULL && e->count == 0) { client_draw_border(cc); @@ -445,10 +452,10 @@ xev_handle_expose(struct xevent *xev, XEvent *ee) void xev_loop(void) { - Window win, root; + Window win, root; + XEvent e; + struct xevent *xev = NULL, *nextxev; int type; - XEvent e; - struct xevent *xev, *nextxev; while (_xev_quit == 0) { #ifdef DIAGNOSTIC diff --git a/xmalloc.c b/xmalloc.c index 71bc5a4..8935754 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -24,7 +24,7 @@ void * xmalloc(size_t siz) { - void *p; + void *p; if ((p = malloc(siz)) == NULL) err(1, "malloc"); @@ -35,7 +35,7 @@ xmalloc(size_t siz) void * xcalloc(size_t no, size_t siz) { - void *p; + void *p; if ((p = calloc(no, siz)) == NULL) err(1, "calloc"); @@ -52,7 +52,7 @@ xfree(void *p) char * xstrdup(const char *str) { - char *p; + char *p; if ((p = strdup(str)) == NULL) err(1, "strdup"); diff --git a/xutil.c b/xutil.c index 0c60fa6..2c6ad65 100644 --- a/xutil.c +++ b/xutil.c @@ -65,9 +65,9 @@ xu_btn_ungrab(Window win, int mask, u_int btn) void xu_ptr_getpos(Window rootwin, int *x, int *y) { - int tmp0, tmp1; - u_int tmp2; - Window w0, w1; + Window w0, w1; + int tmp0, tmp1; + u_int tmp2; XQueryPointer(X_Dpy, rootwin, &w0, &w1, &tmp0, &tmp1, x, y, &tmp2); } @@ -81,8 +81,8 @@ xu_ptr_setpos(Window win, int x, int y) void xu_key_grab(Window win, int mask, int keysym) { - KeyCode code; - int i; + KeyCode code; + int i; code = XKeysymToKeycode(X_Dpy, keysym); if ((XKeycodeToKeysym(X_Dpy, code, 0) != keysym) && @@ -98,7 +98,7 @@ xu_key_grab(Window win, int mask, int keysym) void xu_sendmsg(struct client_ctx *cc, Atom atm, long val) { - XEvent e; + XEvent e; memset(&e, 0, sizeof(e)); e.xclient.type = ClientMessage; @@ -114,9 +114,9 @@ xu_sendmsg(struct client_ctx *cc, Atom atm, long val) int xu_getprop(struct client_ctx *cc, Atom atm, Atom type, long len, u_char **p) { - Atom realtype; - u_long n, extra; - int format; + Atom realtype; + u_long n, extra; + int format; if (XGetWindowProperty(X_Dpy, cc->win, atm, 0L, len, False, type, &realtype, &format, &n, &extra, p) != Success || *p == NULL) @@ -131,8 +131,10 @@ xu_getprop(struct client_ctx *cc, Atom atm, Atom type, long len, u_char **p) int xu_getstate(struct client_ctx *cc, int *state) { - Atom wm_state = XInternAtom(X_Dpy, "WM_STATE", False); - long *p = NULL; + Atom wm_state; + long *p = NULL; + + wm_state = XInternAtom(X_Dpy, "WM_STATE", False); if (xu_getprop(cc, wm_state, wm_state, 2L, (u_char **)&p) <= 0) return (-1); @@ -146,8 +148,8 @@ xu_getstate(struct client_ctx *cc, int *state) void xu_setstate(struct client_ctx *cc, int state) { - long dat[2]; - Atom wm_state; + Atom wm_state; + long dat[2]; /* XXX cache */ wm_state = XInternAtom(X_Dpy, "WM_STATE", False); -- cgit 1.4.1