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

git pushed a commit to branch up/output-remove
in repository enlightenment.

View the commit online.

commit 5297363842e65a68fb232b395f035afe8a085519
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 15:54:04 2026 -0600

    e_comp_wl - take a monitor's wl_output away when it is turned off
    
    e_comp_wl_output_remove() took the output off E's list and nothing
    else: its global stayed advertised, every client kept the output, and
    turning the monitor back on added a second wl_output of the same name.
    zone->output kept pointing at it too.
    
    The global is now removed with wl_global_remove(), and destroyed with
    the output five seconds later: a client that has not seen the removal
    yet may still bind it until then. The wl_output and xdg_output objects
    left are kept valid for their clients and do nothing once the output is
    freed. The zone forgets the output at once, as surface enter and leave
    and the presentation feedback read it from there.
    
    A wl_output that names no output any more is ignored by
    xdg_toplevel.set_fullscreen in xdg and xdg-shell v6: a NULL output
    matched the zone of the removed output, whose output is now NULL too.
    
    wl_test version 11 adds output_remove, which removes the output of a
    zone the way the randr handler does for a screen turned off.
    
    wl-output-remove adds a zone, binds its output and an xdg_output, then
    removes it and binds it again in the same flush. The global must be
    gone; once E has freed the output, releasing what was bound and asking
    for fullscreen on it must work, on the window's own zone; turning the
    output back on must give one new global, which a new client sees once.
    It fails with the global kept, and with the fullscreen check of a NULL
    output; it is a protocol error without the xdg_output check. Only the
    xdg-shell side of the fullscreen check is tested.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/bin/e_comp_wl.c                    |  67 +++++++++++-----
 src/bin/e_comp_wl_extensions.c         |   4 +-
 src/modules/wl_desktop_shell/xdg.c     |   3 +-
 src/modules/wl_desktop_shell/xdg6.c    |   3 +-
 src/modules/wl_test/e_mod_main.c       |  12 ++-
 src/protocol/wl-test.xml               |  10 ++-
 src/tests/wayland/meson.build          |   1 +
 src/tests/wayland/test_output_remove.c | 136 +++++++++++++++++++++++++++++++++
 8 files changed, 210 insertions(+), 26 deletions(-)

diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index ae7968d25..ced36665a 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -3885,6 +3885,31 @@ e_comp_wl_surface_create_signal_get(void)
    return e_comp_wl->signals.surface.create;
 }
 
+/* The wl_output and xdg_output objects of a freed output stay valid for
+ * their clients, and do nothing. */
+static void
+_e_comp_wl_output_resources_forget(E_Comp_Wl_Output *output)
+{
+   struct wl_resource *resource;
+
+   EINA_LIST_FREE(output->resources, resource)
+     wl_resource_set_user_data(resource, NULL);
+   EINA_LIST_FREE(output->xdg_outputs, resource)
+     wl_resource_set_user_data(resource, NULL);
+}
+
+static void
+_e_comp_wl_output_free(E_Comp_Wl_Output *output)
+{
+   _e_comp_wl_output_resources_forget(output);
+   if (output->id) eina_stringshare_del(output->id);
+   if (output->make) eina_stringshare_del(output->make);
+   if (output->model) eina_stringshare_del(output->model);
+   eina_stringshare_del(output->name);
+   eina_stringshare_del(output->description);
+   free(output);
+}
+
 /* internal functions */
 EINTERN void
 e_comp_wl_shutdown(void)
@@ -3892,15 +3917,7 @@ e_comp_wl_shutdown(void)
    E_Comp_Wl_Output *output;
 
    EINA_LIST_FREE(e_comp_wl->outputs, output)
-     {
-        if (output->id) eina_stringshare_del(output->id);
-        if (output->make) eina_stringshare_del(output->make);
-        if (output->model) eina_stringshare_del(output->model);
-        eina_list_free(output->xdg_outputs);
-        eina_stringshare_del(output->name);
-        eina_stringshare_del(output->description);
-        free(output);
-     }
+     _e_comp_wl_output_free(output);
 
    /* free handlers */
    E_FREE_LIST(handlers, ecore_event_handler_del);
@@ -4212,24 +4229,32 @@ e_comp_wl_output_init(const char *id, const char *make, const char *model,
    return EINA_TRUE;
 }
 
