aboutsummaryrefslogtreecommitdiffstats
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
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`.
-rw-r--r--include/sway/tree/container.h3
-rw-r--r--sway/commands/resize.c45
-rw-r--r--sway/input/seatop_resize_floating.c37
-rw-r--r--sway/sway.5.scd3
-rw-r--r--sway/tree/container.c64
5 files changed, 53 insertions, 99 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index f7a4ac37..d2508994 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -212,6 +212,9 @@ void container_update_representation(struct sway_container *container);
212 */ 212 */
213size_t container_titlebar_height(void); 213size_t container_titlebar_height(void);
214 214
215void floating_calculate_constraints(int *min_width, int *max_width,
216 int *min_height, int *max_height);
217
215/** 218/**
216 * Resize and center the container in its workspace. 219 * Resize and center the container in its workspace.
217 */ 220 */
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) {
diff --git a/sway/input/seatop_resize_floating.c b/sway/input/seatop_resize_floating.c
index bf6c7ab4..18c6db73 100644
--- a/sway/input/seatop_resize_floating.c
+++ b/sway/input/seatop_resize_floating.c
@@ -17,41 +17,6 @@ struct seatop_resize_floating_event {
17 double ref_con_lx, ref_con_ly; // container's x/y at start of op 17 double ref_con_lx, ref_con_ly; // container's x/y at start of op
18}; 18};
19 19
20static void calculate_floating_constraints(struct sway_container *con,
21 int *min_width, int *max_width, int *min_height, int *max_height) {
22 if (config->floating_minimum_width == -1) { // no minimum
23 *min_width = 0;
24 } else if (config->floating_minimum_width == 0) { // automatic
25 *min_width = 75;
26 } else {
27 *min_width = config->floating_minimum_width;
28 }
29
30 if (config->floating_minimum_height == -1) { // no minimum
31 *min_height = 0;
32 } else if (config->floating_minimum_height == 0) { // automatic
33 *min_height = 50;
34 } else {
35 *min_height = config->floating_minimum_height;
36 }
37
38 if (config->floating_maximum_width == -1) { // no maximum
39 *max_width = INT_MAX;
40 } else if (config->floating_maximum_width == 0) { // automatic
41 *max_width = con->workspace->width;
42 } else {
43 *max_width = config->floating_maximum_width;
44 }
45
46 if (config->floating_maximum_height == -1) { // no maximum
47 *max_height = INT_MAX;
48 } else if (config->floating_maximum_height == 0) { // automatic
49 *max_height = con->workspace->height;
50 } else {
51 *max_height = config->floating_maximum_height;
52 }
53}
54
55static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { 20static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
56 struct seatop_resize_floating_event *e = seat->seatop_data; 21 struct seatop_resize_floating_event *e = seat->seatop_data;
57 struct sway_container *con = e->con; 22 struct sway_container *con = e->con;
@@ -85,7 +50,7 @@ static void handle_motion(struct sway_seat *seat, uint32_t time_msec) {
85 double width = e->ref_width + grow_width; 50 double width = e->ref_width + grow_width;
86 double height = e->ref_height + grow_height; 51 double height = e->ref_height + grow_height;
87 int min_width, max_width, min_height, max_height; 52 int min_width, max_width, min_height, max_height;
88 calculate_floating_constraints(con, &min_width, &max_width, 53 floating_calculate_constraints(&min_width, &max_width,
89 &min_height, &max_height); 54 &min_height, &max_height);
90 width = fmax(min_width, fmin(width, max_width)); 55 width = fmax(min_width, fmin(width, max_width));
91 height = fmax(min_height, fmin(height, max_height)); 56 height = fmax(min_height, fmin(height, max_height));
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 847b7727..7562efea 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -430,7 +430,8 @@ The default colors are:
430 430
431*floating_maximum_size* <width> x <height> 431*floating_maximum_size* <width> x <height>
432 Specifies the maximum size of floating windows. -1 x -1 removes the upper 432 Specifies the maximum size of floating windows. -1 x -1 removes the upper
433 limit. 433 limit. The default is 0 x 0, which will use the width and height of the
434 entire output layout as the maximums
434 435
435*floating_minimum_size* <width> x <height> 436*floating_minimum_size* <width> x <height>
436 Specifies the minimum size of floating windows. The default is 75 x 50. 437 Specifies the minimum size of floating windows. The default is 75 x 50.
diff --git a/sway/tree/container.c b/sway/tree/container.c
index d448df22..33043941 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -611,56 +611,78 @@ size_t container_titlebar_height(void) {
611 return config->font_height + config->titlebar_v_padding * 2; 611 return config->font_height + config->titlebar_v_padding * 2;
612} 612}
613 613
614void container_init_floating(struct sway_container *con) { 614void floating_calculate_constraints(int *min_width, int *max_width,
615 struct sway_workspace *ws = con->workspace; 615 int *min_height, int *max_height) {
616 int min_width, min_height;
617 int max_width, max_height;
618
619 if (config->floating_minimum_width == -1) { // no minimum 616 if (config->floating_minimum_width == -1) { // no minimum
620 min_width = 0; 617 *min_width = 0;
621 } else if (config->floating_minimum_width == 0) { // automatic 618 } else if (config->floating_minimum_width == 0) { // automatic
622 min_width = 75; 619 *min_width = 75;
623 } else { 620 } else {
624 min_width = config->floating_minimum_width; 621 *min_width = config->floating_minimum_width;
625 } 622 }
626 623
627 if (config->floating_minimum_height == -1) { // no minimum 624 if (config->floating_minimum_height == -1) { // no minimum
628 min_height = 0; 625 *min_height = 0;
629 } else if (config->floating_minimum_height == 0) { // automatic 626 } else if (config->floating_minimum_height == 0) { // automatic
630 min_height = 50; 627 *min_height = 50;
631 } else { 628 } else {
632 min_height = config->floating_minimum_height; 629 *min_height = config->floating_minimum_height;
633 } 630 }
634 631
632 struct wlr_box *box = wlr_output_layout_get_box(root->output_layout, NULL);
633
635 if (config->floating_maximum_width == -1) { // no maximum 634 if (config->floating_maximum_width == -1) { // no maximum
636 max_width = INT_MAX; 635 *max_width = INT_MAX;
637 } else if (config->floating_maximum_width == 0) { // automatic 636 } else if (config->floating_maximum_width == 0) { // automatic
638 max_width = ws->width * 0.6666; 637 *max_width = box->width;
639 } else { 638 } else {
640 max_width = config->floating_maximum_width; 639 *max_width = config->floating_maximum_width;
641 } 640 }
642 641
643 if (config->floating_maximum_height == -1) { // no maximum 642 if (config->floating_maximum_height == -1) { // no maximum
644 max_height = INT_MAX; 643 *max_height = INT_MAX;
645 } else if (config->floating_maximum_height == 0) { // automatic 644 } else if (config->floating_maximum_height == 0) { // automatic
646 max_height = ws->height * 0.6666; 645 *max_height = box->height;
647 } else { 646 } else {
648 max_height = config->floating_maximum_height; 647 *max_height = config->floating_maximum_height;
649 } 648 }
650 649
650}
651
652void container_init_floating(struct sway_container *con) {
653 struct sway_workspace *ws = con->workspace;
654 int min_width, max_width, min_height, max_height;
655 floating_calculate_constraints(&min_width, &max_width,
656 &min_height, &max_height);
657
651 if (!con->view) { 658 if (!con->view) {
652 con->width = max_width; 659 con->width = max_width;
653 con->height = max_height; 660 con->height = max_height;
654 con->x = ws->x + (ws->width - con->width) / 2; 661 if (con->width > ws->width || con->height > ws->height) {
655 con->y = ws->y + (ws->height - con->height) / 2; 662 struct wlr_box *ob = wlr_output_layout_get_box(root->output_layout,
663 ws->output->wlr_output);
664 con->x = ob->x + (ob->width - con->width) / 2;
665 con->y = ob->y + (ob->height - con->height) / 2;
666 } else {
667 con->x = ws->x + (ws->width - con->width) / 2;
668 con->y = ws->y + (ws->height - con->height) / 2;
669 }
656 } else { 670 } else {
657 struct sway_view *view = con->view; 671 struct sway_view *view = con->view;
658 con->content_width = 672 con->content_width =
659 fmax(min_width, fmin(view->natural_width, max_width)); 673 fmax(min_width, fmin(view->natural_width, max_width));
660 con->content_height = 674 con->content_height =
661 fmax(min_height, fmin(view->natural_height, max_height)); 675 fmax(min_height, fmin(view->natural_height, max_height));
662 con->content_x = ws->x + (ws->width - con->content_width) / 2; 676 if (con->content_width > ws->width
663 con->content_y = ws->y + (ws->height - con->content_height) / 2; 677 || con->content_height > ws->height) {
678 struct wlr_box *ob = wlr_output_layout_get_box(root->output_layout,
679 ws->output->wlr_output);
680 con->content_x = ob->x + (ob->width - con->content_width) / 2;
681 con->content_y = ob->y + (ob->height - con->content_height) / 2;
682 } else {
683 con->content_x = ws->x + (ws->width - con->content_width) / 2;
684 con->content_y = ws->y + (ws->height - con->content_height) / 2;
685 }
664 686
665 // If the view's border is B_NONE then these properties are ignored. 687 // If the view's border is B_NONE then these properties are ignored.
666 con->border_top = con->border_bottom = true; 688 con->border_top = con->border_bottom = true;