From 61699a11463d5a1168358ba5f7fece6401ab0654 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 9 Oct 2018 22:25:21 +1000 Subject: resize: Determine if anything changed using before/after check Returning a boolean from container_resize_tiled and resize_tiled doesn't work in all cases. This patch changes it back to void and does a before/after check to see if the container was resized. --- sway/commands/resize.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'sway/commands') diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 1343b165..6de14ca3 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -179,11 +179,11 @@ static void container_recursive_resize(struct sway_container *container, } } -static bool resize_tiled(struct sway_container *parent, int amount, +static void resize_tiled(struct sway_container *parent, int amount, enum resize_axis axis) { struct sway_container *focused = parent; if (!parent) { - return false; + return; } enum sway_container_layout parallel_layout = @@ -216,7 +216,7 @@ static bool resize_tiled(struct sway_container *parent, int amount, } if (!parent) { // Can't resize in this direction - return false; + return; } // Implement up/down/left/right direction by zeroing one of the weights, @@ -248,22 +248,22 @@ static bool resize_tiled(struct sway_container *parent, int amount, if (sibling_pos < parent_pos && minor_weight) { double pixels = -amount / minor_weight; if (major_weight && (sibling_size + pixels / 2) < min_sane) { - return false; // Too small + return; // Too small } else if (!major_weight && sibling_size + pixels < min_sane) { - return false; // Too small + return; // Too small } } else if (sibling_pos > parent_pos && major_weight) { double pixels = -amount / major_weight; if (minor_weight && (sibling_size + pixels / 2) < min_sane) { - return false; // Too small + return; // Too small } else if (!minor_weight && sibling_size + pixels < min_sane) { - return false; // Too small + return; // Too small } } } else { double pixels = amount; if (parent_size + pixels < min_sane) { - return false; // Too small + return; // Too small } } } @@ -317,10 +317,9 @@ static bool resize_tiled(struct sway_container *parent, int amount, } else { arrange_workspace(parent->workspace); } - return true; } -bool container_resize_tiled(struct sway_container *parent, +void container_resize_tiled(struct sway_container *parent, enum wlr_edges edge, int amount) { enum resize_axis axis = RESIZE_AXIS_INVALID; switch (edge) { @@ -339,7 +338,7 @@ bool container_resize_tiled(struct sway_container *parent, case WLR_EDGE_NONE: break; } - return resize_tiled(parent, amount, axis); + resize_tiled(parent, amount, axis); } /** @@ -447,7 +446,10 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis, } } - if (!resize_tiled(current, amount->amount, axis)) { + double old_width = current->width; + double old_height = current->height; + resize_tiled(current, amount->amount, axis); + if (current->width == old_width && current->height == old_height) { return cmd_results_new(CMD_INVALID, "resize", "Cannot resize any further"); } -- cgit v1.2.3 From 41991542cac1d909a55fc834d231fe747097b1a4 Mon Sep 17 00:00:00 2001 From: Rouven Czerwinski Date: Wed, 10 Oct 2018 11:28:37 +0200 Subject: Add mouse_warping container This option always moves the cursor into the middle of the container if the warp variable is true in seat_set_focus_warp. Fixes #2577 --- include/sway/config.h | 8 +++++++- sway/commands/mouse_warping.c | 8 +++++--- sway/config.c | 2 +- sway/input/seat.c | 8 ++++++-- sway/sway.5.scd | 5 +++-- 5 files changed, 22 insertions(+), 9 deletions(-) (limited to 'sway/commands') diff --git a/include/sway/config.h b/include/sway/config.h index 00b5f25b..0325042c 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -325,6 +325,12 @@ enum focus_wrapping_mode { WRAP_FORCE }; +enum mouse_warping_mode { + WARP_NO, + WARP_OUTPUT, + WARP_CONTAINER +}; + /** * The configuration struct. The result of loading a config file. */ @@ -366,7 +372,7 @@ struct sway_config { // Flags bool focus_follows_mouse; bool raise_floating; - bool mouse_warping; + enum mouse_warping_mode mouse_warping; enum focus_wrapping_mode focus_wrapping; bool active; bool failed; diff --git a/sway/commands/mouse_warping.c b/sway/commands/mouse_warping.c index eef32ce7..d067bc65 100644 --- a/sway/commands/mouse_warping.c +++ b/sway/commands/mouse_warping.c @@ -6,13 +6,15 @@ struct cmd_results *cmd_mouse_warping(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { return error; + } else if (strcasecmp(argv[0], "container") == 0) { + config->mouse_warping = WARP_CONTAINER; } else if (strcasecmp(argv[0], "output") == 0) { - config->mouse_warping = true; + config->mouse_warping = WARP_OUTPUT; } else if (strcasecmp(argv[0], "none") == 0) { - config->mouse_warping = false; + config->mouse_warping = WARP_NO; } else { return cmd_results_new(CMD_FAILURE, "mouse_warping", - "Expected 'mouse_warping output|none'"); + "Expected 'mouse_warping output|container|none'"); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/config.c b/sway/config.c index 1926bc08..f239ba1d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -223,7 +223,7 @@ static void config_defaults(struct sway_config *config) { // Flags config->focus_follows_mouse = true; config->raise_floating = true; - config->mouse_warping = true; + config->mouse_warping = WARP_OUTPUT; config->focus_wrapping = WRAP_YES; config->validating = false; config->reloading = false; diff --git a/sway/input/seat.c b/sway/input/seat.c index f418785d..7508d6b9 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -772,7 +772,9 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, } if (last_focus) { - if (config->mouse_warping && warp && new_output != last_output) { + if (config->mouse_warping && warp && + (new_output != last_output || + config->mouse_warping == WARP_CONTAINER)) { double x = 0; double y = 0; if (container) { @@ -782,9 +784,11 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, x = new_workspace->x + new_workspace->width / 2.0; y = new_workspace->y + new_workspace->height / 2.0; } + if (!wlr_output_layout_contains_point(root->output_layout, new_output->wlr_output, seat->cursor->cursor->x, - seat->cursor->cursor->y)) { + seat->cursor->cursor->y) + || config->mouse_warping == WARP_CONTAINER) { wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); cursor_send_pointer_motion(seat->cursor, 0, true); } diff --git a/sway/sway.5.scd b/sway/sway.5.scd index b4c290e4..240e0731 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -492,9 +492,10 @@ The default colors are: If _--pango\_markup_ is given, then _mode_ will be interpreted as pango markup. -*mouse\_warping* output|none +*mouse\_warping* output|container|none If _output_ is specified, the mouse will be moved to new outputs as you - move focus between them. Default is _output_. + move focus between them. If _container_ is specified, the mouse will be + moved to the middle of the container on switch. Default is _output_. *no\_focus* Prevents windows matching from being focused automatically when -- cgit v1.2.3