mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	Support multiple resources per seat client for data_device
This commit is contained in:
		
							parent
							
								
									4f0443a344
								
							
						
					
					
						commit
						8af6fbd7a0
					
				
					 3 changed files with 82 additions and 65 deletions
				
			
		| 
						 | 
					@ -20,8 +20,7 @@ struct wlr_seat_client {
 | 
				
			||||||
	struct wl_list pointers;
 | 
						struct wl_list pointers;
 | 
				
			||||||
	struct wl_list keyboards;
 | 
						struct wl_list keyboards;
 | 
				
			||||||
	struct wl_list touches;
 | 
						struct wl_list touches;
 | 
				
			||||||
 | 
						struct wl_list data_devices;
 | 
				
			||||||
	struct wl_resource *data_device;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct {
 | 
						struct {
 | 
				
			||||||
		struct wl_signal destroy;
 | 
							struct wl_signal destroy;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -231,28 +231,31 @@ static void handle_offer_source_destroyed(struct wl_listener *listener,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct wlr_data_offer *wlr_data_source_send_offer(
 | 
					static struct wlr_data_offer *wlr_data_source_send_offer(
 | 
				
			||||||
		struct wlr_data_source *source,
 | 
							struct wlr_data_source *source,
 | 
				
			||||||
		struct wl_resource *target) {
 | 
							struct wlr_seat_client *target) {
 | 
				
			||||||
	struct wlr_data_offer *offer = calloc(1, sizeof(struct wlr_data_offer));
 | 
						struct wlr_data_offer *offer = calloc(1, sizeof(struct wlr_data_offer));
 | 
				
			||||||
	if (offer == NULL) {
 | 
						if (offer == NULL || wl_list_empty(&target->data_devices)) {
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	offer->resource =
 | 
						uint32_t version = wl_resource_get_version(
 | 
				
			||||||
		wl_resource_create(wl_resource_get_client(target),
 | 
							wl_resource_from_link(target->data_devices.next));
 | 
				
			||||||
			&wl_data_offer_interface,
 | 
						offer->resource = wl_resource_create(target->client,
 | 
				
			||||||
			wl_resource_get_version(target), 0);
 | 
							&wl_data_offer_interface, version, 0);
 | 
				
			||||||
	if (offer->resource == NULL) {
 | 
						if (offer->resource == NULL) {
 | 
				
			||||||
		free(offer);
 | 
							free(offer);
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	wl_resource_set_implementation(offer->resource, &data_offer_impl, offer,
 | 
						wl_resource_set_implementation(offer->resource, &data_offer_impl, offer,
 | 
				
			||||||
		data_offer_resource_destroy);
 | 
							data_offer_resource_destroy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	offer->source_destroy.notify = handle_offer_source_destroyed;
 | 
						offer->source_destroy.notify = handle_offer_source_destroyed;
 | 
				
			||||||
	wl_signal_add(&source->events.destroy, &offer->source_destroy);
 | 
						wl_signal_add(&source->events.destroy, &offer->source_destroy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_data_device_send_data_offer(target, offer->resource);
 | 
						struct wl_resource *target_resource;
 | 
				
			||||||
 | 
						wl_resource_for_each(target_resource, &target->data_devices) {
 | 
				
			||||||
 | 
							wl_data_device_send_data_offer(target_resource, offer->resource);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	char **p;
 | 
						char **p;
 | 
				
			||||||
	wl_array_for_each(p, &source->mime_types) {
 | 
						wl_array_for_each(p, &source->mime_types) {
 | 
				
			||||||
		wl_data_offer_send_offer(offer->resource, *p);
 | 
							wl_data_offer_send_offer(offer->resource, *p);
 | 
				
			||||||
| 
						 | 
					@ -265,20 +268,20 @@ static struct wlr_data_offer *wlr_data_source_send_offer(
 | 
				
			||||||
	return offer;
 | 
						return offer;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) {
 | 
					void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) {
 | 
				
			||||||
	if (!seat_client->data_device) {
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (seat_client->seat->selection_source) {
 | 
						if (seat_client->seat->selection_source) {
 | 
				
			||||||
		struct wlr_data_offer *offer =
 | 
							struct wlr_data_offer *offer = wlr_data_source_send_offer(
 | 
				
			||||||
			wlr_data_source_send_offer(seat_client->seat->selection_source,
 | 
								seat_client->seat->selection_source, seat_client);
 | 
				
			||||||
				seat_client->data_device);
 | 
					
 | 
				
			||||||
		wl_data_device_send_selection(seat_client->data_device,
 | 
							struct wl_resource *resource;
 | 
				
			||||||
			offer->resource);
 | 
							wl_resource_for_each(resource, &seat_client->data_devices) {
 | 
				
			||||||
 | 
								wl_data_device_send_selection(resource, offer->resource);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		wl_data_device_send_selection(seat_client->data_device, NULL);
 | 
							struct wl_resource *resource;
 | 
				
			||||||
 | 
							wl_resource_for_each(resource, &seat_client->data_devices) {
 | 
				
			||||||
 | 
								wl_data_device_send_selection(resource, NULL);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -286,12 +289,13 @@ static void seat_client_selection_data_source_destroy(
 | 
				
			||||||
		struct wl_listener *listener, void *data) {
 | 
							struct wl_listener *listener, void *data) {
 | 
				
			||||||
	struct wlr_seat *seat =
 | 
						struct wlr_seat *seat =
 | 
				
			||||||
		wl_container_of(listener, seat, selection_data_source_destroy);
 | 
							wl_container_of(listener, seat, selection_data_source_destroy);
 | 
				
			||||||
 | 
						struct wlr_seat_client *seat_client = seat->keyboard_state.focused_client;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (seat->keyboard_state.focused_client &&
 | 
						if (seat_client && seat->keyboard_state.focused_surface) {
 | 
				
			||||||
			seat->keyboard_state.focused_surface &&
 | 
							struct wl_resource *resource;
 | 
				
			||||||
			seat->keyboard_state.focused_client->data_device) {
 | 
							wl_resource_for_each(resource, &seat_client->data_devices) {
 | 
				
			||||||
		wl_data_device_send_selection(
 | 
								wl_data_device_send_selection(resource, NULL);
 | 
				
			||||||
			seat->keyboard_state.focused_client->data_device, NULL);
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	seat->selection_source = NULL;
 | 
						seat->selection_source = NULL;
 | 
				
			||||||
| 
						 | 
					@ -367,9 +371,14 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (drag->focus_client && drag->focus_client->data_device) {
 | 
						if (drag->focus_client) {
 | 
				
			||||||
		wl_list_remove(&drag->seat_client_destroy.link);
 | 
							wl_list_remove(&drag->seat_client_destroy.link);
 | 
				
			||||||
		wl_data_device_send_leave(drag->focus_client->data_device);
 | 
					
 | 
				
			||||||
 | 
							struct wl_resource *resource;
 | 
				
			||||||
 | 
							wl_resource_for_each(resource, &drag->focus_client->data_devices) {
 | 
				
			||||||
 | 
								wl_data_device_send_leave(resource);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		drag->focus_client = NULL;
 | 
							drag->focus_client = NULL;
 | 
				
			||||||
		drag->focus = NULL;
 | 
							drag->focus = NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -395,15 +404,15 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
 | 
				
			||||||
		wlr_seat_client_for_wl_client(drag->seat_client->seat,
 | 
							wlr_seat_client_for_wl_client(drag->seat_client->seat,
 | 
				
			||||||
			wl_resource_get_client(surface->resource));
 | 
								wl_resource_get_client(surface->resource));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!focus_client || !focus_client->data_device) {
 | 
						if (!focus_client || wl_list_empty(&focus_client->data_devices)) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wl_resource *offer_resource = NULL;
 | 
						struct wl_resource *offer_resource = NULL;
 | 
				
			||||||
	if (drag->source) {
 | 
						if (drag->source) {
 | 
				
			||||||
		drag->source->accepted = false;
 | 
							drag->source->accepted = false;
 | 
				
			||||||
		struct wlr_data_offer *offer =
 | 
							struct wlr_data_offer *offer = wlr_data_source_send_offer(drag->source,
 | 
				
			||||||
			wlr_data_source_send_offer(drag->source, focus_client->data_device);
 | 
								focus_client);
 | 
				
			||||||
		if (offer == NULL) {
 | 
							if (offer == NULL) {
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -421,10 +430,11 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint32_t serial =
 | 
						uint32_t serial =
 | 
				
			||||||
		wl_display_next_serial(drag->seat_client->seat->display);
 | 
							wl_display_next_serial(drag->seat_client->seat->display);
 | 
				
			||||||
 | 
						struct wl_resource *resource;
 | 
				
			||||||
	wl_data_device_send_enter(focus_client->data_device, serial,
 | 
						wl_resource_for_each(resource, &focus_client->data_devices) {
 | 
				
			||||||
		surface->resource, wl_fixed_from_double(sx),
 | 
							wl_data_device_send_enter(resource, serial, surface->resource,
 | 
				
			||||||
		wl_fixed_from_double(sy), offer_resource);
 | 
								wl_fixed_from_double(sx), wl_fixed_from_double(sy), offer_resource);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	drag->focus = surface;
 | 
						drag->focus = surface;
 | 
				
			||||||
	drag->focus_client = focus_client;
 | 
						drag->focus_client = focus_client;
 | 
				
			||||||
| 
						 | 
					@ -467,9 +477,12 @@ static void pointer_drag_enter(struct wlr_seat_pointer_grab *grab,
 | 
				
			||||||
static void pointer_drag_motion(struct wlr_seat_pointer_grab *grab,
 | 
					static void pointer_drag_motion(struct wlr_seat_pointer_grab *grab,
 | 
				
			||||||
		uint32_t time, double sx, double sy) {
 | 
							uint32_t time, double sx, double sy) {
 | 
				
			||||||
	struct wlr_drag *drag = grab->data;
 | 
						struct wlr_drag *drag = grab->data;
 | 
				
			||||||
	if (drag->focus && drag->focus_client && drag->focus_client->data_device) {
 | 
						if (drag->focus  != NULL&& drag->focus_client != NULL) {
 | 
				
			||||||
		wl_data_device_send_motion(drag->focus_client->data_device, time,
 | 
							struct wl_resource *resource;
 | 
				
			||||||
			wl_fixed_from_double(sx), wl_fixed_from_double(sy));
 | 
							wl_resource_for_each(resource, &drag->focus_client->data_devices) {
 | 
				
			||||||
 | 
								wl_data_device_send_motion(resource, time, wl_fixed_from_double(sx),
 | 
				
			||||||
 | 
									wl_fixed_from_double(sy));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -480,10 +493,12 @@ static uint32_t pointer_drag_button(struct wlr_seat_pointer_grab *grab,
 | 
				
			||||||
	if (drag->source &&
 | 
						if (drag->source &&
 | 
				
			||||||
			grab->seat->pointer_state.grab_button == button &&
 | 
								grab->seat->pointer_state.grab_button == button &&
 | 
				
			||||||
			state == WL_POINTER_BUTTON_STATE_RELEASED) {
 | 
								state == WL_POINTER_BUTTON_STATE_RELEASED) {
 | 
				
			||||||
		if (drag->focus_client && drag->focus_client->data_device &&
 | 
							if (drag->focus_client && drag->source->current_dnd_action &&
 | 
				
			||||||
				drag->source->current_dnd_action &&
 | 
					 | 
				
			||||||
				drag->source->accepted) {
 | 
									drag->source->accepted) {
 | 
				
			||||||
			wl_data_device_send_drop(drag->focus_client->data_device);
 | 
								struct wl_resource *resource;
 | 
				
			||||||
 | 
								wl_resource_for_each(resource, &drag->focus_client->data_devices) {
 | 
				
			||||||
 | 
									wl_data_device_send_drop(resource);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			if (wl_resource_get_version(drag->source->resource) >=
 | 
								if (wl_resource_get_version(drag->source->resource) >=
 | 
				
			||||||
					WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION) {
 | 
										WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION) {
 | 
				
			||||||
				wl_data_source_send_dnd_drop_performed(
 | 
									wl_data_source_send_dnd_drop_performed(
 | 
				
			||||||
| 
						 | 
					@ -538,8 +553,11 @@ static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time,
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (drag->focus_client && drag->focus_client->data_device) {
 | 
						if (drag->focus_client) {
 | 
				
			||||||
		wl_data_device_send_drop(drag->focus_client->data_device);
 | 
							struct wl_resource *resource;
 | 
				
			||||||
 | 
							wl_resource_for_each(resource, &drag->focus_client->data_devices) {
 | 
				
			||||||
 | 
								wl_data_device_send_drop(resource);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlr_drag_end(drag);
 | 
						wlr_drag_end(drag);
 | 
				
			||||||
| 
						 | 
					@ -548,9 +566,13 @@ static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time,
 | 
				
			||||||
static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time,
 | 
					static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time,
 | 
				
			||||||
		struct wlr_touch_point *point) {
 | 
							struct wlr_touch_point *point) {
 | 
				
			||||||
	struct wlr_drag *drag = grab->data;
 | 
						struct wlr_drag *drag = grab->data;
 | 
				
			||||||
	if (drag->focus && drag->focus_client && drag->focus_client->data_device) {
 | 
						if (drag->focus && drag->focus_client) {
 | 
				
			||||||
		wl_data_device_send_motion(drag->focus_client->data_device, time,
 | 
							struct wl_resource *resource;
 | 
				
			||||||
			wl_fixed_from_double(point->sx), wl_fixed_from_double(point->sy));
 | 
							wl_resource_for_each(resource, &drag->focus_client->data_devices) {
 | 
				
			||||||
 | 
								wl_data_device_send_motion(resource, time,
 | 
				
			||||||
 | 
									wl_fixed_from_double(point->sx),
 | 
				
			||||||
 | 
									wl_fixed_from_double(point->sy));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -800,31 +822,26 @@ static const struct wl_data_device_interface data_device_impl = {
 | 
				
			||||||
	.release = data_device_release,
 | 
						.release = data_device_release,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void data_device_destroy(struct wl_resource *resource) {
 | 
				
			||||||
 | 
						wl_list_remove(wl_resource_get_link(resource));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void data_device_manager_get_data_device(struct wl_client *client,
 | 
					void data_device_manager_get_data_device(struct wl_client *client,
 | 
				
			||||||
		struct wl_resource *manager_resource, uint32_t id,
 | 
							struct wl_resource *manager_resource, uint32_t id,
 | 
				
			||||||
		struct wl_resource *seat_resource) {
 | 
							struct wl_resource *seat_resource) {
 | 
				
			||||||
	struct wlr_seat_client *seat_client =
 | 
						struct wlr_seat_client *seat_client =
 | 
				
			||||||
		wl_resource_get_user_data(seat_resource);
 | 
							wl_resource_get_user_data(seat_resource);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wl_resource *resource =
 | 
						struct wl_resource *resource = wl_resource_create(client,
 | 
				
			||||||
		wl_resource_create(client,
 | 
							&wl_data_device_interface, wl_resource_get_version(manager_resource),
 | 
				
			||||||
			&wl_data_device_interface,
 | 
							id);
 | 
				
			||||||
			wl_resource_get_version(manager_resource), id);
 | 
					 | 
				
			||||||
	if (resource == NULL) {
 | 
						if (resource == NULL) {
 | 
				
			||||||
		wl_resource_post_no_memory(manager_resource);
 | 
							wl_resource_post_no_memory(manager_resource);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						wl_resource_set_implementation(resource, &data_device_impl, seat_client,
 | 
				
			||||||
	if (seat_client->data_device != NULL) {
 | 
							&data_device_destroy);
 | 
				
			||||||
		// XXX this is probably a protocol violation, but it simplfies our code
 | 
						wl_list_insert(&seat_client->data_devices, wl_resource_get_link(resource));
 | 
				
			||||||
		// and it's stupid to create several data devices for the same seat.
 | 
					 | 
				
			||||||
		wl_resource_destroy(seat_client->data_device);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	seat_client->data_device = resource;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	wl_resource_set_implementation(resource, &data_device_impl,
 | 
					 | 
				
			||||||
		seat_client, NULL);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void data_source_resource_destroy(struct wl_resource *resource) {
 | 
					static void data_source_resource_destroy(struct wl_resource *resource) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -195,10 +195,10 @@ static void wlr_seat_client_resource_destroy(struct wl_resource *seat_resource)
 | 
				
			||||||
	wl_resource_for_each_safe(resource, tmp, &client->touches) {
 | 
						wl_resource_for_each_safe(resource, tmp, &client->touches) {
 | 
				
			||||||
		wl_resource_destroy(resource);
 | 
							wl_resource_destroy(resource);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						wl_resource_for_each_safe(resource, tmp, &client->data_devices) {
 | 
				
			||||||
	if (client->data_device) {
 | 
							wl_resource_destroy(resource);
 | 
				
			||||||
		wl_resource_destroy(client->data_device);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_remove(&client->link);
 | 
						wl_list_remove(&client->link);
 | 
				
			||||||
	free(client);
 | 
						free(client);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -233,6 +233,7 @@ static void wl_seat_bind(struct wl_client *client, void *_wlr_seat,
 | 
				
			||||||
	wl_list_init(&seat_client->pointers);
 | 
						wl_list_init(&seat_client->pointers);
 | 
				
			||||||
	wl_list_init(&seat_client->keyboards);
 | 
						wl_list_init(&seat_client->keyboards);
 | 
				
			||||||
	wl_list_init(&seat_client->touches);
 | 
						wl_list_init(&seat_client->touches);
 | 
				
			||||||
 | 
						wl_list_init(&seat_client->data_devices);
 | 
				
			||||||
	wl_resource_set_implementation(seat_client->wl_resource, &wl_seat_impl,
 | 
						wl_resource_set_implementation(seat_client->wl_resource, &wl_seat_impl,
 | 
				
			||||||
		seat_client, wlr_seat_client_resource_destroy);
 | 
							seat_client, wlr_seat_client_resource_destroy);
 | 
				
			||||||
	wl_list_insert(&wlr_seat->clients, &seat_client->link);
 | 
						wl_list_insert(&wlr_seat->clients, &seat_client->link);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue