e_pointer: apply map to cursor with the cursor configured output resolution 30/293730/1
authorChangyeon Lee <cyeon.lee@samsung.com>
Fri, 2 Jun 2023 02:38:43 +0000 (11:38 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Fri, 2 Jun 2023 07:10:40 +0000 (16:10 +0900)
if the output resolution and the cursor configured output resolution
are different, cursor should be scale up/down.

Change-Id: I2b92daaa28968f1fc563812566306784016cdc63

src/bin/e_pointer.c

index df8af41..a3ced92 100644 (file)
@@ -14,6 +14,34 @@ static Eina_Inlist *_e_pointer_hooks[] =
    [E_POINTER_HOOK_HIDE] = NULL,
 };
 
+static void
+_e_pointer_configured_output_resolution_ratio_get(E_Client *ec, double *ratio_w, double *ratio_h)
+{
+   E_Output *output;
+
+   if (ratio_w) *ratio_w = 1.0;
+   if (ratio_h) *ratio_h = 1.0;
+
+   if (!e_config->cursor_configured_output_resolution.use) return;
+   if (e_config->cursor_configured_output_resolution.w == 0) return;
+   if (e_config->cursor_configured_output_resolution.h == 0) return;
+
+   if (!ec) return;
+   if (!ec->zone) return;
+
+   output = e_output_find(ec->zone->output_id);
+   if (!output) return;
+   if (output->config.geom.w == 0) return;
+   if (output->config.geom.h == 0) return;
+
+   if (ratio_w)
+      *ratio_w = (double)output->config.geom.w /
+                 (double)e_config->cursor_configured_output_resolution.w;
+   if (ratio_h)
+      *ratio_h = (double)output->config.geom.h /
+                 (double)e_config->cursor_configured_output_resolution.h;
+}
+
 /* move the cursor image with the calcaultion of the hot spot */
 static void
 _e_pointer_position_update(E_Pointer *ptr)
@@ -22,6 +50,8 @@ _e_pointer_position_update(E_Pointer *ptr)
    int rotation;
    int cursor_w, cursor_h;
    E_Client *ec;
+   double ratio_w = 1.0, ratio_h = 1.0;
+   int hot_x = 0, hot_y = 0;
 
    if (!ptr->o_ptr) return;
 
@@ -31,28 +61,40 @@ _e_pointer_position_update(E_Pointer *ptr)
    rotation = ptr->rotation;
 
    evas_object_geometry_get(ec->frame, NULL, NULL, &cursor_w, &cursor_h);
+   _e_pointer_configured_output_resolution_ratio_get(ec, &ratio_w, &ratio_h);
+
+   if ((ratio_w != 1.0) || (ratio_h != 1.0))
+     {
+        hot_x = (int)((double)ptr->hot.x * ratio_w);
+        hot_y = (int)((double)ptr->hot.y * ratio_h);
+     }
+   else
+     {
+        hot_x = ptr->hot.x;
+        hot_y = ptr->hot.y;
+     }
 
    switch (rotation)
      {
       case 0:
-        nx = ptr->x - ptr->hot.x;
-        ny = ptr->y - ptr->hot.y;
+        nx = ptr->x - hot_x;
+        ny = ptr->y - hot_y;
         break;
       case 90:
-        nx = ptr->x - ptr->hot.y;
-        ny = ptr->y + ptr->hot.x;
+        nx = ptr->x - hot_y;
+        ny = ptr->y + hot_x;
         break;
       case 180:
-        nx = ptr->x + ptr->hot.x;
-        ny = ptr->y + ptr->hot.y;
+        nx = ptr->x + hot_x;
+        ny = ptr->y + hot_y;
         break;
       case 270:
-        nx = ptr->x + ptr->hot.y;
-        ny = ptr->y - ptr->hot.x;
+        nx = ptr->x + hot_y;
+        ny = ptr->y - hot_x;
         break;
       default:
-        nx = ptr->x - ptr->hot.x;
-        ny = ptr->y - ptr->hot.y;
+        nx = ptr->x - hot_x;
+        ny = ptr->y - hot_y;
         break;
      }
 
@@ -63,12 +105,13 @@ _e_pointer_position_update(E_Pointer *ptr)
 }
 
 static void
