bool bar_extra = false;
int bar_height = 0;
int bar_justify = SWM_BAR_JUSTIFY_LEFT;
-char *bar_format = NULL;
+char *bar_format = NULL;
bool stack_enabled = true;
bool clock_enabled = true;
bool iconic_enabled = false;
time_t time_started;
#endif
pid_t bar_pid;
-XFontSet bar_fs;
+XFontSet bar_fs = NULL;
XFontSetExtents *bar_fs_extents;
-XftFont *bar_font;
+XftFont *bar_font = NULL;
bool bar_font_legacy = true;
-char *bar_fonts;
+char *bar_fonts = NULL;
XftColor bar_font_color;
XftColor search_font_color;
-struct passwd *pwd;
-char *startup_exception;
+char *startup_exception = NULL;
unsigned int nr_exceptions = 0;
/* layout manager data */
regex_t regex_name;
uint32_t quirk;
int ws; /* Initial workspace. */
-#define SWM_Q_FLOAT (1<<0) /* float this window */
-#define SWM_Q_TRANSSZ (1<<1) /* transiend window size too small */
-#define SWM_Q_ANYWHERE (1<<2) /* don't position this window */
-#define SWM_Q_XTERM_FONTADJ (1<<3) /* adjust xterm fonts when resizing */
-#define SWM_Q_FULLSCREEN (1<<4) /* remove border */
-#define SWM_Q_FOCUSPREV (1<<5) /* focus on caller */
+#define SWM_Q_FLOAT (1<<0) /* Float this window. */
+#define SWM_Q_TRANSSZ (1<<1) /* Transient window size too small. */
+#define SWM_Q_ANYWHERE (1<<2) /* Don't position this window */
+#define SWM_Q_XTERM_FONTADJ (1<<3) /* Adjust xterm fonts when resizing. */
+#define SWM_Q_FULLSCREEN (1<<4) /* Remove border when fullscreen. */
+#define SWM_Q_FOCUSPREV (1<<5) /* Focus on caller. */
#define SWM_Q_NOFOCUSONMAP (1<<6) /* Don't focus on window when mapped. */
#define SWM_Q_FOCUSONMAP_SINGLE (1<<7) /* Only focus if single win of type. */
#define SWM_Q_OBEYAPPFOCUSREQ (1<<8) /* Focus when applications ask. */
#define SWM_Q_IGNOREPID (1<<9) /* Ignore PID when determining ws. */
#define SWM_Q_IGNORESPAWNWS (1<<10) /* Ignore _SWM_WS when managing win. */
#define SWM_Q_NOFOCUSCYCLE (1<<11) /* Remove from normal focus cycle. */
+#define SWM_Q_MINIMALBORDER (1<<12) /* No border when floating/unfocused. */
};
TAILQ_HEAD(quirk_list, quirk);
struct quirk_list quirks = TAILQ_HEAD_INITIALIZER(quirks);
void check_conn(void);
void clear_keys(void);
int clear_maximized(struct workspace *);
+void clear_quirks(void);
+void clear_spawns(void);
void clientmessage(xcb_client_message_event_t *);
void client_msg(struct ws_win *, xcb_atom_t, xcb_timestamp_t);
int conf_load(const char *, int);
/* bar_urgent already adds the space before the last asterisk */
if (urgent_enabled)
- strlcat(fmtnew, "* +U*+4<", sz);
+ strlcat(fmtnew, (urgent_collapse ? "*+U*+4<" : "* +U*+4<"), sz);
if (window_class_enabled) {
strlcat(fmtnew, "+C", sz);
void
xft_init(struct swm_region *r)
{
- char *font, *d, *search;
+ char *font, *str, *search;
XRenderColor color;
if (bar_font == NULL) {
- if ((d = strdup(bar_fonts)) == NULL)
+ if ((search = str = strdup(bar_fonts)) == NULL)
errx(1, "insufficient memory.");
- search = d;
+
while ((font = strsep(&search, ",")) != NULL) {
if (*font == '\0')
continue;
break;
}
}
- free(d);
+ free(str);
}
if (bar_font == NULL)
uint16_t data[2] = { state, XCB_ATOM_NONE };
DNPRINTF(SWM_D_EVENT, "set_win_state: win %#x, state: %u\n",
- win->id, state);
+ WINID(win), state);
if (win == NULL)
return;
struct ws_win *target = NULL;
struct workspace *ws;
+ DNPRINTF(SWM_D_EVENT, "lower_window: win %#x\n", WINID(win));
+
if (win == NULL)
return;
ws = win->ws;
- DNPRINTF(SWM_D_EVENT, "lower_window: win %#x\n", win->id);
-
TAILQ_FOREACH(target, &ws->stack, stack_entry) {
if (target == win || ICONIC(target))
continue;
struct ws_win *target = NULL;
struct workspace *ws;
+ DNPRINTF(SWM_D_EVENT, "raise_window: win %#x\n", WINID(win));
+
if (win == NULL)
return;
- ws = win->ws;
- DNPRINTF(SWM_D_EVENT, "raise_window: win %#x\n", win->id);
+ ws = win->ws;
TAILQ_FOREACH(target, &ws->stack, stack_entry) {
if (target == win || ICONIC(target))
void
kill_refs(struct ws_win *win)
{
- int i, x, num_screens;
- struct swm_region *r;
struct workspace *ws;
+ struct ws_win *w;
+ int i, j, num_screens;
if (win == NULL)
return;
num_screens = get_screen_count();
- for (i = 0; i < num_screens; i++)
- TAILQ_FOREACH(r, &screens[i].rl, entry)
- for (x = 0; x < workspace_limit; x++) {
- ws = &r->s->ws[x];
- if (win == ws->focus)
- ws->focus = NULL;
- if (win == ws->focus_prev)
- ws->focus_prev = NULL;
- }
+ for (i = 0; i < num_screens; i++) {
+ for (j = 0; j < workspace_limit; j++) {
+ ws = &screens[i].ws[j];
+
+ if (win == ws->focus)
+ ws->focus = NULL;
+ if (win == ws->focus_prev)
+ ws->focus_prev = NULL;
+
+ if (TRANS(win))
+ TAILQ_FOREACH(w, &ws->winlist, entry)
+ if (win == w->focus_child)
+ w->focus_child = NULL;
+ }
+ }
}
int
if (win->ws->always_raise)
raise_window(win);
+ /* Update border width */
+ if (win->bordered && (win->quirks & SWM_Q_MINIMALBORDER) &&
+ FLOATING(win)) {
+ win->bordered = 0;
+ X(win) += border_width;
+ Y(win) += border_width;
+ update_window(win);
+ }
+
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win->s->root,
ewmh[_NET_ACTIVE_WINDOW].atom, XCB_ATOM_WINDOW, 32, 1, &none);
&cfw->s->c[(MAXIMIZED(cfw) ?
SWM_S_COLOR_UNFOCUS_MAXIMIZED :
SWM_S_COLOR_UNFOCUS)].pixel);
+
+ /* Update border width */
+ if (cfw->bordered &&
+ (cfw->quirks & SWM_Q_MINIMALBORDER) &&
+ FLOATING(cfw)) {
+ cfw->bordered = 0;
+ X(cfw) += border_width;
+ Y(cfw) += border_width;
+ update_window(cfw);
+ }
} else {
unfocus_win(cfw);
}
ws->focus = win;
}
- /* If this window directs focus to a child window, then clear. */
- if (win->focus_child)
- win->focus_child = NULL;
+ /* Clear focus child redirect. */
+ win->focus_child = NULL;
/* If transient, adjust parent's focus child for focus_magic. */
if (TRANS(win)) {
&win->id);
}
- if (cfw != win)
+ if (cfw != win) {
/* Update window border even if workspace is hidden. */
update_window_color(win);
+ /* Update border width */
+ if (!win->bordered && WS_FOCUSED(win->ws) &&
+ (win->quirks & SWM_Q_MINIMALBORDER) && FLOATING(win)) {
+ win->bordered = 1;
+ X(win) -= border_width;
+ Y(win) -= border_width;
+ update_window(win);
+ }
+ }
+
out:
bar_draw();
struct workspace *ws;
struct swm_region *r;
+ DNPRINTF(SWM_D_MISC, "update_floater: win %#x\n", WINID(win));
+
if (win == NULL)
return;
if ((r = ws->r) == NULL)
return;
- DNPRINTF(SWM_D_MISC, "update_floater: win %#x\n", win->id);
-
win->bordered = true;
if (FULLSCREEN(win)) {
if (r != ws->old_r)
load_float_geom(win);
- if ((win->quirks & SWM_Q_FULLSCREEN) &&
- WIDTH(win) >= WIDTH(r) && HEIGHT(win) >= HEIGHT(r)) {
- /* Remove border for FULLSCREEN quirk. */
+ if (((win->quirks & SWM_Q_FULLSCREEN) &&
+ WIDTH(win) >= WIDTH(r) && HEIGHT(win) >= HEIGHT(r)) ||
+ ((!WS_FOCUSED(win->ws) || win->ws->focus != win) &&
+ (win->quirks & SWM_Q_MINIMALBORDER))) {
+ /* Remove border */
win->bordered = false;
} else if (!MANUAL(win)) {
if (TRANS(win) && (win->quirks & SWM_Q_TRANSSZ)) {
{
struct swm_geometry win_g, r_g = *g;
struct ws_win *win;
- int i, j, s, stacks;
+ int i = 0, j = 0, s = 0, stacks = 0;
int w_inc = 1, h_inc, w_base = 1, h_base;
- int hrh, extra = 0, h_slice, last_h = 0;
- int split, colno, winno, mwin, msize, mscale;
- int remain, missing, v_slice;
+ int hrh = 0, extra = 0, h_slice = 0, last_h = 0;
+ int split = 0, colno = 0;
+ int winno, mwin = 0, msize = 0;
+ int remain, missing, v_slice, mscale;
bool bordered = true, reconfigure = false;
DNPRINTF(SWM_D_STACK, "stack_master: workspace: %d, rot: %s, "
int num_screens, i;
num_screens = get_screen_count();
- for (i = 0; i < num_screens; ++i)
- xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
- screens[i].root, ewmh[_NET_CURRENT_DESKTOP].atom,
- XCB_ATOM_CARDINAL, 32, 1, &screens[i].r_focus->ws->idx);
+ for (i = 0; i < num_screens; ++i) {
+ if (screens[i].r_focus)
+ xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
+ screens[i].root, ewmh[_NET_CURRENT_DESKTOP].atom,
+ XCB_ATOM_CARDINAL, 32, 1,
+ &screens[i].r_focus->ws->idx);
+ }
}
void
DNPRINTF(SWM_D_SPAWN, "spawn_remove: leave\n");
}
+void
+clear_spawns(void)
+{
+ struct spawn_prog *sp;
+
+ while ((sp = TAILQ_FIRST(&spawns)) != NULL) {
+ spawn_remove(sp);
+ }
+}
+
struct spawn_prog*
spawn_find(const char *name)
{
"IGNOREPID",
"IGNORESPAWNWS",
"NOFOCUSCYCLE",
+ "MINIMALBORDER",
};
/* SWM_Q_DELIM: retain '|' for back compat for now (2009-08-11) */
if (quirk == NULL || qstr == NULL)
return (1);
- if ((str = strdup(qstr)) == NULL)
+ if ((cp = str = strdup(qstr)) == NULL)
err(1, "parsequirks: strdup");
- cp = str;
*quirk = 0;
while ((name = strsep(&cp, SWM_Q_DELIM)) != NULL) {
if (cp)
free(qp);
}
+void
+clear_quirks(void)
+{
+ struct quirk *qp;
+
+ while ((qp = TAILQ_FIRST(&quirks)) != NULL) {
+ quirk_remove(qp);
+ }
+}
+
void
quirk_replace(struct quirk *qp, const char *class, const char *instance,
const char *name, uint32_t quirk, int ws)
{
struct workspace *ws;
int i, ws_id, num_screens;
- char *b, *str, s[1024];
+ char *b, *str, *sp, s[1024];
switch (flags) {
case SWM_S_BAR_ACTION:
if (!bar_font_legacy)
break;
- if ((str = strdup(value)) == NULL)
+ if ((sp = str = strdup(value)) == NULL)
err(1, "setconfvalue: strdup");
/* If there are any non-XLFD entries, switch to Xft mode. */
- while ((b = strsep(&str, ",")) != NULL) {
+ while ((b = strsep(&sp, ",")) != NULL) {
if (*b == '\0')
continue;
if (!isxlfd(b)) {
{
int ws_id;
char s[1024];
- char *ap, *sp;
+ char *ap, *sp, *str;
union arg a;
int argc = 0;
pid_t pid;
if (ws_id < 0 || ws_id >= workspace_limit)
errx(1, "autorun: invalid workspace %d", ws_id + 1);
- sp = expand_tilde((char *)&s);
+ sp = str = expand_tilde((char *)&s);
/*
* This is a little intricate
err(1, "setautorun: realloc");
a.argv[argc - 1] = ap;
}
- free(sp);
+ free(str);
if ((a.argv = realloc(a.argv, (argc + 1) * sizeof(char *))) == NULL)
err(1, "setautorun: realloc");
void
free_window(struct ws_win *win)
{
- DNPRINTF(SWM_D_MISC, "free_window: win %#x\n", win->id);
+ DNPRINTF(SWM_D_MISC, "free_window: win %#x\n", WINID(win));
if (win == NULL)
return;
- TAILQ_REMOVE(&win->ws->unmanagedlist, win, entry);
-
xcb_icccm_get_wm_class_reply_wipe(&win->ch);
- kill_refs(win);
-
/* paint memory */
memset(win, 0xff, sizeof *win); /* XXX kill later */
{
struct ws_win *parent;
+ DNPRINTF(SWM_D_MISC, "unmanage_window: win %#x\n", WINID(win));
+
if (win == NULL)
return;
- DNPRINTF(SWM_D_MISC, "unmanage_window: win %#x\n", win->id);
-
if (TRANS(win)) {
parent = find_window(win->transient);
if (parent)
DNPRINTF(SWM_D_EVENT, "destroynotify: win %#x\n", e->window);
- if ((win = find_window(e->window)) == NULL) {
- if ((win = find_unmanaged_window(e->window)) == NULL)
- return;
- free_window(win);
- return;
- }
-
- if (focus_mode != SWM_FOCUS_FOLLOW) {
- /* If we were focused, make sure we focus on something else. */
- if (win == win->ws->focus)
- win->ws->focus_pending = get_focus_prev(win);
- }
+ if ((win = find_window(e->window))) {
+ /* Managed window cleanup. */
+ if (focus_mode != SWM_FOCUS_FOLLOW) {
+ /* If focused, focus on something else. */
+ if (win == win->ws->focus)
+ win->ws->focus_pending = get_focus_prev(win);
+ }
- unmanage_window(win);
- stack();
+ unmanage_window(win);
+ stack();
- if (focus_mode != SWM_FOCUS_FOLLOW && WS_FOCUSED(win->ws)) {
- if (win->ws->focus_pending) {
- focus_win(win->ws->focus_pending);
- win->ws->focus_pending = NULL;
- } else if (win == win->ws->focus) {
- xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT,
- win->ws->r->id, XCB_CURRENT_TIME);
+ if (focus_mode != SWM_FOCUS_FOLLOW && WS_FOCUSED(win->ws)) {
+ if (win->ws->focus_pending) {
+ focus_win(win->ws->focus_pending);
+ win->ws->focus_pending = NULL;
+ } else if (win == win->ws->focus) {
+ xcb_set_input_focus(conn,
+ XCB_INPUT_FOCUS_PARENT, win->ws->r->id,
+ XCB_CURRENT_TIME);
+ }
}
+
+ kill_refs(win);
+ focus_flush();
+ } else {
+ win = find_unmanaged_window(e->window);
}
- free_window(win);
+ if (win) {
+ /* unmanage_window() puts win into unmanaged list. */
+ TAILQ_REMOVE(&win->ws->unmanagedlist, win, entry);
+ free_window(win);
+ }
- focus_flush();
+ DNPRINTF(SWM_D_EVENT, "destroynotify: done.\n");
}
#ifdef SWM_DEBUG
xcb_randr_query_version_reply_t *r;
num_screens = get_screen_count();
- if ((screens = calloc(num_screens,
- sizeof(struct swm_screen))) == NULL)
+ if ((screens = calloc(num_screens, sizeof(struct swm_screen))) == NULL)
err(1, "setup_screens: calloc: failed to allocate memory for "
"screens");
void
shutdown_cleanup(void)
{
+ struct swm_region *r;
+ struct ws_win *w;
+ struct workspace *ws;
int i, num_screens;
/* disable alarm because the following code may not be interrupted */
cursors_cleanup();
+ clear_quirks();
+ clear_spawns();
+ clear_keys();
+
teardown_ewmh();
num_screens = get_screen_count();
for (i = 0; i < num_screens; ++i) {
+ int j;
+
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT,
screens[i].root, XCB_CURRENT_TIME);
XftColorFree(display, DefaultVisual(display, i),
DefaultColormap(display, i), &search_font_color);
}
+
+ for (j = 0; j < SWM_S_COLOR_MAX; ++j) {
+ free(screens[i].c[j].name);
+ }
+
+ /* Free window memory. */
+ for (j = 0; j < SWM_WS_MAX; ++j) {
+ ws = &screens[i].ws[j];
+ free(ws->name);
+
+ while ((w = TAILQ_FIRST(&ws->winlist)) != NULL) {
+ TAILQ_REMOVE(&ws->winlist, w, entry);
+ free_window(w);
+ }
+
+ while ((w = TAILQ_FIRST(&ws->unmanagedlist)) != NULL) {
+ TAILQ_REMOVE(&ws->unmanagedlist, w, entry);
+ free_window(w);
+ }
+ }
+
+ /* Free region memory. */
+ while ((r = TAILQ_FIRST(&screens[i].rl)) != NULL) {
+ TAILQ_REMOVE(&screens[i].rl, r, entry);
+ free(r->bar);
+ free(r);
+ }
+
+ while ((r = TAILQ_FIRST(&screens[i].orl)) != NULL) {
+ TAILQ_REMOVE(&screens[i].rl, r, entry);
+ free(r->bar);
+ free(r);
+ }
}
+ free(screens);
- if (bar_font_legacy)
+ free(bar_format);
+ free(bar_fonts);
+ free(clock_format);
+ free(startup_exception);
+
+ if (bar_fs)
XFreeFontSet(display, bar_fs);
- else {
+ if (bar_font)
XftFontClose(display, bar_font);
- }
xcb_key_symbols_free(syms);
xcb_flush(conn);
int
main(int argc, char *argv[])
{
- struct swm_region *r;
- char conf[PATH_MAX], *cfile = NULL;
- struct stat sb;
- int xfd, i, num_screens;
+ struct pollfd pfd[2];
struct sigaction sact;
+ struct stat sb;
+ struct passwd *pwd;
+ struct swm_region *r;
xcb_generic_event_t *evt;
- int num_readable;
- struct pollfd pfd[2];
+ int xfd, i, num_screens, num_readable;
+ char conf[PATH_MAX], *cfile = NULL;
bool stdin_ready = false, startup = true;
/* suppress unused warning since var is needed */
num_readable = poll(pfd, bar_extra ? 2 : 1, 1000);
if (num_readable == -1) {
- DNPRINTF(SWM_D_MISC, "poll failed: %s", strerror(errno));
- } else if (num_readable > 0 && bar_extra && pfd[1].revents & POLLIN) {
+ DNPRINTF(SWM_D_MISC, "poll failed: %s",
+ strerror(errno));
+ } else if (num_readable > 0 && bar_extra &&
+ pfd[1].revents & POLLIN) {
stdin_ready = true;
}