diff options
author | emersion <contact@emersion.fr> | 2018-06-09 13:26:03 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-06-09 13:26:03 +0100 |
commit | cfd02918c0d5dc539bc8858c7d0fab378145b38c (patch) | |
tree | 97e8b185ec52b576c7411fe74bacb9f727583ecd /sway/input | |
parent | 21d98d5bfb19491f8fd486a2eddc8efe9fb3de6c (diff) |
Render drag icons
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 62 | ||||
-rw-r--r-- | sway/input/seat.c | 98 |
2 files changed, 137 insertions, 23 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, time_msec = get_current_time_msec(); } - struct wlr_seat *seat = cursor->seat->wlr_seat; + struct sway_seat *seat = cursor->seat; + struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; double sx, sy; // Find the container beneath the pointer's previous position - struct sway_container *prev_c = container_at_coords(cursor->seat, + struct sway_container *prev_c = container_at_coords(seat, cursor->previous.x, cursor->previous.y, &surface, &sx, &sy); // Update the stored previous position cursor->previous.x = cursor->cursor->x; cursor->previous.y = cursor->cursor->y; - struct sway_container *c = container_at_coords(cursor->seat, + struct sway_container *c = container_at_coords(seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); if (c && config->focus_follows_mouse && allow_refocusing) { - struct sway_container *focus = seat_get_focus(cursor->seat); + struct sway_container *focus = seat_get_focus(seat); if (focus && c->type == C_WORKSPACE) { // Only follow the mouse if it would move to a new output // 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, output = container_parent(c, C_OUTPUT); } if (output != focus) { - seat_set_focus_warp(cursor->seat, c, false); + seat_set_focus_warp(seat, c, false); } } else if (c->type == C_VIEW) { // Focus c if both of the following are true: // - cursor is over a new view, i.e. entered a new window; and // - the new view is visible, i.e. not hidden in a stack or tab. if (c != prev_c && view_is_visible(c->sway_view)) { - seat_set_focus_warp(cursor->seat, c, false); + seat_set_focus_warp(seat, c, false); } else { struct sway_container *next_focus = - seat_get_focus_inactive(cursor->seat, &root_container); + seat_get_focus_inactive(seat, &root_container); if (next_focus && next_focus->type == C_VIEW && view_is_visible(next_focus->sway_view)) { - seat_set_focus_warp(cursor->seat, next_focus, false); + seat_set_focus_warp(seat, next_focus, false); } } } @@ -202,12 +203,18 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, // send pointer enter/leave if (surface != NULL) { - if (seat_is_input_allowed(cursor->seat, surface)) { - wlr_seat_pointer_notify_enter(seat, surface, sx, sy); - wlr_seat_pointer_notify_motion(seat, time_msec, sx, sy); + if (seat_is_input_allowed(seat, surface)) { + wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy); + wlr_seat_pointer_notify_motion(wlr_seat, time_msec, sx, sy); } } else { - wlr_seat_pointer_clear_focus(seat); + wlr_seat_pointer_clear_focus(wlr_seat); + } + + struct wlr_drag_icon *wlr_drag_icon; + wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) { + struct sway_drag_icon *drag_icon = wlr_drag_icon->data; + drag_icon_update_position(drag_icon); } } @@ -293,22 +300,27 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); struct wlr_event_touch_down *event = data; - struct wlr_seat *seat = cursor->seat->wlr_seat; + struct sway_seat *seat = cursor->seat; + struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; double lx, ly; wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, event->x, event->y, &lx, &ly); double sx, sy; - container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); + container_at_coords(seat, lx, ly, &surface, &sx, &sy); + + seat->touch_id = event->touch_id; + seat->touch_x = lx; + seat->touch_y = ly; if (!surface) { return; } // TODO: fall back to cursor simulation if client has not bound to touch - if (seat_is_input_allowed(cursor->seat, surface)) { - wlr_seat_touch_notify_down(seat, surface, event->time_msec, + if (seat_is_input_allowed(seat, surface)) { + wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec, event->touch_id, sx, sy); cursor->image_client = NULL; 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) { wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); struct wlr_event_touch_motion *event = data; - struct wlr_seat *seat = cursor->seat->wlr_seat; + struct sway_seat *seat = cursor->seat; + struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; double lx, ly; @@ -339,14 +352,25 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { double sx, sy; container_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); + if (seat->touch_id == event->touch_id) { + seat->touch_x = lx; + seat->touch_y = ly; + + struct wlr_drag_icon *wlr_drag_icon; + wl_list_for_each(wlr_drag_icon, &wlr_seat->drag_icons, link) { + struct sway_drag_icon *drag_icon = wlr_drag_icon->data; + drag_icon_update_position(drag_icon); + } + } + if (!surface) { return; } // TODO: fall back to cursor simulation if client has not bound to touch if (seat_is_input_allowed(cursor->seat, surface)) { - wlr_seat_touch_notify_motion( - seat, event->time_msec, event->touch_id, sx, sy); + wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, + event->touch_id, sx, sy); } } diff --git a/sway/input/seat.c b/sway/input/seat.c index 071ef020..1ea36466 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -6,21 +6,22 @@ #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_xcursor_manager.h> +#include "log.h" #include "sway/debug.h" -#include "sway/tree/container.h" -#include "sway/tree/workspace.h" -#include "sway/input/seat.h" +#include "sway/desktop.h" #include "sway/input/cursor.h" #include "sway/input/input-manager.h" #include "sway/input/keyboard.h" +#include "sway/input/seat.h" #include "sway/ipc-server.h" #include "sway/layers.h" #include "sway/output.h" #include "sway/tree/arrange.h" #include "sway/tree/container.h" +#include "sway/tree/container.h" #include "sway/tree/view.h" #include "sway/tree/workspace.h" -#include "log.h" +#include "sway/tree/workspace.h" static void seat_device_destroy(struct sway_seat_device *seat_device) { if (!seat_device) { @@ -40,6 +41,8 @@ void seat_destroy(struct sway_seat *seat) { seat_device_destroy(seat_device); } sway_cursor_destroy(seat->cursor); + wl_list_remove(&seat->new_container.link); + wl_list_remove(&seat->new_drag_icon.link); wl_list_remove(&seat->link); wlr_seat_destroy(seat->wlr_seat); } @@ -234,6 +237,90 @@ static void handle_new_container(struct wl_listener *listener, void *data) { seat_container_from_container(seat, con); } +static void drag_icon_damage_whole(struct sway_drag_icon *icon) { + if (!icon->wlr_drag_icon->mapped) { + return; + } + desktop_damage_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, true); +} + +void drag_icon_update_position(struct sway_drag_icon *icon) { + drag_icon_damage_whole(icon); + + struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon; + struct sway_seat *seat = icon->seat; + struct wlr_cursor *cursor = seat->cursor->cursor; + if (wlr_icon->is_pointer) { + icon->x = cursor->x + wlr_icon->sx; + icon->y = cursor->y + wlr_icon->sy; + } else { + struct wlr_touch_point *point = + wlr_seat_touch_get_point(seat->wlr_seat, wlr_icon->touch_id); + if (point == NULL) { + return; + } + icon->x = seat->touch_x + wlr_icon->sx; + icon->y = seat->touch_y + wlr_icon->sy; + } + + drag_icon_damage_whole(icon); +} + +static void drag_icon_handle_surface_commit(struct wl_listener *listener, + void *data) { + struct sway_drag_icon *icon = + wl_container_of(listener, icon, surface_commit); + drag_icon_update_position(icon); +} + +static void drag_icon_handle_map(struct wl_listener *listener, void *data) { + struct sway_drag_icon *icon = wl_container_of(listener, icon, map); + drag_icon_damage_whole(icon); +} + +static void drag_icon_handle_unmap(struct wl_listener *listener, void *data) { + struct sway_drag_icon *icon = wl_container_of(listener, icon, unmap); + drag_icon_damage_whole(icon); +} + +static void drag_icon_handle_destroy(struct wl_listener *listener, + void *data) { + struct sway_drag_icon *icon = wl_container_of(listener, icon, destroy); + icon->wlr_drag_icon->data = NULL; + wl_list_remove(&icon->link); + wl_list_remove(&icon->surface_commit.link); + wl_list_remove(&icon->unmap.link); + wl_list_remove(&icon->destroy.link); + free(icon); +} + +static void handle_new_drag_icon(struct wl_listener *listener, void *data) { + struct sway_seat *seat = wl_container_of(listener, seat, new_drag_icon); + struct wlr_drag_icon *wlr_drag_icon = data; + + struct sway_drag_icon *icon = calloc(1, sizeof(struct sway_drag_icon)); + if (icon == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + return; + } + icon->seat = seat; + icon->wlr_drag_icon = wlr_drag_icon; + wlr_drag_icon->data = icon; + + icon->surface_commit.notify = drag_icon_handle_surface_commit; + wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit); + icon->unmap.notify = drag_icon_handle_unmap; + wl_signal_add(&wlr_drag_icon->events.unmap, &icon->unmap); + icon->map.notify = drag_icon_handle_map; + wl_signal_add(&wlr_drag_icon->events.map, &icon->map); + icon->destroy.notify = drag_icon_handle_destroy; + wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy); + + wl_list_insert(&root_container.sway_root->drag_icons, &icon->link); + + drag_icon_update_position(icon); +} + static void collect_focus_iter(struct sway_container *con, void *data) { struct sway_seat *seat = data; if (con->type > C_WORKSPACE) { @@ -278,6 +365,9 @@ struct sway_seat *seat_create(struct sway_input_manager *input, &seat->new_container); seat->new_container.notify = handle_new_container; + wl_signal_add(&seat->wlr_seat->events.new_drag_icon, &seat->new_drag_icon); + seat->new_drag_icon.notify = handle_new_drag_icon; + seat->input = input; wl_list_init(&seat->devices); |