meta-agl-profile-telematics: recipes-core: systemd: change canbus systemd match regex
[AGL/meta-agl.git] / meta-agl-bsp / meta-ti / recipes-arago / gstreamer / gstreamer1.0-plugins-bad / 0001-gstwaylandsink-Add-mouse-drag-and-drop-support.patch
1 From 79db7e4cab226515f0e4d40afdb5a5b478755396 Mon Sep 17 00:00:00 2001
2 From: Pooja Prajod <a0132412@ti.com>
3 Date: Wed, 14 Sep 2016 16:03:17 -0400
4 Subject: [PATCH] gstwaylandsink: Add mouse drag and drop support
5
6 This patch adds mouse input listeners to WlDisplay instance.
7
8 Signed-off-by: Pooja Prajod <a0132412@ti.com>
9 Signed-off-by: Eric Ruei <e-ruei1@ti.com>
10 ---
11  ext/wayland/wldisplay.c | 305 +++++++++++++++++++++++++++++++++++++++++++++++-
12  ext/wayland/wldisplay.h |   4 +
13  ext/wayland/wlwindow.c  |   2 +
14  3 files changed, 310 insertions(+), 1 deletion(-)
15
16 diff --git a/ext/wayland/wldisplay.c b/ext/wayland/wldisplay.c
17 index 8c5eeaf..c647f34 100644
18 --- a/ext/wayland/wldisplay.c
19 +++ b/ext/wayland/wldisplay.c
20 @@ -21,18 +21,45 @@
21  #ifdef HAVE_CONFIG_H
22  #include <config.h>
23  #endif
24 -
25 +#include <stdlib.h>
26 +#include <stdio.h>
27  #include "wldisplay.h"
28  #include "wlbuffer.h"
29 +#include "wlwindow.h"
30 +
31 +#include <wayland-client-protocol.h>
32  
33 +#include <unistd.h>
34  #include <errno.h>
35 +#include <linux/input.h>
36  
37  GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
38  #define GST_CAT_DEFAULT gstwayland_debug
39  
40  G_DEFINE_TYPE (GstWlDisplay, gst_wl_display, G_TYPE_OBJECT);
41  
42 +struct touch_point
43 +{
44 +  int32_t id;
45 +  struct wl_list link;
46 +};
47 +
48 +struct input
49 +{
50 +  GstWlDisplay *display;
51 +  struct wl_seat *seat;
52 +  struct wl_pointer *pointer;
53 +  struct wl_touch *touch;
54 +  struct wl_list touch_point_list;
55 +  GstWlWindow *pointer_focus;
56 +  GstWlWindow *touch_focus;
57 +  struct wl_list link;
58 +  GstWlWindow *grab;
59 +};
60 +
61  static void gst_wl_display_finalize (GObject * gobject);
62 +static void input_grab (struct input *input, GstWlWindow *window);
63 +static void input_ungrab (struct input *input);
64  
65  static void
66  gst_wl_display_class_init (GstWlDisplayClass * klass)
67 @@ -51,6 +78,54 @@ gst_wl_display_init (GstWlDisplay * self)
68  }
69  
70  static void
71 +input_grab (struct input *input, GstWlWindow *window)
72 +{
73 +  input->grab = window;
74 +}
75 +
76 +static void
77 +input_ungrab (struct input *input)
78 +{
79 +  input->grab = NULL;
80 +}
81 +
82 +static void
83 +input_remove_pointer_focus (struct input *input)
84 +{
85 +  GstWlWindow *window = input->pointer_focus;
86 +
87 +  if (!window)
88 +    return;
89 +
90 +  input->pointer_focus = NULL;
91 +}
92 +
93 +static void
94 +input_destroy (struct input *input)
95 +{
96 +  input_remove_pointer_focus (input);
97 +
98 +  if (input->display->seat_version >= 3) {
99 +    if (input->pointer)
100 +      wl_pointer_release (input->pointer);
101 +  }
102 +
103 +  wl_list_remove (&input->link);
104 +  wl_seat_destroy (input->seat);
105 +  free (input);
106 +}
107 +
108 +static void
109 +display_destroy_inputs (GstWlDisplay *display)
110 +{
111 +  struct input *tmp;
112 +  struct input *input;
113 +
114 +  wl_list_for_each_safe (input, tmp, &display->input_list, link)
115 +      input_destroy (input);
116 +}
117 +
118 +static void
119  gst_wl_display_finalize (GObject * gobject)
120  {
121    GstWlDisplay *self = GST_WL_DISPLAY (gobject);
122 @@ -74,6 +149,8 @@ gst_wl_display_finalize (GObject * gobject)
123    g_hash_table_unref (self->buffers);
124    g_mutex_clear (&self->buffers_mutex);
125  
126 +  display_destroy_inputs (self);
127 +
128    if (self->shm)
129      wl_shm_destroy (self->shm);
130  
131 @@ -143,6 +220,228 @@ static const struct wl_shm_listener shm_listener = {
132    shm_format
133  };
134  
135 +
136 +static void
137 +pointer_handle_enter (void *data, struct wl_pointer *pointer,
138 +    uint32_t serial, struct wl_surface *surface,
139 +    wl_fixed_t sx_w, wl_fixed_t sy_w)
140 +{
141 +  struct input *input = data;
142 +
143 +  if (!surface) {
144 +    /* enter event for a window we've just destroyed */
145 +    return;
146 +  }
147 +
148 +  input->display->serial = serial;
149 +  input->pointer_focus = wl_surface_get_user_data (surface);
150 +}
151 +
152 +static void
153 +pointer_handle_leave (void *data, struct wl_pointer *pointer,
154 +    uint32_t serial, struct wl_surface *surface)
155 +{
156 +  struct input *input = data;
157 +
158 +  input_remove_pointer_focus (input);
159 +}
160 +
161 +static void
162 +pointer_handle_motion (void *data, struct wl_pointer *pointer,
163 +    uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
164 +{
165 +  struct input *input = data;
166 +  GstWlWindow *window = input->pointer_focus;
167 +
168 +  if (!window)
169 +    return;
170 +
171 +  if (input->grab)
172 +    wl_shell_surface_move (input->grab->shell_surface, input->seat,
173 +        input->display->serial);
174 +
175 +}
176 +
177 +static void
178 +pointer_handle_button (void *data, struct wl_pointer *pointer, uint32_t serial,
179 +    uint32_t time, uint32_t button, uint32_t state_w)
180 +{
181 +  struct input *input = data;
182 +  enum wl_pointer_button_state state = state_w;
183 +  input->display->serial = serial;
184 +
185 +  if (button == BTN_LEFT) {
186 +    if (state == WL_POINTER_BUTTON_STATE_PRESSED)
187 +      input_grab (input, input->pointer_focus);
188 +
189 +    if (input->grab && state == WL_POINTER_BUTTON_STATE_RELEASED)
190 +      input_ungrab (input);
191 +  }
192 +
193 +  if (input->grab)
194 +    wl_shell_surface_move (input->grab->shell_surface, input->seat,
195 +        input->display->serial);
196 +}
197 +
198 +static void
199 +pointer_handle_axis (void *data, struct wl_pointer *pointer,
200 +    uint32_t time, uint32_t axis, wl_fixed_t value)
201 +{
202 +}
203 +
204 +static const struct wl_pointer_listener pointer_listener = {
205 +  pointer_handle_enter,
206 +  pointer_handle_leave,
207 +  pointer_handle_motion,
208 +  pointer_handle_button,
209 +  pointer_handle_axis,
210 +};
211 +
212 +static void
213 +touch_handle_down (void *data, struct wl_touch *wl_touch,
214 +    uint32_t serial, uint32_t time, struct wl_surface *surface,
215 +    int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
216 +{
217 +  struct input *input = data;
218 +  struct touch_point *tp;
219 +
220 +  input->display->serial = serial;
221 +  input->touch_focus = wl_surface_get_user_data (surface);
222 +  if (!input->touch_focus) {
223 +    return;
224 +  }
225 +
226 +  tp = malloc (sizeof *tp);
227 +  if (tp) {
228 +    tp->id = id;
229 +    wl_list_insert (&input->touch_point_list, &tp->link);
230 +    wl_shell_surface_move (input->touch_focus->shell_surface, input->seat,
231 +        serial);
232 +  }
233 +}
234 +
235 +static void
236 +touch_handle_motion (void *data, struct wl_touch *wl_touch,
237 +    uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
238 +{
239 +  struct input *input = data;
240 +  struct touch_point *tp;
241 +
242 +
243 +  if (!input->touch_focus) {
244 +    return;
245 +  }
246 +  wl_list_for_each (tp, &input->touch_point_list, link) {
247 +    if (tp->id != id)
248 +      continue;
249 +
250 +    wl_shell_surface_move (input->touch_focus->shell_surface, input->seat,
251 +        input->display->serial);
252 +
253 +    return;
254 +  }
255 +}
256 +
257 +static void
258 +touch_handle_frame (void *data, struct wl_touch *wl_touch)
259 +{
260 +}
261 +
262 +static void
263 +touch_handle_cancel (void *data, struct wl_touch *wl_touch)
264 +{
265 +}
266 +
267 +static void
268 +touch_handle_up (void *data, struct wl_touch *wl_touch,
269 +    uint32_t serial, uint32_t time, int32_t id)
270 +{
271 +  struct input *input = data;
272 +  struct touch_point *tp, *tmp;
273 +
274 +  if (!input->touch_focus) {
275 +    return;
276 +  }
277 +
278 +  wl_list_for_each_safe (tp, tmp, &input->touch_point_list, link) {
279 +    if (tp->id != id)
280 +      continue;
281 +
282 +    wl_list_remove (&tp->link);
283 +    free (tp);
284 +
285 +    return;
286 +  }
287 +}
288 +
289 +static const struct wl_touch_listener touch_listener = {
290 +  touch_handle_down,
291 +  touch_handle_up,
292 +  touch_handle_motion,
293 +  touch_handle_frame,
294 +  touch_handle_cancel,
295 +};
296 +
297 +
298 +static void
299 +seat_handle_capabilities (void *data, struct wl_seat *seat,
300 +    enum wl_seat_capability caps)
301 +{
302 +  struct input *input = data;
303 +
304 +  if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
305 +    input->pointer = wl_seat_get_pointer (seat);
306 +    wl_pointer_set_user_data (input->pointer, input);
307 +    wl_pointer_add_listener (input->pointer, &pointer_listener, input);
308 +  } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
309 +    wl_pointer_destroy (input->pointer);
310 +    input->pointer = NULL;
311 +  }
312 +
313 +  if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
314 +    input->touch = wl_seat_get_touch (seat);
315 +    wl_touch_set_user_data (input->touch, input);
316 +    wl_touch_add_listener (input->touch, &touch_listener, input);
317 +  } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) {
318 +    wl_touch_destroy (input->touch);
319 +    input->touch = NULL;
320 +  }
321 +}
322 +
323 +static void
324 +seat_handle_name (void *data, struct wl_seat *seat, const char *name)
325 +{
326 +
327 +}
328 +
329 +static const struct wl_seat_listener seat_listener = {
330 +  seat_handle_capabilities,
331 +  seat_handle_name
332 +};
333 +
334 +static void
335 +display_add_input (GstWlDisplay *d, uint32_t id)
336 +{
337 +  struct input *input;
338 +
339 +  input = calloc (1, sizeof (*input));
340 +  if (input == NULL) {
341 +    fprintf (stderr, "%s: out of memory\n", "gst-wayland-sink");
342 +    exit (EXIT_FAILURE);
343 +  }
344 +  input->display = d;
345 +  input->seat = wl_registry_bind (d->registry, id, &wl_seat_interface,
346 +      MAX (d->seat_version, 3));
347 +  input->touch_focus = NULL;
348 +  input->pointer_focus = NULL;
349 +  wl_list_init (&input->touch_point_list);
350 +  wl_list_insert (d->input_list.prev, &input->link);
351 +
352 +  wl_seat_add_listener (input->seat, &seat_listener, input);
353 +  wl_seat_set_user_data (input->seat, input);
354 +
355 +}
356 +
357  static void
358  registry_handle_global (void *data, struct wl_registry *registry,
359      uint32_t id, const char *interface, uint32_t version)
360 @@ -160,6 +459,9 @@ registry_handle_global (void *data, struct wl_registry *registry,
361    } else if (g_strcmp0 (interface, "wl_shm") == 0) {
362      self->shm = wl_registry_bind (registry, id, &wl_shm_interface, 1);
363      wl_shm_add_listener (self->shm, &shm_listener, self);
364 +  } else if (g_strcmp0 (interface, "wl_seat") == 0) {
365 +    self->seat_version = version;
366 +    display_add_input (self, id);
367    } else if (g_strcmp0 (interface, "wl_scaler") == 0) {
368      self->scaler = wl_registry_bind (registry, id, &wl_scaler_interface, 2);
369    }
370 @@ -237,6 +539,7 @@ gst_wl_display_new_existing (struct wl_display * display,
371    self->own_display = take_ownership;
372  
373    self->queue = wl_display_create_queue (self->display);
374 +  wl_list_init (&self->input_list);
375    self->registry = wl_display_get_registry (self->display);
376    wl_proxy_set_queue ((struct wl_proxy *) self->registry, self->queue);
377    wl_registry_add_listener (self->registry, &registry_listener, self);
378 diff --git a/ext/wayland/wldisplay.h b/ext/wayland/wldisplay.h
379 index 5505d60..d8c2cef 100644
380 --- a/ext/wayland/wldisplay.h
381 +++ b/ext/wayland/wldisplay.h
382 @@ -62,6 +62,10 @@ struct _GstWlDisplay
383    GMutex buffers_mutex;
384    GHashTable *buffers;
385    gboolean shutting_down;
386 +
387 +  struct wl_list input_list;
388 +  int seat_version;
389 +  uint32_t serial;
390  };
391  
392  struct _GstWlDisplayClass
393 diff --git a/ext/wayland/wlwindow.c b/ext/wayland/wlwindow.c
394 index a964335..34ae385 100644
395 --- a/ext/wayland/wlwindow.c
396 +++ b/ext/wayland/wlwindow.c
397 @@ -111,6 +111,8 @@ gst_wl_window_new_internal (GstWlDisplay * display)
398  
399    window->area_surface = wl_compositor_create_surface (display->compositor);
400    window->video_surface = wl_compositor_create_surface (display->compositor);
401 +  wl_surface_set_user_data (window->area_surface, window);
402 +  wl_surface_set_user_data (window->video_surface, window);
403  
404    wl_proxy_set_queue ((struct wl_proxy *) window->area_surface, display->queue);
405    wl_proxy_set_queue ((struct wl_proxy *) window->video_surface,
406 -- 
407 1.9.1
408