2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2013 TOYOTA MOTOR CORPORATION.
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.
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.
25 * @brief Multi Input Manager (Weston(Wayland) PlugIn)
35 #include <linux/input.h>
40 #include <sys/types.h>
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"
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
56 /* structure definition */
57 struct uifw_region_mng;
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;
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 */
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 */
86 /* Input Controller Management Table */
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 */
96 /* Application Management Table */
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 */
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 */
112 #define PENDING_X 0x01 /* pending X coordinate */
113 #define PENDING_Y 0x02 /* pending Y coordinate */
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 */
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 */
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);
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,
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);
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
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
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
221 /* definition of class variable */
222 struct ico_input_mgr *pInputMgr = NULL;
225 /*--------------------------------------------------------------------------*/
227 * @brief ico_mgr_add_input_app: add input event to application from HomeScreen.
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)
238 /*--------------------------------------------------------------------------*/
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)
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);
247 struct ico_ictl_mgr *pIctlMgr;
248 struct ico_ictl_input *pInput;
249 struct ico_app_mgr *pAppMgr;
251 pIctlMgr = find_ictlmgr_by_device(device);
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);
257 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
261 pInput = find_ictlinput_by_input(pIctlMgr, input);
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);
267 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
272 /* find application */
273 pAppMgr = find_app_by_appid(appid);
275 /* create Application Management Table */
276 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
278 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
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);
286 pInput->app = pAppMgr;
288 uifw_trace("ico_mgr_add_input_app: Leave(%s.%s[%d] assign to %s)",
289 pIctlMgr->device, pInput->swname ? pInput->swname : "(NULL)", input,
293 /*--------------------------------------------------------------------------*/
295 * @brief ico_mgr_del_input_app: delete input event at application from HomeScreen.
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
307 /*--------------------------------------------------------------------------*/
309 ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
310 const char *appid, const char *device, int32_t input)
312 uifw_trace("ico_mgr_del_input_app: Enter(appid=%s,dev=%s,input=%d)",
313 appid ? appid : "(NULL)", device ? device : "(NULL)", input);
316 struct ico_ictl_mgr *pIctlMgr = NULL;
317 struct ico_ictl_input *pInput = NULL;
318 struct ico_app_mgr *pAppMgr;
320 if ((device != NULL) && (*device != 0)) {
321 pIctlMgr = find_ictlmgr_by_device(device);
323 /* not configure input controller, NOP */
324 uifw_trace("ico_mgr_del_input_app: Leave(%s dose not exist)", device);
328 pInput = find_ictlinput_by_input(pIctlMgr, input);
330 /* not configure input switch, NOP */
331 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d dose not exist)",
341 /* find application */
342 if ((appid != NULL) && (*appid != 0)) {
343 pAppMgr = find_app_by_appid(appid);
345 /* application dose not exist, NOP */
346 uifw_trace("ico_mgr_del_input_app: Leave(app.%s dose not exist)", appid);
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)");
358 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d app.%s deleted)",
359 device, input, appid);
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);
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);
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);
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);
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);
418 uifw_trace("ico_mgr_del_input_app: Leave");
421 /*--------------------------------------------------------------------------*/
423 * @brief ico_mgr_send_input_event: send input event from manager
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
436 /*--------------------------------------------------------------------------*/
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)
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 */
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,
462 /* search pseudo input device */
463 wl_list_for_each (dev, &pInputMgr->dev_list, link) {
464 if ((dev->type == type) && (dev->no == deviceno)) break;
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));
471 uifw_error("ico_mgr_send_input_event: Leave(No Memory)");
474 memset(dev, 0, sizeof(struct uifw_input_device));
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);
482 wl_list_insert(pInputMgr->dev_list.prev, &dev->link);
485 /* convert pending event */
487 if ((code & 0xffff0000) != (EV_REL << 16)) {
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 */
496 if (dev->pending & PENDING_Y) {
498 dev->y = dev->pend_y;
502 event = EVENT_MOTION;
506 dev->pending |= PENDING_X;
507 event = EVENT_PENDING;
511 if (dev->pending & PENDING_X) {
512 dev->x = dev->pend_x;
517 event = EVENT_MOTION;
521 dev->pending |= PENDING_Y;
522 event = EVENT_PENDING;
526 dev->x = (short)(value >> 16);
527 dev->y = (short)(value & 0x0ffff);
531 event = EVENT_MOTION;
533 case ((EV_REL << 16) | REL_X):
534 if (dev->pending & PENDING_Y) {
536 dev->y = dev->pend_y;
540 event = EVENT_MOTION;
543 dev->pend_x = dev->x + value;
544 dev->pending |= PENDING_X;
545 event = EVENT_PENDING;
548 case ((EV_REL << 16) | REL_Y):
549 if (dev->pending & PENDING_X) {
550 dev->x = dev->pend_x;
555 event = EVENT_MOTION;
558 dev->pend_x = dev->y + value;
559 dev->pending |= PENDING_Y;
560 event = EVENT_PENDING;
563 case ((EV_REL << 16) | REL_Z):
564 dev->x += (short)(value >> 16);
565 dev->y += (short)(value & 0x0ffff);
569 event = EVENT_MOTION;
572 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
576 event = EVENT_BUTTON;
586 if (event == EVENT_PENDING) {
587 #if 0 /* too many log */
588 uifw_debug("ico_mgr_send_input_event: Leave(event pending)");
597 ctime = weston_compositor_get_time();
599 fix_x = wl_fixed_from_int(dev->x + dev->disp_x);
600 fix_y = wl_fixed_from_int(dev->y + dev->disp_y);
602 if ((surfaceid == 0) && ((target == NULL) || (*target == 0) || (*target == ' '))) {
603 /* send event to surface via weston */
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);
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)");
616 event = EVENT_BUTTON;
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)");
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 */
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);
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);
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);
653 notify_motion_absolute(pInputMgr->seat, ctime, fix_x, fix_y);
657 uifw_trace("ico_mgr_send_input_event: notify_button(%d,%d)", code, value);
658 if (pInputMgr->seat->pointer) {
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);
668 notify_button(pInputMgr->seat, ctime, code,
669 value ? WL_POINTER_BUTTON_STATE_PRESSED :
670 WL_POINTER_BUTTON_STATE_RELEASED);
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);
679 if (pInputMgr->seat->num_tp > 0) {
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);
687 uifw_debug("ico_mgr_send_input_event: num=%d Up is false",
688 pInputMgr->seat->num_tp);
692 if (pInputMgr->seat->touch->grab) {
693 notify_touch(pInputMgr->seat, ctime,
694 0, fix_x, fix_y, WL_TOUCH_UP);
697 uifw_debug("ico_mgr_send_input_event: reset num count down(%d)",
698 pInputMgr->seat->num_tp);
699 pInputMgr->seat->num_tp --;
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 */
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);
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 */
726 else if (value == 7) {
730 grabsave = pInputMgr->seat->touch->focus;
731 uifw_trace("ico_mgr_send_input_event: notify_touch(UP) org=%08x",
733 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
734 weston_touch_set_focus(pInputMgr->seat, dev->grab);
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);
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 */
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);
754 uifw_trace("ico_mgr_send_input_event: unknown event=%d", event);
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);
763 if ((target != NULL) && (*target != 0) && (*target != ' ')) {
764 /* send event to fixed application */
766 /* get application surface */
767 usurf = ico_window_mgr_get_client_usurf(target);
769 uifw_trace("ico_mgr_send_input_event: Leave(window=%s dose not exist)",
775 /* get UIFW surface */
776 usurf = ico_window_mgr_get_usurf(surfaceid);
778 uifw_trace("ico_mgr_send_input_event: Leave(surface dose not exist)");
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));
791 wl_touch_send_motion(cres, ctime, 0, fix_x, fix_y);
795 cres = wl_resource_find_for_client(
796 &pInputMgr->seat->pointer->resource_list,
797 wl_resource_get_client(usurf->surface->resource));
799 wl_pointer_send_motion(cres, ctime, fix_x, fix_y);
804 cres = wl_resource_find_for_client(
805 &pInputMgr->seat->pointer->resource_list,
806 wl_resource_get_client(usurf->surface->resource));
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);
815 cres = wl_resource_find_for_client(
816 &pInputMgr->seat->touch->resource_list,
817 wl_resource_get_client(usurf->surface->resource));
819 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
821 wl_touch_send_down(cres, serial, ctime, usurf->surface->resource, 0,
825 wl_touch_send_up(cres, serial, ctime, 0);
830 cres = wl_resource_find_for_client(
831 &pInputMgr->seat->keyboard->resource_list,
832 wl_resource_get_client(usurf->surface->resource));
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);
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);
855 #if 0 /* too many log */
856 uifw_debug("ico_mgr_send_input_event: Leave");
860 /*--------------------------------------------------------------------------*/
862 * @brief ico_mgr_set_input_region: set input region for haptic devcie
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)
880 /*--------------------------------------------------------------------------*/
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)
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;
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);
898 /* get target surface */
899 usurf = ico_window_mgr_get_client_usurf(target);
901 uifw_warn("ico_mgr_set_input_region: Leave(target<%s> dose not exist)", target);
905 if (wl_list_empty(&pInputMgr->free_region)) {
906 p = malloc(sizeof(struct uifw_region_mng) * 50);
908 uifw_error("ico_mgr_set_input_region: No Memory");
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);
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;
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;
931 p->region.hotspot_x = hotspot_x;
932 p->region.hotspot_y = hotspot_y;
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;
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;
946 p->region.change = ico_window_mgr_is_visible(usurf);
947 wl_list_insert(usurf->input_region.prev, &p->link);
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));
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);
960 uifw_trace("ico_mgr_set_input_region: Leave");
963 /*--------------------------------------------------------------------------*/
965 * @brief ico_mgr_unset_input_region: unset input region for haptic devcie
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
976 /*--------------------------------------------------------------------------*/
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)
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;
990 uifw_trace("ico_mgr_unset_input_region: Enter(%s %d/%d-%d/%d)",
991 target, x, y, width, height);
993 /* get target surface */
994 usurf = ico_window_mgr_get_client_usurf(target);
996 uifw_warn("ico_mgr_unset_input_region: Leave(target<%s> dose not exist)", target);
1000 if ((x <= 0) && (y <= 0) && (width <= 0) && (height <= 0)) {
1007 wl_array_init(&array);
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));
1019 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1020 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1023 wl_list_remove(&p->link);
1024 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1028 /* send region delete to haptic device input controller */
1029 ico_input_send_region_event(&array);
1031 uifw_trace("ico_mgr_unset_input_region: Leave");
1034 /*--------------------------------------------------------------------------*/
1036 * @brief ico_input_hook_region_visible: change surface visibility
1038 * @param[in] usurf UIFW surface
1041 /*--------------------------------------------------------------------------*/
1043 ico_input_hook_region_visible(struct uifw_win_surface *usurf)
1045 struct uifw_region_mng *p; /* input region mamagement table*/
1046 struct ico_uifw_input_region *rp; /* input region */
1047 struct wl_array array;
1051 visible = ico_window_mgr_is_visible(usurf);
1053 uifw_trace("ico_input_hook_region_visible: Entery(surf=%08x, visible=%d)",
1054 usurf->surfaceid, visible);
1056 wl_array_init(&array);
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));
1066 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1068 rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
1071 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1075 p->region.change = visible;
1078 /* send region delete to haptic device input controller */
1079 ico_input_send_region_event(&array);
1082 uifw_trace("ico_input_hook_region_visible: Leave");
1085 /*--------------------------------------------------------------------------*/
1087 * @brief ico_input_hook_region_destroy: destory surface
1089 * @param[in] usurf UIFW surface
1092 /*--------------------------------------------------------------------------*/
1094 ico_input_hook_region_destroy(struct uifw_win_surface *usurf)
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;
1102 uifw_trace("ico_input_hook_region_destroy: Entery(surf=%08x)", usurf->surfaceid);
1104 wl_array_init(&array);
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));
1113 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1114 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1117 wl_list_remove(&p->link);
1118 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1121 /* send region delete to haptic device input controller */
1122 ico_input_send_region_event(&array);
1124 uifw_trace("ico_input_hook_region_destroy: Leave");
1127 /*--------------------------------------------------------------------------*/
1129 * @brief ico_input_send_region_event: send region event to Haptic dic
1131 * @param[in] usurf UIFW surface
1134 /*--------------------------------------------------------------------------*/
1136 ico_input_send_region_event(struct wl_array *array)
1138 struct ico_ictl_mgr *pIctlMgr;
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);
1149 /*--------------------------------------------------------------------------*/
1151 * @brief ico_device_configure_input: configure input device and input switch
1152 * from Device Input Controller.
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
1164 /*--------------------------------------------------------------------------*/
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)
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 : " ");
1174 struct ico_ictl_mgr *pIctlMgr;
1175 struct ico_ictl_mgr *psameIctlMgr;
1176 struct ico_ictl_input *pInput;
1177 struct ico_app_mgr *pAppMgr;
1179 pIctlMgr = find_ictlmgr_by_device(device);
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;
1194 strncpy(pIctlMgr->device, device, sizeof(pIctlMgr->device)-1);
1195 psameIctlMgr = NULL;
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)");
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;
1212 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1217 pIctlMgr->type = type;
1220 /* search and add input switch */
1221 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1222 if (pInput->input == input) break;
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)");
1232 memset(pInput, 0, sizeof(struct ico_ictl_input));
1234 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1237 strcpy(pInput->swname, "(Unknown)");
1239 wl_list_insert(pIctlMgr->ico_ictl_input.prev, &pInput->link);
1242 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1244 pInput->input = input;
1245 memset(pInput->code, 0, sizeof(pInput->code));
1247 pInput->code[0].code = code;
1249 strncpy(pInput->code[0].name, codename, sizeof(pInput->code[0].name)-1);
1252 if (client == NULL) {
1253 /* internal call for table create */
1254 uifw_trace("ico_device_configure_input: Leave(table create)");
1257 pIctlMgr->client = client;
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;
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);
1270 uifw_trace("ico_device_configure_input: Leave");
1273 /*--------------------------------------------------------------------------*/
1275 * @brief ico_device_configure_code: add input switch from Device Input Controller.
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
1285 /*--------------------------------------------------------------------------*/
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)
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 : " ");
1295 struct ico_ictl_mgr *pIctlMgr;
1296 struct ico_ictl_input *pInput;
1297 struct ico_app_mgr *pAppMgr;
1299 pIctlMgr = find_ictlmgr_by_device(device);
1301 uifw_warn("ico_device_configure_code: Leave(dev=%s dose not exist)", device);
1304 /* search input switch */
1305 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1306 if (pInput->input == input) break;
1308 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
1309 uifw_warn("ico_device_configure_code: Leave(input=%s.%d dose not exist)",
1314 /* search input code */
1315 for (i = 0; i < pInput->ncode; i++) {
1316 if (pInput->code[i].code == code) break;
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)",
1327 pInput->code[i].code = code;
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);
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);
1341 uifw_trace("ico_device_configure_code: Leave");
1344 /*--------------------------------------------------------------------------*/
1346 * @brief ico_device_input_event: device input event from Device Input Controller.
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)
1357 /*--------------------------------------------------------------------------*/
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)
1363 uifw_trace("ico_device_input_event: Enter(time=%d,dev=%s,input=%d,code=%d,state=%d)",
1364 time, device, input, code, state);
1366 struct ico_ictl_mgr *pIctlMgr;
1367 struct ico_ictl_input *pInput;
1369 /* find input devcie by client */
1370 pIctlMgr = find_ictlmgr_by_device(device);
1372 uifw_error("ico_device_input_event: Leave(Unknown device(%s))", device);
1375 /* find input switch by input Id */
1376 pInput = find_ictlinput_by_input(pIctlMgr, input);
1378 uifw_warn("ico_device_input_event: Leave(Unknown input(%s,%d))",
1379 pIctlMgr->device, input);
1383 if (! pInput->app) {
1384 uifw_trace("ico_device_input_event: Leave(%s.%s not assign)",
1385 pIctlMgr->device, pInput->swname);
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);
1395 uifw_trace("ico_device_input_event: Leave");
1398 /*--------------------------------------------------------------------------*/
1400 * @brief ico_control_bind: ico_input_mgr_control bind from HomeScreen
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
1408 /*--------------------------------------------------------------------------*/
1410 ico_control_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1413 struct ico_app_mgr *pAppMgr;
1415 uifw_trace("ico_control_bind: Enter(client=%08x)", (int)client);
1416 appid = ico_window_mgr_get_appid(client);
1419 /* client dose not exist */
1420 uifw_warn("ico_control_bind: Leave(client=%08x dose not exist)", (int)client);
1424 /* find application */
1425 pAppMgr = find_app_by_appid(appid);
1427 /* create Application Management Table */
1428 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1430 uifw_error("ico_control_bind: Leave(No Memory)");
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);
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);
1447 uifw_trace("ico_control_bind: Leave");
1450 /*--------------------------------------------------------------------------*/
1452 * @brief ico_control_unbind: ico_input_mgr_control unbind from HomeScreen
1454 * @param[in] resource client resource(HomeScreen)
1457 /*--------------------------------------------------------------------------*/
1459 ico_control_unbind(struct wl_resource *resource)
1461 struct ico_app_mgr *pAppMgr;
1463 uifw_trace("ico_control_unbind: Enter(resource=%08x)", (int)resource);
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;
1472 uifw_trace("ico_control_unbind: Leave");
1475 /*--------------------------------------------------------------------------*/
1477 * @brief ico_device_bind: ico_input_mgr_device bind from Device Input Controller
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
1485 /*--------------------------------------------------------------------------*/
1487 ico_device_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1489 struct ico_ictl_mgr *pIctlMgr;
1490 struct wl_resource *mgr_resource;
1492 uifw_trace("ico_device_bind: Enter(client=%08x)", (int)client);
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)");
1500 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1501 wl_list_init(&pIctlMgr->ico_ictl_input);
1502 pIctlMgr->client = client;
1505 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1507 mgr_resource = wl_resource_create(client, &ico_input_mgr_device_interface, 1, id);
1509 pIctlMgr->mgr_resource = mgr_resource;
1510 wl_resource_set_implementation(mgr_resource, &input_mgr_ictl_implementation,
1511 pIctlMgr, ico_device_unbind);
1513 uifw_trace("ico_device_bind: Leave");
1516 /*--------------------------------------------------------------------------*/
1518 * @brief ico_device_unbind: ico_input_mgr_device unbind from Device Input Controller
1520 * @param[in] resource client resource(Device Input Controller)
1523 /*--------------------------------------------------------------------------*/
1525 ico_device_unbind(struct wl_resource *resource)
1527 uifw_trace("ico_device_unbind: Enter(resource=%08x)", (int)resource);
1528 uifw_trace("ico_device_unbind: Leave");
1531 /*--------------------------------------------------------------------------*/
1533 * @brief ico_exinput_bind: ico_exinput bind from Application
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
1541 /*--------------------------------------------------------------------------*/
1543 ico_exinput_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1547 struct ico_app_mgr *pAppMgr;
1548 struct ico_ictl_mgr *pIctlMgr;
1549 struct ico_ictl_input *pInput;
1551 appid = ico_window_mgr_get_appid(client);
1552 uifw_trace("ico_exinput_bind: Enter(client=%08x,%s)", (int)client,
1553 appid ? appid : "(NULL)");
1556 /* client dose not exist */
1557 uifw_warn("ico_exinput_bind: Leave(client=%08x dose not exist)", (int)client);
1561 /* find application */
1562 pAppMgr = find_app_by_appid(appid);
1564 /* create Application Management Table */
1565 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1567 uifw_error("ico_exinput_bind: Leave(No Memory)");
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);
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);
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",
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);
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);
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);
1613 uifw_trace("ico_exinput_bind: Leave");
1616 /*--------------------------------------------------------------------------*/
1618 * @brief ico_exinput_unbind: ico_exinput unbind from Application
1620 * @param[in] resource client resource(Application)
1623 /*--------------------------------------------------------------------------*/
1625 ico_exinput_unbind(struct wl_resource *resource)
1627 struct ico_app_mgr *pAppMgr;
1628 struct ico_app_mgr *pAppMgrTmp;
1629 struct ico_ictl_mgr *pIctlMgr;
1630 struct ico_ictl_input *pInput;
1633 uifw_trace("ico_exinput_unbind: Enter(resource=%08x)", (int)resource);
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);
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);
1649 uifw_trace("ico_exinput_unbind: app.%s fix assign %s.%s",
1650 pAppMgr->appid, pIctlMgr->device, pInput->swname);
1657 wl_list_remove(&pAppMgr->link);
1661 pAppMgr->client = NULL;
1662 pAppMgr->resource = NULL;
1666 uifw_trace("ico_exinput_unbind: Leave");
1669 /*--------------------------------------------------------------------------*/
1671 * @brief find_ictlmgr_by_device: find Input Controller by device name
1673 * @param[in] device device name
1674 * @return Input Controller Manager table address
1675 * @retval !=NULL address
1676 * @retval ==NULL not exist
1678 /*--------------------------------------------------------------------------*/
1679 static struct ico_ictl_mgr *
1680 find_ictlmgr_by_device(const char *device)
1682 struct ico_ictl_mgr *pIctlMgr;
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) {
1693 /*--------------------------------------------------------------------------*/
1695 * @brief find_ictlinput_by_input: find Input Switch by input Id
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
1703 /*--------------------------------------------------------------------------*/
1704 static struct ico_ictl_input *
1705 find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr, const int32_t input)
1707 struct ico_ictl_input *pInput;
1709 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1710 if (pInput->input == input) {
1717 /*--------------------------------------------------------------------------*/
1719 * @brief find_app_by_appid: find Application by application Id
1721 * @param[in] appid application Id
1722 * @return Application Management table address
1723 * @retval !=NULL address
1724 * @retval ==NULL not exist
1726 /*--------------------------------------------------------------------------*/
1727 static struct ico_app_mgr *
1728 find_app_by_appid(const char *appid)
1730 struct ico_app_mgr *pAppMgr;
1732 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1733 if (strcmp(pAppMgr->appid, appid) == 0) {
1740 /*--------------------------------------------------------------------------*/
1742 * @brief module_init: initialization of this plugin
1744 * @param[in] ec weston compositor
1745 * @param[in] argc number of arguments(unused)
1746 * @param[in] argv argument list(unused)
1751 /*--------------------------------------------------------------------------*/
1753 module_init(struct weston_compositor *ec, int *argc, char *argv[])
1755 struct uifw_region_mng *p;
1758 uifw_info("ico_input_mgr: Enter(module_init)");
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");
1766 memset(pInputMgr, 0, sizeof(struct ico_input_mgr));
1767 pInputMgr->compositor = ec;
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");
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");
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");
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);
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);
1803 /* found input seat */
1804 pInputMgr->seat = container_of(ec->seat_list.next, struct weston_seat, link);
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);
1810 uifw_info("ico_input_mgr: Leave(module_init)");