From b692a6d31abf8ddda0ed2be78eaf73d465cb2faf Mon Sep 17 00:00:00 2001 From: Denis Doria Date: Thu, 2 Jun 2016 17:35:02 +0200 Subject: [PATCH] Initial implementation for floating_maximum_size --- sway/commands.c | 36 ++++++++++++++++++++++++++++++++++++ sway/config.c | 4 ++-- sway/container.c | 25 ++++++++++++++++++++----- sway/sway.5.txt | 7 +++++++ 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index d8f61242a..3befee133 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -58,6 +58,7 @@ static sway_cmd cmd_exec; static sway_cmd cmd_exec_always; static sway_cmd cmd_exit; static sway_cmd cmd_floating; +static sway_cmd cmd_floating_maximum_size; static sway_cmd cmd_floating_minimum_size; static sway_cmd cmd_floating_mod; static sway_cmd cmd_floating_scroll; @@ -674,6 +675,40 @@ static struct cmd_results *cmd_floating(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *cmd_floating_maximum_size(int argc, char **argv) { + struct cmd_results *error = NULL; + int32_t width; + int32_t height; + char *ptr; + + if ((error = checkarg(argc, "floating_maximum_size", EXPECTED_EQUAL_TO, 3))) { + return error; + } + width = strtol(argv[0], &ptr, 10); + height = strtol(argv[2], &ptr, 10); + + if (width < -1) { + sway_log(L_DEBUG, "floating_maximum_size invalid width value: '%s'", argv[0]); + + } else { + config->floating_maximum_width = width; + + } + + if (height < -1) { + sway_log(L_DEBUG, "floating_maximum_size invalid height value: '%s'", argv[2]); + } + else { + config->floating_maximum_height = height; + + } + + sway_log(L_DEBUG, "New floating_maximum_size: '%d' x '%d'", config->floating_maximum_width, + config->floating_maximum_height); + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) { struct cmd_results *error = NULL; int32_t width; @@ -2468,6 +2503,7 @@ static struct cmd_handler handlers[] = { { "exec_always", cmd_exec_always }, { "exit", cmd_exit }, { "floating", cmd_floating }, + { "floating_maximum_size", cmd_floating_maximum_size }, { "floating_minimum_size", cmd_floating_minimum_size }, { "floating_modifier", cmd_floating_mod }, { "floating_scroll", cmd_floating_scroll }, diff --git a/sway/config.c b/sway/config.c index 95285eba6..151081235 100644 --- a/sway/config.c +++ b/sway/config.c @@ -173,8 +173,8 @@ static void config_defaults(struct sway_config *config) { config->font_height = get_font_text_height(config->font); // floating view - config->floating_maximum_width = -1; - config->floating_maximum_height = -1; + config->floating_maximum_width = 0; + config->floating_maximum_height = 0; config->floating_minimum_width = 75; config->floating_minimum_height = 50; diff --git a/sway/container.c b/sway/container.c index e00d2d7e2..159750647 100644 --- a/sway/container.c +++ b/sway/container.c @@ -329,6 +329,9 @@ swayc_t *new_floating_view(wlc_handle handle) { } void floating_view_sane_size(swayc_t *view) { + // floating_minimum is used as sane value. + // floating_maximum has priority in case of conflict + // TODO: implement total_outputs_dimensions() if (config->floating_minimum_height != -1 && view->desired_height < config->floating_minimum_height) { view->desired_height = config->floating_minimum_height; @@ -338,14 +341,26 @@ void floating_view_sane_size(swayc_t *view) { view->desired_width = config->floating_minimum_width; } - if (config->floating_maximum_height != -1 && - view->desired_height > config->floating_maximum_height) { - view->desired_height = config->floating_maximum_height; - } - if (config->floating_maximum_width != -1 && + // if 0 do not resize, only enforce max value + if (config->floating_maximum_height == 0) { + // Missing total_outputs_dimensions() using swayc_active_workspace() + config->floating_maximum_height = swayc_active_workspace()->height; + + } else if (config->floating_maximum_height != -1 && + view->desired_height > config->floating_maximum_height) { + view->desired_height = config->floating_maximum_height; + } + + // if 0 do not resize, only enforce max value + if (config->floating_maximum_width == 0) { + // Missing total_outputs_dimensions() using swayc_active_workspace() + config->floating_maximum_width = swayc_active_workspace()->width; + + } else if (config->floating_maximum_width != -1 && view->desired_width > config->floating_maximum_width) { view->desired_width = config->floating_maximum_width; } + sway_log(L_DEBUG, "Sane values for view to %d x %d @ %.f, %.f", view->desired_width, view->desired_height, view->x, view->y); diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 1afcf24f0..8faa5345f 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt @@ -65,6 +65,13 @@ They are expected to be used with **bindsym** or at runtime through **swaymsg**( **floating** :: Make focused view floating, non-floating, or the opposite of what it is now. +**floating_maximum_size** x :: + Specifies the maximum dimensions of floating windows. + Uses the container dimensions as default. + -1 x -1 will remove any restriction on dimentions. + 0 x 0 has the same behavior as not setting any value. + If in conflict this option has precedence over floating_minimum_size. + **floating_minimum_size** x :: Specifies the minimum dimensions of floating windows. Default parameters are 75 x 50.