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>
43 #include <wayland-server.h>
44 #include <weston/compositor.h>
45 #include "ico_ivi_common_private.h"
46 #include "ico_ivi_shell_private.h"
47 #include "ico_input_mgr.h"
48 #include "ico_window_mgr_private.h"
49 #include "ico_window_mgr-server-protocol.h"
50 #include "ico_input_mgr-server-protocol.h"
52 /* degine maximum length */
53 #define ICO_MINPUT_DEVICE_LEN 32
54 #define ICO_MINPUT_SW_LEN 20
55 #define ICO_MINPUT_MAX_CODES 20
57 /* structure definition */
58 struct uifw_region_mng;
60 /* working table of Multi Input Manager */
61 struct ico_input_mgr {
62 struct weston_compositor *compositor; /* Weston Compositor */
63 struct wl_list ictl_list; /* Input Controller List */
64 struct wl_list app_list; /* application List */
65 struct wl_list dev_list; /* pseudo device List */
66 struct wl_list free_region; /* free input region table list */
67 struct weston_seat *seat; /* input seat */
68 struct wl_resource *inputmgr;
71 /* Input Switch Table */
72 struct ico_ictl_code {
73 uint16_t code; /* input code numner */
74 char name[ICO_MINPUT_SW_LEN]; /* input code name */
77 struct ico_ictl_input {
78 struct wl_list link; /* link */
79 char swname[ICO_MINPUT_SW_LEN]; /* input switch name */
80 int32_t input; /* input Id */
81 uint16_t fix; /* fixed assign to application */
82 uint16_t ncode; /* number of codes */
83 struct ico_ictl_code code[ICO_MINPUT_MAX_CODES]; /* codes */
84 struct ico_app_mgr *app; /* send event tagret application */
87 /* Input Controller Management Table */
89 struct wl_list link; /* link */
90 struct wl_client *client; /* client */
91 struct wl_resource *mgr_resource; /* resource as manager */
92 char device[ICO_MINPUT_DEVICE_LEN]; /* device name */
93 int type; /* device type */
94 struct wl_list ico_ictl_input; /* list of input switchs */
97 /* Application Management Table */
99 struct wl_list link; /* link */
100 struct wl_client *client; /* client */
101 struct wl_resource *resource; /* resource for send event */
102 struct wl_resource *mgr_resource; /* resource as manager(if NULL, client) */
103 char appid[ICO_IVI_APPID_LENGTH]; /* application id */
106 /* Pseudo Input Device Control Flags */
107 #define EVENT_MOTION 0x01 /* motion event */
108 #define EVENT_BUTTON 0x02 /* button event */
109 #define EVENT_TOUCH 0x03 /* touch event */
110 #define EVENT_KEY 0x04 /* key event */
111 #define EVENT_PENDING 0xff /* pending event input */
113 #define PENDING_X 0x01 /* pending X coordinate */
114 #define PENDING_Y 0x02 /* pending Y coordinate */
116 /* Pseudo Input Device Table */
117 struct uifw_input_device {
118 struct wl_list link; /* link to next device */
119 uint16_t type; /* device type */
120 uint16_t no; /* device number */
121 int disp_x; /* display X coordinate */
122 int disp_y; /* display Y coordinate */
123 int x; /* current X coordinate */
124 int y; /* current Y coordinate */
125 int pend_x; /* pending X coordinate */
126 int pend_y; /* pending Y coordinate */
127 uint16_t node; /* display number */
128 uint16_t pending; /* pending flag */
129 struct weston_surface *grab; /* current grab surface */
132 /* Input Region Table */
133 struct uifw_region_mng {
134 struct wl_list link; /* link pointer */
135 struct ico_uifw_input_region region; /* input region */
138 /* prototype of static function */
139 /* bind input manager form manager */
140 static void ico_control_bind(struct wl_client *client, void *data,
141 uint32_t version, uint32_t id);
142 /* unbind input manager form manager */
143 static void ico_control_unbind(struct wl_resource *resource);
144 /* bind input manager form input controller*/
145 static void ico_device_bind(struct wl_client *client, void *data,
146 uint32_t version, uint32_t id);
147 /* unbind input manager form input controller*/
148 static void ico_device_unbind(struct wl_resource *resource);
149 /* bind input manager(form application) */
150 static void ico_exinput_bind(struct wl_client *client, void *data,
151 uint32_t version, uint32_t id);
152 /* unbind input manager(form application)*/
153 static void ico_exinput_unbind(struct wl_resource *resource);
155 /* find ictl manager by device name */
156 static struct ico_ictl_mgr *find_ictlmgr_by_device(const char *device);
157 /* find ictl input switch by input Id */
158 static struct ico_ictl_input *find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr,
159 const int32_t input);
160 /* find app manager by application Id */
161 static struct ico_app_mgr *find_app_by_appid(const char *appid);
162 /* add input event to application */
163 static void ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
164 const char *appid, const char *device, int32_t input,
165 int32_t fix, int32_t keycode);
166 /* delete input event to application */
167 static void ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
168 const char *appid, const char *device, int32_t input);
169 /* send input event from manager */
170 static void ico_mgr_send_input_event(struct wl_client *client, struct wl_resource *resource,
171 const char *target, uint32_t surfaceid, int32_t type,
172 int32_t deviceno, uint32_t time,
173 int32_t code, int32_t value);
174 /* set input region */
175 static void ico_mgr_set_input_region(struct wl_client *client, struct wl_resource *resource,
176 const char *target, int32_t x, int32_t y,
177 int32_t width, int32_t height, int32_t hotspot_x,
178 int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
179 int32_t cursor_width, int32_t cursor_height,
181 /* unset input region */
182 static void ico_mgr_unset_input_region(struct wl_client *client,
183 struct wl_resource *resource,
184 const char *taret, int32_t x, int32_t y,
185 int32_t width, int32_t height);
186 /* input region set/unset */
187 static void ico_set_input_region(int set, struct uifw_win_surface *usurf,
188 int32_t x, int32_t y, int32_t width, int32_t height,
189 int32_t hotspot_x, int32_t hotspot_y, int32_t cursor_x,
190 int32_t cursor_y, int32_t cursor_width,
191 int32_t cursor_height, uint32_t attr);
192 /* create and regist Input Controller table*/
193 static void ico_device_configure_input(struct wl_client *client,
194 struct wl_resource *resource, const char *device,
195 int32_t type, const char *swname, int32_t input,
196 const char *codename, int32_t code);
197 /* add input to from Input Controller table*/
198 static void ico_device_configure_code(struct wl_client *client,
199 struct wl_resource *resource, const char *device,
200 int32_t input, const char *codename, int32_t code);
201 /* device input event */
202 static void ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
203 uint32_t time, const char *device,
204 int32_t input, int32_t code, int32_t state);
205 static void ico_input_send_region_event(struct wl_array *array);
207 /* definition of Wayland protocol */
208 /* Input Manager Control interface */
209 static const struct ico_input_mgr_control_interface ico_input_mgr_implementation = {
210 ico_mgr_add_input_app,
211 ico_mgr_del_input_app,
212 ico_mgr_send_input_event
215 /* Extended Input interface */
216 static const struct ico_exinput_interface ico_exinput_implementation = {
217 ico_mgr_set_input_region,
218 ico_mgr_unset_input_region
221 /* Input Controller Device interface */
222 static const struct ico_input_mgr_device_interface input_mgr_ictl_implementation = {
223 ico_device_configure_input,
224 ico_device_configure_code,
225 ico_device_input_event
228 /* definition of class variable */
229 struct ico_input_mgr *pInputMgr = NULL;
232 /*--------------------------------------------------------------------------*/
234 * @brief ico_mgr_add_input_app: add input event to application from HomeScreen.
236 * @param[in] client client(HomeScreen)
237 * @param[in] resource resource of request
238 * @param[in] appid target application id
239 * @param[in] device device name
240 * @param[in] input input switch number
241 * @param[in] fix fix to application(1=fix,0=general)
242 * @param[in] keycode switch map to keyboard operation(0=not map to keyboard)
245 /*--------------------------------------------------------------------------*/
247 ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
248 const char *appid, const char *device, int32_t input,
249 int32_t fix, int32_t keycode)
251 uifw_trace("ico_mgr_add_input_app: Enter(appid=%s,dev=%s,input=%d,fix=%d,key=%d)",
252 appid, device, input, fix, keycode);
254 struct ico_ictl_mgr *pIctlMgr;
255 struct ico_ictl_input *pInput;
256 struct ico_app_mgr *pAppMgr;
258 pIctlMgr = find_ictlmgr_by_device(device);
260 /* not configure input controller, create */
261 ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
262 pIctlMgr = find_ictlmgr_by_device(device);
264 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
268 pInput = find_ictlinput_by_input(pIctlMgr, input);
270 /* not configure input switch, create */
271 ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
272 pInput = find_ictlinput_by_input(pIctlMgr, input);
274 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
279 /* find application */
280 pAppMgr = find_app_by_appid(appid);
282 /* create Application Management Table */
283 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
285 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
288 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
289 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
290 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
293 pInput->app = pAppMgr;
295 uifw_trace("ico_mgr_add_input_app: Leave(%s.%s[%d] assign to %s)",
296 pIctlMgr->device, pInput->swname ? pInput->swname : "(NULL)", input,
300 /*--------------------------------------------------------------------------*/
302 * @brief ico_mgr_del_input_app: delete input event at application from HomeScreen.
304 * @param[in] client client(HomeScreen)
305 * @param[in] resource resource of request
306 * @param[in] appid target application id,
307 * if NULL, all applictions without fixed assign switch
308 * @param[in] device device name
309 * if NULL, all device without fixed assign switch
310 * @param[in] input input switch number
311 * if -1, all input without fixed assign switch
314 /*--------------------------------------------------------------------------*/
316 ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
317 const char *appid, const char *device, int32_t input)
319 uifw_trace("ico_mgr_del_input_app: Enter(appid=%s,dev=%s,input=%d)",
320 appid ? appid : "(NULL)", device ? device : "(NULL)", input);
323 struct ico_ictl_mgr *pIctlMgr = NULL;
324 struct ico_ictl_input *pInput = NULL;
325 struct ico_app_mgr *pAppMgr;
327 if ((device != NULL) && (*device != 0)) {
328 pIctlMgr = find_ictlmgr_by_device(device);
330 /* not configure input controller, NOP */
331 uifw_trace("ico_mgr_del_input_app: Leave(%s dose not exist)", device);
335 pInput = find_ictlinput_by_input(pIctlMgr, input);
337 /* not configure input switch, NOP */
338 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d dose not exist)",
348 /* find application */
349 if ((appid != NULL) && (*appid != 0)) {
350 pAppMgr = find_app_by_appid(appid);
352 /* application dose not exist, NOP */
353 uifw_trace("ico_mgr_del_input_app: Leave(app.%s dose not exist)", appid);
358 if (pInput->app != pAppMgr) {
359 /* not same application, NOP */
360 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d not app.%s, current %s)",
361 device, input, appid,
362 pInput->app ? pInput->app->appid : "(NULL)");
365 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d app.%s deleted)",
366 device, input, appid);
371 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
372 if ((pInput->fix == 0) && (pInput->app == pAppMgr)) {
373 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
374 pIctlMgr->device, pInput->input, appid);
381 /* reset all device without fixed assign */
382 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
383 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
384 if ((pInput->fix == 0) && (pInput->app == pAppMgr)) {
385 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
386 pIctlMgr->device, pInput->input, pInput->app->appid);
396 if ((pInput->fix == 0) && (pInput->app != NULL)) {
397 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
398 pIctlMgr->device, pInput->input, pInput->app->appid);
403 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
404 if ((pInput->fix == 0) && (pInput->app != NULL)) {
405 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
406 pIctlMgr->device, pInput->input, pInput->app->appid);
413 /* reset all application without fixed assign */
414 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
415 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
416 if ((pInput->fix == 0) && (pInput->app != NULL)) {
417 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
418 pIctlMgr->device, pInput->input, pInput->app->appid);
425 uifw_trace("ico_mgr_del_input_app: Leave");
428 /*--------------------------------------------------------------------------*/
430 * @brief ico_mgr_send_input_event: send input event from manager
432 * @param[in] client client(HomeScreen)
433 * @param[in] resource resource of request
434 * @param[in] target target window name and application id
435 * @param[in] surfaceid target surface id
436 * @param[in] type event device type
437 * @param[in] deviceno device number
438 * @param[in] time event time (if 0, generate)
439 * @param[in] code event code
440 * @param[in] value event value
443 /*--------------------------------------------------------------------------*/
445 ico_mgr_send_input_event(struct wl_client *client, struct wl_resource *resource,
446 const char *target, uint32_t surfaceid, int32_t type,
447 int32_t deviceno, uint32_t time, int32_t code, int32_t value)
449 struct uifw_win_surface *usurf; /* UIFW surface */
450 struct uifw_input_device *dev; /* device control table */
451 struct wl_resource *cres; /* event send client resource */
452 struct wl_array dummy_array; /* dummy array for wayland API */
453 uint32_t ctime; /* current time(ms) */
454 uint32_t serial; /* event serial number */
455 int event; /* event flag */
456 wl_fixed_t fix_x; /* wayland X coordinate */
457 wl_fixed_t fix_y; /* wayland Y coordinate */
458 wl_fixed_t dx, dy; /* relative coordinate (dummy) */
459 struct weston_surface *grabsave; /* real grab surface */
460 int keyboard_active; /* keyborad active surface flag */
462 #if 0 /* too many log */
463 uifw_debug("ico_mgr_send_input_event: Enter(target=%s surf=%x dev=%d.%d "
464 "time=%d code=%x value=%d)",
465 target ? target : "(NULL)", surfaceid, type, deviceno,
469 /* search pseudo input device */
470 wl_list_for_each (dev, &pInputMgr->dev_list, link) {
471 if ((dev->type == type) && (dev->no == deviceno)) break;
473 if (&dev->link == &pInputMgr->dev_list) {
474 /* device not exist, create new device */
475 uifw_trace("ico_mgr_send_input_event: new device=%d no=%d", type, deviceno);
476 dev = malloc(sizeof(struct uifw_input_device));
478 uifw_error("ico_mgr_send_input_event: Leave(No Memory)");
481 memset(dev, 0, sizeof(struct uifw_input_device));
484 if ((type == ICO_INPUT_MGR_DEVICE_TYPE_POINTER) ||
485 (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) ||
486 (type == ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC)) {
487 ico_window_mgr_get_display_coordinate(deviceno, &dev->disp_x, &dev->disp_y);
489 wl_list_insert(pInputMgr->dev_list.prev, &dev->link);
492 /* convert pending event */
494 if ((code & 0xffff0000) != (EV_REL << 16)) {
498 case ICO_INPUT_MGR_DEVICE_TYPE_POINTER: /* mouse */
499 case ICO_INPUT_MGR_DEVICE_TYPE_TOUCH: /* touch panel */
500 case ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC: /* haptic */
503 if (dev->pending & PENDING_Y) {
505 dev->y = dev->pend_y;
509 event = EVENT_MOTION;
513 dev->pending |= PENDING_X;
514 event = EVENT_PENDING;
518 if (dev->pending & PENDING_X) {
519 dev->x = dev->pend_x;
524 event = EVENT_MOTION;
528 dev->pending |= PENDING_Y;
529 event = EVENT_PENDING;
533 dev->x = (short)(value >> 16);
534 dev->y = (short)(value & 0x0ffff);
538 event = EVENT_MOTION;
540 case ((EV_REL << 16) | REL_X):
541 if (dev->pending & PENDING_Y) {
543 dev->y = dev->pend_y;
547 event = EVENT_MOTION;
550 dev->pend_x = dev->x + value;
551 dev->pending |= PENDING_X;
552 event = EVENT_PENDING;
555 case ((EV_REL << 16) | REL_Y):
556 if (dev->pending & PENDING_X) {
557 dev->x = dev->pend_x;
562 event = EVENT_MOTION;
565 dev->pend_x = dev->y + value;
566 dev->pending |= PENDING_Y;
567 event = EVENT_PENDING;
570 case ((EV_REL << 16) | REL_Z):
571 dev->x += (short)(value >> 16);
572 dev->y += (short)(value & 0x0ffff);
576 event = EVENT_MOTION;
579 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
583 event = EVENT_BUTTON;
593 if (event == EVENT_PENDING) {
594 #if 0 /* too many log */
595 uifw_debug("ico_mgr_send_input_event: Leave(event pending)");
604 ctime = weston_compositor_get_time();
606 fix_x = wl_fixed_from_int(dev->x + dev->disp_x);
607 fix_y = wl_fixed_from_int(dev->y + dev->disp_y);
609 if ((surfaceid == 0) && ((target == NULL) || (*target == 0) || (*target == ' '))) {
610 /* send event to surface via weston */
612 /* disable the event transmission to a input layer */
613 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
614 ico_window_mgr_touch_layer(TRUE);
617 if ((event == EVENT_TOUCH) && (pInputMgr->seat->touch == NULL)) {
618 /* system has no touch, change to pointer event */
619 if (pInputMgr->seat->pointer == NULL) {
620 uifw_trace("ico_mgr_send_input_event: Leave(no touch & no pointerr)");
623 event = EVENT_BUTTON;
626 else if ((event == EVENT_BUTTON) && (pInputMgr->seat->pointer == NULL)) {
627 /* system has no pointer, change to touch event */
628 if (pInputMgr->seat->touch == NULL) {
629 uifw_trace("ico_mgr_send_input_event: Leave(no touch & no pointerr)");
637 if ((type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) &&
638 (pInputMgr->seat->touch)) {
639 if (pInputMgr->seat->num_tp > 10) {
640 uifw_debug("ico_mgr_send_input_event: num=%d reset",
641 pInputMgr->seat->num_tp);
642 pInputMgr->seat->num_tp = 0; /* safty gard */
644 grabsave = pInputMgr->seat->touch->focus;
645 uifw_debug("ico_mgr_send_input_event: MOTION(%d/%d) grab %08x org %08x",
646 fix_x/256, fix_y/256, (int)dev->grab, (int)grabsave);
647 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
648 weston_touch_set_focus(pInputMgr->seat, dev->grab);
650 notify_touch(pInputMgr->seat, ctime, 0, fix_x, fix_y, WL_TOUCH_MOTION);
651 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
652 weston_touch_set_focus(pInputMgr->seat, grabsave);
655 else if (pInputMgr->seat->pointer) {
656 #if 0 /* too many log */
657 uifw_debug("ico_mgr_send_input_event: notify_motion_absolute(%d/%d)",
658 fix_x/256, fix_y/256);
660 notify_motion_absolute(pInputMgr->seat, ctime, fix_x, fix_y);
664 uifw_trace("ico_mgr_send_input_event: notify_button(%d,%d)", code, value);
665 if (pInputMgr->seat->pointer) {
667 dev->grab = weston_compositor_pick_surface(
668 pInputMgr->compositor, fix_x, fix_y, &dx, &dy);
669 weston_pointer_set_focus(pInputMgr->seat->pointer, dev->grab, dx, dy);
670 ico_window_mgr_active_surface(dev->grab);
675 notify_button(pInputMgr->seat, ctime, code,
676 value ? WL_POINTER_BUTTON_STATE_PRESSED :
677 WL_POINTER_BUTTON_STATE_RELEASED);
681 if (value == ICO_INPUT_MGR_CONTROL_TOUCH_EVENT_RESET) {
682 /* reset touch focus */
683 grabsave = pInputMgr->seat->touch->focus;
684 uifw_trace("ico_mgr_send_input_event: notify_touch(UnGrab dev=%08x sys=%08x)",
685 (int)dev->grab, (int)grabsave);
688 weston_touch_set_focus(pInputMgr->seat, NULL);
689 if (pInputMgr->seat->num_tp > 0) {
690 uifw_debug("ico_mgr_send_input_event: num=%d reset for reset focuse",
691 pInputMgr->seat->num_tp);
692 pInputMgr->seat->num_tp = 0;
696 else if (value == ICO_INPUT_MGR_CONTROL_TOUCH_EVENT_DOWN) {
697 grabsave = pInputMgr->seat->touch->focus;
698 dev->grab = weston_compositor_pick_surface(
699 pInputMgr->compositor, fix_x, fix_y, &dx, &dy);
700 uifw_trace("ico_mgr_send_input_event: notify_touch(DOWN=%d/%d) "
701 "grab=%08x org=%08x", fix_x/256, fix_y/256,
702 (int)dev->grab, (int)grabsave);
703 if (grabsave != dev->grab) {
704 weston_touch_set_focus(pInputMgr->seat, dev->grab);
706 if (pInputMgr->seat->num_tp > 0) {
707 uifw_debug("ico_mgr_send_input_event: touch_down illegal num, modify");
708 weston_touch_set_focus(pInputMgr->seat, NULL);
709 pInputMgr->seat->num_tp = 0;
711 notify_touch(pInputMgr->seat, ctime, 0, fix_x, fix_y, WL_TOUCH_DOWN);
712 ico_window_mgr_active_surface(dev->grab);
715 grabsave = pInputMgr->seat->touch->focus;
716 uifw_trace("ico_mgr_send_input_event: notify_touch(UP) org=%08x",
718 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
719 weston_touch_set_focus(pInputMgr->seat, dev->grab);
721 if ((pInputMgr->seat->num_tp == 0) || (pInputMgr->seat->num_tp > 10)) {
722 uifw_debug("ico_mgr_send_input_event: num=%d reset",
723 pInputMgr->seat->num_tp);
724 pInputMgr->seat->num_tp = 1;
726 notify_touch(pInputMgr->seat, ctime, 0, 0, 0, WL_TOUCH_UP);
727 if (grabsave == dev->grab) grabsave = NULL;
728 weston_touch_set_focus(pInputMgr->seat, grabsave);
733 uifw_trace("ico_mgr_send_input_event: notify_key(%d,%d)", code, value);
734 notify_key(pInputMgr->seat, ctime, code,
735 value ? WL_KEYBOARD_KEY_STATE_PRESSED :
736 WL_KEYBOARD_KEY_STATE_RELEASED, STATE_UPDATE_NONE);
739 uifw_trace("ico_mgr_send_input_event: unknown event=%d", event);
742 /* enable the event transmission to a input layer */
743 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
744 ico_window_mgr_touch_layer(FALSE);
748 if ((target != NULL) && (*target != 0) && (*target != ' ')) {
749 /* send event to fixed application */
751 /* get application surface */
752 usurf = ico_window_mgr_get_client_usurf(target);
754 uifw_trace("ico_mgr_send_input_event: Leave(window=%s dose not exist)",
760 /* get UIFW surface */
761 usurf = ico_window_mgr_get_usurf(surfaceid);
763 uifw_trace("ico_mgr_send_input_event: Leave(surface dose not exist)");
771 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
772 cres = wl_resource_find_for_client(
773 &pInputMgr->seat->touch->resource_list,
774 wl_resource_get_client(usurf->surface->resource));
776 wl_touch_send_motion(cres, ctime, 0, fix_x, fix_y);
780 cres = wl_resource_find_for_client(
781 &pInputMgr->seat->pointer->resource_list,
782 wl_resource_get_client(usurf->surface->resource));
784 wl_pointer_send_motion(cres, ctime, fix_x, fix_y);
789 cres = wl_resource_find_for_client(
790 &pInputMgr->seat->pointer->resource_list,
791 wl_resource_get_client(usurf->surface->resource));
793 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
794 wl_pointer_send_button(cres, serial, ctime, code,
795 value ? WL_POINTER_BUTTON_STATE_PRESSED :
796 WL_POINTER_BUTTON_STATE_RELEASED);
800 cres = wl_resource_find_for_client(
801 &pInputMgr->seat->touch->resource_list,
802 wl_resource_get_client(usurf->surface->resource));
804 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
806 wl_touch_send_down(cres, serial, ctime, usurf->surface->resource, 0,
810 wl_touch_send_up(cres, serial, ctime, 0);
815 cres = wl_resource_find_for_client(
816 &pInputMgr->seat->keyboard->resource_list,
817 wl_resource_get_client(usurf->surface->resource));
819 keyboard_active = ico_window_mgr_ismykeyboard(usurf);
820 if (! keyboard_active) {
821 wl_array_init(&dummy_array);
822 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
823 wl_keyboard_send_enter(cres, serial,
824 usurf->surface->resource, &dummy_array);
826 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
827 uifw_trace("ico_mgr_send_input_event: send Key (%d, %d) to %08x",
828 code, value, usurf->surfaceid);
829 wl_keyboard_send_key(cres, serial, ctime, code,
830 value ? WL_KEYBOARD_KEY_STATE_PRESSED :
831 WL_KEYBOARD_KEY_STATE_RELEASED);
832 if (! keyboard_active) {
833 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
834 wl_keyboard_send_leave(cres, serial, usurf->surface->resource);
838 uifw_trace("ico_mgr_send_input_event: Key client %08x dose not exist",
839 (int)usurf->surface->resource);
846 #if 0 /* too many log */
847 uifw_debug("ico_mgr_send_input_event: Leave");
851 /*--------------------------------------------------------------------------*/
853 * @brief ico_mgr_set_input_region: set input region for haptic devcie
855 * @param[in] client client(Device Input Controller)
856 * @param[in] resource resource of request
857 * @param[in] target target window (winname@appid)
858 * @param[in] x input region X coordinate
859 * @param[in] y input region X coordinate
860 * @param[in] width input region width
861 * @param[in] height input region height
862 * @param[in] hotspot_x hotspot of X relative coordinate
863 * @param[in] hotspot_y hotspot of Y relative coordinate
864 * @param[in] cursor_x cursor region X coordinate
865 * @param[in] cursor_y cursor region X coordinate
866 * @param[in] cursor_width cursor region width
867 * @param[in] cursor_height cursor region height
868 * @param[in] attr region attributes(currently unused)
871 /*--------------------------------------------------------------------------*/
873 ico_mgr_set_input_region(struct wl_client *client, struct wl_resource *resource,
874 const char *target, int32_t x, int32_t y,
875 int32_t width, int32_t height, int32_t hotspot_x,
876 int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
877 int32_t cursor_width, int32_t cursor_height, uint32_t attr)
879 struct uifw_win_surface *usurf; /* UIFW surface */
881 uifw_trace("ico_mgr_set_input_region: Enter(%s %d/%d-%d/%d(%d/%d) %d/%d-%d/%d)",
882 target, x, y, width, height, hotspot_x, hotspot_y,
883 cursor_x, cursor_y, cursor_width, cursor_height);
885 /* get target surface */
886 usurf = ico_window_mgr_get_client_usurf(target);
888 uifw_warn("ico_mgr_set_input_region: Leave(target<%s> dose not exist)", target);
892 ico_set_input_region(1, usurf, x, y, width, height, hotspot_x, hotspot_y,
893 cursor_x, cursor_y, cursor_width, cursor_height, attr);
895 uifw_trace("ico_mgr_set_input_region: Leave");
898 /*--------------------------------------------------------------------------*/
900 * @brief ico_mgr_unset_input_region: unset input region for haptic devcie
902 * @param[in] client client(Device Input Controller)
903 * @param[in] resource resource of request
904 * @param[in] target target window (winname@appid)
905 * @param[in] x input region X coordinate
906 * @param[in] y input region X coordinate
907 * @param[in] width input region width
908 * @param[in] height input region height
911 /*--------------------------------------------------------------------------*/
913 ico_mgr_unset_input_region(struct wl_client *client, struct wl_resource *resource,
914 const char *target, int32_t x, int32_t y,
915 int32_t width, int32_t height)
917 struct uifw_win_surface *usurf; /* UIFW surface */
919 uifw_trace("ico_mgr_unset_input_region: Enter(%s %d/%d-%d/%d)",
920 target, x, y, width, height);
922 /* get target surface */
923 usurf = ico_window_mgr_get_client_usurf(target);
925 uifw_warn("ico_mgr_unset_input_region: Leave(target<%s> dose not exist)", target);
929 ico_set_input_region(0, usurf, x, y, width, height, 0, 0, 0, 0, 0, 0, 0);
931 uifw_trace("ico_mgr_unset_input_region: Leave");
934 /*--------------------------------------------------------------------------*/
936 * @brief ico_input_hook_region_change: change surface attribute
938 * @param[in] usurf UIFW surface
941 /*--------------------------------------------------------------------------*/
943 ico_input_hook_region_change(struct uifw_win_surface *usurf)
945 struct uifw_region_mng *p; /* input region mamagement table*/
946 struct ico_uifw_input_region *rp; /* input region */
947 struct wl_array array;
951 visible = ico_window_mgr_is_visible(usurf);
953 uifw_trace("ico_input_hook_region_change: Entery(surf=%08x, visible=%d)",
954 usurf->surfaceid, visible);
956 wl_array_init(&array);
958 wl_list_for_each(p, &usurf->input_region, link) {
959 if (((p->region.change > 0) && (visible <= 0)) ||
960 ((p->region.change <= 0) && (visible > 0))) {
961 /* visible change, send add/remove event */
962 rp = (struct ico_uifw_input_region *)
963 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
966 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
968 rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
971 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
974 p->region.change = visible;
975 p->region.node = usurf->node_tbl->node;
976 p->region.surface_x = usurf->x;
977 p->region.surface_y = usurf->y;
979 else if ((p->region.node != usurf->node_tbl->node) ||
980 (p->region.surface_x != usurf->x) ||
981 (p->region.surface_y != usurf->y)) {
982 /* surface position change, send change event */
983 p->region.node = usurf->node_tbl->node;
984 p->region.surface_x = usurf->x;
985 p->region.surface_y = usurf->y;
987 rp = (struct ico_uifw_input_region *)
988 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
991 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
992 rp->change = ICO_INPUT_MGR_DEVICE_REGION_CHANGE;
997 /* send region delete to haptic device input controller */
998 ico_input_send_region_event(&array);
1000 uifw_trace("ico_input_hook_region_change: Leave");
1003 /*--------------------------------------------------------------------------*/
1005 * @brief ico_input_hook_region_destroy: destory surface
1007 * @param[in] usurf UIFW surface
1010 /*--------------------------------------------------------------------------*/
1012 ico_input_hook_region_destroy(struct uifw_win_surface *usurf)
1014 struct uifw_region_mng *p; /* input region mamagement table*/
1015 struct uifw_region_mng *np; /* next region mamagement table */
1016 struct ico_uifw_input_region *rp; /* input region */
1017 struct wl_array array;
1020 uifw_trace("ico_input_hook_region_destroy: Entery(surf=%08x)", usurf->surfaceid);
1022 wl_array_init(&array);
1024 wl_list_for_each_safe(p, np, &usurf->input_region, link) {
1025 if (p->region.change > 0) {
1026 /* visible, send remove event */
1027 rp = (struct ico_uifw_input_region *)
1028 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1031 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1032 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1035 wl_list_remove(&p->link);
1036 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1039 /* send region delete to haptic device input controller */
1040 ico_input_send_region_event(&array);
1042 uifw_trace("ico_input_hook_region_destroy: Leave");
1045 /*--------------------------------------------------------------------------*/
1047 * @brief ico_set_input_region: input region set/unset
1049 * @param[in] set set(1)/unset(0)
1050 * @param[in] usurf UIFW surface
1051 * @param[in] x input region X coordinate
1052 * @param[in] y input region X coordinate
1053 * @param[in] width input region width
1054 * @param[in] height input region height
1055 * @param[in] hotspot_x hotspot of X relative coordinate
1056 * @param[in] hotspot_y hotspot of Y relative coordinate
1057 * @param[in] cursor_x cursor region X coordinate
1058 * @param[in] cursor_y cursor region X coordinate
1059 * @param[in] cursor_width cursor region width
1060 * @param[in] cursor_height cursor region height
1061 * @param[in] attr region attributes(currently unused)
1064 /*--------------------------------------------------------------------------*/
1066 ico_set_input_region(int set, struct uifw_win_surface *usurf,
1067 int32_t x, int32_t y, int32_t width, int32_t height,
1068 int32_t hotspot_x, int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
1069 int32_t cursor_width, int32_t cursor_height, uint32_t attr)
1071 struct uifw_region_mng *p; /* input region mamagement table*/
1072 struct uifw_region_mng *np; /* next region mamagement table */
1073 struct ico_uifw_input_region *rp; /* input region */
1074 struct wl_array array;
1079 uifw_trace("ico_set_input_region: Enter(%s %d/%d-%d/%d(%d/%d) %d/%d-%d/%d)",
1080 set ? "Set" : "Unset", x, y, width, height, hotspot_x, hotspot_y,
1081 cursor_x, cursor_y, cursor_width, cursor_height);
1084 if (wl_list_empty(&pInputMgr->free_region)) {
1085 p = malloc(sizeof(struct uifw_region_mng) * 50);
1087 uifw_error("ico_set_input_region: No Memory");
1090 memset(p, 0, sizeof(struct uifw_region_mng)*50);
1091 for (i = 0; i < 50; i++, p++) {
1092 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1095 p = container_of(pInputMgr->free_region.next, struct uifw_region_mng, link);
1096 wl_list_remove(&p->link);
1097 p->region.node = usurf->node_tbl->node;
1098 p->region.surfaceid = usurf->surfaceid;
1099 p->region.surface_x = usurf->x;
1100 p->region.surface_y = usurf->y;
1103 p->region.width = width;
1104 p->region.height = height;
1105 if ((hotspot_x <= 0) && (hotspot_y <= 0)) {
1106 p->region.hotspot_x = width / 2;
1107 p->region.hotspot_y = height / 2;
1110 p->region.hotspot_x = hotspot_x;
1111 p->region.hotspot_y = hotspot_y;
1113 if ((cursor_width <= 0) && (cursor_height <= 0)) {
1114 p->region.cursor_x = x;
1115 p->region.cursor_y = y;
1116 p->region.cursor_width = width;
1117 p->region.cursor_height = height;
1120 p->region.cursor_x = cursor_x;
1121 p->region.cursor_y = cursor_y;
1122 p->region.cursor_width = cursor_width;
1123 p->region.cursor_height = cursor_height;
1125 p->region.change = ico_window_mgr_is_visible(usurf);
1126 wl_list_insert(usurf->input_region.prev, &p->link);
1128 /* send input region to haptic device input controller */
1129 if (p->region.change > 0) {
1130 wl_array_init(&array);
1131 rp = (struct ico_uifw_input_region *)
1132 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1134 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1135 rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
1136 ico_input_send_region_event(&array);
1138 uifw_trace("ico_set_input_region: Leave(Set)");
1141 uifw_trace("ico_set_input_region: Leave(Set but Unvisible)");
1147 if ((x <= 0) && (y <= 0) && (width <= 0) && (height <= 0)) {
1154 wl_array_init(&array);
1156 wl_list_for_each_safe(p, np, &usurf->input_region, link) {
1157 if ((alldel != 0) ||
1158 ((x == p->region.x) && (y == p->region.y) &&
1159 (width == p->region.width) && (height == p->region.height))) {
1160 if (p->region.change > 0) {
1161 /* visible, send remove event */
1162 rp = (struct ico_uifw_input_region *)
1163 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1166 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1167 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1170 wl_list_remove(&p->link);
1171 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1175 /* send region delete to haptic device input controller */
1176 ico_input_send_region_event(&array);
1178 uifw_trace("ico_set_input_region: Leave(Unset)");
1182 /*--------------------------------------------------------------------------*/
1184 * @brief ico_input_send_region_event: send region event to Haptic dic
1186 * @param[in] usurf UIFW surface
1189 /*--------------------------------------------------------------------------*/
1191 ico_input_send_region_event(struct wl_array *array)
1193 struct ico_ictl_mgr *pIctlMgr;
1195 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1196 if ((pIctlMgr->type == ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC) &&
1197 (pIctlMgr->mgr_resource != NULL)) {
1198 uifw_trace("ico_input_send_region_event: send event to Hapfic");
1199 ico_input_mgr_device_send_input_regions(pIctlMgr->mgr_resource, array);
1204 /*--------------------------------------------------------------------------*/
1206 * @brief ico_device_configure_input: configure input device and input switch
1207 * from Device Input Controller.
1209 * @param[in] client client(Device Input Controller)
1210 * @param[in] resource resource of request
1211 * @param[in] device device name
1212 * @param[in] type device type(saved but unused)
1213 * @param[in] swname input switch name
1214 * @param[in] input input switch number
1215 * @param[in] codename input code name
1216 * @param[in] code input code number
1219 /*--------------------------------------------------------------------------*/
1221 ico_device_configure_input(struct wl_client *client, struct wl_resource *resource,
1222 const char *device, int32_t type, const char *swname,
1223 int32_t input, const char *codename, int32_t code)
1225 uifw_trace("ico_device_configure_input: Enter(client=%08x,dev=%s,type=%d,swname=%s,"
1226 "input=%d,code=%d[%s])", (int)client, device, type,
1227 swname ? swname : "(NULL)", input, code, codename ? codename : " ");
1229 struct ico_ictl_mgr *pIctlMgr;
1230 struct ico_ictl_mgr *psameIctlMgr;
1231 struct ico_ictl_input *pInput;
1232 struct ico_app_mgr *pAppMgr;
1234 pIctlMgr = find_ictlmgr_by_device(device);
1236 /* search binded table */
1237 psameIctlMgr = NULL;
1238 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1239 if (pIctlMgr->client == client) {
1240 uifw_trace("ico_device_configure_input: set pIctlMgr"
1241 "(mgr=%08x,input=%d,dev=%s)", (int)pIctlMgr,
1242 input, pIctlMgr->device);
1243 if (pIctlMgr->device[0] != 0) {
1244 /* save same device */
1245 psameIctlMgr = pIctlMgr;
1249 strncpy(pIctlMgr->device, device, sizeof(pIctlMgr->device)-1);
1250 psameIctlMgr = NULL;
1256 /* client(device input controller) exist, but other device */
1257 pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
1258 if (pIctlMgr == NULL) {
1259 uifw_error("ico_device_bind: Leave(No Memory)");
1262 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1263 wl_list_init(&pIctlMgr->ico_ictl_input);
1264 pIctlMgr->client = psameIctlMgr->client;
1265 pIctlMgr->mgr_resource = psameIctlMgr->mgr_resource;
1267 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1272 pIctlMgr->type = type;
1275 /* search and add input switch */
1276 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1277 if (pInput->input == input) break;
1279 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
1280 uifw_trace("ico_device_configure_input: create %s.%s(%d) switch",
1281 device, swname, input);
1282 pInput = (struct ico_ictl_input *)malloc(sizeof(struct ico_ictl_input));
1283 if (pInput == NULL) {
1284 uifw_error("ico_device_configure_input: Leave(No Memory)");
1287 memset(pInput, 0, sizeof(struct ico_ictl_input));
1289 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1292 strcpy(pInput->swname, "(Unknown)");
1294 wl_list_insert(pIctlMgr->ico_ictl_input.prev, &pInput->link);
1297 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1299 pInput->input = input;
1300 memset(pInput->code, 0, sizeof(pInput->code));
1302 pInput->code[0].code = code;
1304 strncpy(pInput->code[0].name, codename, sizeof(pInput->code[0].name)-1);
1307 if (client == NULL) {
1308 /* internal call for table create */
1309 uifw_trace("ico_device_configure_input: Leave(table create)");
1312 pIctlMgr->client = client;
1314 /* send to application and manager(ex.HomeScreen) */
1315 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1316 if (pAppMgr->resource == NULL) continue;
1317 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
1319 uifw_trace("ico_device_configure_input: send capabilities to app(%s) %s.%s[%d]",
1320 pAppMgr->appid, device, pInput->swname, input);
1321 ico_exinput_send_capabilities(pAppMgr->resource, device, pIctlMgr->type,
1322 pInput->swname, input,
1323 pInput->code[0].name, pInput->code[0].code);
1325 uifw_trace("ico_device_configure_input: Leave");
1328 /*--------------------------------------------------------------------------*/
1330 * @brief ico_device_configure_code: add input switch from Device Input Controller.
1332 * @param[in] client client(Device Input Controller)
1333 * @param[in] resource resource of request
1334 * @param[in] device device name
1335 * @param[in] input input switch number
1336 * @param[in] codename input code name
1337 * @param[in] code input code number
1340 /*--------------------------------------------------------------------------*/
1342 ico_device_configure_code(struct wl_client *client, struct wl_resource *resource,
1343 const char *device, int32_t input,
1344 const char *codename, int32_t code)
1346 uifw_trace("ico_device_configure_code: Enter(client=%08x,dev=%s,input=%d,code=%d[%s])",
1347 (int)client, device, input, code, codename ? codename : " ");
1350 struct ico_ictl_mgr *pIctlMgr;
1351 struct ico_ictl_input *pInput;
1352 struct ico_app_mgr *pAppMgr;
1354 pIctlMgr = find_ictlmgr_by_device(device);
1356 uifw_warn("ico_device_configure_code: Leave(dev=%s dose not exist)", device);
1359 /* search input switch */
1360 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1361 if (pInput->input == input) break;
1363 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
1364 uifw_warn("ico_device_configure_code: Leave(input=%s.%d dose not exist)",
1369 /* search input code */
1370 for (i = 0; i < pInput->ncode; i++) {
1371 if (pInput->code[i].code == code) break;
1373 if (i >= pInput->ncode) {
1374 /* code dose not exist, add */
1375 if (pInput->ncode >= ICO_MINPUT_MAX_CODES) {
1376 uifw_warn("ico_device_configure_code: Leave(input=%s.%d code overflow)",
1382 pInput->code[i].code = code;
1384 memset(pInput->code[i].name, 0, sizeof(pInput->code[i].name));
1385 strncpy(pInput->code[i].name, codename, sizeof(pInput->code[i].name)-1);
1387 /* send to application and manager(ex.HomeScreen) */
1388 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1389 if (pAppMgr->resource == NULL) continue;
1390 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
1391 uifw_trace("ico_device_configure_input: send code to app(%s) %s.%s[%d]",
1392 pAppMgr->appid, device, pInput->swname, input);
1393 ico_exinput_send_code(pAppMgr->resource, device, input,
1394 pInput->code[i].name, pInput->code[i].code);
1396 uifw_trace("ico_device_configure_code: Leave");
1399 /*--------------------------------------------------------------------------*/
1401 * @brief ico_device_input_event: device input event from Device Input Controller.
1403 * @param[in] client client(Device Input Controller)
1404 * @param[in] resource resource of request
1405 * @param[in] time device input time(miri-sec)
1406 * @param[in] device device name
1407 * @param[in] input input switch number
1408 * @param[in] code input code number
1409 * @param[in] state input state(1=On, 0=Off)
1412 /*--------------------------------------------------------------------------*/
1414 ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
1415 uint32_t time, const char *device,
1416 int32_t input, int32_t code, int32_t state)
1418 uifw_trace("ico_device_input_event: Enter(time=%d,dev=%s,input=%d,code=%d,state=%d)",
1419 time, device, input, code, state);
1421 struct ico_ictl_mgr *pIctlMgr;
1422 struct ico_ictl_input *pInput;
1424 /* find input devcie by client */
1425 pIctlMgr = find_ictlmgr_by_device(device);
1427 uifw_error("ico_device_input_event: Leave(Unknown device(%s))", device);
1430 /* find input switch by input Id */
1431 pInput = find_ictlinput_by_input(pIctlMgr, input);
1433 uifw_warn("ico_device_input_event: Leave(Unknown input(%s,%d))",
1434 pIctlMgr->device, input);
1438 if (! pInput->app) {
1439 uifw_trace("ico_device_input_event: Leave(%s.%s not assign)",
1440 pIctlMgr->device, pInput->swname);
1444 /* send event to application */
1445 uifw_trace("ico_device_input_event: send event=%s.%s[%d],%d,%d to App.%s",
1446 pIctlMgr->device, pInput->swname, input, code, state, pInput->app->appid);
1447 ico_exinput_send_input(pInput->app->resource, time, pIctlMgr->device,
1448 input, code, state);
1450 uifw_trace("ico_device_input_event: Leave");
1453 /*--------------------------------------------------------------------------*/
1455 * @brief ico_control_bind: ico_input_mgr_control bind from HomeScreen
1457 * @param[in] client client(HomeScreen)
1458 * @param[in] data data(unused)
1459 * @param[in] version protocol version(unused)
1460 * @param[in] id client object id
1463 /*--------------------------------------------------------------------------*/
1465 ico_control_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1468 struct ico_app_mgr *pAppMgr;
1470 uifw_trace("ico_control_bind: Enter(client=%08x)", (int)client);
1471 appid = ico_window_mgr_get_appid(client);
1474 /* client dose not exist */
1475 uifw_warn("ico_control_bind: Leave(client=%08x dose not exist)", (int)client);
1479 /* find application */
1480 pAppMgr = find_app_by_appid(appid);
1482 /* create Application Management Table */
1483 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1485 uifw_error("ico_control_bind: Leave(No Memory)");
1488 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
1489 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
1490 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
1492 pAppMgr->client = client;
1493 if (! pAppMgr->mgr_resource) {
1494 pAppMgr->mgr_resource = wl_resource_create(client,
1495 &ico_input_mgr_control_interface, 1, id);
1496 if (pAppMgr->mgr_resource) {
1497 wl_resource_set_implementation(pAppMgr->mgr_resource,
1498 &ico_input_mgr_implementation,
1499 pInputMgr, ico_control_unbind);
1502 uifw_trace("ico_control_bind: Leave");
1505 /*--------------------------------------------------------------------------*/
1507 * @brief ico_control_unbind: ico_input_mgr_control unbind from HomeScreen
1509 * @param[in] resource client resource(HomeScreen)
1512 /*--------------------------------------------------------------------------*/
1514 ico_control_unbind(struct wl_resource *resource)
1516 struct ico_app_mgr *pAppMgr;
1518 uifw_trace("ico_control_unbind: Enter(resource=%08x)", (int)resource);
1520 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1521 if (pAppMgr->mgr_resource == resource) {
1522 uifw_trace("ico_control_unbind: find app.%s", pAppMgr->appid);
1523 pAppMgr->mgr_resource = NULL;
1527 uifw_trace("ico_control_unbind: Leave");
1530 /*--------------------------------------------------------------------------*/
1532 * @brief ico_device_bind: ico_input_mgr_device bind from Device Input Controller
1534 * @param[in] client client(Device Input Controller)
1535 * @param[in] data data(unused)
1536 * @param[in] version protocol version
1537 * @param[in] id client object id
1540 /*--------------------------------------------------------------------------*/
1542 ico_device_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1544 struct ico_ictl_mgr *pIctlMgr;
1545 struct wl_resource *mgr_resource;
1547 uifw_trace("ico_device_bind: Enter(client=%08x)", (int)client);
1549 /* create ictl mgr table */
1550 pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
1551 if (pIctlMgr == NULL) {
1552 uifw_error("ico_device_bind: Leave(No Memory)");
1555 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1556 wl_list_init(&pIctlMgr->ico_ictl_input);
1557 pIctlMgr->client = client;
1560 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1562 mgr_resource = wl_resource_create(client, &ico_input_mgr_device_interface, 1, id);
1564 pIctlMgr->mgr_resource = mgr_resource;
1565 wl_resource_set_implementation(mgr_resource, &input_mgr_ictl_implementation,
1566 pIctlMgr, ico_device_unbind);
1568 uifw_trace("ico_device_bind: Leave");
1571 /*--------------------------------------------------------------------------*/
1573 * @brief ico_device_unbind: ico_input_mgr_device unbind from Device Input Controller
1575 * @param[in] resource client resource(Device Input Controller)
1578 /*--------------------------------------------------------------------------*/
1580 ico_device_unbind(struct wl_resource *resource)
1582 uifw_trace("ico_device_unbind: Enter(resource=%08x)", (int)resource);
1583 uifw_trace("ico_device_unbind: Leave");
1586 /*--------------------------------------------------------------------------*/
1588 * @brief ico_exinput_bind: ico_exinput bind from Application
1590 * @param[in] client client(Application)
1591 * @param[in] data data(unused)
1592 * @param[in] version protocol version(unused)
1593 * @param[in] id client object id
1596 /*--------------------------------------------------------------------------*/
1598 ico_exinput_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1602 struct ico_app_mgr *pAppMgr;
1603 struct ico_ictl_mgr *pIctlMgr;
1604 struct ico_ictl_input *pInput;
1606 appid = ico_window_mgr_get_appid(client);
1607 uifw_trace("ico_exinput_bind: Enter(client=%08x,%s)", (int)client,
1608 appid ? appid : "(NULL)");
1611 /* client dose not exist */
1612 uifw_warn("ico_exinput_bind: Leave(client=%08x dose not exist)", (int)client);
1616 /* find application */
1617 pAppMgr = find_app_by_appid(appid);
1619 /* create Application Management Table */
1620 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1622 uifw_error("ico_exinput_bind: Leave(No Memory)");
1625 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
1626 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
1627 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
1628 uifw_trace("ico_exinput_bind: Create App.%s table", appid);
1630 pAppMgr->client = client;
1631 if (! pAppMgr->resource) {
1632 pAppMgr->resource = wl_resource_create(client, &ico_exinput_interface, 1, id);
1633 if (pAppMgr->resource) {
1634 wl_resource_set_implementation(pAppMgr->resource, &ico_exinput_implementation,
1635 pInputMgr, ico_exinput_unbind);
1639 /* send all capabilities */
1640 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1641 if (pIctlMgr->client == NULL) {
1642 uifw_trace("ico_exinput_bind: Input controller.%s not initialized",
1647 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1648 if (pInput->swname[0] == 0) {
1649 uifw_trace("ico_exinput_bind: Input %s not initialized", pIctlMgr->device);
1652 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) {
1653 uifw_trace("ico_exinput_bind: Input %s.%s fixed assign to App.%s",
1654 pIctlMgr->device, pInput->swname, pInput->app->appid);
1657 uifw_trace("ico_exinput_bind: send capabilities to app(%s) %s.%s[%d]",
1658 pAppMgr->appid, pIctlMgr->device, pInput->swname, pInput->input);
1659 ico_exinput_send_capabilities(pAppMgr->resource, pIctlMgr->device,
1660 pIctlMgr->type, pInput->swname, pInput->input,
1661 pInput->code[0].name, pInput->code[0].code);
1662 for (i = 1; i < pInput->ncode; i++) {
1663 ico_exinput_send_code(pAppMgr->resource, pIctlMgr->device, pInput->input,
1664 pInput->code[i].name, pInput->code[i].code);
1668 uifw_trace("ico_exinput_bind: Leave");
1671 /*--------------------------------------------------------------------------*/
1673 * @brief ico_exinput_unbind: ico_exinput unbind from Application
1675 * @param[in] resource client resource(Application)
1678 /*--------------------------------------------------------------------------*/
1680 ico_exinput_unbind(struct wl_resource *resource)
1682 struct ico_app_mgr *pAppMgr;
1683 struct ico_app_mgr *pAppMgrTmp;
1684 struct ico_ictl_mgr *pIctlMgr;
1685 struct ico_ictl_input *pInput;
1688 uifw_trace("ico_exinput_unbind: Enter(resource=%08x)", (int)resource);
1690 wl_list_for_each_safe (pAppMgr, pAppMgrTmp, &pInputMgr->app_list, link) {
1691 if (pAppMgr->resource == resource) {
1692 uifw_trace("ico_exinput_unbind: find app.%s", pAppMgr->appid);
1694 /* release application from input switch */
1695 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1696 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1697 if (pInput->app == pAppMgr) {
1698 if (pInput->fix == 0) {
1699 uifw_trace("ico_exinput_unbind: app.%s remove %s.%s",
1700 pAppMgr->appid, pIctlMgr->device, pInput->swname);
1704 uifw_trace("ico_exinput_unbind: app.%s fix assign %s.%s",
1705 pAppMgr->appid, pIctlMgr->device, pInput->swname);
1712 wl_list_remove(&pAppMgr->link);
1716 pAppMgr->client = NULL;
1717 pAppMgr->resource = NULL;
1721 uifw_trace("ico_exinput_unbind: Leave");
1724 /*--------------------------------------------------------------------------*/
1726 * @brief find_ictlmgr_by_device: find Input Controller by device name
1728 * @param[in] device device name
1729 * @return Input Controller Manager table address
1730 * @retval !=NULL address
1731 * @retval ==NULL not exist
1733 /*--------------------------------------------------------------------------*/
1734 static struct ico_ictl_mgr *
1735 find_ictlmgr_by_device(const char *device)
1737 struct ico_ictl_mgr *pIctlMgr;
1739 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1740 uifw_debug("find_ictlmgr_by_device: <%s> vs <%s>", device, pIctlMgr->device);
1741 if (strcmp(pIctlMgr->device, device) == 0) {
1748 /*--------------------------------------------------------------------------*/
1750 * @brief find_ictlinput_by_input: find Input Switch by input Id
1752 * @param[in] pIctlMgr Input Controller device
1753 * @param[in] input Input Id
1754 * @return Input Switch table address
1755 * @retval !=NULL address
1756 * @retval ==NULL not exist
1758 /*--------------------------------------------------------------------------*/
1759 static struct ico_ictl_input *
1760 find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr, const int32_t input)
1762 struct ico_ictl_input *pInput;
1764 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1765 if (pInput->input == input) {
1772 /*--------------------------------------------------------------------------*/
1774 * @brief find_app_by_appid: find Application by application Id
1776 * @param[in] appid application Id
1777 * @return Application Management table address
1778 * @retval !=NULL address
1779 * @retval ==NULL not exist
1781 /*--------------------------------------------------------------------------*/
1782 static struct ico_app_mgr *
1783 find_app_by_appid(const char *appid)
1785 struct ico_app_mgr *pAppMgr;
1787 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1788 if (strcmp(pAppMgr->appid, appid) == 0) {
1795 /*--------------------------------------------------------------------------*/
1797 * @brief module_init: initialization of this plugin
1799 * @param[in] ec weston compositor
1800 * @param[in] argc number of arguments(unused)
1801 * @param[in] argv argument list(unused)
1806 /*--------------------------------------------------------------------------*/
1808 module_init(struct weston_compositor *ec, int *argc, char *argv[])
1810 struct uifw_region_mng *p;
1813 uifw_info("ico_input_mgr: Enter(module_init)");
1815 /* initialize management table */
1816 pInputMgr = (struct ico_input_mgr *)malloc(sizeof(struct ico_input_mgr));
1817 if (pInputMgr == NULL) {
1818 uifw_trace("ico_input_mgr: malloc failed");
1821 memset(pInputMgr, 0, sizeof(struct ico_input_mgr));
1822 pInputMgr->compositor = ec;
1824 /* interface to desktop manager(ex.HomeScreen) */
1825 if (wl_global_create(ec->wl_display, &ico_input_mgr_control_interface, 1,
1826 pInputMgr, ico_control_bind) == NULL) {
1827 uifw_trace("ico_input_mgr: wl_global_create mgr failed");
1831 /* interface to Input Controller(ictl) */
1832 if (wl_global_create(ec->wl_display, &ico_input_mgr_device_interface, 1,
1833 pInputMgr, ico_device_bind) == NULL) {
1834 uifw_trace("ico_input_mgr: wl_global_create ictl failed");
1838 /* interface to App(exinput) */
1839 if (wl_global_create(ec->wl_display, &ico_exinput_interface, 1,
1840 pInputMgr, ico_exinput_bind) == NULL) {
1841 uifw_trace("ico_input_mgr: wl_global_create exseat failed");
1845 /* initialize list */
1846 wl_list_init(&pInputMgr->ictl_list);
1847 wl_list_init(&pInputMgr->app_list);
1848 wl_list_init(&pInputMgr->dev_list);
1849 wl_list_init(&pInputMgr->free_region);
1850 p = malloc(sizeof(struct uifw_region_mng)*100);
1852 memset(p, 0, sizeof(struct uifw_region_mng)*100);
1853 for (i = 0; i < 100; i++, p++) {
1854 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1858 /* found input seat */
1859 pInputMgr->seat = container_of(ec->seat_list.next, struct weston_seat, link);
1861 /* set hook for input region control */
1862 ico_window_mgr_set_hook_change(ico_input_hook_region_change);
1863 ico_window_mgr_set_hook_destory(ico_input_hook_region_destroy);
1864 ico_window_mgr_set_hook_inputregion(ico_set_input_region);
1866 uifw_info("ico_input_mgr: Leave(module_init)");