subsurface: Calculate global coordinates with all ancestors 40/309140/1
authorSeunghun Lee <shiin.lee@samsung.com>
Wed, 3 Apr 2024 06:18:15 +0000 (15:18 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Fri, 5 Apr 2024 06:01:41 +0000 (15:01 +0900)
The 'x' and 'y' member variables of E_Client for a subsurface are only
updated when its subsurface position needs to be updated. In other
words, if there's no update made on the position using
wl_subsurface.set_position, they would remain at their default values,
which are zero.

Therefore, we need to consider calculating the global coordinates of the
subsurface considering the positions of all its ancestors.

Change-Id: I92b49e1ca5b90bd1ee4ef43a058b7495a39796aa

src/bin/e_comp_wl_subsurface.c

index 55fd572..ebe333e 100644 (file)
@@ -892,7 +892,9 @@ e_comp_wl_subsurface_position_get(E_Client *ec, int *x, int *y)
 EINTERN Eina_Bool
 e_comp_wl_subsurface_global_coord_get(E_Client *ec, int *x, int *y)
 {
+   E_Client *parent;
    E_Comp_Wl_Subsurf_Data *sdata;
+   int ret_x = 0, ret_y = 0;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
@@ -901,10 +903,28 @@ e_comp_wl_subsurface_global_coord_get(E_Client *ec, int *x, int *y)
    sdata = ec->comp_data->sub.data;
    EINA_SAFETY_ON_NULL_RETURN_VAL(sdata, EINA_FALSE);
 
+   while (1)
+     {
+        ret_x += sdata->position.x;
+        ret_y += sdata->position.y;
+
+        parent = sdata->parent;
+        if (!parent)
+          break;
+
+        sdata = _e_comp_wl_subsurface_data_get(parent);
+        if (!sdata)
+          {
+             ret_x += parent->x;
+             ret_y += parent->y;
+             break;
+          }
+   }
+
    if (x)
-     *x = sdata->position.x + (sdata->parent ? sdata->parent->x : 0);
+     *x = ret_x;
    if (y)
-     *y = sdata->position.y + (sdata->parent ? sdata->parent->y : 0);
+     *y = ret_y;
 
    return EINA_TRUE;
 }