mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-26 22:55:58 +01:00
commit
1225a402d0
2 changed files with 66 additions and 37 deletions
|
@ -7,15 +7,16 @@
|
||||||
#include <wlr/types/wlr_data_source.h>
|
#include <wlr/types/wlr_data_source.h>
|
||||||
#include <wlr/types/wlr_seat.h>
|
#include <wlr/types/wlr_seat.h>
|
||||||
|
|
||||||
static void resource_destroy(struct wl_client *client, struct wl_resource *resource) {
|
static void resource_destroy(struct wl_client *client,
|
||||||
|
struct wl_resource *resource) {
|
||||||
wl_resource_destroy(resource);
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wl_cb_data_device_start_drag(struct wl_client *client,
|
static void data_device_start_drag(struct wl_client *client,
|
||||||
struct wl_resource *res, struct wl_resource *src_res,
|
struct wl_resource *res, struct wl_resource *source_resource,
|
||||||
struct wl_resource *origin_res, struct wl_resource *icon_res,
|
struct wl_resource *origin_res, struct wl_resource *icon_res,
|
||||||
uint32_t serial) {
|
uint32_t serial) {
|
||||||
wlr_log(L_DEBUG, "implement data_device:start_drag");
|
wlr_log(L_DEBUG, "TODO: implement data_device:start_drag");
|
||||||
|
|
||||||
// Will probably look like this:
|
// Will probably look like this:
|
||||||
// struct wlr_seat_handle *handle = wl_resource_get_user_data(res);
|
// struct wlr_seat_handle *handle = wl_resource_get_user_data(res);
|
||||||
|
@ -29,68 +30,79 @@ static void wl_cb_data_device_start_drag(struct wl_client *client,
|
||||||
// origin, icon); // will set surface roles and emit signal for user
|
// origin, icon); // will set surface roles and emit signal for user
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wl_cb_data_device_set_selection(struct wl_client *client,
|
static void data_device_set_selection(struct wl_client *client,
|
||||||
struct wl_resource *res, struct wl_resource *src_res,
|
struct wl_resource *resource, struct wl_resource *source_resource,
|
||||||
uint32_t serial) {
|
uint32_t serial) {
|
||||||
|
if (!source_resource) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: serial validation
|
// TODO: serial validation
|
||||||
struct wlr_seat_handle *handle = wl_resource_get_user_data(res);
|
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
|
||||||
struct wlr_data_device *device = handle->wlr_seat->data_device;
|
struct wlr_data_device *device = handle->wlr_seat->data_device;
|
||||||
struct wlr_data_source *src = wl_resource_get_user_data(src_res);
|
struct wlr_data_source *source = wl_resource_get_user_data(source_resource);
|
||||||
wlr_data_device_set_selection(device, src);
|
wlr_data_device_set_selection(device, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wl_data_device_interface data_device_impl = {
|
static struct wl_data_device_interface data_device_impl = {
|
||||||
.start_drag = wl_cb_data_device_start_drag,
|
.start_drag = data_device_start_drag,
|
||||||
.set_selection = wl_cb_data_device_set_selection,
|
.set_selection = data_device_set_selection,
|
||||||
.release = resource_destroy
|
.release = resource_destroy
|
||||||
};
|
};
|
||||||
|
|
||||||
static void data_device_selection_destroy(struct wl_listener *listener, void *data) {
|
static void data_device_selection_destroy(struct wl_listener *listener,
|
||||||
struct wlr_data_device *device = wl_container_of(listener, device, selection_destroyed);
|
void *data) {
|
||||||
|
struct wlr_data_device *device =
|
||||||
|
wl_container_of(listener, device, selection_destroyed);
|
||||||
assert(data == device->selection);
|
assert(data == device->selection);
|
||||||
device->selection = NULL; // make sure no cancel is sent
|
device->selection = NULL; // make sure no cancel is sent
|
||||||
wlr_data_device_set_selection(device, NULL);
|
wlr_data_device_set_selection(device, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wlr_data_device *seat_ensure_data_device(struct wlr_data_device_manager *manager,
|
static struct wlr_data_device *seat_ensure_data_device(
|
||||||
struct wlr_seat *seat) {
|
struct wlr_data_device_manager *manager, struct wlr_seat *seat) {
|
||||||
if (seat->data_device) {
|
if (seat->data_device) {
|
||||||
return seat->data_device;
|
return seat->data_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(seat->data_device = calloc(1, sizeof(*seat->data_device)))) {
|
seat->data_device = calloc(1, sizeof(*seat->data_device));
|
||||||
|
if (!seat->data_device) {
|
||||||
wlr_log(L_ERROR, "Failed to allocate wlr_data_device");
|
wlr_log(L_ERROR, "Failed to allocate wlr_data_device");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
seat->data_device->seat = seat;
|
seat->data_device->seat = seat;
|
||||||
wl_signal_init(&seat->data_device->events.selection_change);
|
wl_signal_init(&seat->data_device->events.selection_change);
|
||||||
seat->data_device->selection_destroyed.notify = data_device_selection_destroy;
|
seat->data_device->selection_destroyed.notify =
|
||||||
|
data_device_selection_destroy;
|
||||||
return seat->data_device;
|
return seat->data_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void data_device_destroy(struct wl_resource *res) {
|
static void data_device_destroy(struct wl_resource *resource) {
|
||||||
struct wlr_seat_handle *handle = wl_resource_get_user_data(res);
|
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
|
||||||
handle->data_device = NULL;
|
handle->data_device = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void data_device_manager_create_data_source(struct wl_client *client,
|
static void data_device_manager_create_data_source(struct wl_client *client,
|
||||||
struct wl_resource *res, uint32_t id) {
|
struct wl_resource *resource, uint32_t id) {
|
||||||
uint32_t version = wl_resource_get_version(res);
|
uint32_t version = wl_resource_get_version(resource);
|
||||||
if (!wlr_wl_data_source_create(client, version, id)) {
|
if (!wlr_wl_data_source_create(client, version, id)) {
|
||||||
wlr_log(L_ERROR, "Failed to create wlr_wl_data_source");
|
wlr_log(L_ERROR, "Failed to create wlr_wl_data_source");
|
||||||
wl_resource_post_no_memory(res);
|
wl_resource_post_no_memory(resource);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void data_device_manager_get_data_device(struct wl_client *client,
|
static void data_device_manager_get_data_device(struct wl_client *client,
|
||||||
struct wl_resource *res, uint32_t id, struct wl_resource *seat_res) {
|
struct wl_resource *resource, uint32_t id,
|
||||||
struct wlr_data_device_manager *manager = wl_resource_get_user_data(res);
|
struct wl_resource *seat_resource) {
|
||||||
struct wlr_seat_handle *seat_handle = wl_resource_get_user_data(seat_res);
|
struct wlr_data_device_manager *manager =
|
||||||
|
wl_resource_get_user_data(resource);
|
||||||
|
struct wlr_seat_handle *seat_handle =
|
||||||
|
wl_resource_get_user_data(seat_resource);
|
||||||
struct wlr_data_device *device;
|
struct wlr_data_device *device;
|
||||||
if (!(device = seat_ensure_data_device(manager, seat_handle->wlr_seat))) {
|
if (!(device = seat_ensure_data_device(manager, seat_handle->wlr_seat))) {
|
||||||
wl_resource_post_no_memory(res);
|
wl_resource_post_no_memory(resource);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,10 +113,10 @@ static void data_device_manager_get_data_device(struct wl_client *client,
|
||||||
}
|
}
|
||||||
|
|
||||||
seat_handle->data_device = wl_resource_create(client,
|
seat_handle->data_device = wl_resource_create(client,
|
||||||
&wl_data_device_interface, wl_resource_get_version(res), id);
|
&wl_data_device_interface, wl_resource_get_version(resource), id);
|
||||||
if (!seat_handle->data_device) {
|
if (!seat_handle->data_device) {
|
||||||
wlr_log(L_ERROR, "Failed to create wl_data_device resource");
|
wlr_log(L_ERROR, "Failed to create wl_data_device resource");
|
||||||
wl_resource_post_no_memory(res);
|
wl_resource_post_no_memory(resource);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,15 +150,18 @@ static void data_device_manager_bind(struct wl_client *client, void *data,
|
||||||
manager, NULL);
|
manager, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_data_device_manager *wlr_data_device_manager_create(struct wl_display *dpy) {
|
struct wlr_data_device_manager *wlr_data_device_manager_create(
|
||||||
|
struct wl_display *display) {
|
||||||
struct wlr_data_device_manager *manager = calloc(1, sizeof(*manager));
|
struct wlr_data_device_manager *manager = calloc(1, sizeof(*manager));
|
||||||
if (!manager) {
|
if (!manager) {
|
||||||
wlr_log(L_ERROR, "Failed to allocated wlr_data_device_manager");
|
wlr_log(L_ERROR, "Failed to allocated wlr_data_device_manager");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
manager->global = wl_global_create(dpy, &wl_data_device_manager_interface, 3,
|
manager->global =
|
||||||
manager, data_device_manager_bind);
|
wl_global_create(display, &wl_data_device_manager_interface, 3, manager,
|
||||||
|
data_device_manager_bind);
|
||||||
|
|
||||||
if (!manager->global) {
|
if (!manager->global) {
|
||||||
wlr_log(L_ERROR, "Failed to create global for wlr_data_device_manager");
|
wlr_log(L_ERROR, "Failed to create global for wlr_data_device_manager");
|
||||||
free(manager);
|
free(manager);
|
||||||
|
@ -165,6 +180,10 @@ void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager) {
|
||||||
|
|
||||||
void wlr_data_device_set_selection(struct wlr_data_device *device,
|
void wlr_data_device_set_selection(struct wlr_data_device *device,
|
||||||
struct wlr_data_source *source) {
|
struct wlr_data_source *source) {
|
||||||
|
if (device->selection == source) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (device->selection) {
|
if (device->selection) {
|
||||||
wl_list_remove(&device->selection_destroyed.link);
|
wl_list_remove(&device->selection_destroyed.link);
|
||||||
wlr_data_source_cancelled(device->selection);
|
wlr_data_source_cancelled(device->selection);
|
||||||
|
|
|
@ -27,7 +27,8 @@ void wlr_data_source_finish(struct wlr_data_source *source) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_data_source_send(struct wlr_data_source *src, const char *type, int fd) {
|
void wlr_data_source_send(struct wlr_data_source *src, const char *type,
|
||||||
|
int fd) {
|
||||||
assert(src && src->impl && src->impl->send);
|
assert(src && src->impl && src->impl->send);
|
||||||
src->impl->send(src, type, fd);
|
src->impl->send(src, type, fd);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,8 @@ static void data_source_send(struct wlr_data_source *src,
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void data_source_accepted(struct wlr_data_source *src, const char *type) {
|
static void data_source_accepted(struct wlr_data_source *src,
|
||||||
|
const char *type) {
|
||||||
struct wlr_wl_data_source *wl_src = (struct wlr_wl_data_source *) src;
|
struct wlr_wl_data_source *wl_src = (struct wlr_wl_data_source *) src;
|
||||||
wl_data_source_send_target(wl_src->resource, type);
|
wl_data_source_send_target(wl_src->resource, type);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +71,8 @@ static struct wlr_data_source_impl data_source_wl_impl = {
|
||||||
.cancelled = data_source_cancelled,
|
.cancelled = data_source_cancelled,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void data_source_offer(struct wl_client *client, struct wl_resource *resource,
|
static void data_source_offer(struct wl_client *client,
|
||||||
|
struct wl_resource *resource,
|
||||||
const char *type) {
|
const char *type) {
|
||||||
struct wlr_wl_data_source *src = wl_resource_get_user_data(resource);
|
struct wlr_wl_data_source *src = wl_resource_get_user_data(resource);
|
||||||
char *dtype = strdup(type);
|
char *dtype = strdup(type);
|
||||||
|
@ -81,13 +84,20 @@ static void data_source_offer(struct wl_client *client, struct wl_resource *reso
|
||||||
list_add(src->base.types, dtype);
|
list_add(src->base.types, dtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void data_source_destroy(struct wl_client *client, struct wl_resource *resource) {
|
static void data_source_destroy(struct wl_client *client,
|
||||||
|
struct wl_resource *resource) {
|
||||||
wl_resource_destroy(resource);
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void data_source_set_actions(struct wl_client *client,
|
||||||
|
struct wl_resource *resource, uint32_t dnd_actions) {
|
||||||
|
wlr_log(L_DEBUG, "TODO: data source set actions");
|
||||||
|
}
|
||||||
|
|
||||||
static struct wl_data_source_interface wl_data_source_impl = {
|
static struct wl_data_source_interface wl_data_source_impl = {
|
||||||
.offer = data_source_offer,
|
.offer = data_source_offer,
|
||||||
.destroy = data_source_destroy
|
.destroy = data_source_destroy,
|
||||||
|
.set_actions = data_source_set_actions,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void destroy_wl_data_source(struct wl_resource *resource) {
|
static void destroy_wl_data_source(struct wl_resource *resource) {
|
||||||
|
|
Loading…
Reference in a new issue