From 934bbe1ff27cfe7c2407514da64ab55cf62de3df Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Wed, 13 Jun 2012 22:44:12 +0100 Subject: [PATCH] Add new character sequence used for padding. Instead of inserting sequential spaces one by one, add support for padding with the +< character pair. Uses the specified limit or one otherwise. --- spectrwm.1 | 1 + spectrwm.c | 18 ++++++++++++------ spectrwm.conf | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/spectrwm.1 b/spectrwm.1 index 2404cfb..e2335d7 100644 --- a/spectrwm.1 +++ b/spectrwm.1 @@ -115,6 +115,7 @@ before being used. It may contain the following character sequences: .Bl -column "Character sequence" "Replaced with" -offset indent .It Sy "Character sequence" Ta Sy "Replaced with" +.It Li "+<" Ta "Pad with a space" .It Li "+A" Ta "Output of the external script" .It Li "+C" Ta "Window class" .It Li "+D" Ta "Workspace name" diff --git a/spectrwm.c b/spectrwm.c index 05d5a73..8916331 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -1486,21 +1486,21 @@ bar_fmt(const char *fmtexp, char *fmtnew, struct swm_region *r, size_t 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); + strlcat(fmtnew, "+3<", sz); if (clock_enabled) { strlcat(fmtnew, fmtexp, sz); - strlcat(fmtnew, " ", sz); + strlcat(fmtnew, "+4<", sz); } /* bar_urgent already adds the space before the last asterisk */ if (urgent_enabled) - strlcat(fmtnew, "* +U* ", sz); + strlcat(fmtnew, "* +U*+4<", sz); if (title_class_enabled) { strlcat(fmtnew, "+C", sz); if (title_name_enabled == 0) - strlcat(fmtnew, " ", sz); + strlcat(fmtnew, "+4<", sz); } /* checks needed by the colon and floating strlcat(3) calls below */ @@ -1508,7 +1508,7 @@ bar_fmt(const char *fmtexp, char *fmtnew, struct swm_region *r, size_t sz) if (title_name_enabled) { if (title_class_enabled) strlcat(fmtnew, ":", sz); - strlcat(fmtnew, "+T ", sz); + strlcat(fmtnew, "+T+4<", sz); } if (window_name_enabled) { if (r->ws->focus->floating) @@ -1518,7 +1518,7 @@ bar_fmt(const char *fmtexp, char *fmtnew, struct swm_region *r, size_t sz) } /* finally add the action script output and the version */ - strlcat(fmtnew, " +A +V", sz); + strlcat(fmtnew, "+4<+A+4<+V", sz); } /* replaces the bar format character sequences (like in tmux(1)) */ @@ -1556,6 +1556,12 @@ bar_replace_seq(char *fmt, char *fmtrep, struct swm_region *r, size_t *offrep, return (fmt); switch (*fmt) { + case '<': + /* special case; no limit given, pad one space, instead */ + if (limit == sizeof tmp - 1) + limit = 1; + snprintf(tmp, sizeof tmp, "%*s", limit, " "); + break; case 'A': snprintf(tmp, sizeof tmp, "%s", bar_ext); break; diff --git a/spectrwm.conf b/spectrwm.conf index 9c234f8..f56559a 100644 --- a/spectrwm.conf +++ b/spectrwm.conf @@ -27,7 +27,7 @@ # bar_action = baraction.sh # bar_delay = 1 # bar_justify = left -# bar_format = +N:+I +S <+D> %a %b %d %R %Z %Y +A +V +# bar_format = +N:+I +S <+D>+4<%a %b %d %R %Z %Y+8<+A+4<+V # bar_at_bottom = 1 # stack_enabled = 1 # clock_enabled = 1 -- 2.39.2