spacing, declaration lineup to be consistent throughout cwm,

readability, and a bit of knf.

ok oga@
This commit is contained in:
okan 2008-07-11 14:21:28 +00:00
parent 734f45ab4b
commit b23fad3987
17 changed files with 293 additions and 264 deletions

View File

@ -44,16 +44,14 @@ struct conf Conf;
#define gray_height 2 #define gray_height 2
static char gray_bits[] = {0x02, 0x01}; static char gray_bits[] = {0x02, 0x01};
static void _sigchld_cb(int); static void _sigchld_cb(int);
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int ch; const char *conf_file = NULL;
const char *conf_file = NULL; char *display_name = NULL;
int ch;
char *display_name = NULL;
while ((ch = getopt(argc, argv, "c:d:")) != -1) { while ((ch = getopt(argc, argv, "c:d:")) != -1) {
switch (ch) { switch (ch) {
@ -110,8 +108,8 @@ main(int argc, char **argv)
void void
x_setup(char *display_name) x_setup(char *display_name)
{ {
int i; struct screen_ctx *sc;
struct screen_ctx *sc; int i;
TAILQ_INIT(&Screenq); TAILQ_INIT(&Screenq);
@ -140,13 +138,13 @@ x_setup(char *display_name)
void void
x_setupscreen(struct screen_ctx *sc, u_int which) x_setupscreen(struct screen_ctx *sc, u_int which)
{ {
XColor tmp; XColor tmp;
XGCValues gv; XGCValues gv;
Window *wins, w0, w1; Window *wins, w0, w1;
u_int nwins, i = 0; XWindowAttributes winattr;
XWindowAttributes winattr; XSetWindowAttributes rootattr;
XSetWindowAttributes rootattr; struct keybinding *kb;
struct keybinding *kb; u_int nwins, i;
Curscreen = sc; Curscreen = sc;
@ -247,8 +245,8 @@ x_setupscreen(struct screen_ctx *sc, u_int which)
char * char *
x_screenname(int which) x_screenname(int which)
{ {
char *cp, *dstr, *sn; char *cp, *dstr, *sn;
size_t snlen; size_t snlen;
if (which > 9) if (which > 9)
errx(1, "Can't handle more than 9 screens. If you need it, " 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 static void
_sigchld_cb(int which) _sigchld_cb(int which)
{ {
pid_t pid; pid_t pid;
int save_errno = errno; int save_errno = errno;
int status; int status;
/* Collect dead children. */ /* Collect dead children. */
while ((pid = waitpid(-1, &status, WNOHANG)) > 0 || while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
@ -313,7 +311,7 @@ _sigchld_cb(int which)
__dead void __dead void
usage(void) usage(void)
{ {
extern char *__progname; extern char *__progname;
fprintf(stderr, "usage: %s [-c file] [-d display]\n", __progname); fprintf(stderr, "usage: %s [-c file] [-d display]\n", __progname);
exit(1); exit(1);

View File

@ -83,8 +83,8 @@ TAILQ_HEAD(screen_ctx_q, screen_ctx);
struct winname { struct winname {
TAILQ_ENTRY(winname) entry; TAILQ_ENTRY(winname) entry;
char *name; char *name;
}; };
TAILQ_HEAD(winname_q, winname); TAILQ_HEAD(winname_q, winname);

115
client.c
View File

@ -36,7 +36,7 @@ client_setup(void)
struct client_ctx * struct client_ctx *
client_find(Window win) client_find(Window win)
{ {
struct client_ctx *cc; struct client_ctx *cc;
TAILQ_FOREACH(cc, &Clientq, entry) TAILQ_FOREACH(cc, &Clientq, entry)
if (cc->pwin == win || cc->win == win) if (cc->pwin == win || cc->win == win)
@ -48,12 +48,12 @@ client_find(Window win)
struct client_ctx * struct client_ctx *
client_new(Window win, struct screen_ctx *sc, int mapped) client_new(Window win, struct screen_ctx *sc, int mapped)
{ {
struct client_ctx *cc; struct client_ctx *cc;
long tmp; XSetWindowAttributes pxattr;
XSetWindowAttributes pxattr; XWindowAttributes wattr;
XWindowAttributes wattr; XWMHints *wmhints;
int x, y, height, width, state; long tmp;
XWMHints *wmhints; int x, y, height, width, state;
if (win == None) if (win == None)
return (NULL); return (NULL);
@ -127,7 +127,6 @@ client_new(Window win, struct screen_ctx *sc, int mapped)
width += (cc->bwidth)*2; width += (cc->bwidth)*2;
height += (cc->bwidth)*2; height += (cc->bwidth)*2;
} }
pxattr.override_redirect = True; pxattr.override_redirect = True;
pxattr.background_pixel = sc->bgcolor.pixel; pxattr.background_pixel = sc->bgcolor.pixel;
pxattr.event_mask = ChildMask | ButtonPressMask | ButtonReleaseMask | pxattr.event_mask = ChildMask | ButtonPressMask | ButtonReleaseMask |
@ -176,8 +175,8 @@ void
client_do_shape(struct client_ctx *cc) client_do_shape(struct client_ctx *cc)
{ {
/* Windows not rectangular require more effort */ /* Windows not rectangular require more effort */
XRectangle *r; XRectangle *r;
int n, tmp; int n, tmp;
if (Doshape) { if (Doshape) {
XShapeSelectInput(X_Dpy, cc->win, ShapeNotifyMask); XShapeSelectInput(X_Dpy, cc->win, ShapeNotifyMask);
@ -196,15 +195,15 @@ client_do_shape(struct client_ctx *cc)
int int
client_delete(struct client_ctx *cc, int sendevent, int ignorewindow) client_delete(struct client_ctx *cc, int sendevent, int ignorewindow)
{ {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
struct winname *wn; struct winname *wn;
if (cc->state == IconicState && !sendevent) if (cc->state == IconicState && !sendevent)
return (1); return (1);
group_client_delete(cc); group_client_delete(cc);
XGrabServer(X_Dpy);
XGrabServer(X_Dpy);
xu_setstate(cc, WithdrawnState); xu_setstate(cc, WithdrawnState);
XRemoveFromSaveSet(X_Dpy, cc->win); XRemoveFromSaveSet(X_Dpy, cc->win);
@ -245,21 +244,21 @@ client_delete(struct client_ctx *cc, int sendevent, int ignorewindow)
void void
client_leave(struct client_ctx *cc) client_leave(struct client_ctx *cc)
{ {
struct screen_ctx *sc; struct screen_ctx *sc;
if (cc == NULL) if (cc == NULL)
cc = _curcc; cc = _curcc;
if (cc == NULL) if (cc == NULL)
return; return;
sc = CCTOSC(cc);
sc = CCTOSC(cc);
xu_btn_ungrab(sc->rootwin, AnyModifier, Button1); xu_btn_ungrab(sc->rootwin, AnyModifier, Button1);
} }
void void
client_setactive(struct client_ctx *cc, int fg) client_setactive(struct client_ctx *cc, int fg)
{ {
struct screen_ctx* sc; struct screen_ctx *sc;
if (cc == NULL) if (cc == NULL)
cc = _curcc; cc = _curcc;
@ -300,9 +299,9 @@ client_current(void)
void void
client_gravitate(struct client_ctx *cc, int yes) client_gravitate(struct client_ctx *cc, int yes)
{ {
int dx = 0, dy = 0, mult = yes ? 1 : -1; int dx = 0, dy = 0, mult = yes ? 1 : -1;
int gravity = (cc->size->flags & PWinGravity) ? int gravity = (cc->size->flags & PWinGravity) ?
cc->size->win_gravity : NorthWestGravity; cc->size->win_gravity : NorthWestGravity;
switch (gravity) { switch (gravity) {
case NorthWestGravity: case NorthWestGravity:
@ -315,8 +314,8 @@ client_gravitate(struct client_ctx *cc, int yes)
break; break;
} }
cc->geom.x += mult*dx; cc->geom.x += mult * dx;
cc->geom.y += mult*dy; cc->geom.y += mult * dy;
} }
void void
@ -388,7 +387,7 @@ client_raise(struct client_ctx *cc)
void void
client_ptrwarp(struct client_ctx *cc) 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) { if (x == -1 || y == -1) {
x = cc->geom.width / 2; x = cc->geom.width / 2;
@ -406,7 +405,7 @@ client_ptrwarp(struct client_ctx *cc)
void void
client_ptrsave(struct client_ctx *cc) client_ptrsave(struct client_ctx *cc)
{ {
int x, y; int x, y;
xu_ptr_getpos(cc->pwin, &x, &y); xu_ptr_getpos(cc->pwin, &x, &y);
if (_inwindowbounds(cc, x, y)) { if (_inwindowbounds(cc, x, y)) {
@ -442,7 +441,7 @@ client_unhide(struct client_ctx *cc)
void void
client_draw_border(struct client_ctx *cc) client_draw_border(struct client_ctx *cc)
{ {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
if (cc->active) { if (cc->active) {
XSetWindowBackground(X_Dpy, cc->pwin, client_bg_pixel(cc)); XSetWindowBackground(X_Dpy, cc->pwin, client_bg_pixel(cc));
@ -464,8 +463,8 @@ client_draw_border(struct client_ctx *cc)
u_long u_long
client_bg_pixel(struct client_ctx *cc) client_bg_pixel(struct client_ctx *cc)
{ {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
u_long pixl; u_long pixl;
switch (cc->highlight) { switch (cc->highlight) {
case CLIENT_HIGHLIGHT_BLUE: case CLIENT_HIGHLIGHT_BLUE:
@ -485,8 +484,8 @@ client_bg_pixel(struct client_ctx *cc)
Pixmap Pixmap
client_bg_pixmap(struct client_ctx *cc) client_bg_pixmap(struct client_ctx *cc)
{ {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
Pixmap pix; Pixmap pix;
switch (cc->highlight) { switch (cc->highlight) {
case CLIENT_HIGHLIGHT_BLUE: case CLIENT_HIGHLIGHT_BLUE:
@ -506,9 +505,9 @@ client_bg_pixmap(struct client_ctx *cc)
void void
client_update(struct client_ctx *cc) client_update(struct client_ctx *cc)
{ {
Atom *p, wm_delete, wm_protocols, wm_take_focus; Atom *p, wm_delete, wm_protocols, wm_take_focus;
int i; int i;
long n; long n;
/* XXX cache these. */ /* XXX cache these. */
wm_delete = XInternAtom(X_Dpy, "WM_DELETE_WINDOW", False); wm_delete = XInternAtom(X_Dpy, "WM_DELETE_WINDOW", False);
@ -531,7 +530,7 @@ client_update(struct client_ctx *cc)
void void
client_send_delete(struct client_ctx *cc) client_send_delete(struct client_ctx *cc)
{ {
Atom wm_delete, wm_protocols; Atom wm_delete, wm_protocols;
/* XXX - cache */ /* XXX - cache */
wm_delete = XInternAtom(X_Dpy, "WM_DELETE_WINDOW", False); wm_delete = XInternAtom(X_Dpy, "WM_DELETE_WINDOW", False);
@ -546,8 +545,8 @@ client_send_delete(struct client_ctx *cc)
void void
client_setname(struct client_ctx *cc) client_setname(struct client_ctx *cc)
{ {
char *newname; struct winname *wn;
struct winname *wn; char *newname;
XFetchName(X_Dpy, cc->win, &newname); XFetchName(X_Dpy, cc->win, &newname);
if (newname == NULL) if (newname == NULL)
@ -586,10 +585,13 @@ match:
struct client_ctx * struct client_ctx *
client_cycle(int reverse) client_cycle(int reverse)
{ {
struct client_ctx *oldcc = client_current(), *newcc; struct client_ctx *oldcc, *newcc;
struct screen_ctx *sc = screen_current(); struct screen_ctx *sc;
int again = 1; int again = 1;
oldcc = client_current();
sc = screen_current();
/* If no windows then you cant cycle */ /* If no windows then you cant cycle */
if (TAILQ_EMPTY(&sc->mruq)) if (TAILQ_EMPTY(&sc->mruq))
return (NULL); return (NULL);
@ -629,8 +631,8 @@ client_cycle(int reverse)
struct client_ctx * struct client_ctx *
client_mrunext(struct client_ctx *cc) client_mrunext(struct client_ctx *cc)
{ {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
struct client_ctx *ccc; struct client_ctx *ccc;
return ((ccc = TAILQ_NEXT(cc, mru_entry)) != NULL ? return ((ccc = TAILQ_NEXT(cc, mru_entry)) != NULL ?
ccc : TAILQ_FIRST(&sc->mruq)); ccc : TAILQ_FIRST(&sc->mruq));
@ -639,8 +641,8 @@ client_mrunext(struct client_ctx *cc)
struct client_ctx * struct client_ctx *
client_mruprev(struct client_ctx *cc) client_mruprev(struct client_ctx *cc)
{ {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
struct client_ctx *ccc; struct client_ctx *ccc;
return ((ccc = TAILQ_PREV(cc, cycle_entry_q, mru_entry)) != NULL ? return ((ccc = TAILQ_PREV(cc, cycle_entry_q, mru_entry)) != NULL ?
ccc : TAILQ_LAST(&sc->mruq, cycle_entry_q)); ccc : TAILQ_LAST(&sc->mruq, cycle_entry_q));
@ -649,16 +651,16 @@ client_mruprev(struct client_ctx *cc)
void void
client_placecalc(struct client_ctx *cc) client_placecalc(struct client_ctx *cc)
{ {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
int yslack, xslack, xmouse, ymouse; int yslack, xslack, xmouse, ymouse;
yslack = sc->ymax - cc->geom.height - cc->bwidth; yslack = sc->ymax - cc->geom.height - cc->bwidth;
xslack = sc->xmax - cc->geom.width - cc->bwidth; xslack = sc->xmax - cc->geom.width - cc->bwidth;
xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse); xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse);
xmouse = MAX(xmouse, cc->bwidth) - cc->geom.width/2; xmouse = MAX(xmouse, cc->bwidth) - cc->geom.width / 2;
ymouse = MAX(ymouse, cc->bwidth) - cc->geom.height/2; ymouse = MAX(ymouse, cc->bwidth) - cc->geom.height / 2;
xmouse = MAX(xmouse, (int)cc->bwidth); xmouse = MAX(xmouse, (int)cc->bwidth);
ymouse = MAX(ymouse, (int)cc->bwidth); ymouse = MAX(ymouse, (int)cc->bwidth);
@ -700,9 +702,11 @@ client_vertmaximize(struct client_ctx *cc)
if (cc->flags & CLIENT_VMAXIMIZED) { if (cc->flags & CLIENT_VMAXIMIZED) {
cc->geom = cc->savegeom; cc->geom = cc->savegeom;
} else { } else {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
int display_height = DisplayHeight(X_Dpy, sc->which) - int display_height;
cc->bwidth*2;
display_height = DisplayHeight(X_Dpy, sc->which) -
cc->bwidth * 2;
if (!(cc->flags & CLIENT_MAXIMIZED)) if (!(cc->flags & CLIENT_MAXIMIZED))
cc->savegeom = cc->geom; cc->savegeom = cc->geom;
@ -718,7 +722,7 @@ client_vertmaximize(struct client_ctx *cc)
void void
client_mtf(struct client_ctx *cc) client_mtf(struct client_ctx *cc)
{ {
struct screen_ctx *sc; struct screen_ctx *sc;
if (cc == NULL) if (cc == NULL)
cc = _curcc; cc = _curcc;
@ -735,11 +739,11 @@ client_mtf(struct client_ctx *cc)
void void
client_gethints(struct client_ctx *cc) client_gethints(struct client_ctx *cc)
{ {
XClassHint xch; XClassHint xch;
int argc; int argc;
char **argv; char **argv;
Atom mha; Atom mha;
struct mwm_hints *mwmh; struct mwm_hints *mwmh;
if (XGetClassHint(X_Dpy, cc->win, &xch)) { if (XGetClassHint(X_Dpy, cc->win, &xch)) {
if (xch.res_name != NULL) if (xch.res_name != NULL)
@ -758,9 +762,8 @@ client_gethints(struct client_ctx *cc)
if (XGetCommand(X_Dpy, cc->win, &argv, &argc)) { if (XGetCommand(X_Dpy, cc->win, &argv, &argc)) {
#define MAX_ARGLEN 512 #define MAX_ARGLEN 512
#define ARG_SEP_ " " #define ARG_SEP_ " "
int len = MAX_ARGLEN; int i, o, len = MAX_ARGLEN;
int i, o; char *buf;
char *buf;
buf = xmalloc(len); buf = xmalloc(len);
buf[0] = '\0'; buf[0] = '\0';

33
conf.c
View File

@ -53,7 +53,9 @@ conf_cmd_add(struct conf *c, char *image, char *label, int flags)
void void
conf_font(struct conf *c) 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->DefaultFont = font_make(sc, Conf.DefaultFontName);
c->FontHeight = font_ascent() + font_descent() + 1; c->FontHeight = font_ascent() + font_descent() + 1;
@ -62,9 +64,9 @@ conf_font(struct conf *c)
int int
conf_changed(char *path) conf_changed(char *path)
{ {
static struct timespec old_ts; static struct timespec old_ts;
struct stat sb; struct stat sb;
int changed; int changed;
/* If the file does not exist we pretend that nothing changed */ /* If the file does not exist we pretend that nothing changed */
if (stat(path, &sb) == -1 || !(sb.st_mode & S_IFREG)) if (stat(path, &sb) == -1 || !(sb.st_mode & S_IFREG))
@ -178,7 +180,7 @@ conf_init(struct conf *c)
void void
conf_setup(struct conf *c, const char *conf_file) conf_setup(struct conf *c, const char *conf_file)
{ {
struct stat sb; struct stat sb;
if (conf_file == NULL) { if (conf_file == NULL) {
char *home = getenv("HOME"); char *home = getenv("HOME");
@ -310,9 +312,9 @@ struct {
void void
conf_bindname(struct conf *c, char *name, char *binding) conf_bindname(struct conf *c, char *name, char *binding)
{ {
int iter; struct keybinding *current_binding;
struct keybinding *current_binding; char *substring;
char *substring; int iter;
XCALLOC(current_binding, struct keybinding); 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. */ /* We now have the correct binding, remove duplicates. */
conf_unbind(c, current_binding); conf_unbind(c, current_binding);
if (strcmp("unmap",binding) == 0) if (strcmp("unmap", binding) == 0)
return; return;
for (iter = 0; name_to_kbfunc[iter].tag != NULL; iter++) { 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) 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); for (key = TAILQ_FIRST(&c->keybindingq);
key != TAILQ_END(&c->keybindingq); key = keynxt) { key != TAILQ_END(&c->keybindingq); key = keynxt) {
@ -417,10 +419,10 @@ struct {
void void
conf_mousebind(struct conf *c, char *name, char *binding) conf_mousebind(struct conf *c, char *name, char *binding)
{ {
int iter; struct mousebinding *current_binding;
struct mousebinding *current_binding; char *substring;
char *substring; const char *errstr;
const char *errstr; int iter;
XCALLOC(current_binding, struct mousebinding); XCALLOC(current_binding, struct mousebinding);
@ -468,7 +470,7 @@ conf_mousebind(struct conf *c, char *name, char *binding)
void void
conf_mouseunbind(struct conf *c, struct mousebinding *unbind) conf_mouseunbind(struct conf *c, struct mousebinding *unbind)
{ {
struct mousebinding *mb = NULL, *mbnxt; struct mousebinding *mb = NULL, *mbnxt;
for (mb = TAILQ_FIRST(&c->mousebindingq); for (mb = TAILQ_FIRST(&c->mousebindingq);
mb != TAILQ_END(&c->mousebindingq); mb = mbnxt) { mb != TAILQ_END(&c->mousebindingq); mb = mbnxt) {
@ -492,7 +494,6 @@ conf_grab_mouse(struct client_ctx *cc)
{ {
struct mousebinding *mb; struct mousebinding *mb;
int button; int button;
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) { TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
if (mb->context != MOUSEBIND_CTX_WIN) if (mb->context != MOUSEBIND_CTX_WIN)

11
font.c
View File

@ -22,7 +22,7 @@
void void
font_init(struct screen_ctx *sc) font_init(struct screen_ctx *sc)
{ {
XColor xcolor, tmp; XColor xcolor, tmp;
sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin, sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which)); DefaultVisual(X_Dpy, sc->which), DefaultColormap(X_Dpy, sc->which));
@ -43,7 +43,8 @@ font_init(struct screen_ctx *sc)
int int
font_width(const char *text, int len) font_width(const char *text, int len)
{ {
XGlyphInfo extents; XGlyphInfo extents;
XftTextExtents8(X_Dpy, Conf.DefaultFont, (const XftChar8*)text, XftTextExtents8(X_Dpy, Conf.DefaultFont, (const XftChar8*)text,
len, &extents); len, &extents);
@ -63,9 +64,9 @@ font_draw(struct screen_ctx *sc, const char *text, int len,
XftFont * XftFont *
font_make(struct screen_ctx *sc, const char *name) font_make(struct screen_ctx *sc, const char *name)
{ {
XftFont *fn = NULL; XftFont *fn = NULL;
FcPattern *pat, *patx; FcPattern *pat, *patx;
XftResult res; XftResult res;
if ((pat = FcNameParse(name)) == NULL) if ((pat = FcNameParse(name)) == NULL)
return (NULL); return (NULL);

43
grab.c
View File

@ -29,10 +29,10 @@ static int _sweepcalc(struct client_ctx *, int, int, int, int);
void void
grab_sweep_draw(struct client_ctx *cc, int dx, int dy) grab_sweep_draw(struct client_ctx *cc, int dx, int dy)
{ {
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
int x0 = cc->geom.x, y0 = cc->geom.y; char asize[10]; /* fits "nnnnxnnnn\0" */
char asize[10]; /* fits "nnnnxnnnn\0" */ int wide, height, wide_size, wide_name;
int wide, height, wide_size, wide_name; int x = cc->geom.x, y = cc->geom.y;
snprintf(asize, sizeof(asize), "%dx%d", snprintf(asize, sizeof(asize), "%dx%d",
ADJUST_WIDTH(cc, dx), ADJUST_HEIGHT(cc, dy)); 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); wide = MAX(wide_size, wide_name);
height = font_ascent() + font_descent() + 1; 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); XMapWindow(X_Dpy, sc->menuwin);
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0); XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
XClearWindow(X_Dpy, sc->menuwin); XClearWindow(X_Dpy, sc->menuwin);
font_draw(sc, cc->name, strlen(cc->name), sc->menuwin, font_draw(sc, cc->name, strlen(cc->name), sc->menuwin,
2, font_ascent() + 1); 2, font_ascent() + 1);
font_draw(sc, asize, strlen(asize), sc->menuwin, 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 void
grab_sweep(struct client_ctx *cc) grab_sweep(struct client_ctx *cc)
{ {
XEvent ev; XEvent ev;
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
int x0 = cc->geom.x, y0 = cc->geom.y; int x = cc->geom.x, y = cc->geom.y, dx, dy;
int dx, dy;
dx = MAX(1, cc->size->width_inc); dx = MAX(1, cc->size->width_inc);
dy = MAX(1, cc->size->height_inc); dy = MAX(1, cc->size->height_inc);
@ -80,7 +79,7 @@ grab_sweep(struct client_ctx *cc)
client_draw_border(cc); client_draw_border(cc);
break; break;
case MotionNotify: 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 */ /* Recompute window output */
grab_sweep_draw(cc, dx, dy); grab_sweep_draw(cc, dx, dy);
@ -116,9 +115,9 @@ grab_sweep(struct client_ctx *cc)
void void
grab_drag(struct client_ctx *cc) grab_drag(struct client_ctx *cc)
{ {
int x0 = cc->geom.x, y0 = cc->geom.y, xm, ym; XEvent ev;
struct screen_ctx *sc = CCTOSC(cc); struct screen_ctx *sc = CCTOSC(cc);
XEvent ev; int x = cc->geom.x, y = cc->geom.y, xm, ym;
client_raise(cc); client_raise(cc);
@ -135,8 +134,8 @@ grab_drag(struct client_ctx *cc)
client_draw_border(cc); client_draw_border(cc);
break; break;
case MotionNotify: case MotionNotify:
cc->geom.x = x0 + (ev.xmotion.x - xm); cc->geom.x = x + (ev.xmotion.x - xm);
cc->geom.y = y0 + (ev.xmotion.y - ym); cc->geom.y = y + (ev.xmotion.y - ym);
XMoveWindow(X_Dpy, cc->pwin, XMoveWindow(X_Dpy, cc->pwin,
cc->geom.x - cc->bwidth, cc->geom.y - cc->bwidth); cc->geom.x - cc->bwidth, cc->geom.y - cc->bwidth);
@ -151,15 +150,15 @@ grab_drag(struct client_ctx *cc)
} }
static int 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; width = cc->geom.width;
height = cc->geom.height; height = cc->geom.height;
cc->geom.width = abs(x0 - motionx); cc->geom.width = abs(x - motionx);
cc->geom.height = abs(y0 - motiony); cc->geom.height = abs(y - motiony);
if (cc->size->flags & PResizeInc) { if (cc->size->flags & PResizeInc) {
cc->geom.width -= 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.height = MIN(cc->geom.height, cc->size->max_height);
} }
cc->geom.x = x0 <= motionx ? x0 : x0 - cc->geom.width; cc->geom.x = x <= motionx ? x : x - cc->geom.width;
cc->geom.y = y0 <= motiony ? y0 : y0 - cc->geom.height; cc->geom.y = y <= motiony ? y : y - cc->geom.height;
return (width != cc->geom.width || height != cc->geom.height); return (width != cc->geom.width || height != cc->geom.height);
} }

39
group.c
View File

@ -58,7 +58,7 @@ _group_remove(struct client_ctx *cc)
static void static void
_group_hide(struct group_ctx *gc) _group_hide(struct group_ctx *gc)
{ {
struct client_ctx *cc; struct client_ctx *cc;
screen_updatestackingorder(); screen_updatestackingorder();
@ -76,10 +76,10 @@ _group_hide(struct group_ctx *gc)
static void static void
_group_show(struct group_ctx *gc) _group_show(struct group_ctx *gc)
{ {
struct client_ctx *cc; struct client_ctx *cc;
Window *winlist; Window *winlist;
u_int i; u_int i;
int lastempty = -1; int lastempty = -1;
winlist = (Window *) xcalloc(sizeof(*winlist), (gc->highstack + 1)); winlist = (Window *) xcalloc(sizeof(*winlist), (gc->highstack + 1));
@ -113,7 +113,7 @@ _group_show(struct group_ctx *gc)
void void
group_init(void) group_init(void)
{ {
int i; int i;
TAILQ_INIT(&Groupq); TAILQ_INIT(&Groupq);
@ -133,7 +133,9 @@ group_init(void)
void void
group_sticky_toggle_enter(struct client_ctx *cc) 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) { if (gc == cc->group) {
_group_remove(cc); _group_remove(cc);
@ -162,8 +164,8 @@ group_sticky_toggle_exit(struct client_ctx *cc)
void void
_group_fix_hidden_state(struct group_ctx *gc) _group_fix_hidden_state(struct group_ctx *gc)
{ {
struct client_ctx *cc; struct client_ctx *cc;
int same = 0; int same = 0;
TAILQ_FOREACH(cc, &gc->clients, group_entry) { TAILQ_FOREACH(cc, &gc->clients, group_entry) {
if (gc->hidden == ((cc->flags & CLIENT_HIDDEN) ? 1 : 0)) if (gc->hidden == ((cc->flags & CLIENT_HIDDEN) ? 1 : 0))
@ -177,7 +179,7 @@ _group_fix_hidden_state(struct group_ctx *gc)
void void
group_hidetoggle(int idx) group_hidetoggle(int idx)
{ {
struct group_ctx *gc; struct group_ctx *gc;
if (idx < 0 || idx >= CALMWM_NGROUPS) if (idx < 0 || idx >= CALMWM_NGROUPS)
err(1, "group_hidetoggle: index out of range (%d)", idx); err(1, "group_hidetoggle: index out of range (%d)", idx);
@ -201,11 +203,10 @@ group_hidetoggle(int idx)
void void
group_cycle(int reverse) group_cycle(int reverse)
{ {
struct group_ctx *gc, *showgroup = NULL; struct group_ctx *gc, *showgroup = NULL;
assert(Group_active != NULL); assert(Group_active != NULL);
gc = Group_active;
for (;;) { for (;;) {
gc = reverse ? TAILQ_PREV(gc, group_ctx_q, entry) : gc = reverse ? TAILQ_PREV(gc, group_ctx_q, entry) :
TAILQ_NEXT(gc, entry); TAILQ_NEXT(gc, entry);
@ -246,10 +247,10 @@ group_client_delete(struct client_ctx *cc)
void void
group_menu(XButtonEvent *e) group_menu(XButtonEvent *e)
{ {
struct menu_q menuq;
struct menu *mi;
int i;
struct group_ctx *gc; struct group_ctx *gc;
struct menu *mi;
struct menu_q menuq;
int i;
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
@ -295,7 +296,7 @@ cleanup:
void void
group_alltoggle(void) group_alltoggle(void)
{ {
int i; int i;
for (i = 0; i < CALMWM_NGROUPS; i++) { for (i = 0; i < CALMWM_NGROUPS; i++) {
if (Grouphideall) if (Grouphideall)
@ -313,9 +314,9 @@ group_alltoggle(void)
void void
group_autogroup(struct client_ctx *cc) group_autogroup(struct client_ctx *cc)
{ {
struct autogroupwin *aw; struct autogroupwin *aw;
struct group_ctx *gc; struct group_ctx *gc;
char group[CALMWM_MAXNAMELEN]; char group[CALMWM_MAXNAMELEN];
if (cc->app_class == NULL || cc->app_name == NULL) if (cc->app_class == NULL || cc->app_name == NULL)
return; return;

View File

@ -24,7 +24,7 @@
int int
input_keycodetrans(KeyCode kc, u_int state, enum ctltype *ctl, char *chr) input_keycodetrans(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
{ {
int ks; int ks;
*ctl = CTL_NONE; *ctl = CTL_NONE;
*chr = '\0'; *chr = '\0';

View File

@ -46,10 +46,11 @@ kbfunc_client_raise(struct client_ctx *cc, void *arg)
void void
kbfunc_moveresize(struct client_ctx *cc, void *arg) kbfunc_moveresize(struct client_ctx *cc, void *arg)
{ {
struct screen_ctx *sc = screen_current(); struct screen_ctx *sc;
int x, y, flags, amt; int x, y, flags, amt;
u_int mx, my; u_int mx, my;
sc = screen_current();
mx = my = 0; mx = my = 0;
flags = (int)arg; flags = (int)arg;
@ -121,15 +122,16 @@ kbfunc_moveresize(struct client_ctx *cc, void *arg)
default: default:
warnx("invalid flags passed to kbfunc_client_moveresize"); warnx("invalid flags passed to kbfunc_client_moveresize");
} }
} }
void void
kbfunc_client_search(struct client_ctx *scratch, void *arg) kbfunc_client_search(struct client_ctx *scratch, void *arg)
{ {
struct menu_q menuq; struct client_ctx *cc, *old_cc;
struct client_ctx *cc, *old_cc = client_current();
struct menu *mi; struct menu *mi;
struct menu_q menuq;
old_cc = client_current();
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
@ -160,9 +162,9 @@ kbfunc_client_search(struct client_ctx *scratch, void *arg)
void void
kbfunc_menu_search(struct client_ctx *scratch, void *arg) kbfunc_menu_search(struct client_ctx *scratch, void *arg)
{ {
struct menu_q menuq;
struct menu *mi;
struct cmd *cmd; struct cmd *cmd;
struct menu *mi;
struct menu_q menuq;
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
@ -187,7 +189,9 @@ kbfunc_menu_search(struct client_ctx *scratch, void *arg)
void void
kbfunc_client_cycle(struct client_ctx *scratch, void *arg) 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 */ /* XXX for X apps that ignore events */
XGrabKeyboard(X_Dpy, sc->rootwin, True, XGrabKeyboard(X_Dpy, sc->rootwin, True,
@ -226,16 +230,16 @@ void
kbfunc_exec(struct client_ctx *scratch, void *arg) kbfunc_exec(struct client_ctx *scratch, void *arg)
{ {
#define NPATHS 256 #define NPATHS 256
char **ap, *paths[NPATHS], *path, *pathcpy, tpath[MAXPATHLEN]; char **ap, *paths[NPATHS], *path, *pathcpy, *label;
int l, i, j, ngroups; char tpath[MAXPATHLEN];
gid_t mygroups[NGROUPS_MAX]; int l, i, j, ngroups;
uid_t ruid, euid, suid; gid_t mygroups[NGROUPS_MAX];
DIR *dirp; uid_t ruid, euid, suid;
struct dirent *dp; DIR *dirp;
struct stat sb; struct dirent *dp;
struct menu_q menuq; struct menu *mi;
struct menu *mi; struct menu_q menuq;
char *label; struct stat sb;
int cmd = (int)arg; int cmd = (int)arg;
switch (cmd) { switch (cmd) {
@ -308,7 +312,7 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
strlcpy(mi->text, dp->d_name, sizeof(mi->text)); strlcpy(mi->text, dp->d_name, sizeof(mi->text));
TAILQ_INSERT_TAIL(&menuq, mi, entry); TAILQ_INSERT_TAIL(&menuq, mi, entry);
} }
(void) closedir(dirp); (void)closedir(dirp);
} }
xfree(path); xfree(path);
@ -339,13 +343,14 @@ kbfunc_exec(struct client_ctx *scratch, void *arg)
void void
kbfunc_ssh(struct client_ctx *scratch, void *arg) kbfunc_ssh(struct client_ctx *scratch, void *arg)
{ {
struct menu_q menuq; struct menu *mi;
struct menu *mi; struct menu_q menuq;
FILE *fp; FILE *fp;
size_t len; char *buf, *lbuf, *p, *home;
char *buf, *lbuf, *p, *home; char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN];
char hostbuf[MAXHOSTNAMELEN], filename[MAXPATHLEN], cmd[256]; char cmd[256];
int l; int l;
size_t len;
if ((home = getenv("HOME")) == NULL) if ((home = getenv("HOME")) == NULL)
return; return;
@ -386,7 +391,6 @@ kbfunc_ssh(struct client_ctx *scratch, void *arg)
xfree(lbuf); xfree(lbuf);
fclose(fp); fclose(fp);
if ((mi = menu_filter(&menuq, "ssh", NULL, 1, if ((mi = menu_filter(&menuq, "ssh", NULL, 1,
search_match_exec, NULL)) != NULL) { search_match_exec, NULL)) != NULL) {
conf_reload(&Conf); conf_reload(&Conf);
@ -408,8 +412,8 @@ void
kbfunc_client_label(struct client_ctx *cc, void *arg) kbfunc_client_label(struct client_ctx *cc, void *arg)
{ {
struct menu *mi; struct menu *mi;
char *current;
struct menu_q menuq; struct menu_q menuq;
char *current;
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);

15
menu.c
View File

@ -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 (*match)(struct menu_q *, struct menu_q *, char *),
void (*print)(struct menu *, int)) void (*print)(struct menu *, int))
{ {
struct screen_ctx *sc = screen_current(); struct screen_ctx *sc;
struct menu_ctx mc; struct menu_ctx mc;
struct menu_q resultq; struct menu_q resultq;
struct menu *mi = NULL; struct menu *mi = NULL;
@ -75,6 +75,8 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy,
Window focuswin; Window focuswin;
int Mask, focusrevert; int Mask, focusrevert;
sc = screen_current();
TAILQ_INIT(&resultq); TAILQ_INIT(&resultq);
bzero(&mc, sizeof(mc)); 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_q *resultq)
{ {
struct menu *mi; struct menu *mi;
int n = 0; int n, dy, xsave, ysave;
int dy;
int xsave, ysave;
int warp;
if (mc->list) { if (mc->list) {
if (TAILQ_EMPTY(resultq) && 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 static int
menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y) 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? */ /* 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 < 0 || entry >= mc->num)
entry = -1; entry = -1;

View File

@ -63,10 +63,12 @@ mousefunc_menu_group(struct client_ctx *cc, void *arg)
void void
mousefunc_menu_unhide(struct client_ctx *cc, void *arg) mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
{ {
struct menu *mi; struct client_ctx *old_cc;
struct menu_q menuq; struct menu *mi;
char *wname; struct menu_q menuq;
struct client_ctx *old_cc = client_current(); char *wname;
old_cc = client_current();
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);
TAILQ_FOREACH(cc, &Clientq, entry) TAILQ_FOREACH(cc, &Clientq, entry)
@ -96,19 +98,21 @@ mousefunc_menu_unhide(struct client_ctx *cc, void *arg)
if (old_cc != NULL) if (old_cc != NULL)
client_ptrsave(old_cc); client_ptrsave(old_cc);
client_ptrwarp(cc); client_ptrwarp(cc);
} else } else {
while ((mi = TAILQ_FIRST(&menuq)) != NULL) { while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
TAILQ_REMOVE(&menuq, mi, entry); TAILQ_REMOVE(&menuq, mi, entry);
xfree(mi); xfree(mi);
} }
}
} }
void void
mousefunc_menu_cmd(struct client_ctx *cc, void *arg) mousefunc_menu_cmd(struct client_ctx *cc, void *arg)
{ {
struct menu *mi; struct menu *mi;
struct menu_q menuq; struct menu_q menuq;
struct cmd *cmd; struct cmd *cmd;
conf_reload(&Conf); conf_reload(&Conf);
TAILQ_INIT(&menuq); TAILQ_INIT(&menuq);

View File

@ -27,7 +27,7 @@ extern struct screen_ctx *Curscreen;
struct screen_ctx * struct screen_ctx *
screen_fromroot(Window rootwin) screen_fromroot(Window rootwin)
{ {
struct screen_ctx *sc; struct screen_ctx *sc;
TAILQ_FOREACH(sc, &Screenq, entry) TAILQ_FOREACH(sc, &Screenq, entry)
if (sc->rootwin == rootwin) if (sc->rootwin == rootwin)
@ -46,10 +46,12 @@ screen_current(void)
void void
screen_updatestackingorder(void) screen_updatestackingorder(void)
{ {
Window *wins, w0, w1; Window *wins, w0, w1;
struct screen_ctx *sc = screen_current(); struct screen_ctx *sc;
u_int nwins, i, s; struct client_ctx *cc;
struct client_ctx *cc; u_int nwins, i, s;
sc = screen_current();
if (!XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins)) if (!XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins))
return; return;

View File

@ -31,9 +31,11 @@ static int _strsubmatch(char *, char *, int);
void void
search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
{ {
struct winname *wn; struct winname *wn;
struct menu *mi, *tierp[4], *before = NULL; struct menu *mi, *tierp[4], *before = NULL;
int ntiers = sizeof(tierp)/sizeof(tierp[0]); int ntiers;
ntiers = sizeof(tierp) / sizeof(tierp[0]);
TAILQ_INIT(resultq); TAILQ_INIT(resultq);
@ -119,8 +121,10 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
void void
search_print_client(struct menu *mi, int list) search_print_client(struct menu *mi, int list)
{ {
struct client_ctx *cc = mi->ctx; struct client_ctx *cc;
char flag = ' '; char flag = ' ';
cc = mi->ctx;
if (cc == client_current()) if (cc == client_current())
flag = '!'; flag = '!';
@ -134,9 +138,11 @@ search_print_client(struct menu *mi, int list)
if (!list && cc->matchname != cc->name && if (!list && cc->matchname != cc->name &&
strlen(mi->print) < sizeof(mi->print) - 1) { strlen(mi->print) < sizeof(mi->print) - 1) {
int diff = sizeof(mi->print) - 1 - strlen(mi->print); const char *marker = "";
const char *marker = ""; char buf[MENU_MAXENTRY + 1];
char buf[MENU_MAXENTRY + 1]; int diff;
diff = sizeof(mi->print) - 1 - strlen(mi->print);
/* One for the ':' */ /* One for the ':' */
diff -= 1; diff -= 1;
@ -157,7 +163,7 @@ search_print_client(struct menu *mi, int list)
void void
search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search) search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search)
{ {
struct menu *mi; struct menu *mi;
TAILQ_INIT(resultq); TAILQ_INIT(resultq);
@ -169,7 +175,7 @@ search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search)
void void
search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search) search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search)
{ {
struct menu *mi; struct menu *mi;
TAILQ_INIT(resultq); TAILQ_INIT(resultq);
@ -181,8 +187,8 @@ search_match_exec(struct menu_q *menuq, struct menu_q *resultq, char *search)
static int static int
_strsubmatch(char *sub, char *str, int zeroidx) _strsubmatch(char *sub, char *str, int zeroidx)
{ {
size_t len, sublen; size_t len, sublen;
u_int n, flen; u_int n, flen;
if (sub == NULL || str == NULL) if (sub == NULL || str == NULL)
return (0); return (0);
@ -197,6 +203,7 @@ _strsubmatch(char *sub, char *str, int zeroidx)
flen = len - sublen; flen = len - sublen;
else else
flen = 0; flen = 0;
for (n = 0; n <= flen; n++) for (n = 0; n <= flen; n++)
if (strncasecmp(sub, str + n, sublen) == 0) if (strncasecmp(sub, str + n, sublen) == 0)
return (1); return (1);

5
util.c
View File

@ -44,9 +44,8 @@ u_spawn(char *argstr)
void void
u_exec(char *argstr) u_exec(char *argstr)
{ {
char *args[MAXARGLEN], **ap = args; char *args[MAXARGLEN], **ap = args;
char **end = &args[MAXARGLEN - 1]; char **end = &args[MAXARGLEN - 1], *tmp;
char *tmp;
while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL) { while (ap < end && (*ap = strsep(&argstr, " \t")) != NULL) {
if (**ap == '\0') if (**ap == '\0')

View File

@ -35,15 +35,16 @@
void void
xev_handle_maprequest(struct xevent *xev, XEvent *ee) xev_handle_maprequest(struct xevent *xev, XEvent *ee)
{ {
XMapRequestEvent *e = &ee->xmaprequest; XMapRequestEvent *e = &ee->xmaprequest;
struct client_ctx *cc = NULL, *old_cc = client_current(); XWindowAttributes xattr;
XWindowAttributes xattr; struct client_ctx *cc = NULL, *old_cc;
struct screen_ctx *sc; struct screen_ctx *sc;
#ifdef notyet #ifdef notyet
int state; int state;
#endif #endif
if (old_cc != NULL) if ((old_cc = client_current()) != NULL)
client_ptrsave(old_cc); client_ptrsave(old_cc);
if ((cc = client_find(e->window)) == NULL) { if ((cc = client_find(e->window)) == NULL) {
@ -66,8 +67,8 @@ xev_handle_maprequest(struct xevent *xev, XEvent *ee)
void void
xev_handle_unmapnotify(struct xevent *xev, XEvent *ee) xev_handle_unmapnotify(struct xevent *xev, XEvent *ee)
{ {
XUnmapEvent *e = &ee->xunmap; XUnmapEvent *e = &ee->xunmap;
struct client_ctx *cc; struct client_ctx *cc;
if ((cc = client_find(e->window)) != NULL) if ((cc = client_find(e->window)) != NULL)
client_delete(cc, e->send_event, 0); client_delete(cc, e->send_event, 0);
@ -78,8 +79,8 @@ xev_handle_unmapnotify(struct xevent *xev, XEvent *ee)
void void
xev_handle_destroynotify(struct xevent *xev, XEvent *ee) xev_handle_destroynotify(struct xevent *xev, XEvent *ee)
{ {
XDestroyWindowEvent *e = &ee->xdestroywindow; XDestroyWindowEvent *e = &ee->xdestroywindow;
struct client_ctx *cc; struct client_ctx *cc;
if ((cc = client_find(e->window)) != NULL) if ((cc = client_find(e->window)) != NULL)
client_delete(cc, 1, 1); client_delete(cc, 1, 1);
@ -90,10 +91,10 @@ xev_handle_destroynotify(struct xevent *xev, XEvent *ee)
void void
xev_handle_configurerequest(struct xevent *xev, XEvent *ee) xev_handle_configurerequest(struct xevent *xev, XEvent *ee)
{ {
XConfigureRequestEvent *e = &ee->xconfigurerequest; XConfigureRequestEvent *e = &ee->xconfigurerequest;
struct client_ctx *cc; struct client_ctx *cc;
struct screen_ctx *sc; struct screen_ctx *sc;
XWindowChanges wc; XWindowChanges wc;
if ((cc = client_find(e->window)) != NULL) { if ((cc = client_find(e->window)) != NULL) {
sc = CCTOSC(cc); sc = CCTOSC(cc);
@ -146,9 +147,9 @@ xev_handle_configurerequest(struct xevent *xev, XEvent *ee)
void void
xev_handle_propertynotify(struct xevent *xev, XEvent *ee) xev_handle_propertynotify(struct xevent *xev, XEvent *ee)
{ {
XPropertyEvent *e = &ee->xproperty; XPropertyEvent *e = &ee->xproperty;
struct client_ctx *cc; struct client_ctx *cc;
long tmp; long tmp;
if ((cc = client_find(e->window)) != NULL) { if ((cc = client_find(e->window)) != NULL) {
switch (e->atom) { switch (e->atom) {
@ -170,7 +171,7 @@ xev_handle_propertynotify(struct xevent *xev, XEvent *ee)
void void
xev_reconfig(struct client_ctx *cc) xev_reconfig(struct client_ctx *cc)
{ {
XConfigureEvent ce; XConfigureEvent ce;
ce.type = ConfigureNotify; ce.type = ConfigureNotify;
ce.event = cc->win; ce.event = cc->win;
@ -189,8 +190,8 @@ xev_reconfig(struct client_ctx *cc)
void void
xev_handle_enternotify(struct xevent *xev, XEvent *ee) xev_handle_enternotify(struct xevent *xev, XEvent *ee)
{ {
XCrossingEvent *e = &ee->xcrossing; XCrossingEvent *e = &ee->xcrossing;
struct client_ctx *cc; struct client_ctx *cc;
if ((cc = client_find(e->window)) == NULL) { if ((cc = client_find(e->window)) == NULL) {
/* /*
@ -222,10 +223,11 @@ xev_handle_buttonpress(struct xevent *xev, XEvent *ee)
{ {
XButtonEvent *e = &ee->xbutton; XButtonEvent *e = &ee->xbutton;
struct client_ctx *cc; struct client_ctx *cc;
struct screen_ctx *sc = screen_fromroot(e->root); struct screen_ctx *sc;
struct mousebinding *mb; struct mousebinding *mb;
char *wname; char *wname;
sc = screen_fromroot(e->root);
cc = client_find(e->window); cc = client_find(e->window);
/* Ignore caps lock and numlock */ /* Ignore caps lock and numlock */
@ -256,9 +258,9 @@ out:
void void
xev_handle_buttonrelease(struct xevent *xev, XEvent *ee) 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); group_sticky_toggle_exit(cc);
xev_register(xev); xev_register(xev);
@ -267,11 +269,11 @@ xev_handle_buttonrelease(struct xevent *xev, XEvent *ee)
void void
xev_handle_keypress(struct xevent *xev, XEvent *ee) xev_handle_keypress(struct xevent *xev, XEvent *ee)
{ {
XKeyEvent *e = &ee->xkey; XKeyEvent *e = &ee->xkey;
struct client_ctx *cc = NULL; /* Make gcc happy. */ struct client_ctx *cc = NULL;
struct keybinding *kb; struct keybinding *kb;
KeySym keysym, skeysym; KeySym keysym, skeysym;
int modshift; int modshift;
keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0); keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0);
skeysym = XKeycodeToKeysym(X_Dpy, e->keycode, 1); skeysym = XKeycodeToKeysym(X_Dpy, e->keycode, 1);
@ -315,10 +317,13 @@ out:
void void
xev_handle_keyrelease(struct xevent *xev, XEvent *ee) xev_handle_keyrelease(struct xevent *xev, XEvent *ee)
{ {
XKeyEvent *e = &ee->xkey; XKeyEvent *e = &ee->xkey;
struct screen_ctx *sc = screen_fromroot(e->root); struct screen_ctx *sc;
struct client_ctx *cc = client_current(); struct client_ctx *cc;
int keysym; int keysym;
sc = screen_fromroot(e->root);
cc = client_current();
keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0); keysym = XKeycodeToKeysym(X_Dpy, e->keycode, 0);
if (keysym != XK_Alt_L && keysym != XK_Alt_R) if (keysym != XK_Alt_L && keysym != XK_Alt_R)
@ -344,11 +349,13 @@ out:
void void
xev_handle_clientmessage(struct xevent *xev, XEvent *ee) xev_handle_clientmessage(struct xevent *xev, XEvent *ee)
{ {
XClientMessageEvent *e = &ee->xclient; XClientMessageEvent *e = &ee->xclient;
struct client_ctx *cc = client_find(e->window); Atom xa_wm_change_state;
Atom xa_wm_change_state = XInternAtom(X_Dpy, "WM_CHANGE_STATE", False); 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; goto out;
if (e->message_type == xa_wm_change_state && e->format == 32 && if (e->message_type == xa_wm_change_state && e->format == 32 &&
@ -361,8 +368,8 @@ out:
void void
xev_handle_shape(struct xevent *xev, XEvent *ee) xev_handle_shape(struct xevent *xev, XEvent *ee)
{ {
XShapeEvent *sev = (XShapeEvent *) ee; XShapeEvent *sev = (XShapeEvent *) ee;
struct client_ctx *cc; struct client_ctx *cc;
if ((cc = client_find(sev->window)) != NULL) if ((cc = client_find(sev->window)) != NULL)
client_do_shape(cc); client_do_shape(cc);
@ -387,7 +394,7 @@ struct xevent *
xev_new(Window *win, Window *root, xev_new(Window *win, Window *root,
int type, void (*cb)(struct xevent *, XEvent *), void *arg) int type, void (*cb)(struct xevent *, XEvent *), void *arg)
{ {
struct xevent *xev; struct xevent *xev;
XMALLOC(xev, struct xevent); XMALLOC(xev, struct xevent);
xev->xev_win = win; xev->xev_win = win;
@ -402,7 +409,7 @@ xev_new(Window *win, Window *root,
void void
xev_register(struct xevent *xev) xev_register(struct xevent *xev)
{ {
struct xevent_q *xq; struct xevent_q *xq;
xq = _xev_q_lock ? &_xevq_putaway : &_xevq; xq = _xev_q_lock ? &_xevq_putaway : &_xevq;
TAILQ_INSERT_TAIL(xq, xev, entry); TAILQ_INSERT_TAIL(xq, xev, entry);
@ -411,7 +418,7 @@ xev_register(struct xevent *xev)
void void
_xev_reincorporate(void) _xev_reincorporate(void)
{ {
struct xevent *xev; struct xevent *xev;
while ((xev = TAILQ_FIRST(&_xevq_putaway)) != NULL) { while ((xev = TAILQ_FIRST(&_xevq_putaway)) != NULL) {
TAILQ_REMOVE(&_xevq_putaway, xev, entry); TAILQ_REMOVE(&_xevq_putaway, xev, entry);
@ -422,8 +429,8 @@ _xev_reincorporate(void)
void void
xev_handle_expose(struct xevent *xev, XEvent *ee) xev_handle_expose(struct xevent *xev, XEvent *ee)
{ {
XExposeEvent *e = &ee->xexpose; XExposeEvent *e = &ee->xexpose;
struct client_ctx *cc; struct client_ctx *cc;
if ((cc = client_find(e->window)) != NULL && e->count == 0) { if ((cc = client_find(e->window)) != NULL && e->count == 0) {
client_draw_border(cc); client_draw_border(cc);
@ -445,10 +452,10 @@ xev_handle_expose(struct xevent *xev, XEvent *ee)
void void
xev_loop(void) xev_loop(void)
{ {
Window win, root; Window win, root;
XEvent e;
struct xevent *xev = NULL, *nextxev;
int type; int type;
XEvent e;
struct xevent *xev, *nextxev;
while (_xev_quit == 0) { while (_xev_quit == 0) {
#ifdef DIAGNOSTIC #ifdef DIAGNOSTIC

View File

@ -24,7 +24,7 @@
void * void *
xmalloc(size_t siz) xmalloc(size_t siz)
{ {
void *p; void *p;
if ((p = malloc(siz)) == NULL) if ((p = malloc(siz)) == NULL)
err(1, "malloc"); err(1, "malloc");
@ -35,7 +35,7 @@ xmalloc(size_t siz)
void * void *
xcalloc(size_t no, size_t siz) xcalloc(size_t no, size_t siz)
{ {
void *p; void *p;
if ((p = calloc(no, siz)) == NULL) if ((p = calloc(no, siz)) == NULL)
err(1, "calloc"); err(1, "calloc");
@ -52,7 +52,7 @@ xfree(void *p)
char * char *
xstrdup(const char *str) xstrdup(const char *str)
{ {
char *p; char *p;
if ((p = strdup(str)) == NULL) if ((p = strdup(str)) == NULL)
err(1, "strdup"); err(1, "strdup");

28
xutil.c
View File

@ -65,9 +65,9 @@ xu_btn_ungrab(Window win, int mask, u_int btn)
void void
xu_ptr_getpos(Window rootwin, int *x, int *y) xu_ptr_getpos(Window rootwin, int *x, int *y)
{ {
int tmp0, tmp1; Window w0, w1;
u_int tmp2; int tmp0, tmp1;
Window w0, w1; u_int tmp2;
XQueryPointer(X_Dpy, rootwin, &w0, &w1, &tmp0, &tmp1, x, y, &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 void
xu_key_grab(Window win, int mask, int keysym) xu_key_grab(Window win, int mask, int keysym)
{ {
KeyCode code; KeyCode code;
int i; int i;
code = XKeysymToKeycode(X_Dpy, keysym); code = XKeysymToKeycode(X_Dpy, keysym);
if ((XKeycodeToKeysym(X_Dpy, code, 0) != keysym) && if ((XKeycodeToKeysym(X_Dpy, code, 0) != keysym) &&
@ -98,7 +98,7 @@ xu_key_grab(Window win, int mask, int keysym)
void void
xu_sendmsg(struct client_ctx *cc, Atom atm, long val) xu_sendmsg(struct client_ctx *cc, Atom atm, long val)
{ {
XEvent e; XEvent e;
memset(&e, 0, sizeof(e)); memset(&e, 0, sizeof(e));
e.xclient.type = ClientMessage; e.xclient.type = ClientMessage;
@ -114,9 +114,9 @@ xu_sendmsg(struct client_ctx *cc, Atom atm, long val)
int int
xu_getprop(struct client_ctx *cc, Atom atm, Atom type, long len, u_char **p) xu_getprop(struct client_ctx *cc, Atom atm, Atom type, long len, u_char **p)
{ {
Atom realtype; Atom realtype;
u_long n, extra; u_long n, extra;
int format; int format;
if (XGetWindowProperty(X_Dpy, cc->win, atm, 0L, len, False, type, if (XGetWindowProperty(X_Dpy, cc->win, atm, 0L, len, False, type,
&realtype, &format, &n, &extra, p) != Success || *p == NULL) &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 int
xu_getstate(struct client_ctx *cc, int *state) xu_getstate(struct client_ctx *cc, int *state)
{ {
Atom wm_state = XInternAtom(X_Dpy, "WM_STATE", False); Atom wm_state;
long *p = NULL; long *p = NULL;
wm_state = XInternAtom(X_Dpy, "WM_STATE", False);
if (xu_getprop(cc, wm_state, wm_state, 2L, (u_char **)&p) <= 0) if (xu_getprop(cc, wm_state, wm_state, 2L, (u_char **)&p) <= 0)
return (-1); return (-1);
@ -146,8 +148,8 @@ xu_getstate(struct client_ctx *cc, int *state)
void void
xu_setstate(struct client_ctx *cc, int state) xu_setstate(struct client_ctx *cc, int state)
{ {
long dat[2]; Atom wm_state;
Atom wm_state; long dat[2];
/* XXX cache */ /* XXX cache */
wm_state = XInternAtom(X_Dpy, "WM_STATE", False); wm_state = XInternAtom(X_Dpy, "WM_STATE", False);