diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-30 19:08:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-30 19:08:39 -0400 |
commit | 70d9dc0b9ee9639011604a35b38b8ea03983e952 (patch) | |
tree | e2596e9cfa113efa43f2a411176c31e6208a58b1 | |
parent | Merge pull request #1665 from emersion/damage-tracking-lite (diff) | |
parent | Merge branch 'wlroots' into client-cursors (diff) | |
download | sway-70d9dc0b9ee9639011604a35b38b8ea03983e952.tar.gz sway-70d9dc0b9ee9639011604a35b38b8ea03983e952.tar.zst sway-70d9dc0b9ee9639011604a35b38b8ea03983e952.zip |
Merge pull request #1660 from emersion/client-cursors
Handle set_cursor requests from clients
-rw-r--r-- | include/sway/input/cursor.h | 1 | ||||
-rw-r--r-- | sway/input/cursor.c | 31 |
2 files changed, 31 insertions, 1 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index a16b793b..64917ce5 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h | |||
@@ -9,6 +9,7 @@ struct sway_cursor { | |||
9 | struct wlr_xcursor_manager *xcursor_manager; | 9 | struct wlr_xcursor_manager *xcursor_manager; |
10 | 10 | ||
11 | double x, y; | 11 | double x, y; |
12 | struct wl_client *image_client; | ||
12 | 13 | ||
13 | struct wl_listener motion; | 14 | struct wl_listener motion; |
14 | struct wl_listener motion_absolute; | 15 | struct wl_listener motion_absolute; |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 717d864b..d814e08e 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -81,6 +81,18 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, | |||
81 | struct sway_container *cont = | 81 | struct sway_container *cont = |
82 | container_at_cursor(cursor, &surface, &sx, &sy); | 82 | container_at_cursor(cursor, &surface, &sx, &sy); |
83 | 83 | ||
84 | // reset cursor if switching between clients | ||
85 | struct wl_client *client = NULL; | ||
86 | if (surface != NULL) { | ||
87 | client = wl_resource_get_client(surface->resource); | ||
88 | } | ||
89 | if (client != cursor->image_client) { | ||
90 | wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, | ||
91 | "left_ptr", cursor->cursor); | ||
92 | cursor->image_client = client; | ||
93 | } | ||
94 | |||
95 | // send pointer enter/leave | ||
84 | if (cont != NULL && surface != NULL) { | 96 | if (cont != NULL && surface != NULL) { |
85 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); | 97 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); |
86 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); | 98 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); |
@@ -167,7 +179,24 @@ static void handle_request_set_cursor(struct wl_listener *listener, | |||
167 | struct sway_cursor *cursor = | 179 | struct sway_cursor *cursor = |
168 | wl_container_of(listener, cursor, request_set_cursor); | 180 | wl_container_of(listener, cursor, request_set_cursor); |
169 | struct wlr_seat_pointer_request_set_cursor_event *event = data; | 181 | struct wlr_seat_pointer_request_set_cursor_event *event = data; |
170 | wlr_log(L_DEBUG, "TODO: handle request set cursor event: %p", event); | 182 | |
183 | struct wl_client *focused_client = NULL; | ||
184 | struct wlr_surface *focused_surface = | ||
185 | cursor->seat->wlr_seat->pointer_state.focused_surface; | ||
186 | if (focused_surface != NULL) { | ||
187 | focused_client = wl_resource_get_client(focused_surface->resource); | ||
188 | } | ||
189 | |||
190 | // TODO: check cursor mode | ||
191 | if (focused_client == NULL || | ||
192 | event->seat_client->client != focused_client) { | ||
193 | wlr_log(L_DEBUG, "denying request to set cursor from unfocused client"); | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | wlr_cursor_set_surface(cursor->cursor, event->surface, event->hotspot_x, | ||
198 | event->hotspot_y); | ||
199 | cursor->image_client = focused_client; | ||
171 | } | 200 | } |
172 | 201 | ||
173 | void sway_cursor_destroy(struct sway_cursor *cursor) { | 202 | void sway_cursor_destroy(struct sway_cursor *cursor) { |