+/* A client that has not seen the global go may still bind it until it is
+ * destroyed. */
+static Eina_Bool
+_e_comp_wl_output_destroy_cb(void *data)
+{
+   E_Comp_Wl_Output *output = data;
+
+   wl_global_destroy(output->global);
+   _e_comp_wl_output_free(output);
+   return ECORE_CALLBACK_CANCEL;
+}
+
 E_API void
 e_comp_wl_output_remove(const char *id)
 {
    E_Comp_Wl_Output *output;
+   E_Zone *zone;
+   Eina_List *l;
 
    output = _e_comp_wl_output_get(e_comp_wl->outputs, id);
-   if (output)
-     {
-        e_comp_wl->outputs = eina_list_remove(e_comp_wl->outputs, output);
-
-        /* wl_global_destroy(output->global); */
-
-        /* eina_stringshare_del(output->id); */
-        /* eina_stringshare_del(output->make); */
-        /* eina_stringshare_del(output->model); */
-
-        /* free(output); */
-     }
+   if (!output) return;
+   e_comp_wl->outputs = eina_list_remove(e_comp_wl->outputs, output);
+   EINA_LIST_FOREACH(e_comp->zones, l, zone)
+     if (zone->output == output) zone->output = NULL;
+   wl_global_remove(output->global);
+   ecore_timer_loop_add(5.0, _e_comp_wl_output_destroy_cb, output);
 }
 
 /* Set while e_comp_wl_key_inject runs, to keep a key out of the grab it
diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index 6e5b875c4..1b4982ec0 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -1113,7 +1113,7 @@ _e_zxdg_output_v1_cb_unbind(struct wl_resource *resource)
 {
    E_Comp_Wl_Output *output = wl_resource_get_user_data(resource);
 
-   output->xdg_outputs = eina_list_remove(output->xdg_outputs, resource);
+   if (output) output->xdg_outputs = eina_list_remove(output->xdg_outputs, resource);
 }
 
 /* The logical rectangle is in the units of wl_surface coordinates. E's canvas
@@ -1164,6 +1164,8 @@ _e_zxdg_output_manager_v1_cb_xdg_output_get(struct wl_client *client, struct wl_
      }
    wl_resource_set_implementation(res, &_e_zxdg_output_v1_interface, output,
                                   _e_zxdg_output_v1_cb_unbind);
+   /* Of a removed output. */
+   if (!output) return;
    output->xdg_outputs = eina_list_append(output->xdg_outputs, res);
 
    _e_zxdg_output_v1_geometry_send(output, res);
diff --git a/src/modules/wl_desktop_shell/xdg.c b/src/modules/wl_desktop_shell/xdg.c
index f81247788..94370d1d3 100644
--- a/src/modules/wl_desktop_shell/xdg.c
+++ b/src/modules/wl_desktop_shell/xdg.c
@@ -952,7 +952,8 @@ _e_xdg_toplevel_cb_fullscreen_set(struct wl_client *client EINA_UNUSED, struct w
      }
 
    if (ec->lock_user_fullscreen) return;
