7db49341e9f38c2024c71c6cf93340943227c3fa
[AGL/meta-agl.git] / meta-agl-bsp / meta-ti / recipes-arago / weston / weston / 0001-ivi-shell-layer-controller-ti-Improve-functionality.patch
1 From 70f5b755b00d5eab576ed897a8301367b0e367a6 Mon Sep 17 00:00:00 2001
2 From: Volodymyr Riazantsev <volodymyr.riazantsev@globallogic.com>
3 Date: Sat, 16 Jul 2016 02:53:25 -0400
4 Subject: [PATCH] ivi-shell: layer-controller-ti: Improve functionality
5
6 Functionality improved:
7
8    * can launch multiple application on start
9    * handle keyboard focus:
10       - TAB-LEFTALT can be used for switch focus
11       - focus history;
12       - focus on new application.
13
14 Signed-off-by: Volodymyr Riazantsev <volodymyr.riazantsev@globallogic.com>
15 Signed-off-by: Karthik Ramanan <a0393906@ti.com>
16 ---
17  ivi-shell/ivi-layout-controller-ti.c | 167 +++++++++++++++++++++++++++++++----
18  1 file changed, 148 insertions(+), 19 deletions(-)
19
20 diff --git a/ivi-shell/ivi-layout-controller-ti.c b/ivi-shell/ivi-layout-controller-ti.c
21 index 4a2d648..9be51d1 100644
22 --- a/ivi-shell/ivi-layout-controller-ti.c
23 +++ b/ivi-shell/ivi-layout-controller-ti.c
24 @@ -30,6 +30,8 @@
25  #include <fcntl.h>
26  #include <unistd.h>
27  
28 +#include <linux/input.h>
29 +
30  #include "ivi-layout-export.h"
31  
32  #ifndef container_of
33 @@ -85,6 +87,7 @@ struct hmi_controller_layer {
34         int32_t width;
35         int32_t height;
36         int32_t num_surfaces;
37 +       int32_t focus;
38         pid_t pid;
39         struct wl_list link;
40         struct wl_list screen_link;
41 @@ -96,8 +99,10 @@ struct hmi_controller_surface {
42         void               *controller;
43         void               *ivisurf;
44         struct wl_list     link;
45 +       struct wl_list     focus_link;
46         struct wl_listener destroy_listener;
47         int                conf_num;
48 +       int                focus;
49  };
50  
51  struct hmi_controller_screen {
52 @@ -106,11 +111,12 @@ struct hmi_controller_screen {
53  };
54  
55  struct hmi_server_setting {
56 -       uint32_t    base_layer_id;
57 -       int32_t     panel_height;
58 -       char       *ivi_homescreen;
59 -       char       *homescreen_app;
60 -       struct wl_array rules;
61 +       uint32_t         base_layer_id;
62 +       int32_t          panel_height;
63 +       char            *ivi_homescreen;
64 +       char            *homescreen_app;
65 +       struct wl_array  autolaunch_apps;
66 +       struct wl_array  rules;
67  };
68  
69  struct hmi_controller {
70 @@ -126,6 +132,7 @@ struct hmi_controller {
71         struct wl_listener                  destroy_listener;
72         struct wl_client                   *user_interface;
73         struct wl_list                      layers_list;
74 +       struct wl_list                      focus_history_list;
75  
76  };
77  
78 @@ -350,12 +357,59 @@ exit:
79  }
80  
81  static void
82 +move_kbd_focus(struct hmi_controller_surface *ivisurf, struct hmi_controller *hmi_ctrl, bool history)
83 +{
84 +       struct hmi_controller_layer *layer;
85 +       struct hmi_controller_surface *surf;
86 +       struct weston_seat *seat;
87 +       struct weston_keyboard *keyboard;
88 +       struct weston_surface *surface;
89 +
90 +       wl_list_for_each(layer, &hmi_ctrl->layers_list, link) {
91 +               wl_list_for_each(surf, &layer->surfaces_list, link) {
92 +                       if (surf->focus) {
93 +                               surf->focus = 0;
94 +                               wl_list_insert(&hmi_ctrl->focus_history_list, &surf->focus_link);
95 +                               break;
96 +                       }
97 +               }
98 +       }
99 +
100 +       wl_list_for_each(seat, &hmi_ctrl->compositor->seat_list, link) {
101 +               if(!strcmp("default", seat->seat_name))
102 +                       break;
103 +       }
104 +
105 +       keyboard = weston_seat_get_keyboard(seat);
106 +
107 +       if (!keyboard)
108 +               return;
109 +
110 +       if (ivisurf) {
111 +               surface = ivi_controller_interface->surface_get_weston_surface(ivisurf->ivisurf);
112 +               weston_keyboard_set_focus(keyboard, surface);
113 +               ivisurf->focus = 1;
114 +
115 +               if (NULL != ivisurf->focus_link.next)
116 +                       wl_list_remove(&ivisurf->focus_link);
117 +
118 +       } else if (history && !wl_list_empty(&hmi_ctrl->focus_history_list)) {
119 +               struct hmi_controller_surface *s =
120 +                       wl_container_of(hmi_ctrl->focus_history_list.next, s, focus_link);
121 +               wl_list_remove(&s->focus_link);
122 +               surface = ivi_controller_interface->surface_get_weston_surface(s->ivisurf);
123 +               weston_keyboard_set_focus(keyboard, surface);
124 +               s->focus = 1;
125 +       }
126 +}
127 +
128 +static void
129  set_notification_create_surface(struct ivi_layout_surface *ivisurf,
130                                 void *userdata)
131  {
132         struct hmi_controller *hmi_ctrl = userdata;
133 -       struct hmi_controller_layer *hmi_ctrl_layer = NULL;
134 -       struct hmi_controller_surface *hmi_ctrl_surf = NULL;
135 +       struct hmi_controller_layer *hmi_ctrl_layer;
136 +       struct hmi_controller_surface *hmi_ctrl_surf;
137         struct ivi_layout_layer *dest_layer;
138         struct weston_surface *surface;
139  
140 @@ -378,6 +432,7 @@ set_notification_create_surface(struct ivi_layout_surface *ivisurf,
141         hmi_ctrl_surf = calloc(1, sizeof(*hmi_ctrl_surf));
142         hmi_ctrl_surf->ivisurf = ivisurf;
143         wl_list_init(&hmi_ctrl_surf->link);
144 +       wl_list_init(&hmi_ctrl_surf->focus_link);
145         wl_list_insert(&hmi_ctrl_layer->surfaces_list, &hmi_ctrl_surf->link);
146  
147  
148 @@ -419,6 +474,9 @@ remove:
149  
150         wl_list_remove(&surf->link);
151  
152 +       if (surf->focus)
153 +               move_kbd_focus(NULL, hmi_ctrl, true);
154 +
155         ivi_controller_interface->layer_remove_surface(dest_layer, ivisurf);
156  
157         if (wl_list_empty(&hmi_ctrl_layer->surfaces_list)) {
158 @@ -451,9 +509,10 @@ set_notification_configure_surface(struct ivi_layout_surface *ivisurf,
159                                    void *userdata)
160  {
161         struct hmi_controller *hmi_ctrl = userdata;
162 -       struct hmi_controller_layer *hmi_ctrl_layer = NULL;
163 +       struct hmi_controller_layer *hmi_ctrl_layer;
164         struct weston_surface *surface;
165 -       struct hmi_controller_surface *hmi_ctrl_surf = NULL;
166 +       struct weston_seat *seat = NULL;
167 +       struct hmi_controller_surface *hmi_ctrl_surf;
168         int src_rect[4] = {0};
169         int dest_rect[4] = {0};
170  
171 @@ -511,6 +570,16 @@ found:
172                         dest_rect[3] = hmi_ctrl_layer->rule->dest_rect[3] > 0 ?
173                                         hmi_ctrl_layer->rule->dest_rect[3] : dest_rect[3] ;
174                 }
175 +
176 +               if (hmi_ctrl_layer->rule->autofocus) {
177 +
178 +                       wl_list_for_each(seat, &hmi_ctrl->compositor->seat_list, link) {
179 +                               if(!strcmp("default", seat->seat_name))
180 +                                       break;
181 +                       }
182 +
183 +                       move_kbd_focus(hmi_ctrl_surf, hmi_ctrl, false);
184 +               }
185         }
186  
187         ivi_controller_interface->surface_set_source_rectangle(ivisurf
188 @@ -522,6 +591,7 @@ found:
189                         , dest_rect[2], dest_rect[3]);
190  
191         ivi_controller_interface->surface_set_visibility(ivisurf, true);
192 +
193         ivi_controller_interface->commit_changes();
194  
195         hmi_ctrl_surf->conf_num++;
196 @@ -543,14 +613,9 @@ hmi_server_setting_create(struct weston_compositor *ec)
197         weston_config_section_get_uint(shell_section, "base-layer-id",
198                                        &setting->base_layer_id, 1000);
199  
200 -       if ((shell_section = weston_config_get_section(config, "ivi-autolaunch",
201 -                                                 NULL, NULL))) {
202 -               weston_config_section_get_string(shell_section, "path",
203 -                                      &setting->homescreen_app, NULL);
204 -       }
205 -
206 -
207         wl_array_init(&setting->rules);
208 +       wl_array_init(&setting->autolaunch_apps);
209 +       wl_array_init(&setting->autolaunch_apps);
210  
211         while (weston_config_next_section(config, &shell_section, &name)) {
212                 int screen_id;
213 @@ -564,6 +629,12 @@ hmi_server_setting_create(struct weston_compositor *ec)
214                 char *buff;
215                 struct hmi_launch_rule *rule = NULL;
216  
217 +               if (!strcmp(name, "ivi-autolaunch")) {
218 +                       char **s = wl_array_add(&setting->autolaunch_apps, sizeof(*s));
219 +                       weston_config_section_get_string(shell_section, "path", s, NULL);
220 +                       continue;
221 +               }
222 +
223                 if (0 != strcmp(name, "ivi-layout-rule"))
224                         continue;
225  
226 @@ -573,7 +644,7 @@ hmi_server_setting_create(struct weston_compositor *ec)
227  
228                 weston_config_section_get_int(shell_section, "order", &order, -1);
229                 weston_config_section_get_int(shell_section, "mode", &mode, -1);
230 -               weston_config_section_get_int(shell_section, "focus_on", &focus_on, -1);
231 +               weston_config_section_get_int(shell_section, "focus_on", &focus_on, 0);
232                 weston_config_section_get_int(shell_section, "screen", &screen_id, -1);
233  
234                 if (0 == weston_config_section_get_string(shell_section, "crop_rect",
235 @@ -631,8 +702,10 @@ hmi_controller_destroy(struct wl_listener *listener, void *data)
236  
237  static void hmi_controller_launch_homescreen(struct hmi_controller *hmi_ctrl)
238  {
239 -       if (hmi_ctrl->hmi_setting->homescreen_app) {
240 -               if(system(hmi_ctrl->hmi_setting->homescreen_app)) {
241 +       char **app;
242 +
243 +       wl_array_for_each(app, &hmi_ctrl->hmi_setting->autolaunch_apps) {
244 +               if(system(*app)) {
245                         ;
246                 }
247         }
248 @@ -674,6 +747,7 @@ hmi_controller_create(struct weston_compositor *ec)
249                       &hmi_ctrl->destroy_listener);
250  
251         wl_list_init(&hmi_ctrl->layers_list);
252 +       wl_list_init(&hmi_ctrl->focus_history_list);
253  
254         free(pp_screen);
255         pp_screen = NULL;
256 @@ -719,6 +793,57 @@ initialize(struct hmi_controller *hmi_ctrl)
257         return 1;
258  }
259  
260 +static void
261 +switch_focus_bindings(struct weston_keyboard *keyboard, uint32_t time,
262 +                uint32_t key, void *data)
263 +{
264 +       struct hmi_controller *hmi_ctrl = data;
265 +       struct hmi_controller_layer *hmi_ctrl_layer, *next_l, *cycle_l = NULL;
266 +       struct hmi_controller_surface *hmi_ctrl_surf;
267 +       bool pp = false;
268 +
269 +       wl_list_for_each(hmi_ctrl_layer, &hmi_ctrl->layers_list, link) {
270 +               wl_list_for_each(hmi_ctrl_surf, &hmi_ctrl_layer->surfaces_list, link) {
271 +                       if (hmi_ctrl_surf->focus) {
272 +                               goto ff;
273 +                       }
274 +               }
275 +       }
276 +
277 +       hmi_ctrl_surf = NULL;
278 +       pp = true;
279 +
280 +ff:
281 +       wl_list_for_each(next_l, &hmi_ctrl->layers_list, link) {
282 +
283 +               if (pp) {
284 +                       if (next_l->rule && next_l->rule->autofocus) {
285 +                               cycle_l = next_l;
286 +                               break;
287 +                       }
288 +               } else {
289 +                       if (next_l == hmi_ctrl_layer) {
290 +                               pp = true;
291 +                               continue;
292 +                       } else {
293 +                               if (next_l->rule && next_l->rule->autofocus) {
294 +                                       cycle_l = next_l;
295 +                                       break;
296 +                               }
297 +                       }
298 +               }
299 +       }
300 +
301 +       if (!cycle_l)
302 +               return;
303 +
304 +       move_kbd_focus(container_of(cycle_l->surfaces_list.next
305 +                                       , struct hmi_controller_surface
306 +                                       , link)
307 +                                               , hmi_ctrl, false);
308 +}
309 +
310 +
311  /*****************************************************************************
312   *  exported functions
313   ****************************************************************************/
314 @@ -753,5 +878,9 @@ controller_module_init(struct weston_compositor *ec,
315  
316         hmi_controller_launch_homescreen(hmi_ctrl);
317  
318 +       weston_compositor_add_key_binding(ec, KEY_TAB , MODIFIER_ALT,
319 +                                               switch_focus_bindings, hmi_ctrl);
320 +       weston_install_debug_key_binding(ec, 0);
321 +
322         return 0;
323  }
324 -- 
325 2.4.5
326