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