diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-06-09 10:50:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-09 10:50:34 -0700 |
commit | 867fb6aedbbe4cd1c7f4817848682609e8489880 (patch) | |
tree | 3b62f78586a18a17b577c82d48f7e02b0becfaa9 /sway/input/cursor.c | |
parent | Merge pull request #2047 from natesymer/master (diff) | |
parent | Render drag icons (diff) | |
download | sway-bbee3bfdcca62606b0b17a51efbf674b5de013d6.tar.gz sway-bbee3bfdcca62606b0b17a51efbf674b5de013d6.tar.zst sway-bbee3bfdcca62606b0b17a51efbf674b5de013d6.zip |
Merge pull request #2124 from emersion/drag-icons1.0-alpha.3
Render drag icons
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r-- | sway/input/cursor.c | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 4100479c..37a87756 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -144,21 +144,22 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | |||
144 | time_msec = get_current_time_msec(); | 144 | time_msec = get_current_time_msec(); |
145 | } | 145 | } |
146 | 146 | ||
147 | struct wlr_seat *seat = cursor->seat->wlr_seat; | 147 | struct sway_seat *seat = cursor->seat; |
148 | struct wlr_seat *wlr_seat = seat->wlr_seat; | ||
148 | struct wlr_surface *surface = NULL; | 149 | struct wlr_surface *surface = NULL; |
149 | double sx, sy; | 150 | double sx, sy; |
150 | 151 | ||
151 | // Find the container beneath the pointer's previous position | 152 | // Find the container beneath the pointer's previous position |
152 | struct sway_container *prev_c = container_at_coords(cursor->seat, | 153 | struct sway_container *prev_c = container_at_coords(seat, |
153 | cursor->previous.x, cursor->previous.y, &surface, &sx, &sy); | 154 | cursor->previous.x, cursor->previous.y, &surface, &sx, &sy); |
154 | // Update the stored previous position | 155 | // Update the stored previous position |
155 | cursor->previous.x = cursor->cursor->x; | 156 | cursor->previous.x = cursor->cursor->x; |
156 | cursor->previous.y = cursor->cursor->y; | 157 | cursor->previous.y = cursor->cursor->y; |
157 | 158 | ||
158 | struct sway_container *c = container_at_coords(cursor->seat, | 159 | struct sway_container *c = container_at_coords(seat, |
159 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); | 160 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); |
160 | if (c && config->focus_follows_mouse && allow_refocusing) { | 161 | if (c && config->focus_follows_mouse && allow_refocusing) { |
161 | struct sway_container *focus = seat_get_focus(cursor->seat); | 162 | struct sway_container *focus = seat_get_focus(seat); |
162 | if (focus && c->type == C_WORKSPACE) { | 163 | if (focus && c->type == C_WORKSPACE) { |
163 | // Only follow the mouse if it would move to a new output | 164 | // Only follow the mouse if it would move to a new output |
164 | // Otherwise we'll focus the workspace, which is probably wrong | 165 | // Otherwise we'll focus the workspace, which is probably wrong |
@@ -170,20 +171,20 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | |||
170 | output = container_parent(c, C_OUTPUT); | 171 | output = container_parent(c, C_OUTPUT); |
171 | } | 172 | } |
172 | if (output != focus) { | 173 | if (output != focus) { |
173 | seat_set_focus_warp(cursor->seat, c, false); | 174 | seat_set_focus_warp(seat, c, false); |
174 | } | 175 | } |
175 | } else if (c->type == C_VIEW) { | 176 | } else if (c->type == C_VIEW) { |
176 | // Focus c if both of the following are true: | 177 | // Focus c if both of the following are true: |
177 | // - cursor is over a new view, i.e. entered a new window; and | 178 | // - cursor is over a new view, i.e. entered a new window; and |
178 | // - the new view is visible, i.e. not hidden in a stack or tab. | 179 | // - the new view is visible, i.e. not hidden in a stack or tab. |
179 | if (c != prev_c && view_is_visible(c->sway_view)) { | 180 | if (c != prev_c && view_is_visible(c->sway_view)) { |
180 | seat_set_focus_warp(cursor->seat, c, false); | 181 | seat_set_focus_warp(seat, c, false); |
181 | } else { | 182 | } else { |
182 | struct sway_container *next_focus = | 183 | struct sway_container *next_focus = |
183 | seat_get_focus_inactive(cursor->seat, &root_container); | 184 | seat_get_focus_inactive(seat, &root_container); |
184 | if (next_focus && next_focus->type == C_VIEW && | 185 | if (next_focus && next_focus->type == C_VIEW && |
185 | view_is_visible(next_focus->sway_view)) { | 186 | view_is_visible(next_focus->sway_view)) { |
186 | seat_set_focus_warp(cursor->seat, next_focus, false); | 187 | seat_set_focus_warp(seat, next_focus, false); |
187 | } | 188 | } |
188 | } | 189 | } |
189 | } | 190 | } |
@@ -202,12 +203,18 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | |||
202 | 203 | ||
203 | // send pointer enter/leave | 204 | // send pointer enter/leave |
204 | if (surface != NULL) { | 205 | if (surface != NULL) { |
205 | if (seat_is_input_allowed(cursor->seat, surface)) { | 206 | if (seat_is_input_allowed(seat, surface)) { |
206 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); | 207 | wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy); |
207 | wlr_seat_pointer_notify_motion(seat, time_msec, sx, sy); | 208 | wlr_seat_pointer_notify_motion(wlr_seat, time_msec, sx, sy); |
208 | } | 209 | } |
209 | } else { | 210 | } else { |
210 | wlr_seat_pointer_clear_focus(seat); | 211 | wlr_seat_pointer_clear_focus(wlr_seat); |
212 | } | ||
213 | |||
214 | struct wlr_drag_icon *wlr_drag_icon; | ||
215 | wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) { | ||
216 | struct sway_drag_icon *drag_icon = wlr_drag_icon->data; | ||
217 | drag_icon_update_position(drag_icon); | ||
211 | } | 218 | } |
212 | } | 219 | } |
213 | 220 | ||
@@ -293,22 +300,27 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { | |||
293 | wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); | 300 | wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); |
294 | struct wlr_event_touch_down *event = data; | 301 | struct wlr_event_touch_down *event = data; |
295 | 302 | ||
296 | struct wlr_seat *seat = cursor->seat->wlr_seat; | 303 | struct sway_seat *seat = cursor->seat; |
304 | struct wlr_seat *wlr_seat = seat->wlr_seat; | ||
297 | struct wlr_surface *surface = NULL; | 305 | struct wlr_surface *surface = NULL; |
298 | 306 | ||
299 | double lx, ly; | 307 | double lx, ly; |
300 | wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, | 308 | wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, |
301 | event->x, event->y, &lx, &ly); | 309 | event->x, event->y, &lx, &ly); |
302 | double sx, sy; | 310 | double sx, sy; |
303 | container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); | 311 | container_at_coords(seat, lx, ly, &surface, &sx, &sy); |
312 | |||
313 | seat->touch_id = event->touch_id; | ||
314 | seat->touch_x = lx; | ||
315 | seat->touch_y = ly; | ||
304 | 316 | ||
305 | if (!surface) { | 317 | if (!surface) { |
306 | return; | 318 | return; |
307 | } | 319 | } |
308 | 320 | ||
309 | // TODO: fall back to cursor simulation if client has not bound to touch | 321 | // TODO: fall back to cursor simulation if client has not bound to touch |
310 | if (seat_is_input_allowed(cursor->seat, surface)) { | 322 | if (seat_is_input_allowed(seat, surface)) { |
311 | wlr_seat_touch_notify_down(seat, surface, event->time_msec, | 323 | wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec, |
312 | event->touch_id, sx, sy); | 324 | event->touch_id, sx, sy); |
313 | cursor->image_client = NULL; | 325 | cursor->image_client = NULL; |
314 | wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); | 326 | wlr_cursor_set_image(cursor->cursor, NULL, 0, 0, 0, 0, 0, 0); |
@@ -330,7 +342,8 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { | |||
330 | wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); | 342 | wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); |
331 | struct wlr_event_touch_motion *event = data; | 343 | struct wlr_event_touch_motion *event = data; |
332 | 344 | ||
333 | struct wlr_seat *seat = cursor->seat->wlr_seat; | 345 | struct sway_seat *seat = cursor->seat; |
346 | struct wlr_seat *wlr_seat = seat->wlr_seat; | ||
334 | struct wlr_surface *surface = NULL; | 347 | struct wlr_surface *surface = NULL; |
335 | 348 | ||
336 | double lx, ly; | 349 | double lx, ly; |
@@ -339,14 +352,25 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { | |||
339 | double sx, sy; | 352 | double sx, sy; |
340 | container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); | 353 | container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); |
341 | 354 | ||
355 | if (seat->touch_id == event->touch_id) { | ||
356 | seat->touch_x = lx; | ||
357 | seat->touch_y = ly; | ||
358 | |||
359 | struct wlr_drag_icon *wlr_drag_icon; | ||
360 | wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) { | ||
361 | struct sway_drag_icon *drag_icon = wlr_drag_icon->data; | ||
362 | drag_icon_update_position(drag_icon); | ||
363 | } | ||
364 | } | ||
365 | |||
342 | if (!surface) { | 366 | if (!surface) { |
343 | return; | 367 | return; |
344 | } | 368 | } |
345 | 369 | ||
346 | // TODO: fall back to cursor simulation if client has not bound to touch | 370 | // TODO: fall back to cursor simulation if client has not bound to touch |
347 | if (seat_is_input_allowed(cursor->seat, surface)) { | 371 | if (seat_is_input_allowed(cursor->seat, surface)) { |
348 | wlr_seat_touch_notify_motion( | 372 | wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, |
349 | seat, event->time_msec, event->touch_id, sx, sy); | 373 | event->touch_id, sx, sy); |
350 | } | 374 | } |
351 | } | 375 | } |
352 | 376 | ||