ivi-shell: Temporary fix: Send keyboard events to clients who binds wl_keyboard.
[AGL/meta-agl-demo.git] / recipes-graphics / wayland / weston / 0001-ivi-shell-Send-keyboard-events-to-clients-tha-are-bi.patch
1 From affd6eb25a08a3f10f2c7010c3205e930ceb4ec0 Mon Sep 17 00:00:00 2001
2 From: Nobuhiko Tanibata <ntanibata@jp.adit-jv.com>
3 Date: Thu, 10 Dec 2015 16:07:20 +0900
4 Subject: [PATCH] ivi-shell: Temporary fix: Send keyboard events to clients who binds
5  wl_keyboard.
6
7 This is a temporary solution to send keyboard events to clients for CES2016 demo.
8 This shall be resolved by using ilm keyboard focus later.
9
10 Signed-off-by: Nobuhiko Tanibata <ntanibata@jp.adit-jv.com>
11
12 ---
13  ivi-shell/ivi-layout-private.h |  2 ++
14  ivi-shell/ivi-layout.c         | 65 ++++++++++++++++++++++++++++++++++++++++++
15  ivi-shell/ivi-shell.c          | 45 +++++++++++++++++++++++++++++
16  ivi-shell/ivi-shell.h          |  4 +++
17  4 files changed, 116 insertions(+)
18
19 diff --git a/ivi-shell/ivi-layout-private.h b/ivi-shell/ivi-layout-private.h
20 index ee945a6..a75d9b0 100644
21 --- a/ivi-shell/ivi-layout-private.h
22 +++ b/ivi-shell/ivi-layout-private.h
23 @@ -112,6 +112,8 @@ struct ivi_layout {
24
25         struct ivi_layout_transition_set *transitions;
26         struct wl_list pending_transition_list;
27 +
28 +       struct weston_keyboard_grab keyboard_grab;
29  };
30
31  struct ivi_layout *get_instance(void);
32 diff --git a/ivi-shell/ivi-layout.c b/ivi-shell/ivi-layout.c
33 index dbe1010..75404c8 100644
34 --- a/ivi-shell/ivi-layout.c
35 +++ b/ivi-shell/ivi-layout.c
36 @@ -124,6 +124,8 @@ struct ivi_rectangle
37  static void
38  remove_notification(struct wl_list *listener_list, void *callback, void *userdata);
39
40 +static const struct weston_keyboard_grab_interface ivi_layout_keyboard_grab_interface;
41 +
42  static struct ivi_layout ivilayout = {0};
43
44  struct ivi_layout *
45 @@ -2854,6 +2856,9 @@ ivi_layout_init_with_compositor(struct weston_compositor *ec)
46
47         layout->transitions = ivi_layout_transition_set_create(ec);
48         wl_list_init(&layout->pending_transition_list);
49 +
50 +       layout->keyboard_grab.interface = &ivi_layout_keyboard_grab_interface;
51 +       layout->keyboard_grab.keyboard = NULL;
52  }
53
54
55 @@ -2904,6 +2909,66 @@ ivi_layout_surface_is_forced_configure_event(struct ivi_layout_surface *ivisurf)
56         return ivisurf->prop.is_forced_configure_event;
57  }
58
59 +static void
60 +ivi_layout_grab_keyboard_key(struct weston_keyboard_grab *grab,
61 +                            uint32_t time, uint32_t key, uint32_t state)
62 +{
63 +       struct weston_keyboard *keyboard = grab->keyboard;
64 +       struct wl_display *display = keyboard->seat->compositor->wl_display;
65 +       uint32_t serial;
66 +       struct wl_resource *resource;
67 +
68 +       wl_resource_for_each(resource, &keyboard->focus_resource_list) {
69 +               serial = wl_display_next_serial(display);
70 +               wl_keyboard_send_key(resource,
71 +                                    serial,
72 +                                    time,
73 +                                    key,
74 +                                    state);
75 +       }
76 +
77 +       wl_resource_for_each(resource, &keyboard->resource_list) {
78 +               serial = wl_display_next_serial(display);
79 +               wl_keyboard_send_key(resource,
80 +                                    serial,
81 +                                    time,
82 +                                    key,
83 +                                    state);
84 +       }
85 +}
86 +
87 +static void
88 +ivi_layout_grab_keyboard_modifier(struct weston_keyboard_grab *grab,
89 +                                 uint32_t serial, uint32_t mods_depressed,
90 +                                 uint32_t mods_latched, uint32_t mods_locked,
91 +                                 uint32_t group)
92 +{
93 +       struct wl_resource *resource;
94 +       struct weston_keyboard *keyboard = grab->keyboard;
95 +
96 +       wl_resource_for_each(resource, &keyboard->focus_resource_list) {
97 +               wl_keyboard_send_modifiers(resource, serial, mods_depressed,
98 +                                          mods_latched, mods_locked, group);
99 +       }
100 +
101 +       wl_resource_for_each(resource, &keyboard->resource_list) {
102 +               wl_keyboard_send_modifiers(resource, serial, mods_depressed,
103 +                                          mods_latched, mods_locked, group);
104 +       }
105 +}
106 +
107 +static void
108 +ivi_layout_grab_keyboard_cancel(struct weston_keyboard_grab *grab)
109 +{
110 +       (void)grab; /* no op */
111 +}
112 +
113 +static const struct weston_keyboard_grab_interface ivi_layout_keyboard_grab_interface = {
114 +       ivi_layout_grab_keyboard_key,
115 +       ivi_layout_grab_keyboard_modifier,
116 +       ivi_layout_grab_keyboard_cancel
117 +};
118 +
119  static struct ivi_controller_interface ivi_controller_interface = {
120         /**
121          * commit all changes
122 diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
123 index 3b6c82f..43f48cc 100644
124 --- a/ivi-shell/ivi-shell.c
125 +++ b/ivi-shell/ivi-shell.c
126 @@ -423,6 +423,43 @@ ivi_shell_setting_create(struct ivi_shell_setting *dest,
127         return result;
128  }
129
130 +static void
131 +handle_seat_destroy(struct wl_listener *listener, void *data)
132 +{
133 +       struct weston_seat *seat = data;
134 +
135 +       if (seat->keyboard) {
136 +               weston_keyboard_end_grab(seat->keyboard);
137 +       }
138 +}
139 +
140 +static void
141 +handle_seat_updated_caps(struct wl_listener *listener, void *data)
142 +{
143 +       struct weston_seat *seat = data;
144 +
145 +       if ((seat->keyboard_device_count > 0) && seat->keyboard) {
146 +               weston_keyboard_start_grab(seat->keyboard,
147 +                                          &(get_instance()->keyboard_grab));
148 +       }
149 +}
150 +
151 +static void
152 +handle_seat_created(struct wl_listener *listener, void *data)
153 +{
154 +       struct weston_seat *seat = data;
155 +       struct ivi_shell *shell =
156 +               container_of(listener, struct ivi_shell, seat_created_listener);
157 +
158 +       shell->seat_destroy_listener.notify = handle_seat_destroy;
159 +       wl_signal_add(&seat->destroy_signal, &shell->seat_destroy_listener);
160 +
161 +       shell->seat_updated_caps_listener.notify = handle_seat_updated_caps;
162 +       wl_signal_add(&seat->updated_caps_signal, &shell->seat_updated_caps_listener);
163 +
164 +       handle_seat_updated_caps(&shell->seat_updated_caps_listener, seat);
165 +}
166 +
167  /*
168   * Initialization of ivi-shell.
169   */
170 @@ -432,6 +469,7 @@ module_init(struct weston_compositor *compositor,
171  {
172         struct ivi_shell *shell;
173         struct ivi_shell_setting setting = { };
174 +       struct weston_seat *seat;
175         int retval = -1;
176
177         shell = zalloc(sizeof *shell);
178 @@ -458,6 +496,13 @@ module_init(struct weston_compositor *compositor,
179
180         ivi_layout_init_with_compositor(compositor);
181
182 +       shell->seat_created_listener.notify = handle_seat_created;
183 +       wl_signal_add(&compositor->seat_created_signal, &shell->seat_created_listener);
184 +
185 +       wl_list_for_each(seat, &compositor->seat_list, link) {
186 +               handle_seat_created(&shell->seat_created_listener, seat);
187 +       }
188 +
189         /* Call module_init of ivi-modules which are defined in weston.ini */
190         if (load_controller_modules(compositor, setting.ivi_module,
191                                     argc, argv) < 0)
192 diff --git a/ivi-shell/ivi-shell.h b/ivi-shell/ivi-shell.h
193 index 9a05eb2..dc1d85a 100644
194 --- a/ivi-shell/ivi-shell.h
195 +++ b/ivi-shell/ivi-shell.h
196 @@ -41,6 +41,10 @@ struct ivi_shell
197         struct wl_listener hide_input_panel_listener;
198         struct wl_listener update_input_panel_listener;
199
200 +       struct wl_listener seat_created_listener;
201 +       struct wl_listener seat_updated_caps_listener;
202 +       struct wl_listener seat_destroy_listener;
203 +
204         struct weston_layer input_panel_layer;
205
206         bool locked;
207 --
208 1.8.3.1