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.h"
49 #include "ico_window_mgr_private.h"
50 #include "ico_window_mgr-server-protocol.h"
51 #include "ico_input_mgr-server-protocol.h"
53 /* degine maximum length */
54 #define ICO_MINPUT_DEVICE_LEN 32
55 #define ICO_MINPUT_SW_LEN 20
56 #define ICO_MINPUT_MAX_CODES 20
58 /* structure definition */
59 struct uifw_region_mng;
61 /* working table of Multi Input Manager */
62 struct ico_input_mgr {
63 struct weston_compositor *compositor; /* Weston Compositor */
64 struct wl_list ictl_list; /* Input Controller List */
65 struct wl_list app_list; /* application List */
66 struct wl_list dev_list; /* pseudo device List */
67 struct wl_list free_region; /* free input region table list */
68 struct weston_seat *seat; /* input seat */
69 struct wl_resource *inputmgr;
72 /* Input Switch Table */
73 struct ico_ictl_code {
74 uint16_t code; /* input code numner */
75 char name[ICO_MINPUT_SW_LEN]; /* input code name */
78 struct ico_ictl_input {
79 struct wl_list link; /* link */
80 char swname[ICO_MINPUT_SW_LEN]; /* input switch name */
81 int32_t input; /* input Id */
82 uint16_t fix; /* fixed assign to application */
83 uint16_t ncode; /* number of codes */
84 struct ico_ictl_code code[ICO_MINPUT_MAX_CODES]; /* codes */
85 struct ico_app_mgr *app; /* send event tagret application */
88 /* Input Controller Management Table */
90 struct wl_list link; /* link */
91 struct wl_client *client; /* client */
92 struct wl_resource *mgr_resource; /* resource as manager */
93 char device[ICO_MINPUT_DEVICE_LEN]; /* device name */
94 int type; /* device type */
95 struct wl_list ico_ictl_input; /* list of input switchs */
98 /* Application Management Table */
100 struct wl_list link; /* link */
101 struct wl_client *client; /* client */
102 struct wl_resource *resource; /* resource for send event */
103 struct wl_resource *mgr_resource; /* resource as manager(if NULL, client) */
104 char appid[ICO_IVI_APPID_LENGTH]; /* application id */
107 /* Pseudo Input Device Control Flags */
108 #define EVENT_MOTION 0x01 /* motion event */
109 #define EVENT_BUTTON 0x02 /* button event */
110 #define EVENT_TOUCH 0x03 /* touch event */
111 #define EVENT_KEY 0x04 /* key event */
112 #define EVENT_PENDING 0xff /* pending event input */
114 #define PENDING_X 0x01 /* pending X coordinate */
115 #define PENDING_Y 0x02 /* pending Y coordinate */
117 /* Pseudo Input Device Table */
118 struct uifw_input_device {
119 struct wl_list link; /* link to next device */
120 uint16_t type; /* device type */
121 uint16_t no; /* device number */
122 int disp_x; /* display X coordinate */
123 int disp_y; /* display Y coordinate */
124 int x; /* current X coordinate */
125 int y; /* current Y coordinate */
126 int pend_x; /* pending X coordinate */
127 int pend_y; /* pending Y coordinate */
128 uint16_t node; /* display number */
129 uint16_t pending; /* pending flag */
130 struct weston_surface *grab; /* current grab surface */
133 /* Input Region Table */
134 struct uifw_region_mng {
135 struct wl_list link; /* link pointer */
136 struct ico_uifw_input_region region; /* input region */
139 /* prototype of static function */
140 /* bind input manager form manager */
141 static void ico_control_bind(struct wl_client *client, void *data,
142 uint32_t version, uint32_t id);
143 /* unbind input manager form manager */
144 static void ico_control_unbind(struct wl_resource *resource);
145 /* bind input manager form input controller*/
146 static void ico_device_bind(struct wl_client *client, void *data,
147 uint32_t version, uint32_t id);
148 /* unbind input manager form input controller*/
149 static void ico_device_unbind(struct wl_resource *resource);
150 /* bind input manager(form application) */
151 static void ico_exinput_bind(struct wl_client *client, void *data,
152 uint32_t version, uint32_t id);
153 /* unbind input manager(form application)*/
154 static void ico_exinput_unbind(struct wl_resource *resource);
156 /* find ictl manager by device name */
157 static struct ico_ictl_mgr *find_ictlmgr_by_device(const char *device);
158 /* find ictl input switch by input Id */
159 static struct ico_ictl_input *find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr,
160 const int32_t input);
161 /* find app manager by application Id */
162 static struct ico_app_mgr *find_app_by_appid(const char *appid);
163 /* add input event to application */
164 static void ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
165 const char *appid, const char *device, int32_t input,
166 int32_t fix, int32_t keycode);
167 /* delete input event to application */
168 static void ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
169 const char *appid, const char *device, int32_t input);
170 /* send input event from manager */
171 static void ico_mgr_send_input_event(struct wl_client *client, struct wl_resource *resource,
172 const char *target, uint32_t surfaceid, int32_t type,
173 int32_t deviceno, uint32_t time,
174 int32_t code, int32_t value);
175 /* set input region */
176 static void ico_mgr_set_input_region(struct wl_client *client, struct wl_resource *resource,
177 const char *target, int32_t x, int32_t y,
178 int32_t width, int32_t height, int32_t hotspot_x,
179 int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
180 int32_t cursor_width, int32_t cursor_height,
182 /* unset input region */
183 static void ico_mgr_unset_input_region(struct wl_client *client,
184 struct wl_resource *resource,
185 const char *taret, int32_t x, int32_t y,
186 int32_t width, int32_t height);
187 /* input region set/unset */
188 static void ico_set_input_region(int set, struct uifw_win_surface *usurf,
189 int32_t x, int32_t y, int32_t width, int32_t height,
190 int32_t hotspot_x, int32_t hotspot_y, int32_t cursor_x,
191 int32_t cursor_y, int32_t cursor_width,
192 int32_t cursor_height, uint32_t attr);
193 /* create and regist Input Controller table*/
194 static void ico_device_configure_input(struct wl_client *client,
195 struct wl_resource *resource, const char *device,
196 int32_t type, const char *swname, int32_t input,
197 const char *codename, int32_t code);
198 /* add input to from Input Controller table*/
199 static void ico_device_configure_code(struct wl_client *client,
200 struct wl_resource *resource, const char *device,
201 int32_t input, const char *codename, int32_t code);
202 /* device input event */
203 static void ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
204 uint32_t time, const char *device,
205 int32_t input, int32_t code, int32_t state);
206 static void ico_input_send_region_event(struct wl_array *array);
208 /* definition of Wayland protocol */
209 /* Input Manager Control interface */
210 static const struct ico_input_mgr_control_interface ico_input_mgr_implementation = {
211 ico_mgr_add_input_app,
212 ico_mgr_del_input_app,
213 ico_mgr_send_input_event
216 /* Extended Input interface */
217 static const struct ico_exinput_interface ico_exinput_implementation = {
218 ico_mgr_set_input_region,
219 ico_mgr_unset_input_region
222 /* Input Controller Device interface */
223 static const struct ico_input_mgr_device_interface input_mgr_ictl_implementation = {
224 ico_device_configure_input,
225 ico_device_configure_code,
226 ico_device_input_event
229 /* definition of class variable */
230 struct ico_input_mgr *pInputMgr = NULL;
233 /*--------------------------------------------------------------------------*/
235 * @brief ico_mgr_add_input_app: add input event to application from HomeScreen.
237 * @param[in] client client(HomeScreen)
238 * @param[in] resource resource of request
239 * @param[in] appid target application id
240 * @param[in] device device name
241 * @param[in] input input switch number
242 * @param[in] fix fix to application(1=fix,0=general)
243 * @param[in] keycode switch map to keyboard operation(0=not map to keyboard)
246 /*--------------------------------------------------------------------------*/
248 ico_mgr_add_input_app(struct wl_client *client, struct wl_resource *resource,
249 const char *appid, const char *device, int32_t input,
250 int32_t fix, int32_t keycode)
252 struct uifw_client *uclient;
253 struct ico_ictl_mgr *pIctlMgr;
254 struct ico_ictl_input *pInput;
255 struct ico_app_mgr *pAppMgr;
257 uifw_trace("ico_mgr_add_input_app: Enter(appid=%s,dev=%s,input=%d,fix=%d,key=%d)",
258 appid, device, input, fix, keycode);
260 /* check for access control */
261 if (resource != NULL) {
262 /* resource is NULL, internal use */
263 uclient = ico_window_mgr_find_uclient(client);
265 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
266 "ico_input_mgr_control_add_input_app: unknown client");
267 uifw_trace("ico_mgr_add_input_app: Leave(unknown client=%08x)", (int)client);
270 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_CONTROL_ADD_INPUT_APP) == 0) {
271 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
272 "ico_input_mgr_control_add_input_app: not permitted");
273 uifw_trace("ico_mgr_add_input_app: Leave(%s not permitted)", uclient->appid);
277 pIctlMgr = find_ictlmgr_by_device(device);
279 /* not configure input controller, create */
280 ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
281 pIctlMgr = find_ictlmgr_by_device(device);
283 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
287 pInput = find_ictlinput_by_input(pIctlMgr, input);
289 /* not configure input switch, create */
290 ico_device_configure_input(NULL, NULL, device, 0, NULL, input, NULL, 0);
291 pInput = find_ictlinput_by_input(pIctlMgr, input);
293 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
298 /* find application */
299 pAppMgr = find_app_by_appid(appid);
301 /* create Application Management Table */
302 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
304 uifw_error("ico_mgr_add_input_app: Leave(No Memory)");
307 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
308 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
309 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
312 pInput->app = pAppMgr;
314 uifw_trace("ico_mgr_add_input_app: Leave(%s.%s[%d] assign to %s)",
315 pIctlMgr->device, pInput->swname ? pInput->swname : "(NULL)", input,
319 /*--------------------------------------------------------------------------*/
321 * @brief ico_mgr_del_input_app: delete input event at application from HomeScreen.
323 * @param[in] client client(HomeScreen)
324 * @param[in] resource resource of request
325 * @param[in] appid target application id,
326 * if NULL, all applictions without fixed assign switch
327 * @param[in] device device name
328 * if NULL, all device without fixed assign switch
329 * @param[in] input input switch number
330 * if -1, all input without fixed assign switch
333 /*--------------------------------------------------------------------------*/
335 ico_mgr_del_input_app(struct wl_client *client, struct wl_resource *resource,
336 const char *appid, const char *device, int32_t input)
338 struct uifw_client *uclient;
340 struct ico_ictl_mgr *pIctlMgr = NULL;
341 struct ico_ictl_input *pInput = NULL;
342 struct ico_app_mgr *pAppMgr;
344 uifw_trace("ico_mgr_del_input_app: Enter(appid=%s,dev=%s,input=%d)",
345 appid ? appid : "(NULL)", device ? device : "(NULL)", input);
347 /* check for access control */
348 if (resource != NULL) {
349 /* resource is NULL, internal use */
350 uclient = ico_window_mgr_find_uclient(client);
352 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
353 "ico_input_mgr_control_del_input_app: unknown client");
354 uifw_trace("ico_mgr_del_input_app: Leave(unknown client=%08x)", (int)client);
357 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_CONTROL_DEL_INPUT_APP) == 0) {
358 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
359 "ico_input_mgr_control_del_input_app: not permitted");
360 uifw_trace("ico_mgr_del_input_app: Leave(%s not permitted)", uclient->appid);
364 if ((device != NULL) && (*device != 0)) {
365 pIctlMgr = find_ictlmgr_by_device(device);
367 /* not configure input controller, NOP */
368 uifw_trace("ico_mgr_del_input_app: Leave(%s dose not exist)", device);
372 pInput = find_ictlinput_by_input(pIctlMgr, input);
374 /* not configure input switch, NOP */
375 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d dose not exist)",
385 /* find application */
386 if ((appid != NULL) && (*appid != 0)) {
387 pAppMgr = find_app_by_appid(appid);
389 /* application dose not exist, NOP */
390 uifw_trace("ico_mgr_del_input_app: Leave(app.%s dose not exist)", appid);
395 if (pInput->app != pAppMgr) {
396 /* not same application, NOP */
397 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d not app.%s, current %s)",
398 device, input, appid,
399 pInput->app ? pInput->app->appid : "(NULL)");
402 uifw_trace("ico_mgr_del_input_app: Leave(%s.%d app.%s deleted)",
403 device, input, appid);
408 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
409 if ((pInput->fix == 0) && (pInput->app == pAppMgr)) {
410 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
411 pIctlMgr->device, pInput->input, appid);
418 /* reset all device without fixed assign */
419 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
420 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
421 if ((pInput->fix == 0) && (pInput->app == pAppMgr)) {
422 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
423 pIctlMgr->device, pInput->input, pInput->app->appid);
433 if ((pInput->fix == 0) && (pInput->app != NULL)) {
434 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
435 pIctlMgr->device, pInput->input, pInput->app->appid);
440 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
441 if ((pInput->fix == 0) && (pInput->app != NULL)) {
442 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
443 pIctlMgr->device, pInput->input, pInput->app->appid);
450 /* reset all application without fixed assign */
451 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
452 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
453 if ((pInput->fix == 0) && (pInput->app != NULL)) {
454 uifw_trace("ico_mgr_del_input_app: %s.%d app.%s deleted",
455 pIctlMgr->device, pInput->input, pInput->app->appid);
462 uifw_trace("ico_mgr_del_input_app: Leave");
465 /*--------------------------------------------------------------------------*/
467 * @brief ico_mgr_send_input_event: send input event from manager
469 * @param[in] client client(HomeScreen)
470 * @param[in] resource resource of request
471 * @param[in] target target window name and application id
472 * @param[in] surfaceid target surface id
473 * @param[in] type event device type
474 * @param[in] deviceno device number
475 * @param[in] time event time (if 0, generate)
476 * @param[in] code event code
477 * @param[in] value event value
480 /*--------------------------------------------------------------------------*/
482 ico_mgr_send_input_event(struct wl_client *client, struct wl_resource *resource,
483 const char *target, uint32_t surfaceid, int32_t type,
484 int32_t deviceno, uint32_t time, int32_t code, int32_t value)
486 struct uifw_client *uclient;
487 struct uifw_win_surface *usurf; /* UIFW surface */
488 struct uifw_input_device *dev; /* device control table */
489 struct wl_resource *cres; /* event send client resource */
490 struct wl_array dummy_array; /* dummy array for wayland API */
491 uint32_t ctime; /* current time(ms) */
492 uint32_t serial; /* event serial number */
493 int event; /* event flag */
494 wl_fixed_t fix_x; /* wayland X coordinate */
495 wl_fixed_t fix_y; /* wayland Y coordinate */
496 wl_fixed_t dx, dy; /* relative coordinate (dummy) */
497 struct weston_surface *grabsave; /* real grab surface */
498 int keyboard_active; /* keyborad active surface flag */
500 #if 0 /* too many log */
501 uifw_debug("ico_mgr_send_input_event: Enter(target=%s surf=%x dev=%d.%d "
502 "time=%d code=%x value=%d)",
503 target ? target : "(NULL)", surfaceid, type, deviceno,
507 /* check for access control */
508 if (resource != NULL) {
509 /* resource is NULL, internal use */
510 uclient = ico_window_mgr_find_uclient(client);
512 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
513 "ico_input_mgr_control_send_input_event: unknown client");
514 uifw_trace("ico_mgr_send_input_event: Leave(unknown client=%08x)", (int)client);
517 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_CONTROL_ADD_INPUT_APP) == 0) {
518 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
519 "ico_input_mgr_control_send_input_event: not permitted");
520 uifw_trace("ico_mgr_send_input_event: Leave(%s not permitted)", uclient->appid);
524 /* search pseudo input device */
525 wl_list_for_each (dev, &pInputMgr->dev_list, link) {
526 if ((dev->type == type) && (dev->no == deviceno)) break;
528 if (&dev->link == &pInputMgr->dev_list) {
529 /* device not exist, create new device */
530 uifw_trace("ico_mgr_send_input_event: new device=%d no=%d", type, deviceno);
531 dev = malloc(sizeof(struct uifw_input_device));
533 uifw_error("ico_mgr_send_input_event: Leave(No Memory)");
536 memset(dev, 0, sizeof(struct uifw_input_device));
539 if ((type == ICO_INPUT_MGR_DEVICE_TYPE_POINTER) ||
540 (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) ||
541 (type == ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC)) {
542 ico_window_mgr_get_display_coordinate(deviceno, &dev->disp_x, &dev->disp_y);
544 wl_list_insert(pInputMgr->dev_list.prev, &dev->link);
547 /* convert pending event */
549 if ((code & 0xffff0000) != (EV_REL << 16)) {
553 case ICO_INPUT_MGR_DEVICE_TYPE_POINTER: /* mouse */
554 case ICO_INPUT_MGR_DEVICE_TYPE_TOUCH: /* touch panel */
555 case ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC: /* haptic */
558 if (dev->pending & PENDING_Y) {
560 dev->y = dev->pend_y;
564 event = EVENT_MOTION;
568 dev->pending |= PENDING_X;
569 event = EVENT_PENDING;
573 if (dev->pending & PENDING_X) {
574 dev->x = dev->pend_x;
579 event = EVENT_MOTION;
583 dev->pending |= PENDING_Y;
584 event = EVENT_PENDING;
588 dev->x = (short)(value >> 16);
589 dev->y = (short)(value & 0x0ffff);
593 event = EVENT_MOTION;
595 case ((EV_REL << 16) | REL_X):
596 if (dev->pending & PENDING_Y) {
598 dev->y = dev->pend_y;
602 event = EVENT_MOTION;
605 dev->pend_x = dev->x + value;
606 dev->pending |= PENDING_X;
607 event = EVENT_PENDING;
610 case ((EV_REL << 16) | REL_Y):
611 if (dev->pending & PENDING_X) {
612 dev->x = dev->pend_x;
617 event = EVENT_MOTION;
620 dev->pend_x = dev->y + value;
621 dev->pending |= PENDING_Y;
622 event = EVENT_PENDING;
625 case ((EV_REL << 16) | REL_Z):
626 dev->x += (short)(value >> 16);
627 dev->y += (short)(value & 0x0ffff);
631 event = EVENT_MOTION;
634 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
638 event = EVENT_BUTTON;
648 if (event == EVENT_PENDING) {
649 #if 0 /* too many log */
650 uifw_debug("ico_mgr_send_input_event: Leave(event pending)");
659 ctime = weston_compositor_get_time();
661 fix_x = wl_fixed_from_int(dev->x + dev->disp_x);
662 fix_y = wl_fixed_from_int(dev->y + dev->disp_y);
664 if ((surfaceid == 0) && ((target == NULL) || (*target == 0) || (*target == ' '))) {
665 /* send event to surface via weston */
667 /* disable the event transmission to a input layer */
668 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
669 ico_window_mgr_touch_layer(TRUE);
672 if ((event == EVENT_TOUCH) && (pInputMgr->seat->touch == NULL)) {
673 /* system has no touch, change to pointer event */
674 if (pInputMgr->seat->pointer == NULL) {
675 uifw_trace("ico_mgr_send_input_event: Leave(no touch & no pointerr)");
678 event = EVENT_BUTTON;
681 else if ((event == EVENT_BUTTON) && (pInputMgr->seat->pointer == NULL)) {
682 /* system has no pointer, change to touch event */
683 if (pInputMgr->seat->touch == NULL) {
684 uifw_trace("ico_mgr_send_input_event: Leave(no touch & no pointerr)");
692 if ((type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) &&
693 (pInputMgr->seat->touch)) {
694 if (pInputMgr->seat->num_tp > 10) {
695 uifw_debug("ico_mgr_send_input_event: num=%d reset",
696 pInputMgr->seat->num_tp);
697 pInputMgr->seat->num_tp = 0; /* safty gard */
699 grabsave = pInputMgr->seat->touch->focus;
700 uifw_debug("ico_mgr_send_input_event: MOTION(%d/%d) grab %08x org %08x",
701 fix_x/256, fix_y/256, (int)dev->grab, (int)grabsave);
702 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
703 weston_touch_set_focus(pInputMgr->seat, dev->grab);
705 notify_touch(pInputMgr->seat, ctime, 0, fix_x, fix_y, WL_TOUCH_MOTION);
706 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
707 weston_touch_set_focus(pInputMgr->seat, grabsave);
710 else if (pInputMgr->seat->pointer) {
711 #if 0 /* too many log */
712 uifw_debug("ico_mgr_send_input_event: notify_motion_absolute(%d/%d)",
713 fix_x/256, fix_y/256);
715 notify_motion_absolute(pInputMgr->seat, ctime, fix_x, fix_y);
719 uifw_trace("ico_mgr_send_input_event: notify_button(%d,%d)", code, value);
720 if (pInputMgr->seat->pointer) {
722 dev->grab = weston_compositor_pick_surface(
723 pInputMgr->compositor, fix_x, fix_y, &dx, &dy);
724 weston_pointer_set_focus(pInputMgr->seat->pointer, dev->grab, dx, dy);
725 ico_window_mgr_active_surface(dev->grab);
730 notify_button(pInputMgr->seat, ctime, code,
731 value ? WL_POINTER_BUTTON_STATE_PRESSED :
732 WL_POINTER_BUTTON_STATE_RELEASED);
736 if (value == ICO_INPUT_MGR_CONTROL_TOUCH_EVENT_RESET) {
737 /* reset touch focus */
738 grabsave = pInputMgr->seat->touch->focus;
739 uifw_trace("ico_mgr_send_input_event: notify_touch(UnGrab dev=%08x sys=%08x)",
740 (int)dev->grab, (int)grabsave);
743 weston_touch_set_focus(pInputMgr->seat, NULL);
744 if (pInputMgr->seat->num_tp > 0) {
745 uifw_debug("ico_mgr_send_input_event: num=%d reset for reset focuse",
746 pInputMgr->seat->num_tp);
747 pInputMgr->seat->num_tp = 0;
751 else if (value == ICO_INPUT_MGR_CONTROL_TOUCH_EVENT_DOWN) {
752 grabsave = pInputMgr->seat->touch->focus;
753 dev->grab = weston_compositor_pick_surface(
754 pInputMgr->compositor, fix_x, fix_y, &dx, &dy);
755 uifw_trace("ico_mgr_send_input_event: notify_touch(DOWN=%d/%d) "
756 "grab=%08x org=%08x", fix_x/256, fix_y/256,
757 (int)dev->grab, (int)grabsave);
758 if (grabsave != dev->grab) {
759 weston_touch_set_focus(pInputMgr->seat, dev->grab);
761 if (pInputMgr->seat->num_tp > 0) {
762 uifw_debug("ico_mgr_send_input_event: touch_down illegal num, modify");
763 weston_touch_set_focus(pInputMgr->seat, NULL);
764 pInputMgr->seat->num_tp = 0;
766 notify_touch(pInputMgr->seat, ctime, 0, fix_x, fix_y, WL_TOUCH_DOWN);
767 ico_window_mgr_active_surface(dev->grab);
770 grabsave = pInputMgr->seat->touch->focus;
771 uifw_trace("ico_mgr_send_input_event: notify_touch(UP) org=%08x",
773 if ((grabsave != dev->grab) && (dev->grab != NULL)) {
774 weston_touch_set_focus(pInputMgr->seat, dev->grab);
776 if ((pInputMgr->seat->num_tp == 0) || (pInputMgr->seat->num_tp > 10)) {
777 uifw_debug("ico_mgr_send_input_event: num=%d reset",
778 pInputMgr->seat->num_tp);
779 pInputMgr->seat->num_tp = 1;
781 notify_touch(pInputMgr->seat, ctime, 0, 0, 0, WL_TOUCH_UP);
782 if (grabsave == dev->grab) grabsave = NULL;
783 weston_touch_set_focus(pInputMgr->seat, grabsave);
788 uifw_trace("ico_mgr_send_input_event: notify_key(%d,%d)", code, value);
789 notify_key(pInputMgr->seat, ctime, code,
790 value ? WL_KEYBOARD_KEY_STATE_PRESSED :
791 WL_KEYBOARD_KEY_STATE_RELEASED, STATE_UPDATE_NONE);
794 uifw_trace("ico_mgr_send_input_event: unknown event=%d", event);
797 /* enable the event transmission to a input layer */
798 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
799 ico_window_mgr_touch_layer(FALSE);
803 if ((target != NULL) && (*target != 0) && (*target != ' ')) {
804 /* send event to fixed application */
806 /* get application surface */
807 usurf = ico_window_mgr_get_client_usurf(target);
809 uifw_trace("ico_mgr_send_input_event: Leave(window=%s dose not exist)",
815 /* get UIFW surface */
816 usurf = ico_window_mgr_get_usurf(surfaceid);
818 uifw_trace("ico_mgr_send_input_event: Leave(surface dose not exist)");
826 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
827 cres = wl_resource_find_for_client(
828 &pInputMgr->seat->touch->resource_list,
829 wl_resource_get_client(usurf->surface->resource));
831 wl_touch_send_motion(cres, ctime, 0, fix_x, fix_y);
835 cres = wl_resource_find_for_client(
836 &pInputMgr->seat->pointer->resource_list,
837 wl_resource_get_client(usurf->surface->resource));
839 wl_pointer_send_motion(cres, ctime, fix_x, fix_y);
844 cres = wl_resource_find_for_client(
845 &pInputMgr->seat->pointer->resource_list,
846 wl_resource_get_client(usurf->surface->resource));
848 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
849 wl_pointer_send_button(cres, serial, ctime, code,
850 value ? WL_POINTER_BUTTON_STATE_PRESSED :
851 WL_POINTER_BUTTON_STATE_RELEASED);
855 cres = wl_resource_find_for_client(
856 &pInputMgr->seat->touch->resource_list,
857 wl_resource_get_client(usurf->surface->resource));
859 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
861 wl_touch_send_down(cres, serial, ctime, usurf->surface->resource, 0,
865 wl_touch_send_up(cres, serial, ctime, 0);
870 cres = wl_resource_find_for_client(
871 &pInputMgr->seat->keyboard->resource_list,
872 wl_resource_get_client(usurf->surface->resource));
874 keyboard_active = ico_window_mgr_ismykeyboard(usurf);
875 if (! keyboard_active) {
876 wl_array_init(&dummy_array);
877 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
878 wl_keyboard_send_enter(cres, serial,
879 usurf->surface->resource, &dummy_array);
881 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
882 uifw_trace("ico_mgr_send_input_event: send Key (%d, %d) to %08x",
883 code, value, usurf->surfaceid);
884 wl_keyboard_send_key(cres, serial, ctime, code,
885 value ? WL_KEYBOARD_KEY_STATE_PRESSED :
886 WL_KEYBOARD_KEY_STATE_RELEASED);
887 if (! keyboard_active) {
888 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
889 wl_keyboard_send_leave(cres, serial, usurf->surface->resource);
893 uifw_trace("ico_mgr_send_input_event: Key client %08x dose not exist",
894 (int)usurf->surface->resource);
901 #if 0 /* too many log */
902 uifw_debug("ico_mgr_send_input_event: Leave");
906 /*--------------------------------------------------------------------------*/
908 * @brief ico_mgr_set_input_region: set input region for haptic devcie
910 * @param[in] client client(Device Input Controller)
911 * @param[in] resource resource of request
912 * @param[in] target target window (winname@appid)
913 * @param[in] x input region X coordinate
914 * @param[in] y input region X coordinate
915 * @param[in] width input region width
916 * @param[in] height input region height
917 * @param[in] hotspot_x hotspot of X relative coordinate
918 * @param[in] hotspot_y hotspot of Y relative coordinate
919 * @param[in] cursor_x cursor region X coordinate
920 * @param[in] cursor_y cursor region X coordinate
921 * @param[in] cursor_width cursor region width
922 * @param[in] cursor_height cursor region height
923 * @param[in] attr region attributes(currently unused)
926 /*--------------------------------------------------------------------------*/
928 ico_mgr_set_input_region(struct wl_client *client, struct wl_resource *resource,
929 const char *target, int32_t x, int32_t y,
930 int32_t width, int32_t height, int32_t hotspot_x,
931 int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
932 int32_t cursor_width, int32_t cursor_height, uint32_t attr)
934 struct uifw_client *uclient;
935 struct uifw_win_surface *usurf; /* UIFW surface */
937 uifw_trace("ico_mgr_set_input_region: Enter(%s %d/%d-%d/%d(%d/%d) %d/%d-%d/%d)",
938 target, x, y, width, height, hotspot_x, hotspot_y,
939 cursor_x, cursor_y, cursor_width, cursor_height);
941 /* check for access control */
942 if (resource != NULL) {
943 /* resource is NULL, internal use */
944 uclient = ico_window_mgr_find_uclient(client);
946 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
947 "ico_exapi_input_set_input_region: unknown client");
948 uifw_trace("ico_mgr_set_input_region: Leave(unknown client=%08x)", (int)client);
951 if ((uclient->api_access_control & ICO_UIFW_EXINPUT_SET_INPUT_REGION) == 0) {
952 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
953 "ico_exapi_input_set_input_region: not permitted");
954 uifw_trace("ico_mgr_set_input_region: Leave(%s not permitted)", uclient->appid);
958 /* get target surface */
959 usurf = ico_window_mgr_get_client_usurf(target);
961 uifw_warn("ico_mgr_set_input_region: Leave(target<%s> dose not exist)", target);
965 ico_set_input_region(1, usurf, x, y, width, height, hotspot_x, hotspot_y,
966 cursor_x, cursor_y, cursor_width, cursor_height, attr);
968 uifw_trace("ico_mgr_set_input_region: Leave");
971 /*--------------------------------------------------------------------------*/
973 * @brief ico_mgr_unset_input_region: unset input region for haptic devcie
975 * @param[in] client client(Device Input Controller)
976 * @param[in] resource resource of request
977 * @param[in] target target window (winname@appid)
978 * @param[in] x input region X coordinate
979 * @param[in] y input region X coordinate
980 * @param[in] width input region width
981 * @param[in] height input region height
984 /*--------------------------------------------------------------------------*/
986 ico_mgr_unset_input_region(struct wl_client *client, struct wl_resource *resource,
987 const char *target, int32_t x, int32_t y,
988 int32_t width, int32_t height)
990 struct uifw_client *uclient;
991 struct uifw_win_surface *usurf; /* UIFW surface */
993 uifw_trace("ico_mgr_unset_input_region: Enter(%s %d/%d-%d/%d)",
994 target, x, y, width, height);
996 /* check for access control */
997 if (resource != NULL) {
998 /* resource is NULL, internal use */
999 uclient = ico_window_mgr_find_uclient(client);
1001 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1002 "ico_exapi_input_unset_input_region: unknown client");
1003 uifw_trace("ico_mgr_unset_input_region: Leave(unknown client=%08x)", (int)client);
1006 if ((uclient->api_access_control & ICO_UIFW_EXINPUT_UNSET_INPUT_REGION) == 0) {
1007 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1008 "ico_exapi_input_unset_input_region: not permitted");
1009 uifw_trace("ico_mgr_unset_input_region: Leave(%s not permitted)", uclient->appid);
1013 /* get target surface */
1014 usurf = ico_window_mgr_get_client_usurf(target);
1016 uifw_warn("ico_mgr_unset_input_region: Leave(target<%s> dose not exist)", target);
1020 ico_set_input_region(0, usurf, x, y, width, height, 0, 0, 0, 0, 0, 0, 0);
1022 uifw_trace("ico_mgr_unset_input_region: Leave");
1025 /*--------------------------------------------------------------------------*/
1027 * @brief ico_input_hook_region_change: change surface attribute
1029 * @param[in] usurf UIFW surface
1032 /*--------------------------------------------------------------------------*/
1034 ico_input_hook_region_change(struct uifw_win_surface *usurf)
1036 struct uifw_region_mng *p; /* input region mamagement table*/
1037 struct ico_uifw_input_region *rp; /* input region */
1038 struct wl_array array;
1042 visible = ico_window_mgr_is_visible(usurf);
1044 uifw_trace("ico_input_hook_region_change: Entery(surf=%08x, visible=%d)",
1045 usurf->surfaceid, visible);
1047 wl_array_init(&array);
1049 wl_list_for_each(p, &usurf->input_region, link) {
1050 if (((p->region.change > 0) && (visible <= 0)) ||
1051 ((p->region.change <= 0) && (visible > 0))) {
1052 /* visible change, send add/remove event */
1053 rp = (struct ico_uifw_input_region *)
1054 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1057 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1059 rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
1062 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1065 p->region.change = visible;
1066 p->region.node = usurf->node_tbl->node;
1067 p->region.surface_x = usurf->x;
1068 p->region.surface_y = usurf->y;
1070 else if ((p->region.node != usurf->node_tbl->node) ||
1071 (p->region.surface_x != usurf->x) ||
1072 (p->region.surface_y != usurf->y)) {
1073 /* surface position change, send change event */
1074 p->region.node = usurf->node_tbl->node;
1075 p->region.surface_x = usurf->x;
1076 p->region.surface_y = usurf->y;
1078 rp = (struct ico_uifw_input_region *)
1079 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1082 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1083 rp->change = ICO_INPUT_MGR_DEVICE_REGION_CHANGE;
1088 /* send region delete to haptic device input controller */
1089 ico_input_send_region_event(&array);
1091 uifw_trace("ico_input_hook_region_change: Leave");
1094 /*--------------------------------------------------------------------------*/
1096 * @brief ico_input_hook_region_destroy: destory surface
1098 * @param[in] usurf UIFW surface
1101 /*--------------------------------------------------------------------------*/
1103 ico_input_hook_region_destroy(struct uifw_win_surface *usurf)
1105 struct uifw_region_mng *p; /* input region mamagement table*/
1106 struct uifw_region_mng *np; /* next region mamagement table */
1107 struct ico_uifw_input_region *rp; /* input region */
1108 struct wl_array array;
1111 uifw_trace("ico_input_hook_region_destroy: Entery(surf=%08x)", usurf->surfaceid);
1113 wl_array_init(&array);
1115 wl_list_for_each_safe(p, np, &usurf->input_region, link) {
1116 if (p->region.change > 0) {
1117 /* visible, send remove event */
1118 rp = (struct ico_uifw_input_region *)
1119 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1122 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1123 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1126 wl_list_remove(&p->link);
1127 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1130 /* send region delete to haptic device input controller */
1131 ico_input_send_region_event(&array);
1133 uifw_trace("ico_input_hook_region_destroy: Leave");
1136 /*--------------------------------------------------------------------------*/
1138 * @brief ico_set_input_region: input region set/unset
1140 * @param[in] set set(1)/unset(0)
1141 * @param[in] usurf UIFW surface
1142 * @param[in] x input region X coordinate
1143 * @param[in] y input region X coordinate
1144 * @param[in] width input region width
1145 * @param[in] height input region height
1146 * @param[in] hotspot_x hotspot of X relative coordinate
1147 * @param[in] hotspot_y hotspot of Y relative coordinate
1148 * @param[in] cursor_x cursor region X coordinate
1149 * @param[in] cursor_y cursor region X coordinate
1150 * @param[in] cursor_width cursor region width
1151 * @param[in] cursor_height cursor region height
1152 * @param[in] attr region attributes(currently unused)
1155 /*--------------------------------------------------------------------------*/
1157 ico_set_input_region(int set, struct uifw_win_surface *usurf,
1158 int32_t x, int32_t y, int32_t width, int32_t height,
1159 int32_t hotspot_x, int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
1160 int32_t cursor_width, int32_t cursor_height, uint32_t attr)
1162 struct uifw_region_mng *p; /* input region mamagement table*/
1163 struct uifw_region_mng *np; /* next region mamagement table */
1164 struct ico_uifw_input_region *rp; /* input region */
1165 struct wl_array array;
1170 uifw_trace("ico_set_input_region: Enter(%s %d/%d-%d/%d(%d/%d) %d/%d-%d/%d)",
1171 set ? "Set" : "Unset", x, y, width, height, hotspot_x, hotspot_y,
1172 cursor_x, cursor_y, cursor_width, cursor_height);
1175 if (wl_list_empty(&pInputMgr->free_region)) {
1176 p = malloc(sizeof(struct uifw_region_mng) * 50);
1178 uifw_error("ico_set_input_region: No Memory");
1181 memset(p, 0, sizeof(struct uifw_region_mng)*50);
1182 for (i = 0; i < 50; i++, p++) {
1183 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1186 p = container_of(pInputMgr->free_region.next, struct uifw_region_mng, link);
1187 wl_list_remove(&p->link);
1188 p->region.node = usurf->node_tbl->node;
1189 p->region.surfaceid = usurf->surfaceid;
1190 p->region.surface_x = usurf->x;
1191 p->region.surface_y = usurf->y;
1194 p->region.width = width;
1195 p->region.height = height;
1196 if ((hotspot_x <= 0) && (hotspot_y <= 0)) {
1197 p->region.hotspot_x = width / 2;
1198 p->region.hotspot_y = height / 2;
1201 p->region.hotspot_x = hotspot_x;
1202 p->region.hotspot_y = hotspot_y;
1204 if ((cursor_width <= 0) && (cursor_height <= 0)) {
1205 p->region.cursor_x = x;
1206 p->region.cursor_y = y;
1207 p->region.cursor_width = width;
1208 p->region.cursor_height = height;
1211 p->region.cursor_x = cursor_x;
1212 p->region.cursor_y = cursor_y;
1213 p->region.cursor_width = cursor_width;
1214 p->region.cursor_height = cursor_height;
1216 p->region.change = ico_window_mgr_is_visible(usurf);
1217 wl_list_insert(usurf->input_region.prev, &p->link);
1219 /* send input region to haptic device input controller */
1220 if (p->region.change > 0) {
1221 wl_array_init(&array);
1222 rp = (struct ico_uifw_input_region *)
1223 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1225 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1226 rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
1227 ico_input_send_region_event(&array);
1229 uifw_trace("ico_set_input_region: Leave(Set)");
1232 uifw_trace("ico_set_input_region: Leave(Set but Unvisible)");
1238 if ((x <= 0) && (y <= 0) && (width <= 0) && (height <= 0)) {
1245 wl_array_init(&array);
1247 wl_list_for_each_safe(p, np, &usurf->input_region, link) {
1248 if ((alldel != 0) ||
1249 ((x == p->region.x) && (y == p->region.y) &&
1250 (width == p->region.width) && (height == p->region.height))) {
1251 if (p->region.change > 0) {
1252 /* visible, send remove event */
1253 rp = (struct ico_uifw_input_region *)
1254 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1257 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1258 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1261 wl_list_remove(&p->link);
1262 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1266 /* send region delete to haptic device input controller */
1267 ico_input_send_region_event(&array);
1269 uifw_trace("ico_set_input_region: Leave(Unset)");
1273 /*--------------------------------------------------------------------------*/
1275 * @brief ico_input_send_region_event: send region event to Haptic dic
1277 * @param[in] usurf UIFW surface
1280 /*--------------------------------------------------------------------------*/
1282 ico_input_send_region_event(struct wl_array *array)
1284 struct ico_ictl_mgr *pIctlMgr;
1286 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1287 if ((pIctlMgr->type == ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC) &&
1288 (pIctlMgr->mgr_resource != NULL)) {
1289 uifw_trace("ico_input_send_region_event: send event to Hapfic");
1290 ico_input_mgr_device_send_input_regions(pIctlMgr->mgr_resource, array);
1295 /*--------------------------------------------------------------------------*/
1297 * @brief ico_device_configure_input: configure input device and input switch
1298 * from Device Input Controller.
1300 * @param[in] client client(Device Input Controller)
1301 * @param[in] resource resource of request
1302 * @param[in] device device name
1303 * @param[in] type device type(saved but unused)
1304 * @param[in] swname input switch name
1305 * @param[in] input input switch number
1306 * @param[in] codename input code name
1307 * @param[in] code input code number
1310 /*--------------------------------------------------------------------------*/
1312 ico_device_configure_input(struct wl_client *client, struct wl_resource *resource,
1313 const char *device, int32_t type, const char *swname,
1314 int32_t input, const char *codename, int32_t code)
1316 struct uifw_client *uclient;
1317 struct ico_ictl_mgr *pIctlMgr;
1318 struct ico_ictl_mgr *psameIctlMgr;
1319 struct ico_ictl_input *pInput;
1320 struct ico_app_mgr *pAppMgr;
1322 uifw_trace("ico_device_configure_input: Enter(client=%08x,dev=%s,type=%d,swname=%s,"
1323 "input=%d,code=%d[%s])", (int)client, device, type,
1324 swname ? swname : "(NULL)", input, code, codename ? codename : " ");
1326 /* check for access control */
1327 if (resource != NULL) {
1328 /* resource is NULL, internal use */
1329 uclient = ico_window_mgr_find_uclient(client);
1331 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1332 "ico_input_mgr_device_configure_input: unknown client");
1333 uifw_trace("ico_device_configure_input: Leave(unknown client=%08x)", (int)client);
1336 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_DEVICE_CONFIGURE_INPUT) == 0) {
1337 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1338 "ico_input_mgr_device_configure_input: not permitted");
1339 uifw_trace("ico_device_configure_input: Leave(%s not permitted)", uclient->appid);
1343 pIctlMgr = find_ictlmgr_by_device(device);
1345 /* search binded table */
1346 psameIctlMgr = NULL;
1347 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1348 if (pIctlMgr->client == client) {
1349 uifw_trace("ico_device_configure_input: set pIctlMgr"
1350 "(mgr=%08x,input=%d,dev=%s)", (int)pIctlMgr,
1351 input, pIctlMgr->device);
1352 if (pIctlMgr->device[0] != 0) {
1353 /* save same device */
1354 psameIctlMgr = pIctlMgr;
1358 strncpy(pIctlMgr->device, device, sizeof(pIctlMgr->device)-1);
1359 psameIctlMgr = NULL;
1365 /* client(device input controller) exist, but other device */
1366 pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
1367 if (pIctlMgr == NULL) {
1368 uifw_error("ico_device_bind: Leave(No Memory)");
1371 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1372 wl_list_init(&pIctlMgr->ico_ictl_input);
1373 pIctlMgr->client = psameIctlMgr->client;
1374 pIctlMgr->mgr_resource = psameIctlMgr->mgr_resource;
1376 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1381 pIctlMgr->type = type;
1384 /* search and add input switch */
1385 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1386 if (pInput->input == input) break;
1388 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
1389 uifw_trace("ico_device_configure_input: create %s.%s(%d) switch",
1390 device, swname, input);
1391 pInput = (struct ico_ictl_input *)malloc(sizeof(struct ico_ictl_input));
1392 if (pInput == NULL) {
1393 uifw_error("ico_device_configure_input: Leave(No Memory)");
1396 memset(pInput, 0, sizeof(struct ico_ictl_input));
1398 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1401 strcpy(pInput->swname, "(Unknown)");
1403 wl_list_insert(pIctlMgr->ico_ictl_input.prev, &pInput->link);
1406 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1408 pInput->input = input;
1409 memset(pInput->code, 0, sizeof(pInput->code));
1411 pInput->code[0].code = code;
1413 strncpy(pInput->code[0].name, codename, sizeof(pInput->code[0].name)-1);
1416 if (client == NULL) {
1417 /* internal call for table create */
1418 uifw_trace("ico_device_configure_input: Leave(table create)");
1421 pIctlMgr->client = client;
1423 /* send to application and manager(ex.HomeScreen) */
1424 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1425 if (pAppMgr->resource == NULL) continue;
1426 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
1428 uifw_trace("ico_device_configure_input: send capabilities to app(%s) %s.%s[%d]",
1429 pAppMgr->appid, device, pInput->swname, input);
1430 ico_exinput_send_capabilities(pAppMgr->resource, device, pIctlMgr->type,
1431 pInput->swname, input,
1432 pInput->code[0].name, pInput->code[0].code);
1434 uifw_trace("ico_device_configure_input: Leave");
1437 /*--------------------------------------------------------------------------*/
1439 * @brief ico_device_configure_code: add input switch from Device Input Controller.
1441 * @param[in] client client(Device Input Controller)
1442 * @param[in] resource resource of request
1443 * @param[in] device device name
1444 * @param[in] input input switch number
1445 * @param[in] codename input code name
1446 * @param[in] code input code number
1449 /*--------------------------------------------------------------------------*/
1451 ico_device_configure_code(struct wl_client *client, struct wl_resource *resource,
1452 const char *device, int32_t input,
1453 const char *codename, int32_t code)
1455 struct uifw_client *uclient;
1457 struct ico_ictl_mgr *pIctlMgr;
1458 struct ico_ictl_input *pInput;
1459 struct ico_app_mgr *pAppMgr;
1461 uifw_trace("ico_device_configure_code: Enter(client=%08x,dev=%s,input=%d,code=%d[%s])",
1462 (int)client, device, input, code, codename ? codename : " ");
1464 /* check for access control */
1465 if (resource != NULL) {
1466 /* resource is NULL, internal use */
1467 uclient = ico_window_mgr_find_uclient(client);
1469 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1470 "ico_input_mgr_device_configure_code: unknown client");
1471 uifw_trace("ico_device_configure_code: Leave(unknown client=%08x)", (int)client);
1474 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_DEVICE_CONFIGURE_CODE) == 0) {
1475 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1476 "ico_input_mgr_device_configure_code: not permitted");
1477 uifw_trace("ico_device_configure_code: Leave(%s not permitted)", uclient->appid);
1481 pIctlMgr = find_ictlmgr_by_device(device);
1483 uifw_warn("ico_device_configure_code: Leave(dev=%s dose not exist)", device);
1486 /* search input switch */
1487 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1488 if (pInput->input == input) break;
1490 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
1491 uifw_warn("ico_device_configure_code: Leave(input=%s.%d dose not exist)",
1496 /* search input code */
1497 for (i = 0; i < pInput->ncode; i++) {
1498 if (pInput->code[i].code == code) break;
1500 if (i >= pInput->ncode) {
1501 /* code dose not exist, add */
1502 if (pInput->ncode >= ICO_MINPUT_MAX_CODES) {
1503 uifw_warn("ico_device_configure_code: Leave(input=%s.%d code overflow)",
1509 pInput->code[i].code = code;
1511 memset(pInput->code[i].name, 0, sizeof(pInput->code[i].name));
1512 strncpy(pInput->code[i].name, codename, sizeof(pInput->code[i].name)-1);
1514 /* send to application and manager(ex.HomeScreen) */
1515 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1516 if (pAppMgr->resource == NULL) continue;
1517 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
1518 uifw_trace("ico_device_configure_input: send code to app(%s) %s.%s[%d]",
1519 pAppMgr->appid, device, pInput->swname, input);
1520 ico_exinput_send_code(pAppMgr->resource, device, input,
1521 pInput->code[i].name, pInput->code[i].code);
1523 uifw_trace("ico_device_configure_code: Leave");
1526 /*--------------------------------------------------------------------------*/
1528 * @brief ico_device_input_event: device input event from Device Input Controller.
1530 * @param[in] client client(Device Input Controller)
1531 * @param[in] resource resource of request
1532 * @param[in] time device input time(miri-sec)
1533 * @param[in] device device name
1534 * @param[in] input input switch number
1535 * @param[in] code input code number
1536 * @param[in] state input state(1=On, 0=Off)
1539 /*--------------------------------------------------------------------------*/
1541 ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
1542 uint32_t time, const char *device,
1543 int32_t input, int32_t code, int32_t state)
1545 struct uifw_client *uclient;
1546 struct ico_ictl_mgr *pIctlMgr;
1547 struct ico_ictl_input *pInput;
1549 uifw_trace("ico_device_input_event: Enter(time=%d,dev=%s,input=%d,code=%d,state=%d)",
1550 time, device, input, code, state);
1552 /* check for access control */
1553 if (resource != NULL) {
1554 /* resource is NULL, internal use */
1555 uclient = ico_window_mgr_find_uclient(client);
1557 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1558 "ico_input_mgr_device_input_event: unknown client");
1559 uifw_trace("ico_device_input_event: Leave(unknown client=%08x)", (int)client);
1562 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_DEVICE_INPUT_EVENT) == 0) {
1563 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1564 "ico_input_mgr_device_input_event: not permitted");
1565 uifw_trace("ico_device_input_event: Leave(%s not permitted)", uclient->appid);
1569 /* find input devcie by client */
1570 pIctlMgr = find_ictlmgr_by_device(device);
1572 uifw_error("ico_device_input_event: Leave(Unknown device(%s))", device);
1575 /* find input switch by input Id */
1576 pInput = find_ictlinput_by_input(pIctlMgr, input);
1578 uifw_warn("ico_device_input_event: Leave(Unknown input(%s,%d))",
1579 pIctlMgr->device, input);
1583 if (! pInput->app) {
1584 uifw_trace("ico_device_input_event: Leave(%s.%s not assign)",
1585 pIctlMgr->device, pInput->swname);
1588 if (! pInput->app->resource) {
1589 uifw_trace("ico_device_input_event: Leave(%s.%s assigned App.%s "
1590 "is not running or not interested)",
1591 pIctlMgr->device, pInput->swname, pInput->app->appid);
1595 /* send event to application */
1596 uifw_trace("ico_device_input_event: send event=%s.%s[%d],%d,%d to App.%s",
1597 pIctlMgr->device, pInput->swname, input, code, state, pInput->app->appid);
1598 ico_exinput_send_input(pInput->app->resource, time, pIctlMgr->device,
1599 input, code, state);
1601 uifw_trace("ico_device_input_event: Leave");
1604 /*--------------------------------------------------------------------------*/
1606 * @brief ico_control_bind: ico_input_mgr_control bind from HomeScreen
1608 * @param[in] client client(HomeScreen)
1609 * @param[in] data data(unused)
1610 * @param[in] version protocol version(unused)
1611 * @param[in] id client object id
1614 /*--------------------------------------------------------------------------*/
1616 ico_control_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1619 struct ico_app_mgr *pAppMgr;
1621 uifw_trace("ico_control_bind: Enter(client=%08x)", (int)client);
1622 appid = ico_window_mgr_get_appid(client);
1625 /* client dose not exist */
1626 uifw_warn("ico_control_bind: Leave(client=%08x dose not exist)", (int)client);
1630 /* find application */
1631 pAppMgr = find_app_by_appid(appid);
1633 /* create Application Management Table */
1634 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1636 uifw_error("ico_control_bind: Leave(No Memory)");
1639 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
1640 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
1641 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
1643 pAppMgr->client = client;
1644 if (! pAppMgr->mgr_resource) {
1645 pAppMgr->mgr_resource = wl_resource_create(client,
1646 &ico_input_mgr_control_interface, 1, id);
1647 if (pAppMgr->mgr_resource) {
1648 wl_resource_set_implementation(pAppMgr->mgr_resource,
1649 &ico_input_mgr_implementation,
1650 pInputMgr, ico_control_unbind);
1653 uifw_trace("ico_control_bind: Leave");
1656 /*--------------------------------------------------------------------------*/
1658 * @brief ico_control_unbind: ico_input_mgr_control unbind from HomeScreen
1660 * @param[in] resource client resource(HomeScreen)
1663 /*--------------------------------------------------------------------------*/
1665 ico_control_unbind(struct wl_resource *resource)
1667 struct ico_app_mgr *pAppMgr;
1669 uifw_trace("ico_control_unbind: Enter(resource=%08x)", (int)resource);
1671 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1672 if (pAppMgr->mgr_resource == resource) {
1673 uifw_trace("ico_control_unbind: find app.%s", pAppMgr->appid);
1674 pAppMgr->mgr_resource = NULL;
1678 uifw_trace("ico_control_unbind: Leave");
1681 /*--------------------------------------------------------------------------*/
1683 * @brief ico_device_bind: ico_input_mgr_device bind from Device Input Controller
1685 * @param[in] client client(Device Input Controller)
1686 * @param[in] data data(unused)
1687 * @param[in] version protocol version
1688 * @param[in] id client object id
1691 /*--------------------------------------------------------------------------*/
1693 ico_device_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1695 struct ico_ictl_mgr *pIctlMgr;
1696 struct wl_resource *mgr_resource;
1698 uifw_trace("ico_device_bind: Enter(client=%08x)", (int)client);
1700 /* create ictl mgr table */
1701 pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
1702 if (pIctlMgr == NULL) {
1703 uifw_error("ico_device_bind: Leave(No Memory)");
1706 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1707 wl_list_init(&pIctlMgr->ico_ictl_input);
1708 pIctlMgr->client = client;
1711 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1713 mgr_resource = wl_resource_create(client, &ico_input_mgr_device_interface, 1, id);
1715 pIctlMgr->mgr_resource = mgr_resource;
1716 wl_resource_set_implementation(mgr_resource, &input_mgr_ictl_implementation,
1717 pIctlMgr, ico_device_unbind);
1719 uifw_trace("ico_device_bind: Leave");
1722 /*--------------------------------------------------------------------------*/
1724 * @brief ico_device_unbind: ico_input_mgr_device unbind from Device Input Controller
1726 * @param[in] resource client resource(Device Input Controller)
1729 /*--------------------------------------------------------------------------*/
1731 ico_device_unbind(struct wl_resource *resource)
1733 uifw_trace("ico_device_unbind: Enter(resource=%08x)", (int)resource);
1734 uifw_trace("ico_device_unbind: Leave");
1737 /*--------------------------------------------------------------------------*/
1739 * @brief ico_exinput_bind: ico_exinput bind from Application
1741 * @param[in] client client(Application)
1742 * @param[in] data data(unused)
1743 * @param[in] version protocol version(unused)
1744 * @param[in] id client object id
1747 /*--------------------------------------------------------------------------*/
1749 ico_exinput_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1753 struct ico_app_mgr *pAppMgr;
1754 struct ico_ictl_mgr *pIctlMgr;
1755 struct ico_ictl_input *pInput;
1757 appid = ico_window_mgr_get_appid(client);
1758 uifw_trace("ico_exinput_bind: Enter(client=%08x,%s)", (int)client,
1759 appid ? appid : "(NULL)");
1762 /* client dose not exist */
1763 uifw_warn("ico_exinput_bind: Leave(client=%08x dose not exist)", (int)client);
1767 /* find application */
1768 pAppMgr = find_app_by_appid(appid);
1770 /* create Application Management Table */
1771 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1773 uifw_error("ico_exinput_bind: Leave(No Memory)");
1776 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
1777 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
1778 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
1779 uifw_trace("ico_exinput_bind: Create App.%s table", appid);
1781 pAppMgr->client = client;
1782 if (! pAppMgr->resource) {
1783 pAppMgr->resource = wl_resource_create(client, &ico_exinput_interface, 1, id);
1784 if (pAppMgr->resource) {
1785 wl_resource_set_implementation(pAppMgr->resource, &ico_exinput_implementation,
1786 pInputMgr, ico_exinput_unbind);
1790 /* send all capabilities */
1791 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1792 if (pIctlMgr->client == NULL) {
1793 uifw_trace("ico_exinput_bind: Input controller.%s not initialized",
1798 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1799 if (pInput->swname[0] == 0) {
1800 uifw_trace("ico_exinput_bind: Input %s not initialized", pIctlMgr->device);
1803 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) {
1804 uifw_trace("ico_exinput_bind: Input %s.%s fixed assign to App.%s",
1805 pIctlMgr->device, pInput->swname, pInput->app->appid);
1808 uifw_trace("ico_exinput_bind: send capabilities to app(%s) %s.%s[%d]",
1809 pAppMgr->appid, pIctlMgr->device, pInput->swname, pInput->input);
1810 ico_exinput_send_capabilities(pAppMgr->resource, pIctlMgr->device,
1811 pIctlMgr->type, pInput->swname, pInput->input,
1812 pInput->code[0].name, pInput->code[0].code);
1813 for (i = 1; i < pInput->ncode; i++) {
1814 ico_exinput_send_code(pAppMgr->resource, pIctlMgr->device, pInput->input,
1815 pInput->code[i].name, pInput->code[i].code);
1819 uifw_trace("ico_exinput_bind: Leave");
1822 /*--------------------------------------------------------------------------*/
1824 * @brief ico_exinput_unbind: ico_exinput unbind from Application
1826 * @param[in] resource client resource(Application)
1829 /*--------------------------------------------------------------------------*/
1831 ico_exinput_unbind(struct wl_resource *resource)
1833 struct ico_app_mgr *pAppMgr;
1834 struct ico_app_mgr *pAppMgrTmp;
1835 struct ico_ictl_mgr *pIctlMgr;
1836 struct ico_ictl_input *pInput;
1839 uifw_trace("ico_exinput_unbind: Enter(resource=%08x)", (int)resource);
1841 wl_list_for_each_safe (pAppMgr, pAppMgrTmp, &pInputMgr->app_list, link) {
1842 if (pAppMgr->resource == resource) {
1843 uifw_trace("ico_exinput_unbind: find app.%s", pAppMgr->appid);
1845 /* release application from input switch */
1846 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1847 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1848 if (pInput->app == pAppMgr) {
1849 if (pInput->fix == 0) {
1850 uifw_trace("ico_exinput_unbind: app.%s remove %s.%s",
1851 pAppMgr->appid, pIctlMgr->device, pInput->swname);
1855 uifw_trace("ico_exinput_unbind: app.%s fix assign %s.%s",
1856 pAppMgr->appid, pIctlMgr->device, pInput->swname);
1863 wl_list_remove(&pAppMgr->link);
1867 pAppMgr->client = NULL;
1868 pAppMgr->resource = NULL;
1872 uifw_trace("ico_exinput_unbind: Leave");
1875 /*--------------------------------------------------------------------------*/
1877 * @brief find_ictlmgr_by_device: find Input Controller by device name
1879 * @param[in] device device name
1880 * @return Input Controller Manager table address
1881 * @retval !=NULL address
1882 * @retval ==NULL not exist
1884 /*--------------------------------------------------------------------------*/
1885 static struct ico_ictl_mgr *
1886 find_ictlmgr_by_device(const char *device)
1888 struct ico_ictl_mgr *pIctlMgr;
1890 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1891 uifw_debug("find_ictlmgr_by_device: <%s> vs <%s>", device, pIctlMgr->device);
1892 if (strcmp(pIctlMgr->device, device) == 0) {
1899 /*--------------------------------------------------------------------------*/
1901 * @brief find_ictlinput_by_input: find Input Switch by input Id
1903 * @param[in] pIctlMgr Input Controller device
1904 * @param[in] input Input Id
1905 * @return Input Switch table address
1906 * @retval !=NULL address
1907 * @retval ==NULL not exist
1909 /*--------------------------------------------------------------------------*/
1910 static struct ico_ictl_input *
1911 find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr, const int32_t input)
1913 struct ico_ictl_input *pInput;
1915 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1916 if (pInput->input == input) {
1923 /*--------------------------------------------------------------------------*/
1925 * @brief find_app_by_appid: find Application by application Id
1927 * @param[in] appid application Id
1928 * @return Application Management table address
1929 * @retval !=NULL address
1930 * @retval ==NULL not exist
1932 /*--------------------------------------------------------------------------*/
1933 static struct ico_app_mgr *
1934 find_app_by_appid(const char *appid)
1936 struct ico_app_mgr *pAppMgr;
1938 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1939 if (strcmp(pAppMgr->appid, appid) == 0) {
1946 /*--------------------------------------------------------------------------*/
1948 * @brief module_init: initialization of this plugin
1950 * @param[in] ec weston compositor
1951 * @param[in] argc number of arguments(unused)
1952 * @param[in] argv argument list(unused)
1957 /*--------------------------------------------------------------------------*/
1959 module_init(struct weston_compositor *ec, int *argc, char *argv[])
1961 struct uifw_region_mng *p;
1964 uifw_info("ico_input_mgr: Enter(module_init)");
1966 /* initialize management table */
1967 pInputMgr = (struct ico_input_mgr *)malloc(sizeof(struct ico_input_mgr));
1968 if (pInputMgr == NULL) {
1969 uifw_trace("ico_input_mgr: malloc failed");
1972 memset(pInputMgr, 0, sizeof(struct ico_input_mgr));
1973 pInputMgr->compositor = ec;
1975 /* interface to desktop manager(ex.HomeScreen) */
1976 if (wl_global_create(ec->wl_display, &ico_input_mgr_control_interface, 1,
1977 pInputMgr, ico_control_bind) == NULL) {
1978 uifw_trace("ico_input_mgr: wl_global_create mgr failed");
1982 /* interface to Input Controller(ictl) */
1983 if (wl_global_create(ec->wl_display, &ico_input_mgr_device_interface, 1,
1984 pInputMgr, ico_device_bind) == NULL) {
1985 uifw_trace("ico_input_mgr: wl_global_create ictl failed");
1989 /* interface to App(exinput) */
1990 if (wl_global_create(ec->wl_display, &ico_exinput_interface, 1,
1991 pInputMgr, ico_exinput_bind) == NULL) {
1992 uifw_trace("ico_input_mgr: wl_global_create exseat failed");
1996 /* initialize list */
1997 wl_list_init(&pInputMgr->ictl_list);
1998 wl_list_init(&pInputMgr->app_list);
1999 wl_list_init(&pInputMgr->dev_list);
2000 wl_list_init(&pInputMgr->free_region);
2001 p = malloc(sizeof(struct uifw_region_mng)*100);
2003 memset(p, 0, sizeof(struct uifw_region_mng)*100);
2004 for (i = 0; i < 100; i++, p++) {
2005 wl_list_insert(pInputMgr->free_region.prev, &p->link);
2009 /* found input seat */
2010 pInputMgr->seat = container_of(ec->seat_list.next, struct weston_seat, link);
2012 /* set hook for input region control */
2013 ico_window_mgr_set_hook_change(ico_input_hook_region_change);
2014 ico_window_mgr_set_hook_destory(ico_input_hook_region_destroy);
2015 ico_window_mgr_set_hook_inputregion(ico_set_input_region);
2017 uifw_info("ico_input_mgr: Leave(module_init)");