From: Reginald Kennedy Date: Wed, 30 Oct 2013 09:20:02 +0000 (+0800) Subject: Add new option: iconic_enabled X-Git-Url: https://jasonwoof.com/gitweb/?p=spectrwm.git;a=commitdiff_plain;h=75649b6a4b4c9349764c5655c6421e593117a95f Add new option: iconic_enabled When one or more windows are iconic, show the count in bar. Add new bar_format character sequence: +M Replaced with iconic window count. Closes #19 --- diff --git a/spectrwm.1 b/spectrwm.1 index 62aee63..426b780 100644 --- a/spectrwm.1 +++ b/spectrwm.1 @@ -174,6 +174,7 @@ It may contain the following character sequences: .It Li "+D" Ta "Workspace name" .It Li "+F" Ta "Floating indicator" .It Li "+I" Ta "Workspace index" +.It Li "+M" Ta "Number of iconic (minimized) windows in workspace" .It Li "+N" Ta "Screen number" .It Li "+P" Ta "Window class and instance separated by a colon" .It Li "+S" Ta "Stacking algorithm" @@ -221,6 +222,9 @@ Disable by setting to 0 so a custom clock could be used in the .Pa bar_action script. +.It Ic iconic_enabled +Display the number of iconic (minimized) windows in the status bar. +Enable by setting to 1. .It Ic color_focus Border color of the currently focussed window. .It Ic color_unfocus diff --git a/spectrwm.c b/spectrwm.c index 41bd6d4..0335ffa 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -373,6 +373,7 @@ int bar_justify = SWM_BAR_JUSTIFY_LEFT; char *bar_format = NULL; int stack_enabled = 1; int clock_enabled = 1; +int iconic_enabled = 0; int urgent_enabled = 0; char *clock_format = NULL; int window_class_enabled = 0; @@ -2077,6 +2078,8 @@ bar_workspace_name(char *s, size_t sz, struct swm_region *r) void bar_fmt(const char *fmtexp, char *fmtnew, struct swm_region *r, size_t sz) { + struct ws_win *w; + /* if format provided, just copy the buffers */ if (bar_format != NULL) { strlcpy(fmtnew, fmtexp, sz); @@ -2094,6 +2097,15 @@ 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); + + /* If enabled, only show the iconic count if there are iconic wins. */ + if (iconic_enabled && r != NULL && r->ws != NULL) + TAILQ_FOREACH(w, &r->ws->winlist, entry) + if (w->iconic) { + strlcat(fmtnew, "{+M}", sz); + break; + } + strlcat(fmtnew, "+3<", sz); if (clock_enabled) { @@ -2143,9 +2155,10 @@ char * bar_replace_seq(char *fmt, char *fmtrep, struct swm_region *r, size_t *offrep, size_t sz) { + struct ws_win *w; char *ptr; char tmp[SWM_BAR_MAX]; - int limit, size; + int limit, size, count; size_t len; /* reset strlcat(3) buffer */ @@ -2183,6 +2196,14 @@ bar_replace_seq(char *fmt, char *fmtrep, struct swm_region *r, size_t *offrep, case 'I': snprintf(tmp, sizeof tmp, "%d", r->ws->idx + 1); break; + case 'M': + count = 0; + TAILQ_FOREACH(w, &r->ws->winlist, entry) + if (w->iconic) + ++count; + + snprintf(tmp, sizeof tmp, "%d", count); + break; case 'N': snprintf(tmp, sizeof tmp, "%d", r->s->idx + 1); break; @@ -7179,6 +7200,7 @@ enum { SWM_S_FOCUS_CLOSE_WRAP, SWM_S_FOCUS_DEFAULT, SWM_S_FOCUS_MODE, + SWM_S_ICONIC_ENABLED, SWM_S_REGION_PADDING, SWM_S_SPAWN_ORDER, SWM_S_SPAWN_TERM, @@ -7346,6 +7368,9 @@ setconfvalue(const char *selector, const char *value, int flags) else errx(1, "focus_mode"); break; + case SWM_S_ICONIC_ENABLED: + iconic_enabled = atoi(value); + break; case SWM_S_REGION_PADDING: region_padding = atoi(value); if (region_padding < 0) @@ -7649,6 +7674,7 @@ struct config_option configopt[] = { { "focus_close_wrap", setconfvalue, SWM_S_FOCUS_CLOSE_WRAP }, { "focus_default", setconfvalue, SWM_S_FOCUS_DEFAULT }, { "focus_mode", setconfvalue, SWM_S_FOCUS_MODE }, + { "iconic_enabled", setconfvalue, SWM_S_ICONIC_ENABLED }, { "keyboard_mapping", setkeymapping, 0 }, { "layout", setlayout, 0 }, { "modkey", setconfmodkey, 0 }, diff --git a/spectrwm.conf b/spectrwm.conf index e90d93e..27d46cb 100644 --- a/spectrwm.conf +++ b/spectrwm.conf @@ -39,6 +39,7 @@ # stack_enabled = 1 # clock_enabled = 1 # clock_format = %a %b %d %R %Z %Y +# iconic_enabled = 0 # window_class_enabled = 0 # window_instance_enabled = 0 # window_name_enabled = 0