From 7ee1be42694a39172a0851a655e9784459e77be6 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Thu, 22 Sep 2016 03:46:31 +1000 Subject: [PATCH] Added bar +p, window index/count --- spectrwm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spectrwm.c b/spectrwm.c index 3af27de..86fb7af 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -999,6 +999,7 @@ void bar_toggle(struct binding *, struct swm_region *, union arg *); void bar_urgent(char *, size_t); void bar_window_class(char *, size_t, struct swm_region *); void bar_window_class_instance(char *, size_t, struct swm_region *); +void bar_window_index_count(char *, size_t, struct swm_region *); void bar_window_instance(char *, size_t, struct swm_region *); void bar_window_name(char *, size_t, struct swm_region *); void bar_window_state(char *, size_t, struct swm_region *); @@ -2431,6 +2432,30 @@ bar_window_class_instance(char *s, size_t sz, struct swm_region *r) bar_window_instance(s, sz, r); } +void +bar_window_index_count(char *s, size_t sz, struct swm_region *r) +{ + struct ws_win *w; + int count, index; + + if (r == NULL || r->ws == NULL || r->ws->focus == NULL) { + strlcat(s, "0/0", sz); + return; + } + + count = 0; + index = 0; + + TAILQ_FOREACH(w, &r->ws->winlist, entry) { + ++count; + if (w->id == r->ws->focus->id) { + index = count; + } + } + + snprintf(s, sz, "%d/%d", index, count); +} + void bar_window_state(char *s, size_t sz, struct swm_region *r) { @@ -2684,6 +2709,9 @@ bar_replace_seq(char *fmt, char *fmtrep, struct swm_region *r, size_t *offrep, case 'N': snprintf(tmp, sizeof tmp, "%d", r->s->idx + 1); break; + case 'p': + bar_window_index_count(tmp, sizeof tmp, r); + break; case 'P': bar_window_class_instance(tmp, sizeof tmp, r); break; -- 2.39.2