aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-10-17 15:57:13 +0200
committerLibravatar GitHub <noreply@github.com>2018-10-17 15:57:13 +0200
commit765c80e5f7c36df77e9475a662648a0d87b93606 (patch)
tree21f28277ff5109d9f8ec196a12fc74bbb5dfd994 /sway/input
parentMerge pull request #2862 from SpeedJack/fix-stringop-overflow (diff)
parentview: rewarp cursor during view_unmap (diff)
downloadsway-765c80e5f7c36df77e9475a662648a0d87b93606.tar.gz
sway-765c80e5f7c36df77e9475a662648a0d87b93606.tar.zst
sway-765c80e5f7c36df77e9475a662648a0d87b93606.zip
Merge pull request #2820 from Emantor/fix-mouse-warping-container
Fix mouse warping container
Diffstat (limited to 'sway/input')
-rw-r--r--sway/input/cursor.c41
-rw-r--r--sway/input/seat.c27
2 files changed, 50 insertions, 18 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index bbe6b890..925190d6 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -9,6 +9,7 @@
9#include <wlr/types/wlr_cursor.h> 9#include <wlr/types/wlr_cursor.h>
10#include <wlr/types/wlr_xcursor_manager.h> 10#include <wlr/types/wlr_xcursor_manager.h>
11#include <wlr/types/wlr_idle.h> 11#include <wlr/types/wlr_idle.h>
12#include <wlr/types/wlr_box.h>
12#include "list.h" 13#include "list.h"
13#include "log.h" 14#include "log.h"
14#include "config.h" 15#include "config.h"
@@ -1271,4 +1272,44 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
1271 cursor->cursor = wlr_cursor; 1272 cursor->cursor = wlr_cursor;
1272 1273
1273 return cursor; 1274 return cursor;
1275
1276}
1277
1278/**
1279 * Warps the cursor to the middle of the container argument.
1280 * Does nothing if the cursor is already inside the container.
1281 * If container is NULL, returns without doing anything.
1282 */
1283void cursor_warp_to_container(struct sway_cursor *cursor,
1284 struct sway_container *container) {
1285 if (!container) {
1286 return;
1287 }
1288
1289 struct wlr_box box;
1290 container_get_box(container, &box);
1291 if (wlr_box_contains_point(&box, cursor->cursor->x, cursor->cursor->y)) {
1292 return;
1293 }
1294
1295 double x = container->x + container->width / 2.0;
1296 double y = container->y + container->height / 2.0;
1297
1298 wlr_cursor_warp(cursor->cursor, NULL, x, y);
1299}
1300
1301/**
1302 * Warps the cursor to the middle of the workspace argument.
1303 * If workspace is NULL, returns without doing anything.
1304 */
1305void cursor_warp_to_workspace(struct sway_cursor *cursor,
1306 struct sway_workspace *workspace) {
1307 if (!workspace) {
1308 return;
1309 }
1310
1311 double x = workspace->x + workspace->width / 2.0;
1312 double y = workspace->y + workspace->height / 2.0;
1313
1314 wlr_cursor_warp(cursor->cursor, NULL, x, y);
1274} 1315}
diff --git a/sway/input/seat.c b/sway/input/seat.c
index c7deabed..d8d2f3a4 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -774,27 +774,18 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node,
774 workspace_consider_destroy(last_workspace); 774 workspace_consider_destroy(last_workspace);
775 } 775 }
776 776
777 if (last_focus) { 777 if (last_focus && warp) {
778 if (config->mouse_warping && warp && 778 if (container && config->mouse_warping == WARP_CONTAINER) {
779 (new_output != last_output || 779 cursor_warp_to_container(seat->cursor, container);
780 config->mouse_warping == WARP_CONTAINER)) { 780 cursor_send_pointer_motion(seat->cursor, 0, true);
781 double x = 0; 781 } else if (new_output != last_output &&
782 double y = 0; 782 config->mouse_warping >= WARP_OUTPUT) {
783 if (container) { 783 if (container) {
784 x = container->x + container->width / 2.0; 784 cursor_warp_to_container(seat->cursor, container);
785 y = container->y + container->height / 2.0;
786 } else { 785 } else {
787 x = new_workspace->x + new_workspace->width / 2.0; 786 cursor_warp_to_workspace(seat->cursor, new_workspace);
788 y = new_workspace->y + new_workspace->height / 2.0;
789 }
790
791 if (!wlr_output_layout_contains_point(root->output_layout,
792 new_output->wlr_output, seat->cursor->cursor->x,
793 seat->cursor->cursor->y)
794 || config->mouse_warping == WARP_CONTAINER) {
795 wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
796 cursor_send_pointer_motion(seat->cursor, 0, true);
797 } 787 }
788 cursor_send_pointer_motion(seat->cursor, 0, true);
798 } 789 }
799 } 790 }
800 791