diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-02-23 13:02:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-23 13:02:28 -0500 |
commit | e77e53dae51a3a46e1327c0c53e69d6da695cc9a (patch) | |
tree | 5ee7297caffaa4e36d1239224972a1d58c32cf0c /include | |
parent | 00b1b40b36f37fe6ff3ac8726026dde8e73f1979 (diff) | |
parent | d6de6404403679b42721e484609c31243447a6f3 (diff) |
Merge pull request #1517 from emersion/refactor-dnd
Refactor drag-and-drop
Diffstat (limited to 'include')
-rw-r--r-- | include/rootston/seat.h | 3 | ||||
-rw-r--r-- | include/types/wlr_data_device.h | 3 | ||||
-rw-r--r-- | include/wlr/types/wlr_data_device.h | 76 | ||||
-rw-r--r-- | include/wlr/types/wlr_seat.h | 31 |
4 files changed, 88 insertions, 25 deletions
diff --git a/include/rootston/seat.h b/include/rootston/seat.h index a91d8481..b91f9578 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -40,7 +40,8 @@ struct roots_seat { struct wl_listener request_set_selection; struct wl_listener request_set_primary_selection; - struct wl_listener new_drag_icon; + struct wl_listener request_start_drag; + struct wl_listener start_drag; struct wl_listener destroy; }; diff --git a/include/types/wlr_data_device.h b/include/types/wlr_data_device.h index 28073880..5865c999 100644 --- a/include/types/wlr_data_device.h +++ b/include/types/wlr_data_device.h @@ -30,9 +30,6 @@ void data_source_notify_finish(struct wlr_data_source *source); struct wlr_seat_client *seat_client_from_data_device_resource( struct wl_resource *resource); -bool seat_client_start_drag(struct wlr_seat_client *client, - struct wlr_data_source *source, struct wlr_surface *icon_surface, - struct wlr_surface *origin, uint32_t serial); /** * Creates a new wl_data_offer if there is a wl_data_source currently set as * the seat selection and sends it to the seat client, followed by the diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 59aa718f..256654e5 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -89,15 +89,13 @@ struct wlr_data_source { } events; }; +struct wlr_drag; + struct wlr_drag_icon { + struct wlr_drag *drag; struct wlr_surface *surface; - struct wlr_seat_client *client; - struct wl_list link; // wlr_seat::drag_icons bool mapped; - bool is_pointer; - int32_t touch_id; - struct { struct wl_signal map; struct wl_signal unmap; @@ -105,40 +103,46 @@ struct wlr_drag_icon { } events; struct wl_listener surface_destroy; - struct wl_listener seat_client_destroy; void *data; }; +enum wlr_drag_grab_type { + WLR_DRAG_GRAB_KEYBOARD, + WLR_DRAG_GRAB_KEYBOARD_POINTER, + WLR_DRAG_GRAB_KEYBOARD_TOUCH, +}; + struct wlr_drag { - struct wlr_seat_pointer_grab pointer_grab; + enum wlr_drag_grab_type grab_type; struct wlr_seat_keyboard_grab keyboard_grab; + struct wlr_seat_pointer_grab pointer_grab; struct wlr_seat_touch_grab touch_grab; struct wlr_seat *seat; struct wlr_seat_client *seat_client; struct wlr_seat_client *focus_client; - bool is_pointer_grab; + struct wlr_drag_icon *icon; // can be NULL + struct wlr_surface *focus; // can be NULL + struct wlr_data_source *source; // can be NULL - struct wlr_drag_icon *icon; - struct wlr_surface *focus; - struct wlr_data_source *source; + bool started, dropped, cancelling; + int32_t grab_touch_id, touch_id; // if WLR_DRAG_GRAB_TOUCH - bool cancelling; - int32_t grab_touch_id; + struct { + struct wl_signal focus; + struct wl_signal motion; // wlr_drag_motion_event + struct wl_signal drop; // wlr_drag_drop_event + struct wl_signal destroy; + } events; struct wl_listener point_destroy; struct wl_listener source_destroy; struct wl_listener seat_client_destroy; struct wl_listener icon_destroy; - struct { - struct wl_signal focus; - struct wl_signal motion; - struct wl_signal drop; - struct wl_signal destroy; - } events; + void *data; }; struct wlr_drag_motion_event { @@ -179,6 +183,40 @@ void wlr_seat_set_selection(struct wlr_seat *seat, struct wlr_data_source *source, uint32_t serial); /** + * Creates a new drag. To request to start the drag, call + * `wlr_seat_request_start_drag`. + */ +struct wlr_drag *wlr_drag_create(struct wlr_seat_client *seat_client, + struct wlr_data_source *source, struct wlr_surface *icon_surface); + +/** + * Requests a drag to be started on the seat. + */ +void wlr_seat_request_start_drag(struct wlr_seat *seat, struct wlr_drag *drag, + struct wlr_surface *origin, uint32_t serial); + +/** + * Starts a drag on the seat. This starts an implicit keyboard grab, but doesn't + * start a pointer or a touch grab. + */ +void wlr_seat_start_drag(struct wlr_seat *seat, struct wlr_drag *drag, + uint32_t serial); + +/** + * Starts a pointer drag on the seat. This starts implicit keyboard and pointer + * grabs. + */ +void wlr_seat_start_pointer_drag(struct wlr_seat *seat, struct wlr_drag *drag, + uint32_t serial); + +/** + * Starts a touch drag on the seat. This starts implicit keyboard and touch + * grabs. + */ +void wlr_seat_start_touch_drag(struct wlr_seat *seat, struct wlr_drag *drag, + uint32_t serial, struct wlr_touch_point *point); + +/** * Initializes the data source with the provided implementation. */ void wlr_data_source_init(struct wlr_data_source *source, diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index c81c2cec..c020dbdb 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -191,7 +191,6 @@ struct wlr_seat { struct wl_global *global; struct wl_display *display; struct wl_list clients; - struct wl_list drag_icons; // wlr_drag_icon::link char *name; uint32_t capabilities; @@ -239,8 +238,9 @@ struct wlr_seat { struct wl_signal request_set_primary_selection; struct wl_signal set_primary_selection; + // wlr_seat_request_start_drag_event + struct wl_signal request_start_drag; struct wl_signal start_drag; // wlr_drag - struct wl_signal new_drag_icon; // wlr_drag_icon struct wl_signal destroy; } events; @@ -265,6 +265,12 @@ struct wlr_seat_request_set_primary_selection_event { uint32_t serial; }; +struct wlr_seat_request_start_drag_event { + struct wlr_drag *drag; + struct wlr_surface *origin; + uint32_t serial; +}; + struct wlr_seat_pointer_focus_change_event { struct wlr_seat *seat; struct wlr_surface *old_surface, *new_surface; @@ -597,9 +603,30 @@ bool wlr_seat_touch_has_grab(struct wlr_seat *seat); */ bool wlr_seat_validate_grab_serial(struct wlr_seat *seat, uint32_t serial); +/** + * Check whether this serial is valid to start a pointer grab action. + */ +bool wlr_seat_validate_pointer_grab_serial(struct wlr_seat *seat, + struct wlr_surface *origin, uint32_t serial); + +/** + * Check whether this serial is valid to start a touch grab action. If it's the + * case and point_ptr is non-NULL, *point_ptr is set to the touch point matching + * the serial. + */ +bool wlr_seat_validate_touch_grab_serial(struct wlr_seat *seat, + struct wlr_surface *origin, uint32_t serial, + struct wlr_touch_point **point_ptr); + +/** + * Get a seat client from a seat resource. Returns NULL if inert. + */ struct wlr_seat_client *wlr_seat_client_from_resource( struct wl_resource *resource); +/** + * Get a seat client from a pointer resource. Returns NULL if inert. + */ struct wlr_seat_client *wlr_seat_client_from_pointer_resource( struct wl_resource *resource); |