1 #include "e_devicemgr_private.h"
2 #include "e_input_event.h"
3 #include "e_comp_wl_intern.h"
6 e_devicemgr_strcmp(const char *dst, const char *src)
8 int dst_len, src_len, str_len;
10 dst_len = strlen(dst);
11 src_len = strlen(src);
13 if (src_len > dst_len) str_len = src_len;
14 else str_len = dst_len;
16 if (!strncmp(dst, src, str_len))
23 _e_devicemgr_input_pointer_warp(int x, int y)
25 e_input_device_pointer_warp(NULL, x, y);
26 DMWRN("The pointer warped to (%d, %d) !\n", x, y);
28 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
32 e_devicemgr_input_pointer_warp(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface, wl_fixed_t x, wl_fixed_t y)
36 int new_x, new_y, ret;
37 int i, min_x, min_y, max_x, max_y, tmp_x, tmp_y, map_x = 0, map_y = 0;
39 if (!(ec = e_client_from_surface_resource(surface)) || !ec->visible)
41 DMERR("The given surface is invalid or invisible !\n");
42 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
45 if (ec != e_comp_wl->ptr.ec)
47 DMERR("Pointer is not on the given surface !\n");
48 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
51 if ((!e_config->show_cursor) || (!e_comp_wl->ptr.enabled))
53 DMERR("Pointer is not available");
54 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_POINTER_AVAILABLE;
57 new_x = wl_fixed_to_int(x);
58 new_y = wl_fixed_to_int(y);
60 if (new_x < 0) new_x = 0;
61 if ((ec->w != 0) && (new_x > ec->w - 1)) new_x = ec->w - 1;
63 if (new_y < 0) new_y = 0;
64 if ((ec->h != 0) && (new_y > ec->h - 1)) new_y = ec->h - 1;
66 new_x = ec->client.x + new_x;
67 new_y = ec->client.y + new_y;
69 if (e_client_transform_core_enable_get(ec))
71 e_comp_wl_map_inv_coord_get(ec, new_x, new_y, &map_x, &map_y);
72 DMWRN("Pointer warp. (%d, %d) -> map_inv_coord (%d, %d)",
73 new_x, new_y, map_x, map_y);
75 map = e_client_map_get(ec);
76 e_map_point_coord_get(map, 0, &min_x, &min_y, NULL);
80 for (i = 1; i < e_map_count_get(map); i++)
82 e_map_point_coord_get(map, i, &tmp_x, &tmp_y, NULL);
84 if (tmp_x < min_x) min_x = tmp_x;
85 else if (tmp_x > max_x) max_x = tmp_x;
87 if (tmp_y < min_y) min_y = tmp_y;
88 else if (tmp_y > max_y) max_y = tmp_y;
93 if (map_x < min_x) map_x = min_x;
94 if (map_x > max_x - 1) map_x = max_x - 1;
98 if (map_y < min_y) map_y = min_y;
99 if (map_y > max_y - 1) map_y = max_y - 1;
105 ret = _e_devicemgr_input_pointer_warp(new_x, new_y);
110 e_devicemgr_detent_is_detent(const char *name)
112 EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
114 if (!strncmp(name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
121 _e_devicemgr_detent_set_info(E_Devicemgr_Input_Device *dev)
123 if (dev->name && !strncmp(dev->name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
125 E_FREE(e_devicemgr->detent.identifier);
126 if (dev->identifier) e_devicemgr->detent.identifier = strdup(dev->identifier);
131 _e_devicemgr_detent_unset_info(E_Devicemgr_Input_Device *dev)
133 if (dev->name && !strncmp(dev->name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
135 E_FREE(e_devicemgr->detent.identifier);
140 _e_devicemgr_input_keyevent_free(void *data EINA_UNUSED, void *ev)
142 Ecore_Event_Key *e = ev;
144 eina_stringshare_del(e->keyname);
145 eina_stringshare_del(e->key);
146 eina_stringshare_del(e->compose);
153 _e_devicemgr_input_mouse_button_remap(Ecore_Event_Mouse_Button *ev, Eina_Bool pressed)
155 Ecore_Event_Key *ev_key;
156 E_Keyrouter_Event_Data *key_data;
157 struct xkb_keymap *keymap = NULL;
159 g_mutex_lock(&e_comp_wl->xkb.keymap_mutex);
160 keymap = e_comp_wl->xkb.keymap;
161 g_mutex_unlock(&e_comp_wl->xkb.keymap_mutex);
163 EINA_SAFETY_ON_NULL_RETURN_VAL(keymap, ECORE_CALLBACK_PASS_ON);
164 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, ECORE_CALLBACK_PASS_ON);
166 if (ev->buttons != 3) return ECORE_CALLBACK_PASS_ON;
168 ev_key = E_NEW(Ecore_Event_Key, 1);
169 EINA_SAFETY_ON_NULL_RETURN_VAL(ev_key, ECORE_CALLBACK_PASS_ON);
171 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
172 EINA_SAFETY_ON_NULL_GOTO(key_data, failed);
174 ev_key->key = (char *)eina_stringshare_add("XF86Back");
175 ev_key->keyname = (char *)eina_stringshare_add(ev_key->key);
176 ev_key->compose = (char *)eina_stringshare_add(ev_key->key);
177 ev_key->timestamp = e_util_timestamp_get();
178 ev_key->same_screen = 1;
180 ev_key->window = e_comp->ee_win;
181 ev_key->event_window = e_comp->ee_win;
182 ev_key->root_window = e_comp->ee_win;
183 ev_key->keycode = e_devicemgr->dconfig->conf->input.back_keycode;
184 ev_key->data = key_data;
186 if (e_input_thread_mode_get())
188 E_Input_Event_Source *input_event_source = e_input_event_source_get();
189 e_input_event_add(input_event_source, pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, ev_key, _e_devicemgr_input_keyevent_free, NULL);
193 ecore_event_add(pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, ev_key, _e_devicemgr_input_keyevent_free, NULL);
196 return ECORE_CALLBACK_DONE;
200 return ECORE_CALLBACK_PASS_ON;
204 _e_devicemgr_input_device_add(const char *name, const char *identifier, const char *seatname, Ecore_Device_Class clas, Ecore_Device_Subclass subclas)
206 E_Devicemgr_Input_Device *dev = NULL;
208 int current_touch_count = -1;
210 EINA_SAFETY_ON_NULL_RETURN(name);
211 EINA_SAFETY_ON_NULL_RETURN(identifier);
212 EINA_SAFETY_ON_NULL_RETURN(e_devicemgr);
214 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
215 EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
217 if (!dev->name) continue;
218 if (!dev->identifier) continue;
219 if ((dev->clas == clas) && (dev->subclas == subclas) &&
220 (!strcmp(dev->name, name)) &&
221 (!strcmp(dev->identifier, identifier)))
223 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
227 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
229 if (!(dev = E_NEW(E_Devicemgr_Input_Device, 1))) return;
230 dev->name = eina_stringshare_add(name);
231 dev->identifier = eina_stringshare_add(identifier);
232 dev->seat_name = eina_stringshare_add(seatname);
234 dev->subclas = subclas;
236 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
237 e_devicemgr->device_list = eina_list_append(e_devicemgr->device_list, dev);
238 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
240 if (dev->clas == ECORE_DEVICE_CLASS_MOUSE)
241 e_devicemgr->last_device_ptr = dev;
243 if (dev->clas == ECORE_DEVICE_CLASS_TOUCH)
245 if (!e_devicemgr->last_device_touch)
246 e_devicemgr->last_device_touch = dev;
248 current_touch_count = e_input_touch_max_count_get();
249 if (e_devicemgr->max_touch_count < current_touch_count)
251 e_devicemgr->max_touch_count = current_touch_count;
252 if (e_devicemgr->multi)
254 ELOGF("DEVMGR_TOUCH", "Multi pointer is NOT NULL. It'll be updated to %d finger of touch.\n", NULL, current_touch_count);
255 free (e_devicemgr->multi);
258 e_devicemgr->multi = calloc(1, sizeof(E_Devicemgr_Input_Device_Multi)*current_touch_count);
260 if (!e_devicemgr->multi)
261 ELOGF("DEVMGR_TOUCH", "Failed to allocate memory for multi ptr. (finger=%d)\n", NULL, current_touch_count);
263 e_devicemgr_wl_touch_max_count_send(e_devicemgr->max_touch_count, NULL, NULL);
267 E_Devicemgr_Input_Device *last_device_kbd = atomic_load(&e_devicemgr->last_device_kbd);
268 if (!last_device_kbd && dev->clas == ECORE_DEVICE_CLASS_KEYBOARD)
269 atomic_store(&e_devicemgr->last_device_kbd, dev);
271 e_devicemgr_inputgen_device_ready_send(dev);
272 e_devicemgr_wl_device_add(dev);
273 e_devicemgr_inputgen_get_device_info(dev);
274 _e_devicemgr_detent_set_info(dev);
278 _e_devicemgr_input_device_del(const char *name, const char *identifier, const char *seatname, Ecore_Device_Class clas, Ecore_Device_Subclass subclas)
280 E_Devicemgr_Input_Device *dev = NULL;
281 E_Devicemgr_Input_Device *last_device_kbd = NULL;
284 EINA_SAFETY_ON_NULL_RETURN(name);
285 EINA_SAFETY_ON_NULL_RETURN(identifier);
287 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
288 EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
290 if (!dev->name) continue;
291 if (!dev->identifier) continue;
292 if ((dev->clas == clas) && (dev->subclas == subclas) &&
293 (!strcmp(dev->name, name)) &&
294 (!strcmp(dev->identifier, identifier)))
300 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
304 _e_devicemgr_detent_unset_info(dev);
305 e_devicemgr_wl_device_del(dev);
307 if (dev->name) eina_stringshare_del(dev->name);
308 if (dev->identifier) eina_stringshare_del(dev->identifier);
309 if (dev->seat_name) eina_stringshare_del(dev->seat_name);
311 e_devicemgr->device_list = eina_list_remove(e_devicemgr->device_list, dev);
313 if (e_devicemgr->last_device_ptr == dev)
314 e_devicemgr->last_device_ptr = NULL;
316 if (e_devicemgr->last_device_touch == dev)
317 e_devicemgr->last_device_touch = NULL;
319 last_device_kbd = atomic_load(&e_devicemgr->last_device_kbd);
321 if (last_device_kbd == dev)
322 atomic_store(&e_devicemgr->last_device_kbd, NULL);
326 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
330 _e_devicemgr_input_device_update(Ecore_Device *dev)
333 E_Devicemgr_Input_Device *data;
334 char *dev_identifier;
336 EINA_SAFETY_ON_NULL_RETURN(dev);
338 dev_identifier = (char *)ecore_device_identifier_get(dev);
339 EINA_SAFETY_ON_NULL_RETURN(dev_identifier);
341 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
342 EINA_LIST_FOREACH(e_devicemgr->device_list, l, data)
344 if (data->clas == ecore_device_class_get(dev) && data->identifier)
346 if (e_devicemgr_strcmp(dev_identifier, data->identifier))
348 data->subclas = ecore_device_subclass_get(dev);
350 e_devicemgr_wl_device_update(data);
351 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
356 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
360 _e_devicemgr_input_cb_mouse_button_down(void *data, int type, void *event)
362 Ecore_Event_Mouse_Button *ev;
363 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
364 E_Comp_Config *comp_conf = NULL;
366 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
367 ev = (Ecore_Event_Mouse_Button *)event;
369 if (e_devicemgr->dconfig->conf->input.button_remap_enable)
370 res = _e_devicemgr_input_mouse_button_remap(ev, EINA_TRUE);
372 comp_conf = e_comp_config_get();
373 if (comp_conf && comp_conf->input_log_enable)
375 ELOGF("DEVMGR", "Mouse Down (id: %d, button: %d, x: %d, y: %d), res: %d", NULL,
376 ev->multi.device, ev->buttons, ev->x, ev->y, res);
383 _e_devicemgr_input_cb_mouse_button_up(void *data, int type, void *event)
385 Ecore_Event_Mouse_Button *ev;
386 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
387 E_Comp_Config *comp_conf = NULL;
389 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
390 ev = (Ecore_Event_Mouse_Button *)event;
392 if (e_devicemgr->dconfig->conf->input.button_remap_enable)
393 res = _e_devicemgr_input_mouse_button_remap(ev, EINA_FALSE);
395 comp_conf = e_comp_config_get();
396 if (comp_conf && comp_conf->input_log_enable)
398 ELOGF("DEVMGR", "Mouse Up (id: %d, button: %d, x: %d, y: %d), res: %d", NULL,
399 ev->multi.device, ev->buttons, ev->x, ev->y, res);
406 _e_devicemgr_input_cb_mouse_wheel(void *data, int type, void *event)
408 Ecore_Event_Mouse_Wheel *ev;
410 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
411 E_Comp_Config *comp_conf;
413 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
414 ev = (Ecore_Event_Mouse_Wheel *)event;
416 if (!ev->dev) return ECORE_CALLBACK_PASS_ON;
418 if (!e_devicemgr_detent_is_detent(ecore_device_name_get(ev->dev)))
419 return ECORE_CALLBACK_PASS_ON;
422 comp_conf = e_comp_config_get();
423 if (comp_conf && comp_conf->e_wheel_click_angle)
425 detent = (int)(detent / comp_conf->e_wheel_click_angle);
428 if (detent == 1 || detent == -1)
430 detent = detent * (-1);
431 if (!e_devicemgr_intercept_hook_call(E_DEVICEMGR_INTERCEPT_HOOK_DETENT, &detent))
433 DMDBG("Stop propagate detent event. value: %d\n", detent);
434 return ECORE_CALLBACK_DONE;
436 e_devicemgr_wl_detent_send_event(detent);
439 return ECORE_CALLBACK_DONE;
444 _e_devicemgr_input_cb_device_add(void *data, int type, void *event)
446 Ecore_Event_Device_Info *ev;
448 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
449 ev = (Ecore_Event_Device_Info *)event;
451 _e_devicemgr_input_device_add(ev->name, ev->identifier, ev->seatname, ev->clas, ev->subclas);
453 return ECORE_CALLBACK_PASS_ON;
457 _e_devicemgr_input_cb_device_del(void *data, int type, void *event)
459 Ecore_Event_Device_Info *ev;
461 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
462 ev = (Ecore_Event_Device_Info *)event;
464 _e_devicemgr_input_device_del(ev->name, ev->identifier, ev->seatname, ev->clas, ev->subclas);
466 return ECORE_CALLBACK_PASS_ON;
470 _e_devicemgr_input_cb_device_update(void *data, int type, void *event)
472 Ecore_Event_Device_Update *ev;
474 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
476 ev = (Ecore_Event_Device_Update *)event;
477 EINA_SAFETY_ON_NULL_RETURN_VAL(ev->dev, ECORE_CALLBACK_PASS_ON);
479 _e_devicemgr_input_device_update(ev->dev);
481 return ECORE_CALLBACK_PASS_ON;
485 e_devicemgr_input_init(void)
487 e_devicemgr->virtual_mouse_device_fd = -1;
488 e_devicemgr->virtual_key_device_fd = -1;
490 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_devicemgr_input_cb_mouse_button_down, NULL);
491 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_BUTTON_UP, _e_devicemgr_input_cb_mouse_button_up, NULL);
492 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_WHEEL, _e_devicemgr_input_cb_mouse_wheel, NULL);
493 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_ADD, _e_devicemgr_input_cb_device_add, NULL);
494 E_LIST_HANDLER_APPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_DEL, _e_devicemgr_input_cb_device_del, NULL);
495 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_SUBCLASS_UPDATE, _e_devicemgr_input_cb_device_update, NULL);
497 if (e_devicemgr->dconfig->conf->input.virtual_key_device_enable)
499 e_devicemgr->virtual_key_device_fd = e_devicemgr_create_virtual_device(ECORE_DEVICE_CLASS_KEYBOARD, "Virtual Key Device");
501 if (e_devicemgr->virtual_key_device_fd >= 0)
502 DMINF("input.virtual_key_device_enable: device fd : %d\n", e_devicemgr->virtual_key_device_fd);
504 DMWRN("input.virtual_key_device_enable: but failed to create device !\n");
507 if (e_devicemgr->dconfig->conf->input.virtual_mouse_device_enable)
509 e_devicemgr->virtual_mouse_device_fd = e_devicemgr_create_virtual_device(ECORE_DEVICE_CLASS_MOUSE, "Virtual Mouse Device");
511 if (e_devicemgr->virtual_mouse_device_fd >= 0)
512 DMINF("input.virtual_mouse_device_enable: device fd : %d\n", e_devicemgr->virtual_mouse_device_fd);
514 DMWRN("input.virtual_mouse_device_enable: but failed to create device !\n");
517 e_devicemgr->max_touch_count = 0;
523 e_devicemgr_input_shutdown(void)
525 Ecore_Event_Handler *h = NULL;
527 EINA_LIST_FREE(e_devicemgr->handlers, h)
528 ecore_event_handler_del(h);
530 if (e_devicemgr->virtual_key_device_fd)
532 e_devicemgr_destroy_virtual_device(e_devicemgr->virtual_key_device_fd);
533 e_devicemgr->virtual_key_device_fd = -1;
535 if (e_devicemgr->virtual_mouse_device_fd)
537 e_devicemgr_destroy_virtual_device(e_devicemgr->virtual_mouse_device_fd);
538 e_devicemgr->virtual_mouse_device_fd = -1;
541 if (e_devicemgr->multi)
542 free(e_devicemgr->multi);