diff options
author | Danny Bautista <pyrolagus@nerdpol.ch> | 2018-04-10 15:40:27 -0400 |
---|---|---|
committer | Danny Bautista <pyrolagus@nerdpol.ch> | 2018-04-10 15:40:27 -0400 |
commit | c355d680e9a009e09e027a79b27ad21763fa67ea (patch) | |
tree | 1d5f24c369993e603f80b45d07d0451399bcae53 | |
parent | Implement cursor event simulation with sway commands. (diff) | |
download | sway-c355d680e9a009e09e027a79b27ad21763fa67ea.tar.gz sway-c355d680e9a009e09e027a79b27ad21763fa67ea.tar.zst sway-c355d680e9a009e09e027a79b27ad21763fa67ea.zip |
Clean up cursor simulation code.
-rw-r--r-- | include/sway/input/cursor.h | 3 | ||||
-rw-r--r-- | sway/commands/seat/cursor.c | 18 |
2 files changed, 14 insertions, 7 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 30169aa1..fcd94437 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h | |||
@@ -30,6 +30,7 @@ struct sway_cursor { | |||
30 | void sway_cursor_destroy(struct sway_cursor *cursor); | 30 | void sway_cursor_destroy(struct sway_cursor *cursor); |
31 | struct sway_cursor *sway_cursor_create(struct sway_seat *seat); | 31 | struct sway_cursor *sway_cursor_create(struct sway_seat *seat); |
32 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time); | 32 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time); |
33 | void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, uint32_t button, enum wlr_button_state state); | 33 | void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, |
34 | uint32_t button, enum wlr_button_state state); | ||
34 | 35 | ||
35 | #endif | 36 | #endif |
diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 2f2aa5ca..5dad97f1 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c | |||
@@ -10,7 +10,8 @@ | |||
10 | #include "sway/commands.h" | 10 | #include "sway/commands.h" |
11 | #include "sway/input/cursor.h" | 11 | #include "sway/input/cursor.h" |
12 | 12 | ||
13 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, char *action, char *button_str); | 13 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, |
14 | char *action, char *button_str, uint32_t time); | ||
14 | 15 | ||
15 | static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " | 16 | static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " |
16 | "'cursor <set> <x> <y>' or " | 17 | "'cursor <set> <x> <y>' or " |
@@ -28,6 +29,10 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
28 | 29 | ||
29 | struct sway_cursor *cursor = seat->cursor; | 30 | struct sway_cursor *cursor = seat->cursor; |
30 | 31 | ||
32 | struct timespec now; | ||
33 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
34 | uint32_t time = now.tv_nsec / 1000; | ||
35 | |||
31 | if (strcasecmp(argv[0], "move") == 0) { | 36 | if (strcasecmp(argv[0], "move") == 0) { |
32 | if (argc < 3) { | 37 | if (argc < 3) { |
33 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 38 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
@@ -35,7 +40,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
35 | int delta_x = strtol(argv[1], NULL, 10); | 40 | int delta_x = strtol(argv[1], NULL, 10); |
36 | int delta_y = strtol(argv[2], NULL, 10); | 41 | int delta_y = strtol(argv[2], NULL, 10); |
37 | wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); | 42 | wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); |
38 | cursor_send_pointer_motion(cursor, 1); | 43 | cursor_send_pointer_motion(cursor, time); |
39 | } else if (strcasecmp(argv[0], "set") == 0) { | 44 | } else if (strcasecmp(argv[0], "set") == 0) { |
40 | if (argc < 3) { | 45 | if (argc < 3) { |
41 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 46 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
@@ -44,12 +49,12 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
44 | float x = strtof(argv[1], NULL) / root_container.width; | 49 | float x = strtof(argv[1], NULL) / root_container.width; |
45 | float y = strtof(argv[2], NULL) / root_container.height; | 50 | float y = strtof(argv[2], NULL) / root_container.height; |
46 | wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); | 51 | wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); |
47 | cursor_send_pointer_motion(cursor, 0); | 52 | cursor_send_pointer_motion(cursor, time); |
48 | } else { | 53 | } else { |
49 | if (argc < 2) { | 54 | if (argc < 2) { |
50 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 55 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
51 | } | 56 | } |
52 | if ((error = press_or_release(cursor, argv[0], argv[1]))) { | 57 | if ((error = press_or_release(cursor, argv[0], argv[1], time))) { |
53 | return error; | 58 | return error; |
54 | } | 59 | } |
55 | } | 60 | } |
@@ -57,7 +62,8 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
57 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 62 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
58 | } | 63 | } |
59 | 64 | ||
60 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, char *action, char *button_str) { | 65 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, |
66 | char *action, char *button_str, uint32_t time) { | ||
61 | enum wlr_button_state state; | 67 | enum wlr_button_state state; |
62 | uint32_t button; | 68 | uint32_t button; |
63 | if (strcasecmp(action, "press") == 0) { | 69 | if (strcasecmp(action, "press") == 0) { |
@@ -78,6 +84,6 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, char *ac | |||
78 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 84 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
79 | } | 85 | } |
80 | } | 86 | } |
81 | dispatch_cursor_button(cursor, 1, button, state); | 87 | dispatch_cursor_button(cursor, time, button, state); |
82 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 88 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
83 | } | 89 | } |