diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-21 15:21:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-21 15:21:52 +0200 |
commit | 4386dcb6247640de382e31dada9369b0861594dc (patch) | |
tree | d89bcb928037955d3bafa8dce7c9469fed4220a0 /sway | |
parent | Merge pull request #1834 from emersion/xwayland-no-unmap-on-destroy (diff) | |
parent | Default to current time when triggering cursor events (diff) | |
download | sway-4386dcb6247640de382e31dada9369b0861594dc.tar.gz sway-4386dcb6247640de382e31dada9369b0861594dc.tar.zst sway-4386dcb6247640de382e31dada9369b0861594dc.zip |
Merge pull request #1837 from emersion/cursor-default-to-current-time
Default to current time when triggering cursor events
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/seat/cursor.c | 16 | ||||
-rw-r--r-- | sway/input/cursor.c | 18 | ||||
-rw-r--r-- | sway/input/seat.c | 8 |
3 files changed, 24 insertions, 18 deletions
diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 5dad97f1..929384b0 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c | |||
@@ -11,7 +11,7 @@ | |||
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, | 13 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, |
14 | char *action, char *button_str, uint32_t time); | 14 | char *action, char *button_str); |
15 | 15 | ||
16 | static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " | 16 | static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " |
17 | "'cursor <set> <x> <y>' or " | 17 | "'cursor <set> <x> <y>' or " |
@@ -29,10 +29,6 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
29 | 29 | ||
30 | struct sway_cursor *cursor = seat->cursor; | 30 | struct sway_cursor *cursor = seat->cursor; |
31 | 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) { | 32 | if (strcasecmp(argv[0], "move") == 0) { |
37 | if (argc < 3) { | 33 | if (argc < 3) { |
38 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 34 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
@@ -40,7 +36,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
40 | int delta_x = strtol(argv[1], NULL, 10); | 36 | int delta_x = strtol(argv[1], NULL, 10); |
41 | int delta_y = strtol(argv[2], NULL, 10); | 37 | int delta_y = strtol(argv[2], NULL, 10); |
42 | wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); | 38 | wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); |
43 | cursor_send_pointer_motion(cursor, time); | 39 | cursor_send_pointer_motion(cursor, 0); |
44 | } else if (strcasecmp(argv[0], "set") == 0) { | 40 | } else if (strcasecmp(argv[0], "set") == 0) { |
45 | if (argc < 3) { | 41 | if (argc < 3) { |
46 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 42 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
@@ -49,12 +45,12 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
49 | float x = strtof(argv[1], NULL) / root_container.width; | 45 | float x = strtof(argv[1], NULL) / root_container.width; |
50 | float y = strtof(argv[2], NULL) / root_container.height; | 46 | float y = strtof(argv[2], NULL) / root_container.height; |
51 | wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); | 47 | wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); |
52 | cursor_send_pointer_motion(cursor, time); | 48 | cursor_send_pointer_motion(cursor, 0); |
53 | } else { | 49 | } else { |
54 | if (argc < 2) { | 50 | if (argc < 2) { |
55 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 51 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
56 | } | 52 | } |
57 | if ((error = press_or_release(cursor, argv[0], argv[1], time))) { | 53 | if ((error = press_or_release(cursor, argv[0], argv[1]))) { |
58 | return error; | 54 | return error; |
59 | } | 55 | } |
60 | } | 56 | } |
@@ -63,7 +59,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
63 | } | 59 | } |
64 | 60 | ||
65 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, | 61 | static struct cmd_results *press_or_release(struct sway_cursor *cursor, |
66 | char *action, char *button_str, uint32_t time) { | 62 | char *action, char *button_str) { |
67 | enum wlr_button_state state; | 63 | enum wlr_button_state state; |
68 | uint32_t button; | 64 | uint32_t button; |
69 | if (strcasecmp(action, "press") == 0) { | 65 | if (strcasecmp(action, "press") == 0) { |
@@ -84,6 +80,6 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, | |||
84 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 80 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
85 | } | 81 | } |
86 | } | 82 | } |
87 | dispatch_cursor_button(cursor, time, button, state); | 83 | dispatch_cursor_button(cursor, 0, button, state); |
88 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 84 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
89 | } | 85 | } |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 5ed4f1f7..831109dc 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -15,6 +15,12 @@ | |||
15 | #include "sway/tree/workspace.h" | 15 | #include "sway/tree/workspace.h" |
16 | #include "wlr-layer-shell-unstable-v1-protocol.h" | 16 | #include "wlr-layer-shell-unstable-v1-protocol.h" |
17 | 17 | ||
18 | static uint32_t get_current_time_msec() { | ||
19 | struct timespec now; | ||
20 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
21 | return now.tv_nsec / 1000; | ||
22 | } | ||
23 | |||
18 | static struct wlr_surface *layer_surface_at(struct sway_output *output, | 24 | static struct wlr_surface *layer_surface_at(struct sway_output *output, |
19 | struct wl_list *layer, double ox, double oy, double *sx, double *sy) { | 25 | struct wl_list *layer, double ox, double oy, double *sx, double *sy) { |
20 | struct sway_layer_surface *sway_layer; | 26 | struct sway_layer_surface *sway_layer; |
@@ -128,7 +134,11 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor, | |||
128 | return output->swayc; | 134 | return output->swayc; |
129 | } | 135 | } |
130 | 136 | ||
131 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time) { | 137 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec) { |
138 | if (time_msec == 0) { | ||
139 | time_msec = get_current_time_msec(); | ||
140 | } | ||
141 | |||
132 | struct wlr_seat *seat = cursor->seat->wlr_seat; | 142 | struct wlr_seat *seat = cursor->seat->wlr_seat; |
133 | struct wlr_surface *surface = NULL; | 143 | struct wlr_surface *surface = NULL; |
134 | double sx, sy; | 144 | double sx, sy; |
@@ -152,7 +162,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time) { | |||
152 | if (surface != NULL) { | 162 | if (surface != NULL) { |
153 | if (seat_is_input_allowed(cursor->seat, surface)) { | 163 | if (seat_is_input_allowed(cursor->seat, surface)) { |
154 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); | 164 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); |
155 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); | 165 | wlr_seat_pointer_notify_motion(seat, time_msec, sx, sy); |
156 | } | 166 | } |
157 | } else { | 167 | } else { |
158 | wlr_seat_pointer_clear_focus(seat); | 168 | wlr_seat_pointer_clear_focus(seat); |
@@ -178,6 +188,10 @@ static void handle_cursor_motion_absolute( | |||
178 | 188 | ||
179 | void dispatch_cursor_button(struct sway_cursor *cursor, | 189 | void dispatch_cursor_button(struct sway_cursor *cursor, |
180 | uint32_t time_msec, uint32_t button, enum wlr_button_state state) { | 190 | uint32_t time_msec, uint32_t button, enum wlr_button_state state) { |
191 | if (time_msec == 0) { | ||
192 | time_msec = get_current_time_msec(); | ||
193 | } | ||
194 | |||
181 | struct wlr_surface *surface = NULL; | 195 | struct wlr_surface *surface = NULL; |
182 | double sx, sy; | 196 | double sx, sy; |
183 | struct sway_container *cont = | 197 | struct sway_container *cont = |
diff --git a/sway/input/seat.c b/sway/input/seat.c index 631a273f..d1fc62c4 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -550,9 +550,7 @@ void seat_set_focus_warp(struct sway_seat *seat, | |||
550 | wlr_output, seat->cursor->cursor->x, | 550 | wlr_output, seat->cursor->cursor->x, |
551 | seat->cursor->cursor->y)) { | 551 | seat->cursor->cursor->y)) { |
552 | wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); | 552 | wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); |
553 | struct timespec now; | 553 | cursor_send_pointer_motion(seat->cursor, 0); |
554 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
555 | cursor_send_pointer_motion(seat->cursor, now.tv_nsec / 1000); | ||
556 | } | 554 | } |
557 | } | 555 | } |
558 | } | 556 | } |
@@ -565,9 +563,7 @@ void seat_set_focus_warp(struct sway_seat *seat, | |||
565 | } | 563 | } |
566 | 564 | ||
567 | if (last_workspace && last_workspace != new_workspace) { | 565 | if (last_workspace && last_workspace != new_workspace) { |
568 | struct timespec now; | 566 | cursor_send_pointer_motion(seat->cursor, 0); |
569 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
570 | cursor_send_pointer_motion(seat->cursor, now.tv_nsec / 1000); | ||
571 | } | 567 | } |
572 | 568 | ||
573 | seat->has_focus = (container != NULL); | 569 | seat->has_focus = (container != NULL); |