-_e_pointer_object_rotation(E_Pointer *ptr)
+_e_pointer_object_map_update(E_Pointer *ptr)
 {
    E_Map *map;
    int x, y, w, h;
    E_Client *ec;
-   int rotation;
+   int rotation = 0;
+   double ratio_w = 1.0, ratio_h = 1.0;
 
    EINA_SAFETY_ON_NULL_RETURN(ptr);
    if (!ptr->o_ptr) return;
@@ -76,26 +119,43 @@ _e_pointer_object_rotation(E_Pointer *ptr)
    ec = e_comp_object_client_get(ptr->o_ptr);
    EINA_SAFETY_ON_NULL_RETURN(ec);
 
+   _e_pointer_configured_output_resolution_ratio_get(ec, &ratio_w, &ratio_h);
    rotation = ptr->rotation;
 
-   evas_object_geometry_get(ec->frame, &x, &y, &w, &h);
-
-   if ((rotation == 0) || (rotation % 90 != 0) || (rotation / 90 > 3))
+   if (((ratio_w == 1.0) && (ratio_h == 1.0)) &&
+       ((rotation == 0) || (rotation % 90 != 0) || (rotation / 90 > 3)))
      {
         e_client_map_enable_set(ec, EINA_FALSE);
         e_client_map_set(ec, NULL);
         return;
      }
 
+   evas_object_geometry_get(ec->frame, &x, &y, &w, &h);
+
    map = e_map_new();
+   EINA_SAFETY_ON_NULL_RETURN(map);
+
    e_map_util_points_populate_from_object_full(map, ec->frame, 0);
-   e_map_util_points_color_set(map, 255, 255, 255, 255);
 
-   if (rotation == 90)
-     rotation = 270;
-   else if (rotation == 270)
-     rotation = 90;
-   e_map_util_rotate(map, rotation, x, y);
+   if ((ratio_w != 1.0) || (ratio_h != 1.0))
+     {
+        e_map_point_coord_set(map, 1, x + (int)((double)w * ratio_w), y, 0);
+        e_map_point_coord_set(map, 2, x + (int)((double)w * ratio_w),
+                             y + (int)((double)h * ratio_h), 0);
+        e_map_point_coord_set(map, 3, x, y + (int)((double)h * ratio_h), 0);
+     }
+
+   if (rotation)
+     {
+        if (rotation == 90)
+          rotation = 270;
+        else if (rotation == 270)
+          rotation = 90;
+
+        e_map_util_rotate(map, rotation, x, y);
+     }
+
+   e_map_util_points_color_set(map, 255, 255, 255, 255);
    e_map_util_object_move_sync_set(map, EINA_TRUE);
 
    e_client_map_set(ec, map);
@@ -106,14 +166,14 @@ _e_pointer_object_rotation(E_Pointer *ptr)
 
 // TODO: transform the cursor position with hot spot...!!!!!!
 static void
-_e_pointer_rotation_apply(E_Pointer *ptr)
+_e_pointer_map_apply(E_Pointer *ptr)
 {
    EINA_SAFETY_ON_NULL_RETURN(ptr);
 
    if (ptr->hwc)
      e_comp_object_hwc_update_set(ptr->o_ptr, EINA_TRUE);
    else
-     _e_pointer_object_rotation(ptr);
+     _e_pointer_object_map_update(ptr);
 }
 
 static void
@@ -343,8 +403,8 @@ e_pointer_object_set(E_Pointer *ptr, Evas_Object *obj, int x, int y)
         /* move the pointer to the current position */
         _e_pointer_position_update(ptr);
 
-        /* apply the cursor obj rotation */
-        _e_pointer_rotation_apply(ptr);
+        /* apply the cursor obj map */
+        _e_pointer_map_apply(ptr);
      }
 
    if (need_call_hide)
@@ -420,7 +480,7 @@ e_pointer_rotation_set(E_Pointer *ptr, int rotation)
    ptr->rotation = rotation;
 
    _e_pointer_position_update(ptr);
-   _e_pointer_rotation_apply(ptr);
+   _e_pointer_map_apply(ptr);
 
    EINA_LIST_FOREACH(e_input_devices_get(), l, dev)
      e_input_device_pointer_rotation_set(dev, rotation);
@@ -456,7 +516,7 @@ e_pointer_hwc_set(E_Pointer *ptr, Eina_Bool set)
    else
     {
        _e_pointer_position_update(ptr);
-       _e_pointer_rotation_apply(ptr);
+       _e_pointer_map_apply(ptr);
     }
 
    return EINA_TRUE;