+void
+bar_workspace_state(char *s, size_t sz, struct swm_region *r)
+{
+ struct ws_win *win;
+ int i, j, num_screens;
+ bool used_workspaces[SWM_WS_MAX];
+ char tmp[8];
+ int first = 1;
+ char *fmt;
+
+ if (r == NULL || r->ws == NULL)
+ return;
+
+ for (i = 0; i < SWM_WS_MAX; ++i)
+ used_workspaces[i] = false;
+
+ num_screens = get_screen_count();
+ for (i = 0; i < num_screens; i++)
+ for (j = 0; j < workspace_limit; j++)
+ TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
+ ++used_workspaces[win->ws->idx];
+
+ for (i = 0; i < SWM_WS_MAX; ++i) {
+ fmt = NULL;
+ if (i == r->ws->idx) {
+ fmt = " [%d]";
+ } else if (used_workspaces[i]) {
+ fmt = " %d";
+ }
+ if (fmt) {
+ fmt = fmt + first;
+ first = 0;
+ snprintf(tmp, sizeof tmp, fmt, i + 1);
+ strlcat(s, tmp, sz);
+ }
+ }
+}
+