introduced i3 command for changing the hidden state and the mode of i3bar
The hidden_state and mode of each i3bar instance can now be controlled from within i3. Therefore, two new i3 command were introduced: _ bar hidden_state show|hide|toggle [<bar_id>] show: always show the bar hide: normal hide mode toggle: toggle between show and hide (individually for each bar) _ bar mode dock|hide|invisible|toggle [<bar_id>] hide,dock: like before invisible: always keep the bar hidden toggle: toggle between dock and hide (individually for each bar) This patch introduces a hidden_state ("hidden_state hide|show") in the barconfig, which indicates the current hidden_state of each i3bar instance. It only affects the bar when in hide mode. Additionally, a new invisible mode was introduced. In order to change the hidden_state or mode of the bar from i3, a barconfig-update event was introduced, for which a bar can subscribe and the bar then gets notified about the currently set hidden_state and mode in its barconfig. For convenience, an id field ("id <bar_id>") was added to the barconfig, where one can set the desired id for the corresponding bar. If the id is not specified, i3 will deterministically choose an id; otherwise, with the previous random approach for finding a new id, which is actually not shared with i3bar, as it would determine its id on startup, the event-subscription would be destroyed on reload. Still, this issue remains when manually changing the bar_id in the config and then reloading. fixes #833, #651
This commit is contained in:
committed by
Michael Stapelberg
parent
f0eba6d15c
commit
e3913093b6
112
src/commands.c
112
src/commands.c
@ -1632,6 +1632,8 @@ void cmd_reload(I3_CMD) {
|
||||
x_set_i3_atoms();
|
||||
/* Send an IPC event just in case the ws names have changed */
|
||||
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"reload\"}");
|
||||
/* Send an update event for the barconfig just in case it has changed */
|
||||
update_barconfig();
|
||||
|
||||
// XXX: default reply for now, make this a better reply
|
||||
ysuccess(true);
|
||||
@ -1915,3 +1917,113 @@ void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name) {
|
||||
|
||||
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"rename\"}");
|
||||
}
|
||||
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user