diff options
author | Rouven Czerwinski <rouven@czerwinskis.de> | 2018-10-10 11:28:37 +0200 |
---|---|---|
committer | Rouven Czerwinski <rouven@czerwinskis.de> | 2018-10-10 12:45:21 +0200 |
commit | 41991542cac1d909a55fc834d231fe747097b1a4 (patch) | |
tree | 0e0eba7984d8e98b70c29159a2792ec1e39b9351 | |
parent | Merge pull request #2812 from RyanDwyer/fix-version-messages (diff) | |
download | sway-41991542cac1d909a55fc834d231fe747097b1a4.tar.gz sway-41991542cac1d909a55fc834d231fe747097b1a4.tar.zst sway-41991542cac1d909a55fc834d231fe747097b1a4.zip |
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
-rw-r--r-- | include/sway/config.h | 8 | ||||
-rw-r--r-- | sway/commands/mouse_warping.c | 8 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/input/seat.c | 8 | ||||
-rw-r--r-- | sway/sway.5.scd | 5 |
5 files changed, 22 insertions, 9 deletions
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 { | |||
325 | WRAP_FORCE | 325 | WRAP_FORCE |
326 | }; | 326 | }; |
327 | 327 | ||
328 | enum mouse_warping_mode { | ||
329 | WARP_NO, | ||
330 | WARP_OUTPUT, | ||
331 | WARP_CONTAINER | ||
332 | }; | ||
333 | |||
328 | /** | 334 | /** |
329 | * The configuration struct. The result of loading a config file. | 335 | * The configuration struct. The result of loading a config file. |
330 | */ | 336 | */ |
@@ -366,7 +372,7 @@ struct sway_config { | |||
366 | // Flags | 372 | // Flags |
367 | bool focus_follows_mouse; | 373 | bool focus_follows_mouse; |
368 | bool raise_floating; | 374 | bool raise_floating; |
369 | bool mouse_warping; | 375 | enum mouse_warping_mode mouse_warping; |
370 | enum focus_wrapping_mode focus_wrapping; | 376 | enum focus_wrapping_mode focus_wrapping; |
371 | bool active; | 377 | bool active; |
372 | bool failed; | 378 | 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) { | |||
6 | struct cmd_results *error = NULL; | 6 | struct cmd_results *error = NULL; |
7 | if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { | 7 | if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { |
8 | return error; | 8 | return error; |
9 | } else if (strcasecmp(argv[0], "container") == 0) { | ||
10 | config->mouse_warping = WARP_CONTAINER; | ||
9 | } else if (strcasecmp(argv[0], "output") == 0) { | 11 | } else if (strcasecmp(argv[0], "output") == 0) { |
10 | config->mouse_warping = true; | 12 | config->mouse_warping = WARP_OUTPUT; |
11 | } else if (strcasecmp(argv[0], "none") == 0) { | 13 | } else if (strcasecmp(argv[0], "none") == 0) { |
12 | config->mouse_warping = false; | 14 | config->mouse_warping = WARP_NO; |
13 | } else { | 15 | } else { |
14 | return cmd_results_new(CMD_FAILURE, "mouse_warping", | 16 | return cmd_results_new(CMD_FAILURE, "mouse_warping", |
15 | "Expected 'mouse_warping output|none'"); | 17 | "Expected 'mouse_warping output|container|none'"); |
16 | } | 18 | } |
17 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 19 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
18 | } | 20 | } |
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) { | |||
223 | // Flags | 223 | // Flags |
224 | config->focus_follows_mouse = true; | 224 | config->focus_follows_mouse = true; |
225 | config->raise_floating = true; | 225 | config->raise_floating = true; |
226 | config->mouse_warping = true; | 226 | config->mouse_warping = WARP_OUTPUT; |
227 | config->focus_wrapping = WRAP_YES; | 227 | config->focus_wrapping = WRAP_YES; |
228 | config->validating = false; | 228 | config->validating = false; |
229 | config->reloading = false; | 229 | 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, | |||
772 | } | 772 | } |
773 | 773 | ||
774 | if (last_focus) { | 774 | if (last_focus) { |
775 | if (config->mouse_warping && warp && new_output != last_output) { | 775 | if (config->mouse_warping && warp && |
776 | (new_output != last_output || | ||
777 | config->mouse_warping == WARP_CONTAINER)) { | ||
776 | double x = 0; | 778 | double x = 0; |
777 | double y = 0; | 779 | double y = 0; |
778 | if (container) { | 780 | if (container) { |
@@ -782,9 +784,11 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, | |||
782 | x = new_workspace->x + new_workspace->width / 2.0; | 784 | x = new_workspace->x + new_workspace->width / 2.0; |
783 | y = new_workspace->y + new_workspace->height / 2.0; | 785 | y = new_workspace->y + new_workspace->height / 2.0; |
784 | } | 786 | } |
787 | |||
785 | if (!wlr_output_layout_contains_point(root->output_layout, | 788 | if (!wlr_output_layout_contains_point(root->output_layout, |
786 | new_output->wlr_output, seat->cursor->cursor->x, | 789 | new_output->wlr_output, seat->cursor->cursor->x, |
787 | seat->cursor->cursor->y)) { | 790 | seat->cursor->cursor->y) |
791 | || config->mouse_warping == WARP_CONTAINER) { | ||
788 | wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); | 792 | wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); |
789 | cursor_send_pointer_motion(seat->cursor, 0, true); | 793 | cursor_send_pointer_motion(seat->cursor, 0, true); |
790 | } | 794 | } |
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: | |||
492 | If _--pango\_markup_ is given, then _mode_ will be interpreted as pango | 492 | If _--pango\_markup_ is given, then _mode_ will be interpreted as pango |
493 | markup. | 493 | markup. |
494 | 494 | ||
495 | *mouse\_warping* output|none | 495 | *mouse\_warping* output|container|none |
496 | If _output_ is specified, the mouse will be moved to new outputs as you | 496 | If _output_ is specified, the mouse will be moved to new outputs as you |
497 | move focus between them. Default is _output_. | 497 | move focus between them. If _container_ is specified, the mouse will be |
498 | moved to the middle of the container on switch. Default is _output_. | ||
498 | 499 | ||
499 | *no\_focus* <criteria> | 500 | *no\_focus* <criteria> |
500 | Prevents windows matching <criteria> from being focused automatically when | 501 | Prevents windows matching <criteria> from being focused automatically when |