aboutsummaryrefslogtreecommitdiff
path: root/sway/input
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-10-17 15:57:13 +0200
committerGitHub <noreply@github.com>2018-10-17 15:57:13 +0200
commit765c80e5f7c36df77e9475a662648a0d87b93606 (patch)
tree21f28277ff5109d9f8ec196a12fc74bbb5dfd994 /sway/input
parent8d56269d9c9f2a5914aeb8f37f5877eb05000906 (diff)
parent1f0aeae33591fb46b3f8a91ca91975daf2a8bbf9 (diff)
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 @@
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_idle.h>
+#include <wlr/types/wlr_box.h>
#include "list.h"
#include "log.h"
#include "config.h"
@@ -1271,4 +1272,44 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
cursor->cursor = wlr_cursor;
return cursor;
+
+}
+
+/**
+ * Warps the cursor to the middle of the container argument.
+ * Does nothing if the cursor is already inside the container.
+ * If container is NULL, returns without doing anything.
+ */
+void cursor_warp_to_container(struct sway_cursor *cursor,
+ struct sway_container *container) {
+ if (!container) {
+ return;
+ }
+
+ struct wlr_box box;
+ container_get_box(container, &box);
+ if (wlr_box_contains_point(&box, cursor->cursor->x, cursor->cursor->y)) {
+ return;
+ }
+
+ double x = container->x + container->width / 2.0;
+ double y = container->y + container->height / 2.0;
+
+ wlr_cursor_warp(cursor->cursor, NULL, x, y);
+}
+
+/**
+ * Warps the cursor to the middle of the workspace argument.
+ * If workspace is NULL, returns without doing anything.
+ */
+void cursor_warp_to_workspace(struct sway_cursor *cursor,
+ struct sway_workspace *workspace) {
+ if (!workspace) {
+ return;
+ }
+
+ double x = workspace->x + workspace->width / 2.0;
+ double y = workspace->y + workspace->height / 2.0;
+
+ wlr_cursor_warp(cursor->cursor, NULL, x, y);
}
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,
workspace_consider_destroy(last_workspace);
}
- if (last_focus) {
- if (config->mouse_warping && warp &&
- (new_output != last_output ||
- config->mouse_warping == WARP_CONTAINER)) {
- double x = 0;
- double y = 0;
+ if (last_focus && warp) {
+ if (container && config->mouse_warping == WARP_CONTAINER) {
+ cursor_warp_to_container(seat->cursor, container);
+ cursor_send_pointer_motion(seat->cursor, 0, true);
+ } else if (new_output != last_output &&
+ config->mouse_warping >= WARP_OUTPUT) {
if (container) {
- x = container->x + container->width / 2.0;
- y = container->y + container->height / 2.0;
+ cursor_warp_to_container(seat->cursor, container);
} else {
- 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)
- || config->mouse_warping == WARP_CONTAINER) {
- wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
- cursor_send_pointer_motion(seat->cursor, 0, true);
+ cursor_warp_to_workspace(seat->cursor, new_workspace);
}
+ cursor_send_pointer_motion(seat->cursor, 0, true);
}
}