From 6834a33290e7cf9466a3671cb00d3d7b08f68ca7 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Tue, 15 Dec 2015 14:05:42 +0100 Subject: [PATCH] Add bar height option (Airblader/i3) --- include/config.h | 2 +- sway/commands.c | 19 +++++++++++++++++++ sway/config.c | 2 +- sway/ipc-server.c | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/config.h b/include/config.h index 80340720..2f3b4cb0 100644 --- a/include/config.h +++ b/include/config.h @@ -92,7 +92,7 @@ struct bar_config { list_t *bindings; char *status_command; char *font; - int bar_height; + int height; // -1 not defined int tray_padding; bool workspace_buttons; bool strip_workspace_numbers; diff --git a/sway/commands.c b/sway/commands.c index 733fb293..23e6e68c 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -69,6 +69,7 @@ static sway_cmd bar_cmd_bindsym; static sway_cmd bar_cmd_colors; static sway_cmd bar_cmd_mode; static sway_cmd bar_cmd_modifier; +static sway_cmd bar_cmd_height; static sway_cmd bar_cmd_hidden_state; static sway_cmd bar_cmd_id; static sway_cmd bar_cmd_position; @@ -1592,6 +1593,23 @@ static struct cmd_results *bar_cmd_colors(int argc, char **argv) { return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL); } +static struct cmd_results *bar_cmd_height(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + int height = atoi(argv[0]); + if (height < 0) { + return cmd_results_new(CMD_INVALID, "height", + "Invalid height value: %s", argv[0]); + } + + config->current_bar->height = height; + sway_log(L_DEBUG, "Setting bar height to %d on bar: %s", height, config->current_bar->id); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "hidden_state", EXPECTED_EQUAL_TO, 1))) { @@ -1831,6 +1849,7 @@ static struct cmd_handler bar_handlers[] = { { "bindsym", bar_cmd_bindsym }, { "colors", bar_cmd_colors }, { "font", NULL }, + { "height", bar_cmd_height }, { "hidden_state", bar_cmd_hidden_state }, { "id", bar_cmd_id }, { "mode", bar_cmd_mode }, diff --git a/sway/config.c b/sway/config.c index e0c9151d..ec875169 100644 --- a/sway/config.c +++ b/sway/config.c @@ -562,7 +562,7 @@ struct bar_config *default_bar_config(void) { bar->bindings = create_list(); bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p' && sleep 1; done"); bar->font = strdup("monospace 10"); - bar->bar_height = -1; + bar->height = -1; bar->workspace_buttons = true; bar->strip_workspace_numbers = false; bar->binding_mode_indicator = true; diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 727f06da..60b61d74 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -419,7 +419,7 @@ void ipc_client_handle_command(struct ipc_client *client) { } json_object_object_add(json, "status_command", json_object_new_string(bar->status_command)); json_object_object_add(json, "font", json_object_new_string(bar->font)); - json_object_object_add(json, "bar_height", json_object_new_int(bar->bar_height)); + json_object_object_add(json, "bar_height", json_object_new_int(bar->height)); json_object_object_add(json, "workspace_buttons", json_object_new_boolean(bar->workspace_buttons)); json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers)); json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator));