From 8f0b61ce705da4ea5864696581f5ac0ff7c29558 Mon Sep 17 00:00:00 2001 From: Jansen Date: Tue, 18 Mar 2025 17:44:04 +0100 Subject: [PATCH] command for defining default floating height / width --- include/sway/commands.h | 2 ++ include/sway/config.h | 3 ++ sway/commands.c | 2 ++ sway/commands/floating_default_size.c | 43 +++++++++++++++++++++++++++ sway/config.c | 3 ++ sway/meson.build | 1 + sway/sway.5.scd | 8 +++++ sway/tree/container.c | 4 +-- 8 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 sway/commands/floating_default_size.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 5210d3ba7..f9b60b025 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -129,6 +129,8 @@ sway_cmd cmd_exec; sway_cmd cmd_exec_always; sway_cmd cmd_exit; sway_cmd cmd_floating; +sway_cmd cmd_floating_default_height; +sway_cmd cmd_floating_default_width; sway_cmd cmd_floating_maximum_size; sway_cmd cmd_floating_minimum_size; sway_cmd cmd_floating_modifier; diff --git a/include/sway/config.h b/include/sway/config.h index bb770c6f7..b1256f719 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -582,6 +582,9 @@ struct sway_config { int32_t floating_minimum_width; int32_t floating_minimum_height; + float floating_default_height; + float floating_default_width; + // The keysym to keycode translation struct xkb_state *keysym_translation_state; diff --git a/sway/commands.c b/sway/commands.c index c2c12ee65..269d1f236 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -59,6 +59,8 @@ static const struct cmd_handler handlers[] = { { "default_floating_border", cmd_default_floating_border }, { "exec", cmd_exec }, { "exec_always", cmd_exec_always }, + { "floating_default_height", cmd_floating_default_height }, + { "floating_default_width", cmd_floating_default_width }, { "floating_maximum_size", cmd_floating_maximum_size }, { "floating_minimum_size", cmd_floating_minimum_size }, { "floating_modifier", cmd_floating_modifier }, diff --git a/sway/commands/floating_default_size.c b/sway/commands/floating_default_size.c new file mode 100644 index 000000000..d09bd5c4e --- /dev/null +++ b/sway/commands/floating_default_size.c @@ -0,0 +1,43 @@ +#include "sway/commands.h" +#include +#include +#include +#include + +struct cmd_results *cmd_floating_default_width(int argc, char **argv) { + struct cmd_results *error; + if ((error = + checkarg(argc, "floating_default_width", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + char *err; + float width = strtof(argv[0], &err); + if (*err) { + return cmd_results_new(CMD_INVALID, + "Expected 'floating_default_width '"); + } + + config->floating_default_width = width; + + return cmd_results_new(CMD_SUCCESS, NULL); +} + +struct cmd_results *cmd_floating_default_height(int argc, char **argv) { + struct cmd_results *error; + if ((error = + checkarg(argc, "floating_default_height", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + char *err; + float height = strtof(argv[0], &err); + if (*err) { + return cmd_results_new(CMD_INVALID, + "Expected 'floating_default_height '"); + } + + config->floating_default_height = height; + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/config.c b/sway/config.c index ec7059687..c3ea2d416 100644 --- a/sway/config.c +++ b/sway/config.c @@ -268,6 +268,9 @@ static void config_defaults(struct sway_config *config) { config->floating_minimum_width = 75; config->floating_minimum_height = 50; + config->floating_default_height = 0.75; + config->floating_default_width = 0.5; + // Flags config->focus_follows_mouse = FOLLOWS_YES; config->mouse_warping = WARP_OUTPUT; diff --git a/sway/meson.build b/sway/meson.build index 8042c89be..936e7fcd8 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -57,6 +57,7 @@ sway_sources = files( 'commands/exec_always.c', 'commands/floating.c', 'commands/floating_minmax_size.c', + 'commands/floating_default_size.c', 'commands/floating_modifier.c', 'commands/focus.c', 'commands/focus_follows_mouse.c', diff --git a/sway/sway.5.scd b/sway/sway.5.scd index f580b2af3..9fadb9ceb 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -711,6 +711,14 @@ The default colors are: *floating_minimum_size* x Specifies the minimum size of floating windows. The default is 75 x 50. +*floating_default_height* + Specifies the default size of floating windows as fraction of maximal + available height + +*floating_default_width* + Specifies the default size of floating windows as fraction of maximal + available width + *floating_modifier* [normal|inverse] When the _modifier_ key is held down, you may hold left click to move windows, and right click to resize them. Setting _modifier_ to _none_ diff --git a/sway/tree/container.c b/sway/tree/container.c index 6ff4036fa..7dec9d070 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -953,8 +953,8 @@ void container_floating_set_default_size(struct sway_container *con) { struct wlr_box box; workspace_get_box(con->pending.workspace, &box); - double width = fmax(min_width, fmin(box.width * 0.5, max_width)); - double height = fmax(min_height, fmin(box.height * 0.75, max_height)); + double width = fmax(min_width, fmin(box.width * config->floating_default_width, max_width)); + double height = fmax(min_height, fmin(box.height * config->floating_default_height, max_height)); if (!con->view) { con->pending.width = width; con->pending.height = height;