diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-10-24 08:22:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 08:22:13 -0400 |
commit | bbf08f3ef9cf831c6af49060871995eaa0963bca (patch) | |
tree | 005f9540a0d68f827eb0024a1fb4bf53f48a4f20 /rootston | |
parent | 93042e844be026e05a3120385af530c406bb695e (diff) | |
parent | 1dbe31493708790f6fafb4c9da8d24cbb3fa07b9 (diff) |
Merge pull request #262 from acrisci/feature/data-device-selection
wlr-data-device
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/cursor.c | 59 | ||||
-rw-r--r-- | rootston/input.c | 2 | ||||
-rw-r--r-- | rootston/main.c | 4 | ||||
-rw-r--r-- | rootston/output.c | 9 |
4 files changed, 72 insertions, 2 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index 2a3a7c25..b55eab3f 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -4,6 +4,7 @@ #include <stdint.h> #include <string.h> #include <math.h> +#include <assert.h> #ifdef __linux__ #include <linux/input-event-codes.h> #elif __FreeBSD__ @@ -12,6 +13,7 @@ #include <wayland-server.h> #include <wlr/types/wlr_cursor.h> #include <wlr/util/log.h> +#include <wlr/types/wlr_data_device.h> #include "rootston/config.h" #include "rootston/input.h" #include "rootston/desktop.h" @@ -355,6 +357,58 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { (uint32_t)(event->time_usec / 1000), BTN_LEFT, event->state); } +static void handle_drag_icon_destroy(struct wl_listener *listener, void *data) { + struct roots_drag_icon *drag_icon = + wl_container_of(listener, drag_icon, surface_destroy); + wl_list_remove(&drag_icon->link); + wl_list_remove(&drag_icon->surface_destroy.link); + wl_list_remove(&drag_icon->surface_commit.link); + free(drag_icon); +} + +static void handle_drag_icon_commit(struct wl_listener *listener, void *data) { + struct roots_drag_icon *drag_icon = + wl_container_of(listener, drag_icon, surface_commit); + // TODO the spec hints at rules that can determine whether the drag icon is + // mapped here, but it is not completely clear so we need to test more + // toolkits to see how we should interpret the surface state here. + drag_icon->sx += drag_icon->surface->current->sx; + drag_icon->sy += drag_icon->surface->current->sy; +} + +static void handle_pointer_grab_begin(struct wl_listener *listener, + void *data) { + struct roots_input *input = + wl_container_of(listener, input, pointer_grab_begin); + struct wlr_seat_pointer_grab *grab = data; + + if (grab->interface == &wlr_data_device_pointer_drag_interface) { + struct wlr_drag *drag = grab->data; + if (drag->icon) { + struct roots_drag_icon *iter_icon; + wl_list_for_each(iter_icon, &input->drag_icons, link) { + if (iter_icon->surface == drag->icon) { + // already in the list + return; + } + } + + struct roots_drag_icon *drag_icon = + calloc(1, sizeof(struct roots_drag_icon)); + drag_icon->surface = drag->icon; + wl_list_insert(&input->drag_icons, &drag_icon->link); + + wl_signal_add(&drag->icon->events.destroy, + &drag_icon->surface_destroy); + drag_icon->surface_destroy.notify = handle_drag_icon_destroy; + + wl_signal_add(&drag->icon->events.commit, + &drag_icon->surface_commit); + drag_icon->surface_commit.notify = handle_drag_icon_commit; + } + } +} + static void handle_pointer_grab_end(struct wl_listener *listener, void *data) { struct roots_input *input = wl_container_of(listener, input, pointer_grab_end); @@ -428,6 +482,11 @@ void cursor_initialize(struct roots_input *input) { wl_signal_add(&input->wl_seat->events.pointer_grab_end, &input->pointer_grab_end); input->pointer_grab_end.notify = handle_pointer_grab_end; + wl_signal_add(&input->wl_seat->events.pointer_grab_begin, &input->pointer_grab_begin); + input->pointer_grab_begin.notify = handle_pointer_grab_begin; + + wl_list_init(&input->request_set_cursor.link); + wl_signal_add(&input->wl_seat->events.request_set_cursor, &input->request_set_cursor); input->request_set_cursor.notify = handle_request_set_cursor; diff --git a/rootston/input.c b/rootston/input.c index 5dc7d16d..f424485e 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -124,6 +124,8 @@ struct roots_input *input_create(struct roots_server *server, cursor_load_config(config, input->cursor, input, server->desktop); + wl_list_init(&input->drag_icons); + return input; } diff --git a/rootston/main.c b/rootston/main.c index b80c2efd..2a054e6c 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -20,11 +20,11 @@ int main(int argc, char **argv) { assert(server.backend = wlr_backend_autocreate(server.wl_display)); assert(server.renderer = wlr_gles2_renderer_create(server.backend)); + server.data_device_manager = + wlr_data_device_manager_create(server.wl_display); wl_display_init_shm(server.wl_display); server.desktop = desktop_create(&server, server.config); server.input = input_create(&server, server.config); - server.data_device_manager = wlr_data_device_manager_create( - server.wl_display); const char *socket = wl_display_add_socket_auto(server.wl_display); if (!socket) { diff --git a/rootston/output.c b/rootston/output.c index 99f70bcf..89e1475b 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -150,6 +150,15 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { render_view(view, desktop, wlr_output, &now); } + struct roots_drag_icon *drag_icon = NULL; + wl_list_for_each(drag_icon, &server->input->drag_icons, link) { + struct wlr_surface *icon = drag_icon->surface; + struct wlr_cursor *cursor = server->input->cursor; + double icon_x = cursor->x + drag_icon->sx; + double icon_y = cursor->y + drag_icon->sy; + render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); + } + wlr_renderer_end(server->renderer); wlr_output_swap_buffers(wlr_output); |