Add patch : ivi input support touch and pointer on subsurface
[AGL/meta-agl.git] / meta-ivi-common / recipes-graphics / wayland / wayland-ivi-extension / 0001-ivi-input-support-touch-and-pointer-on-subsurface.patch
1 From e1823ef6721dec9db2343c7f92703d03a435e2bf Mon Sep 17 00:00:00 2001
2 From: Ryo Kagaya <rkagaya@jp.adit-jv.com>
3 Date: Fri, 4 Nov 2016 18:30:06 +0900
4 Subject: [PATCH] ivi-input: support touch and pointer on subsurface
5
6 When sends event to client, find a focused surface from subsurface list.
7
8 support following events
9  -touch_down
10  -touch_up
11  -touch_motion
12  -pointer_button
13 ---
14  .../src/ivi-input-controller.c                     | 78 ++++++++++++++++++----
15  1 file changed, 64 insertions(+), 14 deletions(-)
16
17 diff --git a/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c b/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c
18 index 9ed85d2..b1f9d6d 100644
19 --- a/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c
20 +++ b/ivi-input-modules/ivi-input-controller/src/ivi-input-controller.c
21 @@ -372,7 +372,8 @@ pointer_grab_button(struct weston_pointer_grab *grab, uint32_t time,
22      struct surface_ctx *surf_ctx;
23      wl_fixed_t sx, sy;
24      struct weston_view *picked_view, *w_view, *old_focus;
25 -    struct weston_surface *w_surf;
26 +    struct weston_surface *w_surf, *send_surf;
27 +    struct weston_subsurface *sub;
28      struct wl_resource *resource;
29      struct wl_client *surface_client;
30      uint32_t serial;
31 @@ -391,12 +392,24 @@ pointer_grab_button(struct weston_pointer_grab *grab, uint32_t time,
32          /* search for the picked view in layout surfaces */
33          wl_list_for_each(surf_ctx, &seat->input_ctx->surface_list, link) {
34              w_surf = interface->surface_get_weston_surface(surf_ctx->layout_surface);
35 -            w_view = wl_container_of(w_surf->views.next, w_view, surface_link);
36 +
37 +            /* Find a focused surface from subsurface list */
38 +            send_surf = w_surf;
39 +            if (!wl_list_empty(&w_surf->subsurface_list)) {
40 +                wl_list_for_each(sub, &w_surf->subsurface_list, parent_link) {
41 +                    if (sub->surface == picked_view->surface) {
42 +                        send_surf = sub->surface;
43 +                        break;
44 +                    }
45 +                }
46 +            }
47 +
48 +            w_view = wl_container_of(send_surf->views.next, w_view, surface_link);
49  
50              if (get_accepted_seat(surf_ctx, grab->pointer->seat->seat_name) < 0)
51                  continue;
52  
53 -            if (picked_view->surface == w_surf) {
54 +            if (picked_view->surface == send_surf) {
55                  /* Correct layout surface is found*/
56                  surf_ctx->focus |= ILM_INPUT_DEVICE_POINTER;
57                  send_input_focus(seat->input_ctx,
58 @@ -458,7 +471,8 @@ touch_grab_down(struct weston_touch_grab *grab, uint32_t time, int touch_id,
59  
60      /* For each surface_ctx, check for focus and send */
61      wl_list_for_each(surf_ctx, &seat->input_ctx->surface_list, link) {
62 -        struct weston_surface *surf;
63 +        struct weston_surface *surf, *send_surf;
64 +        struct weston_subsurface *sub;
65          struct weston_view *view;
66          struct wl_resource *resource;
67          struct wl_client *surface_client;
68 @@ -469,9 +483,20 @@ touch_grab_down(struct weston_touch_grab *grab, uint32_t time, int touch_id,
69          if (get_accepted_seat(surf_ctx, grab->touch->seat->seat_name) < 0)
70              continue;
71  
72 +        /* Find a focused surface from subsurface list */
73 +        send_surf = surf;
74 +        if (!wl_list_empty(&surf->subsurface_list)) {
75 +            wl_list_for_each(sub, &surf->subsurface_list, parent_link) {
76 +                if (sub->surface == grab->touch->focus->surface) {
77 +                    send_surf = sub->surface;
78 +                    break;
79 +                }
80 +            }
81 +        }
82 +
83          /* Touches set touch focus */
84          if (grab->touch->num_tp == 1) {
85 -            if (surf == grab->touch->focus->surface) {
86 +            if (send_surf == grab->touch->focus->surface) {
87                  surf_ctx->focus |= ILM_INPUT_DEVICE_TOUCH;
88                  send_input_focus(seat->input_ctx,
89                                   interface->get_id_of_surface(surf_ctx->layout_surface),
90 @@ -490,23 +515,23 @@ touch_grab_down(struct weston_touch_grab *grab, uint32_t time, int touch_id,
91              continue;
92  
93          /* Assume one view per surface */
94 -        view = wl_container_of(surf->views.next, view, surface_link);
95 +        view = wl_container_of(send_surf->views.next, view, surface_link);
96          weston_view_from_global_fixed(view, x, y, &sx, &sy);
97  
98 -        surface_client = wl_resource_get_client(surf->resource);
99 +        surface_client = wl_resource_get_client(send_surf->resource);
100          serial = wl_display_next_serial(display);
101          wl_resource_for_each(resource, &grab->touch->resource_list) {
102              if (wl_resource_get_client(resource) != surface_client)
103                  continue;
104  
105 -            wl_touch_send_down(resource, serial, time, surf->resource,
106 +            wl_touch_send_down(resource, serial, time, send_surf->resource,
107                                 touch_id, sx, sy);
108          }
109          wl_resource_for_each(resource, &grab->touch->focus_resource_list) {
110              if (wl_resource_get_client(resource) != surface_client)
111                  continue;
112  
113 -            wl_touch_send_down(resource, serial, time, surf->resource,
114 +            wl_touch_send_down(resource, serial, time, send_surf->resource,
115                                 touch_id, sx, sy);
116          }
117      }
118 @@ -525,7 +550,8 @@ touch_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
119  
120      /* For each surface_ctx, check for focus and send */
121      wl_list_for_each(surf_ctx, &seat->input_ctx->surface_list, link) {
122 -        struct weston_surface *surf;
123 +        struct weston_surface *surf, *send_surf;
124 +        struct weston_subsurface *sub;
125          struct wl_resource *resource;
126          struct wl_client *surface_client;
127          uint32_t serial;
128 @@ -537,8 +563,20 @@ touch_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
129              continue;
130  
131          surf = interface->surface_get_weston_surface(surf_ctx->layout_surface);
132 -        surface_client = wl_resource_get_client(surf->resource);
133          serial = wl_display_next_serial(display);
134 +
135 +        /* Find a focused surface from subsurface list */
136 +        send_surf = surf;
137 +        if (!wl_list_empty(&surf->subsurface_list)) {
138 +            wl_list_for_each(sub, &surf->subsurface_list, parent_link) {
139 +                if (sub->surface == grab->touch->focus->surface) {
140 +                    send_surf = sub->surface;
141 +                    break;
142 +                }
143 +            }
144 +        }
145 +        surface_client = wl_resource_get_client(send_surf->resource);
146 +
147          wl_resource_for_each(resource, &grab->touch->resource_list) {
148              if (wl_resource_get_client(resource) != surface_client)
149                  continue;
150 @@ -555,7 +593,7 @@ touch_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id)
151  
152          /* Touches unset touch focus */
153          if (grab->touch->num_tp == 0) {
154 -            if (surf == grab->touch->focus->surface)
155 +            if (send_surf == grab->touch->focus->surface)
156                  surf_ctx->focus &= ~ILM_INPUT_DEVICE_TOUCH;
157                  send_input_focus(seat->input_ctx,
158                                   interface->get_id_of_surface(surf_ctx->layout_surface),
159 @@ -576,7 +614,8 @@ touch_grab_motion(struct weston_touch_grab *grab, uint32_t time, int touch_id,
160  
161      /* For each surface_ctx, check for focus and send */
162      wl_list_for_each(surf_ctx, &seat->input_ctx->surface_list, link) {
163 -        struct weston_surface *surf;
164 +        struct weston_surface *surf, *send_surf;
165 +        struct weston_subsurface *sub;
166          struct weston_view *view;
167          struct wl_resource *resource;
168          struct wl_client *surface_client;
169 @@ -592,7 +631,18 @@ touch_grab_motion(struct weston_touch_grab *grab, uint32_t time, int touch_id,
170          view = wl_container_of(surf->views.next, view, surface_link);
171          weston_view_from_global_fixed(view, x, y, &sx, &sy);
172  
173 -        surface_client = wl_resource_get_client(surf->resource);
174 +        /* Find a focused surface from subsurface list */
175 +        send_surf = surf;
176 +        if (!wl_list_empty(&surf->subsurface_list)) {
177 +            wl_list_for_each(sub, &surf->subsurface_list, parent_link) {
178 +                if (sub->surface == grab->touch->focus->surface) {
179 +                    send_surf = sub->surface;
180 +                    break;
181 +                }
182 +            }
183 +        }
184 +        surface_client = wl_resource_get_client(send_surf->resource);
185 +
186          wl_resource_for_each(resource, &grab->touch->resource_list) {
187              if (wl_resource_get_client(resource) != surface_client)
188                  continue;
189 -- 
190 1.9.1
191