summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h3
-rw-r--r--include/sway/input/cursor.h2
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/seat.c2
-rw-r--r--sway/commands/seat/cursor.c89
-rw-r--r--sway/input/cursor.c2
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway.5.txt7
8 files changed, 105 insertions, 2 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index bc5d5412..dbebaa49 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -204,8 +204,9 @@ sway_cmd input_cmd_xkb_options;
204sway_cmd input_cmd_xkb_rules; 204sway_cmd input_cmd_xkb_rules;
205sway_cmd input_cmd_xkb_variant; 205sway_cmd input_cmd_xkb_variant;
206 206
207sway_cmd seat_cmd_fallback;
208sway_cmd seat_cmd_attach; 207sway_cmd seat_cmd_attach;
208sway_cmd seat_cmd_fallback;
209sway_cmd seat_cmd_cursor;
209 210
210sway_cmd cmd_ipc_cmd; 211sway_cmd cmd_ipc_cmd;
211sway_cmd cmd_ipc_events; 212sway_cmd cmd_ipc_events;
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index daf7d4ee..fcd94437 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -30,5 +30,7 @@ struct sway_cursor {
30void sway_cursor_destroy(struct sway_cursor *cursor); 30void sway_cursor_destroy(struct sway_cursor *cursor);
31struct sway_cursor *sway_cursor_create(struct sway_seat *seat); 31struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
32void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time); 32void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time);
33void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec,
34 uint32_t button, enum wlr_button_state state);
33 35
34#endif 36#endif
diff --git a/sway/commands.c b/sway/commands.c
index 55929659..54d84450 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -203,6 +203,7 @@ static struct cmd_handler input_handlers[] = {
203// must be in order for the bsearch 203// must be in order for the bsearch
204static struct cmd_handler seat_handlers[] = { 204static struct cmd_handler seat_handlers[] = {
205 { "attach", seat_cmd_attach }, 205 { "attach", seat_cmd_attach },
206 { "cursor", seat_cmd_cursor },
206 { "fallback", seat_cmd_fallback }, 207 { "fallback", seat_cmd_fallback },
207}; 208};
208 209
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index 819b769c..5916015f 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -40,6 +40,8 @@ struct cmd_results *cmd_seat(int argc, char **argv) {
40 struct cmd_results *res; 40 struct cmd_results *res;
41 if (strcasecmp("attach", argv[1]) == 0) { 41 if (strcasecmp("attach", argv[1]) == 0) {
42 res = seat_cmd_attach(argc_new, argv_new); 42 res = seat_cmd_attach(argc_new, argv_new);
43 } else if (strcasecmp("cursor", argv[1]) == 0) {
44 res = seat_cmd_cursor(argc_new, argv_new);
43 } else if (strcasecmp("fallback", argv[1]) == 0) { 45 } else if (strcasecmp("fallback", argv[1]) == 0) {
44 res = seat_cmd_fallback(argc_new, argv_new); 46 res = seat_cmd_fallback(argc_new, argv_new);
45 } else { 47 } else {
diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c
new file mode 100644
index 00000000..5dad97f1
--- /dev/null
+++ b/sway/commands/seat/cursor.c
@@ -0,0 +1,89 @@
1#define _XOPEN_SOURCE 700
2#ifdef __linux__
3#include <linux/input-event-codes.h>
4#elif __FreeBSD__
5#include <dev/evdev/input-event-codes.h>
6#endif
7
8#include <strings.h>
9#include <wlr/types/wlr_cursor.h>
10#include "sway/commands.h"
11#include "sway/input/cursor.h"
12
13static struct cmd_results *press_or_release(struct sway_cursor *cursor,
14 char *action, char *button_str, uint32_t time);
15
16static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or "
17 "'cursor <set> <x> <y>' or "
18 "'curor <press|release> <left|right|1|2|3...>'";
19
20struct cmd_results *seat_cmd_cursor(int argc, char **argv) {
21 struct cmd_results *error = NULL;
22 if ((error = checkarg(argc, "cursor", EXPECTED_AT_LEAST, 2))) {
23 return error;
24 }
25 struct sway_seat *seat = config->handler_context.seat;
26 if (!seat) {
27 return cmd_results_new(CMD_FAILURE, "cursor", "No seat defined");
28 }
29
30 struct sway_cursor *cursor = seat->cursor;
31
32 struct timespec now;
33 clock_gettime(CLOCK_MONOTONIC, &now);
34 uint32_t time = now.tv_nsec / 1000;
35
36 if (strcasecmp(argv[0], "move") == 0) {
37 if (argc < 3) {
38 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
39 }
40 int delta_x = strtol(argv[1], NULL, 10);
41 int delta_y = strtol(argv[2], NULL, 10);
42 wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y);
43 cursor_send_pointer_motion(cursor, time);
44 } else if (strcasecmp(argv[0], "set") == 0) {
45 if (argc < 3) {
46 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
47 }
48 // map absolute coords (0..1,0..1) to root container coords
49 float x = strtof(argv[1], NULL) / root_container.width;
50 float y = strtof(argv[2], NULL) / root_container.height;
51 wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y);
52 cursor_send_pointer_motion(cursor, time);
53 } else {
54 if (argc < 2) {
55 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
56 }
57 if ((error = press_or_release(cursor, argv[0], argv[1], time))) {
58 return error;
59 }
60 }
61
62 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
63}
64
65static struct cmd_results *press_or_release(struct sway_cursor *cursor,
66 char *action, char *button_str, uint32_t time) {
67 enum wlr_button_state state;
68 uint32_t button;
69 if (strcasecmp(action, "press") == 0) {
70 state = WLR_BUTTON_PRESSED;
71 } else if (strcasecmp(action, "release") == 0) {
72 state = WLR_BUTTON_RELEASED;
73 } else {
74 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
75 }
76
77 if (strcasecmp(button_str, "left") == 0) {
78 button = BTN_LEFT;
79 } else if (strcasecmp(button_str, "right") == 0) {
80 button = BTN_RIGHT;
81 } else {
82 button = strtol(button_str, NULL, 10);
83 if (button == 0) {
84 return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
85 }
86 }
87 dispatch_cursor_button(cursor, time, button, state);
88 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
89}
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 0df01504..15a61cbf 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -166,7 +166,7 @@ static void handle_cursor_motion_absolute(
166 cursor_send_pointer_motion(cursor, event->time_msec); 166 cursor_send_pointer_motion(cursor, event->time_msec);
167} 167}
168 168
169static void dispatch_cursor_button(struct sway_cursor *cursor, 169void dispatch_cursor_button(struct sway_cursor *cursor,
170 uint32_t time_msec, uint32_t button, enum wlr_button_state state) { 170 uint32_t time_msec, uint32_t button, enum wlr_button_state state) {
171 struct wlr_surface *surface = NULL; 171 struct wlr_surface *surface = NULL;
172 double sx, sy; 172 double sx, sy;
diff --git a/sway/meson.build b/sway/meson.build
index d0730296..9e55e335 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -47,6 +47,7 @@ sway_sources = files(
47 'commands/resize.c', 47 'commands/resize.c',
48 'commands/seat.c', 48 'commands/seat.c',
49 'commands/seat/attach.c', 49 'commands/seat/attach.c',
50 'commands/seat/cursor.c',
50 'commands/seat/fallback.c', 51 'commands/seat/fallback.c',
51 'commands/set.c', 52 'commands/set.c',
52 'commands/split.c', 53 'commands/split.c',
diff --git a/sway/sway.5.txt b/sway/sway.5.txt
index 59c3295a..03975349 100644
--- a/sway/sway.5.txt
+++ b/sway/sway.5.txt
@@ -328,6 +328,13 @@ The default colors are:
328 the named seat, and _}_ on its own line will close the block. 328 the named seat, and _}_ on its own line will close the block.
329 See **sway-input**(5) for details. 329 See **sway-input**(5) for details.
330 330
331**seat** <seat_name> cursor <move|set> <x> <y>::
332 Move cursor relatively to current position or set to absolute screen position.
333 A value of 0 causes the axis to be ignored in both commands.
334
335**seat** <seat_name> cursor <press|release> <left|right|1|2|3...>::
336 Simulate press of mouse button specified by left, right, or numerical code.
337
331**kill**:: 338**kill**::
332 Kills (force-closes) the currently-focused container and all of its children. 339 Kills (force-closes) the currently-focused container and all of its children.
333 340