aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/resize.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-03-02 02:29:28 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-03-04 12:50:47 -0500
commita3b9f2dcfa649d9141f7bbb39e5eb951560eef72 (patch)
treefe8e29aed212a23fbdb66237170f5e4b4d79c139 /sway/commands/resize.c
parentMinor fix of code duplication. (diff)
downloadsway-a3b9f2dcfa649d9141f7bbb39e5eb951560eef72.tar.gz
sway-a3b9f2dcfa649d9141f7bbb39e5eb951560eef72.tar.zst
sway-a3b9f2dcfa649d9141f7bbb39e5eb951560eef72.zip
floating_maximum_size: change default behavior
This changes the way zero (which is the default) is interpreted for both the width and height of `floating_maximum_size`. It now refers to the width and height of the entire output layout, which matches i3's behavior. This also removes duplicated code to calculate the floating constraints in three files. Before this, `container_init_floating` used two-thirds of the workspace width/height as the max and the entire workspace width/height was used everywhere else. Now, all callers use a single function `floating_calculate_constraints`.
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r--sway/commands/resize.c45
1 files changed, 4 insertions, 41 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index c9261535..440937f0 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -66,45 +66,6 @@ static int parse_resize_amount(int argc, char **argv,
66 return 2; 66 return 2;
67} 67}
68 68
69static void calculate_constraints(int *min_width, int *max_width,
70 int *min_height, int *max_height) {
71 struct sway_container *con = config->handler_context.container;
72
73 if (config->floating_minimum_width == -1) { // no minimum
74 *min_width = 0;
75 } else if (config->floating_minimum_width == 0) { // automatic
76 *min_width = 75;
77 } else {
78 *min_width = config->floating_minimum_width;
79 }
80
81 if (config->floating_minimum_height == -1) { // no minimum
82 *min_height = 0;
83 } else if (config->floating_minimum_height == 0) { // automatic
84 *min_height = 50;
85 } else {
86 *min_height = config->floating_minimum_height;
87 }
88
89 if (config->floating_maximum_width == -1 ||
90 container_is_scratchpad_hidden(con)) { // no max
91 *max_width = INT_MAX;
92 } else if (config->floating_maximum_width == 0) { // automatic
93 *max_width = con->workspace->width;
94 } else {
95 *max_width = config->floating_maximum_width;
96 }
97
98 if (config->floating_maximum_height == -1 ||
99 container_is_scratchpad_hidden(con)) { // no max
100 *max_height = INT_MAX;
101 } else if (config->floating_maximum_height == 0) { // automatic
102 *max_height = con->workspace->height;
103 } else {
104 *max_height = config->floating_maximum_height;
105 }
106}
107
108static uint32_t parse_resize_axis(const char *axis) { 69static uint32_t parse_resize_axis(const char *axis) {
109 if (strcasecmp(axis, "width") == 0 || strcasecmp(axis, "horizontal") == 0) { 70 if (strcasecmp(axis, "width") == 0 || strcasecmp(axis, "horizontal") == 0) {
110 return AXIS_HORIZONTAL; 71 return AXIS_HORIZONTAL;
@@ -258,7 +219,8 @@ static struct cmd_results *resize_adjust_floating(uint32_t axis,
258 219
259 // Make sure we're not adjusting beyond floating min/max size 220 // Make sure we're not adjusting beyond floating min/max size
260 int min_width, max_width, min_height, max_height; 221 int min_width, max_width, min_height, max_height;
261 calculate_constraints(&min_width, &max_width, &min_height, &max_height); 222 floating_calculate_constraints(&min_width, &max_width,
223 &min_height, &max_height);
262 if (con->width + grow_width < min_width) { 224 if (con->width + grow_width < min_width) {
263 grow_width = min_width - con->width; 225 grow_width = min_width - con->width;
264 } else if (con->width + grow_width > max_width) { 226 } else if (con->width + grow_width > max_width) {
@@ -383,7 +345,8 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con,
383static struct cmd_results *resize_set_floating(struct sway_container *con, 345static struct cmd_results *resize_set_floating(struct sway_container *con,
384 struct resize_amount *width, struct resize_amount *height) { 346 struct resize_amount *width, struct resize_amount *height) {
385 int min_width, max_width, min_height, max_height, grow_width = 0, grow_height = 0; 347 int min_width, max_width, min_height, max_height, grow_width = 0, grow_height = 0;
386 calculate_constraints(&min_width, &max_width, &min_height, &max_height); 348 floating_calculate_constraints(&min_width, &max_width,
349 &min_height, &max_height);
387 350
388 if (width->amount) { 351 if (width->amount) {
389 switch (width->unit) { 352 switch (width->unit) {