2 #include <time.h> // gettimeofday()
3 #include <libds/backend.h>
5 #include <libds-tizen/input_devicemgr.h>
6 #include <libds/interfaces/backend.h>
7 #include <libds/interfaces/keyboard.h>
8 #include <libds/interfaces/pointer.h>
9 #include <libds/interfaces/touch.h>
13 #include "input_devicemgr.h"
15 #define TIZEN_INPUT_DEVICEMGR_VERSION 4
16 #define TIZEN_PRIV_INPUT_GENERATOR "http://tizen.org/privilege/inputgenerator"
17 #define TIZEN_PRIV_INPUT_BLOCK "http://tizen.org/privilege/internal/inputdevice.block"
18 #define TIZEN_INPUT_DEVICEMGR_MAX_BTN 16
20 static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface;
24 backend_handle_destroy(struct wl_listener *listener, void *data);
26 backend_handle_input_device_add(struct wl_listener *listener, void *data);
28 seat_handle_destroy(struct wl_listener *listener, void *data);
30 //tizen_input_device_manager bind/unbind
32 device_manager_handle_bind(struct wl_client *client, void *data,
33 uint32_t version, uint32_t id);
35 device_manager_client_handle_resource_destroy(struct wl_resource *resource);
37 //tizen_input_device_manager's handlers for requests
39 device_manager_handle_block_events(struct wl_client *client,
40 struct wl_resource *resource, uint32_t serial,
41 uint32_t clas, uint32_t duration);
43 device_manager_handle_unblock_events(struct wl_client *client,
44 struct wl_resource *resource, uint32_t serial);
46 device_manager_handle_init_generator(struct wl_client *client,
47 struct wl_resource *resource, uint32_t clas);
49 device_manager_handle_init_generator_with_name(struct wl_client *client,
50 struct wl_resource *resource, uint32_t clas, const char *name);
52 device_manager_handle_deinit_generator(struct wl_client *client,
53 struct wl_resource *resource, uint32_t clas);
55 device_manager_handle_generate_key(struct wl_client *client,
56 struct wl_resource *resource,
57 const char *keyname, uint32_t pressed);
59 device_manager_handle_generate_touch(struct wl_client *client,
60 struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y,
63 device_manager_handle_generate_pointer(struct wl_client *client,
64 struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y,
67 device_manager_handle_pointer_warp(struct wl_client *client,
68 struct wl_resource *resource, struct wl_resource *surface,
69 wl_fixed_t x, wl_fixed_t y);
71 device_manager_handle_destroy(struct wl_client *client,
72 struct wl_resource *resource);
75 static void tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr);
77 tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr,
78 struct wl_resource *resource, uint32_t clas, const char *name);
80 tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr,
81 struct wl_resource *resource);
83 tz_devicemgr_generate_key(struct ds_input_device *device, int keycode,
86 tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr,
87 int keycode, bool pressed);
89 tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr);
91 tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr);
93 tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name);
96 tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y,
99 tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y,
102 tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger);
104 tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y);
106 tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state);
109 tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr,
110 struct wl_client *client, const char *rule);
113 tz_devicemgr_grab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr);
115 tz_devicemgr_ungrab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr);
117 tz_devicemgr_ungrab_keyboard_check(struct ds_tizen_input_devicemgr *tz_devicemgr);
119 tz_devicemgr_blocked_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr);
121 WL_EXPORT struct ds_tizen_input_devicemgr *
122 ds_tizen_input_devicemgr_create(struct ds_backend *backend,
123 struct ds_seat *seat)
125 struct ds_tizen_input_devicemgr *tz_devicemgr;
127 tz_devicemgr = calloc(1, sizeof *tz_devicemgr);
129 ds_err("Fail to allocate ds_tizen_input_devicemgr");
133 tz_devicemgr->backend = backend;
134 tz_devicemgr->backend_destroy.notify = backend_handle_destroy;
135 ds_backend_add_destroy_listener(backend, &tz_devicemgr->backend_destroy);
137 tz_devicemgr->seat = seat;
138 tz_devicemgr->seat_destroy.notify = seat_handle_destroy;
139 ds_seat_add_destroy_listener(seat, &tz_devicemgr->seat_destroy);
141 tz_devicemgr->new_input.notify = backend_handle_input_device_add;
142 ds_backend_add_new_input_listener(backend, &tz_devicemgr->new_input);
144 tz_devicemgr->global = wl_global_create(backend->display,
145 &tizen_input_device_manager_interface,
146 TIZEN_INPUT_DEVICEMGR_VERSION,
147 tz_devicemgr, device_manager_handle_bind);
148 if (!tz_devicemgr->global) {
152 tz_devicemgr->devices.kbd = calloc(1,
153 sizeof(struct ds_tizen_input_devicemgr_device));
154 if (!tz_devicemgr->devices.kbd) {
157 tz_devicemgr->devices.ptr = calloc(1,
158 sizeof(struct ds_tizen_input_devicemgr_device));
159 if (!tz_devicemgr->devices.ptr) {
162 tz_devicemgr->devices.touch = calloc(1,
163 sizeof(struct ds_tizen_input_devicemgr_device));
164 if (!tz_devicemgr->devices.touch) {
167 tz_devicemgr->touch_max_count = 5;//TODO: make this variable configurable
169 tz_devicemgr->grab = ds_seat_create_keyboard_grab(
170 tz_devicemgr->seat, &devicemgr_keyboard_grab_iface, tz_devicemgr);
171 if (!tz_devicemgr->grab) {
175 wl_signal_init(&tz_devicemgr->events.destroy);
176 wl_signal_init(&tz_devicemgr->events.pointer_warp);
177 wl_list_init(&tz_devicemgr->clients);
178 wl_list_init(&tz_devicemgr->devices.kbd->key.pressed);
179 wl_list_init(&tz_devicemgr->keymap_list);
180 wl_list_init(&tz_devicemgr->blocked_keys);
182 if (!tizen_security_init()) {
183 ds_inf("tizen_security_init() is failed. go on without security");
186 ds_inf("Global created: ds_tizen_input_devicemgr(%p) ", tz_devicemgr);
190 free(tz_devicemgr->devices.touch);
192 free(tz_devicemgr->devices.ptr);
194 free(tz_devicemgr->devices.kbd);
196 wl_global_destroy(tz_devicemgr->global);
198 wl_list_remove(&tz_devicemgr->backend_destroy.link);
199 wl_list_remove(&tz_devicemgr->seat_destroy.link);
200 wl_list_remove(&tz_devicemgr->new_input.link);
206 ds_tizen_input_devicemgr_add_destroy_listener(
207 struct ds_tizen_input_devicemgr *tz_devicemgr,
208 struct wl_listener *listener)
210 wl_signal_add(&tz_devicemgr->events.destroy, listener);
214 ds_tizen_input_devicemgr_add_pointer_warp_listener(
215 struct ds_tizen_input_devicemgr *tz_devicemgr,
216 struct wl_listener *listener)
218 wl_signal_add(&tz_devicemgr->events.pointer_warp, listener);
222 ds_tizen_input_devicemgr_set_keymap_list(
223 struct ds_tizen_input_devicemgr *tz_devicemgr, struct wl_list *list)
225 struct ds_tizen_input_devicemgr_keymap_data *data, *new_data;
227 if (!tz_devicemgr || !list) {
228 ds_err("Please insert correct data\n");
232 wl_list_for_each(data, list, link) {
233 new_data = calloc(1, sizeof *data);
235 ds_err("Failed to alloc memory");
238 new_data->name = strdup(data->name);
239 new_data->keycode = data->keycode;
240 wl_list_insert(&tz_devicemgr->keymap_list, &new_data->link);
242 ds_inf("keymap set. length:%d",
243 wl_list_length(&tz_devicemgr->keymap_list));
249 ds_tizen_input_devicemgr_set_output_width_height(
250 struct ds_tizen_input_devicemgr *tz_devicemgr,
251 uint32_t width, uint32_t height)
253 if (!tz_devicemgr) return false;
255 tz_devicemgr->output.width = width;
256 tz_devicemgr->output.height = height;
258 ds_inf("output's width: %d, height:%d", width, height);
264 tz_devicemgr_destroy(struct ds_tizen_input_devicemgr *tz_devicemgr)
266 struct ds_tizen_input_devicemgr_client *client_data, *tmp;
268 tizen_security_finish();
270 tz_devicemgr_keymap_list_cleanup(tz_devicemgr);
271 tz_devicemgr_blocked_keys_cleanup(tz_devicemgr);
272 tz_devicemgr_ungrab_keyboard(tz_devicemgr);
273 ds_seat_keyboard_grab_destroy(tz_devicemgr->grab);
275 wl_signal_emit_mutable(&tz_devicemgr->events.destroy, tz_devicemgr);
276 wl_list_remove(&tz_devicemgr->backend_destroy.link);
277 wl_list_remove(&tz_devicemgr->seat_destroy.link);
278 wl_list_remove(&tz_devicemgr->new_input.link);
280 wl_global_destroy(tz_devicemgr->global);
282 wl_list_for_each_safe(client_data, tmp, &tz_devicemgr->clients, link) {
283 wl_list_remove(&client_data->link);
284 tz_devicemgr_deinit_generator(tz_devicemgr, client_data->resource);
286 wl_resource_set_user_data(client_data->resource, NULL);
290 free(tz_devicemgr->devices.touch);
291 free(tz_devicemgr->devices.ptr);
292 free(tz_devicemgr->devices.kbd);
297 backend_handle_destroy(struct wl_listener *listener, void *data)
299 struct ds_tizen_input_devicemgr *tz_devicemgr;
301 tz_devicemgr = wl_container_of(listener, tz_devicemgr, backend_destroy);
303 ds_inf("Global destroy: ds_tizen_input_devicemgr(%p)", tz_devicemgr);
305 tz_devicemgr_destroy(tz_devicemgr);
309 seat_handle_destroy(struct wl_listener *listener, void *data)
311 struct ds_tizen_input_devicemgr *tz_devicemgr;
313 tz_devicemgr = wl_container_of(listener, tz_devicemgr, seat_destroy);
315 wl_list_remove(&tz_devicemgr->seat_destroy.link);
316 wl_list_init(&tz_devicemgr->seat_destroy.link);
317 tz_devicemgr->seat = NULL;
321 tz_devicemgr_device_close(struct ds_tizen_input_devicemgr_device *dev)
323 if (!dev->input_device) return;
324 ds_input_device_destroy(dev->input_device);
325 dev->input_device = NULL;
329 backend_handle_input_device_add(struct wl_listener *listener, void *data)
331 struct ds_input_device *dev = data;
332 struct ds_tizen_input_devicemgr *tz_devicemgr;
333 enum ds_input_device_type dev_type;
335 tz_devicemgr = wl_container_of(listener, tz_devicemgr, new_input);
337 dev_type = ds_input_device_get_type(dev);
338 if (dev_type == DS_INPUT_DEVICE_KEYBOARD) {
339 if (tz_devicemgr->devices.kbd->input_device) return;
340 ds_inf("devicemgr's kbd device is set to dev(%p)", dev);
341 tz_devicemgr->devices.kbd->input_device = dev;
343 else if (dev_type == DS_INPUT_DEVICE_POINTER) {
344 if (tz_devicemgr->devices.ptr->input_device) return;
345 ds_inf("devicemgr's ptr device is set to dev(%p)", dev);
346 tz_devicemgr->devices.ptr->input_device = dev;
348 else if (dev_type == DS_INPUT_DEVICE_TOUCH) {
349 if (tz_devicemgr->devices.touch->input_device) return;
350 ds_inf("devicemgr's touch device is set to dev(%p)", dev);
351 tz_devicemgr->devices.touch->input_device = dev;
355 static const struct tizen_input_device_manager_interface _devicemgr_impl = {
356 .block_events = device_manager_handle_block_events,
357 .unblock_events = device_manager_handle_unblock_events,
358 .init_generator = device_manager_handle_init_generator,
359 .deinit_generator = device_manager_handle_deinit_generator,
360 .generate_key = device_manager_handle_generate_key,
361 .generate_pointer = device_manager_handle_generate_pointer,
362 .generate_touch = device_manager_handle_generate_touch,
363 .pointer_warp = device_manager_handle_pointer_warp,
364 .init_generator_with_name =
365 device_manager_handle_init_generator_with_name, // v2
366 .destroy = device_manager_handle_destroy, // v3
367 .generate_axis = NULL, // v3
368 .set_touch_count = NULL, // v4
372 device_manager_client_handle_resource_destroy(struct wl_resource *resource)
374 struct ds_tizen_input_devicemgr *tz_devicemgr;
375 struct ds_tizen_input_devicemgr_client *client_data, *tmp;
377 tz_devicemgr = wl_resource_get_user_data(resource);
379 tz_devicemgr_deinit_generator(tz_devicemgr, resource);
381 if (resource == tz_devicemgr->block_resource) {
382 tz_devicemgr_ungrab_keyboard_check(tz_devicemgr);
383 if (tz_devicemgr->timer) {
384 wl_event_source_remove(tz_devicemgr->timer);
385 tz_devicemgr->timer = NULL;
389 wl_list_for_each_safe(client_data, tmp, &tz_devicemgr->clients, link) {
390 if (client_data->resource == resource) {
391 wl_list_remove(&client_data->link);
398 device_manager_handle_bind(struct wl_client *client, void *data,
399 uint32_t version, uint32_t id)
401 struct ds_tizen_input_devicemgr *tz_devicemgr = data;
402 struct ds_tizen_input_devicemgr_client *client_data;
404 client_data = calloc(1, sizeof *client_data);
406 ds_err("Failed to allocate memory !\n");
407 wl_client_post_no_memory(client);
411 client_data->resource = wl_resource_create(client,
412 &tizen_input_device_manager_interface, MIN(version,4), id);
413 if (!client_data->resource) {
414 ds_err("Failed to create resource! (ver. :%d, id:%d)", version, id);
416 wl_client_post_no_memory(client);
420 client_data->init = false;
421 wl_list_init(&client_data->link);
422 wl_list_insert(&tz_devicemgr->clients, &client_data->link);
424 wl_resource_set_implementation(client_data->resource, &_devicemgr_impl,
425 tz_devicemgr, device_manager_client_handle_resource_destroy);
429 device_manager_handle_init_generator(struct wl_client *client,
430 struct wl_resource *resource, uint32_t clas)
432 struct ds_tizen_input_devicemgr *tz_devicemgr;
433 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
435 tz_devicemgr = wl_resource_get_user_data(resource);
437 if (!tz_devicemgr_check_privilege(tz_devicemgr, client,
438 TIZEN_PRIV_INPUT_GENERATOR)) {
439 ds_err("No permission to input generate");
440 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION;
444 ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas,
446 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) {
447 ds_err("Failed to init input generator\n");
452 tizen_input_device_manager_send_error(resource, ret);
456 device_manager_handle_init_generator_with_name(struct wl_client *client,
457 struct wl_resource *resource, uint32_t clas, const char *name)
459 struct ds_tizen_input_devicemgr *tz_devicemgr;
460 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
462 tz_devicemgr = wl_resource_get_user_data(resource);
465 ds_err("no name for device");
466 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
470 if (!tz_devicemgr_check_privilege(tz_devicemgr, client,
471 TIZEN_PRIV_INPUT_GENERATOR)) {
472 ds_err("No permission to input generate");
473 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION;
477 ret = tz_devicemgr_init_generator(tz_devicemgr, resource, clas,
479 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) {
480 ds_err("Failed to init input generator\n");
485 tizen_input_device_manager_send_error(resource, ret);
489 device_manager_handle_deinit_generator(struct wl_client *client,
490 struct wl_resource *resource, uint32_t clas __attribute__((unused)))
492 struct ds_tizen_input_devicemgr *tz_devicemgr;
493 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
495 tz_devicemgr = wl_resource_get_user_data(resource);
497 if (!tz_devicemgr_check_privilege(tz_devicemgr, client,
498 TIZEN_PRIV_INPUT_GENERATOR)) {
499 ds_err("No permission to input generate");
500 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION;
504 ret = tz_devicemgr_deinit_generator(tz_devicemgr, resource);
505 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) {
506 ds_err("Failed to deinit input generator\n");
511 tizen_input_device_manager_send_error(resource, ret);
516 xkb_keycode_t keycode;
520 find_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, void *data)
522 struct keycode_map *found_keycodes = (struct keycode_map *)data;
523 xkb_keysym_t keysym = found_keycodes->keysym;
525 const xkb_keysym_t *syms_out = NULL;
527 if (found_keycodes->keycode) return;
529 nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out);
530 if (nsyms && syms_out) {
531 if (*syms_out == keysym) {
532 found_keycodes->keycode = key;
538 tz_devicemgr_xkb_keycode_from_keysym(struct xkb_keymap *keymap,
539 xkb_keysym_t keysym, xkb_keycode_t *keycode)
541 struct keycode_map found_keycodes = {0,};
542 found_keycodes.keysym = keysym;
543 xkb_keymap_key_for_each(keymap, find_keycode, &found_keycodes);
545 *keycode = found_keycodes.keycode;
549 tz_devicemgr_xkb_keyname_to_keycode(struct xkb_keymap *keymap,
552 xkb_keysym_t keysym = 0x0;
553 xkb_keycode_t keycode = 0;
555 if (!strncmp(name, "Keycode-", sizeof("Keycode-")-1)) {
556 keycode = atoi(name + 8);
558 keysym = xkb_keysym_from_name(name, XKB_KEYSYM_NO_FLAGS);
559 tz_devicemgr_xkb_keycode_from_keysym(keymap, keysym, &keycode);
566 tz_devicemgr_client_get_device_clas(struct ds_tizen_input_devicemgr *tz_devicemgr,
567 struct wl_resource *resource)
569 struct ds_tizen_input_devicemgr_client *client_data;
571 wl_list_for_each(client_data, &tz_devicemgr->clients, link) {
572 if (client_data->resource == resource)
573 return client_data->clas;
579 device_manager_handle_generate_key(struct wl_client *client,
580 struct wl_resource *resource, const char *keyname, uint32_t pressed)
582 struct ds_tizen_input_devicemgr *tz_devicemgr;
583 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
586 struct ds_keyboard *kbd;
589 tz_devicemgr = wl_resource_get_user_data(resource);
591 clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource);
592 if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) == 0)
594 ds_err("Keyboard generator is not initialized by client");
598 if (!tz_devicemgr->devices.kbd ||
599 !tz_devicemgr->devices.kbd->input_device) {
600 ds_err("Keyboard device is not initialized\n");
604 if (!tz_devicemgr_check_privilege(tz_devicemgr, client,
605 TIZEN_PRIV_INPUT_GENERATOR)) {
606 ds_err("No permission to input generate");
607 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION;
611 // keyname to keycode using xkb_info
612 kbd = ds_input_device_get_keyboard(
613 tz_devicemgr->devices.kbd->input_device);
615 keycode = tz_devicemgr_xkb_keyname_to_keycode(kbd->keymap, keyname);
619 keycode = tz_devicemgr_keyname_to_keycode(&tz_devicemgr->keymap_list,
625 res = tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device,
628 ds_err("Generating key is failed. key: %s, pressed: %d",
632 res = tz_devicemgr_pressed_keys_update(tz_devicemgr, keycode, pressed);
634 ds_err("Updating pressed keys is failed. key: %s, pressed: %d",
638 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
641 tizen_input_device_manager_send_error(resource, ret);
645 device_manager_handle_generate_pointer(struct wl_client *client,
646 struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y,
649 struct ds_tizen_input_devicemgr *tz_devicemgr;
650 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
655 tz_devicemgr = wl_resource_get_user_data(resource);
657 clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource);
658 if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) == 0)
660 ds_err("Pointer generator is not initialized by client");
664 if (!tz_devicemgr->devices.ptr ||
665 !tz_devicemgr->devices.ptr->input_device) {
666 ds_err("Pointer device is not initialized\n");
670 if (!tz_devicemgr_check_privilege(tz_devicemgr, client,
671 TIZEN_PRIV_INPUT_GENERATOR)) {
672 ds_err("No permission to input generate");
673 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION;
677 if (button <= 0 || button >= TIZEN_INPUT_DEVICEMGR_MAX_BTN)
679 ds_err("Invalid button: %d\n", button);
680 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
684 if (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE) {
685 res = tz_devicemgr_generate_mouse_move(
686 tz_devicemgr->devices.ptr->input_device, (double)x, (double)y);
687 if (!res) goto finish;
688 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
691 state = (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN) ?
693 res = tz_devicemgr_generate_mouse_button(
694 tz_devicemgr->devices.ptr->input_device, button, state);
695 if (!res) goto finish;
696 if (state) tz_devicemgr->devices.ptr->mouse.pressed |= 1 << (button - 1);
697 else tz_devicemgr->devices.ptr->mouse.pressed &= ~(1 << (button - 1));
698 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
702 tizen_input_device_manager_send_error(resource, ret);
706 device_manager_handle_generate_touch(struct wl_client *client,
707 struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y,
710 struct ds_tizen_input_devicemgr *tz_devicemgr;
711 double transformed_x = .0, transformed_y = .0;
712 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
716 tz_devicemgr = wl_resource_get_user_data(resource);
718 clas = tz_devicemgr_client_get_device_clas(tz_devicemgr, resource);
719 if ((clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) == 0)
721 ds_err("Touch generator is not initialized by client");
725 if (!tz_devicemgr->devices.touch ||
726 !tz_devicemgr->devices.touch->input_device) {
727 ds_err("Touch device is not initialized\n");
731 if (!tz_devicemgr_check_privilege(tz_devicemgr, client,
732 TIZEN_PRIV_INPUT_GENERATOR)) {
733 ds_err("No permission to input generate");
734 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION;
738 if (finger >= (uint32_t)tz_devicemgr->touch_max_count)
740 ds_err("Invalid fingers: %d\n", finger);
741 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
745 if (tz_devicemgr->output.width != 0 && tz_devicemgr->output.height != 0) {
746 transformed_x = x / (double)tz_devicemgr->output.width;
747 transformed_y = y / (double)tz_devicemgr->output.height;
751 case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN: // 0
752 res = tz_devicemgr_generate_touch_move(
753 tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger);
755 res= tz_devicemgr_generate_touch_down(
756 tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger);
758 tz_devicemgr->devices.touch->touch.pressed |= 1 << finger;
759 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
761 case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END: // 2
762 res = tz_devicemgr_generate_touch_up(
763 tz_devicemgr->devices.touch->input_device, finger);
765 tz_devicemgr->devices.touch->touch.pressed &= ~(1 << finger);
766 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
768 case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE: // 1
769 res = tz_devicemgr_generate_touch_move(
770 tz_devicemgr->devices.touch->input_device, transformed_x, transformed_y, finger);
772 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
779 tizen_input_device_manager_send_error(resource, ret);
783 device_manager_handle_pointer_warp(struct wl_client *client,
784 struct wl_resource *resource, struct wl_resource *surface,
785 wl_fixed_t x, wl_fixed_t y)
787 struct ds_tizen_input_devicemgr *tz_devicemgr;
788 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
789 int32_t new_x, new_y;
790 double transformed_x = .0, transformed_y = .0;
791 struct ds_tizen_input_devicemgr_event_pointer_warp ds_event;
793 unsigned int timestamp;
795 tz_devicemgr = wl_resource_get_user_data(resource);
797 if (!tz_devicemgr->devices.ptr ||
798 !tz_devicemgr->devices.ptr->input_device) {
799 ds_err("Pointer device is not initialized\n");
803 new_x = wl_fixed_to_int(x);
804 new_y = wl_fixed_to_int(y);
806 if (tz_devicemgr->output.width != 0 && tz_devicemgr->output.height != 0) {
807 transformed_x = new_x / (double)tz_devicemgr->output.width;
808 transformed_y = new_y / (double)tz_devicemgr->output.height;
811 gettimeofday(&time, NULL);
812 timestamp = time.tv_sec * 1000 + time.tv_usec / 1000;
814 ds_event.time_msec = timestamp;
815 ds_event.surface = ds_surface_from_resource(surface);
816 ds_event.x = transformed_x;
817 ds_event.y = transformed_y;
818 ds_inf("Pointer warp. surface:%p, x:%.2f, y:%.2f", ds_event.surface,
819 ds_event.x, ds_event.y);
821 wl_signal_emit_mutable(&tz_devicemgr->events.pointer_warp, &ds_event);
822 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
825 tizen_input_device_manager_send_error(resource, ret);
829 device_manager_handle_destroy(struct wl_client *client,
830 struct wl_resource *resource)
832 wl_resource_destroy(resource);
836 tz_devicemgr_check_privilege(struct ds_tizen_input_devicemgr *tz_devicemgr,
837 struct wl_client *client, const char *rule)
843 if (!client) return false;
845 wl_client_get_credentials(client, &pid, &uid, &gid);
847 return tizen_security_check_privilege(pid, uid, rule);
850 static const struct ds_input_device_interface input_device_iface =
855 static struct ds_keyboard *
858 struct ds_keyboard *kbd;
859 kbd = calloc(1, sizeof *kbd);
861 ds_err("Could not allocate memory");
864 ds_keyboard_init(kbd, NULL);
869 static struct ds_pointer *
872 struct ds_pointer *pointer;
873 pointer = calloc(1, sizeof *pointer);
875 ds_err("Could not allocate memory");
878 ds_pointer_init(pointer, NULL);
883 static struct ds_touch *
886 struct ds_touch *touch;
887 touch = calloc(1, sizeof *touch);
889 ds_err("Could not allocate memory");
892 ds_touch_init(touch, NULL);
898 tz_devicemgr_create_device(struct ds_tizen_input_devicemgr_device *dev,
899 uint32_t clas, const char *name)
901 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
902 const char *dev_name;
904 if (dev->name && strlen(dev->name) > 0) {
905 ds_inf("device already has name. name:%s", dev->name);
906 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
909 if (dev->input_device) {
910 dev_name = ds_input_device_get_name(dev->input_device);
911 ds_inf("device was already set. name:%s", dev_name);
912 dev->name = strdup(dev_name);
913 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
916 //input_device create
917 dev->input_device = calloc(1, sizeof(struct ds_input_device));
918 if(!dev->input_device) {
919 ds_err("Failed to create input device !\n");
923 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD)
925 ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_KEYBOARD,
926 &input_device_iface, name, -1, -1);
927 dev->input_device->keyboard = create_ds_keyboard();
929 else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE)
931 ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_POINTER,
932 &input_device_iface, name, -1, -1);
933 dev->input_device->pointer = create_ds_pointer();
935 else if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN)
937 ds_input_device_init(dev->input_device, DS_INPUT_DEVICE_TOUCH,
938 &input_device_iface, name, -1, -1);
939 dev->input_device->touch = create_ds_touch();
943 dev->name = strdup(name);
945 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
949 tz_devicemgr_init_generator(struct ds_tizen_input_devicemgr *tz_devicemgr,
950 struct wl_resource *resource, uint32_t clas, const char *name)
952 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
953 struct ds_tizen_input_devicemgr_client *client_data;
954 struct ds_tizen_input_devicemgr_device *dev;
957 ds_inf("Init generator. name:%s", name);
959 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) {
960 dev = tz_devicemgr->devices.kbd;
961 ret = tz_devicemgr_create_device(dev, clas, name);
962 if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) {
964 tz_devicemgr->devices.kbd->ref++;
967 wl_signal_emit_mutable(&tz_devicemgr->backend->events.new_input,
971 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) {
972 dev = tz_devicemgr->devices.ptr;
973 ret = tz_devicemgr_create_device(dev, clas, name);
974 if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) {
976 tz_devicemgr->devices.ptr->ref++;
979 wl_signal_emit_mutable(&tz_devicemgr->backend->events.new_input,
983 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) {
984 dev = tz_devicemgr->devices.touch;
985 ret = tz_devicemgr_create_device(dev, clas, name);
986 if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) {
988 tz_devicemgr->devices.touch->ref++;
991 wl_signal_emit_mutable(&tz_devicemgr->backend->events.new_input,
997 wl_list_for_each(client_data, &tz_devicemgr->clients, link) {
998 if (client_data->resource == resource) {
999 if (client_data->init == false) {
1000 client_data->init = true;
1001 client_data->clas = clas;
1012 tz_devicemgr_deinit_generator(struct ds_tizen_input_devicemgr *tz_devicemgr,
1013 struct wl_resource *resource)
1015 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
1016 struct ds_tizen_input_devicemgr_client *client_data;
1017 struct ds_tizen_input_devicemgr_device *dev;
1022 ds_inf("Deinit generator.");
1023 wl_list_for_each(client_data, &tz_devicemgr->clients, link) {
1024 if (client_data->resource == resource) {
1025 if (client_data->init == true) {
1026 client_data->init = false;
1027 clas = client_data->clas;
1034 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) {
1035 dev = tz_devicemgr->devices.kbd;
1039 tz_devicemgr_pressed_keys_cleanup(tz_devicemgr);
1042 tz_devicemgr_device_close(dev);
1043 dev->created = false;
1049 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE) {
1050 dev = tz_devicemgr->devices.ptr;
1052 if (dev->ref <= 0) {
1054 while(dev->mouse.pressed)
1056 if (dev->mouse.pressed & (1 << i))
1058 res = tz_devicemgr_generate_mouse_button(dev->input_device,
1061 dev->mouse.pressed &= ~(1 << i);
1064 if (i >= TIZEN_INPUT_DEVICEMGR_MAX_BTN) break;
1069 tz_devicemgr_device_close(dev);
1070 dev->created = false;
1076 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN) {
1077 dev = tz_devicemgr->devices.touch;
1079 if (dev->ref <= 0) {
1081 while(dev->touch.pressed)
1083 if (dev->touch.pressed & (1 << i))
1085 res = tz_devicemgr_generate_touch_up(dev->input_device,
1088 dev->touch.pressed &= ~(1 << i);
1091 if (i >= tz_devicemgr->touch_max_count) break;
1096 tz_devicemgr_device_close(dev);
1097 dev->created = false;
1104 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
1108 tz_devicemgr_keyname_to_keycode(struct wl_list *list, const char *name)
1110 struct ds_tizen_input_devicemgr_keymap_data *data;
1112 if (!wl_list_empty(list)) {
1113 wl_list_for_each(data, list, link) {
1114 if (!strcmp(data->name, name)) {
1115 return data->keycode;
1124 tz_devicemgr_generate_key(struct ds_input_device *device, int keycode,
1127 struct ds_keyboard_event_key ds_event;
1128 struct timeval time;
1129 unsigned int timestamp;
1130 struct ds_keyboard *kbd;
1132 kbd = ds_input_device_get_keyboard(device);
1134 ds_err("No ds_keyboard to notify event");
1138 gettimeofday(&time, NULL);
1139 timestamp = time.tv_sec * 1000 + time.tv_usec / 1000;
1141 ds_event.time_msec = timestamp;
1142 ds_event.keycode = keycode - 8;
1144 ds_event.state = WL_KEYBOARD_KEY_STATE_PRESSED;
1146 ds_event.state = WL_KEYBOARD_KEY_STATE_RELEASED;
1148 ds_inf("Generate key. kbd:%p, key:%d, state:%s", kbd, ds_event.keycode,
1149 (ds_event.state == WL_KEYBOARD_KEY_STATE_PRESSED) ?
1150 "PRESSED" : "RELEASED");
1152 ds_keyboard_notify_key(kbd, &ds_event);
1158 tz_devicemgr_pressed_keys_update(struct ds_tizen_input_devicemgr *tz_devicemgr,
1159 int keycode, bool pressed)
1161 struct ds_tizen_input_devicemgr_key_info *key, *tmp;
1164 key = calloc(1, sizeof(*key));
1166 ds_err("Failed to alloc keydata memory.\n");
1169 key->keycode = keycode;
1170 wl_list_init(&key->link);
1171 wl_list_insert(&tz_devicemgr->devices.kbd->key.pressed, &key->link);
1174 wl_list_for_each_safe(key, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) {
1175 if (key->keycode == keycode) {
1176 wl_list_remove(&key->link);
1183 ds_inf("Update pressed keys. length: %d, keycode:%d, pressed:%d",
1184 wl_list_length(&tz_devicemgr->devices.kbd->key.pressed), keycode, pressed);
1190 tz_devicemgr_pressed_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr)
1192 struct ds_tizen_input_devicemgr_key_info *keydata, *tmp;
1194 ds_inf("Clean up the kbd.pressed_keys. length: %d",
1195 wl_list_length(&tz_devicemgr->devices.kbd->key.pressed));
1197 wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->devices.kbd->key.pressed, link) {
1198 if (tz_devicemgr->devices.kbd->input_device)
1199 tz_devicemgr_generate_key(tz_devicemgr->devices.kbd->input_device,
1200 keydata->keycode, false);
1201 wl_list_remove(&keydata->link);
1207 tz_devicemgr_keymap_list_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr)
1209 struct ds_tizen_input_devicemgr_keymap_data *keymap, *tmp;
1211 ds_inf("Clean up the keymap_list. length: %d",
1212 wl_list_length(&tz_devicemgr->keymap_list));
1214 wl_list_for_each_safe(keymap, tmp, &tz_devicemgr->keymap_list, link) {
1216 wl_list_remove(&keymap->link);
1222 tz_devicemgr_generate_touch_move(struct ds_input_device *device, double x, double y,
1225 struct ds_touch_event_motion ds_event;
1226 struct timeval time;
1227 unsigned int timestamp;
1228 struct ds_touch *touch;
1230 touch = ds_input_device_get_touch(device);
1232 ds_err("No ds_touch to notify event");
1236 gettimeofday(&time, NULL);
1237 timestamp = time.tv_sec * 1000 + time.tv_usec / 1000;
1239 ds_event.time_msec = timestamp;
1240 ds_event.id = finger;
1243 ds_inf("Generate touch motion. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y);
1245 wl_signal_emit_mutable(&touch->events.motion, &ds_event);
1251 tz_devicemgr_generate_touch_down(struct ds_input_device *device, double x, double y,
1254 struct ds_touch_event_down ds_event;
1255 struct timeval time;
1256 unsigned int timestamp;
1257 struct ds_touch *touch;
1259 touch = ds_input_device_get_touch(device);
1261 ds_err("No ds_touch to notify event");
1265 gettimeofday(&time, NULL);
1266 timestamp = time.tv_sec * 1000 + time.tv_usec / 1000;
1268 ds_event.time_msec = timestamp;
1269 ds_event.id = finger;
1272 ds_inf("Generate touch down. touch:%p, id:%d (%d, %d)", touch, ds_event.id, x, y);
1274 wl_signal_emit_mutable(&touch->events.down, &ds_event);
1280 tz_devicemgr_generate_touch_up(struct ds_input_device *device, uint32_t finger)
1282 struct ds_touch_event_up ds_event;
1283 struct timeval time;
1284 unsigned int timestamp;
1285 struct ds_touch *touch;
1287 touch = ds_input_device_get_touch(device);
1289 ds_err("No ds_touch to notify event");
1293 gettimeofday(&time, NULL);
1294 timestamp = time.tv_sec * 1000 + time.tv_usec / 1000;
1296 ds_event.time_msec = timestamp;
1297 ds_event.id = finger;
1298 ds_inf("Generate touch up. touch:%p, id:%d", touch, ds_event.id);
1300 wl_signal_emit_mutable(&touch->events.up, &ds_event);
1306 tz_devicemgr_generate_mouse_move(struct ds_input_device *device, double x, double y)
1308 struct ds_pointer_event_motion ds_event;
1309 struct timeval time;
1310 unsigned int timestamp;
1311 struct ds_pointer *pointer;
1313 pointer = ds_input_device_get_pointer(device);
1315 ds_err("No ds_pointer to notify event");
1319 gettimeofday(&time, NULL);
1320 timestamp = time.tv_sec * 1000 + time.tv_usec / 1000;
1322 ds_event.time_msec = timestamp;
1323 ds_event.delta_x = x;
1324 ds_event.delta_y = y;
1325 ds_inf("Generate mouse motion. pointer:%p, x:%f, y:%f", pointer, ds_event.delta_x, ds_event.delta_y);
1327 wl_signal_emit_mutable(&pointer->events.motion, &ds_event);
1333 tz_devicemgr_generate_mouse_button(struct ds_input_device *device, uint32_t button, bool state)
1335 struct ds_pointer_event_button ds_event;
1336 struct timeval time;
1337 unsigned int timestamp;
1338 struct ds_pointer *pointer;
1340 pointer = ds_input_device_get_pointer(device);
1342 ds_err("No ds_pointer to notify event");
1346 gettimeofday(&time, NULL);
1347 timestamp = time.tv_sec * 1000 + time.tv_usec / 1000;
1349 ds_event.time_msec = timestamp;
1350 ds_event.button = button;
1352 ds_event.state = DS_BUTTON_PRESSED;
1354 ds_event.state = DS_BUTTON_RELEASED;
1355 ds_inf("Generate mouse button. pointer:%p, button:%d, state:%s", pointer, ds_event.button, state ? "PRESSED" : "RELEASED");
1357 wl_signal_emit_mutable(&pointer->events.button, &ds_event);
1363 devicemgr_keyboard_grab_iface_enter(struct ds_seat_keyboard_grab *grab,
1364 struct ds_surface *surface, uint32_t keycodes[],
1365 size_t num_keycodes, struct ds_keyboard_modifiers *modifiers)
1367 ds_inf("devicemgr. keyboard_grab_iface_enter");
1371 devicemgr_keyboard_grab_iface_clear_focus(struct ds_seat_keyboard_grab *grab)
1373 ds_inf("devicemgr. keyboard_grab_iface_clear_focus");
1377 tz_devicemgr_blocked_keys_cleanup(struct ds_tizen_input_devicemgr *tz_devicemgr)
1379 struct ds_tizen_input_devicemgr_key_info *keydata, *tmp;
1381 ds_inf("Clean up the blocked keys. length: %d",
1382 wl_list_length(&tz_devicemgr->blocked_keys));
1384 wl_list_for_each_safe(keydata, tmp, &tz_devicemgr->blocked_keys, link) {
1385 wl_list_remove(&keydata->link);
1391 devicemgr_keyboard_grab_iface_key(struct ds_seat_keyboard_grab *grab,
1392 uint32_t time_msec, uint32_t key, uint32_t state)
1394 struct ds_tizen_input_devicemgr *devicemgr;
1395 struct ds_tizen_input_devicemgr_key_info *keydata, *tmp;
1396 bool key_blocked = false;
1398 ds_inf("devicemgr. keyboard_grab_iface_key");
1400 devicemgr = ds_seat_keyboard_grab_get_data(grab);
1401 if (!devicemgr->block_resource) {
1402 if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
1406 wl_list_for_each_safe(keydata, tmp, &devicemgr->blocked_keys, link) {
1407 if (keydata->keycode == (int)key) {
1408 wl_list_remove(&keydata->link);
1414 if (wl_list_empty(&devicemgr->blocked_keys)) {
1415 tz_devicemgr_ungrab_keyboard(devicemgr);
1423 if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
1424 keydata = calloc(1, sizeof (*keydata));
1427 keydata->keycode = key;
1428 wl_list_init(&keydata->link);
1429 wl_list_insert(&devicemgr->blocked_keys, &keydata->link);
1433 if (wl_list_empty(&devicemgr->blocked_keys))
1435 wl_list_for_each_safe(keydata, tmp, &devicemgr->blocked_keys, link) {
1436 if (keydata->keycode == (int)key) {
1437 wl_list_remove(&keydata->link);
1446 ds_inf("block key event: (%d %s)\n", key, (state ? "press" : "release"));
1450 devicemgr_modifiers_grab_iface_key(struct ds_seat_keyboard_grab *grab,
1451 struct ds_keyboard_modifiers *modifiers)
1453 ds_inf("devicemgr. modifiers_grab_iface_key");
1457 devicemgr_cancel_grab_iface_key(struct ds_seat_keyboard_grab *grab)
1459 ds_inf("devicemgr. cancel_grab_iface_key");
1462 static const struct ds_keyboard_grab_interface devicemgr_keyboard_grab_iface = {
1463 .enter = devicemgr_keyboard_grab_iface_enter,
1464 .clear_focus = devicemgr_keyboard_grab_iface_clear_focus,
1465 .key = devicemgr_keyboard_grab_iface_key,
1466 .modifiers = devicemgr_modifiers_grab_iface_key,
1467 .cancel = devicemgr_cancel_grab_iface_key,
1471 tz_devicemgr_grab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr)
1473 ds_seat_keyboard_start_grab(tz_devicemgr->seat, tz_devicemgr->grab);
1477 tz_devicemgr_ungrab_keyboard(struct ds_tizen_input_devicemgr *tz_devicemgr)
1479 ds_seat_keyboard_end_grab(tz_devicemgr->seat);
1483 tz_devicemgr_ungrab_keyboard_check(struct ds_tizen_input_devicemgr *tz_devicemgr)
1485 if (wl_list_empty(&tz_devicemgr->blocked_keys))
1486 tz_devicemgr_ungrab_keyboard(tz_devicemgr);
1488 tz_devicemgr->block_resource = NULL;
1492 devicemgr_add_timer(struct ds_tizen_input_devicemgr *tz_devicemgr,
1493 wl_event_loop_timer_func_t func, int time)
1495 struct wl_event_loop *event_loop;
1497 event_loop = wl_display_get_event_loop(tz_devicemgr->backend->display);
1499 ds_err("Failed to get event_loop from display: %p",
1500 tz_devicemgr->backend->display);
1504 tz_devicemgr->timer = wl_event_loop_add_timer(event_loop, func,
1506 if (!tz_devicemgr->timer) {
1507 ds_err("Failed to timer");
1510 wl_event_source_timer_update(tz_devicemgr->timer, time);
1516 devicemgr_block_timer(void *data)
1518 struct ds_tizen_input_devicemgr *devicemgr = data;
1520 tizen_input_device_manager_send_block_expired(devicemgr->block_resource);
1522 tz_devicemgr_ungrab_keyboard_check(devicemgr);
1524 wl_event_source_remove(devicemgr->timer);
1525 devicemgr->timer = NULL;
1531 device_manager_handle_block_events(struct wl_client *client,
1532 struct wl_resource *resource, uint32_t serial, uint32_t clas,
1535 struct ds_tizen_input_devicemgr *tz_devicemgr;
1536 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
1539 tz_devicemgr = wl_resource_get_user_data(resource);
1541 if (!tz_devicemgr_check_privilege(tz_devicemgr, client,
1542 TIZEN_PRIV_INPUT_BLOCK)) {
1543 ds_err("No permission to input generate");
1544 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION;
1548 if (clas != TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD) {
1549 ds_err("only support keyboard device. (requested: 0x%x)\n", clas);
1550 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1554 if(tz_devicemgr->block_resource) {
1555 ds_err("currently the input system is already blocked\n");
1556 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1560 res = devicemgr_add_timer(tz_devicemgr, devicemgr_block_timer, duration);
1562 ds_err("Failed to add a timer\n");
1566 tz_devicemgr_grab_keyboard(tz_devicemgr);
1567 tz_devicemgr->block_resource = resource;
1568 ds_inf("Block events. clas: %d, duration:%d", clas, duration);
1569 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
1572 tizen_input_device_manager_send_error(resource, ret);
1576 device_manager_handle_unblock_events(struct wl_client *client,
1577 struct wl_resource *resource, uint32_t serial)
1579 struct ds_tizen_input_devicemgr *tz_devicemgr;
1580 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
1582 tz_devicemgr = wl_resource_get_user_data(resource);
1584 if (!tz_devicemgr_check_privilege(tz_devicemgr, client,
1585 TIZEN_PRIV_INPUT_BLOCK)) {
1586 ds_err("No permission to input generate");
1587 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_PERMISSION;
1591 if (tz_devicemgr->block_resource != resource) {
1592 ds_err("currently the input system is blocked by another resource");
1593 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1597 tz_devicemgr_ungrab_keyboard_check(tz_devicemgr);
1598 tz_devicemgr->block_resource = NULL;
1599 ds_inf("Unblock events.");
1600 ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
1602 if (tz_devicemgr->timer) {
1603 wl_event_source_remove(tz_devicemgr->timer);
1604 tz_devicemgr->timer = NULL;
1608 tizen_input_device_manager_send_error(resource, ret);