1 #include "e_devicemgr_private.h"
4 e_devicemgr_strcmp(const char *dst, const char *src)
6 int dst_len, src_len, str_len;
11 if (src_len > dst_len) str_len = src_len;
12 else str_len = dst_len;
14 if (!strncmp(dst, src, str_len))
21 _e_devicemgr_input_pointer_warp(int x, int y)
23 e_input_device_pointer_warp(NULL, x, y);
24 DMDBG("The pointer warped to (%d, %d) !\n", x, y);
26 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
30 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)
34 int new_x, new_y, ret;
35 int i, min_x, min_y, max_x, max_y, tmp_x, tmp_y;
37 if (!(ec = wl_resource_get_user_data(surface)) || !ec->visible)
39 DMDBG("The given surface is invalid or invisible !\n");
40 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
43 if (ec != e_comp_wl->ptr.ec)
45 DMDBG("Pointer is not on the given surface !\n");
46 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
49 if (e_pointer_is_hidden(e_comp->pointer))
51 DMDBG("Pointer is hidden");
52 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_POINTER_AVAILABLE;
55 new_x = wl_fixed_to_int(x);
56 new_y = wl_fixed_to_int(y);
58 if (new_x < 0) new_x = 0;
59 if ((ec->w != 0) && (new_x > ec->w - 1)) new_x = ec->w - 1;
61 if (new_y < 0) new_y = 0;
62 if ((ec->h != 0) && (new_y > ec->h - 1)) new_y = ec->h - 1;
64 if (evas_object_map_enable_get(ec->frame))
66 e_comp_wl_map_inv_coord_get(ec, new_x, new_y, &new_x, &new_y);
68 map = e_client_map_get(ec);
69 e_map_point_coord_get(map, 0, &min_x, &min_y, NULL);
73 for (i = 1; i < e_map_count_get(map); i++)
75 e_map_point_coord_get(map, i, &tmp_x, &tmp_y, NULL);
77 if (tmp_x < min_x) min_x = tmp_x;
78 else if (tmp_x > max_x) max_x = tmp_x;
80 if (tmp_y < min_y) min_y = tmp_y;
81 else if (tmp_y > max_y) max_y = tmp_y;
86 if (new_x < min_x) new_x = min_x;
87 if (new_x > max_x - 1) new_x = max_x - 1;
91 if (new_y < min_y) new_y = min_y;
92 if (new_y > max_y - 1) new_y = max_y - 1;
96 ret = _e_devicemgr_input_pointer_warp(ec->client.x + new_x, ec->client.y + new_y);
101 e_devicemgr_detent_is_detent(const char *name)
103 EINA_SAFETY_ON_NULL_RETURN_VAL(name, EINA_FALSE);
105 if (!strncmp(name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
112 _e_devicemgr_detent_set_info(E_Devicemgr_Input_Device *dev)
114 if (dev->name && !strncmp(dev->name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
116 E_FREE(e_devicemgr->detent.identifier);
117 if (dev->identifier) e_devicemgr->detent.identifier = strdup(dev->identifier);
122 _e_devicemgr_detent_unset_info(E_Devicemgr_Input_Device *dev)
124 if (dev->name && !strncmp(dev->name, DETENT_DEVICE_NAME, sizeof(DETENT_DEVICE_NAME)))
126 E_FREE(e_devicemgr->detent.identifier);
131 _e_devicemgr_input_keyevent_free(void *data EINA_UNUSED, void *ev)
133 Ecore_Event_Key *e = ev;
135 eina_stringshare_del(e->keyname);
136 eina_stringshare_del(e->key);
137 eina_stringshare_del(e->compose);
144 _e_devicemgr_input_mouse_button_remap(Ecore_Event_Mouse_Button *ev, Eina_Bool pressed)
146 Ecore_Event_Key *ev_key;
147 E_Keyrouter_Event_Data *key_data;
149 EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl->xkb.keymap, ECORE_CALLBACK_PASS_ON);
150 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, ECORE_CALLBACK_PASS_ON);
152 if (ev->buttons != 3) return ECORE_CALLBACK_PASS_ON;
154 ev_key = E_NEW(Ecore_Event_Key, 1);
155 EINA_SAFETY_ON_NULL_RETURN_VAL(ev_key, ECORE_CALLBACK_PASS_ON);
157 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
158 EINA_SAFETY_ON_NULL_GOTO(key_data, failed);
160 ev_key->key = (char *)eina_stringshare_add("XF86Back");
161 ev_key->keyname = (char *)eina_stringshare_add(ev_key->key);
162 ev_key->compose = (char *)eina_stringshare_add(ev_key->key);
163 ev_key->timestamp = (int)(ecore_time_get()*1000);
164 ev_key->same_screen = 1;
166 ev_key->window = e_comp->ee_win;
167 ev_key->event_window = e_comp->ee_win;
168 ev_key->root_window = e_comp->ee_win;
169 ev_key->keycode = e_devicemgr->dconfig->conf->input.back_keycode;
170 ev_key->data = key_data;
173 ecore_event_add(ECORE_EVENT_KEY_DOWN, ev_key, _e_devicemgr_input_keyevent_free, NULL);
175 ecore_event_add(ECORE_EVENT_KEY_UP, ev_key, _e_devicemgr_input_keyevent_free, NULL);
177 return ECORE_CALLBACK_DONE;
181 return ECORE_CALLBACK_PASS_ON;
185 _e_devicemgr_input_device_add(const char *name, const char *identifier, const char *seatname, Ecore_Device_Class clas, Ecore_Device_Subclass subclas)
187 E_Devicemgr_Input_Device *dev = NULL;
189 int current_touch_count = -1;
191 EINA_SAFETY_ON_NULL_RETURN(name);
192 EINA_SAFETY_ON_NULL_RETURN(identifier);
194 EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
196 if (!dev->name) continue;
197 if (!dev->identifier) continue;
198 if ((dev->clas == clas) && (dev->subclas == subclas) &&
199 (!strcmp(dev->name, name)) &&
200 (!strcmp(dev->identifier, identifier)))
206 if (!(dev = E_NEW(E_Devicemgr_Input_Device, 1))) return;
207 dev->name = eina_stringshare_add(name);
208 dev->identifier = eina_stringshare_add(identifier);
209 dev->seat_name = eina_stringshare_add(seatname);
211 dev->subclas = subclas;
213 e_devicemgr->device_list = eina_list_append(e_devicemgr->device_list, dev);
215 if (dev->clas == ECORE_DEVICE_CLASS_MOUSE)
216 e_devicemgr->last_device_ptr = dev;
218 if (dev->clas == ECORE_DEVICE_CLASS_TOUCH)
220 if (!e_devicemgr->last_device_touch)
221 e_devicemgr->last_device_touch = dev;
223 current_touch_count = e_input_touch_max_count_get();
224 if (e_devicemgr->max_touch_count < current_touch_count)
226 e_devicemgr->max_touch_count = current_touch_count;
227 if (e_devicemgr->multi)
229 ELOGF("DEVMGR_TOUCH", "Multi pointer is NOT NULL. It'll be updated to %d finger of touch.\n", NULL, current_touch_count);
230 free (e_devicemgr->multi);
233 e_devicemgr->multi = calloc(1, sizeof(E_Devicemgr_Input_Device_Multi)*current_touch_count);
235 if (!e_devicemgr->multi)
236 ELOGF("DEVMGR_TOUCH", "Failed to allocate memory for multi ptr. (finger=%d)\n", NULL, current_touch_count);
238 e_devicemgr_wl_touch_max_count_send(e_devicemgr->max_touch_count, NULL, NULL);
242 if (!e_devicemgr->last_device_kbd && dev->clas == ECORE_DEVICE_CLASS_KEYBOARD)
243 e_devicemgr->last_device_kbd = dev;
245 e_devicemgr_wl_device_add(dev);
246 e_devicemgr_inputgen_get_device_info(dev);
247 _e_devicemgr_detent_set_info(dev);
251 _e_devicemgr_input_device_del(const char *name, const char *identifier, const char *seatname, Ecore_Device_Class clas, Ecore_Device_Subclass subclas)
253 E_Devicemgr_Input_Device *dev = NULL;
256 EINA_SAFETY_ON_NULL_RETURN(name);
257 EINA_SAFETY_ON_NULL_RETURN(identifier);
259 EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
261 if (!dev->name) continue;
262 if (!dev->identifier) continue;
263 if ((dev->clas == clas) && (dev->subclas == subclas) &&
264 (!strcmp(dev->name, name)) &&
265 (!strcmp(dev->identifier, identifier)))
273 _e_devicemgr_detent_unset_info(dev);
274 e_devicemgr_wl_device_del(dev);
276 if (dev->name) eina_stringshare_del(dev->name);
277 if (dev->identifier) eina_stringshare_del(dev->identifier);
278 if (dev->seat_name) eina_stringshare_del(dev->seat_name);
280 e_devicemgr->device_list = eina_list_remove(e_devicemgr->device_list, dev);
282 if (e_devicemgr->last_device_ptr == dev)
283 e_devicemgr->last_device_ptr = NULL;
285 if (e_devicemgr->last_device_touch == dev)
286 e_devicemgr->last_device_touch = NULL;
288 if (e_devicemgr->last_device_kbd == dev)
289 e_devicemgr->last_device_kbd = NULL;
295 _e_devicemgr_input_device_update(Ecore_Device *dev)
298 E_Devicemgr_Input_Device *data;
299 char *dev_identifier;
301 EINA_SAFETY_ON_NULL_RETURN(dev);
303 dev_identifier = (char *)ecore_device_identifier_get(dev);
304 EINA_SAFETY_ON_NULL_RETURN(dev_identifier);
306 EINA_LIST_FOREACH(e_devicemgr->device_list, l, data)
308 if (data->clas == ecore_device_class_get(dev) && data->identifier)
310 if (e_devicemgr_strcmp(dev_identifier, data->identifier))
312 data->subclas = ecore_device_subclass_get(dev);
314 e_devicemgr_wl_device_update(data);
322 _e_devicemgr_input_cb_mouse_button_down(void *data, int type, void *event)
324 Ecore_Event_Mouse_Button *ev;
325 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
326 E_Comp_Config *comp_conf = NULL;
328 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
329 ev = (Ecore_Event_Mouse_Button *)event;
331 if (e_devicemgr->dconfig->conf->input.button_remap_enable)
332 res = _e_devicemgr_input_mouse_button_remap(ev, EINA_TRUE);
334 comp_conf = e_comp_config_get();
335 if (comp_conf && comp_conf->input_log_enable)
337 ELOGF("DEVMGR", "Mouse Down (id: %d, button: %d, x: %d, y: %d), res: %d", NULL,
338 ev->multi.device, ev->buttons, ev->x, ev->y, res);
345 _e_devicemgr_input_cb_mouse_button_up(void *data, int type, void *event)
347 Ecore_Event_Mouse_Button *ev;
348 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
349 E_Comp_Config *comp_conf = NULL;
351 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
352 ev = (Ecore_Event_Mouse_Button *)event;
354 if (e_devicemgr->dconfig->conf->input.button_remap_enable)
355 res = _e_devicemgr_input_mouse_button_remap(ev, EINA_FALSE);
357 comp_conf = e_comp_config_get();
358 if (comp_conf && comp_conf->input_log_enable)
360 ELOGF("DEVMGR", "Mouse Up (id: %d, button: %d, x: %d, y: %d), res: %d", NULL,
361 ev->multi.device, ev->buttons, ev->x, ev->y, res);
368 _e_devicemgr_input_cb_mouse_wheel(void *data, int type, void *event)
370 Ecore_Event_Mouse_Wheel *ev;
372 Eina_Bool res = ECORE_CALLBACK_PASS_ON;
373 E_Comp_Config *comp_conf;
375 EINA_SAFETY_ON_NULL_RETURN_VAL(event, res);
376 ev = (Ecore_Event_Mouse_Wheel *)event;
378 if (!ev->dev) return ECORE_CALLBACK_PASS_ON;
380 if (!e_devicemgr_detent_is_detent(ecore_device_name_get(ev->dev)))
381 return ECORE_CALLBACK_PASS_ON;
384 comp_conf = e_comp_config_get();
385 if (comp_conf && comp_conf->e_wheel_click_angle)
387 detent = (int)(detent / comp_conf->e_wheel_click_angle);
390 if (detent == 1 || detent == -1)
392 detent = detent * (-1);
393 if (!e_devicemgr_intercept_hook_call(E_DEVICEMGR_INTERCEPT_HOOK_DETENT, &detent))
395 DMDBG("Stop propagate detent event. value: %d\n", detent);
396 return ECORE_CALLBACK_DONE;
398 e_devicemgr_wl_detent_send_event(detent);
401 return ECORE_CALLBACK_DONE;
406 _e_devicemgr_input_cb_device_add(void *data, int type, void *event)
408 Ecore_Event_Device_Info *ev;
410 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
411 ev = (Ecore_Event_Device_Info *)event;
413 _e_devicemgr_input_device_add(ev->name, ev->identifier, ev->seatname, ev->clas, ev->subclas);
415 return ECORE_CALLBACK_PASS_ON;
419 _e_devicemgr_input_cb_device_del(void *data, int type, void *event)
421 Ecore_Event_Device_Info *ev;
423 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
424 ev = (Ecore_Event_Device_Info *)event;
426 _e_devicemgr_input_device_del(ev->name, ev->identifier, ev->seatname, ev->clas, ev->subclas);
428 return ECORE_CALLBACK_PASS_ON;
432 _e_devicemgr_input_cb_device_update(void *data, int type, void *event)
434 Ecore_Event_Device_Update *ev;
436 EINA_SAFETY_ON_NULL_RETURN_VAL(event, ECORE_CALLBACK_PASS_ON);
438 ev = (Ecore_Event_Device_Update *)event;
439 EINA_SAFETY_ON_NULL_RETURN_VAL(ev->dev, ECORE_CALLBACK_PASS_ON);
441 _e_devicemgr_input_device_update(ev->dev);
443 return ECORE_CALLBACK_PASS_ON;
447 e_devicemgr_input_init(void)
449 e_devicemgr->virtual_mouse_device_fd = -1;
450 e_devicemgr->virtual_key_device_fd = -1;
452 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_devicemgr_input_cb_mouse_button_down, NULL);
453 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_BUTTON_UP, _e_devicemgr_input_cb_mouse_button_up, NULL);
454 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_MOUSE_WHEEL, _e_devicemgr_input_cb_mouse_wheel, NULL);
455 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_ADD, _e_devicemgr_input_cb_device_add, NULL);
456 E_LIST_HANDLER_APPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_DEL, _e_devicemgr_input_cb_device_del, NULL);
457 E_LIST_HANDLER_PREPEND(e_devicemgr->handlers, ECORE_EVENT_DEVICE_SUBCLASS_UPDATE, _e_devicemgr_input_cb_device_update, NULL);
459 if (e_devicemgr->dconfig->conf->input.virtual_key_device_enable)
461 e_devicemgr->virtual_key_device_fd = e_devicemgr_create_virtual_device(ECORE_DEVICE_CLASS_KEYBOARD, "Virtual Key Device");
463 if (e_devicemgr->virtual_key_device_fd >= 0)
464 DMINF("input.virtual_key_device_enable: device fd : %d\n", e_devicemgr->virtual_key_device_fd);
466 DMWRN("input.virtual_key_device_enable: but failed to create device !\n");
469 if (e_devicemgr->dconfig->conf->input.virtual_mouse_device_enable)
471 e_devicemgr->virtual_mouse_device_fd = e_devicemgr_create_virtual_device(ECORE_DEVICE_CLASS_MOUSE, "Virtual Mouse Device");
473 if (e_devicemgr->virtual_mouse_device_fd >= 0)
474 DMINF("input.virtual_mouse_device_enable: device fd : %d\n", e_devicemgr->virtual_mouse_device_fd);
476 DMWRN("input.virtual_mouse_device_enable: but failed to create device !\n");
479 e_devicemgr->max_touch_count = 0;
485 e_devicemgr_input_shutdown(void)
487 Ecore_Event_Handler *h = NULL;
489 EINA_LIST_FREE(e_devicemgr->handlers, h)
490 ecore_event_handler_del(h);
492 if (e_devicemgr->virtual_key_device_fd)
494 e_devicemgr_destroy_virtual_device(e_devicemgr->virtual_key_device_fd);
495 e_devicemgr->virtual_key_device_fd = -1;
497 if (e_devicemgr->virtual_mouse_device_fd)
499 e_devicemgr_destroy_virtual_device(e_devicemgr->virtual_mouse_device_fd);
500 e_devicemgr->virtual_mouse_device_fd = -1;
503 if (e_devicemgr->multi)
504 free(e_devicemgr->multi);