1 #include "e_devicemgr_private.h"
2 #include "e_input_event.h"
5 e_devicemgr_strcmp(const char *dst, const char *src)
7 int dst_len, src_len, str_len;
10 src_len = strlen(src);
12 if (src_len > dst_len) str_len = src_len;
13 else str_len = dst_len;
15 if (!strncmp(dst, src, str_len))
22 _e_devicemgr_input_pointer_warp(int x, int y)
24 e_input_device_pointer_warp(NULL, x, y);
25 DMWRN("The pointer warped to (%d, %d) !\n", x, y);
27 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
31 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)
35 int new_x, new_y, ret;
36 int i, min_x, min_y, max_x, max_y, tmp_x, tmp_y, map_x = 0, map_y = 0;
38 if (!(ec = e_client_from_surface_resource(surface)) || !ec->visible)
40 DMERR("The given surface is invalid or invisible !\n");
41 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
44 if (ec != e_comp_wl->ptr.ec)
46 DMERR("Pointer is not on the given surface !\n");
47 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
50 if (e_pointer_is_hidden(e_comp->pointer))
52 DMERR("Pointer is hidden");
53 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_POINTER_AVAILABLE;
56 new_x = wl_fixed_to_int(x);
57 new_y = wl_fixed_to_int(y);
59 if (new_x < 0) new_x = 0;
60 if ((ec->w != 0) && (new_x > ec->w - 1)) new_x = ec->w - 1;
62 if (new_y < 0) new_y = 0;
63 if ((ec->h != 0) && (new_y > ec->h - 1)) new_y = ec->h - 1;
65 new_x = ec->client.x + new_x;
66 new_y = ec->client.y + new_y;
68 if (evas_object_map_enable_get(ec->frame))
70 e_comp_wl_map_inv_coord_get(ec, new_x, new_y, &map_x, &map_y);
71 DMWRN("Pointer warp. (%d, %d) -> map_inv_coord (%d, %d)",
72 new_x, new_y, map_x, map_y);
74 map = e_client_map_get(ec);
75 e_map_point_coord_get(map, 0, &min_x, &min_y, NULL);
79 for (i = 1; i < e_map_count_get(map); i++)
81 e_map_point_coord_get(map, i, &tmp_x, &tmp_y, NULL);
83 if (tmp_x < min_x) min_x = tmp_x;
84 else if (tmp_x > max_x) max_x = tmp_x;
86 if (tmp_y < min_y) min_y = tmp_y;
87 else if (tmp_y > max_y) max_y = tmp_y;
92 if (map_x < min_x) map_x = min_x;
93 if (map_x > max_x - 1) map_x = max_x - 1;
97 if (map_y < min_y) map_y = min_y;
98 if (map_y > max_y - 1) map_y = max_y - 1;
104 ret = _e_devicemgr_input_pointer_warp(new_x, new_y);
109 e_devicemgr_detent_is_detent(const char *name)
111 EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
113 if (!strncmp(name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
120 _e_devicemgr_detent_set_info(E_Devicemgr_Input_Device *dev)
122 if (dev->name && !strncmp(dev->name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
124 E_FREE(e_devicemgr->detent.identifier);
125 if (dev->identifier) e_devicemgr->detent.identifier = strdup(dev->identifier);
130 _e_devicemgr_detent_unset_info(E_Devicemgr_Input_Device *dev)
132 if (dev->name && !strncmp(dev->name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
134 E_FREE(e_devicemgr->detent.identifier);
139 _e_devicemgr_input_keyevent_free(void *data EINA_UNUSED, void *ev)
141 Ecore_Event_Key *e = ev;
143 eina_stringshare_del(e->keyname);
144 eina_stringshare_del(e->key);
145 eina_stringshare_del(e->compose);
152 _e_devicemgr_input_mouse_button_remap(Ecore_Event_Mouse_Button *ev, Eina_Bool pressed)
154 Ecore_Event_Key *ev_key;
155 E_Keyrouter_Event_Data *key_data;
157 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl->xkb.keymap, ECORE_CALLBACK_PASS_ON);
158 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, ECORE_CALLBACK_PASS_ON);
160 if (ev->buttons != 3) return ECORE_CALLBACK_PASS_ON;
162 ev_key = E_NEW(Ecore_Event_Key, 1);
163 EINA_SAFETY_ON_NULL_RETURN_VAL(ev_key, ECORE_CALLBACK_PASS_ON);
165 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
166 EINA_SAFETY_ON_NULL_GOTO(key_data, failed);
168 ev_key->key = (char *)eina_stringshare_add("XF86Back");
169 ev_key->keyname = (char *)eina_stringshare_add(ev_key->key);
170 ev_key->compose = (char *)eina_stringshare_add(ev_key->key);
171 ev_key->timestamp = e_util_timestamp_get();
172 ev_key->same_screen = 1;
174 ev_key->window = e_comp->ee_win;
175 ev_key->event_window = e_comp->ee_win;
176 ev_key->root_window = e_comp->ee_win;
177 ev_key->keycode = e_devicemgr->dconfig->conf->input.back_keycode;
178 ev_key->data = key_data;
180 if (e_input_thread_mode_get())
182 E_Input_Event_Source *input_event_source = e_input_event_source_get();
183 e_input_event_add(input_event_source, pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, ev_key, _e_devicemgr_input_keyevent_free, NULL);
187 ecore_event_add(pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, ev_key, _e_devicemgr_input_keyevent_free, NULL);
190 return ECORE_CALLBACK_DONE;
194 return ECORE_CALLBACK_PASS_ON;
198 _e_devicemgr_input_device_add(const char *name, const char *identifier, const char *seatname, Ecore_Device_Class clas, Ecore_Device_Subclass subclas)
200 E_Devicemgr_Input_Device *dev = NULL;
202 int current_touch_count = -1;
204 EINA_SAFETY_ON_NULL_RETURN(name);
205 EINA_SAFETY_ON_NULL_RETURN(identifier);
206 EINA_SAFETY_ON_NULL_RETURN(e_devicemgr);
208 g_mutex_lock(&e_devicemgr->device_list_mutex);
209 EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
211 if (!dev->name) continue;
212 if (!dev->identifier) continue;
213 if ((dev->clas == clas) && (dev->subclas == subclas) &&
214 (!strcmp(dev->name, name)) &&
215 (!strcmp(dev->identifier, identifier)))
217 g_mutex_unlock(&e_devicemgr->device_list_mutex);
221 g_mutex_unlock(&e_devicemgr->device_list_mutex);
223 if (!(dev = E_NEW(E_Devicemgr_Input_Device, 1))) return;
224 dev->name = eina_stringshare_add(name);
225 dev->identifier = eina_stringshare_add(identifier);
226 dev->seat_name = eina_stringshare_add(seatname);
228 dev->subclas = subclas;
230 g_mutex_lock(&e_devicemgr->device_list_mutex);
231 e_devicemgr->device_list = eina_list_append(e_devicemgr->device_list, dev);
232 g_mutex_unlock(&e_devicemgr->device_list_mutex);
234 if (dev->clas == ECORE_DEVICE_CLASS_MOUSE)
235 e_devicemgr->last_device_ptr = dev;
237 if (dev->clas == ECORE_DEVICE_CLASS_TOUCH)
239 if (!e_devicemgr->last_device_touch)
240 e_devicemgr->last_device_touch = dev;
242 current_touch_count = e_input_touch_max_count_get();
243 if (e_devicemgr->max_touch_count < current_touch_count)
245 e_devicemgr->max_touch_count = current_touch_count;
246 if (e_devicemgr->multi)
248 ELOGF("DEVMGR_TOUCH", "Multi pointer is NOT NULL. It'll be updated to %d finger of touch.\n", NULL, current_touch_count);
249 free (e_devicemgr->multi);
252 e_devicemgr->multi = calloc(1, sizeof(E_Devicemgr_Input_Device_Multi)*current_touch_count);
254 if (!e_devicemgr->multi)
255 ELOGF("DEVMGR_TOUCH", "Failed to allocate memory for multi ptr. (finger=%d)\n", NULL, current_touch_count);
257 e_devicemgr_wl_touch_max_count_send(e_devicemgr->max_touch_count, NULL, NULL);
261 g_mutex_lock(&e_devicemgr->last_device_kbd_mutex);
262 if (!e_devicemgr->last_device_kbd && dev->clas == ECORE_DEVICE_CLASS_KEYBOARD)
263 e_devicemgr->last_device_kbd = dev;
265 g_mutex_unlock(&e_devicemgr->last_device_kbd_mutex);
267 e_devicemgr_inputgen_device_ready_send(dev);
268 e_devicemgr_wl_device_add(dev);
269 e_devicemgr_inputgen_get_device_info(dev);
270 _e_devicemgr_detent_set_info(dev);
274 _e_devicemgr_input_device_del(const char *name, const char *identifier, const char *seatname, Ecore_Device_Class clas, Ecore_Device_Subclass subclas)
276 E_Devicemgr_Input_Device *dev = NULL;
279 EINA_SAFETY_ON_NULL_RETURN(name);
280 EINA_SAFETY_ON_NULL_RETURN(identifier);
282 g_mutex_lock(&e_devicemgr->device_list_mutex);
283 EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
285 if (!dev->name) continue;
286 if (!dev->identifier) continue;
287 if ((dev->clas == clas) && (dev->subclas == subclas) &&
288 (!strcmp(dev->name, name)) &&
289 (!strcmp(dev->identifier, identifier)))
292 g_mutex_unlock(&e_devicemgr->device_list_mutex);
298 _e_devicemgr_detent_unset_info(dev);
299 e_devicemgr_wl_device_del(dev);
301 if (dev->name) eina_stringshare_del(dev->name);
302 if (dev->identifier) eina_stringshare_del(dev->identifier);
303 if (dev->seat_name) eina_stringshare_del(dev->seat_name);
305 g_mutex_lock(&e_devicemgr->device_list_mutex);
306 e_devicemgr->device_list = eina_list_remove(e_devicemgr->device_list, dev);
307 g_mutex_unlock(&e_devicemgr->device_list_mutex);
309 if (e_devicemgr->last_device_ptr == dev)
310 e_devicemgr->last_device_ptr = NULL;
312 if (e_devicemgr->last_device_touch == dev)
313 e_devicemgr->last_device_touch = NULL;
315 if (e_devicemgr->last_device_kbd == dev)
317 g_mutex_lock(&e_devicemgr->last_device_kbd_mutex);
318 e_devicemgr->last_device_kbd = NULL;
319 g_mutex_unlock(&e_devicemgr->last_device_kbd_mutex);
326 _e_devicemgr_input_device_update(Ecore_Device *dev)
329 E_Devicemgr_Input_Device *data;
330 char *dev_identifier;
332 EINA_SAFETY_ON_NULL_RETURN(dev);
334 dev_identifier = (char *)ecore_device_identifier_get(dev);
335 EINA_SAFETY_ON_NULL_RETURN(dev_identifier);
337 g_mutex_lock(&e_devicemgr->device_list_mutex);
338 EINA_LIST_FOREACH(e_devicemgr->device_list, l, data)
340 if (data->clas == ecore_device_class_get(dev) && data->identifier)
342 if (e_devicemgr_strcmp(dev_identifier, data->identifier))
344 data->subclas = ecore_device_subclass_get(dev);
346 e_devicemgr_wl_device_update(data);
347 g_mutex_unlock(&e_devicemgr->device_list_mutex);
352 g_mutex_unlock(&e_devicemgr->device_list_mutex);
356 _e_devicemgr_input_cb_mouse_button_down(void *data, int type, void *event)
358 Ecore_Event_Mouse_Button *ev;
359 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
360 E_Comp_Config *comp_conf = NULL;
362 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
363 ev = (Ecore_Event_Mouse_Button *)event;
365 if (e_devicemgr->dconfig->conf->input.button_remap_enable)
366 res = _e_devicemgr_input_mouse_button_remap(ev, EINA_TRUE);
368 comp_conf = e_comp_config_get();
369 if (comp_conf && comp_conf->input_log_enable)
371 ELOGF("DEVMGR", "Mouse Down (id: %d, button: %d, x: %d, y: %d), res: %d", NULL,
372 ev->multi.device, ev->buttons, ev->x, ev->y, res);
379 _e_devicemgr_input_cb_mouse_button_up(void *data, int type, void *event)
381 Ecore_Event_Mouse_Button *ev;
382 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
383 E_Comp_Config *comp_conf = NULL;
385 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
386 ev = (Ecore_Event_Mouse_Button *)event;
388 if (e_devicemgr->dconfig->conf->input.button_remap_enable)
389 res = _e_devicemgr_input_mouse_button_remap(ev, EINA_FALSE);
391 comp_conf = e_comp_config_get();
392 if (comp_conf && comp_conf->input_log_enable)
394 ELOGF("DEVMGR", "Mouse Up (id: %d, button: %d, x: %d, y: %d), res: %d", NULL,
395 ev->multi.device, ev->buttons, ev->x, ev->y, res);
402 _e_devicemgr_input_cb_mouse_wheel(void *data, int type, void *event)
404 Ecore_Event_Mouse_Wheel *ev;
406 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
407 E_Comp_Config *comp_conf;
409 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
410 ev = (Ecore_Event_Mouse_Wheel *)event;
412 if (!ev->dev) return ECORE_CALLBACK_PASS_ON;
414 if (!e_devicemgr_detent_is_detent(ecore_device_name_get(ev->dev)))
415 return ECORE_CALLBACK_PASS_ON;
418 comp_conf = e_comp_config_get();
419 if (comp_conf && comp_conf->e_wheel_click_angle)
421 detent = (int)(detent / comp_conf->e_wheel_click_angle);
424 if (detent == 1 || detent == -1)
426 detent = detent * (-1);
427 if (!e_devicemgr_intercept_hook_call(E_DEVICEMGR_INTERCEPT_HOOK_DETENT, &detent))
429 DMDBG("Stop propagate detent event. value: %d\n", detent);
430 return ECORE_CALLBACK_DONE;
432 e_devicemgr_wl_detent_send_event(detent);
435 return ECORE_CALLBACK_DONE;
440 _e_devicemgr_input_cb_device_add(void *data, int type, void *event)
442 Ecore_Event_Device_Info *ev;
444 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
445 ev = (Ecore_Event_Device_Info *)event;
447 _e_devicemgr_input_device_add(ev->name, ev->identifier, ev->seatname, ev->clas, ev->subclas);
449 return ECORE_CALLBACK_PASS_ON;
453 _e_devicemgr_input_cb_device_del(void *data, int type, void *event)
455 Ecore_Event_Device_Info *ev;
457 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
458 ev = (Ecore_Event_Device_Info *)event;
460 _e_devicemgr_input_device_del(ev->name, ev->identifier, ev->seatname, ev->clas, ev->subclas);
462 return ECORE_CALLBACK_PASS_ON;
466 _e_devicemgr_input_cb_device_update(void *data, int type, void *event)
468 Ecore_Event_Device_Update *ev;
470 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
472 ev = (Ecore_Event_Device_Update *)event;
473 EINA_SAFETY_ON_NULL_RETURN_VAL(ev->dev, ECORE_CALLBACK_PASS_ON);
475 _e_devicemgr_input_device_update(ev->dev);
477 return ECORE_CALLBACK_PASS_ON;
481 e_devicemgr_input_init(void)
483 e_devicemgr->virtual_mouse_device_fd = -1;
484 e_devicemgr->virtual_key_device_fd = -1;
486 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_devicemgr_input_cb_mouse_button_down, NULL);
487 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_BUTTON_UP, _e_devicemgr_input_cb_mouse_button_up, NULL);
488 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_WHEEL, _e_devicemgr_input_cb_mouse_wheel, NULL);
489 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_ADD, _e_devicemgr_input_cb_device_add, NULL);
490 E_LIST_HANDLER_APPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_DEL, _e_devicemgr_input_cb_device_del, NULL);
491 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_SUBCLASS_UPDATE, _e_devicemgr_input_cb_device_update, NULL);
493 if (e_devicemgr->dconfig->conf->input.virtual_key_device_enable)
495 e_devicemgr->virtual_key_device_fd = e_devicemgr_create_virtual_device(ECORE_DEVICE_CLASS_KEYBOARD, "Virtual Key Device");
497 if (e_devicemgr->virtual_key_device_fd >= 0)
498 DMINF("input.virtual_key_device_enable: device fd : %d\n", e_devicemgr->virtual_key_device_fd);
500 DMWRN("input.virtual_key_device_enable: but failed to create device !\n");
503 if (e_devicemgr->dconfig->conf->input.virtual_mouse_device_enable)
505 e_devicemgr->virtual_mouse_device_fd = e_devicemgr_create_virtual_device(ECORE_DEVICE_CLASS_MOUSE, "Virtual Mouse Device");
507 if (e_devicemgr->virtual_mouse_device_fd >= 0)
508 DMINF("input.virtual_mouse_device_enable: device fd : %d\n", e_devicemgr->virtual_mouse_device_fd);
510 DMWRN("input.virtual_mouse_device_enable: but failed to create device !\n");
513 e_devicemgr->max_touch_count = 0;
519 e_devicemgr_input_shutdown(void)
521 Ecore_Event_Handler *h = NULL;
523 EINA_LIST_FREE(e_devicemgr->handlers, h)
524 ecore_event_handler_del(h);
526 if (e_devicemgr->virtual_key_device_fd)
528 e_devicemgr_destroy_virtual_device(e_devicemgr->virtual_key_device_fd);
529 e_devicemgr->virtual_key_device_fd = -1;
531 if (e_devicemgr->virtual_mouse_device_fd)
533 e_devicemgr_destroy_virtual_device(e_devicemgr->virtual_mouse_device_fd);
534 e_devicemgr->virtual_mouse_device_fd = -1;
537 if (e_devicemgr->multi)
538 free(e_devicemgr->multi);