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
6 This patch enables grab, drag and ungrab of videos
7 that are being played on waylandsink.
9 Signed-off-by: Pooja Prajod <a0132412@ti.com>
11 ext/wayland/gstwaylandsink.c | 283 +++++++++++++++++++++++++++++++++++++++++++
12 ext/wayland/gstwaylandsink.h | 26 ++++
13 2 files changed, 309 insertions(+)
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
22 #include "gstwaylandsink.h"
23 +#include <linux/input.h>
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);
31 +static void input_grab (struct input *input, struct window *window);
32 +static void input_ungrab (struct input *input);
37 @@ -225,6 +229,54 @@ gst_wayland_sink_set_property (GObject * object,
41 +input_grab (struct input *input, struct window *window)
43 + input->grab = window;
47 +input_ungrab (struct input *input)
53 +input_remove_pointer_focus (struct input *input)
55 + struct window *window = input->pointer_focus;
60 + input->pointer_focus = NULL;
64 +input_destroy (struct input *input)
66 + input_remove_pointer_focus (input);
68 + if (input->display->seat_version >= 3) {
70 + wl_pointer_release (input->pointer);
73 + wl_list_remove (&input->link);
74 + wl_seat_destroy (input->seat);
79 +display_destroy_inputs (struct display *display)
82 + struct input *input;
84 + wl_list_for_each_safe (input, tmp, &display->input_list, link)
85 + input_destroy (input);
89 destroy_display (struct display *display)
92 @@ -236,6 +288,7 @@ destroy_display (struct display *display)
93 if (display->compositor)
94 wl_compositor_destroy (display->compositor);
96 + display_destroy_inputs (display);
97 wl_display_flush (display->display);
98 wl_display_disconnect (display->display);
100 @@ -318,6 +371,229 @@ struct wl_shm_listener shm_listenter = {
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)
110 + struct input *input = data;
113 + /* enter event for a window we've just destroyed */
117 + input->display->serial = serial;
118 + input->pointer_focus = wl_surface_get_user_data (surface);
122 +pointer_handle_leave (void *data, struct wl_pointer *pointer,
123 + uint32_t serial, struct wl_surface *surface)
125 + struct input *input = data;
127 + input_remove_pointer_focus (input);
131 +pointer_handle_motion (void *data, struct wl_pointer *pointer,
132 + uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
134 + struct input *input = data;
135 + struct window *window = input->pointer_focus;
141 + wl_shell_surface_move (input->grab->shell_surface, input->seat,
142 + input->display->serial);
147 +pointer_handle_button (void *data, struct wl_pointer *pointer, uint32_t serial,
148 + uint32_t time, uint32_t button, uint32_t state_w)
150 + struct input *input = data;
151 + enum wl_pointer_button_state state = state_w;
152 + input->display->serial = serial;
154 + if (button == BTN_LEFT) {
155 + if (state == WL_POINTER_BUTTON_STATE_PRESSED)
156 + input_grab (input, input->pointer_focus);
158 + if (input->grab && state == WL_POINTER_BUTTON_STATE_RELEASED)
159 + input_ungrab (input);
163 + wl_shell_surface_move (input->grab->shell_surface, input->seat,
164 + input->display->serial);
168 +pointer_handle_axis (void *data, struct wl_pointer *pointer,
169 + uint32_t time, uint32_t axis, wl_fixed_t value)
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,
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)
186 + struct input *input = data;
187 + struct touch_point *tp;
189 + input->display->serial = serial;
190 + input->touch_focus = wl_surface_get_user_data (surface);
191 + if (!input->touch_focus) {
195 + tp = malloc (sizeof *tp);
198 + wl_list_insert (&input->touch_point_list, &tp->link);
199 + wl_shell_surface_move (input->touch_focus->shell_surface, input->seat,
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)
208 + struct input *input = data;
209 + struct touch_point *tp;
212 + if (!input->touch_focus) {
215 + wl_list_for_each (tp, &input->touch_point_list, link) {
219 + wl_shell_surface_move (input->touch_focus->shell_surface, input->seat,
220 + input->display->serial);
227 +touch_handle_frame (void *data, struct wl_touch *wl_touch)
232 +touch_handle_cancel (void *data, struct wl_touch *wl_touch)
237 +touch_handle_up (void *data, struct wl_touch *wl_touch,
238 + uint32_t serial, uint32_t time, int32_t id)
240 + struct input *input = data;
241 + struct touch_point *tp, *tmp;
243 + if (!input->touch_focus) {
247 + wl_list_for_each_safe (tp, tmp, &input->touch_point_list, link) {
251 + wl_list_remove (&tp->link);
258 +static const struct wl_touch_listener touch_listener = {
261 + touch_handle_motion,
262 + touch_handle_frame,
263 + touch_handle_cancel,
269 +seat_handle_capabilities (void *data, struct wl_seat *seat,
270 + enum wl_seat_capability caps)
272 + struct input *input = data;
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;
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;
294 +seat_handle_name (void *data, struct wl_seat *seat, const char *name)
299 +static const struct wl_seat_listener seat_listener = {
300 + seat_handle_capabilities,
305 +display_add_input (struct display *d, uint32_t id)
307 + struct input *input;
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);
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);
322 + wl_seat_add_listener (input->seat, &seat_listener, input);
323 + wl_seat_set_user_data (input->seat, input);
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);
340 @@ -352,6 +631,8 @@ create_display (void)
344 + wl_list_init (&display->input_list);
346 display->registry = wl_display_get_registry (display->display);
347 wl_registry_add_listener (display->registry, ®istry_listener, display);
349 @@ -491,6 +772,8 @@ create_window (GstWaylandSink * sink, struct display *display, int width,
351 window->surface = wl_compositor_create_surface (display->compositor);
353 + wl_surface_set_user_data (window->surface, window);
355 window->shell_surface = wl_shell_get_shell_surface (display->shell,
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
363 #define GST_WAYLAND_SINK_GET_CLASS(inst) \
364 (G_TYPE_INSTANCE_GET_CLASS ((inst), GST_TYPE_WAYLAND_SINK, GstWaylandSinkClass))
369 + struct wl_list link;
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;
389 struct wl_display *display;
390 @@ -63,6 +84,11 @@ struct display
391 struct wl_shell *shell;
395 + struct wl_list input_list;