2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2013-2014 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_view *grab; /* current grab surface view */
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_view *grabsave; /* real grab surface view */
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->touch->num_tp > 10) {
695 uifw_debug("ico_mgr_send_input_event: num=%d reset",
696 pInputMgr->seat->touch->num_tp);
697 pInputMgr->seat->touch->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_view(
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->surface);
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->touch->num_tp > 0) {
745 uifw_debug("ico_mgr_send_input_event: num=%d reset for reset focuse",
746 pInputMgr->seat->touch->num_tp);
747 pInputMgr->seat->touch->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_view(
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->touch->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->touch->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->surface);
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->touch->num_tp == 0) ||
777 (pInputMgr->seat->touch->num_tp > 10)) {
778 uifw_debug("ico_mgr_send_input_event: num=%d reset",
779 pInputMgr->seat->touch->num_tp);
780 pInputMgr->seat->touch->num_tp = 1;
782 notify_touch(pInputMgr->seat, ctime, 0, 0, 0, WL_TOUCH_UP);
783 if (grabsave == dev->grab) grabsave = NULL;
784 weston_touch_set_focus(pInputMgr->seat, grabsave);
789 uifw_trace("ico_mgr_send_input_event: notify_key(%d,%d)", code, value);
790 notify_key(pInputMgr->seat, ctime, code,
791 value ? WL_KEYBOARD_KEY_STATE_PRESSED :
792 WL_KEYBOARD_KEY_STATE_RELEASED, STATE_UPDATE_NONE);
795 uifw_trace("ico_mgr_send_input_event: unknown event=%d", event);
798 /* enable the event transmission to a input layer */
799 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
800 ico_window_mgr_touch_layer(FALSE);
804 if ((target != NULL) && (*target != 0) && (*target != ' ')) {
805 /* send event to fixed application */
807 /* get application surface */
808 usurf = ico_window_mgr_get_client_usurf(target);
810 uifw_trace("ico_mgr_send_input_event: Leave(window=%s dose not exist)",
816 /* get UIFW surface */
817 usurf = ico_window_mgr_get_usurf(surfaceid);
819 uifw_trace("ico_mgr_send_input_event: Leave(surface dose not exist)");
827 if (type == ICO_INPUT_MGR_DEVICE_TYPE_TOUCH) {
828 cres = wl_resource_find_for_client(
829 &pInputMgr->seat->touch->resource_list,
830 wl_resource_get_client(usurf->surface->resource));
832 wl_touch_send_motion(cres, ctime, 0, fix_x, fix_y);
836 cres = wl_resource_find_for_client(
837 &pInputMgr->seat->pointer->resource_list,
838 wl_resource_get_client(usurf->surface->resource));
840 wl_pointer_send_motion(cres, ctime, fix_x, fix_y);
845 cres = wl_resource_find_for_client(
846 &pInputMgr->seat->pointer->resource_list,
847 wl_resource_get_client(usurf->surface->resource));
849 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
850 wl_pointer_send_button(cres, serial, ctime, code,
851 value ? WL_POINTER_BUTTON_STATE_PRESSED :
852 WL_POINTER_BUTTON_STATE_RELEASED);
856 cres = wl_resource_find_for_client(
857 &pInputMgr->seat->touch->resource_list,
858 wl_resource_get_client(usurf->surface->resource));
860 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
862 wl_touch_send_down(cres, serial, ctime, usurf->surface->resource, 0,
866 wl_touch_send_up(cres, serial, ctime, 0);
871 cres = wl_resource_find_for_client(
872 &pInputMgr->seat->keyboard->resource_list,
873 wl_resource_get_client(usurf->surface->resource));
875 keyboard_active = ico_window_mgr_ismykeyboard(usurf);
876 if (! keyboard_active) {
877 wl_array_init(&dummy_array);
878 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
879 wl_keyboard_send_enter(cres, serial,
880 usurf->surface->resource, &dummy_array);
882 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
883 uifw_trace("ico_mgr_send_input_event: send Key (%d, %d) to %08x",
884 code, value, usurf->surfaceid);
885 wl_keyboard_send_key(cres, serial, ctime, code,
886 value ? WL_KEYBOARD_KEY_STATE_PRESSED :
887 WL_KEYBOARD_KEY_STATE_RELEASED);
888 if (! keyboard_active) {
889 serial = wl_display_next_serial(pInputMgr->compositor->wl_display);
890 wl_keyboard_send_leave(cres, serial, usurf->surface->resource);
894 uifw_trace("ico_mgr_send_input_event: Key client %08x dose not exist",
895 (int)usurf->surface->resource);
902 #if 0 /* too many log */
903 uifw_debug("ico_mgr_send_input_event: Leave");
907 /*--------------------------------------------------------------------------*/
909 * @brief ico_mgr_set_input_region: set input region for haptic devcie
911 * @param[in] client client(Device Input Controller)
912 * @param[in] resource resource of request
913 * @param[in] target target window (winname@appid)
914 * @param[in] x input region X coordinate
915 * @param[in] y input region X coordinate
916 * @param[in] width input region width
917 * @param[in] height input region height
918 * @param[in] hotspot_x hotspot of X relative coordinate
919 * @param[in] hotspot_y hotspot of Y relative coordinate
920 * @param[in] cursor_x cursor region X coordinate
921 * @param[in] cursor_y cursor region X coordinate
922 * @param[in] cursor_width cursor region width
923 * @param[in] cursor_height cursor region height
924 * @param[in] attr region attributes(currently unused)
927 /*--------------------------------------------------------------------------*/
929 ico_mgr_set_input_region(struct wl_client *client, struct wl_resource *resource,
930 const char *target, int32_t x, int32_t y,
931 int32_t width, int32_t height, int32_t hotspot_x,
932 int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
933 int32_t cursor_width, int32_t cursor_height, uint32_t attr)
935 struct uifw_client *uclient;
936 struct uifw_win_surface *usurf; /* UIFW surface */
938 uifw_trace("ico_mgr_set_input_region: Enter(%s %d/%d-%d/%d(%d/%d) %d/%d-%d/%d)",
939 target, x, y, width, height, hotspot_x, hotspot_y,
940 cursor_x, cursor_y, cursor_width, cursor_height);
942 /* check for access control */
943 if (resource != NULL) {
944 /* resource is NULL, internal use */
945 uclient = ico_window_mgr_find_uclient(client);
947 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
948 "ico_exapi_input_set_input_region: unknown client");
949 uifw_trace("ico_mgr_set_input_region: Leave(unknown client=%08x)", (int)client);
952 if ((uclient->api_access_control & ICO_UIFW_EXINPUT_SET_INPUT_REGION) == 0) {
953 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
954 "ico_exapi_input_set_input_region: not permitted");
955 uifw_trace("ico_mgr_set_input_region: Leave(%s not permitted)", uclient->appid);
959 /* get target surface */
960 usurf = ico_window_mgr_get_client_usurf(target);
962 uifw_warn("ico_mgr_set_input_region: Leave(target<%s> dose not exist)", target);
966 ico_set_input_region(1, usurf, x, y, width, height, hotspot_x, hotspot_y,
967 cursor_x, cursor_y, cursor_width, cursor_height, attr);
969 uifw_trace("ico_mgr_set_input_region: Leave");
972 /*--------------------------------------------------------------------------*/
974 * @brief ico_mgr_unset_input_region: unset input region for haptic devcie
976 * @param[in] client client(Device Input Controller)
977 * @param[in] resource resource of request
978 * @param[in] target target window (winname@appid)
979 * @param[in] x input region X coordinate
980 * @param[in] y input region X coordinate
981 * @param[in] width input region width
982 * @param[in] height input region height
985 /*--------------------------------------------------------------------------*/
987 ico_mgr_unset_input_region(struct wl_client *client, struct wl_resource *resource,
988 const char *target, int32_t x, int32_t y,
989 int32_t width, int32_t height)
991 struct uifw_client *uclient;
992 struct uifw_win_surface *usurf; /* UIFW surface */
994 uifw_trace("ico_mgr_unset_input_region: Enter(%s %d/%d-%d/%d)",
995 target, x, y, width, height);
997 /* check for access control */
998 if (resource != NULL) {
999 /* resource is NULL, internal use */
1000 uclient = ico_window_mgr_find_uclient(client);
1002 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1003 "ico_exapi_input_unset_input_region: unknown client");
1004 uifw_trace("ico_mgr_unset_input_region: Leave(unknown client=%08x)", (int)client);
1007 if ((uclient->api_access_control & ICO_UIFW_EXINPUT_UNSET_INPUT_REGION) == 0) {
1008 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1009 "ico_exapi_input_unset_input_region: not permitted");
1010 uifw_trace("ico_mgr_unset_input_region: Leave(%s not permitted)", uclient->appid);
1014 /* get target surface */
1015 usurf = ico_window_mgr_get_client_usurf(target);
1017 uifw_warn("ico_mgr_unset_input_region: Leave(target<%s> dose not exist)", target);
1021 ico_set_input_region(0, usurf, x, y, width, height, 0, 0, 0, 0, 0, 0, 0);
1023 uifw_trace("ico_mgr_unset_input_region: Leave");
1026 /*--------------------------------------------------------------------------*/
1028 * @brief ico_input_hook_region_change: change surface attribute
1030 * @param[in] usurf UIFW surface
1033 /*--------------------------------------------------------------------------*/
1035 ico_input_hook_region_change(struct uifw_win_surface *usurf)
1037 struct uifw_region_mng *p; /* input region mamagement table*/
1038 struct ico_uifw_input_region *rp; /* input region */
1039 struct wl_array array;
1043 visible = ico_window_mgr_is_visible(usurf);
1045 uifw_trace("ico_input_hook_region_change: Entery(surf=%08x, visible=%d)",
1046 usurf->surfaceid, visible);
1048 wl_array_init(&array);
1050 wl_list_for_each(p, &usurf->input_region, link) {
1051 if (((p->region.change > 0) && (visible <= 0)) ||
1052 ((p->region.change <= 0) && (visible > 0))) {
1053 /* visible change, send add/remove event */
1054 rp = (struct ico_uifw_input_region *)
1055 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1058 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1060 rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
1063 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1066 p->region.change = visible;
1067 p->region.node = usurf->node_tbl->node;
1068 p->region.surface_x = usurf->x;
1069 p->region.surface_y = usurf->y;
1071 else if ((p->region.node != usurf->node_tbl->node) ||
1072 (p->region.surface_x != usurf->x) ||
1073 (p->region.surface_y != usurf->y)) {
1074 /* surface position change, send change event */
1075 p->region.node = usurf->node_tbl->node;
1076 p->region.surface_x = usurf->x;
1077 p->region.surface_y = usurf->y;
1079 rp = (struct ico_uifw_input_region *)
1080 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1083 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1084 rp->change = ICO_INPUT_MGR_DEVICE_REGION_CHANGE;
1089 /* send region delete to haptic device input controller */
1090 ico_input_send_region_event(&array);
1092 uifw_trace("ico_input_hook_region_change: Leave");
1095 /*--------------------------------------------------------------------------*/
1097 * @brief ico_input_hook_region_destroy: destory surface
1099 * @param[in] usurf UIFW surface
1102 /*--------------------------------------------------------------------------*/
1104 ico_input_hook_region_destroy(struct uifw_win_surface *usurf)
1106 struct uifw_region_mng *p; /* input region mamagement table*/
1107 struct uifw_region_mng *np; /* next region mamagement table */
1108 struct ico_uifw_input_region *rp; /* input region */
1109 struct wl_array array;
1112 uifw_trace("ico_input_hook_region_destroy: Entery(surf=%08x)", usurf->surfaceid);
1114 wl_array_init(&array);
1116 wl_list_for_each_safe(p, np, &usurf->input_region, link) {
1117 if (p->region.change > 0) {
1118 /* visible, send remove event */
1119 rp = (struct ico_uifw_input_region *)
1120 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1123 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1124 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1127 wl_list_remove(&p->link);
1128 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1131 /* send region delete to haptic device input controller */
1132 ico_input_send_region_event(&array);
1134 uifw_trace("ico_input_hook_region_destroy: Leave");
1137 /*--------------------------------------------------------------------------*/
1139 * @brief ico_set_input_region: input region set/unset
1141 * @param[in] set set(1)/unset(0)
1142 * @param[in] usurf UIFW surface
1143 * @param[in] x input region X coordinate
1144 * @param[in] y input region X coordinate
1145 * @param[in] width input region width
1146 * @param[in] height input region height
1147 * @param[in] hotspot_x hotspot of X relative coordinate
1148 * @param[in] hotspot_y hotspot of Y relative coordinate
1149 * @param[in] cursor_x cursor region X coordinate
1150 * @param[in] cursor_y cursor region X coordinate
1151 * @param[in] cursor_width cursor region width
1152 * @param[in] cursor_height cursor region height
1153 * @param[in] attr region attributes(currently unused)
1156 /*--------------------------------------------------------------------------*/
1158 ico_set_input_region(int set, struct uifw_win_surface *usurf,
1159 int32_t x, int32_t y, int32_t width, int32_t height,
1160 int32_t hotspot_x, int32_t hotspot_y, int32_t cursor_x, int32_t cursor_y,
1161 int32_t cursor_width, int32_t cursor_height, uint32_t attr)
1163 struct uifw_region_mng *p; /* input region mamagement table*/
1164 struct uifw_region_mng *np; /* next region mamagement table */
1165 struct ico_uifw_input_region *rp; /* input region */
1166 struct wl_array array;
1171 uifw_trace("ico_set_input_region: Enter(%s %d/%d-%d/%d(%d/%d) %d/%d-%d/%d)",
1172 set ? "Set" : "Unset", x, y, width, height, hotspot_x, hotspot_y,
1173 cursor_x, cursor_y, cursor_width, cursor_height);
1176 if (wl_list_empty(&pInputMgr->free_region)) {
1177 p = malloc(sizeof(struct uifw_region_mng) * 50);
1179 uifw_error("ico_set_input_region: No Memory");
1182 memset(p, 0, sizeof(struct uifw_region_mng)*50);
1183 for (i = 0; i < 50; i++, p++) {
1184 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1187 p = container_of(pInputMgr->free_region.next, struct uifw_region_mng, link);
1188 wl_list_remove(&p->link);
1189 p->region.node = usurf->node_tbl->node;
1190 p->region.surfaceid = usurf->surfaceid;
1191 p->region.surface_x = usurf->x;
1192 p->region.surface_y = usurf->y;
1195 p->region.width = width;
1196 p->region.height = height;
1197 if ((hotspot_x <= 0) && (hotspot_y <= 0)) {
1198 p->region.hotspot_x = width / 2;
1199 p->region.hotspot_y = height / 2;
1202 p->region.hotspot_x = hotspot_x;
1203 p->region.hotspot_y = hotspot_y;
1205 if ((cursor_width <= 0) && (cursor_height <= 0)) {
1206 p->region.cursor_x = x;
1207 p->region.cursor_y = y;
1208 p->region.cursor_width = width;
1209 p->region.cursor_height = height;
1212 p->region.cursor_x = cursor_x;
1213 p->region.cursor_y = cursor_y;
1214 p->region.cursor_width = cursor_width;
1215 p->region.cursor_height = cursor_height;
1217 p->region.change = ico_window_mgr_is_visible(usurf);
1218 wl_list_insert(usurf->input_region.prev, &p->link);
1220 /* send input region to haptic device input controller */
1221 if (p->region.change > 0) {
1222 wl_array_init(&array);
1223 rp = (struct ico_uifw_input_region *)
1224 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1226 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1227 rp->change = ICO_INPUT_MGR_DEVICE_REGION_ADD;
1228 ico_input_send_region_event(&array);
1230 uifw_trace("ico_set_input_region: Leave(Set)");
1233 uifw_trace("ico_set_input_region: Leave(Set but Unvisible)");
1239 if ((x <= 0) && (y <= 0) && (width <= 0) && (height <= 0)) {
1246 wl_array_init(&array);
1248 wl_list_for_each_safe(p, np, &usurf->input_region, link) {
1249 if ((alldel != 0) ||
1250 ((x == p->region.x) && (y == p->region.y) &&
1251 (width == p->region.width) && (height == p->region.height))) {
1252 if (p->region.change > 0) {
1253 /* visible, send remove event */
1254 rp = (struct ico_uifw_input_region *)
1255 wl_array_add(&array, sizeof(struct ico_uifw_input_region));
1258 memcpy(rp, &p->region, sizeof(struct ico_uifw_input_region));
1259 rp->change = ICO_INPUT_MGR_DEVICE_REGION_REMOVE;
1262 wl_list_remove(&p->link);
1263 wl_list_insert(pInputMgr->free_region.prev, &p->link);
1267 /* send region delete to haptic device input controller */
1268 ico_input_send_region_event(&array);
1270 uifw_trace("ico_set_input_region: Leave(Unset)");
1274 /*--------------------------------------------------------------------------*/
1276 * @brief ico_input_send_region_event: send region event to Haptic dic
1278 * @param[in] usurf UIFW surface
1281 /*--------------------------------------------------------------------------*/
1283 ico_input_send_region_event(struct wl_array *array)
1285 struct ico_ictl_mgr *pIctlMgr;
1287 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1288 if ((pIctlMgr->type == ICO_INPUT_MGR_DEVICE_TYPE_HAPTIC) &&
1289 (pIctlMgr->mgr_resource != NULL)) {
1290 uifw_trace("ico_input_send_region_event: send event to Hapfic");
1291 ico_input_mgr_device_send_input_regions(pIctlMgr->mgr_resource, array);
1296 /*--------------------------------------------------------------------------*/
1298 * @brief ico_device_configure_input: configure input device and input switch
1299 * from Device Input Controller.
1301 * @param[in] client client(Device Input Controller)
1302 * @param[in] resource resource of request
1303 * @param[in] device device name
1304 * @param[in] type device type(saved but unused)
1305 * @param[in] swname input switch name
1306 * @param[in] input input switch number
1307 * @param[in] codename input code name
1308 * @param[in] code input code number
1311 /*--------------------------------------------------------------------------*/
1313 ico_device_configure_input(struct wl_client *client, struct wl_resource *resource,
1314 const char *device, int32_t type, const char *swname,
1315 int32_t input, const char *codename, int32_t code)
1317 struct uifw_client *uclient;
1318 struct ico_ictl_mgr *pIctlMgr;
1319 struct ico_ictl_mgr *psameIctlMgr;
1320 struct ico_ictl_input *pInput;
1321 struct ico_app_mgr *pAppMgr;
1323 uifw_trace("ico_device_configure_input: Enter(client=%08x,dev=%s,type=%d,swname=%s,"
1324 "input=%d,code=%d[%s])", (int)client, device, type,
1325 swname ? swname : "(NULL)", input, code, codename ? codename : " ");
1327 /* check for access control */
1328 if (resource != NULL) {
1329 /* resource is NULL, internal use */
1330 uclient = ico_window_mgr_find_uclient(client);
1332 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1333 "ico_input_mgr_device_configure_input: unknown client");
1334 uifw_trace("ico_device_configure_input: Leave(unknown client=%08x)", (int)client);
1337 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_DEVICE_CONFIGURE_INPUT) == 0) {
1338 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1339 "ico_input_mgr_device_configure_input: not permitted");
1340 uifw_trace("ico_device_configure_input: Leave(%s not permitted)", uclient->appid);
1344 pIctlMgr = find_ictlmgr_by_device(device);
1346 /* search binded table */
1347 psameIctlMgr = NULL;
1348 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1349 if (pIctlMgr->client == client) {
1350 uifw_trace("ico_device_configure_input: set pIctlMgr"
1351 "(mgr=%08x,input=%d,dev=%s)", (int)pIctlMgr,
1352 input, pIctlMgr->device);
1353 if (pIctlMgr->device[0] != 0) {
1354 /* save same device */
1355 psameIctlMgr = pIctlMgr;
1359 strncpy(pIctlMgr->device, device, sizeof(pIctlMgr->device)-1);
1360 psameIctlMgr = NULL;
1366 /* client(device input controller) exist, but other device */
1367 pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
1368 if (pIctlMgr == NULL) {
1369 uifw_error("ico_device_bind: Leave(No Memory)");
1372 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1373 wl_list_init(&pIctlMgr->ico_ictl_input);
1374 pIctlMgr->client = psameIctlMgr->client;
1375 pIctlMgr->mgr_resource = psameIctlMgr->mgr_resource;
1377 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1382 pIctlMgr->type = type;
1385 /* search and add input switch */
1386 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1387 if (pInput->input == input) break;
1389 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
1390 uifw_trace("ico_device_configure_input: create %s.%s(%d) switch",
1391 device, swname, input);
1392 pInput = (struct ico_ictl_input *)malloc(sizeof(struct ico_ictl_input));
1393 if (pInput == NULL) {
1394 uifw_error("ico_device_configure_input: Leave(No Memory)");
1397 memset(pInput, 0, sizeof(struct ico_ictl_input));
1399 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1402 strcpy(pInput->swname, "(Unknown)");
1404 wl_list_insert(pIctlMgr->ico_ictl_input.prev, &pInput->link);
1407 strncpy(pInput->swname, swname, sizeof(pInput->swname)-1);
1409 pInput->input = input;
1410 memset(pInput->code, 0, sizeof(pInput->code));
1412 pInput->code[0].code = code;
1414 strncpy(pInput->code[0].name, codename, sizeof(pInput->code[0].name)-1);
1417 if (client == NULL) {
1418 /* internal call for table create */
1419 uifw_trace("ico_device_configure_input: Leave(table create)");
1422 pIctlMgr->client = client;
1424 /* send to application and manager(ex.HomeScreen) */
1425 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1426 if (pAppMgr->resource == NULL) continue;
1427 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
1429 uifw_trace("ico_device_configure_input: send capabilities to app(%s) %s.%s[%d]",
1430 pAppMgr->appid, device, pInput->swname, input);
1431 ico_exinput_send_capabilities(pAppMgr->resource, device, pIctlMgr->type,
1432 pInput->swname, input,
1433 pInput->code[0].name, pInput->code[0].code);
1435 uifw_trace("ico_device_configure_input: Leave");
1438 /*--------------------------------------------------------------------------*/
1440 * @brief ico_device_configure_code: add input switch from Device Input Controller.
1442 * @param[in] client client(Device Input Controller)
1443 * @param[in] resource resource of request
1444 * @param[in] device device name
1445 * @param[in] input input switch number
1446 * @param[in] codename input code name
1447 * @param[in] code input code number
1450 /*--------------------------------------------------------------------------*/
1452 ico_device_configure_code(struct wl_client *client, struct wl_resource *resource,
1453 const char *device, int32_t input,
1454 const char *codename, int32_t code)
1456 struct uifw_client *uclient;
1458 struct ico_ictl_mgr *pIctlMgr;
1459 struct ico_ictl_input *pInput;
1460 struct ico_app_mgr *pAppMgr;
1462 uifw_trace("ico_device_configure_code: Enter(client=%08x,dev=%s,input=%d,code=%d[%s])",
1463 (int)client, device, input, code, codename ? codename : " ");
1465 /* check for access control */
1466 if (resource != NULL) {
1467 /* resource is NULL, internal use */
1468 uclient = ico_window_mgr_find_uclient(client);
1470 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1471 "ico_input_mgr_device_configure_code: unknown client");
1472 uifw_trace("ico_device_configure_code: Leave(unknown client=%08x)", (int)client);
1475 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_DEVICE_CONFIGURE_CODE) == 0) {
1476 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1477 "ico_input_mgr_device_configure_code: not permitted");
1478 uifw_trace("ico_device_configure_code: Leave(%s not permitted)", uclient->appid);
1482 pIctlMgr = find_ictlmgr_by_device(device);
1484 uifw_warn("ico_device_configure_code: Leave(dev=%s dose not exist)", device);
1487 /* search input switch */
1488 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1489 if (pInput->input == input) break;
1491 if (&pInput->link == &pIctlMgr->ico_ictl_input) {
1492 uifw_warn("ico_device_configure_code: Leave(input=%s.%d dose not exist)",
1497 /* search input code */
1498 for (i = 0; i < pInput->ncode; i++) {
1499 if (pInput->code[i].code == code) break;
1501 if (i >= pInput->ncode) {
1502 /* code dose not exist, add */
1503 if (pInput->ncode >= ICO_MINPUT_MAX_CODES) {
1504 uifw_warn("ico_device_configure_code: Leave(input=%s.%d code overflow)",
1510 pInput->code[i].code = code;
1512 memset(pInput->code[i].name, 0, sizeof(pInput->code[i].name));
1513 strncpy(pInput->code[i].name, codename, sizeof(pInput->code[i].name)-1);
1515 /* send to application and manager(ex.HomeScreen) */
1516 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1517 if (pAppMgr->resource == NULL) continue;
1518 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) continue;
1519 uifw_trace("ico_device_configure_input: send code to app(%s) %s.%s[%d]",
1520 pAppMgr->appid, device, pInput->swname, input);
1521 ico_exinput_send_code(pAppMgr->resource, device, input,
1522 pInput->code[i].name, pInput->code[i].code);
1524 uifw_trace("ico_device_configure_code: Leave");
1527 /*--------------------------------------------------------------------------*/
1529 * @brief ico_device_input_event: device input event from Device Input Controller.
1531 * @param[in] client client(Device Input Controller)
1532 * @param[in] resource resource of request
1533 * @param[in] time device input time(miri-sec)
1534 * @param[in] device device name
1535 * @param[in] input input switch number
1536 * @param[in] code input code number
1537 * @param[in] state input state(1=On, 0=Off)
1540 /*--------------------------------------------------------------------------*/
1542 ico_device_input_event(struct wl_client *client, struct wl_resource *resource,
1543 uint32_t time, const char *device,
1544 int32_t input, int32_t code, int32_t state)
1546 struct uifw_client *uclient;
1547 struct ico_ictl_mgr *pIctlMgr;
1548 struct ico_ictl_input *pInput;
1550 uifw_trace("ico_device_input_event: Enter(time=%d,dev=%s,input=%d,code=%d,state=%d)",
1551 time, device, input, code, state);
1553 /* check for access control */
1554 if (resource != NULL) {
1555 /* resource is NULL, internal use */
1556 uclient = ico_window_mgr_find_uclient(client);
1558 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1559 "ico_input_mgr_device_input_event: unknown client");
1560 uifw_trace("ico_device_input_event: Leave(unknown client=%08x)", (int)client);
1563 if ((uclient->api_access_control & ICO_UIFW_INPUT_MGR_DEVICE_INPUT_EVENT) == 0) {
1564 wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
1565 "ico_input_mgr_device_input_event: not permitted");
1566 uifw_trace("ico_device_input_event: Leave(%s not permitted)", uclient->appid);
1570 /* find input devcie by client */
1571 pIctlMgr = find_ictlmgr_by_device(device);
1573 uifw_error("ico_device_input_event: Leave(Unknown device(%s))", device);
1576 /* find input switch by input Id */
1577 pInput = find_ictlinput_by_input(pIctlMgr, input);
1579 uifw_warn("ico_device_input_event: Leave(Unknown input(%s,%d))",
1580 pIctlMgr->device, input);
1584 if (! pInput->app) {
1585 uifw_trace("ico_device_input_event: Leave(%s.%s not assign)",
1586 pIctlMgr->device, pInput->swname);
1589 if (! pInput->app->resource) {
1590 uifw_trace("ico_device_input_event: Leave(%s.%s assigned App.%s "
1591 "is not running or not interested)",
1592 pIctlMgr->device, pInput->swname, pInput->app->appid);
1596 /* send event to application */
1597 uifw_trace("ico_device_input_event: send event=%s.%s[%d],%d,%d to App.%s",
1598 pIctlMgr->device, pInput->swname, input, code, state, pInput->app->appid);
1599 ico_exinput_send_input(pInput->app->resource, time, pIctlMgr->device,
1600 input, code, state);
1602 uifw_trace("ico_device_input_event: Leave");
1605 /*--------------------------------------------------------------------------*/
1607 * @brief ico_control_bind: ico_input_mgr_control bind from HomeScreen
1609 * @param[in] client client(HomeScreen)
1610 * @param[in] data data(unused)
1611 * @param[in] version protocol version(unused)
1612 * @param[in] id client object id
1615 /*--------------------------------------------------------------------------*/
1617 ico_control_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1620 struct ico_app_mgr *pAppMgr;
1622 uifw_trace("ico_control_bind: Enter(client=%08x)", (int)client);
1623 appid = ico_window_mgr_get_appid(client);
1626 /* client dose not exist */
1627 uifw_warn("ico_control_bind: Leave(client=%08x dose not exist)", (int)client);
1631 /* find application */
1632 pAppMgr = find_app_by_appid(appid);
1634 /* create Application Management Table */
1635 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1637 uifw_error("ico_control_bind: Leave(No Memory)");
1640 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
1641 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
1642 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
1644 pAppMgr->client = client;
1645 if (! pAppMgr->mgr_resource) {
1646 pAppMgr->mgr_resource = wl_resource_create(client,
1647 &ico_input_mgr_control_interface, 1, id);
1648 if (pAppMgr->mgr_resource) {
1649 wl_resource_set_implementation(pAppMgr->mgr_resource,
1650 &ico_input_mgr_implementation,
1651 pInputMgr, ico_control_unbind);
1654 uifw_trace("ico_control_bind: Leave");
1657 /*--------------------------------------------------------------------------*/
1659 * @brief ico_control_unbind: ico_input_mgr_control unbind from HomeScreen
1661 * @param[in] resource client resource(HomeScreen)
1664 /*--------------------------------------------------------------------------*/
1666 ico_control_unbind(struct wl_resource *resource)
1668 struct ico_app_mgr *pAppMgr;
1670 uifw_trace("ico_control_unbind: Enter(resource=%08x)", (int)resource);
1672 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1673 if (pAppMgr->mgr_resource == resource) {
1674 uifw_trace("ico_control_unbind: find app.%s", pAppMgr->appid);
1675 pAppMgr->mgr_resource = NULL;
1679 uifw_trace("ico_control_unbind: Leave");
1682 /*--------------------------------------------------------------------------*/
1684 * @brief ico_device_bind: ico_input_mgr_device bind from Device Input Controller
1686 * @param[in] client client(Device Input Controller)
1687 * @param[in] data data(unused)
1688 * @param[in] version protocol version
1689 * @param[in] id client object id
1692 /*--------------------------------------------------------------------------*/
1694 ico_device_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1696 struct ico_ictl_mgr *pIctlMgr;
1697 struct wl_resource *mgr_resource;
1699 uifw_trace("ico_device_bind: Enter(client=%08x)", (int)client);
1701 /* create ictl mgr table */
1702 pIctlMgr = (struct ico_ictl_mgr *)malloc(sizeof(struct ico_ictl_mgr));
1703 if (pIctlMgr == NULL) {
1704 uifw_error("ico_device_bind: Leave(No Memory)");
1707 memset(pIctlMgr, 0, sizeof(struct ico_ictl_mgr));
1708 wl_list_init(&pIctlMgr->ico_ictl_input);
1709 pIctlMgr->client = client;
1712 wl_list_insert(pInputMgr->ictl_list.prev, &pIctlMgr->link);
1714 mgr_resource = wl_resource_create(client, &ico_input_mgr_device_interface, 1, id);
1716 pIctlMgr->mgr_resource = mgr_resource;
1717 wl_resource_set_implementation(mgr_resource, &input_mgr_ictl_implementation,
1718 pIctlMgr, ico_device_unbind);
1720 uifw_trace("ico_device_bind: Leave");
1723 /*--------------------------------------------------------------------------*/
1725 * @brief ico_device_unbind: ico_input_mgr_device unbind from Device Input Controller
1727 * @param[in] resource client resource(Device Input Controller)
1730 /*--------------------------------------------------------------------------*/
1732 ico_device_unbind(struct wl_resource *resource)
1734 uifw_trace("ico_device_unbind: Enter(resource=%08x)", (int)resource);
1735 uifw_trace("ico_device_unbind: Leave");
1738 /*--------------------------------------------------------------------------*/
1740 * @brief ico_exinput_bind: ico_exinput bind from Application
1742 * @param[in] client client(Application)
1743 * @param[in] data data(unused)
1744 * @param[in] version protocol version(unused)
1745 * @param[in] id client object id
1748 /*--------------------------------------------------------------------------*/
1750 ico_exinput_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
1754 struct ico_app_mgr *pAppMgr;
1755 struct ico_ictl_mgr *pIctlMgr;
1756 struct ico_ictl_input *pInput;
1758 appid = ico_window_mgr_get_appid(client);
1759 uifw_trace("ico_exinput_bind: Enter(client=%08x,%s)", (int)client,
1760 appid ? appid : "(NULL)");
1763 /* client dose not exist */
1764 uifw_warn("ico_exinput_bind: Leave(client=%08x dose not exist)", (int)client);
1768 /* find application */
1769 pAppMgr = find_app_by_appid(appid);
1771 /* create Application Management Table */
1772 pAppMgr = (struct ico_app_mgr *)malloc(sizeof(struct ico_app_mgr));
1774 uifw_error("ico_exinput_bind: Leave(No Memory)");
1777 memset(pAppMgr, 0, sizeof(struct ico_app_mgr));
1778 strncpy(pAppMgr->appid, appid, sizeof(pAppMgr->appid)-1);
1779 wl_list_insert(pInputMgr->app_list.prev, &pAppMgr->link);
1780 uifw_trace("ico_exinput_bind: Create App.%s table", appid);
1782 pAppMgr->client = client;
1783 if (! pAppMgr->resource) {
1784 pAppMgr->resource = wl_resource_create(client, &ico_exinput_interface, 1, id);
1785 if (pAppMgr->resource) {
1786 wl_resource_set_implementation(pAppMgr->resource, &ico_exinput_implementation,
1787 pInputMgr, ico_exinput_unbind);
1791 /* send all capabilities */
1792 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1793 if (pIctlMgr->client == NULL) {
1794 uifw_trace("ico_exinput_bind: Input controller.%s not initialized",
1799 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1800 if (pInput->swname[0] == 0) {
1801 uifw_trace("ico_exinput_bind: Input %s not initialized", pIctlMgr->device);
1804 if ((pInput->app != NULL) && (pInput->app != pAppMgr) && (pInput->fix)) {
1805 uifw_trace("ico_exinput_bind: Input %s.%s fixed assign to App.%s",
1806 pIctlMgr->device, pInput->swname, pInput->app->appid);
1809 uifw_trace("ico_exinput_bind: send capabilities to app(%s) %s.%s[%d]",
1810 pAppMgr->appid, pIctlMgr->device, pInput->swname, pInput->input);
1811 ico_exinput_send_capabilities(pAppMgr->resource, pIctlMgr->device,
1812 pIctlMgr->type, pInput->swname, pInput->input,
1813 pInput->code[0].name, pInput->code[0].code);
1814 for (i = 1; i < pInput->ncode; i++) {
1815 ico_exinput_send_code(pAppMgr->resource, pIctlMgr->device, pInput->input,
1816 pInput->code[i].name, pInput->code[i].code);
1820 uifw_trace("ico_exinput_bind: Leave");
1823 /*--------------------------------------------------------------------------*/
1825 * @brief ico_exinput_unbind: ico_exinput unbind from Application
1827 * @param[in] resource client resource(Application)
1830 /*--------------------------------------------------------------------------*/
1832 ico_exinput_unbind(struct wl_resource *resource)
1834 struct ico_app_mgr *pAppMgr;
1835 struct ico_app_mgr *pAppMgrTmp;
1836 struct ico_ictl_mgr *pIctlMgr;
1837 struct ico_ictl_input *pInput;
1840 uifw_trace("ico_exinput_unbind: Enter(resource=%08x)", (int)resource);
1842 wl_list_for_each_safe (pAppMgr, pAppMgrTmp, &pInputMgr->app_list, link) {
1843 if (pAppMgr->resource == resource) {
1844 uifw_trace("ico_exinput_unbind: find app.%s", pAppMgr->appid);
1846 /* release application from input switch */
1847 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1848 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1849 if (pInput->app == pAppMgr) {
1850 if (pInput->fix == 0) {
1851 uifw_trace("ico_exinput_unbind: app.%s remove %s.%s",
1852 pAppMgr->appid, pIctlMgr->device, pInput->swname);
1856 uifw_trace("ico_exinput_unbind: app.%s fix assign %s.%s",
1857 pAppMgr->appid, pIctlMgr->device, pInput->swname);
1864 wl_list_remove(&pAppMgr->link);
1868 pAppMgr->client = NULL;
1869 pAppMgr->resource = NULL;
1873 uifw_trace("ico_exinput_unbind: Leave");
1876 /*--------------------------------------------------------------------------*/
1878 * @brief find_ictlmgr_by_device: find Input Controller by device name
1880 * @param[in] device device name
1881 * @return Input Controller Manager table address
1882 * @retval !=NULL address
1883 * @retval ==NULL not exist
1885 /*--------------------------------------------------------------------------*/
1886 static struct ico_ictl_mgr *
1887 find_ictlmgr_by_device(const char *device)
1889 struct ico_ictl_mgr *pIctlMgr;
1891 wl_list_for_each (pIctlMgr, &pInputMgr->ictl_list, link) {
1892 uifw_debug("find_ictlmgr_by_device: <%s> vs <%s>", device, pIctlMgr->device);
1893 if (strcmp(pIctlMgr->device, device) == 0) {
1900 /*--------------------------------------------------------------------------*/
1902 * @brief find_ictlinput_by_input: find Input Switch by input Id
1904 * @param[in] pIctlMgr Input Controller device
1905 * @param[in] input Input Id
1906 * @return Input Switch table address
1907 * @retval !=NULL address
1908 * @retval ==NULL not exist
1910 /*--------------------------------------------------------------------------*/
1911 static struct ico_ictl_input *
1912 find_ictlinput_by_input(struct ico_ictl_mgr *pIctlMgr, const int32_t input)
1914 struct ico_ictl_input *pInput;
1916 wl_list_for_each (pInput, &pIctlMgr->ico_ictl_input, link) {
1917 if (pInput->input == input) {
1924 /*--------------------------------------------------------------------------*/
1926 * @brief find_app_by_appid: find Application by application Id
1928 * @param[in] appid application Id
1929 * @return Application Management table address
1930 * @retval !=NULL address
1931 * @retval ==NULL not exist
1933 /*--------------------------------------------------------------------------*/
1934 static struct ico_app_mgr *
1935 find_app_by_appid(const char *appid)
1937 struct ico_app_mgr *pAppMgr;
1939 wl_list_for_each (pAppMgr, &pInputMgr->app_list, link) {
1940 if (strcmp(pAppMgr->appid, appid) == 0) {
1947 /*--------------------------------------------------------------------------*/
1949 * @brief module_init: initialization of this plugin
1951 * @param[in] ec weston compositor
1952 * @param[in] argc number of arguments(unused)
1953 * @param[in] argv argument list(unused)
1958 /*--------------------------------------------------------------------------*/
1960 module_init(struct weston_compositor *ec, int *argc, char *argv[])
1962 struct uifw_region_mng *p;
1965 uifw_info("ico_input_mgr: Enter(module_init)");
1967 /* initialize management table */
1968 pInputMgr = (struct ico_input_mgr *)malloc(sizeof(struct ico_input_mgr));
1969 if (pInputMgr == NULL) {
1970 uifw_trace("ico_input_mgr: malloc failed");
1973 memset(pInputMgr, 0, sizeof(struct ico_input_mgr));
1974 pInputMgr->compositor = ec;
1976 /* interface to desktop manager(ex.HomeScreen) */
1977 if (wl_global_create(ec->wl_display, &ico_input_mgr_control_interface, 1,
1978 pInputMgr, ico_control_bind) == NULL) {
1979 uifw_trace("ico_input_mgr: wl_global_create mgr failed");
1983 /* interface to Input Controller(ictl) */
1984 if (wl_global_create(ec->wl_display, &ico_input_mgr_device_interface, 1,
1985 pInputMgr, ico_device_bind) == NULL) {
1986 uifw_trace("ico_input_mgr: wl_global_create ictl failed");
1990 /* interface to App(exinput) */
1991 if (wl_global_create(ec->wl_display, &ico_exinput_interface, 1,
1992 pInputMgr, ico_exinput_bind) == NULL) {
1993 uifw_trace("ico_input_mgr: wl_global_create exseat failed");
1997 /* initialize list */
1998 wl_list_init(&pInputMgr->ictl_list);
1999 wl_list_init(&pInputMgr->app_list);
2000 wl_list_init(&pInputMgr->dev_list);
2001 wl_list_init(&pInputMgr->free_region);
2002 p = malloc(sizeof(struct uifw_region_mng)*100);
2004 memset(p, 0, sizeof(struct uifw_region_mng)*100);
2005 for (i = 0; i < 100; i++, p++) {
2006 wl_list_insert(pInputMgr->free_region.prev, &p->link);
2010 /* found input seat */
2011 pInputMgr->seat = container_of(ec->seat_list.next, struct weston_seat, link);
2013 /* set hook for input region control */
2014 ico_window_mgr_set_hook_change(ico_input_hook_region_change);
2015 ico_window_mgr_set_hook_destory(ico_input_hook_region_destroy);
2016 ico_window_mgr_set_hook_inputregion(ico_set_input_region);
2018 uifw_info("ico_input_mgr: Leave(module_init)");