+
+/*
+ * Implementation of 'bar mode dock|hide|invisible|toggle [<bar_id>]'
+ *
+ */
+bool cmd_bar_mode(char *bar_mode, char *bar_id) {
+ int mode;
+ bool toggle = false;
+ if (strcmp(bar_mode, "dock") == 0)
+ mode = M_DOCK;
+ else if (strcmp(bar_mode, "hide") == 0)
+ mode = M_HIDE;
+ else if (strcmp(bar_mode, "invisible") == 0)
+ mode = M_INVISIBLE;
+ else if (strcmp(bar_mode, "toggle") == 0)
+ toggle = true;
+ else {
+ ELOG("Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
+ return false;
+ }
+
+ bool changed_sth = false;
+ Barconfig *current = NULL;
+ TAILQ_FOREACH(current, &barconfigs, configs) {
+ if (bar_id && strcmp(current->id, bar_id) != 0)
+ continue;
+
+ if (toggle)
+ mode = (current->mode + 1) % 2;
+
+ DLOG("Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->id, bar_mode, mode);
+ current->mode = mode;
+ changed_sth = true;
+
+ if (bar_id)
+ break;
+ }
+
+ if (bar_id && !changed_sth) {
+ DLOG("Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * Implementation of 'bar hidden_state hide|show|toggle [<bar_id>]'
+ *
+ */
+bool cmd_bar_hidden_state(char *bar_hidden_state, char *bar_id) {
+ int hidden_state;
+ bool toggle = false;
+ if (strcmp(bar_hidden_state, "hide") == 0)
+ hidden_state = S_HIDE;
+ else if (strcmp(bar_hidden_state, "show") == 0)
+ hidden_state = S_SHOW;
+ else if (strcmp(bar_hidden_state, "toggle") == 0)
+ toggle = true;
+ else {
+ ELOG("Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
+ return false;
+ }
+
+ bool changed_sth = false;
+ Barconfig *current = NULL;
+ TAILQ_FOREACH(current, &barconfigs, configs) {
+ if (bar_id && strcmp(current->id, bar_id) != 0)
+ continue;
+
+ if (toggle)
+ hidden_state = (current->hidden_state + 1) % 2;
+
+ DLOG("Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->id, bar_hidden_state, hidden_state);
+ current->hidden_state = hidden_state;
+ changed_sth = true;
+
+ if (bar_id)
+ break;
+ }
+
+ if (bar_id && !changed_sth) {
+ DLOG("Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * Implementation of 'bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) [<bar_id>]'
+ *
+ */
+void cmd_bar(I3_CMD, char *bar_type, char *bar_value, char *bar_id) {
+ bool ret;
+ if (strcmp(bar_type, "mode") == 0)
+ ret = cmd_bar_mode(bar_value, bar_id);
+ else if (strcmp(bar_type, "hidden_state") == 0)
+ ret = cmd_bar_hidden_state(bar_value, bar_id);
+ else {
+ ELOG("Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
+ ret = false;
+ }
+
+ ysuccess(ret);
+ if (!ret)
+ return;
+
+ update_barconfig();
+}