subsurface: Move a handler for updating stack order of subsurfaces 45/256945/4
authorSeunghun Lee <chwila927@gmail.com>
Thu, 15 Apr 2021 02:38:57 +0000 (11:38 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 19 Apr 2021 08:44:44 +0000 (08:44 +0000)
Place it with the other subsurface functions.

Change-Id: I57adb07ef066752e93e6027c43884bb2b0042c04

src/bin/e_comp_wl.c
src/bin/e_comp_wl_subsurface.c

index 9892ee8477d98caa078e3f1472136b2634abd254..5b097db41b4887eb395feffbab00b430dcf3a289 100644 (file)
@@ -719,18 +719,6 @@ _e_comp_wl_touch_cancel(void)
    _e_comp_wl_send_touch_cancel(ec);
 }
 
-static void
-_e_comp_wl_evas_cb_restack(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
-{
-   E_Client *ec = (E_Client *)data;
-
-   if ((!ec) || (!ec->comp_data)) return;
-   if (e_object_is_del(E_OBJECT(ec))) return;
-   if (ec->comp_data->sub.restacking) return;
-
-   e_comp_wl_subsurface_stack_update(ec);
-}
-
 static E_Devicemgr_Input_Device *
 _e_comp_wl_device_last_device_get(Ecore_Device_Class dev_class)
 {
@@ -2079,21 +2067,9 @@ _e_comp_wl_client_evas_init(E_Client *ec)
    if (!ec || !ec->comp_data) return;
    if (ec->comp_data->evas_init) return;
 
-   /* Workaround:
-    * Updating stack order of subsurface has to be done for safety, because
-    * stack order can be abnormal before registering a callback function.
-    * If a callback function of EVAS_CALLBACK_RESTACK is called immediately
-    * in some way, stack order will become normal, otherwise it will remain
-    * abnormal until callback function is called.
-    *
-    * Note that stacking subsurface object can be improved by taking advantage
-    * of evas smart member object mechanism. */
-   e_comp_wl_subsurface_stack_update(ec);
-
    evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_SHOW,        _e_comp_wl_evas_cb_show,        ec);
    evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_HIDE,        _e_comp_wl_evas_cb_hide,        ec);
    evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_MOVE,        _e_comp_wl_evas_cb_move,        ec);
-   evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESTACK,     _e_comp_wl_evas_cb_restack,     ec);
 
 
    evas_object_event_callback_priority_add(ec->frame, EVAS_CALLBACK_MOUSE_IN,    EVAS_CALLBACK_PRIORITY_AFTER, _e_comp_wl_evas_cb_mouse_in,    ec);
index c0031680d85bc758ae6f92e6b0e93c44c1d929c8..dbce48a024923d75ed60f1c25f9e434eca4c104c 100644 (file)
@@ -4,6 +4,7 @@
 
 static struct wl_global *global = NULL;
 static Eina_List *hooks = NULL;
+static Eina_List *handlers = NULL;
 
 static E_Comp_Wl_Subsurf_Data *_e_comp_wl_subsurface_data_get(E_Client *ec);
 
@@ -16,6 +17,7 @@ static void       _e_comp_wl_subsurface_remove_from_parent(E_Client *parent, E_C
 static void       _e_comp_wl_subsurface_child_remove(E_Comp_Wl_Client_Data *parent_cdata, E_Client *child);
 static void       _e_comp_wl_subsurface_place_above(E_Client *parent, E_Client *subc, E_Client *above);
 static void       _e_comp_wl_subsurface_place_below(E_Client *parent, E_Client *subc, E_Client *below);
+static void       _e_comp_wl_subsurface_stack_update(E_Client *ec);
 
 static void
 _e_comp_wl_subsurface_restack_bg_rectangle(E_Client *ec)
@@ -899,6 +901,53 @@ _e_comp_wl_subsurface_circular_reference_check(E_Client *ec, E_Client *parent)
    return EINA_FALSE;
 }
 
+static void
+_e_comp_wl_subsurface_cb_comp_object_restack(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   E_Client *ec;
+
+   ec = data;
+   if ((!ec) || (!ec->comp_data))
+     return;
+
+   if (e_object_is_del(E_OBJECT(ec)))
+     return;
+
+   if (ec->comp_data->sub.restacking)
+     return;
+
+   _e_comp_wl_subsurface_stack_update(ec);
+}
+
+static Eina_Bool
+_e_comp_wl_subsurface_cb_comp_object_add(void *data EINA_UNUSED, int type EINA_UNUSED, E_Event_Comp_Object *ev)
+{
+   E_Client *ec;
+
+   ec = e_comp_object_client_get(ev->comp_object);
+   if (!ec)
+     goto end;
+
+   if (e_object_is_del(E_OBJECT(ec)))
+     goto end;
+
+   /* Workaround:
+    * Updating stack order of subsurface has to be done for safety, because
+    * stack order can be abnormal before registering a callback function.
+    * If a callback function of EVAS_CALLBACK_RESTACK is called immediately
+    * in some way, stack order will become normal, otherwise it will remain
+    * abnormal until callback function is called.
+    *
+    * Note that stacking subsurface object can be improved by taking advantage
+    * of evas smart member object mechanism. */
+   _e_comp_wl_subsurface_stack_update(ec);
+
+   evas_object_event_callback_add(ec->frame, EVAS_CALLBACK_RESTACK,  _e_comp_wl_subsurface_cb_comp_object_restack,   ec);
+
+end:
+   return ECORE_CALLBACK_RENEW;
+}
+
 EINTERN Eina_Bool
 e_comp_wl_subsurfaces_init(E_Comp_Wl_Data *wl_comp)
 {
@@ -919,6 +968,8 @@ e_comp_wl_subsurfaces_init(E_Comp_Wl_Data *wl_comp)
    E_LIST_HOOK_APPEND(hooks, E_CLIENT_HOOK_ICONIFY,   _e_comp_wl_subsurface_cb_ec_iconify,     NULL);
    E_LIST_HOOK_APPEND(hooks, E_CLIENT_HOOK_UNICONIFY, _e_comp_wl_subsurface_cb_ec_uniconify,   NULL);
 
+   E_LIST_HANDLER_APPEND(handlers, E_EVENT_COMP_OBJECT_ADD, _e_comp_wl_subsurface_cb_comp_object_add, NULL);
+
    return EINA_TRUE;
 }
 
