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 c2cebcd549a0f8ac0c5a585c7479439797ab9384
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 8 12:24:52 2026 -0600

    elementary: a window's background is unset alive, as its content is
    
    Unsetting the "background" part of a window referenced the background,
    then deleted it, and returned it: the caller got a deleted object with
    an extra ref. Follow the contract of Efl.Content as the content part
    does: take the background out of the theme, hand it back alive, holding
    no ref of the window's and parented to the canvas.
    
    A content that replaces another detached the old one before it knew that
    the window could take the new one, so a refusal (the window itself, say)
    left the slot empty with the old content hidden. Check that the new
    content can be added first.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_win.c        | 39 +++++++++++++++++++-----
 src/tests/elementary/efl_ui_test_win.c | 54 ++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 8 deletions(-)

diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c
index eb775d2d40..c8d26985ef 100644
--- a/src/lib/elementary/efl_ui_win.c
+++ b/src/lib/elementary/efl_ui_win.c
@@ -7652,6 +7652,22 @@ _win_content_detach(Efl_Ui_Win_Data *sd, Eo *obj)
    return prev;
 }
 
+// Takes the background out of the window, and gives it back: still alive, no
+// longer the window's, as the content is.
+static Eo *
+_win_bg_detach(Efl_Ui_Win_Data *sd, Eo *obj)
+{
+   Eo *bg = sd->bg;
+
+   if (!bg) return NULL;
+   efl_wref_del(bg, &sd->bg);
+   sd->bg = NULL;
+   edje_object_part_unswallow(_elm_config->win_no_border ? sd->legacy.edje : sd->frame_obj, bg);
+   elm_widget_sub_object_del(obj, bg);
+   evas_object_hide(bg);
+   return bg;
+}
+
 static Eina_Bool
 _efl_ui_win_content_set(Eo *obj, Efl_Ui_Win_Data *sd, const char *part, Eo *content)
 {
@@ -7666,11 +7682,13 @@ _efl_ui_win_content_set(Eo *obj, Efl_Ui_Win_Data *sd, const char *part, Eo *cont
         // clear the slot of the content that replaced it when it is deleted. It
         // stays a child of the window, which ends it (callers that mean to keep
         // it unset it first, and one that wants it gone deletes it).
+        // (a content that cannot become the window's is refused before anything
+        // moves: the slot keeps the content it has)
+        if (content && !elm_widget_sub_object_add(obj, content))
+          goto err;
         prev = _win_content_detach(sd, obj);
         if (prev && (prev != content)) evas_object_hide(prev);
         if (!content) return EINA_TRUE;
-        if (!elm_widget_sub_object_add(obj, content))
-          goto err;
         /* FIXME: Switch to swallow inside the frame
         if (!edje_object_part_swallow(sd->frame_obj, "elm.swallow.client", content))
           goto err;
@@ -7725,12 +7743,17 @@ _efl_ui_win_content_unset(Eo *obj, Efl_Ui_Win_Data *sd, const char *part)
           efl_parent_set(content, evas_object_evas_get(obj));
         return content;
      }
-   content = _efl_ui_win_content_get(obj, sd, part);
-   if (!content) return NULL;
-
-   efl_ref(content);
-   _efl_ui_win_content_set(obj, sd, part, NULL);
-   return content;
+   if (eina_streq(part, "background"))
+     {
+        // The same for the background: alive, no reference of ours, no longer a
+        // child of the window (the theme's own background shows).
+        content = _win_bg_detach(sd, obj);
+        if (content && (efl_parent_get(content) == obj))
+          efl_parent_set(content, evas_object_evas_get(obj));
+        return content;
+     }
+   WIN_PART_ERR(part);
+   return NULL;
 }
 
 static Eina_Bool
diff --git a/src/tests/elementary/efl_ui_test_win.c b/src/tests/elementary/efl_ui_test_win.c
index 3eebd72861..d0848011cc 100644
--- a/src/tests/elementary/efl_ui_test_win.c
+++ b/src/tests/elementary/efl_ui_test_win.c
@@ -749,6 +749,58 @@ EFL_START_TEST(efl_ui_win_test_content_replace_and_unset)
 }
 EFL_END_TEST
 
+// The background part follows the same contract: unset, it comes back alive
+// and holding nothing of the window's, so that deleting it frees it.
+EFL_START_TEST(efl_ui_win_test_background_unset)
+{
+   Efl_Ui_Win *win;
+   Eo *rect, *got = NULL;
+
+   win = efl_new(EFL_UI_WIN_CLASS);
+   rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, win);
+   efl_wref_add(rect, &got);
+   ck_assert(efl_content_set(efl_part(win, "background"), rect));
+   ck_assert_ptr_eq(efl_content_get(efl_part(win, "background")), rect);
+
+   ck_assert_ptr_eq(efl_content_unset(efl_part(win, "background")), rect);
+   ck_assert_ptr_eq(efl_content_get(efl_part(win, "background")), NULL);
+   // alive, and nobody has a reference but its parent, which is not the window
+   ck_assert_ptr_ne(got, NULL);
+   ck_assert(!efl_invalidating_get(rect));
+   ck_assert(!efl_invalidated_get(rect));
+   ck_assert_int_eq(efl_ref_count(rect), 1);
+   ck_assert_ptr_ne(efl_parent_get(rect), win);
+   efl_del(rect);
+   ck_assert_ptr_eq(got, NULL);
+
+   // and a window that has none gives none
+   ck_assert_ptr_eq(efl_content_unset(efl_part(win, "background")), NULL);
+   efl_unref(win);
+}
+EFL_END_TEST
+
+// A content the window cannot take (itself) is refused before anything moves: the
+// content it has stays in its slot, shown.
+EFL_START_TEST(efl_ui_win_test_content_replace_refused)
+{
+   Efl_Ui_Win *win;
+   Eo *a;
+
+   win = efl_new(EFL_UI_WIN_CLASS);
+   a = efl_add(EFL_UI_BUTTON_CLASS, win);
+   ck_assert(efl_content_set(win, a));
+   efl_gfx_entity_visible_set(a, EINA_TRUE);
+
+   EXPECT_ERROR_START;
+   ck_assert(!efl_content_set(win, win));
+   EXPECT_ERROR_END;
+   ck_assert_ptr_eq(efl_content_get(win), a);
+   ck_assert(efl_gfx_entity_visible_get(a));
+   ck_assert_ptr_eq(efl_parent_get(a), win);
+   efl_unref(win);
+}
+EFL_END_TEST
+
 void
 efl_ui_test_win(TCase *tc)
 {
@@ -773,4 +825,6 @@ efl_ui_test_win(TCase *tc)
    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_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