#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)
struct swm_screen *s; /* always valid, never changes */
XWindowAttributes wa;
XSizeHints sh;
+ long sh_mask;
XClassHint ch;
XWMHints *hints;
};
int horizontal_msize;
int horizontal_mwin;
int horizontal_stacks;
+ int horizontal_flip;
int vertical_msize;
int vertical_mwin;
int vertical_stacks;
+ int vertical_flip;
} l_state;
};
#define SWM_ARG_ID_MASTERGROW (21)
#define SWM_ARG_ID_MASTERADD (22)
#define SWM_ARG_ID_MASTERDEL (23)
+#define SWM_ARG_ID_FLIPLAYOUT (24)
#define SWM_ARG_ID_STACKRESET (30)
#define SWM_ARG_ID_STACKINIT (31)
#define SWM_ARG_ID_CYCLEWS_UP (40)
#define SWM_Q_FOCUSPREV (1<<5) /* focus on caller */
};
TAILQ_HEAD(quirk_list, quirk);
-struct quirk_list quirks = TAILQ_HEAD_INITIALIZER(quirks);
+struct quirk_list quirks = TAILQ_HEAD_INITIALIZER(quirks);
/*
* Supported EWMH hints should be added to
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;
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];
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);
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;
char *
xrandr_geteventname(XEvent *e)
{
- char *name = NULL;
+ char *name = NULL;
switch(e->type - xrandr_eventbase) {
case RRScreenChangeNotify:
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
if (status)
result = screen_def.pixel;
else
- fprintf(stderr, "color '%s' not found.\n", colorname);
+ warnx("color '%s' not found", colorname);
return (result);
}
{
strlcpy(ws->stacker, "[ ]", sizeof ws->stacker);
if (ws->cur_layout->l_stack == vertical_stack)
- snprintf(ws->stacker, sizeof ws->stacker, "[%d|%d]",
+ snprintf(ws->stacker, sizeof ws->stacker,
+ ws->l_state.vertical_flip ? "[%d>%d]" : "[%d|%d]",
ws->l_state.vertical_mwin, ws->l_state.vertical_stacks);
if (ws->cur_layout->l_stack == horizontal_stack)
- snprintf(ws->stacker, sizeof ws->stacker, "[%d-%d]",
+ snprintf(ws->stacker, sizeof ws->stacker,
+ ws->l_state.horizontal_flip ? "[%dv%d]" : "[%d-%d]",
ws->l_state.horizontal_mwin, ws->l_state.horizontal_stacks);
}
{
strlcpy(ws->stacker, "[ ]", sizeof ws->stacker);
if (ws->cur_layout->l_stack == vertical_stack)
- strlcpy(ws->stacker, "[|]", sizeof ws->stacker);
+ strlcpy(ws->stacker, ws->l_state.vertical_flip ? "[>]" : "[|]",
+ sizeof ws->stacker);
if (ws->cur_layout->l_stack == horizontal_stack)
- strlcpy(ws->stacker, "[-]", sizeof ws->stacker);
+ strlcpy(ws->stacker, ws->l_state.horizontal_flip ? "[v]" : "[-]",
+ sizeof ws->stacker);
}
void
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;
}
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);
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
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);
}
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);
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;
unmap_all();
XCloseDisplay(display);
execvp(start_argv[0], start_argv);
- fprintf(stderr, "execvp failed\n");
- perror(" failed");
+ warn("execvp failed");
quit(NULL, NULL);
}
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);
ret = NULL;
if (asprintf(&ret, "%d", getpid()) == -1) {
- perror("_SWM_PID");
+ warn("spawn: asprintf _SWM_PID");
_exit(1);
}
setenv("_SWM_PID", ret, 1);
ret = NULL;
if (setsid() == -1) {
- perror("setsid");
+ warn("spawn: setsid");
_exit(1);
}
* 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);
execvp(args->argv[0], args->argv);
- perror("execvp");
+ warn("spawn: execvp");
_exit(1);
}
PropModeReplace, (unsigned char *)&win->id,1);
}
- if (window_name_enabled)
+ if (window_name_enabled || title_class_enabled || title_name_enabled)
bar_update();
}
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);
if (window_name_enabled || title_name_enabled ||
title_class_enabled)
bar_update();
-
return;
}
if (ws->l_state.vertical_stacks > 1)
ws->l_state.vertical_stacks--;
break;
+ case SWM_ARG_ID_FLIPLAYOUT:
+ ws->l_state.vertical_flip = !ws->l_state.vertical_flip;
+ break;
default:
return;
}
{
DNPRINTF(SWM_D_STACK, "vertical_stack: workspace: %d\n", ws->idx);
- stack_master(ws, g, 0, 0);
+ stack_master(ws, g, 0, ws->l_state.vertical_flip);
}
void
if (ws->l_state.horizontal_stacks > 1)
ws->l_state.horizontal_stacks--;
break;
+ case SWM_ARG_ID_FLIPLAYOUT:
+ ws->l_state.horizontal_flip = !ws->l_state.horizontal_flip;
+ break;
default:
return;
}
{
DNPRINTF(SWM_D_STACK, "horizontal_stack: workspace: %d\n", ws->idx);
- stack_master(ws, g, 1, 0);
+ stack_master(ws, g, 1, ws->l_state.horizontal_flip);
}
/* fullscreen view */
}
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
FILE *lfile;
unsigned char *name;
int count = 0;
- unsigned long len;
DNPRINTF(SWM_D_MISC, "uniconify\n");
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);
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;
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) {
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';
/* user/key callable function IDs */
enum keyfuncid {
kf_cycle_layout,
+ kf_flip_layout,
kf_stack_reset,
kf_master_shrink,
kf_master_grow,
} keyfuncs[kf_invalid + 1] = {
/* name function argument */
{ "cycle_layout", cycle_layout, {0} },
+ { "flip_layout", stack_config, {.id = SWM_ARG_ID_FLIPLAYOUT} },
{ "stack_reset", stack_config, {.id = SWM_ARG_ID_STACKRESET} },
{ "master_shrink", stack_config, {.id = SWM_ARG_ID_MASTERSHRINK} },
{ "master_grow", stack_config, {.id = SWM_ARG_ID_MASTERGROW} },
/* spawn */
struct spawn_prog {
+ TAILQ_ENTRY(spawn_prog) entry;
char *name;
int argc;
char **argv;
};
-
-int spawns_size = 0, spawns_length = 0;
-struct spawn_prog *spawns = NULL;
+TAILQ_HEAD(spawn_list, spawn_prog);
+struct spawn_list spawns = TAILQ_HEAD_INITIALIZER(spawns);
int
spawn_expand(struct swm_region *r, union arg *args, char *spawn_name,
DNPRINTF(SWM_D_SPAWN, "spawn_expand: %s\n", spawn_name);
/* find program */
- for (i = 0; i < spawns_length; i++) {
- if (!strcasecmp(spawn_name, spawns[i].name))
- prog = &spawns[i];
+ TAILQ_FOREACH(prog, &spawns, entry) {
+ if (!strcasecmp(spawn_name, prog->name))
+ break;
}
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);
}
}
void
-setspawn(struct spawn_prog *prog)
+spawn_insert(char *name, char *args)
{
- int i, j;
+ char *arg, *cp, *ptr;
+ struct spawn_prog *sp;
- if (prog == NULL || prog->name == NULL)
- return;
+ DNPRINTF(SWM_D_SPAWN, "spawn_insert: %s\n", name);
- /* find existing */
- for (i = 0; i < spawns_length; i++) {
- if (!strcmp(spawns[i].name, prog->name)) {
- /* found */
- if (prog->argv == NULL) {
- /* delete */
- DNPRINTF(SWM_D_SPAWN,
- "setspawn: delete #%d: %s\n",
- i, spawns[i].name);
- free(spawns[i].name);
- for (j = 0; j < spawns[i].argc; j++)
- free(spawns[i].argv[j]);
- free(spawns[i].argv);
- j = spawns_length - 1;
- if (i < j)
- spawns[i] = spawns[j];
- spawns_length--;
- free(prog->name);
- } else {
- /* replace */
- DNPRINTF(SWM_D_SPAWN,
- "setspawn: replace #%d: %s\n",
- i, spawns[i].name);
- free(spawns[i].name);
- for (j = 0; j < spawns[i].argc; j++)
- free(spawns[i].argv[j]);
- free(spawns[i].argv);
- spawns[i] = *prog;
- }
- /* found case handled */
- free(prog);
- return;
- }
+ if ((sp = calloc(1, sizeof *sp)) == NULL)
+ err(1, "spawn_insert: malloc");
+ if ((sp->name = strdup(name)) == NULL)
+ err(1, "spawn_insert: strdup");
+
+ /* convert the arguments to an argument list */
+ if ((ptr = cp = strdup(args)) == NULL)
+ err(1, "spawn_insert: strdup");
+ while ((arg = strsep(&ptr, " \t")) != NULL) {
+ /* empty field; skip it */
+ if (*arg == '\0')
+ continue;
+
+ sp->argc++;
+ if ((sp->argv = realloc(sp->argv, sp->argc *
+ sizeof *sp->argv)) == NULL)
+ err(1, "spawn_insert: realloc");
+ if ((sp->argv[sp->argc - 1] = strdup(arg)) == NULL)
+ err(1, "spawn_insert: strdup");
}
+ free(cp);
+
+ TAILQ_INSERT_TAIL(&spawns, sp, entry);
+ DNPRINTF(SWM_D_SPAWN, "spawn_insert: leave\n");
+}
- if (prog->argv == NULL) {
- fprintf(stderr,
- "error: setspawn: cannot find program: %s", prog->name);
- free(prog);
+void
+spawn_remove(struct spawn_prog *sp)
+{
+ int i;
+
+ DNPRINTF(SWM_D_SPAWN, "spawn_remove: %s\n", sp->name);
+
+ TAILQ_REMOVE(&spawns, sp, entry);
+ for (i = 0; i < sp->argc; i++)
+ free(sp->argv[i]);
+ free(sp->argv);
+ free(sp->name);
+ free(sp);
+
+ DNPRINTF(SWM_D_SPAWN, "spawn_remove: leave\n");
+}
+
+void
+spawn_replace(struct spawn_prog *sp, char *name, char *args)
+{
+ DNPRINTF(SWM_D_SPAWN, "spawn_replace: %s [%s]\n", sp->name, name);
+
+ spawn_remove(sp);
+ spawn_insert(name, args);
+
+ DNPRINTF(SWM_D_SPAWN, "spawn_replace: leave\n");
+}
+
+void
+setspawn(char *name, char *args)
+{
+ struct spawn_prog *sp;
+
+ DNPRINTF(SWM_D_SPAWN, "setspawn: %s\n", name);
+
+ if (name == NULL)
return;
- }
- /* not found: add */
- if (spawns_size == 0 || spawns == NULL) {
- spawns_size = 4;
- DNPRINTF(SWM_D_SPAWN, "setspawn: init list %d\n", spawns_size);
- spawns = malloc((size_t)spawns_size *
- sizeof(struct spawn_prog));
- if (spawns == NULL) {
- fprintf(stderr, "setspawn: malloc failed\n");
- perror(" failed");
- quit(NULL, NULL);
- }
- } else if (spawns_length == spawns_size) {
- spawns_size *= 2;
- DNPRINTF(SWM_D_SPAWN, "setspawn: grow list %d\n", spawns_size);
- spawns = realloc(spawns, (size_t)spawns_size *
- sizeof(struct spawn_prog));
- if (spawns == NULL) {
- fprintf(stderr, "setspawn: realloc failed\n");
- perror(" failed");
- quit(NULL, NULL);
+ TAILQ_FOREACH(sp, &spawns, entry) {
+ if (!strcmp(sp->name, name)) {
+ if (*args == '\0')
+ spawn_remove(sp);
+ else
+ spawn_replace(sp, name, args);
+ DNPRINTF(SWM_D_SPAWN, "setspawn: leave\n");
+ return;
}
}
-
- if (spawns_length < spawns_size) {
- DNPRINTF(SWM_D_SPAWN, "setspawn: add #%d %s\n",
- spawns_length, prog->name);
- i = spawns_length++;
- spawns[i] = *prog;
- } else {
- fprintf(stderr, "spawns array problem?\n");
- if (spawns == NULL) {
- fprintf(stderr, "spawns array is NULL!\n");
- quit(NULL, NULL);
- }
+ if (*args == '\0') {
+ warnx("error: setspawn: cannot find program: %s", name);
+ return;
}
- free(prog);
+
+ spawn_insert(name, args);
+ DNPRINTF(SWM_D_SPAWN, "setspawn: leave\n");
}
int
setconfspawn(char *selector, char *value, int flags)
{
- struct spawn_prog *prog;
- char *vp, *cp, *word;
-
DNPRINTF(SWM_D_SPAWN, "setconfspawn: [%s] [%s]\n", selector, value);
- if ((prog = calloc(1, sizeof *prog)) == NULL)
- err(1, "setconfspawn: calloc prog");
- prog->name = strdup(selector);
- if (prog->name == NULL)
- err(1, "setconfspawn prog->name");
- if ((cp = vp = strdup(value)) == NULL)
- err(1, "setconfspawn: strdup(value) ");
- while ((word = strsep(&cp, " \t")) != NULL) {
- DNPRINTF(SWM_D_SPAWN, "setconfspawn: arg [%s]\n", word);
- if (cp)
- cp += (long)strspn(cp, " \t");
- if (strlen(word) > 0) {
- prog->argc++;
- if ((prog->argv = realloc(prog->argv,
- prog->argc * sizeof(char *))) == NULL)
- err(1, "setconfspawn: realloc");
- if ((prog->argv[prog->argc - 1] = strdup(word)) == NULL)
- err(1, "setconfspawn: strdup");
- }
- }
- free(vp);
- setspawn(prog);
+ setspawn(selector, value);
DNPRINTF(SWM_D_SPAWN, "setconfspawn: done\n");
return (0);
enum keyfuncid kfid;
unsigned int mod;
KeySym ks;
- int i;
+ struct spawn_prog *sp;
DNPRINTF(SWM_D_KEY, "setconfbinding: enter\n");
if (selector == NULL) {
DNPRINTF(SWM_D_KEY, "setconfbinding: unbind %s\n", value);
}
}
/* search by custom spawn name */
- for (i = 0; i < spawns_length; i++) {
- if (strcasecmp(selector, spawns[i].name) == 0) {
+ TAILQ_FOREACH(sp, &spawns, entry) {
+ if (strcasecmp(selector, sp->name) == 0) {
DNPRINTF(SWM_D_KEY, "setconfbinding: %s: match\n",
selector);
if (parsekeys(value, mod_key, &mod, &ks) == 0) {
setkeybinding(mod, ks, kf_spawn_custom,
- spawns[i].name);
+ sp->name);
return (0);
} else
return (1);
setup_keys(void)
{
setkeybinding(MODKEY, XK_space, kf_cycle_layout,NULL);
+ setkeybinding(MODKEY|ShiftMask, XK_backslash, kf_flip_layout, NULL);
setkeybinding(MODKEY|ShiftMask, XK_space, kf_stack_reset, NULL);
setkeybinding(MODKEY, XK_h, kf_master_shrink,NULL);
setkeybinding(MODKEY, XK_l, kf_master_grow, NULL);
void
quirk_insert(const char *class, const char *name, unsigned long quirk)
{
- struct quirk *qp;
+ struct quirk *qp;
DNPRINTF(SWM_D_QUIRK, "quirk_insert: %s:%s [%lu]\n", class, name,
quirk);
void
setquirk(const char *class, const char *name, unsigned long quirk)
{
- struct quirk *qp;
+ struct quirk *qp;
DNPRINTF(SWM_D_QUIRK, "setquirk: enter %s:%s [%lu]\n", class, name,
- quirk);
+ quirk);
TAILQ_FOREACH(qp, &quirks, entry) {
if (!strcmp(qp->class, class) && !strcmp(qp->name, name)) {
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) {
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);
" 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;
}
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;
}
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) {
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;
}
}
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);
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();
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;
}
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));
int
xerror(Display *d, XErrorEvent *ee)
{
- /* fprintf(stderr, "error: %p %p\n", display, ee); */
+ /* warnx("error: %p %p", display, ee); */
return (-1);
}
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");