2017-10-09 22:23:43 +00:00
|
|
|
#define _XOPEN_SOURCE 700
|
2017-10-15 15:06:03 +00:00
|
|
|
#include <stdlib.h>
|
2017-10-03 19:06:32 +00:00
|
|
|
#include <math.h>
|
2017-10-09 22:23:43 +00:00
|
|
|
#ifdef __linux__
|
2017-09-23 22:18:19 +00:00
|
|
|
#include <linux/input-event-codes.h>
|
2017-10-09 22:23:43 +00:00
|
|
|
#elif __FreeBSD__
|
|
|
|
#include <dev/evdev/input-event-codes.h>
|
|
|
|
#endif
|
2017-09-23 21:48:13 +00:00
|
|
|
#include <wlr/util/log.h>
|
2017-11-09 01:25:02 +00:00
|
|
|
#include "rootston/xcursor.h"
|
|
|
|
#include "rootston/cursor.h"
|
2017-10-27 16:41:31 +00:00
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
struct roots_cursor *roots_cursor_create(struct roots_seat *seat) {
|
|
|
|
struct roots_cursor *cursor = calloc(1, sizeof(struct roots_cursor));
|
|
|
|
if (!cursor) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
cursor->cursor = wlr_cursor_create();
|
|
|
|
if (!cursor->cursor) {
|
|
|
|
return NULL;
|
2017-10-27 16:41:31 +00:00
|
|
|
}
|
2017-11-09 01:25:02 +00:00
|
|
|
|
|
|
|
return cursor;
|
2017-09-28 23:48:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_destroy(struct roots_cursor *cursor) {
|
|
|
|
// TODO
|
2017-09-30 08:39:06 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
static void cursor_set_xcursor_image(struct roots_cursor *cursor,
|
|
|
|
struct wlr_xcursor_image *image) {
|
|
|
|
wlr_cursor_set_image(cursor->cursor, image->buffer, image->width,
|
2017-11-11 16:27:44 +00:00
|
|
|
image->width, image->height, image->hotspot_x, image->hotspot_y, 0);
|
2017-10-09 10:51:28 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t time) {
|
|
|
|
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
|
|
|
|
struct roots_seat *seat = cursor->seat;
|
2017-09-23 21:52:21 +00:00
|
|
|
struct roots_view *view;
|
2017-09-30 16:33:39 +00:00
|
|
|
struct wlr_surface *surface;
|
|
|
|
double sx, sy;
|
2017-11-09 01:25:02 +00:00
|
|
|
switch (cursor->mode) {
|
2017-09-23 21:52:21 +00:00
|
|
|
case ROOTS_CURSOR_PASSTHROUGH:
|
2017-11-09 01:25:02 +00:00
|
|
|
view = view_at(desktop, cursor->cursor->x, cursor->cursor->y,
|
2017-10-21 03:19:41 +00:00
|
|
|
&surface, &sx, &sy);
|
2017-11-09 01:25:02 +00:00
|
|
|
bool set_compositor_cursor = !view && cursor->cursor_client;
|
2017-10-12 12:28:37 +00:00
|
|
|
if (view) {
|
|
|
|
struct wl_client *view_client =
|
|
|
|
wl_resource_get_client(view->wlr_surface->resource);
|
2017-11-09 01:25:02 +00:00
|
|
|
set_compositor_cursor = view_client != cursor->cursor_client;
|
2017-10-12 12:28:37 +00:00
|
|
|
}
|
|
|
|
if (set_compositor_cursor) {
|
2017-11-09 01:25:02 +00:00
|
|
|
struct wlr_xcursor *xcursor = get_default_xcursor(cursor->xcursor_theme);
|
|
|
|
cursor_set_xcursor_image(cursor, xcursor->images[0]);
|
|
|
|
cursor->cursor_client = NULL;
|
2017-10-09 11:12:38 +00:00
|
|
|
}
|
2017-09-23 21:52:21 +00:00
|
|
|
if (view) {
|
2017-11-09 01:25:02 +00:00
|
|
|
wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy);
|
|
|
|
wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy);
|
2017-09-23 21:52:21 +00:00
|
|
|
} else {
|
2017-11-09 01:25:02 +00:00
|
|
|
wlr_seat_pointer_clear_focus(seat->seat);
|
2017-09-23 21:52:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ROOTS_CURSOR_MOVE:
|
2017-11-09 01:25:02 +00:00
|
|
|
if (seat->focus) {
|
|
|
|
double dx = cursor->cursor->x - cursor->offs_x;
|
|
|
|
double dy = cursor->cursor->y - cursor->offs_y;
|
|
|
|
view_move(seat->focus, cursor->view_x + dx,
|
|
|
|
cursor->view_y + dy);
|
2017-09-23 22:18:19 +00:00
|
|
|
}
|
2017-09-23 21:52:21 +00:00
|
|
|
break;
|
|
|
|
case ROOTS_CURSOR_RESIZE:
|
2017-11-09 01:25:02 +00:00
|
|
|
if (seat->focus) {
|
|
|
|
double dx = cursor->cursor->x - cursor->offs_x;
|
|
|
|
double dy = cursor->cursor->y - cursor->offs_y;
|
|
|
|
double active_x = seat->focus->x;
|
|
|
|
double active_y = seat->focus->y;
|
|
|
|
int width = cursor->view_width;
|
|
|
|
int height = cursor->view_height;
|
|
|
|
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
|
|
|
|
active_y = cursor->view_y + dy;
|
2017-09-30 11:22:42 +00:00
|
|
|
height -= dy;
|
2017-11-03 13:49:15 +00:00
|
|
|
if (height < 0) {
|
|
|
|
active_y += height;
|
|
|
|
}
|
2017-11-09 01:25:02 +00:00
|
|
|
} else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) {
|
2017-09-30 11:22:42 +00:00
|
|
|
height += dy;
|
|
|
|
}
|
2017-11-09 01:25:02 +00:00
|
|
|
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) {
|
|
|
|
active_x = cursor->view_x + dx;
|
2017-09-30 11:22:42 +00:00
|
|
|
width -= dx;
|
2017-11-03 13:49:15 +00:00
|
|
|
if (width < 0) {
|
|
|
|
active_x += width;
|
|
|
|
}
|
2017-11-09 01:25:02 +00:00
|
|
|
} else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) {
|
2017-09-30 11:22:42 +00:00
|
|
|
width += dx;
|
|
|
|
}
|
2017-10-19 16:33:02 +00:00
|
|
|
|
2017-10-28 09:58:34 +00:00
|
|
|
if (width < 0) {
|
|
|
|
width = 0;
|
|
|
|
}
|
|
|
|
if (height < 0) {
|
|
|
|
height = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
if (active_x != seat->focus->x ||
|
|
|
|
active_y != seat->focus->y) {
|
|
|
|
view_move_resize(seat->focus, active_x, active_y,
|
2017-11-03 13:49:15 +00:00
|
|
|
width, height);
|
|
|
|
} else {
|
2017-11-09 01:25:02 +00:00
|
|
|
view_resize(seat->focus, width, height);
|
2017-10-19 16:33:02 +00:00
|
|
|
}
|
2017-09-30 08:39:06 +00:00
|
|
|
}
|
2017-09-23 21:52:21 +00:00
|
|
|
break;
|
|
|
|
case ROOTS_CURSOR_ROTATE:
|
2017-11-09 01:25:02 +00:00
|
|
|
if (seat->focus) {
|
|
|
|
struct roots_view *view = seat->focus;
|
2017-10-03 19:06:32 +00:00
|
|
|
int ox = view->x + view->wlr_surface->current->width/2,
|
|
|
|
oy = view->y + view->wlr_surface->current->height/2;
|
2017-11-09 01:25:02 +00:00
|
|
|
int ux = cursor->offs_x - ox,
|
|
|
|
uy = cursor->offs_y - oy;
|
|
|
|
int vx = cursor->cursor->x - ox,
|
|
|
|
vy = cursor->cursor->y - oy;
|
2017-10-03 19:06:32 +00:00
|
|
|
float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy);
|
2017-10-04 20:01:54 +00:00
|
|
|
int steps = 12;
|
|
|
|
angle = round(angle/M_PI*steps) / (steps/M_PI);
|
2017-11-09 01:25:02 +00:00
|
|
|
view->rotation = cursor->view_rotation + angle;
|
2017-10-03 19:06:32 +00:00
|
|
|
}
|
2017-09-23 21:52:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-10-03 20:14:25 +00:00
|
|
|
|
2017-10-03 17:14:36 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
static void roots_cursor_press_button(struct roots_cursor *cursor,
|
|
|
|
struct wlr_input_device *device, uint32_t time, uint32_t button,
|
|
|
|
uint32_t state) {
|
|
|
|
struct roots_seat *seat = cursor->seat;
|
|
|
|
struct roots_desktop *desktop = seat->input->server->desktop;
|
2017-09-30 16:33:39 +00:00
|
|
|
struct wlr_surface *surface;
|
|
|
|
double sx, sy;
|
2017-09-23 22:18:19 +00:00
|
|
|
struct roots_view *view = view_at(desktop,
|
2017-11-09 01:25:02 +00:00
|
|
|
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
2017-10-03 17:14:36 +00:00
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
if (state == WLR_BUTTON_PRESSED && view && roots_seat_has_meta_pressed(seat)) {
|
|
|
|
roots_seat_focus_view(seat, view);
|
2017-10-03 17:14:36 +00:00
|
|
|
|
2017-10-27 18:36:25 +00:00
|
|
|
uint32_t edges;
|
2017-10-03 17:14:36 +00:00
|
|
|
switch (button) {
|
|
|
|
case BTN_LEFT:
|
2017-11-09 01:25:02 +00:00
|
|
|
roots_seat_begin_move(seat, view);
|
2017-10-03 17:14:36 +00:00
|
|
|
break;
|
|
|
|
case BTN_RIGHT:
|
2017-10-27 18:36:25 +00:00
|
|
|
edges = 0;
|
|
|
|
if (sx < view->wlr_surface->current->width/2) {
|
|
|
|
edges |= ROOTS_CURSOR_RESIZE_EDGE_LEFT;
|
|
|
|
} else {
|
|
|
|
edges |= ROOTS_CURSOR_RESIZE_EDGE_RIGHT;
|
|
|
|
}
|
|
|
|
if (sy < view->wlr_surface->current->height/2) {
|
|
|
|
edges |= ROOTS_CURSOR_RESIZE_EDGE_TOP;
|
|
|
|
} else {
|
|
|
|
edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM;
|
|
|
|
}
|
2017-11-09 01:25:02 +00:00
|
|
|
roots_seat_begin_resize(seat, view, edges);
|
2017-10-03 17:14:36 +00:00
|
|
|
break;
|
2017-10-03 19:06:32 +00:00
|
|
|
case BTN_MIDDLE:
|
2017-11-09 01:25:02 +00:00
|
|
|
roots_seat_begin_rotate(seat, view);
|
2017-10-27 18:36:25 +00:00
|
|
|
break;
|
2017-10-03 17:14:36 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
uint32_t serial =
|
|
|
|
wlr_seat_pointer_notify_button(seat->seat, time, button, state);
|
2017-10-03 17:14:36 +00:00
|
|
|
|
2017-09-23 18:53:15 +00:00
|
|
|
int i;
|
2017-09-23 22:18:19 +00:00
|
|
|
switch (state) {
|
2017-09-23 18:53:15 +00:00
|
|
|
case WLR_BUTTON_RELEASED:
|
2017-11-09 01:25:02 +00:00
|
|
|
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
|
|
|
|
roots_cursor_update_position(cursor, time);
|
2017-09-23 18:53:15 +00:00
|
|
|
break;
|
|
|
|
case WLR_BUTTON_PRESSED:
|
2017-11-09 01:25:02 +00:00
|
|
|
i = cursor->input_events_idx;
|
|
|
|
cursor->input_events[i].serial = serial;
|
|
|
|
cursor->input_events[i].cursor = cursor->cursor;
|
|
|
|
cursor->input_events[i].device = device;
|
|
|
|
cursor->input_events_idx = (i + 1)
|
|
|
|
% (sizeof(cursor->input_events) / sizeof(cursor->input_events[0]));
|
|
|
|
roots_seat_focus_view(seat, view);
|
2017-09-23 18:53:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_motion(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_pointer_motion *event) {
|
|
|
|
wlr_cursor_move(cursor->cursor, event->device,
|
|
|
|
event->delta_x, event->delta_y);
|
|
|
|
roots_cursor_update_position(cursor, event->time_msec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_pointer_motion_absolute *event) {
|
|
|
|
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
|
|
|
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
|
|
|
|
roots_cursor_update_position(cursor, event->time_msec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void roots_cursor_handle_button(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_pointer_button *event) {
|
|
|
|
roots_cursor_press_button(cursor, event->device, event->time_msec,
|
|
|
|
event->button, event->state);
|
2017-09-23 22:18:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_axis(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_pointer_axis *event) {
|
|
|
|
wlr_seat_pointer_notify_axis(cursor->seat->seat, event->time_msec,
|
|
|
|
event->orientation, event->delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_touch_down *event) {
|
2017-10-21 03:19:41 +00:00
|
|
|
struct roots_touch_point *point =
|
|
|
|
calloc(1, sizeof(struct roots_touch_point));
|
2017-11-09 01:25:02 +00:00
|
|
|
if (!point) {
|
|
|
|
wlr_log(L_ERROR, "could not allocate memory for touch point");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-21 03:19:41 +00:00
|
|
|
point->device = event->device->data;
|
|
|
|
point->slot = event->slot;
|
|
|
|
point->x = event->x_mm / event->width_mm;
|
|
|
|
point->y = event->y_mm / event->height_mm;
|
2017-11-09 01:25:02 +00:00
|
|
|
wlr_cursor_warp_absolute(cursor->cursor, event->device, point->x, point->y);
|
|
|
|
roots_cursor_update_position(cursor, event->time_msec);
|
|
|
|
wl_list_insert(&cursor->touch_points, &point->link);
|
|
|
|
roots_cursor_press_button(cursor, event->device,
|
2017-10-30 10:40:06 +00:00
|
|
|
event->time_msec, BTN_LEFT, 1);
|
2017-10-21 03:19:41 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_touch_up(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_touch_up *event) {
|
2017-10-21 03:19:41 +00:00
|
|
|
struct roots_touch_point *point;
|
2017-11-09 01:25:02 +00:00
|
|
|
wl_list_for_each(point, &cursor->touch_points, link) {
|
2017-10-21 03:19:41 +00:00
|
|
|
if (point->slot == event->slot) {
|
|
|
|
wl_list_remove(&point->link);
|
2017-11-09 01:25:02 +00:00
|
|
|
free(point);
|
2017-10-21 03:19:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-09 01:25:02 +00:00
|
|
|
roots_cursor_press_button(cursor, event->device,
|
2017-10-30 10:40:06 +00:00
|
|
|
event->time_msec, BTN_LEFT, 0);
|
2017-10-21 03:19:41 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_touch_motion *event) {
|
2017-10-21 03:19:41 +00:00
|
|
|
struct roots_touch_point *point;
|
2017-11-09 01:25:02 +00:00
|
|
|
wl_list_for_each(point, &cursor->touch_points, link) {
|
2017-10-21 03:19:41 +00:00
|
|
|
if (point->slot == event->slot) {
|
|
|
|
point->x = event->x_mm / event->width_mm;
|
|
|
|
point->y = event->y_mm / event->height_mm;
|
2017-11-09 01:25:02 +00:00
|
|
|
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
2017-10-21 03:19:41 +00:00
|
|
|
point->x, point->y);
|
2017-11-09 01:25:02 +00:00
|
|
|
roots_cursor_update_position(cursor, event->time_msec);
|
2017-10-21 03:19:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_tablet_tool_axis *event) {
|
2017-09-23 18:53:15 +00:00
|
|
|
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
|
|
|
|
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
2017-11-09 01:25:02 +00:00
|
|
|
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
2017-09-23 18:53:15 +00:00
|
|
|
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
|
2017-11-09 01:25:02 +00:00
|
|
|
roots_cursor_update_position(cursor, event->time_msec);
|
2017-11-04 05:35:12 +00:00
|
|
|
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
|
2017-11-11 14:58:59 +00:00
|
|
|
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
2017-11-04 05:35:12 +00:00
|
|
|
event->x_mm / event->width_mm, -1);
|
2017-11-11 14:58:59 +00:00
|
|
|
roots_cursor_update_position(cursor, event->time_msec);
|
2017-11-04 05:35:12 +00:00
|
|
|
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
2017-11-11 14:58:59 +00:00
|
|
|
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
2017-11-04 05:35:12 +00:00
|
|
|
-1, event->y_mm / event->height_mm);
|
2017-11-11 14:58:59 +00:00
|
|
|
roots_cursor_update_position(cursor, event->time_msec);
|
2017-09-23 18:53:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_tool_tip(struct roots_cursor *cursor,
|
|
|
|
struct wlr_event_tablet_tool_tip *event) {
|
|
|
|
roots_cursor_press_button(cursor, event->device,
|
2017-10-30 10:40:06 +00:00
|
|
|
event->time_msec, BTN_LEFT, event->state);
|
2017-09-23 18:53:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor,
|
|
|
|
struct wlr_seat_pointer_request_set_cursor_event *event) {
|
|
|
|
struct wlr_surface *focused_surface =
|
|
|
|
event->seat_client->seat->pointer_state.focused_surface;
|
|
|
|
bool has_focused = focused_surface != NULL && focused_surface->resource != NULL;
|
|
|
|
struct wl_client *focused_client = NULL;
|
|
|
|
if (has_focused) {
|
|
|
|
focused_client = wl_resource_get_client(focused_surface->resource);
|
|
|
|
}
|
|
|
|
if (event->seat_client->client != focused_client ||
|
|
|
|
cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
|
|
|
wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_log(L_DEBUG, "Setting client cursor");
|
|
|
|
wlr_cursor_set_surface(cursor->cursor, event->surface, event->hotspot_x,
|
|
|
|
event->hotspot_y);
|
|
|
|
cursor->cursor_client = event->seat_client->client;
|
2017-10-15 15:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-10-17 21:21:11 +00:00
|
|
|
drag_icon->sx += drag_icon->surface->current->sx;
|
|
|
|
drag_icon->sy += drag_icon->surface->current->sy;
|
2017-10-15 15:06:03 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-10-15 15:06:03 +00:00
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor,
|
|
|
|
struct wlr_seat_pointer_grab *grab) {
|
|
|
|
struct roots_seat *seat = cursor->seat;
|
2017-10-15 15:06:03 +00:00
|
|
|
if (grab->interface == &wlr_data_device_pointer_drag_interface) {
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
if (drag->icon) {
|
2017-10-16 12:00:01 +00:00
|
|
|
struct roots_drag_icon *iter_icon;
|
2017-11-09 01:25:02 +00:00
|
|
|
wl_list_for_each(iter_icon, &seat->drag_icons, link) {
|
2017-10-16 12:00:01 +00:00
|
|
|
if (iter_icon->surface == drag->icon) {
|
|
|
|
// already in the list
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 15:06:03 +00:00
|
|
|
struct roots_drag_icon *drag_icon =
|
|
|
|
calloc(1, sizeof(struct roots_drag_icon));
|
2017-11-01 12:05:02 +00:00
|
|
|
drag_icon->mapped = true;
|
2017-10-15 15:06:03 +00:00
|
|
|
drag_icon->surface = drag->icon;
|
2017-11-09 01:25:02 +00:00
|
|
|
wl_list_insert(&seat->drag_icons, &drag_icon->link);
|
2017-10-15 15:06:03 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor,
|
|
|
|
struct wlr_seat_pointer_grab *grab) {
|
2017-11-01 12:05:02 +00:00
|
|
|
if (grab->interface == &wlr_data_device_pointer_drag_interface) {
|
|
|
|
struct wlr_drag *drag = grab->data;
|
|
|
|
struct roots_drag_icon *icon;
|
2017-11-09 01:25:02 +00:00
|
|
|
wl_list_for_each(icon, &cursor->seat->drag_icons, link) {
|
2017-11-01 12:05:02 +00:00
|
|
|
if (icon->surface == drag->icon) {
|
|
|
|
icon->mapped = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:25:02 +00:00
|
|
|
roots_cursor_update_position(cursor, 0);
|
2017-09-23 14:36:32 +00:00
|
|
|
}
|