@@ -927,6 +978,7 @@ e_comp_wl_subsurfaces_shutdown(void)
 {
    E_FREE_FUNC(global, wl_global_destroy);
    E_FREE_LIST(hooks, e_client_hook_del);
+   E_FREE_LIST(handlers, ecore_event_handler_del);
 }
 
 E_API Eina_Bool
@@ -1194,51 +1246,9 @@ e_comp_wl_subsurface_restack(E_Client *ec)
 E_API void
 e_comp_wl_subsurface_stack_update(E_Client *ec)
 {
-   E_Client *topmost;
-
    EINA_SAFETY_ON_NULL_RETURN(ec);
 
-   if (!ec->comp_data) return;
-   if (e_object_is_del(E_OBJECT(ec))) return;
-   if (ec->comp_data->sub.restacking) return;
-
-   /* return if ec isn't both a parent of a subsurface and a subsurface itself */
-   if (!ec->comp_data->sub.list && !ec->comp_data->sub.below_list && !ec->comp_data->sub.data)
-     {
-        if (ec->comp_data->sub.below_obj)
-          _e_comp_wl_subsurface_restack_bg_rectangle(ec);
-        return;
-     }
-
-   topmost = e_comp_wl_topmost_parent_get(ec);
-
-   _e_comp_wl_subsurface_restack(topmost);
-   _e_comp_wl_subsurface_restack_bg_rectangle(topmost);
-
-   //To update client stack list
-   if ((ec->comp_data->sub.data) &&
-       (ec->comp_data->sub.data->parent))
-     {
-        E_Client *parent;
-        Evas_Object *o;
-
-        parent = ec->comp_data->sub.data->parent;
-
-        if ((parent->comp_data->sub.list) &&
-            (eina_list_data_find(parent->comp_data->sub.list, ec)))
-          {
-             //stack above done
-             o = evas_object_below_get(ec->frame);
-             e_comp_object_layer_update(ec->frame, o, NULL);
-          }
-        else if ((parent->comp_data->sub.below_list) &&
-                 (eina_list_data_find(parent->comp_data->sub.below_list, ec)))
-          {
-             //stack below done
-             o = evas_object_above_get(ec->frame);
-             e_comp_object_layer_update(ec->frame, NULL, o);
-          }
-     }
+   _e_comp_wl_subsurface_stack_update(ec);
 }
 
 EINTERN Eina_Bool
@@ -1449,3 +1459,51 @@ _e_comp_wl_subsurface_place_below(E_Client *parent, E_Client *subc, E_Client *be
 
    pc->sub.list_changed = EINA_TRUE;
 }
+
+static void
+_e_comp_wl_subsurface_stack_update(E_Client *ec)
+{
+   E_Client *topmost;
+
+   if (!ec->comp_data) return;
+   if (e_object_is_del(E_OBJECT(ec))) return;
+   if (ec->comp_data->sub.restacking) return;
+
+   /* return if ec isn't both a parent of a subsurface and a subsurface itself */
+   if (!ec->comp_data->sub.list && !ec->comp_data->sub.below_list && !ec->comp_data->sub.data)
+     {
+        if (ec->comp_data->sub.below_obj)
+          _e_comp_wl_subsurface_restack_bg_rectangle(ec);
+        return;
+     }
+
+   topmost = e_comp_wl_topmost_parent_get(ec);
+
+   _e_comp_wl_subsurface_restack(topmost);
+   _e_comp_wl_subsurface_restack_bg_rectangle(topmost);
+
+   //To update client stack list
+   if ((ec->comp_data->sub.data) &&
+       (ec->comp_data->sub.data->parent))
+     {
+        E_Client *parent;
+        Evas_Object *o;
+
+        parent = ec->comp_data->sub.data->parent;
+
+        if ((parent->comp_data->sub.list) &&
+            (eina_list_data_find(parent->comp_data->sub.list, ec)))
+          {
+             //stack above done
+             o = evas_object_below_get(ec->frame);
+             e_comp_object_layer_update(ec->frame, o, NULL);
+          }
+        else if ((parent->comp_data->sub.below_list) &&
+                 (eina_list_data_find(parent->comp_data->sub.below_list, ec)))
+          {
+             //stack below done
+             o = evas_object_above_get(ec->frame);
+             e_comp_object_layer_update(ec->frame, NULL, o);
+          }
+     }
+}