4988d4d64ff1655e64b5e8318d460936dccb057f
[profile/ivi/ico-uxf-weston-plugin.git] / src / ico_input_mgr.c
1 /*
2  * Copyright © 2010-2011 Intel Corporation
3  * Copyright © 2008-2011 Kristian Høgsberg
4  * Copyright © 2013 TOYOTA MOTOR CORPORATION.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and
7  * its documentation for any purpose is hereby granted without fee, provided
8  * that the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of the copyright holders not be used in
11  * advertising or publicity pertaining to distribution of the software
12  * without specific, written prior permission.  The copyright holders make
13  * no representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied warranty.
15  *
16  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23  */
24 /**
25  * @brief   Multi Input Manager (Weston(Wayland) PlugIn)
26  *
27  * @date    Jul-26-2013
28  */
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <stdbool.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <linux/input.h>
36 #include <assert.h>
37 #include <signal.h>
38 #include <math.h>
39 #include <time.h>
40 #include <sys/types.h>
41
42 #include <wayland-server.h>
43 #include <weston/compositor.h>
44 #include "ico_ivi_common.h"
45 #include "ico_ivi_shell.h"
46 #include "ico_window_mgr.h"
47 #include "ico_input_mgr.h"
48 #include "ico_window_mgr-server-protocol.h"
49 #include "ico_input_mgr-server-protocol.h"
50
51 /* degine maximum length                */
52 #define ICO_MINPUT_DEVICE_LEN           32
53 #define ICO_MINPUT_SW_LEN               20
54 #define ICO_MINPUT_MAX_CODES            20
55
56 /* structure definition */
57 struct uifw_region_mng;
58
59 /* working table of Multi Input Manager */
60 struct ico_input_mgr {
61     struct weston_compositor *compositor;   /* Weston Compositor                    */
62     struct wl_list  ictl_list;              /* Input Controller List                */
63     struct wl_list  app_list;               /* application List                     */
64     struct wl_list  dev_list;               /* pseudo device List                   */
65     struct wl_list  free_region;            /* free input region table list         */
66     struct weston_seat *seat;               /* input seat                           */
67     struct wl_resource *inputmgr;
68 };
69
70 /* Input Switch Table                   */
71 struct ico_ictl_code {
72     uint16_t    code;                       /* input code numner                    */
73     char        name[ICO_MINPUT_SW_LEN];    /* input code name                      */
74 };
75
76 struct ico_ictl_input {
77     struct wl_list link;                    /* link                                 */
78     char        swname[ICO_MINPUT_SW_LEN];  /* input switch name                    */
79     int32_t     input;                      /* input Id                             */
80     uint16_t    fix;                        /* fixed assign to application          */
81     uint16_t    ncode;                      /* number of codes                      */
82     struct ico_ictl_code code[ICO_MINPUT_MAX_CODES];   /* codes                     */
83     struct ico_app_mgr  *app;               /* send event tagret application        */
84 };
85
86 /* Input Controller Management Table    */
87 struct ico_ictl_mgr {
88     struct wl_list link;                    /* link                                 */
89     struct wl_client    *client;            /* client                               */
90     struct wl_resource  *mgr_resource;      /* resource as manager                  */
91     char    device[ICO_MINPUT_DEVICE_LEN];  /* device name                          */
92     int     type;                           /* device type                          */
93     struct wl_list ico_ictl_input;          /* list of input switchs                */
94 };
95
96 /* Application Management Table */
97 struct ico_app_mgr {
98     struct wl_list link;                    /* link                                 */
99     struct wl_client    *client;            /* client                               */
100     struct wl_resource  *resource;          /* resource for send event              */
101     struct wl_resource  *mgr_resource;      /* resource as manager(if NULL, client) */
102     char    appid[ICO_IVI_APPID_LENGTH];    /* application id                       */
103 };
104
105 /* Pseudo Input Device Control Flags    */
106 #define EVENT_MOTION        0x01            /* motion event                         */
107 #define EVENT_BUTTON        0x02            /* button event                         */
108 #define EVENT_TOUCH         0x03            /* touch event                          */
109 #define EVENT_KEY           0x04            /* key event                            */
110 #define EVENT_PENDING       0xff            /* pending event input                  */
111
112 #define PENDING_X           0x01            /* pending X coordinate                 */
113 #define PENDING_Y           0x02            /* pending Y coordinate                 */
114
115 /* Pseudo Input Device Table    */
116 struct uifw_input_device    {
117     struct wl_list  link;                   /* link to next device                  */
118     uint16_t    type;                       /* device type                          */
119     uint16_t    no;                         /* device number                        */
120     int         disp_x;                     /* display X coordinate                 */
121     int         disp_y;                     /* display Y coordinate                 */
122     int         x;                          /* current X coordinate                 */
123     int         y;                          /* current Y coordinate                 */
124     int         pend_x;                     /* pending X coordinate                 */
125     int         pend_y;                     /* pending Y coordinate                 */
126     uint16_t    pending;                    /* pending flag                         */
127     char        res[2];                     /* (unused)                             */
128     struct weston_surface *grab;            /* current grab surface                 */
129 };
130
131 /* Input Region Table           */
132 struct uifw_region_mng  {
133     struct wl_list  link;                   /* link pointer                         */
134     struct ico_uifw_input_region region;    /* input region                         */
135 };
136
137 /* prototype of static function */
138                                             /* bind input manager form manager      */
139 static void ico_control_bind(struct wl_client *client, void *data,
140                              uint32_t version, uint32_t id);
141                                             /* unbind input manager form manager    */
142 static void ico_control_unbind(struct wl_resource *resource);
143                                             /* bind input manager form input controller*/
144 static void ico_device_bind(struct wl_client *client, void *data,
145                             uint32_t version, uint32_t id);
146                                             /* unbind input manager form input controller*/
147 static void ico_device_unbind(struct wl_resource *resource);
148                                             /* bind input manager(form application) */
149 static void ico_exinput_bind(struct wl_client *client, void *data,
150                              uint32_t version, uint32_t id);
151                                             /* unbind input manager(form application)*/
152 static void ico_exinput_unbind(struct wl_resource *resource);
153
154                                             /* find ictl manager by device name     */
155 static struct ico_ictl_mgr *find_ictlmgr_by_device(const char *device);
156                                             /* find ictl input switch by input Id   */
157 static struct ico_ictl_input *find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr,
158                                                       const int32_t input);
159                                             /* find app manager by application Id   */
160 static struct ico_app_mgr *find_app_by_appid(const char *appid);
161                                             /* add input event to application       */
162 static void ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
163                                   const char *appid, const char *device, int32_t input,
164                                   int32_t fix, int32_t keycode);
165                                             /* delete input event to application    */
166 static void ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
167                                   const char *appid, const char *device, int32_t input);
168                                             /* send input event from manager        */
169 static void ico_mgr_send_input_event(struct wl_client *client, struct wl_resource *resource,
170                                      const char *target, uint32_t surfaceid, int32_t type,
171                                      int32_t deviceno, uint32_t time,
172                                      int32_t code, int32_t value);
173                                             /* set input region                     */
174 static void ico_mgr_set_input_region(struct wl_client *client, struct wl_resource *resource,
175                                      const char *target, int32_t x, int32_t y,
176                                      int32_t width, int32_t height, int32_t hotspot_x,
177                                      int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
178                                      int32_t cursor_width, int32_t cursor_height,
179                                      uint32_t attr);
180                                             /* unset input region                   */
181 static void ico_mgr_unset_input_region(struct wl_client *client,
182                                        struct wl_resource *resource,
183                                        const char *taret, int32_t x, int32_t y,
184                                        int32_t width, int32_t height);
185                                             /* create and regist Input Controller table*/
186 static void ico_device_configure_input(struct wl_client *client,
187                                        struct wl_resource *resource, const char *device,
188                                        int32_t type, const char *swname, int32_t input,
189                                        const char *codename, int32_t code);
190                                             /* add input to from Input Controller table*/
191 static void ico_device_configure_code(struct wl_client *client,
192                                       struct wl_resource *resource, const char *device,
193                                       int32_t input, const char *codename, int32_t code);
194                                             /* device input event                   */
195 static void ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
196                                    uint32_t time, const char *device,
197                                    int32_t input, int32_t code, int32_t state);
198 static void ico_input_send_region_event(struct wl_array *array);
199
200 /* definition of Wayland protocol       */
201 /* Input Manager Control interface      */
202 static const struct ico_input_mgr_control_interface ico_input_mgr_implementation = {
203     ico_mgr_add_input_app,
204     ico_mgr_del_input_app,
205     ico_mgr_send_input_event
206 };
207
208 /* Extended Input interface             */
209 static const struct ico_exinput_interface ico_exinput_implementation = {
210     ico_mgr_set_input_region,
211     ico_mgr_unset_input_region
212 };
213
214 /* Input Controller Device interface    */
215 static const struct ico_input_mgr_device_interface input_mgr_ictl_implementation = {
216     ico_device_configure_input,
217     ico_device_configure_code,
218     ico_device_input_event
219 };
220
221 /* definition of class variable */
222 struct ico_input_mgr    *pInputMgr = NULL;
223
224 /* implementation */
225 /*--------------------------------------------------------------------------*/
226 /**
227  * @brief   ico_mgr_add_input_app: add input event to application from HomeScreen.
228  *
229  * @param[in]   client          client(HomeScreen)
230  * @param[in]   resource        resource of request
231  * @param[in]   appid           target application id
232  * @param[in]   device          device name
233  * @param[in]   input           input switch number
234  * @param[in]   fix             fix to application(1=fix,0=general)
235  * @param[in]   keycode         switch map to keyboard operation(0=not map to keyboard)
236  * @return      none
237  */
238 /*--------------------------------------------------------------------------*/
239 static void
240 ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
241                       const char *appid, const char *device, int32_t input,
242                       int32_t fix, int32_t keycode)
243 {
244     uifw_trace("ico_mgr_add_input_app: Enter(appid=%s,dev=%s,input=%d,fix=%d,key=%d)",
245                appid, device, input, fix, keycode);
246
247     struct ico_ictl_mgr     *pIctlMgr;
248     struct ico_ictl_input   *pInput;
249     struct ico_app_mgr      *pAppMgr;
250
251     pIctlMgr = find_ictlmgr_by_device(device);
252     if (! pIctlMgr) {
253         /* not configure input controller, create   */
254         ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
255         pIctlMgr = find_ictlmgr_by_device(device);
256         if (! pIctlMgr) {
257             uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
258             return;
259         }
260     }
261     pInput = find_ictlinput_by_input(pIctlMgr, input);
262     if (! pInput)   {
263         /* not configure input switch, create   */
264         ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
265         pInput = find_ictlinput_by_input(pIctlMgr, input);
266         if (! pInput)   {
267             uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
268             return;
269         }
270     }
271
272     /* find application         */
273     pAppMgr = find_app_by_appid(appid);
274     if (! pAppMgr)  {
275         /* create Application Management Table  */
276         pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
277         if (! pAppMgr)  {
278             uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
279             return;
280         }
281         memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
282         strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
283         wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
284     }
285
286     pInput->app = pAppMgr;
287     pInput->fix = fix;
288     uifw_trace("ico_mgr_add_input_app: Leave(%s.%s[%d] assign to %s)",
289                pIctlMgr->device, pInput->swname ? pInput->swname : "(NULL)", input,
290                pAppMgr->appid);
291 }
292
293 /*--------------------------------------------------------------------------*/
294 /**
295  * @brief   ico_mgr_del_input_app: delete input event at application from HomeScreen.
296  *
297  * @param[in]   client          client(HomeScreen)
298  * @param[in]   resource        resource of request
299  * @param[in]   appid           target application id,
300  *                              if NULL, all applictions without fixed assign switch
301  * @param[in]   device          device name
302  *                              if NULL, all device without fixed assign switch
303  * @param[in]   input           input switch number
304  *                              if -1, all input without fixed assign switch
305  * @return      none
306  */
307 /*--------------------------------------------------------------------------*/
308 static void
309 ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
310                       const char *appid, const char *device, int32_t input)
311 {
312     uifw_trace("ico_mgr_del_input_app: Enter(appid=%s,dev=%s,input=%d)",
313                appid ? appid : "(NULL)", device ? device : "(NULL)", input);
314
315     int     alldev = 0;
316     struct ico_ictl_mgr     *pIctlMgr = NULL;
317     struct ico_ictl_input   *pInput = NULL;
318     struct ico_app_mgr      *pAppMgr;
319
320     if ((device != NULL) && (*device != 0)) {
321         pIctlMgr = find_ictlmgr_by_device(device);
322         if (! pIctlMgr) {
323             /* not configure input controller, NOP  */
324             uifw_trace("ico_mgr_del_input_app: Leave(%s dose not exist)", device);
325             return;
326         }
327         if (input >= 0) {
328             pInput = find_ictlinput_by_input(pIctlMgr, input);
329             if (! pInput)   {
330                 /* not configure input switch, NOP  */
331                 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d dose not exist)",
332                            device, input);
333                 return;
334             }
335         }
336     }
337     else    {
338         alldev = 1;
339     }
340
341     /* find application         */
342     if ((appid != NULL) && (*appid != 0))   {
343         pAppMgr = find_app_by_appid(appid);
344         if (! pAppMgr)  {
345             /* application dose not exist, NOP  */
346             uifw_trace("ico_mgr_del_input_app: Leave(app.%s dose not exist)", appid);
347             return;
348         }
349         if (alldev == 0)    {
350             if (input >= 0) {
351                 if (pInput->app != pAppMgr) {
352                     /* not same application, NOP        */
353                     uifw_trace("ico_mgr_del_input_app: Leave(%s.%d not app.%s, current %s)",
354                                device, input, appid,
355                                pInput->app ? pInput->app->appid : "(NULL)");
356                     return;
357                 }
358                 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d app.%s deleted)",
359                            device, input, appid);
360                 pInput->app = NULL;
361                 return;
362             }
363             else    {
364                 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
365                     if ((pInput->fix == 0) && (pInput->app == pAppMgr))   {
366                         uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
367                                    pIctlMgr->device, pInput->input, appid);
368                         pInput->app = NULL;
369                     }
370                 }
371             }
372         }
373         else    {
374             /* reset all device without fixed assign    */
375             wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link)    {
376                 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
377                     if ((pInput->fix == 0) && (pInput->app == pAppMgr))   {
378                         uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
379                                    pIctlMgr->device, pInput->input, pInput->app->appid);
380                         pInput->app = NULL;
381                     }
382                 }
383             }
384         }
385     }
386     else    {
387         if (alldev == 0)    {
388             if (input >= 0) {
389                 if ((pInput->fix == 0) && (pInput->app != NULL))    {
390                     uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
391                                pIctlMgr->device, pInput->input, pInput->app->appid);
392                     pInput->app = NULL;
393                 }
394             }
395             else    {
396                 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
397                     if ((pInput->fix == 0) && (pInput->app != NULL))    {
398                         uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
399                                pIctlMgr->device, pInput->input, pInput->app->appid);
400                         pInput->app = NULL;
401                     }
402                 }
403             }
404         }
405         else    {
406             /* reset all application without fixed assign       */
407             wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link)    {
408                 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
409                     if ((pInput->fix == 0) && (pInput->app != NULL))    {
410                         uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
411                                    pIctlMgr->device, pInput->input, pInput->app->appid);
412                         pInput->app = NULL;
413                     }
414                 }
415             }
416         }
417     }
418     uifw_trace("ico_mgr_del_input_app: Leave");
419 }
420
421 /*--------------------------------------------------------------------------*/
422 /**
423  * @brief   ico_mgr_send_input_event: send input event from manager
424  *
425  * @param[in]   client          client(HomeScreen)
426  * @param[in]   resource        resource of request
427  * @param[in]   target          target window name and application id
428  * @param[in]   surfaceid       target surface id
429  * @param[in]   type            event device type
430  * @param[in]   deviceno        device number
431  * @param[in]   time            event time (if 0, generate)
432  * @param[in]   code            event code
433  * @param[in]   value           event value
434  * @return      none
435  */
436 /*--------------------------------------------------------------------------*/
437 static void
438 ico_mgr_send_input_event(struct wl_client *client, struct wl_resource *resource,
439                          const char *target, uint32_t surfaceid, int32_t type,
440                          int32_t deviceno, uint32_t time, int32_t code, int32_t value)
441 {
442     struct uifw_win_surface *usurf;         /* UIFW surface                 */
443     struct uifw_input_device *dev;          /* device control table         */
444     struct wl_resource      *cres;          /* event send client resource   */
445     struct wl_array dummy_array;            /* dummy array for wayland API  */
446     uint32_t    ctime;                      /* current time(ms)             */
447     uint32_t    serial;                     /* event serial number          */
448     int         event;                      /* event flag                   */
449     wl_fixed_t  fix_x;                      /* wayland X coordinate         */
450     wl_fixed_t  fix_y;                      /* wayland Y coordinate         */
451     wl_fixed_t  dx, dy;                     /* relative coordinate (dummy)  */
452     struct weston_surface   *grabsave;      /* real grab surface            */
453     int         keyboard_active;            /* keyborad active surface flag */
454
455 #if 0           /* too many log */
456     uifw_debug("ico_mgr_send_input_event: Enter(target=%s surf=%x dev=%d.%d "
457                "time=%d code=%x value=%d)",
458                target ? target : "(NULL)", surfaceid, type, deviceno,
459                time, code, value);
460 #endif
461
462     /* search pseudo input device           */
463     wl_list_for_each (dev, &pInputMgr->dev_list, link)  {
464         if ((dev->type == type) && (dev->no == deviceno))   break;
465     }
466     if (&dev->link == &pInputMgr->dev_list) {
467         /* device not exist, create new device  */
468         uifw_trace("ico_mgr_send_input_event: new device=%d no=%d", type, deviceno);
469         dev = malloc(sizeof(struct uifw_input_device));
470         if (! dev)  {
471             uifw_error("ico_mgr_send_input_event: Leave(No Memory)");
472             return;
473         }
474         memset(dev, 0, sizeof(struct uifw_input_device));
475         dev->type = type;
476         dev->no = deviceno;
477         if ((type == ICO_INPUT_MGR_DEVICE_TYPE_POINTER) ||
478             (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) ||
479             (type == ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC)) {
480             ico_window_mgr_get_display_coordinate(deviceno, &dev->disp_x, &dev->disp_y);
481         }
482         wl_list_insert(pInputMgr->dev_list.prev, &dev->link);
483     }
484
485     /* convert pending event            */
486     event = 0;
487     if ((code & 0xffff0000) != (EV_REL << 16))  {
488         code &= 0x0000ffff;
489     }
490     switch (type)   {
491     case ICO_INPUT_MGR_DEVICE_TYPE_POINTER:         /* mouse        */
492     case ICO_INPUT_MGR_DEVICE_TYPE_TOUCH:           /* touch panel  */
493     case ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC:          /* haptic       */
494         switch (code)   {
495         case ABS_X:
496             if (dev->pending & PENDING_Y)   {
497                 dev->x = value;
498                 dev->y = dev->pend_y;
499                 dev->pending = 0;
500                 dev->pend_x = 0;
501                 dev->pend_y = 0;
502                 event = EVENT_MOTION;
503             }
504             else    {
505                 dev->pend_x = value;
506                 dev->pending |= PENDING_X;
507                 event = EVENT_PENDING;
508             }
509             break;
510         case ABS_Y:
511             if (dev->pending & PENDING_X)   {
512                 dev->x = dev->pend_x;
513                 dev->y = value;
514                 dev->pending = 0;
515                 dev->pend_x = 0;
516                 dev->pend_y = 0;
517                 event = EVENT_MOTION;
518             }
519             else    {
520                 dev->pend_y = value;
521                 dev->pending |= PENDING_Y;
522                 event = EVENT_PENDING;
523             }
524             break;
525         case ABS_Z:
526             dev->x = (short)(value >> 16);
527             dev->y = (short)(value & 0x0ffff);
528             dev->pending = 0;
529             dev->pend_x = 0;
530             dev->pend_y = 0;
531             event = EVENT_MOTION;
532             break;
533         case ((EV_REL << 16) | REL_X):
534             if (dev->pending & PENDING_Y)   {
535                 dev->x += value;
536                 dev->y = dev->pend_y;
537                 dev->pending = 0;
538                 dev->pend_x = 0;
539                 dev->pend_y = 0;
540                 event = EVENT_MOTION;
541             }
542             else    {
543                 dev->pend_x = dev->x + value;
544                 dev->pending |= PENDING_X;
545                 event = EVENT_PENDING;
546             }
547             break;
548         case ((EV_REL << 16) | REL_Y):
549             if (dev->pending & PENDING_X)   {
550                 dev->x = dev->pend_x;
551                 dev->y += value;
552                 dev->pending = 0;
553                 dev->pend_x = 0;
554                 dev->pend_y = 0;
555                 event = EVENT_MOTION;
556             }
557             else    {
558                 dev->pend_x = dev->y + value;
559                 dev->pending |= PENDING_Y;
560                 event = EVENT_PENDING;
561             }
562             break;
563         case ((EV_REL << 16) | REL_Z):
564             dev->x += (short)(value >> 16);
565             dev->y += (short)(value & 0x0ffff);
566             dev->pending = 0;
567             dev->pend_x = 0;
568             dev->pend_y = 0;
569             event = EVENT_MOTION;
570             break;
571         default:
572             if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH)    {
573                 event = EVENT_TOUCH;
574             }
575             else    {
576                 event = EVENT_BUTTON;
577             }
578             break;
579         }
580         break;
581     default:
582         event = EVENT_KEY;
583         break;
584     }
585
586     if (event == EVENT_PENDING)   {
587 #if 0           /* too many log */
588         uifw_debug("ico_mgr_send_input_event: Leave(event pending)");
589 #endif
590         return;
591     }
592
593     if (time)   {
594         ctime = time;
595     }
596     else    {
597         ctime = weston_compositor_get_time();
598     }
599     fix_x = wl_fixed_from_int(dev->x + dev->disp_x);
600     fix_y = wl_fixed_from_int(dev->y + dev->disp_y);
601
602     if ((surfaceid == 0) && ((target == NULL) || (*target == 0) || (*target == ' ')))  {
603         /* send event to surface via weston */
604
605         /* disable the event transmission to a input layer  */
606         if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH)    {
607             ico_window_mgr_touch_layer(TRUE);
608         }
609
610         if ((event == EVENT_TOUCH) && (pInputMgr->seat->touch == NULL)) {
611             /* system has no touch, change to pointer event */
612             if (pInputMgr->seat->pointer == NULL)   {
613                 uifw_trace("ico_mgr_send_input_event: Leave(no touch & no pointerr)");
614                 return;
615             }
616             event = EVENT_BUTTON;
617             code = BTN_LEFT;
618         }
619         else if ((event == EVENT_BUTTON) && (pInputMgr->seat->pointer == NULL)) {
620             /* system has no pointer, change to touch event */
621             if (pInputMgr->seat->touch == NULL) {
622                 uifw_trace("ico_mgr_send_input_event: Leave(no touch & no pointerr)");
623                 return;
624             }
625             event = EVENT_TOUCH;
626         }
627
628         switch (event)    {
629         case EVENT_MOTION:
630             if ((type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) &&
631                 (pInputMgr->seat->touch))   {
632                 if (pInputMgr->seat->num_tp > 10)   {
633                     uifw_debug("ico_mgr_send_input_event: num=%d reset",
634                                pInputMgr->seat->num_tp);
635                     pInputMgr->seat->num_tp = 0;        /* safty gard   */
636                 }
637                 grabsave = pInputMgr->seat->touch->focus;
638                 uifw_debug("ico_mgr_send_input_event: MOTION(%d/%d) grab %08x org %08x",
639                            fix_x/256, fix_y/256, (int)dev->grab, (int)grabsave);
640                 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
641                     weston_touch_set_focus(pInputMgr->seat, dev->grab);
642                 }
643                 notify_touch(pInputMgr->seat, ctime, 0, fix_x, fix_y, WL_TOUCH_MOTION);
644                 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
645                     weston_touch_set_focus(pInputMgr->seat, grabsave);
646                 }
647             }
648             else if (pInputMgr->seat->pointer)  {
649 #if 0           /* too many log */
650                 uifw_debug("ico_mgr_send_input_event: notify_motion_absolute(%d/%d)",
651                            fix_x/256, fix_y/256);
652 #endif
653                 notify_motion_absolute(pInputMgr->seat, ctime, fix_x, fix_y);
654             }
655             break;
656         case EVENT_BUTTON:
657             uifw_trace("ico_mgr_send_input_event: notify_button(%d,%d)", code, value);
658             if (pInputMgr->seat->pointer)   {
659                 if (value)  {
660                     dev->grab = weston_compositor_pick_surface(
661                                     pInputMgr->compositor, fix_x, fix_y, &dx, &dy);
662                     weston_pointer_set_focus(pInputMgr->seat->pointer, dev->grab, dx, dy);
663                     ico_window_mgr_active_surface(dev->grab);
664                 }
665                 else    {
666                     dev->grab = NULL;
667                 }
668                 notify_button(pInputMgr->seat, ctime, code,
669                               value ? WL_POINTER_BUTTON_STATE_PRESSED :
670                                       WL_POINTER_BUTTON_STATE_RELEASED);
671             }
672             break;
673         case EVENT_TOUCH:
674             if (value >= 7) {
675                 grabsave = pInputMgr->seat->touch->focus;
676                 uifw_trace("ico_mgr_send_input_event: notify_touch(UnGrab dev=%08x sys=%08x)",
677                            (int)dev->grab, (int)grabsave);
678                 dev->grab = NULL;
679                 if (pInputMgr->seat->num_tp > 0)   {
680                     if (value == 7) {
681                         if (pInputMgr->seat->num_tp > 1)    {
682                             uifw_debug("ico_mgr_send_input_event: num=%d Up is true",
683                                        pInputMgr->seat->num_tp);
684                             value = 0;
685                         }
686                         else    {
687                             uifw_debug("ico_mgr_send_input_event: num=%d Up is false",
688                                        pInputMgr->seat->num_tp);
689                         }
690                     }
691                     if (value != 7) {
692                         if (pInputMgr->seat->touch->grab)   {
693                             notify_touch(pInputMgr->seat, ctime,
694                                          0, fix_x, fix_y, WL_TOUCH_UP);
695                         }
696                         else    {
697                             uifw_debug("ico_mgr_send_input_event: reset num count down(%d)",
698                                         pInputMgr->seat->num_tp);
699                             pInputMgr->seat->num_tp --;
700                         }
701                     }
702                 }
703                 if (pInputMgr->seat->num_tp > 10)   {
704                     uifw_debug("ico_mgr_send_input_event: num=%d reset",
705                                pInputMgr->seat->num_tp);
706                     pInputMgr->seat->num_tp = 0;        /* safty gard   */
707                 }
708             }
709             if ((value > 0) && (value != 9) && (value != 7))    {
710                 grabsave = pInputMgr->seat->touch->focus;
711                 dev->grab = weston_compositor_pick_surface(
712                                 pInputMgr->compositor, fix_x, fix_y, &dx, &dy);
713                 uifw_trace("ico_mgr_send_input_event: notify_touch(DOWN=%d/%d) "
714                            "grab=%08x org=%08x", fix_x/256, fix_y/256,
715                            (int)dev->grab, (int)grabsave);
716                 if (grabsave != dev->grab)  {
717                     weston_touch_set_focus(pInputMgr->seat, dev->grab);
718                 }
719                 notify_touch(pInputMgr->seat, ctime, 0, fix_x, fix_y, WL_TOUCH_DOWN);
720                 ico_window_mgr_active_surface(dev->grab);
721                 if (pInputMgr->seat->num_tp == 0)   {
722                     uifw_debug("ico_mgr_send_input_event: touch_down illegal num, modify");
723                     pInputMgr->seat->num_tp = 1;        /* safty gard   */
724                 }
725             }
726             else if (value == 7)    {
727                 dev->grab = NULL;
728             }
729             else    {
730                 grabsave = pInputMgr->seat->touch->focus;
731                 uifw_trace("ico_mgr_send_input_event: notify_touch(UP) org=%08x",
732                            (int)grabsave);
733                 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
734                     weston_touch_set_focus(pInputMgr->seat, dev->grab);
735                 }
736                 notify_touch(pInputMgr->seat, ctime, 0, 0, 0, WL_TOUCH_UP);
737                 if (grabsave == dev->grab)  grabsave = NULL;
738                 weston_touch_set_focus(pInputMgr->seat, grabsave);
739                 dev->grab = NULL;
740                 if (pInputMgr->seat->num_tp > 10)   {
741                     uifw_debug("ico_mgr_send_input_event: num=%d reset",
742                                pInputMgr->seat->num_tp);
743                     pInputMgr->seat->num_tp = 0;        /* safty gard   */
744                 }
745             }
746             break;
747         case EVENT_KEY:
748             uifw_trace("ico_mgr_send_input_event: notify_key(%d,%d)", code, value);
749             notify_key(pInputMgr->seat, ctime, code,
750                        value ? WL_KEYBOARD_KEY_STATE_PRESSED :
751                                WL_KEYBOARD_KEY_STATE_RELEASED, STATE_UPDATE_NONE);
752             break;
753         default:
754             uifw_trace("ico_mgr_send_input_event: unknown event=%d", event);
755             break;
756         }
757         /* enable the event transmission to a input layer   */
758         if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH)    {
759             ico_window_mgr_touch_layer(FALSE);
760         }
761     }
762     else    {
763         if ((target != NULL) && (*target != 0) && (*target != ' '))    {
764             /* send event to fixed application  */
765
766             /* get application surface       */
767             usurf = ico_window_mgr_get_client_usurf(target);
768             if (! usurf)  {
769                 uifw_trace("ico_mgr_send_input_event: Leave(window=%s dose not exist)",
770                            target);
771                 return;
772             }
773         }
774         else    {
775             /* get UIFW surface             */
776             usurf = ico_window_mgr_get_usurf(surfaceid);
777             if (! usurf)    {
778                 uifw_trace("ico_mgr_send_input_event: Leave(surface dose not exist)");
779                 return;
780             }
781         }
782
783         /* send event                   */
784         switch (event)    {
785         case EVENT_MOTION:
786             if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH)    {
787                 cres = wl_resource_find_for_client(
788                                     &pInputMgr->seat->touch->resource_list,
789                                     wl_resource_get_client(usurf->surface->resource));
790                 if (cres)   {
791                     wl_touch_send_motion(cres, ctime, 0, fix_x, fix_y);
792                 }
793             }
794             else    {
795                 cres = wl_resource_find_for_client(
796                                     &pInputMgr->seat->pointer->resource_list,
797                                     wl_resource_get_client(usurf->surface->resource));
798                 if (cres)   {
799                     wl_pointer_send_motion(cres, ctime, fix_x, fix_y);
800                 }
801             }
802             break;
803         case EVENT_BUTTON:
804             cres = wl_resource_find_for_client(
805                                 &pInputMgr->seat->pointer->resource_list,
806                                 wl_resource_get_client(usurf->surface->resource));
807             if (cres)   {
808                 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
809                 wl_pointer_send_button(cres, serial, ctime, code,
810                                        value ? WL_POINTER_BUTTON_STATE_PRESSED :
811                                                WL_POINTER_BUTTON_STATE_RELEASED);
812             }
813             break;
814         case EVENT_TOUCH:
815             cres = wl_resource_find_for_client(
816                                 &pInputMgr->seat->touch->resource_list,
817                                 wl_resource_get_client(usurf->surface->resource));
818             if (cres)   {
819                 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
820                 if (value)  {
821                     wl_touch_send_down(cres, serial, ctime, usurf->surface->resource, 0,
822                                        fix_x, fix_y);
823                 }
824                 else    {
825                     wl_touch_send_up(cres, serial, ctime, 0);
826                 }
827             }
828             break;
829         case EVENT_KEY:
830             cres = wl_resource_find_for_client(
831                                 &pInputMgr->seat->keyboard->resource_list,
832                                 wl_resource_get_client(usurf->surface->resource));
833             if (cres)   {
834                 keyboard_active = ico_window_mgr_ismykeyboard(usurf);
835                 if (! keyboard_active)  {
836                     wl_array_init(&dummy_array);
837                     serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
838                     wl_keyboard_send_enter(cres, serial,
839                                            usurf->surface->resource, &dummy_array);
840                 }
841                 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
842                 wl_keyboard_send_key(cres, serial, ctime, code,
843                                      value ? WL_KEYBOARD_KEY_STATE_PRESSED :
844                                              WL_KEYBOARD_KEY_STATE_RELEASED);
845                 if (! keyboard_active)  {
846                     serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
847                     wl_keyboard_send_leave(cres, serial, usurf->surface->resource);
848                 }
849             }
850             break;
851         default:
852             break;
853         }
854     }
855 #if 0           /* too many log */
856     uifw_debug("ico_mgr_send_input_event: Leave");
857 #endif
858 }
859
860 /*--------------------------------------------------------------------------*/
861 /**
862  * @brief   ico_mgr_set_input_region: set input region for haptic devcie
863  *
864  * @param[in]   client          client(Device Input Controller)
865  * @param[in]   resource        resource of request
866  * @param[in]   target          target window (winname@appid)
867  * @param[in]   x               input region X coordinate
868  * @param[in]   y               input region X coordinate
869  * @param[in]   width           input region width
870  * @param[in]   height          input region height
871  * @param[in]   hotspot_x       hotspot of X relative coordinate
872  * @param[in]   hotspot_y       hotspot of Y relative coordinate
873  * @param[in]   cursor_x        cursor region X coordinate
874  * @param[in]   cursor_y        cursor region X coordinate
875  * @param[in]   cursor_width    cursor region width
876  * @param[in]   cursor_height   cursor region height
877  * @param[in]   attr            region attributes(currently unused)
878  * @return      none
879  */
880 /*--------------------------------------------------------------------------*/
881 static void
882 ico_mgr_set_input_region(struct wl_client *client, struct wl_resource *resource,
883                          const char *target, int32_t x, int32_t y,
884                          int32_t width, int32_t height, int32_t hotspot_x,
885                          int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
886                          int32_t cursor_width, int32_t cursor_height, uint32_t attr)
887 {
888     struct uifw_win_surface *usurf;         /* UIFW surface                 */
889     struct uifw_region_mng  *p;
890     struct ico_uifw_input_region *rp;
891     struct wl_array         array;
892     int     i;
893
894     uifw_trace("ico_mgr_set_input_region: Enter(%s %d/%d-%d/%d(%d/%d) %d/%d-%d/%d)",
895                target, x, y, width, height, hotspot_x, hotspot_y,
896                cursor_x, cursor_y, cursor_width, cursor_height);
897
898     /* get target surface           */
899     usurf = ico_window_mgr_get_client_usurf(target);
900     if (! usurf)    {
901         uifw_warn("ico_mgr_set_input_region: Leave(target<%s> dose not exist)", target);
902         return;
903     }
904
905     if (wl_list_empty(&pInputMgr->free_region)) {
906         p = malloc(sizeof(struct uifw_region_mng) * 50);
907         if (! p)    {
908             uifw_error("ico_mgr_set_input_region: No Memory");
909             return;
910         }
911         memset(p, 0, sizeof(struct uifw_region_mng)*50);
912         for (i = 0; i < 50; i++, p++)  {
913             wl_list_insert(pInputMgr->free_region.prev, &p->link);
914         }
915     }
916     p = container_of(pInputMgr->free_region.next, struct uifw_region_mng, link);
917     wl_list_remove(&p->link);
918     p->region.node = usurf->node_tbl->node;
919     p->region.surfaceid = usurf->surfaceid;
920     p->region.surface_x = usurf->x;
921     p->region.surface_y = usurf->y;
922     p->region.x = x;
923     p->region.y = y;
924     p->region.width = width;
925     p->region.height = height;
926     if ((hotspot_x <= 0) && (hotspot_y <= 0))   {
927         p->region.hotspot_x = width / 2;
928         p->region.hotspot_y = height / 2;
929     }
930     else    {
931         p->region.hotspot_x = hotspot_x;
932         p->region.hotspot_y = hotspot_y;
933     }
934     if ((cursor_width <= 0) && (cursor_height <= 0))    {
935         p->region.cursor_x = x;
936         p->region.cursor_y = y;
937         p->region.cursor_width = width;
938         p->region.cursor_height = height;
939     }
940     else    {
941         p->region.cursor_x = cursor_x;
942         p->region.cursor_y = cursor_y;
943         p->region.cursor_width = cursor_width;
944         p->region.cursor_height = cursor_height;
945     }
946     p->region.change = ico_window_mgr_is_visible(usurf);
947     wl_list_insert(usurf->input_region.prev, &p->link);
948
949     /* send input region to haptic device input controller  */
950     if (p->region.change > 0)   {
951         wl_array_init(&array);
952         rp = (struct ico_uifw_input_region *)
953                  wl_array_add(&array, sizeof(struct ico_uifw_input_region));
954         if (rp) {
955             memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
956             rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
957             ico_input_send_region_event(&array);
958         }
959     }
960     uifw_trace("ico_mgr_set_input_region: Leave");
961 }
962
963 /*--------------------------------------------------------------------------*/
964 /**
965  * @brief   ico_mgr_unset_input_region: unset input region for haptic devcie
966  *
967  * @param[in]   client          client(Device Input Controller)
968  * @param[in]   resource        resource of request
969  * @param[in]   target          target window (winname@appid)
970  * @param[in]   x               input region X coordinate
971  * @param[in]   y               input region X coordinate
972  * @param[in]   width           input region width
973  * @param[in]   height          input region height
974  * @return      none
975  */
976 /*--------------------------------------------------------------------------*/
977 static void
978 ico_mgr_unset_input_region(struct wl_client *client, struct wl_resource *resource,
979                            const char *target, int32_t x, int32_t y,
980                            int32_t width, int32_t height)
981 {
982     struct uifw_win_surface     *usurf;     /* UIFW surface                 */
983     struct uifw_region_mng      *p;         /* input region mamagement table*/
984     struct uifw_region_mng      *np;        /* next region mamagement table */
985     struct ico_uifw_input_region *rp;       /* input region                 */
986     struct wl_array             array;
987     int                         alldel;
988     int                         delcount = 0;
989
990     uifw_trace("ico_mgr_unset_input_region: Enter(%s %d/%d-%d/%d)",
991                target, x, y, width, height);
992
993     /* get target surface           */
994     usurf = ico_window_mgr_get_client_usurf(target);
995     if (! usurf)    {
996         uifw_warn("ico_mgr_unset_input_region: Leave(target<%s> dose not exist)", target);
997         return;
998     }
999
1000     if ((x <= 0) && (y <= 0) && (width <= 0) && (height <= 0))  {
1001         alldel = 1;
1002     }
1003     else    {
1004         alldel = 0;
1005     }
1006
1007     wl_array_init(&array);
1008
1009     wl_list_for_each_safe(p, np, &usurf->input_region, link)    {
1010         if ((alldel != 0) ||
1011             ((x == p->region.x) && (y == p->region.y) &&
1012              (width == p->region.width) && (height == p->region.height)))   {
1013             if (p->region.change > 0)   {
1014                 /* visible, send remove event   */
1015                 rp = (struct ico_uifw_input_region *)
1016                      wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1017                 if (rp) {
1018                     delcount ++;
1019                     memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1020                     rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1021                 }
1022             }
1023             wl_list_remove(&p->link);
1024             wl_list_insert(pInputMgr->free_region.prev, &p->link);
1025         }
1026     }
1027     if (delcount > 0)   {
1028         /* send region delete to haptic device input controller */
1029         ico_input_send_region_event(&array);
1030     }
1031     uifw_trace("ico_mgr_unset_input_region: Leave");
1032 }
1033
1034 /*--------------------------------------------------------------------------*/
1035 /**
1036  * @brief   ico_input_hook_region_visible: change surface visibility
1037  *
1038  * @param[in]   usurf           UIFW surface
1039  * @return      none
1040  */
1041 /*--------------------------------------------------------------------------*/
1042 static void
1043 ico_input_hook_region_visible(struct uifw_win_surface *usurf)
1044 {
1045     struct uifw_region_mng      *p;         /* input region mamagement table*/
1046     struct ico_uifw_input_region *rp;       /* input region                 */
1047     struct wl_array             array;
1048     int                         chgcount = 0;
1049     int                         visible;
1050
1051     visible = ico_window_mgr_is_visible(usurf);
1052
1053     uifw_trace("ico_input_hook_region_visible: Entery(surf=%08x, visible=%d)",
1054                usurf->surfaceid, visible);
1055
1056     wl_array_init(&array);
1057
1058     wl_list_for_each(p, &usurf->input_region, link) {
1059         if (((p->region.change > 0) && (visible <= 0)) ||
1060             ((p->region.change <= 0) && (visible > 0))) {
1061             /* visible change, send remove event    */
1062             rp = (struct ico_uifw_input_region *)
1063                  wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1064             if (rp) {
1065                 chgcount ++;
1066                 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1067                 if (visible > 0)    {
1068                     rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
1069                 }
1070                 else    {
1071                     rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1072                 }
1073             }
1074         }
1075         p->region.change = visible;
1076     }
1077     if (chgcount > 0)   {
1078         /* send region delete to haptic device input controller */
1079         ico_input_send_region_event(&array);
1080     }
1081
1082     uifw_trace("ico_input_hook_region_visible: Leave");
1083 }
1084
1085 /*--------------------------------------------------------------------------*/
1086 /**
1087  * @brief   ico_input_hook_region_destroy: destory surface
1088  *
1089  * @param[in]   usurf           UIFW surface
1090  * @return      none
1091  */
1092 /*--------------------------------------------------------------------------*/
1093 static void
1094 ico_input_hook_region_destroy(struct uifw_win_surface *usurf)
1095 {
1096     struct uifw_region_mng      *p;         /* input region mamagement table*/
1097     struct uifw_region_mng      *np;        /* next region mamagement table */
1098     struct ico_uifw_input_region *rp;       /* input region                 */
1099     struct wl_array             array;
1100     int                         delcount = 0;
1101
1102     uifw_trace("ico_input_hook_region_destroy: Entery(surf=%08x)", usurf->surfaceid);
1103
1104     wl_array_init(&array);
1105
1106     wl_list_for_each_safe(p, np, &usurf->input_region, link)    {
1107         if (p->region.change > 0)   {
1108             /* visible, send remove event   */
1109             rp = (struct ico_uifw_input_region *)
1110                  wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1111             if (rp) {
1112                 delcount ++;
1113                 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1114                 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1115             }
1116         }
1117         wl_list_remove(&p->link);
1118         wl_list_insert(pInputMgr->free_region.prev, &p->link);
1119     }
1120     if (delcount > 0)   {
1121         /* send region delete to haptic device input controller */
1122         ico_input_send_region_event(&array);
1123     }
1124     uifw_trace("ico_input_hook_region_destroy: Leave");
1125 }
1126
1127 /*--------------------------------------------------------------------------*/
1128 /**
1129  * @brief   ico_input_send_region_event: send region event to Haptic dic
1130  *
1131  * @param[in]   usurf           UIFW surface
1132  * @return      none
1133  */
1134 /*--------------------------------------------------------------------------*/
1135 static void
1136 ico_input_send_region_event(struct wl_array *array)
1137 {
1138     struct ico_ictl_mgr     *pIctlMgr;
1139
1140     wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link)   {
1141         if ((pIctlMgr->type == ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC) &&
1142             (pIctlMgr->mgr_resource != NULL))   {
1143             uifw_trace("ico_input_send_region_event: send event to Hapfic");
1144             ico_input_mgr_device_send_input_regions(pIctlMgr->mgr_resource, array);
1145         }
1146     }
1147 }
1148
1149 /*--------------------------------------------------------------------------*/
1150 /**
1151  * @brief   ico_device_configure_input: configure input device and input switch
1152  *          from Device Input Controller.
1153  *
1154  * @param[in]   client          client(Device Input Controller)
1155  * @param[in]   resource        resource of request
1156  * @param[in]   device          device name
1157  * @param[in]   type            device type(saved but unused)
1158  * @param[in]   swname          input switch name
1159  * @param[in]   input           input switch number
1160  * @param[in]   codename        input code name
1161  * @param[in]   code            input code number
1162  * @return      none
1163  */
1164 /*--------------------------------------------------------------------------*/
1165 static void
1166 ico_device_configure_input(struct wl_client *client, struct wl_resource *resource,
1167                            const char *device, int32_t type, const char *swname,
1168                            int32_t input, const char *codename, int32_t code)
1169 {
1170     uifw_trace("ico_device_configure_input: Enter(client=%08x,dev=%s,type=%d,swname=%s,"
1171                "input=%d,code=%d[%s])", (int)client, device, type,
1172                swname ? swname : "(NULL)", input, code, codename ? codename : " ");
1173
1174     struct ico_ictl_mgr     *pIctlMgr;
1175     struct ico_ictl_mgr     *psameIctlMgr;
1176     struct ico_ictl_input   *pInput;
1177     struct ico_app_mgr      *pAppMgr;
1178
1179     pIctlMgr = find_ictlmgr_by_device(device);
1180     if (! pIctlMgr) {
1181         /* search binded table      */
1182         psameIctlMgr = NULL;
1183         wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link)    {
1184             if (pIctlMgr->client == client) {
1185                 uifw_trace("ico_device_configure_input: set pIctlMgr"
1186                            "(mgr=%08x,input=%d,dev=%s)", (int)pIctlMgr,
1187                            input, pIctlMgr->device);
1188                 if (pIctlMgr->device[0] != 0)   {
1189                     /* save same device         */
1190                     psameIctlMgr = pIctlMgr;
1191                 }
1192                 else    {
1193                     /* first device             */
1194                     strncpy(pIctlMgr->device, device, sizeof(pIctlMgr->device)-1);
1195                     psameIctlMgr = NULL;
1196                     break;
1197                 }
1198             }
1199         }
1200         if (psameIctlMgr)   {
1201             /* client(device input controller) exist, but other device  */
1202             pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
1203             if (pIctlMgr == NULL) {
1204                 uifw_error("ico_device_bind: Leave(No Memory)");
1205                 return;
1206             }
1207             memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1208             wl_list_init(&pIctlMgr->ico_ictl_input);
1209             pIctlMgr->client = psameIctlMgr->client;
1210             pIctlMgr->mgr_resource = psameIctlMgr->mgr_resource;
1211
1212             wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1213         }
1214     }
1215
1216     if (type)   {
1217         pIctlMgr->type = type;
1218     }
1219
1220     /* search and add input switch  */
1221     wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
1222         if (pInput->input == input)     break;
1223     }
1224     if (&pInput->link == &pIctlMgr->ico_ictl_input)    {
1225         uifw_trace("ico_device_configure_input: create %s.%s(%d) switch",
1226                    device, swname, input);
1227         pInput = (struct ico_ictl_input *)malloc(sizeof(struct ico_ictl_input));
1228         if (pInput == NULL) {
1229             uifw_error("ico_device_configure_input: Leave(No Memory)");
1230             return;
1231         }
1232         memset(pInput, 0, sizeof(struct ico_ictl_input));
1233         if (swname) {
1234             strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1235         }
1236         else    {
1237             strcpy(pInput->swname, "(Unknown)");
1238         }
1239         wl_list_insert(pIctlMgr->ico_ictl_input.prev, &pInput->link);
1240     }
1241     if (swname) {
1242         strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1243     }
1244     pInput->input = input;
1245     memset(pInput->code, 0, sizeof(pInput->code));
1246     pInput->ncode = 1;
1247     pInput->code[0].code = code;
1248     if (codename)   {
1249         strncpy(pInput->code[0].name, codename, sizeof(pInput->code[0].name)-1);
1250     }
1251
1252     if (client == NULL) {
1253         /* internal call for table create   */
1254         uifw_trace("ico_device_configure_input: Leave(table create)");
1255         return;
1256     }
1257     pIctlMgr->client = client;
1258
1259     /* send to application and manager(ex.HomeScreen)   */
1260     wl_list_for_each (pAppMgr, &pInputMgr->app_list, link)  {
1261         if (pAppMgr->resource == NULL)  continue;
1262         if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
1263
1264         uifw_trace("ico_device_configure_input: send capabilities to app(%s) %s.%s[%d]",
1265                    pAppMgr->appid, device, pInput->swname, input);
1266         ico_exinput_send_capabilities(pAppMgr->resource, device, pIctlMgr->type,
1267                                       pInput->swname, input,
1268                                       pInput->code[0].name, pInput->code[0].code);
1269     }
1270     uifw_trace("ico_device_configure_input: Leave");
1271 }
1272
1273 /*--------------------------------------------------------------------------*/
1274 /**
1275  * @brief   ico_device_configure_code: add input switch from Device Input Controller.
1276  *
1277  * @param[in]   client          client(Device Input Controller)
1278  * @param[in]   resource        resource of request
1279  * @param[in]   device          device name
1280  * @param[in]   input           input switch number
1281  * @param[in]   codename        input code name
1282  * @param[in]   code            input code number
1283  * @return      none
1284  */
1285 /*--------------------------------------------------------------------------*/
1286 static void
1287 ico_device_configure_code(struct wl_client *client, struct wl_resource *resource,
1288                           const char *device, int32_t input,
1289                           const char *codename, int32_t code)
1290 {
1291     uifw_trace("ico_device_configure_code: Enter(client=%08x,dev=%s,input=%d,code=%d[%s])",
1292                (int)client, device, input, code, codename ? codename : " ");
1293
1294     int     i;
1295     struct ico_ictl_mgr     *pIctlMgr;
1296     struct ico_ictl_input   *pInput;
1297     struct ico_app_mgr      *pAppMgr;
1298
1299     pIctlMgr = find_ictlmgr_by_device(device);
1300     if (! pIctlMgr) {
1301         uifw_warn("ico_device_configure_code: Leave(dev=%s dose not exist)", device);
1302         return;
1303     }
1304     /* search input switch      */
1305     wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
1306         if (pInput->input == input)     break;
1307     }
1308     if (&pInput->link == &pIctlMgr->ico_ictl_input)    {
1309         uifw_warn("ico_device_configure_code: Leave(input=%s.%d dose not exist)",
1310                   device, input);
1311         return;
1312     }
1313
1314     /* search input code        */
1315     for (i = 0; i < pInput->ncode; i++) {
1316         if (pInput->code[i].code == code)   break;
1317     }
1318     if (i >= pInput->ncode) {
1319         /* code dose not exist, add */
1320         if (pInput->ncode >= ICO_MINPUT_MAX_CODES) {
1321             uifw_warn("ico_device_configure_code: Leave(input=%s.%d code overflow)",
1322                       device, input);
1323             return;
1324         }
1325         i = pInput->ncode;
1326         pInput->ncode ++;
1327         pInput->code[i].code = code;
1328     }
1329     memset(pInput->code[i].name, 0, sizeof(pInput->code[i].name));
1330     strncpy(pInput->code[i].name, codename, sizeof(pInput->code[i].name)-1);
1331
1332     /* send to application and manager(ex.HomeScreen)   */
1333     wl_list_for_each (pAppMgr, &pInputMgr->app_list, link)  {
1334         if (pAppMgr->resource == NULL)  continue;
1335         if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
1336         uifw_trace("ico_device_configure_input: send code to app(%s) %s.%s[%d]",
1337                    pAppMgr->appid, device, pInput->swname, input);
1338         ico_exinput_send_code(pAppMgr->resource, device, input,
1339                               pInput->code[i].name, pInput->code[i].code);
1340     }
1341     uifw_trace("ico_device_configure_code: Leave");
1342 }
1343
1344 /*--------------------------------------------------------------------------*/
1345 /**
1346  * @brief   ico_device_input_event: device input event from Device Input Controller.
1347  *
1348  * @param[in]   client          client(Device Input Controller)
1349  * @param[in]   resource        resource of request
1350  * @param[in]   time            device input time(miri-sec)
1351  * @param[in]   device          device name
1352  * @param[in]   input           input switch number
1353  * @param[in]   code            input code number
1354  * @param[in]   state           input state(1=On, 0=Off)
1355  * @return      none
1356  */
1357 /*--------------------------------------------------------------------------*/
1358 static void
1359 ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
1360                        uint32_t time, const char *device,
1361                        int32_t input, int32_t code, int32_t state)
1362 {
1363     uifw_trace("ico_device_input_event: Enter(time=%d,dev=%s,input=%d,code=%d,state=%d)",
1364                time, device, input, code, state);
1365
1366     struct ico_ictl_mgr     *pIctlMgr;
1367     struct ico_ictl_input   *pInput;
1368
1369     /* find input devcie by client      */
1370     pIctlMgr = find_ictlmgr_by_device(device);
1371     if (! pIctlMgr) {
1372         uifw_error("ico_device_input_event: Leave(Unknown device(%s))", device);
1373         return;
1374     }
1375     /* find input switch by input Id    */
1376     pInput = find_ictlinput_by_input(pIctlMgr, input);
1377     if (! pInput) {
1378         uifw_warn("ico_device_input_event: Leave(Unknown input(%s,%d))",
1379                   pIctlMgr->device, input);
1380         return;
1381     }
1382
1383     if (! pInput->app)  {
1384         uifw_trace("ico_device_input_event: Leave(%s.%s not assign)",
1385                   pIctlMgr->device, pInput->swname);
1386         return;
1387     }
1388
1389     /* send event to application        */
1390     uifw_trace("ico_device_input_event: send event=%s.%s[%d],%d,%d to App.%s",
1391                pIctlMgr->device, pInput->swname, input, code, state, pInput->app->appid);
1392     ico_exinput_send_input(pInput->app->resource, time, pIctlMgr->device,
1393                            input, code, state);
1394
1395     uifw_trace("ico_device_input_event: Leave");
1396 }
1397
1398 /*--------------------------------------------------------------------------*/
1399 /**
1400  * @brief   ico_control_bind: ico_input_mgr_control bind from HomeScreen
1401  *
1402  * @param[in]   client          client(HomeScreen)
1403  * @param[in]   data            data(unused)
1404  * @param[in]   version         protocol version(unused)
1405  * @param[in]   id              client object id
1406  * @return      none
1407  */
1408 /*--------------------------------------------------------------------------*/
1409 static void
1410 ico_control_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1411 {
1412     char                    *appid;
1413     struct ico_app_mgr      *pAppMgr;
1414
1415     uifw_trace("ico_control_bind: Enter(client=%08x)", (int)client);
1416     appid = ico_window_mgr_get_appid(client);
1417
1418     if (! appid)    {
1419         /* client dose not exist        */
1420         uifw_warn("ico_control_bind: Leave(client=%08x dose not exist)", (int)client);
1421         return;
1422     }
1423
1424     /* find application         */
1425     pAppMgr = find_app_by_appid(appid);
1426     if (! pAppMgr)  {
1427         /* create Application Management Table  */
1428         pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1429         if (! pAppMgr)  {
1430             uifw_error("ico_control_bind: Leave(No Memory)");
1431             return;
1432         }
1433         memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
1434         strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
1435         wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
1436     }
1437     pAppMgr->client = client;
1438     if (! pAppMgr->mgr_resource)    {
1439         pAppMgr->mgr_resource = wl_resource_create(client,
1440                                                    &ico_input_mgr_control_interface, 1, id);
1441         if (pAppMgr->mgr_resource)  {
1442             wl_resource_set_implementation(pAppMgr->mgr_resource,
1443                                            &ico_input_mgr_implementation,
1444                                            pInputMgr, ico_control_unbind);
1445         }
1446     }
1447     uifw_trace("ico_control_bind: Leave");
1448 }
1449
1450 /*--------------------------------------------------------------------------*/
1451 /**
1452  * @brief   ico_control_unbind: ico_input_mgr_control unbind from HomeScreen
1453  *
1454  * @param[in]   resource        client resource(HomeScreen)
1455  * @return      none
1456  */
1457 /*--------------------------------------------------------------------------*/
1458 static void
1459 ico_control_unbind(struct wl_resource *resource)
1460 {
1461     struct ico_app_mgr  *pAppMgr;
1462
1463     uifw_trace("ico_control_unbind: Enter(resource=%08x)", (int)resource);
1464
1465     wl_list_for_each (pAppMgr, &pInputMgr->app_list, link)  {
1466         if (pAppMgr->mgr_resource == resource)  {
1467             uifw_trace("ico_control_unbind: find app.%s", pAppMgr->appid);
1468             pAppMgr->mgr_resource = NULL;
1469             break;
1470         }
1471     }
1472     uifw_trace("ico_control_unbind: Leave");
1473 }
1474
1475 /*--------------------------------------------------------------------------*/
1476 /**
1477  * @brief   ico_device_bind: ico_input_mgr_device bind from Device Input Controller
1478  *
1479  * @param[in]   client          client(Device Input Controller)
1480  * @param[in]   data            data(unused)
1481  * @param[in]   version         protocol version
1482  * @param[in]   id              client object id
1483  * @return      none
1484  */
1485 /*--------------------------------------------------------------------------*/
1486 static void
1487 ico_device_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1488 {
1489     struct ico_ictl_mgr *pIctlMgr;
1490     struct wl_resource  *mgr_resource;
1491
1492     uifw_trace("ico_device_bind: Enter(client=%08x)", (int)client);
1493
1494     /* create ictl mgr table */
1495     pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
1496     if (pIctlMgr == NULL) {
1497         uifw_error("ico_device_bind: Leave(No Memory)");
1498         return;
1499     }
1500     memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1501     wl_list_init(&pIctlMgr->ico_ictl_input);
1502     pIctlMgr->client = client;
1503
1504     /* add list */
1505     wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1506
1507     mgr_resource = wl_resource_create(client, &ico_input_mgr_device_interface, 1, id);
1508     if (mgr_resource)   {
1509         pIctlMgr->mgr_resource = mgr_resource;
1510         wl_resource_set_implementation(mgr_resource, &input_mgr_ictl_implementation,
1511                                        pIctlMgr, ico_device_unbind);
1512     }
1513     uifw_trace("ico_device_bind: Leave");
1514 }
1515
1516 /*--------------------------------------------------------------------------*/
1517 /**
1518  * @brief   ico_device_unbind: ico_input_mgr_device unbind from Device Input Controller
1519  *
1520  * @param[in]   resource        client resource(Device Input Controller)
1521  * @return      none
1522  */
1523 /*--------------------------------------------------------------------------*/
1524 static void
1525 ico_device_unbind(struct wl_resource *resource)
1526 {
1527     uifw_trace("ico_device_unbind: Enter(resource=%08x)", (int)resource);
1528     uifw_trace("ico_device_unbind: Leave");
1529 }
1530
1531 /*--------------------------------------------------------------------------*/
1532 /**
1533  * @brief   ico_exinput_bind: ico_exinput bind from Application
1534  *
1535  * @param[in]   client          client(Application)
1536  * @param[in]   data            data(unused)
1537  * @param[in]   version         protocol version(unused)
1538  * @param[in]   id              client object id
1539  * @return      none
1540  */
1541 /*--------------------------------------------------------------------------*/
1542 static void
1543 ico_exinput_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1544 {
1545     int                     i;
1546     char                    *appid;
1547     struct ico_app_mgr      *pAppMgr;
1548     struct ico_ictl_mgr     *pIctlMgr;
1549     struct ico_ictl_input   *pInput;
1550
1551     appid = ico_window_mgr_get_appid(client);
1552     uifw_trace("ico_exinput_bind: Enter(client=%08x,%s)", (int)client,
1553                appid ? appid : "(NULL)");
1554
1555     if (! appid)    {
1556         /* client dose not exist        */
1557         uifw_warn("ico_exinput_bind: Leave(client=%08x dose not exist)", (int)client);
1558         return;
1559     }
1560
1561     /* find application         */
1562     pAppMgr = find_app_by_appid(appid);
1563     if (! pAppMgr)  {
1564         /* create Application Management Table  */
1565         pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1566         if (! pAppMgr)  {
1567             uifw_error("ico_exinput_bind: Leave(No Memory)");
1568             return;
1569         }
1570         memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
1571         strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
1572         wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
1573         uifw_trace("ico_exinput_bind: Create App.%s table", appid);
1574     }
1575     pAppMgr->client = client;
1576     if (! pAppMgr->resource)    {
1577         pAppMgr->resource = wl_resource_create(client, &ico_exinput_interface, 1, id);
1578         if (pAppMgr->resource)  {
1579             wl_resource_set_implementation(pAppMgr->resource, &ico_exinput_implementation,
1580                                            pInputMgr, ico_exinput_unbind);
1581         }
1582     }
1583
1584     /* send all capabilities    */
1585     wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link)    {
1586         if (pIctlMgr->client == NULL)   {
1587             uifw_trace("ico_exinput_bind: Input controller.%s not initialized",
1588                        pIctlMgr->device);
1589             continue;
1590         }
1591
1592         wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
1593             if (pInput->swname[0] == 0) {
1594                 uifw_trace("ico_exinput_bind: Input %s not initialized", pIctlMgr->device);
1595                 continue;
1596             }
1597             if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) {
1598                 uifw_trace("ico_exinput_bind: Input %s.%s fixed assign to App.%s",
1599                            pIctlMgr->device, pInput->swname, pInput->app->appid);
1600                 continue;
1601             }
1602             uifw_trace("ico_exinput_bind: send capabilities to app(%s) %s.%s[%d]",
1603                        pAppMgr->appid, pIctlMgr->device, pInput->swname, pInput->input);
1604             ico_exinput_send_capabilities(pAppMgr->resource, pIctlMgr->device,
1605                                           pIctlMgr->type, pInput->swname, pInput->input,
1606                                           pInput->code[0].name, pInput->code[0].code);
1607             for (i = 1; i < pInput->ncode; i++) {
1608                 ico_exinput_send_code(pAppMgr->resource, pIctlMgr->device, pInput->input,
1609                                       pInput->code[i].name, pInput->code[i].code);
1610             }
1611         }
1612     }
1613     uifw_trace("ico_exinput_bind: Leave");
1614 }
1615
1616 /*--------------------------------------------------------------------------*/
1617 /**
1618  * @brief   ico_exinput_unbind: ico_exinput unbind from Application
1619  *
1620  * @param[in]   resource        client resource(Application)
1621  * @return      none
1622  */
1623 /*--------------------------------------------------------------------------*/
1624 static void
1625 ico_exinput_unbind(struct wl_resource *resource)
1626 {
1627     struct ico_app_mgr      *pAppMgr;
1628     struct ico_app_mgr      *pAppMgrTmp;
1629     struct ico_ictl_mgr     *pIctlMgr;
1630     struct ico_ictl_input   *pInput;
1631     int                     fix = 0;
1632
1633     uifw_trace("ico_exinput_unbind: Enter(resource=%08x)", (int)resource);
1634
1635     wl_list_for_each_safe (pAppMgr, pAppMgrTmp, &pInputMgr->app_list, link) {
1636         if (pAppMgr->resource == resource)  {
1637             uifw_trace("ico_exinput_unbind: find app.%s", pAppMgr->appid);
1638
1639             /* release application from input switch    */
1640             wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link)    {
1641                 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
1642                     if (pInput->app == pAppMgr) {
1643                         if (pInput->fix == 0)   {
1644                             uifw_trace("ico_exinput_unbind: app.%s remove %s.%s",
1645                                        pAppMgr->appid, pIctlMgr->device, pInput->swname);
1646                             pInput->app = NULL;
1647                         }
1648                         else    {
1649                             uifw_trace("ico_exinput_unbind: app.%s fix assign %s.%s",
1650                                        pAppMgr->appid, pIctlMgr->device, pInput->swname);
1651                             fix ++;
1652                         }
1653                     }
1654                 }
1655             }
1656             if (fix == 0)   {
1657                 wl_list_remove(&pAppMgr->link);
1658                 free(pAppMgr);
1659             }
1660             else    {
1661                 pAppMgr->client = NULL;
1662                 pAppMgr->resource = NULL;
1663             }
1664         }
1665     }
1666     uifw_trace("ico_exinput_unbind: Leave");
1667 }
1668
1669 /*--------------------------------------------------------------------------*/
1670 /**
1671  * @brief   find_ictlmgr_by_device: find Input Controller by device name
1672  *
1673  * @param[in]   device          device name
1674  * @return      Input Controller Manager table address
1675  * @retval      !=NULL          address
1676  * @retval      ==NULL          not exist
1677  */
1678 /*--------------------------------------------------------------------------*/
1679 static struct ico_ictl_mgr *
1680 find_ictlmgr_by_device(const char *device)
1681 {
1682     struct ico_ictl_mgr     *pIctlMgr;
1683
1684     wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link)    {
1685         uifw_debug("find_ictlmgr_by_device: <%s> vs <%s>", device, pIctlMgr->device);
1686         if (strcmp(pIctlMgr->device, device) == 0)  {
1687             return pIctlMgr;
1688         }
1689     }
1690     return NULL;
1691 }
1692
1693 /*--------------------------------------------------------------------------*/
1694 /**
1695  * @brief   find_ictlinput_by_input: find Input Switch by input Id
1696  *
1697  * @param[in]   pIctlMgr        Input Controller device
1698  * @param[in]   input           Input Id
1699  * @return      Input Switch table address
1700  * @retval      !=NULL          address
1701  * @retval      ==NULL          not exist
1702  */
1703 /*--------------------------------------------------------------------------*/
1704 static struct ico_ictl_input *
1705 find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr, const int32_t input)
1706 {
1707     struct ico_ictl_input   *pInput;
1708
1709     wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link)  {
1710         if (pInput->input == input) {
1711             return pInput;
1712         }
1713     }
1714     return NULL;
1715 }
1716
1717 /*--------------------------------------------------------------------------*/
1718 /**
1719  * @brief   find_app_by_appid: find Application by application Id
1720  *
1721  * @param[in]   appid           application Id
1722  * @return      Application Management table address
1723  * @retval      !=NULL          address
1724  * @retval      ==NULL          not exist
1725  */
1726 /*--------------------------------------------------------------------------*/
1727 static struct ico_app_mgr *
1728 find_app_by_appid(const char *appid)
1729 {
1730     struct ico_app_mgr      *pAppMgr;
1731
1732     wl_list_for_each (pAppMgr, &pInputMgr->app_list, link)  {
1733         if (strcmp(pAppMgr->appid, appid) == 0) {
1734             return pAppMgr;
1735         }
1736     }
1737     return NULL;
1738 }
1739
1740 /*--------------------------------------------------------------------------*/
1741 /**
1742  * @brief   module_init: initialization of this plugin
1743  *
1744  * @param[in]   ec          weston compositor
1745  * @param[in]   argc        number of arguments(unused)
1746  * @param[in]   argv        argument list(unused)
1747  * @return      result
1748  * @retval      0           OK
1749  * @retval      -1          error
1750  */
1751 /*--------------------------------------------------------------------------*/
1752 WL_EXPORT int
1753 module_init(struct weston_compositor *ec, int *argc, char *argv[])
1754 {
1755     struct uifw_region_mng  *p;
1756     int     i;
1757
1758     uifw_info("ico_input_mgr: Enter(module_init)");
1759
1760     /* initialize management table */
1761     pInputMgr = (struct ico_input_mgr *)malloc(sizeof(struct ico_input_mgr));
1762     if (pInputMgr == NULL) {
1763         uifw_trace("ico_input_mgr: malloc failed");
1764         return -1;
1765     }
1766     memset(pInputMgr, 0, sizeof(struct ico_input_mgr));
1767     pInputMgr->compositor = ec;
1768
1769     /* interface to desktop manager(ex.HomeScreen)  */
1770     if (wl_global_create(ec->wl_display, &ico_input_mgr_control_interface, 1,
1771                          pInputMgr, ico_control_bind) == NULL) {
1772         uifw_trace("ico_input_mgr: wl_global_create mgr failed");
1773         return -1;
1774     }
1775
1776     /* interface to Input Controller(ictl) */
1777     if (wl_global_create(ec->wl_display, &ico_input_mgr_device_interface, 1,
1778                          pInputMgr, ico_device_bind) == NULL) {
1779         uifw_trace("ico_input_mgr: wl_global_create ictl failed");
1780         return -1;
1781     }
1782
1783     /* interface to App(exinput) */
1784     if (wl_global_create(ec->wl_display, &ico_exinput_interface, 1,
1785                          pInputMgr, ico_exinput_bind) == NULL) {
1786         uifw_trace("ico_input_mgr: wl_global_create exseat failed");
1787         return -1;
1788     }
1789
1790     /* initialize list */
1791     wl_list_init(&pInputMgr->ictl_list);
1792     wl_list_init(&pInputMgr->app_list);
1793     wl_list_init(&pInputMgr->dev_list);
1794     wl_list_init(&pInputMgr->free_region);
1795     p = malloc(sizeof(struct uifw_region_mng)*100);
1796     if (p)  {
1797         memset(p, 0, sizeof(struct uifw_region_mng)*100);
1798         for (i = 0; i < 100; i++, p++)  {
1799             wl_list_insert(pInputMgr->free_region.prev, &p->link);
1800         }
1801     }
1802
1803     /* found input seat */
1804     pInputMgr->seat = container_of(ec->seat_list.next, struct weston_seat, link);
1805
1806     /* set hook for input region control    */
1807     ico_window_mgr_set_hook_visible(ico_input_hook_region_visible);
1808     ico_window_mgr_set_hook_destory(ico_input_hook_region_destroy);
1809
1810     uifw_info("ico_input_mgr: Leave(module_init)");
1811     return 0;
1812 }
1813