Merge branch 'master' into laggy-move-resize

This commit is contained in:
emersion 2017-11-19 22:28:51 +01:00
commit 7904b625f0
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
25 changed files with 1061 additions and 294 deletions

View file

@ -637,3 +637,21 @@ void wlr_cursor_map_input_to_region(struct wlr_cursor *cur,
c_device->mapped_box = box;
}
bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur,
struct wlr_input_device *device, double x_mm, double y_mm,
double width_mm, double height_mm, double *lx, double *ly) {
if (width_mm <= 0 || height_mm <= 0) {
return false;
}
struct wlr_box *mapping = get_mapping(cur, device);
if (!mapping) {
mapping = wlr_output_layout_get_box(cur->state->layout, NULL);
}
*lx = x_mm > 0 ? mapping->width * (x_mm / width_mm) + mapping->x : cur->x;
*ly = y_mm > 0 ? mapping->height * (y_mm / height_mm) + mapping->y : cur->y;
return true;
}

View file

@ -275,7 +275,8 @@ void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) {
struct wlr_data_offer *offer =
wlr_data_source_send_offer(seat_client->seat->selection_source,
seat_client->data_device);
wl_data_device_send_selection(seat_client->data_device, offer->resource);
wl_data_device_send_selection(seat_client->data_device,
offer->resource);
} else {
wl_data_device_send_selection(seat_client->data_device, NULL);
}
@ -351,15 +352,13 @@ static void data_device_release(struct wl_client *client,
wl_resource_destroy(resource);
}
static void drag_client_seat_unbound(struct wl_listener *listener, void *data) {
static void handle_drag_seat_client_destroy(struct wl_listener *listener,
void *data) {
struct wlr_drag *drag =
wl_container_of(listener, drag, seat_client_unbound);
struct wlr_seat_client *unbound_client = data;
wl_container_of(listener, drag, seat_client_destroy);
if (drag->focus_client == unbound_client) {
drag->focus_client = NULL;
wl_list_remove(&drag->seat_client_unbound.link);
}
drag->focus_client = NULL;
wl_list_remove(&drag->seat_client_destroy.link);
}
static void wlr_drag_set_focus(struct wlr_drag *drag,
@ -369,7 +368,7 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
}
if (drag->focus_client && drag->focus_client->data_device) {
wl_list_remove(&drag->seat_client_unbound.link);
wl_list_remove(&drag->seat_client_destroy.link);
wl_data_device_send_leave(drag->focus_client->data_device);
drag->focus_client = NULL;
drag->focus = NULL;
@ -429,16 +428,20 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
drag->focus = surface;
drag->focus_client = focus_client;
drag->seat_client_unbound.notify = drag_client_seat_unbound;
wl_signal_add(&focus_client->seat->events.client_unbound,
&drag->seat_client_unbound);
drag->seat_client_destroy.notify = handle_drag_seat_client_destroy;
wl_signal_add(&focus_client->events.destroy,
&drag->seat_client_destroy);
}
static void wlr_drag_end(struct wlr_drag *drag) {
if (!drag->cancelling) {
drag->cancelling = true;
wlr_seat_pointer_end_grab(drag->pointer_grab.seat);
wlr_seat_keyboard_end_grab(drag->keyboard_grab.seat);
if (drag->is_pointer_grab) {
wlr_seat_pointer_end_grab(drag->seat);
} else {
wlr_seat_touch_end_grab(drag->seat);
}
wlr_seat_keyboard_end_grab(drag->seat);
if (drag->source) {
wl_list_remove(&drag->source_destroy.link);
@ -447,6 +450,7 @@ static void wlr_drag_end(struct wlr_drag *drag) {
wlr_drag_set_focus(drag, NULL, 0, 0);
if (drag->icon) {
drag->icon->mapped = false;
wl_list_remove(&drag->icon_destroy.link);
}
@ -521,6 +525,54 @@ wlr_pointer_grab_interface wlr_data_device_pointer_drag_interface = {
.cancel = pointer_drag_cancel,
};
uint32_t touch_drag_down(struct wlr_seat_touch_grab *grab,
uint32_t time, struct wlr_touch_point *point) {
// eat the event
return 0;
}
static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time,
struct wlr_touch_point *point) {
struct wlr_drag *drag = grab->data;
if (drag->grab_touch_id != point->touch_id) {
return;
}
if (drag->focus_client && drag->focus_client->data_device) {
wl_data_device_send_drop(drag->focus_client->data_device);
}
wlr_drag_end(drag);
}
static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time,
struct wlr_touch_point *point) {
struct wlr_drag *drag = grab->data;
if (drag->focus && drag->focus_client && drag->focus_client->data_device) {
wl_data_device_send_motion(drag->focus_client->data_device, time,
wl_fixed_from_double(point->sx), wl_fixed_from_double(point->sy));
}
}
static void touch_drag_enter(struct wlr_seat_touch_grab *grab, uint32_t time,
struct wlr_touch_point *point) {
struct wlr_drag *drag = grab->data;
wlr_drag_set_focus(drag, point->focus_surface, point->sx, point->sy);
}
static void touch_drag_cancel(struct wlr_seat_touch_grab *grab) {
struct wlr_drag *drag = grab->data;
wlr_drag_end(drag);
}
const struct wlr_touch_grab_interface wlr_data_device_touch_drag_interface = {
.down = touch_drag_down,
.up = touch_drag_up,
.motion = touch_drag_motion,
.enter = touch_drag_enter,
.cancel = touch_drag_cancel,
};
static void keyboard_drag_enter(struct wlr_seat_keyboard_grab *grab,
struct wlr_surface *surface) {
// nothing has keyboard focus during drags
@ -561,20 +613,119 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener,
wlr_drag_end(drag);
}
static void wlr_drag_icon_destroy(struct wlr_drag_icon *icon) {
if (!icon) {
return;
}
wl_signal_emit(&icon->events.destroy, icon);
wl_list_remove(&icon->surface_commit.link);
wl_list_remove(&icon->surface_destroy.link);
wl_list_remove(&icon->seat_client_destroy.link);
wl_list_remove(&icon->link);
free(icon);
}
static void handle_drag_icon_surface_destroy(struct wl_listener *listener,
void *data) {
struct wlr_drag_icon *icon =
wl_container_of(listener, icon, surface_destroy);
wlr_drag_icon_destroy(icon);
}
static void handle_drag_icon_surface_commit(struct wl_listener *listener,
void *data) {
struct wlr_drag_icon *icon =
wl_container_of(listener, icon, surface_commit);
icon->sx += icon->surface->current->sx;
icon->sy += icon->surface->current->sy;
}
static void handle_drag_icon_seat_client_destroy(struct wl_listener *listener,
void *data) {
struct wlr_drag_icon *icon =
wl_container_of(listener, icon, seat_client_destroy);
wlr_drag_icon_destroy(icon);
}
static struct wlr_drag_icon *wlr_drag_icon_create(
struct wlr_surface *icon_surface, struct wlr_seat_client *client,
bool is_pointer, int32_t touch_id) {
struct wlr_drag_icon *icon = calloc(1, sizeof(struct wlr_drag_icon));
if (!icon) {
return NULL;
}
icon->surface = icon_surface;
icon->client = client;
icon->is_pointer = is_pointer;
icon->touch_id = touch_id;
icon->mapped = true;
wl_list_insert(&client->seat->drag_icons, &icon->link);
wl_signal_init(&icon->events.destroy);
wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy);
icon->surface_destroy.notify = handle_drag_icon_surface_destroy;
wl_signal_add(&icon->surface->events.commit, &icon->surface_commit);
icon->surface_commit.notify = handle_drag_icon_surface_commit;
wl_signal_add(&client->events.destroy, &icon->seat_client_destroy);
icon->seat_client_destroy.notify = handle_drag_icon_seat_client_destroy;
return icon;
}
static bool seat_client_start_drag(struct wlr_seat_client *client,
struct wlr_data_source *source, struct wlr_surface *icon) {
struct wlr_data_source *source, struct wlr_surface *icon_surface,
struct wlr_surface *origin, uint32_t serial) {
struct wlr_drag *drag = calloc(1, sizeof(struct wlr_drag));
if (drag == NULL) {
return false;
}
struct wlr_seat *seat = client->seat;
drag->seat = client->seat;
drag->is_pointer_grab = client->pointer != NULL &&
client->seat->pointer_state.button_count == 1 &&
client->seat->pointer_state.grab_serial == serial &&
client->seat->pointer_state.focused_surface &&
client->seat->pointer_state.focused_surface == origin;
bool is_touch_grab = client->touch &&
wlr_seat_touch_num_points(client->seat) == 1 &&
client->seat->touch_state.grab_serial == serial;
// set in the iteration
struct wlr_touch_point *point = NULL;
if (is_touch_grab) {
wl_list_for_each(point, &client->seat->touch_state.touch_points, link) {
is_touch_grab = point->surface && point->surface == origin;
break;
}
}
if (!drag->is_pointer_grab && !is_touch_grab) {
free(drag);
return true;
}
if (icon_surface) {
int32_t touch_id = (point ? point->touch_id : 0);
struct wlr_drag_icon *icon =
wlr_drag_icon_create(icon_surface, client, drag->is_pointer_grab,
touch_id);
if (!icon) {
free(drag);
return false;
}
if (icon) {
drag->icon = icon;
drag->icon_destroy.notify = drag_handle_icon_destroy;
wl_signal_add(&icon->events.destroy, &drag->icon_destroy);
drag->icon = icon;
}
if (source) {
@ -587,13 +738,23 @@ static bool seat_client_start_drag(struct wlr_seat_client *client,
drag->pointer_grab.data = drag;
drag->pointer_grab.interface = &wlr_data_device_pointer_drag_interface;
drag->touch_grab.data = drag;
drag->touch_grab.interface = &wlr_data_device_touch_drag_interface;
drag->grab_touch_id = drag->seat->touch_state.grab_id;
drag->keyboard_grab.data = drag;
drag->keyboard_grab.interface = &wlr_data_device_keyboard_drag_interface;
wlr_seat_pointer_clear_focus(seat);
wlr_seat_keyboard_start_grab(drag->seat, &drag->keyboard_grab);
wlr_seat_keyboard_start_grab(seat, &drag->keyboard_grab);
wlr_seat_pointer_start_grab(seat, &drag->pointer_grab);
if (drag->is_pointer_grab) {
wlr_seat_pointer_clear_focus(drag->seat);
wlr_seat_pointer_start_grab(drag->seat, &drag->pointer_grab);
} else {
assert(point);
wlr_seat_touch_start_grab(drag->seat, &drag->touch_grab);
wlr_drag_set_focus(drag, point->surface, point->sx, point->sy);
}
return true;
}
@ -603,21 +764,12 @@ static void data_device_start_drag(struct wl_client *client,
struct wl_resource *source_resource,
struct wl_resource *origin_resource, struct wl_resource *icon_resource,
uint32_t serial) {
struct wlr_seat_client *seat_client = wl_resource_get_user_data(device_resource);
struct wlr_seat *seat = seat_client->seat;
struct wlr_seat_client *seat_client =
wl_resource_get_user_data(device_resource);
struct wlr_surface *origin = wl_resource_get_user_data(origin_resource);
struct wlr_data_source *source = NULL;
struct wlr_surface *icon = NULL;
bool is_pointer_grab = seat->pointer_state.button_count == 1 &&
seat->pointer_state.grab_serial == serial &&
seat->pointer_state.focused_surface &&
seat->pointer_state.focused_surface == origin;
if (!is_pointer_grab) {
return;
}
if (source_resource) {
source = wl_resource_get_user_data(source_resource);
}
@ -632,9 +784,7 @@ static void data_device_start_drag(struct wl_client *client,
}
}
// TODO touch grab
if (!seat_client_start_drag(seat_client, source, icon)) {
if (!seat_client_start_drag(seat_client, source, icon, origin, serial)) {
wl_resource_post_no_memory(device_resource);
return;
}
@ -653,7 +803,8 @@ static const struct wl_data_device_interface data_device_impl = {
void data_device_manager_get_data_device(struct wl_client *client,
struct wl_resource *manager_resource, uint32_t id,
struct wl_resource *seat_resource) {
struct wlr_seat_client *seat_client = wl_resource_get_user_data(seat_resource);
struct wlr_seat_client *seat_client =
wl_resource_get_user_data(seat_resource);
struct wl_resource *resource =
wl_resource_create(client,
@ -820,9 +971,9 @@ struct wlr_data_device_manager *wlr_data_device_manager_create(
}
void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) {
if (!manager) {
return;
}
wl_global_destroy(manager->global);
free(manager);
if (!manager) {
return;
}
wl_global_destroy(manager->global);
free(manager);
}

View file

@ -181,7 +181,7 @@ static void wl_seat_get_touch(struct wl_client *client,
static void wlr_seat_client_resource_destroy(struct wl_resource *resource) {
struct wlr_seat_client *client = wl_resource_get_user_data(resource);
wl_signal_emit(&client->seat->events.client_unbound, client);
wl_signal_emit(&client->events.destroy, client);
if (client == client->seat->pointer_state.focused_client) {
client->seat->pointer_state.focused_client = NULL;
@ -240,7 +240,7 @@ static void wl_seat_bind(struct wl_client *client, void *_wlr_seat,
wl_seat_send_name(seat_client->wl_resource, wlr_seat->name);
}
wl_seat_send_capabilities(seat_client->wl_resource, wlr_seat->capabilities);
wl_signal_emit(&wlr_seat->events.client_bound, seat_client);
wl_signal_init(&seat_client->events.destroy);
}
static void default_pointer_enter(struct wlr_seat_pointer_grab *grab,
@ -300,12 +300,50 @@ static const struct wlr_keyboard_grab_interface default_keyboard_grab_impl = {
.cancel = default_keyboard_cancel,
};
static uint32_t default_touch_down(struct wlr_seat_touch_grab *grab, uint32_t time,
struct wlr_touch_point *point) {
return wlr_seat_touch_send_down(grab->seat, point->surface, time,
point->touch_id, point->sx, point->sy);
}
static void default_touch_up(struct wlr_seat_touch_grab *grab, uint32_t time,
struct wlr_touch_point *point) {
wlr_seat_touch_send_up(grab->seat, time, point->touch_id);
}
static void default_touch_motion(struct wlr_seat_touch_grab *grab,
uint32_t time, struct wlr_touch_point *point) {
if (!point->focus_surface || point->focus_surface == point->surface) {
wlr_seat_touch_send_motion(grab->seat, time, point->touch_id, point->sx,
point->sy);
}
}
static void default_touch_enter(struct wlr_seat_touch_grab *grab,
uint32_t time, struct wlr_touch_point *point) {
// not handled by default
}
static void default_touch_cancel(struct wlr_seat_touch_grab *grab) {
// cannot be cancelled
}
static const struct wlr_touch_grab_interface default_touch_grab_impl = {
.down = default_touch_down,
.up = default_touch_up,
.motion = default_touch_motion,
.enter = default_touch_enter,
.cancel = default_touch_cancel,
};
struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
struct wlr_seat *wlr_seat = calloc(1, sizeof(struct wlr_seat));
if (!wlr_seat) {
return NULL;
}
// pointer state
wlr_seat->pointer_state.seat = wlr_seat;
wl_list_init(&wlr_seat->pointer_state.surface_destroy.link);
wl_list_init(&wlr_seat->pointer_state.resource_destroy.link);
@ -321,6 +359,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
wlr_seat->pointer_state.default_grab = pointer_grab;
wlr_seat->pointer_state.grab = pointer_grab;
// keyboard state
struct wlr_seat_keyboard_grab *keyboard_grab =
calloc(1, sizeof(struct wlr_seat_keyboard_grab));
if (!keyboard_grab) {
@ -338,6 +377,23 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
wl_list_init(
&wlr_seat->keyboard_state.surface_destroy.link);
// touch state
struct wlr_seat_touch_grab *touch_grab =
calloc(1, sizeof(struct wlr_seat_touch_grab));
if (!touch_grab) {
free(pointer_grab);
free(keyboard_grab);
free(wlr_seat);
return NULL;
}
touch_grab->interface = &default_touch_grab_impl;
touch_grab->seat = wlr_seat;
wlr_seat->touch_state.default_grab = touch_grab;
wlr_seat->touch_state.grab = touch_grab;
wlr_seat->touch_state.seat = wlr_seat;
wl_list_init(&wlr_seat->touch_state.touch_points);
struct wl_global *wl_global = wl_global_create(display,
&wl_seat_interface, 6, wlr_seat, wl_seat_bind);
if (!wl_global) {
@ -348,9 +404,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
wlr_seat->display = display;
wlr_seat->name = strdup(name);
wl_list_init(&wlr_seat->clients);
wl_signal_init(&wlr_seat->events.client_bound);
wl_signal_init(&wlr_seat->events.client_unbound);
wl_list_init(&wlr_seat->drag_icons);
wl_signal_init(&wlr_seat->events.request_set_cursor);
wl_signal_init(&wlr_seat->events.selection);
@ -361,6 +415,9 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
wl_signal_init(&wlr_seat->events.keyboard_grab_begin);
wl_signal_init(&wlr_seat->events.keyboard_grab_end);
wl_signal_init(&wlr_seat->events.touch_grab_begin);
wl_signal_init(&wlr_seat->events.touch_grab_end);
return wlr_seat;
}
@ -378,6 +435,7 @@ void wlr_seat_destroy(struct wlr_seat *wlr_seat) {
wl_global_destroy(wlr_seat->wl_global);
free(wlr_seat->pointer_state.default_grab);
free(wlr_seat->keyboard_state.default_grab);
free(wlr_seat->touch_state.default_grab);
free(wlr_seat->data_device);
free(wlr_seat->name);
free(wlr_seat);
@ -550,7 +608,9 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
void wlr_seat_pointer_start_grab(struct wlr_seat *wlr_seat,
struct wlr_seat_pointer_grab *grab) {
assert(wlr_seat);
grab->seat = wlr_seat;
assert(grab->seat);
wlr_seat->pointer_state.grab = grab;
wl_signal_emit(&wlr_seat->events.pointer_grab_begin, grab);
@ -596,7 +656,7 @@ uint32_t wlr_seat_pointer_notify_button(struct wlr_seat *wlr_seat,
struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab;
uint32_t serial = grab->interface->button(grab, time, button, state);
if (wlr_seat->pointer_state.button_count == 1) {
if (serial && wlr_seat->pointer_state.button_count == 1) {
wlr_seat->pointer_state.grab_serial = serial;
}
@ -610,6 +670,10 @@ void wlr_seat_pointer_notify_axis(struct wlr_seat *wlr_seat, uint32_t time,
grab->interface->axis(grab, time, orientation, value);
}
bool wlr_seat_pointer_has_grab(struct wlr_seat *seat) {
return seat->pointer_state.grab->interface != &default_pointer_grab_impl;
}
void wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time,
uint32_t key, uint32_t state) {
struct wlr_seat_client *client = wlr_seat->keyboard_state.focused_client;
@ -807,6 +871,10 @@ void wlr_seat_keyboard_clear_focus(struct wlr_seat *seat) {
wlr_seat_keyboard_enter(seat, NULL);
}
bool wlr_seat_keyboard_has_grab(struct wlr_seat *seat) {
return seat->keyboard_state.grab->interface != &default_keyboard_grab_impl;
}
void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat) {
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
@ -819,3 +887,265 @@ void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time,
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
grab->interface->key(grab, time, key, state);
}
void wlr_seat_touch_start_grab(struct wlr_seat *wlr_seat,
struct wlr_seat_touch_grab *grab) {
grab->seat = wlr_seat;
wlr_seat->touch_state.grab = grab;
wl_signal_emit(&wlr_seat->events.touch_grab_begin, grab);
}
void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat) {
struct wlr_seat_touch_grab *grab = wlr_seat->touch_state.grab;
if (grab != wlr_seat->touch_state.default_grab) {
wlr_seat->touch_state.grab = wlr_seat->touch_state.default_grab;
wl_signal_emit(&wlr_seat->events.touch_grab_end, grab);
if (grab->interface->cancel) {
grab->interface->cancel(grab);
}
}
}
static void touch_point_clear_focus(struct wlr_touch_point *point) {
if (point->focus_surface) {
wl_list_remove(&point->focus_surface_destroy.link);
point->focus_client = NULL;
point->focus_surface = NULL;
}
}
static void touch_point_destroy(struct wlr_touch_point *point) {
wl_signal_emit(&point->events.destroy, point);
touch_point_clear_focus(point);
wl_list_remove(&point->surface_destroy.link);
wl_list_remove(&point->resource_destroy.link);
wl_list_remove(&point->link);
free(point);
}
static void handle_touch_point_resource_destroy(struct wl_listener *listener,
void *data) {
struct wlr_touch_point *point =
wl_container_of(listener, point, resource_destroy);
touch_point_destroy(point);
}
static void handle_touch_point_surface_destroy(struct wl_listener *listener,
void *data) {
struct wlr_touch_point *point =
wl_container_of(listener, point, surface_destroy);
touch_point_destroy(point);
}
static struct wlr_touch_point *touch_point_create(
struct wlr_seat *seat, int32_t touch_id,
struct wlr_surface *surface, double sx, double sy) {
struct wl_client *wl_client = wl_resource_get_client(surface->resource);
struct wlr_seat_client *client = wlr_seat_client_for_wl_client(seat, wl_client);
if (!client || !client->touch) {
// touch points are not valid without a connected client with touch
return NULL;
}
struct wlr_touch_point *point = calloc(1, sizeof(struct wlr_touch_point));
if (!point) {
return NULL;
}
point->touch_id = touch_id;
point->surface = surface;
point->client = client;
point->sx = sx;
point->sy = sy;
wl_signal_init(&point->events.destroy);
wl_signal_add(&surface->events.destroy, &point->surface_destroy);
point->surface_destroy.notify = handle_touch_point_surface_destroy;
wl_resource_add_destroy_listener(surface->resource,
&point->resource_destroy);
point->resource_destroy.notify = handle_touch_point_resource_destroy;
wl_list_insert(&seat->touch_state.touch_points, &point->link);
return point;
}
struct wlr_touch_point *wlr_seat_touch_get_point(
struct wlr_seat *seat, int32_t touch_id) {
struct wlr_touch_point *point = NULL;
wl_list_for_each(point, &seat->touch_state.touch_points, link) {
if (point->touch_id == touch_id) {
return point;
}
}
return NULL;
}
uint32_t wlr_seat_touch_notify_down(struct wlr_seat *seat,
struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx,
double sy) {
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
struct wlr_touch_point *point =
touch_point_create(seat, touch_id, surface, sx, sy);
if (!point) {
wlr_log(L_ERROR, "could not create touch point");
return 0;
}
uint32_t serial = grab->interface->down(grab, time, point);
if (serial && wlr_seat_touch_num_points(seat) == 1) {
seat->touch_state.grab_serial = serial;
seat->touch_state.grab_id = touch_id;
}
return serial;
}
void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time,
int32_t touch_id) {
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
if (!point) {
wlr_log(L_ERROR, "got touch up for unknown touch point");
return;
}
grab->interface->up(grab, time, point);
touch_point_destroy(point);
}
void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time,
int32_t touch_id, double sx, double sy) {
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
if (!point) {
wlr_log(L_ERROR, "got touch motion for unknown touch point");
return;
}
point->sx = sx;
point->sy = sy;
grab->interface->motion(grab, time, point);
}
static void handle_point_focus_destroy(struct wl_listener *listener,
void *data) {
struct wlr_touch_point *point =
wl_container_of(listener, point, focus_surface_destroy);
touch_point_clear_focus(point);
}
static void touch_point_set_focus(struct wlr_touch_point *point,
struct wlr_surface *surface, double sx, double sy) {
if (point->focus_surface == surface) {
return;
}
touch_point_clear_focus(point);
if (surface && surface->resource) {
struct wlr_seat_client *client =
wlr_seat_client_for_wl_client(point->client->seat,
wl_resource_get_client(surface->resource));
if (client && client->touch) {
wl_signal_add(&surface->events.destroy, &point->focus_surface_destroy);
point->focus_surface_destroy.notify = handle_point_focus_destroy;
point->focus_surface = surface;
point->focus_client = client;
point->sx = sx;
point->sy = sy;
}
}
}
void wlr_seat_touch_point_focus(struct wlr_seat *seat,
struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx,
double sy) {
assert(surface);
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
if (!point) {
wlr_log(L_ERROR, "got touch point focus for unknown touch point");
return;
}
struct wlr_surface *focus = point->focus_surface;
touch_point_set_focus(point, surface, sx, sy);
if (focus != point->focus_surface) {
struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
grab->interface->enter(grab, time, point);
}
}
void wlr_seat_touch_point_clear_focus(struct wlr_seat *seat, uint32_t time,
int32_t touch_id) {
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
if (!point) {
wlr_log(L_ERROR, "got touch point focus for unknown touch point");
return;
}
touch_point_clear_focus(point);
}
uint32_t wlr_seat_touch_send_down(struct wlr_seat *seat,
struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx,
double sy) {
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
if (!point) {
wlr_log(L_ERROR, "got touch down for unknown touch point");
return 0;
}
uint32_t serial = wl_display_next_serial(seat->display);
wl_touch_send_down(point->client->touch, serial, time, surface->resource,
touch_id, wl_fixed_from_double(sx), wl_fixed_from_double(sy));
wl_touch_send_frame(point->client->touch);
return serial;
}
void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id) {
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
if (!point) {
wlr_log(L_ERROR, "got touch up for unknown touch point");
return;
}
uint32_t serial = wl_display_next_serial(seat->display);
wl_touch_send_up(point->client->touch, serial, time, touch_id);
wl_touch_send_frame(point->client->touch);
}
void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id,
double sx, double sy) {
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
if (!point) {
wlr_log(L_ERROR, "got touch motion for unknown touch point");
return;
}
wl_touch_send_motion(point->client->touch, time, touch_id,
wl_fixed_from_double(sx), wl_fixed_from_double(sy));
wl_touch_send_frame(point->client->touch);
}
int wlr_seat_touch_num_points(struct wlr_seat *seat) {
return wl_list_length(&seat->touch_state.touch_points);
}
bool wlr_seat_touch_has_grab(struct wlr_seat *seat) {
return seat->touch_state.grab->interface != &default_touch_grab_impl;
}

View file

@ -46,7 +46,7 @@ int wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager,
return 1;
}
theme->scale = scale;
theme->theme = wlr_xcursor_theme_load(NULL, manager->size * scale);
theme->theme = wlr_xcursor_theme_load(manager->name, manager->size * scale);
if (theme->theme == NULL) {
free(theme);
return 1;