e_input: Do not devide translation components by output's w/h of a matrix
[platform/upstream/enlightenment.git] / src / bin / e_input_evdev.c
index 5cd53f4..1386b92 100644 (file)
@@ -1,11 +1,14 @@
-#include "e.h"
-#include "e_input_private.h"
-#include "e_device.h"
-#include "e_keyrouter_private.h"
+#include "e_input_intern.h"
+#include "e_input_log.h"
 #include "e_input_event.h"
-#include "e_devicemgr.h"
+#include "e_keyrouter_intern.h"
+#include "e_devicemgr_intern.h"
+#include "e_device_intern.h"
+#include "e_comp_screen_intern.h"
+#include "e_output_intern.h"
 
 #include <glib.h>
+#include <ctype.h>
 
 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
 
@@ -40,7 +43,7 @@ _device_calibration_set(E_Input_Evdev *edev)
         edev->mouse.maxw = w;
         edev->mouse.maxh = h;
 
-        if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
+        if (edev->caps & E_INPUT_SEAT_POINTER)
           {
              edev->seat->ptr.dx = (double)(w / 2);
              edev->seat->ptr.dy = (double)(h / 2);
@@ -64,45 +67,42 @@ _device_calibration_set(E_Input_Evdev *edev)
 
 //LCOV_EXCL_START
 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
-   const char *sysname;
    float cal[6];
-   const char *device;
-   Eina_List *devices;
 
    if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
        (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
      return;
 
-   sysname = libinput_device_get_sysname(edev->device);
-
-   devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
-   if (eina_list_count(devices) < 1) return;
-
 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
    const char *vals;
    enum libinput_config_status status;
+   struct udev_device *udev_device = NULL;
 
-   EINA_LIST_FREE(devices, device)
+   udev_device = libinput_device_get_udev_device(edev->device);
+   if (!udev_device)
      {
-        vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
-        if ((!vals) ||
-            (sscanf(vals, "%f %f %f %f %f %f",
-                    &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
-          goto cont;
+        ERR("no udev_device");
+        return;
+     }
 
-        cal[2] /= w;
-        cal[5] /= h;
+   vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
+   if ((!vals) ||
+       (sscanf(vals, "%f %f %f %f %f %f",
+               &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
+     {
+        udev_device_unref(udev_device);
+        return;
+     }
+   udev_device_unref(udev_device);
 
-        status =
-          libinput_device_config_calibration_set_matrix(edev->device, cal);
+   ELOGF("E_INPUT_EVDEV", "calibration_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
+         NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
 
-        if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
-          ERR("Failed to apply calibration");
+   status =
+     libinput_device_config_calibration_set_matrix(edev->device, cal);
 
-cont:
-        eina_stringshare_del(device);
-        continue;
-     }
+   if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
+     ERR("Failed to apply calibration");
 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
 //LCOV_EXCL_STOP
@@ -186,8 +186,7 @@ _device_touch_count_update(E_Input_Evdev *edev)
           }
      }
 
-   ei->touch_device_count++;
-   ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
+   ELOGF("E_INPUT_EVDEV_TOUCH", "Touch max count is %d.\n", NULL, ei->touch_max_count);
 }
 
 static void
@@ -214,31 +213,21 @@ _device_keyboard_setup(E_Input_Evdev *edev)
    if (!(input = edev->seat->input)) return;
    if (!input->dev->xkb_ctx) return;
 
-   g_mutex_init(&edev->xkb.keymap_mutex);
-
    /* create keymap from xkb context */
-   g_mutex_lock(&edev->xkb.keymap_mutex);
    edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
    if (!edev->xkb.keymap)
      {
-        g_mutex_unlock(&edev->xkb.keymap_mutex);
         ERR("Failed to create keymap: %m");
         return;
      }
 
-   g_mutex_lock(&edev->xkb.state_mutex);
-
    /* create xkb state */
    if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
      {
-        g_mutex_unlock(&edev->xkb.state_mutex);
-        g_mutex_unlock(&edev->xkb.keymap_mutex);
         ERR("Failed to create xkb state: %m");
         return;
      }
 
-   g_mutex_unlock(&edev->xkb.state_mutex);
-
    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
    if (xkb_idx != XKB_MOD_INVALID)
      edev->xkb.ctrl_mask = 1 << xkb_idx;
@@ -286,8 +275,6 @@ _device_keyboard_setup(E_Input_Evdev *edev)
      edev->xkb.altgr_mask = 1 << xkb_idx;
    else
      edev->xkb.altgr_mask = 0;
-
-   g_mutex_unlock(&edev->xkb.keymap_mutex);
 }
 
 static int
@@ -339,8 +326,6 @@ _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
 {
    xkb_mod_mask_t mask;
 
-   g_mutex_lock(&from->xkb.state_mutex);
-
    edev->xkb.depressed =
      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
    edev->xkb.latched =
@@ -350,8 +335,6 @@ _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
    edev->xkb.group =
      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
 
-   g_mutex_unlock(&from->xkb.state_mutex);
-
    mask = (edev->xkb.depressed | edev->xkb.latched);
 
    if (mask & from->xkb.ctrl_mask)
@@ -700,13 +683,11 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar
           }
      }
 
-   g_mutex_lock(&edev->xkb.state_mutex);
    xkb_state_update_key(edev->xkb.state, code,
                         (state ? XKB_KEY_DOWN : XKB_KEY_UP));
 
    /* get the keysym for this code */
    nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
-   g_mutex_unlock(&edev->xkb.state_mutex);
 
    if (nsyms == 1) sym = syms[0];
 
@@ -730,8 +711,6 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar
      }
 
    /* if shift is active, we need to transform the key to lower */
-   g_mutex_lock(&edev->xkb.keymap_mutex);
-   g_mutex_lock(&edev->xkb.state_mutex);
    if (xkb_state_mod_index_is_active(edev->xkb.state,
                                      xkb_map_mod_get_index(edev->xkb.keymap,
                                      XKB_MOD_NAME_SHIFT),
@@ -740,8 +719,6 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar
         if (keyname[0] != '\0')
           keyname[0] = tolower(keyname[0]);
      }
-   g_mutex_unlock(&edev->xkb.keymap_mutex);
-   g_mutex_unlock(&edev->xkb.state_mutex);
 
    if (_device_keysym_translate(sym, edev->xkb.modifiers,
                                 compose_buffer, sizeof(compose_buffer)))
@@ -801,8 +778,8 @@ _device_handle_key(struct libinput_device *device, struct libinput_event_keyboar
 
    if (e_config->key_input_ttrace_enable)
      {
-        TRACE_INPUT_BEGIN(ECORE_EVENT_KEY:%s:%s:%u:%lld, state ? "PRESS" : "RELEASE", e->keyname, timestamp, libinput_event_keyboard_get_time_usec(event));
-        ELOGF("INPUT", "ECORE_EVENT_KEY:%s:%s:%u:%lld|B|", NULL, state ? "PRESS" : "RELEASE", e->keyname, timestamp, libinput_event_keyboard_get_time_usec(event));
+        TRACE_INPUT_BEGIN(ECORE_EVENT_KEY:%s:%s:%u:%lld, state ? "PRESS" : "RELEASE", e->keyname, timestamp, (long long unsigned int)libinput_event_keyboard_get_time_usec(event));
+        ELOGF("INPUT", "ECORE_EVENT_KEY:%s:%s:%u:%lld|B|", NULL, state ? "PRESS" : "RELEASE", e->keyname, timestamp, (long long unsigned int)libinput_event_keyboard_get_time_usec(event));
      }
 
    _e_input_key_event_list_add(e);
@@ -1000,7 +977,7 @@ _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_point
 
    comp_conf = e_comp_config_get();
    if (comp_conf && comp_conf->input_log_enable)
-     ELOGF("Mouse", "Relative Move (dx: %d, dy: %d, unaccel(%d, %d) device: %s)", NULL, ev->dx, ev->dx, ev->dx_unaccel, ev->dy_unaccel, ecore_device_name_get(ev->dev));
+     ELOGF("Mouse", "Relative Move (time: %d, dx: %d, dy: %d, unaccel(%d, %d) device: %s)", NULL, ev->timestamp, ev->dx, ev->dy, ev->dx_unaccel, ev->dy_unaccel, ecore_device_name_get(ev->dev));
 
    ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
 
@@ -1956,7 +1933,7 @@ _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
                   edev->mouse.miny = output->config.geom.y;
                   edev->mouse.maxw = output->config.geom.w;
                   edev->mouse.maxh = output->config.geom.h;
-                  if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
+                  if (edev->caps & E_INPUT_SEAT_POINTER)
                     {
                        edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
                        edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
@@ -2296,8 +2273,6 @@ _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
 
-   E_Input *e_input = e_input_get();
-
    /* try to allocate space for new evdev */
    if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
 
@@ -2305,9 +2280,6 @@ _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
    edev->device = device;
    edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
 
-   if (e_input)
-     g_rec_mutex_lock(&e_input->libinput_mutex);
-
    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
      {
         edev->caps |= E_INPUT_SEAT_KEYBOARD;
@@ -2364,9 +2336,6 @@ _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
    /* configure device */
    _device_configure(edev);
 
-   if (e_input)
-     g_rec_mutex_unlock(&e_input->libinput_mutex);
-
    return edev;
 }
 
@@ -2374,21 +2343,15 @@ void
 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
 {
    Ecore_Device *dev;
-   E_Input *e_input = e_input_get();
-
    EINA_SAFETY_ON_NULL_RETURN(edev);
 
    ecore_thread_main_loop_begin();
 
    if (edev->caps & E_INPUT_SEAT_KEYBOARD)
      {
-        g_mutex_lock(&edev->xkb.state_mutex);
         if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
-        g_mutex_unlock(&edev->xkb.state_mutex);
 
-        g_mutex_lock(&edev->xkb.keymap_mutex);
         if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
-        g_mutex_unlock(&edev->xkb.keymap_mutex);
      }
 
    if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
@@ -2412,9 +2375,7 @@ _e_input_evdev_device_destroy(E_Input_Evdev *edev)
           }
      }
    if (edev->path) eina_stringshare_del(edev->path);
-   if (e_input) g_rec_mutex_lock(&e_input->libinput_mutex);
    if (edev->device) libinput_device_unref(edev->device);
-   if (e_input) g_rec_mutex_unlock(&e_input->libinput_mutex);
    if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
    if (edev->touch.coords)
      {
@@ -2509,12 +2470,10 @@ _e_input_evdev_event_process(struct libinput_event *event)
 EINTERN void
 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
 {
-   const char *sysname;
    float cal[6];
-   const char *device;
-   Eina_List *devices;
    const char *vals;
    enum libinput_config_status status;
+   struct udev_device *udev_device = NULL;
 
    EINA_SAFETY_ON_NULL_RETURN(edev);
    EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
@@ -2523,32 +2482,34 @@ e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
        (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
      return;
 
-   sysname = libinput_device_get_sysname(edev->device);
-
-   devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
-   if (eina_list_count(devices) < 1) return;
+   udev_device = libinput_device_get_udev_device(edev->device);
+   if (!udev_device)
+     {
+        ERR("no udev_device");
+        return;
+     }
 
-   EINA_LIST_FREE(devices, device)
+   vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
+   if ((!vals) ||
+       (sscanf(vals, "%f %f %f %f %f %f",
+               &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
      {
-        vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
-       if ((!vals) ||
-            (sscanf(vals, "%f %f %f %f %f %f",
-                    &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
-          goto cont;
+        udev_device_unref(udev_device);
+        return;
+     }
+   udev_device_unref(udev_device);
 
-        cal[2] /= w;
-        cal[5] /= h;
+   ELOGF("E_INPUT_EVDEV", "axis_size_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
+         NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
 
-        status =
-          libinput_device_config_calibration_set_matrix(edev->device, cal);
+   cal[2] /= w;
+   cal[5] /= h;
 
-        if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
-          ERR("Failed to apply calibration");
+   status =
+     libinput_device_config_calibration_set_matrix(edev->device, cal);
 
-cont:
-        eina_stringshare_del(device);
-        continue;
-     }
+   if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
+     ERR("Failed to apply calibration");
 }
 
 EINTERN const char *
@@ -2700,7 +2661,6 @@ e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
 {
    Eina_Bool res = EINA_FALSE;
    E_Input_Backend *input;
-   E_Input *e_input = e_input_get();
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
@@ -2711,22 +2671,13 @@ e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
         input = evdev->seat->input;
         if (!input) return EINA_FALSE;
 
-        if (e_input)
-          g_rec_mutex_lock(&e_input->libinput_mutex);
-
         if (libinput_dispatch(input->libinput) != 0)
           {
              ERR("Failed to dispatch libinput events: %m");
 
-             if (e_input)
-               g_rec_mutex_unlock(&e_input->libinput_mutex);
-
              return EINA_FALSE;
           }
 
-        if (e_input)
-          g_rec_mutex_unlock(&e_input->libinput_mutex);
-
         /* process pending events */
         _input_events_process(input);
         res = EINA_TRUE;