Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4081 from orestisfl/i3bar-regression
Browse files Browse the repository at this point in the history
i3bar mode: Fix regression: bar_id can be NULL
  • Loading branch information
Airblader committed May 14, 2020
2 parents f63a4be + fb2677f commit 4d92900
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
18 changes: 11 additions & 7 deletions parser-specs/commands.spec
Expand Up @@ -454,23 +454,27 @@ state TITLE_FORMAT:

# bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) [<bar_id>]
state BAR:
bar_type = 'hidden_state'
'hidden_state'
-> BAR_HIDDEN_STATE
bar_type = 'mode'
'mode'
-> BAR_MODE

state BAR_HIDDEN_STATE:
bar_hidden_state = 'hide', 'show', 'toggle'
->
bar_value = 'hide', 'show', 'toggle'
-> BAR_HIDDEN_STATE_ID

state BAR_HIDDEN_STATE_ID:
bar_id = word
->
end
-> call cmd_bar_hidden_state($bar_hidden_state, $bar_id)
-> call cmd_bar_mode($bar_value, $bar_id)

state BAR_MODE:
bar_value = 'dock', 'hide', 'invisible', 'toggle'
->
-> BAR_MODE_ID

state BAR_MODE_ID:
bar_id = word
->
end
-> call cmd_bar_mode($bar_value, $bar_id)
-> call cmd_bar_hidden_state($bar_value, $bar_id)
46 changes: 38 additions & 8 deletions src/commands.c
Expand Up @@ -2094,9 +2094,14 @@ void cmd_bar_mode(I3_CMD, const char *bar_mode, const char *bar_id) {
assert(false);
}

if (TAILQ_EMPTY(&barconfigs)) {
yerror("No bars found\n");
return;
}

Barconfig *current = NULL;
TAILQ_FOREACH (current, &barconfigs, configs) {
if (strcmp(current->id, bar_id) != 0) {
if (bar_id && strcmp(current->id, bar_id) != 0) {
continue;
}

Expand All @@ -2111,11 +2116,21 @@ void cmd_bar_mode(I3_CMD, const char *bar_mode, const char *bar_id) {
ipc_send_barconfig_update_event(current);
}

ysuccess(true);
return;
if (bar_id) {
/* We are looking for a specific bar and we found it */
ysuccess(true);
return;
}
}

yerror("Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
if (bar_id) {
/* We are looking for a specific bar and we did not find it */
yerror("Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
} else {
/* We have already handled the case of no bars, so we must have
* updated all active bars now. */
ysuccess(true);
}
}

/*
Expand All @@ -2136,9 +2151,14 @@ void cmd_bar_hidden_state(I3_CMD, const char *bar_hidden_state, const char *bar_
assert(false);
}

if (TAILQ_EMPTY(&barconfigs)) {
yerror("No bars found\n");
return;
}

Barconfig *current = NULL;
TAILQ_FOREACH (current, &barconfigs, configs) {
if (strcmp(current->id, bar_id) != 0) {
if (bar_id && strcmp(current->id, bar_id) != 0) {
continue;
}

Expand All @@ -2153,11 +2173,21 @@ void cmd_bar_hidden_state(I3_CMD, const char *bar_hidden_state, const char *bar_
ipc_send_barconfig_update_event(current);
}

ysuccess(true);
return;
if (bar_id) {
/* We are looking for a specific bar and we found it */
ysuccess(true);
return;
}
}

yerror("Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
if (bar_id) {
/* We are looking for a specific bar and we did not find it */
yerror("Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
} else {
/* We have already handled the case of no bars, so we must have
* updated all active bars now. */
ysuccess(true);
}
}

/*
Expand Down

0 comments on commit 4d92900

Please sign in to comment.