mirror of
https://github.com/swaywm/sway.git
synced 2024-11-11 13:04:11 +01:00
Fix bar subcommand handler structs and selection
This commit is contained in:
parent
782a835175
commit
00745d6280
@ -531,6 +531,8 @@ void free_sway_binding(struct sway_binding *sb);
|
|||||||
|
|
||||||
void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding);
|
void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding);
|
||||||
|
|
||||||
|
void load_swaybar(struct bar_config *bar);
|
||||||
|
|
||||||
void load_swaybars(void);
|
void load_swaybars(void);
|
||||||
|
|
||||||
void terminate_swaybg(pid_t pid);
|
void terminate_swaybg(pid_t pid);
|
||||||
|
@ -17,7 +17,6 @@ static struct cmd_handler bar_handlers[] = {
|
|||||||
{ "height", bar_cmd_height },
|
{ "height", bar_cmd_height },
|
||||||
{ "hidden_state", bar_cmd_hidden_state },
|
{ "hidden_state", bar_cmd_hidden_state },
|
||||||
{ "icon_theme", bar_cmd_icon_theme },
|
{ "icon_theme", bar_cmd_icon_theme },
|
||||||
{ "id", bar_cmd_id },
|
|
||||||
{ "mode", bar_cmd_mode },
|
{ "mode", bar_cmd_mode },
|
||||||
{ "modifier", bar_cmd_modifier },
|
{ "modifier", bar_cmd_modifier },
|
||||||
{ "output", bar_cmd_output },
|
{ "output", bar_cmd_output },
|
||||||
@ -27,7 +26,6 @@ static struct cmd_handler bar_handlers[] = {
|
|||||||
{ "separator_symbol", bar_cmd_separator_symbol },
|
{ "separator_symbol", bar_cmd_separator_symbol },
|
||||||
{ "status_command", bar_cmd_status_command },
|
{ "status_command", bar_cmd_status_command },
|
||||||
{ "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
|
{ "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
|
||||||
{ "swaybar_command", bar_cmd_swaybar_command },
|
|
||||||
{ "tray_output", bar_cmd_tray_output },
|
{ "tray_output", bar_cmd_tray_output },
|
||||||
{ "tray_padding", bar_cmd_tray_padding },
|
{ "tray_padding", bar_cmd_tray_padding },
|
||||||
{ "workspace_buttons", bar_cmd_workspace_buttons },
|
{ "workspace_buttons", bar_cmd_workspace_buttons },
|
||||||
@ -36,8 +34,8 @@ static struct cmd_handler bar_handlers[] = {
|
|||||||
|
|
||||||
// Must be in alphabetical order for bsearch
|
// Must be in alphabetical order for bsearch
|
||||||
static struct cmd_handler bar_config_handlers[] = {
|
static struct cmd_handler bar_config_handlers[] = {
|
||||||
{ "hidden_state", bar_cmd_hidden_state },
|
{ "id", bar_cmd_id },
|
||||||
{ "mode", bar_cmd_mode }
|
{ "swaybar_command", bar_cmd_swaybar_command },
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_results *cmd_bar(int argc, char **argv) {
|
struct cmd_results *cmd_bar(int argc, char **argv) {
|
||||||
@ -46,16 +44,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (find_handler(argv[0], bar_config_handlers,
|
bool spawn = false;
|
||||||
sizeof(bar_config_handlers))) {
|
|
||||||
if (config->reading) {
|
|
||||||
return config_subcommand(argv, argc, bar_config_handlers,
|
|
||||||
sizeof(bar_config_handlers));
|
|
||||||
}
|
|
||||||
return cmd_results_new(CMD_FAILURE, "bar",
|
|
||||||
"Can only be used in config file.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
struct bar_config *bar = NULL;
|
struct bar_config *bar = NULL;
|
||||||
if (!find_handler(argv[0], bar_handlers, sizeof(bar_handlers))
|
if (!find_handler(argv[0], bar_handlers, sizeof(bar_handlers))
|
||||||
@ -69,6 +58,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!bar) {
|
if (!bar) {
|
||||||
|
spawn = !config->reading;
|
||||||
wlr_log(WLR_DEBUG, "Creating bar: %s", argv[0]);
|
wlr_log(WLR_DEBUG, "Creating bar: %s", argv[0]);
|
||||||
bar = default_bar_config();
|
bar = default_bar_config();
|
||||||
if (!bar) {
|
if (!bar) {
|
||||||
@ -83,7 +73,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config->current_bar) {
|
if (!config->current_bar && config->reading) {
|
||||||
// Create new bar with default values
|
// Create new bar with default values
|
||||||
struct bar_config *bar = default_bar_config();
|
struct bar_config *bar = default_bar_config();
|
||||||
if (!bar) {
|
if (!bar) {
|
||||||
@ -111,5 +101,23 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
|
|||||||
wlr_log(WLR_DEBUG, "Creating bar %s", bar->id);
|
wlr_log(WLR_DEBUG, "Creating bar %s", bar->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return config_subcommand(argv, argc, bar_handlers, sizeof(bar_handlers));
|
if (find_handler(argv[0], bar_config_handlers,
|
||||||
|
sizeof(bar_config_handlers))) {
|
||||||
|
if (config->reading) {
|
||||||
|
return config_subcommand(argv, argc, bar_config_handlers,
|
||||||
|
sizeof(bar_config_handlers));
|
||||||
|
}
|
||||||
|
return cmd_results_new(CMD_INVALID, "bar",
|
||||||
|
"Can only be used in the config file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
struct cmd_results *res =
|
||||||
|
config_subcommand(argv, argc, bar_handlers, sizeof(bar_handlers));
|
||||||
|
if (!config->reading) {
|
||||||
|
if (spawn) {
|
||||||
|
load_swaybar(config->current_bar);
|
||||||
|
}
|
||||||
|
config->current_bar = NULL;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -226,13 +226,17 @@ static void invoke_swaybar(struct bar_config *bar) {
|
|||||||
close(filedes[1]);
|
close(filedes[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load_swaybar(struct bar_config *bar) {
|
||||||
|
if (bar->pid != 0) {
|
||||||
|
terminate_swaybar(bar->pid);
|
||||||
|
}
|
||||||
|
wlr_log(WLR_DEBUG, "Invoking swaybar for bar id '%s'", bar->id);
|
||||||
|
invoke_swaybar(bar);
|
||||||
|
}
|
||||||
|
|
||||||
void load_swaybars(void) {
|
void load_swaybars(void) {
|
||||||
for (int i = 0; i < config->bars->length; ++i) {
|
for (int i = 0; i < config->bars->length; ++i) {
|
||||||
struct bar_config *bar = config->bars->items[i];
|
struct bar_config *bar = config->bars->items[i];
|
||||||
if (bar->pid != 0) {
|
load_swaybar(bar);
|
||||||
terminate_swaybar(bar->pid);
|
|
||||||
}
|
|
||||||
wlr_log(WLR_DEBUG, "Invoking swaybar for bar id '%s'", bar->id);
|
|
||||||
invoke_swaybar(bar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user