This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit fbb0085ac32089aac6b6a6e2db5bae623b3085cd
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 8 15:13:11 2026 -0600

    elementary: replacing a window background leaves no stray one behind
    
    _elm_win_bg_set() deleted the old background with a plain efl_del, then
    took the new one. A callback of the deleted background that set another
    one left that one swallowed and a child of the window while the new one
    was set over it, so it outlived the part; and a swallow that failed
    after sub_object_add() left the refused object a child of the window.
    
    The old background is still deleted before the new one is taken, as
    before, and a refused one still leaves the part empty. What a callback
    of the old one sets goes too, a background only half taken is given
    back, and setting the background that is there is a no-op.
    
    The old one is deleted with evas_object_del, which waits for the
    references an Evas callback holds on the object, after its slot is
    forgotten so its weak reference does not clear the new one.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_win.c        | 48 ++++++++++++++++++++++++++++++----
 src/tests/elementary/efl_ui_test_win.c | 48 ++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 5 deletions(-)

diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c
index c8d26985ef..61a697b19a 100644
--- a/src/lib/elementary/efl_ui_win.c
+++ b/src/lib/elementary/efl_ui_win.c
@@ -7521,10 +7521,48 @@ if (x < 0) { x = 0; bad = 1; } } while (0)
 
 #define WIN_PART_ERR(part) ERR("No such part in window: '%s'. Supported parts are: 'content' and 'background'.", part);
 
+// Replaces the background with nothing: the slot is forgotten first (the weak
+// reference would otherwise clear it when the background dies), then, if it is
+// still alive, it leaves the part and the window and is deleted.
+// evas_object_del waits for the references an Evas callback holds on it, where
+// efl_del would not.
+static void
+_win_bg_drop(Efl_Ui_Win_Data *sd)
+{
+   Eo *prev = sd->bg;
+
+   if (!prev) return;
+   efl_wref_del(prev, &sd->bg);
+   sd->bg = NULL;
+   if (!efl_alive_get(prev)) return;
+   edje_object_part_unswallow(_elm_config->win_no_border ? sd->legacy.edje : sd->frame_obj, prev);
+   elm_widget_sub_object_del(sd->obj, prev);
+   if (efl_parent_get(prev) == sd->obj)
+     efl_parent_set(prev, evas_object_evas_get(sd->obj));
+   evas_object_del(prev);
+}
+
+// Takes the background back out of the window after a part of taking it failed.
+static Eina_Bool
+_win_bg_refuse(Efl_Ui_Win_Data *sd, Eo *bg)
+{
+   edje_object_part_unswallow(_elm_config->win_no_border ? sd->legacy.edje : sd->frame_obj, bg);
+   elm_widget_sub_object_del(sd->obj, bg);
+   return EINA_FALSE;
+}
+
 static Eina_Bool
 _elm_win_bg_set(Efl_Ui_Win_Data *sd, Eo *bg)
 {
-   ELM_SAFE_DEL(sd->bg);
+   if (bg && (bg == sd->bg)) return EINA_TRUE;
+   _win_bg_drop(sd);
+   // (a callback of the deleted background may have set another one, or this
+   // one: whatever it set goes too, so that one background is held at the end)
+   if (bg && (bg == sd->bg)) return EINA_TRUE;
+   while (sd->bg)
+     {
+        _win_bg_drop(sd);
+     }
    if (!bg) return EINA_TRUE;
 
    if (!elm_widget_sub_object_add(sd->obj, bg))
@@ -7534,12 +7572,12 @@ _elm_win_bg_set(Efl_Ui_Win_Data *sd, Eo *bg)
         if (!_elm_config->win_no_border)
           {
              if (!edje_object_part_swallow(sd->frame_obj, "elm.swallow.background", bg))
-               return EINA_FALSE;
+               return _win_bg_refuse(sd, bg);
           }
         else
           {
              if (!edje_object_part_swallow(sd->legacy.edje, "elm.swallow.background", bg))
-               return EINA_FALSE;
+               return _win_bg_refuse(sd, bg);
           }
      }
    else
