data-device, primary-selection: add request_set_selection

This makes compositors able to block and/or customize set_selection requests
coming from clients. For instance, it's possible for a compositor to disable
rich selection content (by removing all MIME types except text/plain). This
commit implements the design proposed in [1].

Two new events are added to wlr_seat: request_set_selection and
request_set_primary_selection. Compositors need to listen to these events and
either destroy the source or effectively set the selection.

Fixes https://github.com/swaywm/wlroots/issues/1138

[1]: https://github.com/swaywm/wlroots/issues/1367#issuecomment-442403454
This commit is contained in:
emersion 2018-11-29 19:30:04 +01:00
parent c41d01306d
commit 4cb0697e57
15 changed files with 142 additions and 63 deletions

View file

@ -38,6 +38,8 @@ struct roots_seat {
struct wl_list tablets;
struct wl_list tablet_pads;
struct wl_listener request_set_selection;
struct wl_listener request_set_primary_selection;
struct wl_listener new_drag_icon;
struct wl_listener destroy;
};

View file

@ -34,7 +34,7 @@ struct wlr_data_control_device_v1 {
struct wl_resource *selection_offer_resource; // current selection offer
struct wl_listener seat_destroy;
struct wl_listener seat_selection;
struct wl_listener seat_set_selection;
};
struct wlr_data_control_manager_v1 *wlr_data_control_manager_v1_create(

View file

@ -165,6 +165,12 @@ void wlr_data_device_manager_destroy(struct wlr_data_device_manager *manager);
*/
void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client);
/**
* Requests a selection to be set for the seat.
*/
void wlr_seat_request_set_selection(struct wlr_seat *seat,
struct wlr_data_source *source, uint32_t serial);
/**
* Sets the current selection for the seat. NULL can be provided to clear it.
* This removes the previous one if there was any. In case the selection doesn't

View file

@ -39,7 +39,7 @@ struct wlr_gtk_primary_selection_device {
struct wl_listener seat_destroy;
struct wl_listener seat_focus_change;
struct wl_listener seat_primary_selection;
struct wl_listener seat_set_primary_selection;
void *data;
};

View file

@ -48,6 +48,8 @@ void wlr_primary_selection_source_send(
struct wlr_primary_selection_source *source, const char *mime_type,
int fd);
void wlr_seat_request_set_primary_selection(struct wlr_seat *seat,
struct wlr_primary_selection_source *source, uint32_t serial);
/**
* Sets the current primary selection for the seat. NULL can be provided to
* clear it. This removes the previous one if there was any. In case the

View file

@ -23,6 +23,7 @@
struct wlr_seat_client {
struct wl_client *client;
struct wlr_seat *seat;
struct wl_list link;
// lists of wl_resource
struct wl_list resources;
@ -34,8 +35,6 @@ struct wlr_seat_client {
struct {
struct wl_signal destroy;
} events;
struct wl_list link;
};
struct wlr_touch_point {
@ -226,13 +225,18 @@ struct wlr_seat {
struct wl_signal touch_grab_begin;
struct wl_signal touch_grab_end;
// wlr_seat_pointer_request_set_cursor_event
struct wl_signal request_set_cursor;
struct wl_signal selection;
struct wl_signal primary_selection;
// wlr_seat_request_set_selection_event
struct wl_signal request_set_selection;
struct wl_signal set_selection;
// wlr_seat_request_set_primary_selection_event
struct wl_signal request_set_primary_selection;
struct wl_signal set_primary_selection;
struct wl_signal start_drag;
struct wl_signal new_drag_icon;
struct wl_signal start_drag; // wlr_drag
struct wl_signal new_drag_icon; // wlr_drag_icon
struct wl_signal destroy;
} events;
@ -247,6 +251,16 @@ struct wlr_seat_pointer_request_set_cursor_event {
int32_t hotspot_x, hotspot_y;
};
struct wlr_seat_request_set_selection_event {
struct wlr_data_source *source;
uint32_t serial;
};
struct wlr_seat_request_set_primary_selection_event {
struct wlr_primary_selection_source *source;
uint32_t serial;
};
struct wlr_seat_pointer_focus_change_event {
struct wlr_seat *seat;
struct wlr_surface *old_surface, *new_surface;

View file

@ -128,8 +128,8 @@ struct wlr_xwm {
struct wl_listener compositor_new_surface;
struct wl_listener compositor_destroy;
struct wl_listener seat_selection;
struct wl_listener seat_primary_selection;
struct wl_listener seat_set_selection;
struct wl_listener seat_set_primary_selection;
struct wl_listener seat_start_drag;
struct wl_listener seat_drag_focus;
struct wl_listener seat_drag_motion;