-   if (output_resource)
+   /* The wl_output of a removed output has no data, and names no zone. */
+   if ((output_resource) && (wl_resource_get_user_data(output_resource)))
      {
         Eina_List *l;
         E_Zone *zone;
diff --git a/src/modules/wl_desktop_shell/xdg6.c b/src/modules/wl_desktop_shell/xdg6.c
index c1a08a0e8..17a76f2e4 100644
--- a/src/modules/wl_desktop_shell/xdg6.c
+++ b/src/modules/wl_desktop_shell/xdg6.c
@@ -640,7 +640,8 @@ _e_xdg_toplevel_cb_fullscreen_set(struct wl_client *client EINA_UNUSED, struct w
      }
 
    if (ec->lock_user_fullscreen) return;
-   if (output_resource)
+   /* The wl_output of a removed output has no data, and names no zone. */
+   if ((output_resource) && (wl_resource_get_user_data(output_resource)))
      {
         Eina_List *l;
         E_Zone *zone;
diff --git a/src/modules/wl_test/e_mod_main.c b/src/modules/wl_test/e_mod_main.c
index ed8c14c7f..a10992550 100644
--- a/src/modules/wl_test/e_mod_main.c
+++ b/src/modules/wl_test/e_mod_main.c
@@ -378,6 +378,15 @@ _wl_test_cb_output_scale_set(struct wl_client *client EINA_UNUSED, struct wl_res
    ERR("wl_test: zone %u has no wl_output", zone);
 }
 
+static void
+_wl_test_cb_output_remove(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED, uint32_t zone)
+{
+   char id[32];
+
+   snprintf(id, sizeof(id), "e-test-%u", zone);
+   e_comp_wl_output_remove(id);
+}
+
 static void
 _wl_test_cb_get_screensaver(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
 {
@@ -666,6 +675,7 @@ static const struct wl_test_interface _wl_test_implementation =
    _wl_test_cb_key_modified,
    _wl_test_cb_get_pixel,
    _wl_test_cb_output_scale_set,
+   _wl_test_cb_output_remove,
 };
 
 static void
@@ -699,7 +709,7 @@ e_modapi_init(E_Module *m)
         return NULL;
      }
 
-   _wl_test_global = wl_global_create(e_comp_wl->wl.disp, &wl_test_interface, 10,
+   _wl_test_global = wl_global_create(e_comp_wl->wl.disp, &wl_test_interface, 11,
                                      NULL, _wl_test_cb_bind);
    if (!_wl_test_global)
      {
diff --git a/src/protocol/wl-test.xml b/src/protocol/wl-test.xml
index b371e0ec9..4204daf65 100644
--- a/src/protocol/wl-test.xml
+++ b/src/protocol/wl-test.xml
@@ -23,7 +23,7 @@
     DEALINGS IN THE SOFTWARE.
   </copyright>
 
-  <interface name="wl_test" version="10">
+  <interface name="wl_test" version="11">
     <description summary="private interface for the compositor test suite">
       A back door into the compositor for its own test suite. It exposes
       internal state and synthesises input, so it is only built with
@@ -372,5 +372,13 @@
       <arg name="zone" type="uint" summary="index of the zone"/>
       <arg name="scale" type="int"/>
     </request>
+
+    <request name="output_remove" since="11">
+      <description summary="remove the output of a zone made by zone_add">
+        Reaches E the way a monitor being turned off does. output_configure
+        brings it back.
+      </description>
+      <arg name="zone" type="uint" summary="index of a zone from zone_add"/>
+    </request>
   </interface>
 </protocol>
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index 04ab3ac5e..6898017ba 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -91,6 +91,7 @@ wl_protocol_tests = [
   ['xdg-decoration', 'test_xdg_decoration.c'],
   ['shm-truncate', 'test_shm_truncate.c'],
   ['output', 'test_output.c'],
+  ['output-remove', 'test_output_remove.c'],
   ['buffer-scale', 'test_buffer_scale.c'],
   ['output-scale', 'test_output_scale.c'],
   ['buffer-transform', 'test_buffer_transform.c'],
diff --git a/src/tests/wayland/test_output_remove.c b/src/tests/wayland/test_output_remove.c
new file mode 100644
index 000000000..506332811
--- /dev/null
+++ b/src/tests/wayland/test_output_remove.c
@@ -0,0 +1,136 @@
+/* A monitor turned off takes its wl_output global away: clients see it
+ * removed, what they bound of it keeps working and names no output, and
+ * turning the monitor back on advertises it once. */
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include "e_wl_testkit.h"
+#include "xdg-output-unstable-v1-client-protocol.h"
+
+#define MAX_GLOBALS 8
+#define APP_ID "e.test.output-remove"
+
+typedef struct
+{
+   struct wl_registry *registry;
+   uint32_t names[MAX_GLOBALS];
+   int count;
+} Outputs;
+
+static void
+_global(void *data, struct wl_registry *registry __attribute__((unused)),
+        uint32_t name, const char *iface, uint32_t version __attribute__((unused)))
+{
+   Outputs *outputs = data;
+
+   if (strcmp(iface, wl_output_interface.name)) return;
+   if (outputs->count < MAX_GLOBALS) outputs->names[outputs->count++] = name;
+}
+
+static void
+_global_remove(void *data, struct wl_registry *registry __attribute__((unused)),
+               uint32_t name)
+{
+   Outputs *outputs = data;
+   int i;
+
+   for (i = 0; i < outputs->count; i++)
+     {
+        if (outputs->names[i] != name) continue;
+        outputs->names[i] = outputs->names[--outputs->count];
+        return;
+     }
+}
+
+static const struct wl_registry_listener _registry_listener =
+{
+   _global, _global_remove
+};
+
+static void
+_outputs_watch(Tk *tk, Outputs *outputs)
+{
+   outputs->registry = wl_display_get_registry(tk_display(tk));
+   wl_registry_add_listener(outputs->registry, &_registry_listener, outputs);
+   tk_sync(tk);
+}
+
+static int
+_has(const Outputs *outputs, uint32_t name)
+{
+   int i;
+
+   for (i = 0; i < outputs->count; i++)
+     if (outputs->names[i] == name) return 1;
+   return 0;
+}
+
+int
+main(void)
+{
+   struct zxdg_output_manager_v1 *xdg_manager;
+   struct zxdg_output_v1 *xdg_output;
+   struct wl_output *output, *late;
+   struct timespec destroyed = { 6, 0 };
+   struct wl_test *tester;
+   Tk_Toplevel *top;
+   Tk_Client *client;
+   Outputs outputs = { 0 }, fresh = { 0 };
+   uint32_t name;
+   Tk *tk, *tk2;
+
+   tk = tk_connect("test-output-remove");
+   tester = tk_bind(tk, &wl_test_interface, 11);
+   xdg_manager = tk_bind(tk, &zxdg_output_manager_v1_interface, 3);
+   if (!tester) tk_fail(tk, "no wl_test version 11");
+   _outputs_watch(tk, &outputs);
+   if (outputs.count != 1) tk_fail(tk, "%d outputs to start with", outputs.count);
+   top = tk_toplevel_new(tk, APP_ID, "output remove", 200, 100);
+
+   wl_test_zone_add(tester, 1024, 0, 800, 600);
+   tk_sync(tk);
+   if (outputs.count != 2) tk_fail(tk, "%d outputs after adding one", outputs.count);
+   name = outputs.names[1];
+   output = wl_registry_bind(outputs.registry, name, &wl_output_interface, 4);
+   xdg_output = zxdg_output_manager_v1_get_xdg_output(xdg_manager, output);
+   tk_sync(tk);
+
+   /* Bound in the same flush, before this client can see the removal. */
+   wl_test_output_remove(tester, 1);
+   late = wl_registry_bind(outputs.registry, name, &wl_output_interface, 4);
+   zxdg_output_manager_v1_get_xdg_output(xdg_manager, late);
+   tk_sync(tk);
+   if (_has(&outputs, name)) tk_fail(tk, "the removed output is still advertised");
+
+   /* Once E has freed the output, what was bound of it still works. */
+   nanosleep(&destroyed, NULL);
+   zxdg_output_v1_destroy(xdg_output);
+   wl_output_release(output);
+   tk_sync(tk);
+
+   /* Fullscreen on an output that is gone is fullscreen where it is. */
+   xdg_toplevel_set_fullscreen(tk_toplevel_xdg(top), late);
+   client = tk_wait_states(tk, APP_ID, WL_TEST_CLIENT_STATE_FULLSCREEN,
+                           WL_TEST_CLIENT_STATE_FULLSCREEN, "fullscreen");
+   if (client->x >= 1024)
+     tk_fail(tk, "fullscreen on a removed output went to its zone, at %d",
+             client->x);
+   wl_output_release(late);
+   tk_sync(tk);
+
+   wl_test_output_configure(tester, 1, 1024, 0, 800, 600);
+   tk_sync(tk);
+   if (outputs.count != 2)
+     tk_fail(tk, "%d outputs once the removed one is back", outputs.count);
+   if (_has(&outputs, name)) tk_fail(tk, "the output came back under its old global");
+
+   tk2 = tk_connect("test-output-remove-2");
+   _outputs_watch(tk2, &fresh);
+   if (fresh.count != 2)
+     tk_fail(tk2, "a new client sees %d outputs, wanted 2", fresh.count);
+   tk_disconnect(tk2);
+
+   tk_disconnect(tk);
+   printf("test-output-remove: ok\n");
+   return 0;
+}

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

Reply via email to