@@ -7547,12 +7585,12 @@ _elm_win_bg_set(Efl_Ui_Win_Data *sd, Eo *bg)
         if (!_elm_config->win_no_border)
           {
              if (!edje_object_part_swallow(sd->frame_obj, "efl.background", bg))
-               return EINA_FALSE;
+               return _win_bg_refuse(sd, bg);
           }
         else
           {
              if (!edje_object_part_swallow(sd->legacy.edje, "efl.background", bg))
-               return EINA_FALSE;
+               return _win_bg_refuse(sd, bg);
           }
      }
    efl_gfx_entity_visible_set(bg, 1);
diff --git a/src/tests/elementary/efl_ui_test_win.c b/src/tests/elementary/efl_ui_test_win.c
index d0848011cc..685d233d2a 100644
--- a/src/tests/elementary/efl_ui_test_win.c
+++ b/src/tests/elementary/efl_ui_test_win.c
@@ -499,6 +499,53 @@ EFL_START_TEST(efl_ui_win_test_background_load)
 }
 EFL_END_TEST
 
+static Eo *_bg_other = NULL;
+
+static void
+_bg_replace_cb(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+   Eo *win = data;
+   Eo *other = efl_add(EFL_CANVAS_RECTANGLE_CLASS, win);
+
+   efl_wref_add(other, &_bg_other);
+   // (a callback of the background that goes sets another one)
+   efl_content_set(efl_part(win, "background"), other);
+}
+
+// Setting a background deletes the one there, a refused one leaves the part
+// empty, and what a callback of the deleted one sets does not outlive the one
+// that is set.
+EFL_START_TEST(efl_ui_win_test_background_replace)
+{
+   Efl_Ui_Win *win;
+   Eo *a, *b, *c, *got_a = NULL, *got_b = NULL;
+
+   win = efl_new(EFL_UI_WIN_CLASS);
+   a = efl_add(EFL_CANVAS_RECTANGLE_CLASS, win);
+   efl_wref_add(a, &got_a);
+   ck_assert(efl_content_set(efl_part(win, "background"), a));
+
+   // refused: empty, the old one gone, and nothing is left half attached
+   EXPECT_ERROR_START;
+   ck_assert(!efl_content_set(efl_part(win, "background"), win));
+   EXPECT_ERROR_END;
+   ck_assert_ptr_eq(efl_content_get(efl_part(win, "background")), NULL);
+   ck_assert_ptr_eq(got_a, NULL);
+
+   // a callback of the replaced one sets another background: that one goes too
+   b = efl_add(EFL_CANVAS_RECTANGLE_CLASS, win);
+   efl_wref_add(b, &got_b);
+   efl_event_callback_add(b, EFL_EVENT_DEL, _bg_replace_cb, win);
+   ck_assert(efl_content_set(efl_part(win, "background"), b));
+   c = efl_add(EFL_CANVAS_RECTANGLE_CLASS, win);
+   ck_assert(efl_content_set(efl_part(win, "background"), c));
+   ck_assert_ptr_eq(got_b, NULL);
+   ck_assert_ptr_eq(efl_content_get(efl_part(win, "background")), c);
+   ck_assert_ptr_eq(_bg_other, NULL);
+   efl_unref(win);
+}
+EFL_END_TEST
+
 EFL_START_TEST(efl_ui_win_test_type)
 {
    Efl_Ui_Win *win;
@@ -824,6 +871,7 @@ efl_ui_test_win(TCase *tc)
    tcase_add_test(tc, efl_ui_win_test_rotation_normalized);
    tcase_add_test(tc, efl_ui_win_test_type);
    tcase_add_test(tc, efl_ui_win_test_content_replaced);
+   tcase_add_test(tc, efl_ui_win_test_background_replace);
    tcase_add_test(tc, efl_ui_win_test_content_replace_and_unset);
    tcase_add_test(tc, efl_ui_win_test_background_unset);
    tcase_add_test(tc, efl_ui_win_test_content_replace_refused);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to