mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05: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;
 | 
					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_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_update_action(struct wlr_data_offer *offer);
 | 
				
			||||||
void data_offer_destroy(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;
 | 
						void *data;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum wlr_data_offer_type {
 | 
				
			||||||
 | 
						WLR_DATA_OFFER_SELECTION,
 | 
				
			||||||
 | 
						WLR_DATA_OFFER_DRAG,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wlr_data_offer {
 | 
					struct wlr_data_offer {
 | 
				
			||||||
	struct wl_resource *resource;
 | 
						struct wl_resource *resource;
 | 
				
			||||||
	struct wlr_data_source *source;
 | 
						struct wlr_data_source *source;
 | 
				
			||||||
 | 
						enum wlr_data_offer_type type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint32_t actions;
 | 
						uint32_t actions;
 | 
				
			||||||
	enum wl_data_device_manager_dnd_action preferred_action;
 | 
						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;
 | 
						struct wlr_data_source *source = seat_client->seat->selection_source;
 | 
				
			||||||
	if (source != NULL) {
 | 
						if (source != NULL) {
 | 
				
			||||||
		struct wlr_data_offer *offer =
 | 
							struct wlr_data_offer *offer = data_offer_create(device_resource,
 | 
				
			||||||
			data_offer_create(device_resource, source);
 | 
								source, WLR_DATA_OFFER_SELECTION);
 | 
				
			||||||
		if (offer == NULL) {
 | 
							if (offer == NULL) {
 | 
				
			||||||
			wl_client_post_no_memory(seat_client->client);
 | 
								wl_client_post_no_memory(seat_client->client);
 | 
				
			||||||
			return;
 | 
								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) {
 | 
					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);
 | 
						uint32_t action = data_offer_choose_action(offer);
 | 
				
			||||||
	if (offer->source->current_dnd_action == action) {
 | 
						if (offer->source->current_dnd_action == action) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
| 
						 | 
					@ -160,6 +162,13 @@ static void data_offer_handle_set_actions(struct wl_client *client,
 | 
				
			||||||
		return;
 | 
							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->actions = actions;
 | 
				
			||||||
	offer->preferred_action = preferred_action;
 | 
						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_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 =
 | 
						struct wlr_seat_client *seat_client =
 | 
				
			||||||
		seat_client_from_data_device_resource(device_resource);
 | 
							seat_client_from_data_device_resource(device_resource);
 | 
				
			||||||
	assert(seat_client != NULL);
 | 
						assert(seat_client != NULL);
 | 
				
			||||||
| 
						 | 
					@ -210,6 +219,7 @@ struct wlr_data_offer *data_offer_create(struct wl_resource *device_resource,
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	offer->source = source;
 | 
						offer->source = source;
 | 
				
			||||||
 | 
						offer->type = type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wl_client *client = wl_resource_get_client(device_resource);
 | 
						struct wl_client *client = wl_resource_get_client(device_resource);
 | 
				
			||||||
	uint32_t version = wl_resource_get_version(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;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (source->finalized) {
 | 
						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");
 | 
								"wl_data_device.set_selection");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -61,8 +61,8 @@ static void drag_set_focus(struct wlr_drag *drag,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		struct wl_resource *device_resource;
 | 
							struct wl_resource *device_resource;
 | 
				
			||||||
		wl_resource_for_each(device_resource, &focus_client->data_devices) {
 | 
							wl_resource_for_each(device_resource, &focus_client->data_devices) {
 | 
				
			||||||
			struct wlr_data_offer *offer =
 | 
								struct wlr_data_offer *offer = data_offer_create(device_resource,
 | 
				
			||||||
				data_offer_create(device_resource, drag->source);
 | 
									drag->source, WLR_DATA_OFFER_DRAG);
 | 
				
			||||||
			if (offer == NULL) {
 | 
								if (offer == NULL) {
 | 
				
			||||||
				wl_resource_post_no_memory(device_resource);
 | 
									wl_resource_post_no_memory(device_resource);
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue