int bar_verbose = 1;
int bar_height = 0;
int bar_justify = SWM_BAR_JUSTIFY_LEFT;
+char *bar_format = NULL;
int stack_enabled = 1;
int clock_enabled = 1;
int urgent_enabled = 0;
}
void
-bar_print(struct swm_region *r, char *s)
+bar_print(struct swm_region *r, const char *s)
{
int x = 0;
size_t len;
}
void
-bar_class_name(char *s, ssize_t sz, struct ws_win *cur_focus)
+bar_class_name(char *s, size_t sz, struct swm_region *r)
{
- int do_class, do_name;
- XClassHint *ch;
+ if (r == NULL || r->ws == NULL || r->ws->focus == NULL)
+ return;
+ if (r->ws->focus->ch.res_class != NULL)
+ strlcat(s, r->ws->focus->ch.res_class, sz);
+}
- if (title_name_enabled == 0 && title_class_enabled == 0)
+void
+bar_title_name(char *s, size_t sz, struct swm_region *r)
+{
+ if (r == NULL || r->ws == NULL || r->ws->focus == NULL)
return;
- if (cur_focus == NULL)
+ if (r->ws->focus->ch.res_name != NULL)
+ strlcat(s, r->ws->focus->ch.res_name, sz);
+}
+
+void
+bar_class_title_name(char *s, size_t sz, struct swm_region *r)
+{
+ if (r == NULL || r->ws == NULL || r->ws->focus == NULL)
return;
- ch = &cur_focus->ch;
- do_class = (title_class_enabled && ch->res_class != NULL);
- do_name = (title_name_enabled && ch->res_name != NULL);
+ bar_class_name(s, sz, r);
+ strlcat(s, ":", sz);
+ bar_title_name(s, sz, r);
+}
- if (do_class)
- strlcat(s, ch->res_class, sz);
- if (do_class && do_name)
- strlcat(s, ":", sz);
- if (do_name)
- strlcat(s, ch->res_name, sz);
- strlcat(s, " ", sz);
+void
+bar_window_float(char *s, size_t sz, struct swm_region *r)
+{
+ if (r == NULL || r ->ws == NULL || r->ws->focus == NULL)
+ return;
+ if (r->ws->focus->floating)
+ strlcat(s, "(f)", sz);
}
void
-bar_window_name(char *s, ssize_t sz, struct ws_win *cur_focus)
+bar_window_name(char *s, size_t sz, struct swm_region *r)
{
unsigned char *title;
- if (window_name_enabled && cur_focus != NULL) {
- title = get_win_name(cur_focus->id);
- if (title != NULL) {
- DNPRINTF(SWM_D_BAR, "bar_window_name: title: %s\n",
- title);
-
- if (cur_focus->floating)
- strlcat(s, "(f) ", sz);
- strlcat(s, (char *)title, sz);
- strlcat(s, " ", sz);
- XFree(title);
- }
- }
+ if (r == NULL || r->ws == NULL || r->ws->focus == NULL)
+ return;
+ if ((title = get_win_name(r->ws->focus->id)) == NULL)
+ return;
+
+ strlcat(s, (char *)title, sz);
+ XFree(title);
}
int urgent[SWM_WS_MAX];
void
-bar_urgent(char *s, ssize_t sz)
+bar_urgent(char *s, size_t sz)
{
XWMHints *wmh = NULL;
struct ws_win *win;
int i, j;
char b[8];
- if (urgent_enabled == 0)
- return;
-
for (i = 0; i < workspace_limit; i++)
urgent[i] = 0;
XFree(wmh);
}
- strlcat(s, "* ", sz);
for (i = 0; i < workspace_limit; i++) {
if (urgent[i])
snprintf(b, sizeof b, "%d ", i + 1);
snprintf(b, sizeof b, "- ");
strlcat(s, b, sz);
}
- strlcat(s, "* ", sz);
}
void
-bar_update(void)
+bar_workspace_name(char *s, size_t sz, struct swm_region *r)
{
- time_t tmt;
+ if (r == NULL || r->ws == NULL)
+ return;
+ if (r->ws->name != NULL)
+ strlcat(s, r->ws->name, sz);
+}
+
+/* build the default bar format according to the defined enabled options */
+void
+bar_fmt(const char *fmtexp, char *fmtnew, struct swm_region *r, size_t sz)
+{
+ /* if format provided, just copy the buffers */
+ if (bar_format != NULL) {
+ strlcpy(fmtnew, fmtexp, sz);
+ return;
+ }
+
+ /* reset the output buffer */
+ *fmtnew = '\0';
+
+ strlcat(fmtnew, "+N:+I ", sz);
+ if (stack_enabled)
+ strlcat(fmtnew, "+S", sz);
+ strlcat(fmtnew, " ", sz);
+
+ /* only show the workspace name if there's actually one */
+ if (r != NULL && r->ws != NULL && r->ws->name != NULL)
+ strlcat(fmtnew, "<+D>", sz);
+ strlcat(fmtnew, " ", sz);
+
+ if (clock_enabled) {
+ strlcat(fmtnew, fmtexp, sz);
+ strlcat(fmtnew, " ", sz);
+ }
+
+ /* bar_urgent already adds the space before the last asterisk */
+ if (urgent_enabled)
+ strlcat(fmtnew, "* +U* ", sz);
+
+ if (title_class_enabled) {
+ strlcat(fmtnew, "+C", sz);
+ if (title_name_enabled == 0)
+ strlcat(fmtnew, " ", sz);
+ }
+
+ /* checks needed by the colon and floating strlcat(3) calls below */
+ if (r != NULL && r->ws != NULL && r->ws->focus != NULL) {
+ if (title_name_enabled) {
+ if (title_class_enabled)
+ strlcat(fmtnew, ":", sz);
+ strlcat(fmtnew, "+T ", sz);
+ }
+ if (window_name_enabled) {
+ if (r->ws->focus->floating)
+ strlcat(fmtnew, "+F ", sz);
+ strlcat(fmtnew, "+64W ", sz);
+ }
+ }
+
+ /* finally add the action script output and the version */
+ strlcat(fmtnew, " +A +V", sz);
+}
+
+/* replaces the bar format character sequences (like in tmux(1)) */
+char *
+bar_replace_seq(char *fmt, char *fmtrep, struct swm_region *r, size_t *offrep,
+ size_t sz)
+{
+ char *ptr;
+ char num[8], tmp[SWM_BAR_MAX];
+ int limit;
+ size_t len, numoff = 0;
+
+ /* reset strlcat(3) buffer */
+ *tmp = '\0';
+
+ /* get number, if any */
+ fmt++;
+ while (*fmt != '\0' && isdigit((unsigned char) *fmt)) {
+ if (numoff >= sizeof num - 1)
+ break;
+ num[numoff++] = *fmt++;
+ }
+ num[numoff] = '\0';
+
+ if ((limit = strtonum(num, 1, sizeof tmp - 1, NULL)) == 0)
+ limit = sizeof tmp - 1;
+
+ /* if number is too big, skip to the first non-digit */
+ if (numoff >= sizeof num - 1) {
+ while (*fmt != '\0' && isdigit((unsigned char) *fmt))
+ fmt++;
+ }
+ /* there is nothing to replace (ie EOL) */
+ if (*fmt == '\0')
+ return (fmt);
+
+ switch (*fmt) {
+ case 'A':
+ snprintf(tmp, sizeof tmp, "%s", bar_ext);
+ break;
+ case 'C':
+ bar_class_name(tmp, sizeof tmp, r);
+ break;
+ case 'D':
+ bar_workspace_name(tmp, sizeof tmp, r);
+ break;
+ case 'F':
+ bar_window_float(tmp, sizeof tmp, r);
+ break;
+ case 'I':
+ snprintf(tmp, sizeof tmp, "%d", r->ws->idx + 1);
+ break;
+ case 'N':
+ snprintf(tmp, sizeof tmp, "%d", r->s->idx + 1);
+ break;
+ case 'P':
+ bar_class_title_name(tmp, sizeof tmp, r);
+ break;
+ case 'S':
+ snprintf(tmp, sizeof tmp, "%s", r->ws->stacker);
+ break;
+ case 'T':
+ bar_title_name(tmp, sizeof tmp, r);
+ break;
+ case 'U':
+ bar_urgent(tmp, sizeof tmp);
+ break;
+ case 'V':
+ snprintf(tmp, sizeof tmp, "%s", bar_vertext);
+ break;
+ case 'W':
+ bar_window_name(tmp, sizeof tmp, r);
+ break;
+ default:
+ /* unknown character sequence; copy as-is */
+ snprintf(tmp, sizeof tmp, "+%c", *fmt);
+ break;
+ }
+
+ len = strlen(tmp);
+ ptr = tmp;
+ if (len < limit)
+ limit = len;
+ while (limit-- > 0) {
+ if (*offrep >= sz - 1)
+ break;
+ fmtrep[(*offrep)++] = *ptr++;
+ }
+
+ fmt++;
+ return (fmt);
+}
+
+void
+bar_replace(char *fmt, char *fmtrep, struct swm_region *r, size_t sz)
+{
+ size_t off;
+
+ off = 0;
+ while (*fmt != '\0') {
+ if (*fmt != '+') {
+ /* skip ordinary characters */
+ if (off >= sz - 1)
+ break;
+ fmtrep[off++] = *fmt++;
+ continue;
+ }
+
+ /* character sequence found; replace it */
+ fmt = bar_replace_seq(fmt, fmtrep, r, &off, sz);
+ if (off >= sz - 1)
+ break;
+ }
+
+ fmtrep[off] = '\0';
+}
+
+void
+bar_fmt_expand(char *fmtexp, size_t sz)
+{
+ char *fmt = NULL;
+ size_t len;
struct tm tm;
+ time_t tmt;
+
+ /* start by grabbing the current time and date */
+ time(&tmt);
+ localtime_r(&tmt, &tm);
+
+ /* figure out what to expand */
+ if (bar_format != NULL)
+ fmt = bar_format;
+ else if (bar_format == NULL && clock_enabled)
+ fmt = clock_format;
+ /* if nothing to expand bail out */
+ if (fmt == NULL) {
+ *fmtexp = '\0';
+ return;
+ }
+
+ /* copy as-is, just in case the format shouldn't be expanded below */
+ strlcpy(fmtexp, fmt, sz);
+ /* finally pass the string through strftime(3) */
+#ifndef SWM_DENY_CLOCK_FORMAT
+ if ((len = strftime(fmtexp, sz, fmt, &tm)) == 0)
+ warnx("format too long");
+ fmtexp[len] = '\0';
+#endif
+}
+
+void
+bar_fmt_print(void)
+{
+ char fmtexp[SWM_BAR_MAX], fmtnew[SWM_BAR_MAX];
+ char fmtrep[SWM_BAR_MAX];
+ int i;
struct swm_region *r;
- int i, x;
+
+ /* expand the format by first passing it through strftime(3) */
+ bar_fmt_expand(fmtexp, sizeof fmtexp);
+
+ for (i = 0; i < ScreenCount(display); i++) {
+ TAILQ_FOREACH(r, &screens[i].rl, entry) {
+ bar_fmt(fmtexp, fmtnew, r, sizeof fmtnew);
+ bar_replace(fmtnew, fmtrep, r, sizeof fmtrep);
+ bar_print(r, fmtrep);
+ }
+ }
+}
+
+void
+bar_update(void)
+{
size_t len;
- char ws[SWM_BAR_MAX];
- char s[SWM_BAR_MAX];
- unsigned char cn[SWM_BAR_MAX];
- char loc[SWM_BAR_MAX];
- char *b, *stack = "";
+ char *b;
if (bar_enabled == 0)
return;
} else
strlcpy((char *)bar_ext, "", sizeof bar_ext);
- if (clock_enabled == 0)
- strlcpy(s, "", sizeof s);
- else {
- time(&tmt);
- localtime_r(&tmt, &tm);
- len = strftime(s, sizeof s, clock_format, &tm);
- s[len] = '\0';
- strlcat(s, " ", sizeof s);
- }
-
- for (i = 0; i < ScreenCount(display); i++) {
- x = 1;
- TAILQ_FOREACH(r, &screens[i].rl, entry) {
- strlcpy((char *)cn, "", sizeof cn);
- strlcpy(ws, "", sizeof ws);
- if (r && r->ws) {
- bar_urgent((char *)cn, sizeof cn);
- bar_class_name((char *)cn, sizeof cn,
- r->ws->focus);
- bar_window_name((char *)cn, sizeof cn,
- r->ws->focus);
- if (r->ws->name)
- snprintf(ws, sizeof ws, "<%s>",
- r->ws->name);
- if (stack_enabled)
- stack = r->ws->stacker;
-
- snprintf(loc, sizeof loc,
- "%d:%d %s %s %s%s %s %s",
- x++, r->ws->idx + 1, stack, ws, s, cn,
- bar_ext, bar_vertext);
- bar_print(r, loc);
- }
- }
- }
+ bar_fmt_print();
alarm(bar_delay);
}
void
-bar_check_opts(void)
-{
- if (title_class_enabled || title_name_enabled || window_name_enabled)
- bar_update();
-}
-
-void
bar_signal(int sig)
{
bar_alarm = 1;
PropModeReplace, (unsigned char *)&win->id, 1);
}
- bar_check_opts();
+ bar_update();
}
void
a.id = SWM_ARG_ID_FOCUSCUR;
focus(new_ws->r, &a);
- bar_update();
-
/* unmap old windows */
if (unmap_old)
TAILQ_FOREACH(win, &old_ws->winlist, entry)
winfocus = TAILQ_FIRST(wl);
}
+ kill_refs(win);
focus_magic(winfocus);
}
drain_enter_notify();
a.id = SWM_ARG_ID_FOCUSCUR;
focus(r, &a);
- bar_update();
}
void
}
stack();
+ bar_update();
}
void
kf_swap_next,
kf_swap_prev,
kf_spawn_term,
- kf_spawn_menu,
kf_quit,
kf_restart,
kf_focus_main,
kf_bar_toggle,
kf_wind_kill,
kf_wind_del,
- kf_screenshot_all,
- kf_screenshot_wind,
kf_float_toggle,
kf_version,
- kf_spawn_lock,
- kf_spawn_initscr,
kf_spawn_custom,
kf_iconify,
kf_uniconify,
{
};
-void
-legacyfunc(struct swm_region *r, union arg *args)
-{
-};
-
struct keyfunc {
char name[SWM_FUNCNAME_LEN];
void (*func)(struct swm_region *r, union arg *);
{ "swap_next", swapwin, {.id = SWM_ARG_ID_SWAPNEXT} },
{ "swap_prev", swapwin, {.id = SWM_ARG_ID_SWAPPREV} },
{ "spawn_term", spawnterm, {.argv = spawn_term} },
- { "spawn_menu", legacyfunc, {0} },
{ "quit", quit, {0} },
{ "restart", restart, {0} },
{ "focus_main", focus, {.id = SWM_ARG_ID_FOCUSMAIN} },
{ "bar_toggle", bar_toggle, {0} },
{ "wind_kill", wkill, {.id = SWM_ARG_ID_KILLWINDOW} },
{ "wind_del", wkill, {.id = SWM_ARG_ID_DELETEWINDOW} },
- { "screenshot_all", legacyfunc, {0} },
- { "screenshot_wind", legacyfunc, {0} },
{ "float_toggle", floating_toggle,{0} },
{ "version", version, {0} },
- { "spawn_lock", legacyfunc, {0} },
- { "spawn_initscr", legacyfunc, {0} },
{ "spawn_custom", dummykeyfunc, {0} },
{ "iconify", iconify, {0} },
{ "uniconify", uniconify, {0} },
enum keyfuncid funcid;
char *spawn_name;
};
-RB_HEAD(key_list, key);
+RB_HEAD(key_tree, key);
int
key_cmp(struct key *kp1, struct key *kp2)
return (0);
}
-RB_GENERATE_STATIC(key_list, key, entry, key_cmp);
-struct key_list keys;
+RB_GENERATE(key_tree, key, entry, key_cmp);
+struct key_tree keys;
/* mouse */
enum { client_click, root_click };
struct key *kp;
mod_key = mod;
- RB_FOREACH(kp, key_list, &keys)
+ RB_FOREACH(kp, key_tree, &keys)
if (kp->mod & ShiftMask)
kp->mod = mod | ShiftMask;
else
kp->keysym = ks;
kp->funcid = kfid;
kp->spawn_name = strdupsafe(spawn_name);
- RB_INSERT(key_list, &keys, kp);
+ RB_INSERT(key_tree, &keys, kp);
DNPRINTF(SWM_D_KEY, "key_insert: leave\n");
}
kp.keysym = ks;
kp.mod = mod;
- return (RB_FIND(key_list, &keys, &kp));
+ return (RB_FIND(key_tree, &keys, &kp));
}
void
{
DNPRINTF(SWM_D_KEY, "key_remove: %s\n", keyfuncs[kp->funcid].name);
- RB_REMOVE(key_list, &keys, kp);
+ RB_REMOVE(key_tree, &keys, kp);
free(kp->spawn_name);
free(kp);
if (TAILQ_EMPTY(&screens[k].rl))
continue;
XUngrabKey(display, AnyKey, AnyModifier, screens[k].root);
- RB_FOREACH(kp, key_list, &keys) {
+ RB_FOREACH(kp, key_tree, &keys) {
if ((code = XKeysymToKeycode(display, kp->keysym)))
for (j = 0; j < LENGTH(modifiers); j++)
XGrabKey(display, code,
SWM_S_FOCUS_CLOSE_WRAP, SWM_S_FOCUS_DEFAULT, SWM_S_SPAWN_ORDER,
SWM_S_DISABLE_BORDER, SWM_S_BORDER_WIDTH, SWM_S_BAR_FONT,
SWM_S_BAR_ACTION, SWM_S_SPAWN_TERM, SWM_S_SS_APP, SWM_S_DIALOG_RATIO,
- SWM_S_BAR_AT_BOTTOM, SWM_S_VERBOSE_LAYOUT, SWM_S_BAR_JUSTIFY
+ SWM_S_BAR_AT_BOTTOM, SWM_S_VERBOSE_LAYOUT, SWM_S_BAR_JUSTIFY,
+ SWM_S_BAR_FORMAT
};
int
else
errx(1, "invalid bar_justify");
break;
+ case SWM_S_BAR_FORMAT:
+ free(bar_format);
+ if ((bar_format = strdup(value)) == NULL)
+ err(1, "setconfvalue: bar_format");
+ break;
case SWM_S_STACK_ENABLED:
stack_enabled = atoi(value);
break;
int
setlayout(char *selector, char *value, int flags)
{
- int ws_id, i, x, mg, ma, si, raise;
+ int ws_id, i, x, mg, ma, si, raise, f = 0;
int st = SWM_V_STACK;
char s[1024];
struct workspace *ws;
if (!strcasecmp(s, "vertical"))
st = SWM_V_STACK;
- else if (!strcasecmp(s, "horizontal"))
+ else if (!strcasecmp(s, "vertical_flip")) {
+ st = SWM_V_STACK;
+ f = 1;
+ } else if (!strcasecmp(s, "horizontal"))
st = SWM_H_STACK;
- else if (!strcasecmp(s, "fullscreen"))
+ else if (!strcasecmp(s, "horizontal_flip")) {
+ st = SWM_H_STACK;
+ f = 1;
+ } else if (!strcasecmp(s, "fullscreen"))
st = SWM_MAX_STACK;
else
errx(1, "invalid layout entry, should be 'ws[<idx>]:"
SWM_ARG_ID_STACKDEC);
stack();
}
+ /* Apply flip */
+ if (f) {
+ ws[ws_id].cur_layout->l_config(&ws[ws_id],
+ SWM_ARG_ID_FLIPLAYOUT);
+ stack();
+ }
}
return (0);
{ "bar_action", setconfvalue, SWM_S_BAR_ACTION },
{ "bar_delay", setconfvalue, SWM_S_BAR_DELAY },
{ "bar_justify", setconfvalue, SWM_S_BAR_JUSTIFY },
+ { "bar_format", setconfvalue, SWM_S_BAR_FORMAT },
{ "keyboard_mapping", setkeymapping, 0 },
{ "bind", setconfbinding, 0 },
{ "stack_enabled", setconfvalue, SWM_S_STACK_ENABLED },
TAILQ_REMOVE(&win->ws->winlist, win, entry);
TAILQ_INSERT_TAIL(&win->ws->unmanagedlist, win, entry);
-
- kill_refs(win);
}
void
if (win == NULL) {
/* if there are no windows clear the status-bar */
- bar_check_opts();
+ bar_update();
return;
}
X(win), Y(win), WIDTH(win), HEIGHT(win));
#endif
case XA_WM_CLASS:
- if (title_name_enabled || title_class_enabled)
- bar_update();
- break;
case XA_WM_NAME:
- if (window_name_enabled)
- bar_update();
+ bar_update();
break;
default:
break;