X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=scrotwm.c;h=789aca0707d075a8dfa66d9c18b7cb210467dca8;hb=739a5e6e3218529604d7a36cda21910719897e7b;hp=76ae71b00db6b57eb25b241462d249726e32ffc4;hpb=ae990c02fcc2aafb50e4786970e8d0935a1d2951;p=spectrwm.git diff --git a/scrotwm.c b/scrotwm.c index 76ae71b..789aca0 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -161,9 +161,18 @@ u_int32_t swm_debug = 0 #define Y(r) (r)->g.y #define WIDTH(r) (r)->g.w #define HEIGHT(r) (r)->g.h +#define SH_MIN(w) (w)->sh_mask & PMinSize +#define SH_MIN_W(w) (w)->sh.min_width +#define SH_MIN_H(w) (w)->sh.min_height +#define SH_MAX(w) (w)->sh_mask & PMaxSize +#define SH_MAX_W(w) (w)->sh.max_width +#define SH_MAX_H(w) (w)->sh.max_height +#define SH_INC(w) (w)->sh_mask & PResizeInc +#define SH_INC_W(w) (w)->sh.width_inc +#define SH_INC_H(w) (w)->sh.height_inc #define SWM_MAX_FONT_STEPS (3) -#define WINID(w) (w ? w->id : 0) -#define YESNO(x) (x ? "yes" : "no") +#define WINID(w) ((w) ? (w)->id : 0) +#define YESNO(x) ((x) ? "yes" : "no") #define SWM_FOCUS_DEFAULT (0) #define SWM_FOCUS_SYNERGY (1) @@ -337,6 +346,7 @@ struct ws_win { struct swm_screen *s; /* always valid, never changes */ XWindowAttributes wa; XSizeHints sh; + long sh_mask; XClassHint ch; XWMHints *hints; }; @@ -489,6 +499,7 @@ void focus_magic(struct ws_win *); /* quirks */ struct quirk { + TAILQ_ENTRY(quirk) entry; char *class; char *name; unsigned long quirk; @@ -499,8 +510,8 @@ struct quirk { #define SWM_Q_FULLSCREEN (1<<4) /* remove border */ #define SWM_Q_FOCUSPREV (1<<5) /* focus on caller */ }; -int quirks_size = 0, quirks_length = 0; -struct quirk *quirks = NULL; +TAILQ_HEAD(quirk_list, quirk); +struct quirk_list quirks = TAILQ_HEAD_INITIALIZER(quirks); /* * Supported EWMH hints should be added to @@ -552,20 +563,22 @@ struct ewmh_hint { void store_float_geom(struct ws_win *, struct swm_region *); int floating_toggle_win(struct ws_win *); void spawn_select(struct swm_region *, union arg *, char *, int *); -unsigned char *get_win_name(Display *, Window, Atom, Atom, unsigned long *); +unsigned char *get_win_name(Window); int -get_property(Window id, Atom atom, long count, Atom type, - unsigned long *n, unsigned char **data) +get_property(Window id, Atom atom, long count, Atom type, unsigned long *nitems, + unsigned long *nbytes, unsigned char **data) { int format, status; - unsigned long tmp, extra; - unsigned long *nitems; + unsigned long *nbytes_ret, *nitems_ret; + unsigned long nbytes_tmp, nitems_tmp; Atom real; - nitems = n != NULL ? n : &tmp; + nbytes_ret = nbytes != NULL ? nbytes : &nbytes_tmp; + nitems_ret = nitems != NULL ? nitems : &nitems_tmp; + status = XGetWindowProperty(display, id, atom, 0L, count, False, type, - &real, &format, nitems, &extra, data); + &real, &format, nitems_ret, nbytes_ret, data); if (status != Success) return False; @@ -659,7 +672,7 @@ teardown_ewmh(void) for (i = 0; i < ScreenCount(display); i++) { /* Get the support check window and destroy it */ success = get_property(screens[i].root, sup_check, 1, XA_WINDOW, - &n, &data); + &n, NULL, &data); if (success) { id = data[0]; @@ -680,7 +693,7 @@ ewmh_autoquirk(struct ws_win *win) Atom type; success = get_property(win->id, ewmh[_NET_WM_WINDOW_TYPE].atom, (~0L), - XA_ATOM, &n, (void *)&data); + XA_ATOM, &n, NULL, (void *)&data); if (!success) { XFree(data); @@ -866,7 +879,7 @@ ewmh_get_win_state(struct ws_win *win) win->ewmh_flags |= SWM_F_MANUAL; success = get_property(win->id, ewmh[_NET_WM_STATE].atom, - (~0L), XA_ATOM, &n, (void *)&states); + (~0L), XA_ATOM, &n, NULL, (void *)&states); if (!success) return; @@ -994,7 +1007,7 @@ geteventname(XEvent *e) char * xrandr_geteventname(XEvent *e) { - char *name = NULL; + char *name = NULL; switch(e->type - xrandr_eventbase) { case RRScreenChangeNotify: @@ -1015,34 +1028,34 @@ dumpwins(struct swm_region *r, union arg *args) XWindowAttributes wa; if (r->ws == NULL) { - fprintf(stderr, "dumpwins: invalid workspace\n"); + warnx("dumpwins: invalid workspace"); return; } - fprintf(stderr, "=== managed window list ws %02d ===\n", r->ws->idx); + warnx("=== managed window list ws %02d ===", r->ws->idx); TAILQ_FOREACH(win, &r->ws->winlist, entry) { state = getstate(win->id); if (!XGetWindowAttributes(display, win->id, &wa)) - fprintf(stderr, "window: 0x%lx, failed " - "XGetWindowAttributes\n", win->id); - fprintf(stderr, "window: 0x%lx, map_state: %d, state: %d, " - "transient: 0x%lx\n", - win->id, wa.map_state, state, win->transient); + warnx("window: 0x%lx, failed XGetWindowAttributes", + win->id); + warnx("window: 0x%lx, map_state: %d, state: %d, " + "transient: 0x%lx", win->id, wa.map_state, state, + win->transient); } - fprintf(stderr, "===== unmanaged window list =====\n"); + warnx("===== unmanaged window list ====="); TAILQ_FOREACH(win, &r->ws->unmanagedlist, entry) { state = getstate(win->id); if (!XGetWindowAttributes(display, win->id, &wa)) - fprintf(stderr, "window: 0x%lx, failed " - "XGetWindowAttributes\n", win->id); - fprintf(stderr, "window: 0x%lx, map_state: %d, state: %d, " - "transient: 0x%lx\n", - win->id, wa.map_state, state, win->transient); + warnx("window: 0x%lx, failed XGetWindowAttributes", + win->id); + warnx("window: 0x%lx, map_state: %d, state: %d, " + "transient: 0x%lx", win->id, wa.map_state, state, + win->transient); } - fprintf(stderr, "=================================\n"); + warnx("================================="); } #else void @@ -1172,7 +1185,7 @@ name_to_color(char *colorname) if (status) result = screen_def.pixel; else - fprintf(stderr, "color '%s' not found.\n", colorname); + warnx("color '%s' not found", colorname); return (result); } @@ -1239,9 +1252,8 @@ custom_region(char *val) y > DisplayHeight(display, sidx) || w + x > DisplayWidth(display, sidx) || h + y > DisplayHeight(display, sidx)) { - fprintf(stderr, "ignoring region %ux%u+%u+%u " - "- not within screen boundaries " - "(%ux%u)\n", w, h, x, y, + warnx("ignoring region %ux%u+%u+%u - not within screen " + "boundaries (%ux%u)", w, h, x, y, DisplayWidth(display, sidx), DisplayHeight(display, sidx)); return; } @@ -1344,11 +1356,10 @@ void bar_window_name(char *s, ssize_t sz, struct ws_win *cur_focus) { unsigned char *title; - unsigned long len; if (window_name_enabled && cur_focus != NULL) { - if ((title = get_win_name(display, cur_focus->id, a_netwmname, - a_utf8_string, &len)) != NULL) { + title = get_win_name(cur_focus->id); + if (title != NULL) { DNPRINTF(SWM_D_BAR, "bar_window_name: title: %s\n", title); @@ -1423,8 +1434,7 @@ bar_update(void) strlcpy((char *)bar_ext, b, sizeof bar_ext); } if (b == NULL && errno != EAGAIN) { - fprintf(stderr, "bar_update: bar_extra failed: " - "errno: %d %s\n", errno, strerror(errno)); + warn("bar_update: bar_extra failed"); bar_extra_stop(); } } else @@ -1435,7 +1445,8 @@ bar_update(void) else { time(&tmt); localtime_r(&tmt, &tm); - strftime(s, sizeof s, clock_format, &tm); + len = strftime(s, sizeof s, clock_format, &tm); + s[len] = '\0'; strlcat(s, " ", sizeof s); } @@ -1641,7 +1652,7 @@ getstate(Window w) unsigned char *p = NULL; unsigned long n; - if (!get_property(w, astate, 2L, astate, &n, &p)) + if (!get_property(w, astate, 2L, astate, &n, NULL, &p)) return (-1); if (n != 0) result = *((long *)p); @@ -1708,6 +1719,43 @@ config_win(struct ws_win *win, XConfigureRequestEvent *ev) ce.display = ev->display; ce.event = ev->window; ce.window = ev->window; + + /* make response appear more WM_SIZE_HINTS-compliant */ + if (win->sh_mask) + DNPRINTF(SWM_D_MISC, "config_win: hints: window: 0x%lx," + " sh_mask: %ld, min: %d x %d, max: %d x %d, inc: " + "%d x %d\n", win->id, win->sh_mask, SH_MIN_W(win), + SH_MIN_H(win), SH_MAX_W(win), SH_MAX_H(win), + SH_INC_W(win), SH_INC_H(win)); + + /* min size */ + if (SH_MIN(win)) { + /* the hint may be set... to 0! */ + if (SH_MIN_W(win) > 0 && ce.width < SH_MIN_W(win)) + ce.width = SH_MIN_W(win); + if (SH_MIN_H(win) > 0 && ce.height < SH_MIN_H(win)) + ce.height = SH_MIN_H(win); + } + + /* max size */ + if (SH_MAX(win)) { + /* may also be advertized as 0 */ + if (SH_MAX_W(win) > 0 && ce.width > SH_MAX_W(win)) + ce.width = SH_MAX_W(win); + if (SH_MAX_H(win) > 0 && ce.height > SH_MAX_H(win)) + ce.height = SH_MAX_H(win); + } + + /* resize increment. */ + if (SH_INC(win)) { + if (SH_INC_W(win) > 1 && ce.width > SH_INC_W(win)) + ce.width -= (ce.width - SH_MIN_W(win)) % + SH_INC_W(win); + if (SH_INC_H(win) > 1 && ce.height > SH_INC_H(win)) + ce.height -= (ce.height - SH_MIN_H(win)) % + SH_INC_H(win); + } + /* adjust x and y for requested border_width. */ ce.x += border_width - ev->border_width; ce.y += border_width - ev->border_width; @@ -1824,8 +1872,7 @@ restart(struct swm_region *r, union arg *args) unmap_all(); XCloseDisplay(display); execvp(start_argv[0], start_argv); - fprintf(stderr, "execvp failed\n"); - perror(" failed"); + warn("execvp failed"); quit(NULL, NULL); } @@ -1919,7 +1966,7 @@ spawn(int ws_idx, union arg *args, int close_fd) setenv("LD_PRELOAD", SWM_LIB, 1); if (asprintf(&ret, "%d", ws_idx) == -1) { - perror("_SWM_WS"); + warn("spawn: asprintf SWM_WS"); _exit(1); } setenv("_SWM_WS", ret, 1); @@ -1927,7 +1974,7 @@ spawn(int ws_idx, union arg *args, int close_fd) ret = NULL; if (asprintf(&ret, "%d", getpid()) == -1) { - perror("_SWM_PID"); + warn("spawn: asprintf _SWM_PID"); _exit(1); } setenv("_SWM_PID", ret, 1); @@ -1935,7 +1982,7 @@ spawn(int ws_idx, union arg *args, int close_fd) ret = NULL; if (setsid() == -1) { - perror("setsid"); + warn("spawn: setsid"); _exit(1); } @@ -1946,7 +1993,7 @@ spawn(int ws_idx, union arg *args, int close_fd) * leave stderr open to record errors */ if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) { - perror("open"); + warn("spawn: open"); _exit(1); } dup2(fd, STDIN_FILENO); @@ -1957,7 +2004,7 @@ spawn(int ws_idx, union arg *args, int close_fd) execvp(args->argv[0], args->argv); - perror("execvp"); + warn("spawn: execvp"); _exit(1); } @@ -2161,7 +2208,7 @@ focus_win(struct ws_win *win) PropModeReplace, (unsigned char *)&win->id,1); } - if (window_name_enabled) + if (window_name_enabled || title_class_enabled || title_name_enabled) bar_update(); } @@ -2340,7 +2387,7 @@ sort_windows(struct ws_win_list *wl) if (win->transient) { parent = find_window(win->transient); if (parent == NULL) { - fprintf(stderr, "not possible bug\n"); + warnx("not possible bug"); continue; } TAILQ_REMOVE(wl, win, entry); @@ -2484,7 +2531,6 @@ done: if (window_name_enabled || title_name_enabled || title_class_enabled) bar_update(); - return; } @@ -3268,32 +3314,28 @@ iconify(struct swm_region *r, union arg *args) } unsigned char * -get_win_name(Display *dpy, Window win, Atom wname, Atom stype, - unsigned long *slen) +get_win_name(Window win) { - int status, retfmt; - unsigned long nitems, nbytes, nextra; unsigned char *prop = NULL; - Atom rettype; + unsigned long nbytes, nitems; - status = XGetWindowProperty(dpy, win, wname, 0L, 0L, False, stype, - &rettype, &retfmt, &nitems, &nbytes, &prop); - if (status != Success) - return (NULL); - XFree(prop); - - status = XGetWindowProperty(dpy, win, wname, 0L, nbytes, False, - stype, &rettype, &retfmt, &nitems, &nextra, &prop); - if (status != Success) { + /* try _NET_WM_NAME first */ + if (get_property(win, a_netwmname, 0L, a_utf8_string, NULL, &nbytes, + &prop)) { XFree(prop); - return (NULL); + if (get_property(win, a_netwmname, nbytes, a_utf8_string, + &nitems, NULL, &prop)) + return (prop); } - if (rettype != stype) { - XFree(prop); + + /* fallback to WM_NAME */ + if (!get_property(win, a_wmname, 0L, a_string, NULL, &nbytes, &prop)) return (NULL); - } - *slen = nitems; - return (prop); + XFree(prop); + if (get_property(win, a_wmname, nbytes, a_string, &nitems, NULL, &prop)) + return (prop); + + return (NULL); } void @@ -3303,7 +3345,6 @@ uniconify(struct swm_region *r, union arg *args) FILE *lfile; unsigned char *name; int count = 0; - unsigned long len; DNPRINTF(SWM_D_MISC, "uniconify\n"); @@ -3335,8 +3376,7 @@ uniconify(struct swm_region *r, union arg *args) if (win->iconic == 0) continue; - name = get_win_name(display, win->id, a_netwmname, - a_utf8_string, &len); + name = get_win_name(win->id); if (name == NULL) continue; fprintf(lfile, "%s.%lu\n", name, win->id); @@ -3444,8 +3484,7 @@ search_win(struct swm_region *r, union arg *args) sw = calloc(1, sizeof(struct search_window)); if (sw == NULL) { - fprintf(stderr, "search_win: calloc: %s", - strerror(errno)); + warn("search_win: calloc"); fclose(lfile); search_win_cleanup(); return; @@ -3494,8 +3533,7 @@ search_resp_uniconify(char *resp, unsigned long len) TAILQ_FOREACH(win, &search_r->ws->winlist, entry) { if (win->iconic == 0) continue; - name = get_win_name(display, win->id, a_netwmname, - a_utf8_string, &len); + name = get_win_name(win->id); if (name == NULL) continue; if (asprintf(&s, "%s.%lu", name, win->id) == -1) { @@ -3618,13 +3656,13 @@ search_do_resp(void) searchpid = 0; if ((resp = calloc(1, MAX_RESP_LEN + 1)) == NULL) { - fprintf(stderr, "search: calloc\n"); + warn("search: calloc"); goto done; } rbytes = read(select_resp_pipe[0], resp, MAX_RESP_LEN); if (rbytes <= 0) { - fprintf(stderr, "search: read error: %s\n", strerror(errno)); + warn("search: read error"); goto done; } resp[rbytes] = '\0'; @@ -4280,7 +4318,7 @@ struct key { char *spawn_name; }; TAILQ_HEAD(key_list, key); -struct key_list keys = TAILQ_HEAD_INITIALIZER(keys); +struct key_list keys = TAILQ_HEAD_INITIALIZER(keys); /* mouse */ enum { client_click, root_click }; @@ -4300,8 +4338,8 @@ struct button { void update_modkey(unsigned int mod) { - int i; - struct key *kp; + int i; + struct key *kp; mod_key = mod; TAILQ_FOREACH(kp, &keys, entry) @@ -4343,8 +4381,7 @@ spawn_expand(struct swm_region *r, union arg *args, char *spawn_name, prog = &spawns[i]; } if (prog == NULL) { - fprintf(stderr, "spawn_custom: program %s not found\n", - spawn_name); + warnx("spawn_custom: program %s not found", spawn_name); return (-1); } @@ -4508,8 +4545,7 @@ setspawn(struct spawn_prog *prog) } if (prog->argv == NULL) { - fprintf(stderr, - "error: setspawn: cannot find program: %s", prog->name); + warnx("error: setspawn: cannot find program: %s", prog->name); free(prog); return; } @@ -4521,8 +4557,7 @@ setspawn(struct spawn_prog *prog) spawns = malloc((size_t)spawns_size * sizeof(struct spawn_prog)); if (spawns == NULL) { - fprintf(stderr, "setspawn: malloc failed\n"); - perror(" failed"); + warn("setspawn: malloc failed"); quit(NULL, NULL); } } else if (spawns_length == spawns_size) { @@ -4531,8 +4566,7 @@ setspawn(struct spawn_prog *prog) spawns = realloc(spawns, (size_t)spawns_size * sizeof(struct spawn_prog)); if (spawns == NULL) { - fprintf(stderr, "setspawn: realloc failed\n"); - perror(" failed"); + warn("setspawn: realloc failed"); quit(NULL, NULL); } } @@ -4543,9 +4577,9 @@ setspawn(struct spawn_prog *prog) i = spawns_length++; spawns[i] = *prog; } else { - fprintf(stderr, "spawns array problem?\n"); + warnx("spawns array problem?"); if (spawns == NULL) { - fprintf(stderr, "spawns array is NULL!\n"); + warnx("spawns array is NULL!"); quit(NULL, NULL); } } @@ -4682,7 +4716,7 @@ strdupsafe(char *str) void key_insert(unsigned int mod, KeySym ks, enum keyfuncid kfid, char *spawn_name) { - struct key *kp; + struct key *kp; DNPRINTF(SWM_D_KEY, "key_insert: enter %s [%s]\n", keyfuncs[kfid].name, spawn_name); @@ -4728,7 +4762,7 @@ void setkeybinding(unsigned int mod, KeySym ks, enum keyfuncid kfid, char *spawn_name) { - struct key *kp; + struct key *kp; DNPRINTF(SWM_D_KEY, "setkeybinding: enter %s [%s]\n", keyfuncs[kfid].name, spawn_name); @@ -4882,7 +4916,7 @@ setup_keys(void) void clear_keys(void) { - struct key *kp_loop, *kp_next; + struct key *kp_loop, *kp_next; kp_loop = TAILQ_FIRST(&keys); while (kp_loop != NULL) { @@ -5028,79 +5062,78 @@ parsequirks(char *qstr, unsigned long *quirk) } void -setquirk(const char *class, const char *name, const int quirk) +quirk_insert(const char *class, const char *name, unsigned long quirk) { - int i, j; + struct quirk *qp; - /* find existing */ - for (i = 0; i < quirks_length; i++) { - if (!strcmp(quirks[i].class, class) && - !strcmp(quirks[i].name, name)) { - if (!quirk) { - /* found: delete */ - DNPRINTF(SWM_D_QUIRK, - "setquirk: delete #%d %s:%s\n", - i, quirks[i].class, quirks[i].name); - free(quirks[i].class); - free(quirks[i].name); - j = quirks_length - 1; - if (i < j) - quirks[i] = quirks[j]; - quirks_length--; - return; - } else { - /* found: replace */ - DNPRINTF(SWM_D_QUIRK, - "setquirk: replace #%d %s:%s\n", - i, quirks[i].class, quirks[i].name); - free(quirks[i].class); - free(quirks[i].name); - quirks[i].class = strdup(class); - quirks[i].name = strdup(name); - quirks[i].quirk = quirk; - return; - } + DNPRINTF(SWM_D_QUIRK, "quirk_insert: %s:%s [%lu]\n", class, name, + quirk); + + if ((qp = malloc(sizeof *qp)) == NULL) + err(1, "quirk_insert: malloc"); + if ((qp->class = strdup(class)) == NULL) + err(1, "quirk_insert: strdup"); + if ((qp->name = strdup(name)) == NULL) + err(1, "quirk_insert: strdup"); + + qp->quirk = quirk; + TAILQ_INSERT_TAIL(&quirks, qp, entry); + + DNPRINTF(SWM_D_QUIRK, "quirk_insert: leave\n"); +} + +void +quirk_remove(struct quirk *qp) +{ + DNPRINTF(SWM_D_QUIRK, "quirk_remove: %s:%s [%lu]\n", qp->class, + qp->name, qp->quirk); + + TAILQ_REMOVE(&quirks, qp, entry); + free(qp->class); + free(qp->name); + free(qp); + + DNPRINTF(SWM_D_QUIRK, "quirk_remove: leave\n"); +} + +void +quirk_replace(struct quirk *qp, const char *class, const char *name, + unsigned long quirk) +{ + DNPRINTF(SWM_D_QUIRK, "quirk_replace: %s:%s [%lu]\n", qp->class, + qp->name, qp->quirk); + + quirk_remove(qp); + quirk_insert(class, name, quirk); + + DNPRINTF(SWM_D_QUIRK, "quirk_replace: leave\n"); +} + +void +setquirk(const char *class, const char *name, unsigned long quirk) +{ + struct quirk *qp; + + DNPRINTF(SWM_D_QUIRK, "setquirk: enter %s:%s [%lu]\n", class, name, + quirk); + + TAILQ_FOREACH(qp, &quirks, entry) { + if (!strcmp(qp->class, class) && !strcmp(qp->name, name)) { + if (!quirk) + quirk_remove(qp); + else + quirk_replace(qp, class, name, quirk); + DNPRINTF(SWM_D_QUIRK, "setquirk: leave\n"); + return; } } if (!quirk) { - fprintf(stderr, - "error: setquirk: cannot find class/name combination"); + warnx("error: setquirk: cannot find class/name combination"); return; } - /* not found: add */ - if (quirks_size == 0 || quirks == NULL) { - quirks_size = 4; - DNPRINTF(SWM_D_QUIRK, "setquirk: init list %d\n", quirks_size); - quirks = malloc((size_t)quirks_size * sizeof(struct quirk)); - if (quirks == NULL) { - fprintf(stderr, "setquirk: malloc failed\n"); - perror(" failed"); - quit(NULL, NULL); - } - } else if (quirks_length == quirks_size) { - quirks_size *= 2; - DNPRINTF(SWM_D_QUIRK, "setquirk: grow list %d\n", quirks_size); - quirks = realloc(quirks, - (size_t)quirks_size * sizeof(struct quirk)); - if (quirks == NULL) { - fprintf(stderr, "setquirk: realloc failed\n"); - perror(" failed"); - quit(NULL, NULL); - } - } - if (quirks_length < quirks_size) { - DNPRINTF(SWM_D_QUIRK, "setquirk: add %d\n", quirks_length); - j = quirks_length++; - quirks[j].class = strdup(class); - quirks[j].name = strdup(name); - quirks[j].quirk = quirk; - } else { - fprintf(stderr, "quirks array problem?\n"); - if (quirks == NULL) { - fprintf(stderr, "quirks array problem!\n"); - quit(NULL, NULL); - } - } + + quirk_insert(class, name, quirk); + DNPRINTF(SWM_D_QUIRK, "setquirk: leave\n"); } int @@ -5496,7 +5529,7 @@ conf_load(char *filename, int keymapping) DNPRINTF(SWM_D_CONF, "conf_load: begin\n"); if (filename == NULL) { - fprintf(stderr, "conf_load: no filename\n"); + warnx("conf_load: no filename"); return (1); } if ((config = fopen(filename, "r")) == NULL) { @@ -5575,12 +5608,9 @@ conf_load(char *filename, int keymapping) optval = strdup(cp); /* call function to deal with it all */ if (configopt[optind].func(optsub, optval, - configopt[optind].funcflags) != 0) { - fprintf(stderr, "%s line %zd: %s\n", - filename, lineno, line); + configopt[optind].funcflags) != 0) errx(1, "%s: line %zd: invalid data for %s", filename, lineno, configopt[optind].optname); - } free(optval); free(optsub); free(line); @@ -5615,7 +5645,7 @@ set_child_transient(struct ws_win *win, Window *trans) " for 0x%lx trans 0x%lx\n", win->id, win->transient); if (win->hints == NULL) { - fprintf(stderr, "no hints for 0x%lx\n", win->id); + warnx("no hints for 0x%lx", win->id); return; } @@ -5627,8 +5657,7 @@ set_child_transient(struct ws_win *win, Window *trans) XFree(wmh); if ((wmh = XGetWMHints(display, w->id)) == NULL) { - fprintf(stderr, "can't get hints for 0x%lx\n", - w->id); + warnx("can't get hints for 0x%lx", w->id); continue; } @@ -5710,6 +5739,7 @@ manage_window(Window id) const char *errstr; XWindowChanges wc; struct pid_e *p; + struct quirk *qp; if ((win = find_window(id)) != NULL) return (win); /* already being managed */ @@ -5745,7 +5775,7 @@ manage_window(Window id) False, XA_STRING, &type, &format, &nitems, &bytes, &prop); } XGetWindowAttributes(display, id, &win->wa); - XGetWMNormalHints(display, id, &win->sh, &mask); + XGetWMNormalHints(display, id, &win->sh, &win->sh_mask); win->hints = XGetWMHints(display, id); XGetTransientForHint(display, id, &trans); if (trans) { @@ -5798,9 +5828,8 @@ manage_window(Window id) if (ww->ws->r) r = ww->ws->r; else - fprintf(stderr, - "manage_window: fix this " - "bug mcbride\n"); + warnx("manage_window: fix this " + "bug mcbride"); border_me = 1; } } @@ -5846,17 +5875,17 @@ manage_window(Window id) border_me = 1; } - for (i = 0; i < quirks_length; i++){ - if (!strcmp(win->ch.res_class, quirks[i].class) && - !strcmp(win->ch.res_name, quirks[i].name)) { + TAILQ_FOREACH(qp, &quirks, entry) { + if (!strcmp(win->ch.res_class, qp->class) && + !strcmp(win->ch.res_name, qp->name)) { DNPRINTF(SWM_D_CLASS, "manage_window: found: " "class: %s, name: %s\n", win->ch.res_class, win->ch.res_name); - if (quirks[i].quirk & SWM_Q_FLOAT) { + if (qp->quirk & SWM_Q_FLOAT) { win->floating = 1; border_me = 1; } - win->quirks = quirks[i].quirk; + win->quirks = qp->quirk; } } } @@ -5954,7 +5983,10 @@ unmanage_window(struct ws_win *win) focus_prev(win); - XFree(win->hints); + if (win->hints) { + XFree(win->hints); + win->hints = NULL; + } TAILQ_REMOVE(&win->ws->winlist, win, entry); TAILQ_INSERT_TAIL(&win->ws->unmanagedlist, win, entry); @@ -6083,14 +6115,13 @@ void configurenotify(XEvent *e) { struct ws_win *win; - long mask; DNPRINTF(SWM_D_EVENT, "configurenotify: window: 0x%lx\n", e->xconfigure.window); win = find_window(e->xconfigure.window); if (win) { - XGetWMNormalHints(display, win->id, &win->sh, &mask); + XGetWMNormalHints(display, win->id, &win->sh, &win->sh_mask); adjust_font(win); if (font_adjusted) stack(); @@ -6281,7 +6312,7 @@ focusevent(XEvent *e) SWM_S_COLOR_FOCUS : SWM_S_COLOR_UNFOCUS].color); break; default: - fprintf(stderr, "ignoring focusevent\n"); + warnx("ignoring focusevent"); DNPRINTF(SWM_D_FOCUS, "ignoring focusevent\n"); break; } @@ -6369,11 +6400,11 @@ propertynotify(XEvent *e) case XA_WM_NORMAL_HINTS: long mask; XGetWMNormalHints(display, win->id, &win->sh, &mask); - fprintf(stderr, "normal hints: flag 0x%x\n", win->sh.flags); + warnx("normal hints: flag 0x%x", win->sh.flags); if (win->sh.flags & PMinSize) { WIDTH(win) = win->sh.min_width; HEIGHT(win) = win->sh.min_height; - fprintf(stderr, "min %d %d\n", WIDTH(win), HEIGHT(win)); + warnx("min %d %d", WIDTH(win), HEIGHT(win)); } XMoveResizeWindow(display, win->id, X(win), Y(win), WIDTH(win), HEIGHT(win)); @@ -6510,7 +6541,7 @@ xerror_start(Display *d, XErrorEvent *ee) int xerror(Display *d, XErrorEvent *ee) { - /* fprintf(stderr, "error: %p %p\n", display, ee); */ + /* warnx("error: %p %p", display, ee); */ return (-1); } @@ -6869,8 +6900,7 @@ main(int argc, char *argv[]) struct sigaction sact; start_argv = argv; - fprintf(stderr, "Welcome to scrotwm V%s Build: %s\n", - SCROTWM_VERSION, buildstr); + warnx("Welcome to scrotwm V%s Build: %s", SCROTWM_VERSION, buildstr); if (!setlocale(LC_CTYPE, "") || !setlocale(LC_TIME, "") || !XSupportsLocale()) warnx("no locale support");