From 69265ad34cd218e1f9e47ad3db6f6aff574c8fd5 Mon Sep 17 00:00:00 2001 From: Josip Janzic Date: Sat, 31 Aug 2019 11:16:10 +0200 Subject: [PATCH] Add new command to set titlebar position --- include/sway/commands.h | 1 + include/sway/config.h | 6 ++++++ sway/commands.c | 1 + sway/commands/titlebar_position.c | 30 ++++++++++++++++++++++++++++++ sway/config.c | 1 + sway/meson.build | 1 + 6 files changed, 40 insertions(+) create mode 100644 sway/commands/titlebar_position.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 270585870..a19b0ccfe 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -190,6 +190,7 @@ sway_cmd cmd_title_align; sway_cmd cmd_title_format; sway_cmd cmd_titlebar_border_thickness; sway_cmd cmd_titlebar_padding; +sway_cmd cmd_titlebar_position; sway_cmd cmd_unbindcode; sway_cmd cmd_unbindswitch; sway_cmd cmd_unbindgesture; diff --git a/include/sway/config.h b/include/sway/config.h index f9da19675..64e7d2f06 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -473,6 +473,11 @@ enum xwayland_mode { XWAYLAND_MODE_IMMEDIATE, }; +enum titlebar_position { + TITLEBAR_TOP, + TITLEBAR_BOTTOM +}; + /** * The configuration struct. The result of loading a config file. */ @@ -534,6 +539,7 @@ struct sway_config { bool show_marks; enum alignment title_align; bool primary_selection; + enum titlebar_position titlebar_position; bool tiling_drag; int tiling_drag_threshold; diff --git a/sway/commands.c b/sway/commands.c index 55eda183c..884d7ce8e 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -93,6 +93,7 @@ static const struct cmd_handler handlers[] = { { "title_align", cmd_title_align }, { "titlebar_border_thickness", cmd_titlebar_border_thickness }, { "titlebar_padding", cmd_titlebar_padding }, + { "titlebar_position", cmd_titlebar_position }, { "unbindcode", cmd_unbindcode }, { "unbindgesture", cmd_unbindgesture }, { "unbindswitch", cmd_unbindswitch }, diff --git a/sway/commands/titlebar_position.c b/sway/commands/titlebar_position.c new file mode 100644 index 000000000..4c53e1f56 --- /dev/null +++ b/sway/commands/titlebar_position.c @@ -0,0 +1,30 @@ +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/output.h" +#include "sway/tree/arrange.h" +#include "sway/tree/root.h" + +struct cmd_results *cmd_titlebar_position(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "titlebar_position", EXPECTED_AT_LEAST, 1))) { + return error; + } + + if (strcmp(argv[0], "top") == 0) { + config->titlebar_position = TITLEBAR_TOP; + } else if (strcmp(argv[0], "bottom") == 0) { + config->titlebar_position = TITLEBAR_BOTTOM; + } else { + return cmd_results_new(CMD_INVALID, + "Expected 'titlebar_position top|bottom'"); + } + + arrange_root(); + for (int i = 0; i < root->outputs->length; ++i) { + struct sway_output *output = root->outputs->items[i]; + output_damage_whole(output); + } + + return cmd_results_new(CMD_SUCCESS, NULL); +} + diff --git a/sway/config.c b/sway/config.c index 8c8c148d9..a7022a42e 100644 --- a/sway/config.c +++ b/sway/config.c @@ -271,6 +271,7 @@ static void config_defaults(struct sway_config *config) { config->reading = false; config->show_marks = true; config->title_align = ALIGN_LEFT; + config->titlebar_position = TITLEBAR_TOP; config->tiling_drag = true; config->tiling_drag_threshold = 9; config->primary_selection = true; diff --git a/sway/meson.build b/sway/meson.build index 3abd778db..3f8de9545 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -117,6 +117,7 @@ sway_sources = files( 'commands/title_format.c', 'commands/titlebar_border_thickness.c', 'commands/titlebar_padding.c', + 'commands/titlebar_position.c', 'commands/unmark.c', 'commands/urgent.c', 'commands/workspace.c',