aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-04-21 14:07:22 +0100
committerLibravatar emersion <contact@emersion.fr>2018-04-21 14:07:22 +0100
commit4cf77e1de4b0be8b7d9374f04ff0e191ce22610a (patch)
tree21b52ebdf2de5dffa5177000626ae9ddd2a16f44
parentMerge pull request #1836 from emersion/workspace-focus-update-cursor (diff)
downloadsway-4cf77e1de4b0be8b7d9374f04ff0e191ce22610a.tar.gz
sway-4cf77e1de4b0be8b7d9374f04ff0e191ce22610a.tar.zst
sway-4cf77e1de4b0be8b7d9374f04ff0e191ce22610a.zip
Default to current time when triggering cursor events
-rw-r--r--include/sway/input/cursor.h2
-rw-r--r--sway/commands/seat/cursor.c16
-rw-r--r--sway/input/cursor.c18
-rw-r--r--sway/input/seat.c8
4 files changed, 25 insertions, 19 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index fcd94437..20c1c903 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -29,7 +29,7 @@ struct sway_cursor {
29 29
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_msec);
33void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, 33void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec,
34 uint32_t button, enum wlr_button_state state); 34 uint32_t button, enum wlr_button_state state);
35 35
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
13static struct cmd_results *press_or_release(struct sway_cursor *cursor, 13static 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
16static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " 16static 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
65static struct cmd_results *press_or_release(struct sway_cursor *cursor, 61static 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
18static uint32_t get_current_time_msec() {
19 struct timespec now;
20 clock_gettime(CLOCK_MONOTONIC, &now);
21 return now.tv_nsec / 1000;
22}
23
18static struct wlr_surface *layer_surface_at(struct sway_output *output, 24static 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
131void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time) { 137void 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
179void dispatch_cursor_button(struct sway_cursor *cursor, 189void 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);