Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Kristian Høgsberg |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 5 | * documentation for any purpose is hereby granted without fee, provided that |
| 6 | * the above copyright notice appear in all copies and that both that copyright |
| 7 | * notice and this permission notice appear in supporting documentation, and |
| 8 | * that the name of the copyright holders not be used in advertising or |
| 9 | * publicity pertaining to distribution of the software without specific, |
| 10 | * written prior permission. The copyright holders make no representations |
| 11 | * about the suitability of this software for any purpose. It is provided "as |
| 12 | * is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 20 | * OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Daniel Stone | 8e7a8bd | 2013-08-15 01:10:24 +0100 | [diff] [blame] | 23 | #include "config.h" |
| 24 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <unistd.h> |
| 28 | #include <stdio.h> |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 29 | #include <assert.h> |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 30 | |
| 31 | #include "compositor.h" |
| 32 | |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 33 | struct weston_drag { |
| 34 | struct wl_client *client; |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 35 | struct weston_data_source *data_source; |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 36 | struct wl_listener data_source_listener; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 37 | struct weston_view *focus; |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 38 | struct wl_resource *focus_resource; |
| 39 | struct wl_listener focus_listener; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 40 | struct weston_view *icon; |
Kristian Høgsberg | c43aad1 | 2013-05-08 15:30:42 -0400 | [diff] [blame] | 41 | struct wl_listener icon_destroy_listener; |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 42 | int32_t dx, dy; |
| 43 | }; |
| 44 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 45 | struct weston_pointer_drag { |
| 46 | struct weston_drag base; |
| 47 | struct weston_pointer_grab grab; |
| 48 | }; |
| 49 | |
| 50 | struct weston_touch_drag { |
| 51 | struct weston_drag base; |
| 52 | struct weston_touch_grab grab; |
| 53 | }; |
| 54 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 55 | static void |
| 56 | data_offer_accept(struct wl_client *client, struct wl_resource *resource, |
| 57 | uint32_t serial, const char *mime_type) |
| 58 | { |
Kristian Høgsberg | 5e76a49 | 2013-07-25 16:09:37 -0700 | [diff] [blame] | 59 | struct weston_data_offer *offer = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 60 | |
| 61 | /* FIXME: Check that client is currently focused by the input |
| 62 | * device that is currently dragging this data source. Should |
| 63 | * this be a wl_data_device request? */ |
| 64 | |
| 65 | if (offer->source) |
| 66 | offer->source->accept(offer->source, serial, mime_type); |
| 67 | } |
| 68 | |
| 69 | static void |
| 70 | data_offer_receive(struct wl_client *client, struct wl_resource *resource, |
| 71 | const char *mime_type, int32_t fd) |
| 72 | { |
Kristian Høgsberg | 5e76a49 | 2013-07-25 16:09:37 -0700 | [diff] [blame] | 73 | struct weston_data_offer *offer = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 74 | |
| 75 | if (offer->source) |
| 76 | offer->source->send(offer->source, mime_type, fd); |
| 77 | else |
| 78 | close(fd); |
| 79 | } |
| 80 | |
| 81 | static void |
| 82 | data_offer_destroy(struct wl_client *client, struct wl_resource *resource) |
| 83 | { |
| 84 | wl_resource_destroy(resource); |
| 85 | } |
| 86 | |
| 87 | static const struct wl_data_offer_interface data_offer_interface = { |
| 88 | data_offer_accept, |
| 89 | data_offer_receive, |
| 90 | data_offer_destroy, |
| 91 | }; |
| 92 | |
| 93 | static void |
| 94 | destroy_data_offer(struct wl_resource *resource) |
| 95 | { |
Kristian Høgsberg | 5e76a49 | 2013-07-25 16:09:37 -0700 | [diff] [blame] | 96 | struct weston_data_offer *offer = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 97 | |
| 98 | if (offer->source) |
| 99 | wl_list_remove(&offer->source_destroy_listener.link); |
| 100 | free(offer); |
| 101 | } |
| 102 | |
| 103 | static void |
| 104 | destroy_offer_data_source(struct wl_listener *listener, void *data) |
| 105 | { |
Kristian Høgsberg | 5e76a49 | 2013-07-25 16:09:37 -0700 | [diff] [blame] | 106 | struct weston_data_offer *offer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 107 | |
Kristian Høgsberg | 5e76a49 | 2013-07-25 16:09:37 -0700 | [diff] [blame] | 108 | offer = container_of(listener, struct weston_data_offer, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 109 | source_destroy_listener); |
| 110 | |
| 111 | offer->source = NULL; |
| 112 | } |
| 113 | |
| 114 | static struct wl_resource * |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 115 | weston_data_source_send_offer(struct weston_data_source *source, |
| 116 | struct wl_resource *target) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 117 | { |
Kristian Høgsberg | 5e76a49 | 2013-07-25 16:09:37 -0700 | [diff] [blame] | 118 | struct weston_data_offer *offer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 119 | char **p; |
| 120 | |
| 121 | offer = malloc(sizeof *offer); |
| 122 | if (offer == NULL) |
| 123 | return NULL; |
| 124 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 125 | offer->resource = |
| 126 | wl_resource_create(wl_resource_get_client(target), |
| 127 | &wl_data_offer_interface, 1, 0); |
Kristian Høgsberg | 3c30f0f | 2013-08-06 10:24:04 -0700 | [diff] [blame] | 128 | if (offer->resource == NULL) { |
| 129 | free(offer); |
| 130 | return NULL; |
| 131 | } |
| 132 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 133 | wl_resource_set_implementation(offer->resource, &data_offer_interface, |
| 134 | offer, destroy_data_offer); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 135 | |
| 136 | offer->source = source; |
| 137 | offer->source_destroy_listener.notify = destroy_offer_data_source; |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 138 | wl_signal_add(&source->destroy_signal, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 139 | &offer->source_destroy_listener); |
| 140 | |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 141 | wl_data_device_send_data_offer(target, offer->resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 142 | |
| 143 | wl_array_for_each(p, &source->mime_types) |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 144 | wl_data_offer_send_offer(offer->resource, *p); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 145 | |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 146 | return offer->resource; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void |
| 150 | data_source_offer(struct wl_client *client, |
| 151 | struct wl_resource *resource, |
| 152 | const char *type) |
| 153 | { |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 154 | struct weston_data_source *source = |
| 155 | wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 156 | char **p; |
| 157 | |
| 158 | p = wl_array_add(&source->mime_types, sizeof *p); |
| 159 | if (p) |
| 160 | *p = strdup(type); |
| 161 | if (!p || !*p) |
| 162 | wl_resource_post_no_memory(resource); |
| 163 | } |
| 164 | |
| 165 | static void |
| 166 | data_source_destroy(struct wl_client *client, struct wl_resource *resource) |
| 167 | { |
| 168 | wl_resource_destroy(resource); |
| 169 | } |
| 170 | |
| 171 | static struct wl_data_source_interface data_source_interface = { |
| 172 | data_source_offer, |
| 173 | data_source_destroy |
| 174 | }; |
| 175 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 176 | static void |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 177 | drag_surface_configure(struct weston_drag *drag, |
Jonas Ådahl | 767d891 | 2013-12-03 22:30:17 +0100 | [diff] [blame] | 178 | struct weston_pointer *pointer, |
| 179 | struct weston_touch *touch, |
| 180 | struct weston_surface *es, |
| 181 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 7848bb6 | 2013-05-07 11:18:46 -0400 | [diff] [blame] | 182 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 183 | struct weston_layer_entry *list; |
Kristian Høgsberg | aad8099 | 2013-05-07 22:53:43 -0400 | [diff] [blame] | 184 | float fx, fy; |
Kristian Høgsberg | 415f30c | 2013-05-07 22:42:28 -0400 | [diff] [blame] | 185 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 186 | assert((pointer != NULL && touch == NULL) || |
| 187 | (pointer == NULL && touch != NULL)); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 188 | |
Kristian Høgsberg | 415f30c | 2013-05-07 22:42:28 -0400 | [diff] [blame] | 189 | if (!weston_surface_is_mapped(es) && es->buffer_ref.buffer) { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 190 | if (pointer && pointer->sprite && |
| 191 | weston_view_is_mapped(pointer->sprite)) |
Kristian Høgsberg | 195b869 | 2013-05-08 15:02:05 -0400 | [diff] [blame] | 192 | list = &pointer->sprite->layer_link; |
Kristian Høgsberg | 415f30c | 2013-05-07 22:42:28 -0400 | [diff] [blame] | 193 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 194 | list = &es->compositor->cursor_layer.view_list; |
Kristian Høgsberg | 415f30c | 2013-05-07 22:42:28 -0400 | [diff] [blame] | 195 | |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 196 | weston_layer_entry_remove(&drag->icon->layer_link); |
| 197 | weston_layer_entry_insert(list, &drag->icon->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 198 | weston_view_update_transform(drag->icon); |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 199 | pixman_region32_clear(&es->pending.input); |
Kristian Høgsberg | 415f30c | 2013-05-07 22:42:28 -0400 | [diff] [blame] | 200 | } |
Kristian Høgsberg | 7848bb6 | 2013-05-07 11:18:46 -0400 | [diff] [blame] | 201 | |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 202 | drag->dx += sx; |
| 203 | drag->dy += sy; |
Kristian Høgsberg | aad8099 | 2013-05-07 22:53:43 -0400 | [diff] [blame] | 204 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 205 | /* init to 0 for avoiding a compile warning */ |
| 206 | fx = fy = 0; |
| 207 | if (pointer) { |
| 208 | fx = wl_fixed_to_double(pointer->x) + drag->dx; |
| 209 | fy = wl_fixed_to_double(pointer->y) + drag->dy; |
| 210 | } else if (touch) { |
| 211 | fx = wl_fixed_to_double(touch->grab_x) + drag->dx; |
| 212 | fy = wl_fixed_to_double(touch->grab_y) + drag->dy; |
| 213 | } |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 214 | weston_view_set_position(drag->icon, fx, fy); |
Kristian Høgsberg | 7848bb6 | 2013-05-07 11:18:46 -0400 | [diff] [blame] | 215 | } |
| 216 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 217 | static int |
| 218 | pointer_drag_surface_get_label(struct weston_surface *surface, |
| 219 | char *buf, size_t len) |
| 220 | { |
| 221 | return snprintf(buf, len, "pointer drag icon"); |
| 222 | } |
| 223 | |
Kristian Høgsberg | 7848bb6 | 2013-05-07 11:18:46 -0400 | [diff] [blame] | 224 | static void |
Jonas Ådahl | 767d891 | 2013-12-03 22:30:17 +0100 | [diff] [blame] | 225 | pointer_drag_surface_configure(struct weston_surface *es, |
| 226 | int32_t sx, int32_t sy) |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 227 | { |
| 228 | struct weston_pointer_drag *drag = es->configure_private; |
| 229 | struct weston_pointer *pointer = drag->grab.pointer; |
| 230 | |
| 231 | assert(es->configure == pointer_drag_surface_configure); |
| 232 | |
Jonas Ådahl | 767d891 | 2013-12-03 22:30:17 +0100 | [diff] [blame] | 233 | drag_surface_configure(&drag->base, pointer, NULL, es, sx, sy); |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 234 | } |
| 235 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 236 | static int |
| 237 | touch_drag_surface_get_label(struct weston_surface *surface, |
| 238 | char *buf, size_t len) |
| 239 | { |
| 240 | return snprintf(buf, len, "touch drag icon"); |
| 241 | } |
| 242 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 243 | static void |
Jonas Ådahl | 767d891 | 2013-12-03 22:30:17 +0100 | [diff] [blame] | 244 | touch_drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 245 | { |
| 246 | struct weston_touch_drag *drag = es->configure_private; |
| 247 | struct weston_touch *touch = drag->grab.touch; |
| 248 | |
| 249 | assert(es->configure == touch_drag_surface_configure); |
| 250 | |
Jonas Ådahl | 767d891 | 2013-12-03 22:30:17 +0100 | [diff] [blame] | 251 | drag_surface_configure(&drag->base, NULL, touch, es, sx, sy); |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static void |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 255 | destroy_drag_focus(struct wl_listener *listener, void *data) |
| 256 | { |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 257 | struct weston_drag *drag = |
| 258 | container_of(listener, struct weston_drag, focus_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 259 | |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 260 | drag->focus_resource = NULL; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static void |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 264 | weston_drag_set_focus(struct weston_drag *drag, |
| 265 | struct weston_seat *seat, |
| 266 | struct weston_view *view, |
| 267 | wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 268 | { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 269 | struct wl_resource *resource, *offer = NULL; |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 270 | struct wl_display *display = seat->compositor->wl_display; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 271 | uint32_t serial; |
| 272 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 273 | if (drag->focus && view && drag->focus->surface == view->surface) { |
| 274 | drag->focus = view; |
| 275 | return; |
| 276 | } |
| 277 | |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 278 | if (drag->focus_resource) { |
| 279 | wl_data_device_send_leave(drag->focus_resource); |
| 280 | wl_list_remove(&drag->focus_listener.link); |
| 281 | drag->focus_resource = NULL; |
| 282 | drag->focus = NULL; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 285 | if (!view || !view->surface->resource) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 286 | return; |
| 287 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 288 | if (!drag->data_source && |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 289 | wl_resource_get_client(view->surface->resource) != drag->client) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 290 | return; |
| 291 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 292 | resource = wl_resource_find_for_client(&seat->drag_resource_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 293 | wl_resource_get_client(view->surface->resource)); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 294 | if (!resource) |
| 295 | return; |
| 296 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 297 | serial = wl_display_next_serial(display); |
| 298 | |
Kristian Høgsberg | a34e2f2 | 2013-08-20 15:58:25 -0700 | [diff] [blame] | 299 | if (drag->data_source) { |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 300 | offer = weston_data_source_send_offer(drag->data_source, |
| 301 | resource); |
Kristian Høgsberg | a34e2f2 | 2013-08-20 15:58:25 -0700 | [diff] [blame] | 302 | if (offer == NULL) |
| 303 | return; |
| 304 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 305 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 306 | wl_data_device_send_enter(resource, serial, view->surface->resource, |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 307 | sx, sy, offer); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 308 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 309 | drag->focus = view; |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 310 | drag->focus_listener.notify = destroy_drag_focus; |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 311 | wl_resource_add_destroy_listener(resource, &drag->focus_listener); |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 312 | drag->focus_resource = resource; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 316 | drag_grab_focus(struct weston_pointer_grab *grab) |
| 317 | { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 318 | struct weston_pointer_drag *drag = |
| 319 | container_of(grab, struct weston_pointer_drag, grab); |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 320 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 321 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 322 | wl_fixed_t sx, sy; |
| 323 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 324 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 325 | pointer->x, pointer->y, |
| 326 | &sx, &sy); |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 327 | if (drag->base.focus != view) |
| 328 | weston_drag_set_focus(&drag->base, pointer->seat, view, sx, sy); |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 332 | drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 333 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 334 | { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 335 | struct weston_pointer_drag *drag = |
| 336 | container_of(grab, struct weston_pointer_drag, grab); |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 337 | struct weston_pointer *pointer = drag->grab.pointer; |
Kristian Høgsberg | aad8099 | 2013-05-07 22:53:43 -0400 | [diff] [blame] | 338 | float fx, fy; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 339 | wl_fixed_t sx, sy; |
Kristian Høgsberg | aad8099 | 2013-05-07 22:53:43 -0400 | [diff] [blame] | 340 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 341 | weston_pointer_move(pointer, x, y); |
| 342 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 343 | if (drag->base.icon) { |
| 344 | fx = wl_fixed_to_double(pointer->x) + drag->base.dx; |
| 345 | fy = wl_fixed_to_double(pointer->y) + drag->base.dy; |
| 346 | weston_view_set_position(drag->base.icon, fx, fy); |
| 347 | weston_view_schedule_repaint(drag->base.icon); |
Kristian Høgsberg | aad8099 | 2013-05-07 22:53:43 -0400 | [diff] [blame] | 348 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 349 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 350 | if (drag->base.focus_resource) { |
| 351 | weston_view_from_global_fixed(drag->base.focus, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 352 | pointer->x, pointer->y, |
| 353 | &sx, &sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 354 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 355 | wl_data_device_send_motion(drag->base.focus_resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 356 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static void |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 360 | data_device_end_drag_grab(struct weston_drag *drag, |
| 361 | struct weston_seat *seat) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 362 | { |
Kristian Høgsberg | 5a9fb35 | 2013-05-08 15:47:52 -0400 | [diff] [blame] | 363 | if (drag->icon) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 364 | if (weston_view_is_mapped(drag->icon)) |
| 365 | weston_view_unmap(drag->icon); |
Kristian Høgsberg | 5a9fb35 | 2013-05-08 15:47:52 -0400 | [diff] [blame] | 366 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 367 | drag->icon->surface->configure = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 368 | weston_surface_set_label_func(drag->icon->surface, NULL); |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 369 | pixman_region32_clear(&drag->icon->surface->pending.input); |
Kristian Høgsberg | 5a9fb35 | 2013-05-08 15:47:52 -0400 | [diff] [blame] | 370 | wl_list_remove(&drag->icon_destroy_listener.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 371 | weston_view_destroy(drag->icon); |
Kristian Høgsberg | 5a9fb35 | 2013-05-08 15:47:52 -0400 | [diff] [blame] | 372 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 373 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 374 | weston_drag_set_focus(drag, seat, NULL, 0, 0); |
| 375 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 376 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 377 | static void |
| 378 | data_device_end_pointer_drag_grab(struct weston_pointer_drag *drag) |
| 379 | { |
| 380 | struct weston_pointer *pointer = drag->grab.pointer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 381 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 382 | data_device_end_drag_grab(&drag->base, pointer->seat); |
| 383 | weston_pointer_end_grab(pointer); |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 384 | free(drag); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 388 | drag_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 389 | uint32_t time, uint32_t button, uint32_t state_w) |
| 390 | { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 391 | struct weston_pointer_drag *drag = |
| 392 | container_of(grab, struct weston_pointer_drag, grab); |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 393 | struct weston_pointer *pointer = drag->grab.pointer; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 394 | enum wl_pointer_button_state state = state_w; |
| 395 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 396 | if (drag->base.focus_resource && |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 397 | pointer->grab_button == button && |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 398 | state == WL_POINTER_BUTTON_STATE_RELEASED) |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 399 | wl_data_device_send_drop(drag->base.focus_resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 400 | |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 401 | if (pointer->button_count == 0 && |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 402 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 403 | if (drag->base.data_source) |
| 404 | wl_list_remove(&drag->base.data_source_listener.link); |
| 405 | data_device_end_pointer_drag_grab(drag); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 409 | static void |
| 410 | drag_grab_cancel(struct weston_pointer_grab *grab) |
| 411 | { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 412 | struct weston_pointer_drag *drag = |
| 413 | container_of(grab, struct weston_pointer_drag, grab); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 414 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 415 | if (drag->base.data_source) |
| 416 | wl_list_remove(&drag->base.data_source_listener.link); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 417 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 418 | data_device_end_pointer_drag_grab(drag); |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 419 | } |
| 420 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 421 | static const struct weston_pointer_grab_interface pointer_drag_grab_interface = { |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 422 | drag_grab_focus, |
| 423 | drag_grab_motion, |
| 424 | drag_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 425 | drag_grab_cancel, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 426 | }; |
| 427 | |
| 428 | static void |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 429 | drag_grab_touch_down(struct weston_touch_grab *grab, uint32_t time, |
| 430 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 431 | { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 432 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 433 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 434 | static void |
| 435 | data_device_end_touch_drag_grab(struct weston_touch_drag *drag) |
| 436 | { |
| 437 | struct weston_touch *touch = drag->grab.touch; |
| 438 | |
| 439 | data_device_end_drag_grab(&drag->base, touch->seat); |
| 440 | weston_touch_end_grab(touch); |
| 441 | free(drag); |
| 442 | } |
| 443 | |
| 444 | static void |
| 445 | drag_grab_touch_up(struct weston_touch_grab *grab, |
| 446 | uint32_t time, int touch_id) |
| 447 | { |
| 448 | struct weston_touch_drag *touch_drag = |
| 449 | container_of(grab, struct weston_touch_drag, grab); |
| 450 | struct weston_touch *touch = grab->touch; |
| 451 | |
| 452 | if (touch_id != touch->grab_touch_id) |
| 453 | return; |
| 454 | |
| 455 | if (touch_drag->base.focus_resource) |
| 456 | wl_data_device_send_drop(touch_drag->base.focus_resource); |
| 457 | if (touch_drag->base.data_source) |
| 458 | wl_list_remove(&touch_drag->base.data_source_listener.link); |
| 459 | data_device_end_touch_drag_grab(touch_drag); |
| 460 | } |
| 461 | |
| 462 | static void |
| 463 | drag_grab_touch_focus(struct weston_touch_drag *drag) |
| 464 | { |
| 465 | struct weston_touch *touch = drag->grab.touch; |
| 466 | struct weston_view *view; |
| 467 | wl_fixed_t view_x, view_y; |
| 468 | |
| 469 | view = weston_compositor_pick_view(touch->seat->compositor, |
| 470 | touch->grab_x, touch->grab_y, |
| 471 | &view_x, &view_y); |
| 472 | if (drag->base.focus != view) |
| 473 | weston_drag_set_focus(&drag->base, touch->seat, |
| 474 | view, view_x, view_y); |
| 475 | } |
| 476 | |
| 477 | static void |
| 478 | drag_grab_touch_motion(struct weston_touch_grab *grab, uint32_t time, |
| 479 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 480 | { |
| 481 | struct weston_touch_drag *touch_drag = |
| 482 | container_of(grab, struct weston_touch_drag, grab); |
| 483 | struct weston_touch *touch = grab->touch; |
| 484 | wl_fixed_t view_x, view_y; |
| 485 | float fx, fy; |
| 486 | |
| 487 | if (touch_id != touch->grab_touch_id) |
| 488 | return; |
| 489 | |
| 490 | drag_grab_touch_focus(touch_drag); |
| 491 | if (touch_drag->base.icon) { |
| 492 | fx = wl_fixed_to_double(touch->grab_x) + touch_drag->base.dx; |
| 493 | fy = wl_fixed_to_double(touch->grab_y) + touch_drag->base.dy; |
| 494 | weston_view_set_position(touch_drag->base.icon, fx, fy); |
| 495 | weston_view_schedule_repaint(touch_drag->base.icon); |
| 496 | } |
| 497 | |
| 498 | if (touch_drag->base.focus_resource) { |
| 499 | weston_view_from_global_fixed(touch_drag->base.focus, |
| 500 | touch->grab_x, touch->grab_y, |
| 501 | &view_x, &view_y); |
| 502 | wl_data_device_send_motion(touch_drag->base.focus_resource, time, |
| 503 | view_x, view_y); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | static void |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 508 | drag_grab_touch_frame(struct weston_touch_grab *grab) |
| 509 | { |
| 510 | } |
| 511 | |
| 512 | static void |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 513 | drag_grab_touch_cancel(struct weston_touch_grab *grab) |
| 514 | { |
| 515 | struct weston_touch_drag *touch_drag = |
| 516 | container_of(grab, struct weston_touch_drag, grab); |
| 517 | |
| 518 | if (touch_drag->base.data_source) |
| 519 | wl_list_remove(&touch_drag->base.data_source_listener.link); |
| 520 | data_device_end_touch_drag_grab(touch_drag); |
| 521 | } |
| 522 | |
| 523 | static const struct weston_touch_grab_interface touch_drag_grab_interface = { |
| 524 | drag_grab_touch_down, |
| 525 | drag_grab_touch_up, |
| 526 | drag_grab_touch_motion, |
Jonas Ådahl | 1679f23 | 2014-04-12 09:39:51 +0200 | [diff] [blame] | 527 | drag_grab_touch_frame, |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 528 | drag_grab_touch_cancel |
| 529 | }; |
| 530 | |
| 531 | static void |
| 532 | destroy_pointer_data_device_source(struct wl_listener *listener, void *data) |
| 533 | { |
| 534 | struct weston_pointer_drag *drag = container_of(listener, |
| 535 | struct weston_pointer_drag, base.data_source_listener); |
| 536 | |
| 537 | data_device_end_pointer_drag_grab(drag); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static void |
Kristian Høgsberg | c43aad1 | 2013-05-08 15:30:42 -0400 | [diff] [blame] | 541 | handle_drag_icon_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 7848bb6 | 2013-05-07 11:18:46 -0400 | [diff] [blame] | 542 | { |
Kristian Høgsberg | 054c50a | 2013-05-08 15:27:47 -0400 | [diff] [blame] | 543 | struct weston_drag *drag = container_of(listener, struct weston_drag, |
Kristian Høgsberg | c43aad1 | 2013-05-08 15:30:42 -0400 | [diff] [blame] | 544 | icon_destroy_listener); |
Kristian Høgsberg | 7848bb6 | 2013-05-07 11:18:46 -0400 | [diff] [blame] | 545 | |
Kristian Høgsberg | c43aad1 | 2013-05-08 15:30:42 -0400 | [diff] [blame] | 546 | drag->icon = NULL; |
Kristian Høgsberg | 7848bb6 | 2013-05-07 11:18:46 -0400 | [diff] [blame] | 547 | } |
| 548 | |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 549 | WL_EXPORT int |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 550 | weston_pointer_start_drag(struct weston_pointer *pointer, |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 551 | struct weston_data_source *source, |
| 552 | struct weston_surface *icon, |
| 553 | struct wl_client *client) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 554 | { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 555 | struct weston_pointer_drag *drag; |
Kristian Høgsberg | 5a9fb35 | 2013-05-08 15:47:52 -0400 | [diff] [blame] | 556 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 557 | drag = zalloc(sizeof *drag); |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 558 | if (drag == NULL) |
| 559 | return -1; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 560 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 561 | drag->grab.interface = &pointer_drag_grab_interface; |
| 562 | drag->base.client = client; |
| 563 | drag->base.data_source = source; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 564 | |
Kristian Høgsberg | 5a9fb35 | 2013-05-08 15:47:52 -0400 | [diff] [blame] | 565 | if (icon) { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 566 | drag->base.icon = weston_view_create(icon); |
| 567 | if (drag->base.icon == NULL) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 568 | free(drag); |
| 569 | return -1; |
| 570 | } |
| 571 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 572 | drag->base.icon_destroy_listener.notify = handle_drag_icon_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 573 | wl_signal_add(&icon->destroy_signal, |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 574 | &drag->base.icon_destroy_listener); |
Kristian Høgsberg | 5a9fb35 | 2013-05-08 15:47:52 -0400 | [diff] [blame] | 575 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 576 | icon->configure = pointer_drag_surface_configure; |
Kristian Høgsberg | 5a9fb35 | 2013-05-08 15:47:52 -0400 | [diff] [blame] | 577 | icon->configure_private = drag; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 578 | weston_surface_set_label_func(icon, |
| 579 | pointer_drag_surface_get_label); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 580 | } else { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 581 | drag->base.icon = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | if (source) { |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 585 | drag->base.data_source_listener.notify = destroy_pointer_data_device_source; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 586 | wl_signal_add(&source->destroy_signal, |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 587 | &drag->base.data_source_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 590 | weston_pointer_set_focus(pointer, NULL, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 591 | wl_fixed_from_int(0), wl_fixed_from_int(0)); |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 592 | weston_pointer_start_grab(pointer, &drag->grab); |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | static void |
| 598 | destroy_touch_data_device_source(struct wl_listener *listener, void *data) |
| 599 | { |
| 600 | struct weston_touch_drag *drag = container_of(listener, |
| 601 | struct weston_touch_drag, base.data_source_listener); |
| 602 | |
| 603 | data_device_end_touch_drag_grab(drag); |
| 604 | } |
| 605 | |
| 606 | WL_EXPORT int |
| 607 | weston_touch_start_drag(struct weston_touch *touch, |
| 608 | struct weston_data_source *source, |
| 609 | struct weston_surface *icon, |
| 610 | struct wl_client *client) |
| 611 | { |
| 612 | struct weston_touch_drag *drag; |
| 613 | |
| 614 | drag = zalloc(sizeof *drag); |
| 615 | if (drag == NULL) |
| 616 | return -1; |
| 617 | |
| 618 | drag->grab.interface = &touch_drag_grab_interface; |
| 619 | drag->base.client = client; |
| 620 | drag->base.data_source = source; |
| 621 | |
| 622 | if (icon) { |
| 623 | drag->base.icon = weston_view_create(icon); |
| 624 | if (drag->base.icon == NULL) { |
| 625 | free(drag); |
| 626 | return -1; |
| 627 | } |
| 628 | |
| 629 | drag->base.icon_destroy_listener.notify = handle_drag_icon_destroy; |
| 630 | wl_signal_add(&icon->destroy_signal, |
| 631 | &drag->base.icon_destroy_listener); |
| 632 | |
| 633 | icon->configure = touch_drag_surface_configure; |
| 634 | icon->configure_private = drag; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 635 | weston_surface_set_label_func(icon, |
| 636 | touch_drag_surface_get_label); |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 637 | } else { |
| 638 | drag->base.icon = NULL; |
| 639 | } |
| 640 | |
| 641 | if (source) { |
| 642 | drag->base.data_source_listener.notify = destroy_touch_data_device_source; |
| 643 | wl_signal_add(&source->destroy_signal, |
| 644 | &drag->base.data_source_listener); |
| 645 | } |
| 646 | |
| 647 | weston_touch_start_grab(touch, &drag->grab); |
| 648 | |
| 649 | drag_grab_touch_focus(drag); |
Kristian Høgsberg | 0abad07 | 2013-09-11 09:42:26 -0700 | [diff] [blame] | 650 | |
| 651 | return 0; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static void |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 655 | data_device_start_drag(struct wl_client *client, struct wl_resource *resource, |
| 656 | struct wl_resource *source_resource, |
| 657 | struct wl_resource *origin_resource, |
| 658 | struct wl_resource *icon_resource, uint32_t serial) |
| 659 | { |
| 660 | struct weston_seat *seat = wl_resource_get_user_data(resource); |
Jason Ekstrand | 8202d72 | 2014-06-24 21:19:24 -0700 | [diff] [blame] | 661 | struct weston_surface *origin = wl_resource_get_user_data(origin_resource); |
Kristian Høgsberg | 1702d4c | 2013-09-11 09:45:03 -0700 | [diff] [blame] | 662 | struct weston_data_source *source = NULL; |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 663 | struct weston_surface *icon = NULL; |
Jason Ekstrand | 8202d72 | 2014-06-24 21:19:24 -0700 | [diff] [blame] | 664 | int is_pointer_grab, is_touch_grab; |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 665 | int32_t ret = 0; |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 666 | |
Jason Ekstrand | 8202d72 | 2014-06-24 21:19:24 -0700 | [diff] [blame] | 667 | is_pointer_grab = seat->pointer && |
| 668 | seat->pointer->button_count == 1 && |
| 669 | seat->pointer->grab_serial == serial && |
| 670 | seat->pointer->focus && |
| 671 | seat->pointer->focus->surface == origin; |
| 672 | |
| 673 | is_touch_grab = seat->touch && |
| 674 | seat->touch->num_tp == 1 && |
| 675 | seat->touch->grab_serial == serial && |
| 676 | seat->touch->focus && |
| 677 | seat->touch->focus->surface == origin; |
| 678 | |
| 679 | if (!is_pointer_grab && !is_touch_grab) |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 680 | return; |
| 681 | |
| 682 | /* FIXME: Check that the data source type array isn't empty. */ |
| 683 | |
| 684 | if (source_resource) |
| 685 | source = wl_resource_get_user_data(source_resource); |
| 686 | if (icon_resource) |
| 687 | icon = wl_resource_get_user_data(icon_resource); |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 688 | |
| 689 | if (icon) { |
| 690 | if (weston_surface_set_role(icon, "wl_data_device-icon", |
| 691 | resource, |
| 692 | WL_DATA_DEVICE_ERROR_ROLE) < 0) |
| 693 | return; |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Jason Ekstrand | 8202d72 | 2014-06-24 21:19:24 -0700 | [diff] [blame] | 696 | if (is_pointer_grab) |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 697 | ret = weston_pointer_start_drag(seat->pointer, source, icon, client); |
Jason Ekstrand | 8202d72 | 2014-06-24 21:19:24 -0700 | [diff] [blame] | 698 | else if (is_touch_grab) |
Xiong Zhang | fd51e7b | 2013-11-25 18:42:49 +0800 | [diff] [blame] | 699 | ret = weston_touch_start_drag(seat->touch, source, icon, client); |
| 700 | |
| 701 | if (ret < 0) |
Kristian Høgsberg | 85de9c2 | 2013-09-04 20:44:26 -0700 | [diff] [blame] | 702 | wl_resource_post_no_memory(resource); |
| 703 | } |
| 704 | |
| 705 | static void |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 706 | destroy_selection_data_source(struct wl_listener *listener, void *data) |
| 707 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 708 | struct weston_seat *seat = container_of(listener, struct weston_seat, |
| 709 | selection_data_source_listener); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 710 | struct wl_resource *data_device; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 711 | struct weston_surface *focus = NULL; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 712 | |
| 713 | seat->selection_data_source = NULL; |
| 714 | |
| 715 | if (seat->keyboard) |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 716 | focus = seat->keyboard->focus; |
| 717 | if (focus && focus->resource) { |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 718 | data_device = wl_resource_find_for_client(&seat->drag_resource_list, |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 719 | wl_resource_get_client(focus->resource)); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 720 | if (data_device) |
| 721 | wl_data_device_send_selection(data_device, NULL); |
| 722 | } |
| 723 | |
| 724 | wl_signal_emit(&seat->selection_signal, seat); |
| 725 | } |
| 726 | |
Giulio Camuffo | dddf9e6 | 2015-05-01 12:59:35 +0300 | [diff] [blame^] | 727 | /** \brief Send the selection to the specified client |
| 728 | * |
| 729 | * This function creates a new wl_data_offer if there is a wl_data_source |
| 730 | * currently set as the selection and sends it to the specified client, |
| 731 | * followed by the wl_data_device.selection() event. |
| 732 | * If there is no current selection the wl_data_device.selection() event |
| 733 | * will carry a NULL wl_data_offer. |
| 734 | * |
| 735 | * If the client does not have a wl_data_device for the specified seat |
| 736 | * nothing will be done. |
| 737 | * |
| 738 | * \param seat The seat owning the wl_data_device used to send the events. |
| 739 | * \param client The client to which to send the selection. |
| 740 | */ |
| 741 | WL_EXPORT void |
| 742 | weston_seat_send_selection(struct weston_seat *seat, struct wl_client *client) |
| 743 | { |
| 744 | struct wl_resource *data_device, *offer; |
| 745 | |
| 746 | data_device = wl_resource_find_for_client(&seat->drag_resource_list, |
| 747 | client); |
| 748 | if (data_device && seat->selection_data_source) { |
| 749 | offer = weston_data_source_send_offer(seat->selection_data_source, |
| 750 | data_device); |
| 751 | wl_data_device_send_selection(data_device, offer); |
| 752 | } else if (data_device) { |
| 753 | wl_data_device_send_selection(data_device, NULL); |
| 754 | } |
| 755 | } |
| 756 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 757 | WL_EXPORT void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 758 | weston_seat_set_selection(struct weston_seat *seat, |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 759 | struct weston_data_source *source, uint32_t serial) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 760 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 761 | struct weston_surface *focus = NULL; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 762 | |
| 763 | if (seat->selection_data_source && |
| 764 | seat->selection_serial - serial < UINT32_MAX / 2) |
| 765 | return; |
| 766 | |
| 767 | if (seat->selection_data_source) { |
| 768 | seat->selection_data_source->cancel(seat->selection_data_source); |
| 769 | wl_list_remove(&seat->selection_data_source_listener.link); |
| 770 | seat->selection_data_source = NULL; |
| 771 | } |
| 772 | |
| 773 | seat->selection_data_source = source; |
| 774 | seat->selection_serial = serial; |
| 775 | |
| 776 | if (seat->keyboard) |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 777 | focus = seat->keyboard->focus; |
| 778 | if (focus && focus->resource) { |
Giulio Camuffo | dddf9e6 | 2015-05-01 12:59:35 +0300 | [diff] [blame^] | 779 | weston_seat_send_selection(seat, wl_resource_get_client(focus->resource)); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | wl_signal_emit(&seat->selection_signal, seat); |
| 783 | |
| 784 | if (source) { |
| 785 | seat->selection_data_source_listener.notify = |
| 786 | destroy_selection_data_source; |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 787 | wl_signal_add(&source->destroy_signal, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 788 | &seat->selection_data_source_listener); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | static void |
| 793 | data_device_set_selection(struct wl_client *client, |
| 794 | struct wl_resource *resource, |
| 795 | struct wl_resource *source_resource, uint32_t serial) |
| 796 | { |
| 797 | if (!source_resource) |
| 798 | return; |
| 799 | |
| 800 | /* FIXME: Store serial and check against incoming serial here. */ |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 801 | weston_seat_set_selection(wl_resource_get_user_data(resource), |
| 802 | wl_resource_get_user_data(source_resource), |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 803 | serial); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 804 | } |
kabeer khan | 3a510d8 | 2014-10-20 11:47:15 +0530 | [diff] [blame] | 805 | static void |
| 806 | data_device_release(struct wl_client *client, struct wl_resource *resource) |
| 807 | { |
| 808 | wl_resource_destroy(resource); |
| 809 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 810 | |
| 811 | static const struct wl_data_device_interface data_device_interface = { |
| 812 | data_device_start_drag, |
| 813 | data_device_set_selection, |
kabeer khan | 3a510d8 | 2014-10-20 11:47:15 +0530 | [diff] [blame] | 814 | data_device_release |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 815 | }; |
| 816 | |
| 817 | static void |
| 818 | destroy_data_source(struct wl_resource *resource) |
| 819 | { |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 820 | struct weston_data_source *source = |
| 821 | wl_resource_get_user_data(resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 822 | char **p; |
| 823 | |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 824 | wl_signal_emit(&source->destroy_signal, source); |
| 825 | |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 826 | wl_array_for_each(p, &source->mime_types) |
| 827 | free(*p); |
| 828 | |
| 829 | wl_array_release(&source->mime_types); |
| 830 | |
Kristian Høgsberg | 489b279 | 2013-06-25 11:26:31 -0400 | [diff] [blame] | 831 | free(source); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | static void |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 835 | client_source_accept(struct weston_data_source *source, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 836 | uint32_t time, const char *mime_type) |
| 837 | { |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 838 | wl_data_source_send_target(source->resource, mime_type); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | static void |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 842 | client_source_send(struct weston_data_source *source, |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 843 | const char *mime_type, int32_t fd) |
| 844 | { |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 845 | wl_data_source_send_send(source->resource, mime_type, fd); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 846 | close(fd); |
| 847 | } |
| 848 | |
| 849 | static void |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 850 | client_source_cancel(struct weston_data_source *source) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 851 | { |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 852 | wl_data_source_send_cancelled(source->resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | static void |
| 856 | create_data_source(struct wl_client *client, |
| 857 | struct wl_resource *resource, uint32_t id) |
| 858 | { |
Kristian Høgsberg | 7ff3bdb | 2013-07-25 15:52:14 -0700 | [diff] [blame] | 859 | struct weston_data_source *source; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 860 | |
| 861 | source = malloc(sizeof *source); |
| 862 | if (source == NULL) { |
| 863 | wl_resource_post_no_memory(resource); |
| 864 | return; |
| 865 | } |
| 866 | |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 867 | wl_signal_init(&source->destroy_signal); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 868 | source->accept = client_source_accept; |
| 869 | source->send = client_source_send; |
| 870 | source->cancel = client_source_cancel; |
| 871 | |
| 872 | wl_array_init(&source->mime_types); |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 873 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 874 | source->resource = |
| 875 | wl_resource_create(client, &wl_data_source_interface, 1, id); |
| 876 | wl_resource_set_implementation(source->resource, &data_source_interface, |
| 877 | source, destroy_data_source); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | static void unbind_data_device(struct wl_resource *resource) |
| 881 | { |
Jason Ekstrand | 8a4a9eb | 2013-06-14 10:07:55 -0500 | [diff] [blame] | 882 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | static void |
| 886 | get_data_device(struct wl_client *client, |
| 887 | struct wl_resource *manager_resource, |
| 888 | uint32_t id, struct wl_resource *seat_resource) |
| 889 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 890 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 891 | struct wl_resource *resource; |
| 892 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 893 | resource = wl_resource_create(client, |
kabeer khan | 3a510d8 | 2014-10-20 11:47:15 +0530 | [diff] [blame] | 894 | &wl_data_device_interface, |
| 895 | wl_resource_get_version(manager_resource), |
| 896 | id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 897 | if (resource == NULL) { |
| 898 | wl_resource_post_no_memory(manager_resource); |
| 899 | return; |
| 900 | } |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 901 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 902 | wl_list_insert(&seat->drag_resource_list, |
| 903 | wl_resource_get_link(resource)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 904 | wl_resource_set_implementation(resource, &data_device_interface, |
| 905 | seat, unbind_data_device); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | static const struct wl_data_device_manager_interface manager_interface = { |
| 909 | create_data_source, |
| 910 | get_data_device |
| 911 | }; |
| 912 | |
| 913 | static void |
| 914 | bind_manager(struct wl_client *client, |
| 915 | void *data, uint32_t version, uint32_t id) |
| 916 | { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 917 | struct wl_resource *resource; |
| 918 | |
kabeer khan | 3a510d8 | 2014-10-20 11:47:15 +0530 | [diff] [blame] | 919 | resource = wl_resource_create(client, |
| 920 | &wl_data_device_manager_interface, |
| 921 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 922 | if (resource == NULL) { |
| 923 | wl_client_post_no_memory(client); |
| 924 | return; |
| 925 | } |
| 926 | |
| 927 | wl_resource_set_implementation(resource, &manager_interface, |
| 928 | NULL, NULL); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | WL_EXPORT void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 932 | wl_data_device_set_keyboard_focus(struct weston_seat *seat) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 933 | { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 934 | struct weston_surface *focus; |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 935 | |
| 936 | if (!seat->keyboard) |
| 937 | return; |
| 938 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 939 | focus = seat->keyboard->focus; |
| 940 | if (!focus || !focus->resource) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 941 | return; |
| 942 | |
Giulio Camuffo | dddf9e6 | 2015-05-01 12:59:35 +0300 | [diff] [blame^] | 943 | weston_seat_send_selection(seat, wl_resource_get_client(focus->resource)); |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | WL_EXPORT int |
| 947 | wl_data_device_manager_init(struct wl_display *display) |
| 948 | { |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 949 | if (wl_global_create(display, |
kabeer khan | 3a510d8 | 2014-10-20 11:47:15 +0530 | [diff] [blame] | 950 | &wl_data_device_manager_interface, 2, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 951 | NULL, bind_manager) == NULL) |
Kristian Høgsberg | 2158a88 | 2013-04-18 15:07:39 -0400 | [diff] [blame] | 952 | return -1; |
| 953 | |
| 954 | return 0; |
| 955 | } |