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 6bcabd7..1386b92 100644 (file)
@@ -1,13 +1,14 @@
-#include "e.h"
 #include "e_input_intern.h"
-#include "e_input_private.h"
-#include "e_device_intern.h"
-#include "e_keyrouter_private.h"
+#include "e_input_log.h"
 #include "e_input_event.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)
 
@@ -66,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
@@ -188,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
@@ -216,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;
@@ -288,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
@@ -341,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 =
@@ -352,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)
@@ -702,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];
 
@@ -732,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),
@@ -742,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)))
@@ -2374,13 +2349,9 @@ _e_input_evdev_device_destroy(E_Input_Evdev *edev)
 
    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);
@@ -2499,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));
@@ -2513,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 *