mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
data-device: add wlr_data_offer.type
This commit is contained in:
parent
3f82eb1853
commit
909b3b16f3
6 changed files with 23 additions and 7 deletions
|
@ -17,7 +17,7 @@ struct wlr_client_data_source {
|
|||
extern const struct wlr_surface_role drag_icon_surface_role;
|
||||
|
||||
struct wlr_data_offer *data_offer_create(struct wl_resource *device_resource,
|
||||
struct wlr_data_source *source);
|
||||
struct wlr_data_source *source, enum wlr_data_offer_type type);
|
||||
void data_offer_update_action(struct wlr_data_offer *offer);
|
||||
void data_offer_destroy(struct wlr_data_offer *offer);
|
||||
|
||||
|
|
|
@ -35,9 +35,15 @@ struct wlr_data_device_manager {
|
|||
void *data;
|
||||
};
|
||||
|
||||
enum wlr_data_offer_type {
|
||||
WLR_DATA_OFFER_SELECTION,
|
||||
WLR_DATA_OFFER_DRAG,
|
||||
};
|
||||
|
||||
struct wlr_data_offer {
|
||||
struct wl_resource *resource;
|
||||
struct wlr_data_source *source;
|
||||
enum wlr_data_offer_type type;
|
||||
|
||||
uint32_t actions;
|
||||
enum wl_data_device_manager_dnd_action preferred_action;
|
||||
|
|
|
@ -107,8 +107,8 @@ static void device_resource_send_selection(struct wl_resource *device_resource)
|
|||
|
||||
struct wlr_data_source *source = seat_client->seat->selection_source;
|
||||
if (source != NULL) {
|
||||
struct wlr_data_offer *offer =
|
||||
data_offer_create(device_resource, source);
|
||||
struct wlr_data_offer *offer = data_offer_create(device_resource,
|
||||
source, WLR_DATA_OFFER_SELECTION);
|
||||
if (offer == NULL) {
|
||||
wl_client_post_no_memory(seat_client->client);
|
||||
return;
|
||||
|
|
|
@ -55,6 +55,8 @@ static uint32_t data_offer_choose_action(struct wlr_data_offer *offer) {
|
|||
}
|
||||
|
||||
void data_offer_update_action(struct wlr_data_offer *offer) {
|
||||
assert(offer->type == WLR_DATA_OFFER_DRAG);
|
||||
|
||||
uint32_t action = data_offer_choose_action(offer);
|
||||
if (offer->source->current_dnd_action == action) {
|
||||
return;
|
||||
|
@ -160,6 +162,13 @@ static void data_offer_handle_set_actions(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
|
||||
if (offer->type != WLR_DATA_OFFER_DRAG) {
|
||||
wl_resource_post_error(offer->resource,
|
||||
WL_DATA_OFFER_ERROR_INVALID_OFFER,
|
||||
"set_action can only be sent to drag-and-drop offers");
|
||||
return;
|
||||
}
|
||||
|
||||
offer->actions = actions;
|
||||
offer->preferred_action = preferred_action;
|
||||
|
||||
|
@ -199,7 +208,7 @@ static void data_offer_handle_source_destroy(struct wl_listener *listener,
|
|||
}
|
||||
|
||||
struct wlr_data_offer *data_offer_create(struct wl_resource *device_resource,
|
||||
struct wlr_data_source *source) {
|
||||
struct wlr_data_source *source, enum wlr_data_offer_type type) {
|
||||
struct wlr_seat_client *seat_client =
|
||||
seat_client_from_data_device_resource(device_resource);
|
||||
assert(seat_client != NULL);
|
||||
|
@ -210,6 +219,7 @@ struct wlr_data_offer *data_offer_create(struct wl_resource *device_resource,
|
|||
return NULL;
|
||||
}
|
||||
offer->source = source;
|
||||
offer->type = type;
|
||||
|
||||
struct wl_client *client = wl_resource_get_client(device_resource);
|
||||
uint32_t version = wl_resource_get_version(device_resource);
|
||||
|
|
|
@ -186,7 +186,7 @@ static void data_source_offer(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
if (source->finalized) {
|
||||
wlr_log(WLR_DEBUG, "offering additional MIME type after "
|
||||
wlr_log(WLR_DEBUG, "Offering additional MIME type after "
|
||||
"wl_data_device.set_selection");
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,8 @@ static void drag_set_focus(struct wlr_drag *drag,
|
|||
|
||||
struct wl_resource *device_resource;
|
||||
wl_resource_for_each(device_resource, &focus_client->data_devices) {
|
||||
struct wlr_data_offer *offer =
|
||||
data_offer_create(device_resource, drag->source);
|
||||
struct wlr_data_offer *offer = data_offer_create(device_resource,
|
||||
drag->source, WLR_DATA_OFFER_DRAG);
|
||||
if (offer == NULL) {
|
||||
wl_resource_post_no_memory(device_resource);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue