e_input_evdev: adjust event coord. according to the associated output 89/272189/1
authorduna.oh <duna.oh@samsung.com>
Thu, 10 Mar 2022 11:52:59 +0000 (20:52 +0900)
committerduna.oh <duna.oh@samsung.com>
Fri, 11 Mar 2022 02:10:03 +0000 (11:10 +0900)
Change-Id: I50db5155a9512aea6d33338710ad77d1a03f4e5e

src/bin/e_input_evdev.c
src/bin/e_input_private.h

index 9f76fc4..27ea2d7 100644 (file)
@@ -2,6 +2,7 @@
 #include "e_input_private.h"
 
 static void  _device_modifiers_update(E_Input_Evdev *edev);
+static void  _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
 
 void
 _device_calibration_set(E_Input_Evdev *edev)
@@ -9,6 +10,15 @@ _device_calibration_set(E_Input_Evdev *edev)
    E_Output *output;
    int w = 0, h = 0;
    int temp;
+   const char *output_name;
+
+   output_name = libinput_device_get_output_name(edev->device);
+   if (output_name)
+     {
+        E_FREE(edev->output_name);
+        edev->output_name = strdup(output_name);
+        ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
+     }
 
    output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
    e_output_size_get(output, &w, &h);
@@ -1357,10 +1367,41 @@ _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touc
 }
 
 static void
+_device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
+{
+   E_Output *output = NULL;
+
+   EINA_SAFETY_ON_NULL_RETURN(edev);
+
+   if (!edev->output_configured)
+     {
+        if (edev->output_name)
+          {
+             output = e_output_find(edev->output_name);
+             if (output)
+               {
+                  edev->mouse.minx = output->config.geom.x;
+                  edev->mouse.miny = output->config.geom.y;
+                  edev->mouse.maxw = output->config.geom.w;
+                  edev->mouse.maxh = output->config.geom.h;
+               }
+          }
+
+          edev->output_configured = EINA_TRUE;
+          ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
+                NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
+     }
+   if (x) *x = edev->mouse.minx;
+   if (y) *y = edev->mouse.miny;
+   if (w) *w = edev->mouse.maxw;
+   if (h) *h = edev->mouse.maxh;
+}
+
+static void
 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
 {
    E_Input_Evdev *edev;
-   int w = 0, h = 0;
+   int x = 0, y = 0, w = 0, h = 0;
    E_Comp_Config *comp_conf = NULL;
 
    if (!(edev = libinput_device_get_user_data(device)))
@@ -1368,12 +1409,12 @@ _device_handle_touch_down(struct libinput_device *device, struct libinput_event_
         return;
      }
 
-   e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
+   _device_configured_size_get(edev, &x, &y, &w, &h);
 
    edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
-     libinput_event_touch_get_x_transformed(event, w);
+     x + libinput_event_touch_get_x_transformed(event, w);
    edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
-     libinput_event_touch_get_y_transformed(event, h);
+     y + libinput_event_touch_get_y_transformed(event, h);
 
    edev->mt_slot = libinput_event_touch_get_slot(event);
    if (edev->mt_slot < 0)
@@ -1420,19 +1461,19 @@ static void
 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
 {
    E_Input_Evdev *edev;
-   int w = 0, h = 0;
+   int x = 0, y = 0, w = 0, h = 0;
 
    if (!(edev = libinput_device_get_user_data(device)))
      {
         return;
      }
 
-   e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
+   _device_configured_size_get(edev, &x, &y, &w, &h);
 
    edev->mouse.dx = edev->seat->ptr.dx =
-     libinput_event_touch_get_x_transformed(event, w);
+     x + libinput_event_touch_get_x_transformed(event, w);
    edev->mouse.dy = edev->seat->ptr.dy =
-     libinput_event_touch_get_y_transformed(event, h);
+     y + libinput_event_touch_get_y_transformed(event, h);
 
    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
@@ -1753,6 +1794,7 @@ _e_input_evdev_device_destroy(E_Input_Evdev *edev)
         free(edev->touch.coords);
         edev->touch.coords = NULL;
      }
+   E_FREE(edev->output_name);
 
    free(edev);
 }
index 9e0192b..1ade6cf 100644 (file)
@@ -122,6 +122,9 @@ struct _E_Input_Evdev
         unsigned int raw_pressed;
         Eina_Bool blocked;
      } touch;
+
+   char *output_name;
+   Eina_Bool output_configured;
 };
 
 void _input_events_process(E_Input_Backend *input);