aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-31 10:49:52 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-31 13:05:45 -0400
commitae6d459000865f0a3a54a1d0429ee28b282a7954 (patch)
tree264caea4be15679d6da1ffa51c3056780827149d
parentCheck for null container (diff)
downloadsway-ae6d459000865f0a3a54a1d0429ee28b282a7954.tar.gz
sway-ae6d459000865f0a3a54a1d0429ee28b282a7954.tar.zst
sway-ae6d459000865f0a3a54a1d0429ee28b282a7954.zip
Implement mouse warping
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/mouse_warping.c19
-rw-r--r--sway/input/cursor.c4
-rw-r--r--sway/input/seat.c18
-rw-r--r--sway/meson.build1
5 files changed, 39 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c
index eee7f254..d983dcbb 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -101,6 +101,7 @@ static struct cmd_handler handlers[] = {
101 { "include", cmd_include }, 101 { "include", cmd_include },
102 { "input", cmd_input }, 102 { "input", cmd_input },
103 { "mode", cmd_mode }, 103 { "mode", cmd_mode },
104 { "mouse_warping", cmd_mouse_warping },
104 { "output", cmd_output }, 105 { "output", cmd_output },
105 { "seat", cmd_seat }, 106 { "seat", cmd_seat },
106 { "workspace", cmd_workspace }, 107 { "workspace", cmd_workspace },
diff --git a/sway/commands/mouse_warping.c b/sway/commands/mouse_warping.c
new file mode 100644
index 00000000..eef32ce7
--- /dev/null
+++ b/sway/commands/mouse_warping.c
@@ -0,0 +1,19 @@
1#include <string.h>
2#include <strings.h>
3#include "sway/commands.h"
4
5struct cmd_results *cmd_mouse_warping(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 } else if (strcasecmp(argv[0], "output") == 0) {
10 config->mouse_warping = true;
11 } else if (strcasecmp(argv[0], "none") == 0) {
12 config->mouse_warping = false;
13 } else {
14 return cmd_results_new(CMD_FAILURE, "mouse_warping",
15 "Expected 'mouse_warping output|none'");
16 }
17 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
18}
19
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 74af6426..9cdd66d8 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -156,8 +156,8 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) {
156 cursor_send_pointer_motion(cursor, event->time_msec); 156 cursor_send_pointer_motion(cursor, event->time_msec);
157} 157}
158 158
159static void handle_cursor_motion_absolute(struct wl_listener *listener, 159static void handle_cursor_motion_absolute(
160 void *data) { 160 struct wl_listener *listener, void *data) {
161 struct sway_cursor *cursor = 161 struct sway_cursor *cursor =
162 wl_container_of(listener, cursor, motion_absolute); 162 wl_container_of(listener, cursor, motion_absolute);
163 struct wlr_event_pointer_motion_absolute *event = data; 163 struct wlr_event_pointer_motion_absolute *event = data;
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 8d592872..eab5cf40 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -333,15 +333,29 @@ void sway_seat_set_focus(struct sway_seat *seat,
333 if (last_focus) { 333 if (last_focus) {
334 struct sway_container *last_ws = last_focus; 334 struct sway_container *last_ws = last_focus;
335 if (last_ws && last_ws->type != C_WORKSPACE) { 335 if (last_ws && last_ws->type != C_WORKSPACE) {
336 last_ws = container_parent(last_focus, C_WORKSPACE); 336 last_ws = container_parent(last_ws, C_WORKSPACE);
337 } 337 }
338 if (last_ws) { 338 if (last_ws) {
339 wlr_log(L_DEBUG, "sending workspace event");
340 ipc_event_workspace(last_ws, container, "focus"); 339 ipc_event_workspace(last_ws, container, "focus");
341 if (last_ws->children->length == 0) { 340 if (last_ws->children->length == 0) {
342 container_workspace_destroy(last_ws); 341 container_workspace_destroy(last_ws);
343 } 342 }
344 } 343 }
344 struct sway_container *last_output = last_focus;
345 if (last_output && last_output->type != C_OUTPUT) {
346 last_output = container_parent(last_output, C_OUTPUT);
347 }
348 struct sway_container *new_output = container;
349 if (new_output && new_output->type != C_OUTPUT) {
350 new_output = container_parent(new_output, C_OUTPUT);
351 }
352 if (new_output != last_output && config->mouse_warping) {
353 struct wlr_output *output = new_output->sway_output->wlr_output;
354 // TODO: Change container coords to layout coords
355 double x = container->x + output->lx + container->width / 2.0;
356 double y = container->y + output->ly + container->height / 2.0;
357 wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
358 }
345 } 359 }
346 360
347 if (last_focus && last_focus->type == C_VIEW && 361 if (last_focus && last_focus->type == C_VIEW &&
diff --git a/sway/meson.build b/sway/meson.build
index e8a192f0..5bc57964 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -63,6 +63,7 @@ sway_sources = files(
63 'commands/input/xkb_options.c', 63 'commands/input/xkb_options.c',
64 'commands/input/xkb_rules.c', 64 'commands/input/xkb_rules.c',
65 'commands/input/xkb_variant.c', 65 'commands/input/xkb_variant.c',
66 'commands/mouse_warping.c',
66 'commands/output.c', 67 'commands/output.c',
67 'commands/reload.c', 68 'commands/reload.c',
68 'commands/workspace.c', 69 'commands/workspace.c',