This is an automated email from the git hooks/post-receive script.
git pushed a commit to reference refs/pull/204/head
in repository enlightenment.
View the commit online.
commit e8b21ae8f5bcd37310be3fa61f2fd7fbe62acadc
Author: Cedric BAIL <[email protected]>
AuthorDate: Mon Nov 23 21:43:23 2026 -0600
e_comp_wl - add zwp_idle_inhibit_manager_v1
A video player or a browser playing a film asks the compositor not to
blank the screen with this protocol. E does not advertise it, so on
Wayland the screen blanks in the middle of a film.
The protocol honours an inhibitor only while its surface is visible: a
film in an iconified window or on another desk must not keep the
screen on. Visibility changes without any input, so instead of
tracking it, E looks at the inhibitors when the idle timeout is
reached. If one has a visible surface the timeout starts again,
otherwise the screen idles as usual. The screen therefore idles at
most one timeout late after a film is hidden or stopped. Occlusion by
other windows is not taken into account.
An inhibitor created while the screensaver is already on does not
turn it off, as the protocol asks.
Only Wayland code is touched.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bin/e_comp_wl.c | 7 ++
src/bin/e_comp_wl.h | 5 ++
src/bin/e_comp_wl_extensions.c | 104 +++++++++++++++++++++++++++
src/bin/generated/meson.build | 1 +
src/tests/wayland/globals.expected | 1 +
src/tests/wayland/meson.build | 2 +
src/tests/wayland/test_idle_inhibit.c | 130 ++++++++++++++++++++++++++++++++++
7 files changed, 250 insertions(+)
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 140e92d73..40b27d833 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -4245,6 +4245,13 @@ _e_comp_wl_screensaver_idle_cb(void *data EINA_UNUSED)
{
screensaver_idle_timer = NULL;
if (e_screensaver_ignore_get()) return EINA_FALSE;
+ /* Whether an inhibitor's surface is visible can change at any time
+ * without input, so it is looked at when the timeout is reached. */
+ if (e_comp_wl_extension_idle_inhibited())
+ {
+ e_comp_wl_notidle();
+ return EINA_FALSE;
+ }
if (!saver_on)
{
saver_on = EINA_TRUE;
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index 1ac794975..1309a91b6 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -154,6 +154,10 @@ typedef struct E_Comp_Wl_Extension_Data
{
struct wl_global *global;
} xdg_activation_v1;
+ struct
+ {
+ struct wl_global *global;
+ } zwp_idle_inhibit_manager_v1;
} E_Comp_Wl_Extension_Data;
struct _E_Comp_Wl_Data
@@ -462,6 +466,7 @@ E_API Eina_Bool e_comp_wl_grab_client_mouse_move(const Ecore_Event_Mouse_Move *e
E_API Eina_Bool e_comp_wl_grab_client_mouse_button(const Ecore_Event_Mouse_Button *ev);
EINTERN void e_comp_wl_extension_xdg_output_update(E_Comp_Wl_Output *output);
+EINTERN Eina_Bool e_comp_wl_extension_idle_inhibited(void);
E_API void e_comp_wl_extension_relative_motion_event(uint64_t time_usec, double dx, double dy, double dx_unaccel, double dy_unaccel);
E_API void e_comp_wl_extension_pointer_constraints_commit(E_Client *ec);
E_API Eina_Bool e_comp_wl_extension_pointer_constraints_update(E_Client *ec, int x, int y);
diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index c177df7e1..240e9dc7b 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -9,6 +9,7 @@
#include "action_route-server-protocol.h"
#include "xdg-output-unstable-v1-server-protocol.h"
#include "xdg-activation-v1-server-protocol.h"
+#include "idle-inhibit-unstable-v1-server-protocol.h"
/* mutter uses 32, seems reasonable */
#define HANDLE_LEN 32
@@ -1286,6 +1287,107 @@ static const struct xdg_activation_v1_interface _e_xdg_activation_v1_interface =
.activate = _e_xdg_activation_v1_cb_activate,
};
+typedef struct Idle_Inhibitor
+{
+ struct wl_resource *surface;
+ struct wl_listener surface_destroy;
+} Idle_Inhibitor;
+
+static Eina_List *idle_inhibitors;
+
+/* The protocol honours an inhibitor only while its surface is visible.
+ * Occlusion by other windows is not taken into account. */
+EINTERN Eina_Bool
+e_comp_wl_extension_idle_inhibited(void)
+{
+ Idle_Inhibitor *inhibitor;
+ E_Client *ec;
+ Eina_List *l;
+
+ EINA_LIST_FOREACH(idle_inhibitors, l, inhibitor)
+ {
+ if (!inhibitor->surface) continue;
+ ec = wl_resource_get_user_data(inhibitor->surface);
+ if ((!ec) || (e_object_is_del(E_OBJECT(ec)))) continue;
+ if (evas_object_visible_get(ec->frame)) return EINA_TRUE;
+ }
+ return EINA_FALSE;
+}
+
+static void
+_e_zwp_idle_inhibitor_v1_cb_surface_destroy(struct wl_listener *listener, void *data EINA_UNUSED)
+{
+ Idle_Inhibitor *inhibitor = container_of(listener, Idle_Inhibitor, surface_destroy);
+
+ wl_list_remove(&inhibitor->surface_destroy.link);
+ inhibitor->surface = NULL;
+}
+
+static void
+_e_zwp_idle_inhibitor_v1_cb_resource_destroy(struct wl_resource *resource)
+{
+ Idle_Inhibitor *inhibitor = wl_resource_get_user_data(resource);
+
+ if (inhibitor->surface)
+ wl_list_remove(&inhibitor->surface_destroy.link);
+ idle_inhibitors = eina_list_remove(idle_inhibitors, inhibitor);
+ free(inhibitor);
+}
+
+static void
+_e_zwp_idle_inhibitor_v1_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static const struct zwp_idle_inhibitor_v1_interface _e_zwp_idle_inhibitor_v1_interface =
+{
+ _e_zwp_idle_inhibitor_v1_cb_destroy,
+};
+
+static void
+_e_zwp_idle_inhibit_manager_v1_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static void
+_e_zwp_idle_inhibit_manager_v1_cb_create_inhibitor(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface)
+{
+ Idle_Inhibitor *inhibitor;
+ struct wl_resource *res;
+
+ inhibitor = E_NEW(Idle_Inhibitor, 1);
+ if (!inhibitor)
+ {
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ res = wl_resource_create(client, &zwp_idle_inhibitor_v1_interface,
+ wl_resource_get_version(resource), id);
+ if (!res)
+ {
+ free(inhibitor);
+ wl_client_post_no_memory(client);
+ return;
+ }
+
+ inhibitor->surface = surface;
+ inhibitor->surface_destroy.notify = _e_zwp_idle_inhibitor_v1_cb_surface_destroy;
+ wl_resource_add_destroy_listener(surface, &inhibitor->surface_destroy);
+ idle_inhibitors = eina_list_append(idle_inhibitors, inhibitor);
+ wl_resource_set_implementation(res, &_e_zwp_idle_inhibitor_v1_interface,
+ inhibitor,
+ _e_zwp_idle_inhibitor_v1_cb_resource_destroy);
+}
+
+static const struct zwp_idle_inhibit_manager_v1_interface _e_zwp_idle_inhibit_manager_v1_interface =
+{
+ _e_zwp_idle_inhibit_manager_v1_cb_destroy,
+ _e_zwp_idle_inhibit_manager_v1_cb_create_inhibitor,
+};
+
#define GLOBAL_BIND_CB(NAME, IFACE, ...) \
static void \
_e_comp_wl_##NAME##_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t version, uint32_t id) \
@@ -1310,6 +1412,7 @@ GLOBAL_BIND_CB(zwp_relative_pointer_manager_v1, zwp_relative_pointer_manager_v1_
GLOBAL_BIND_CB(zwp_pointer_constraints_v1, zwp_pointer_constraints_v1_interface)
GLOBAL_BIND_CB(zxdg_output_manager_v1, zxdg_output_manager_v1_interface)
GLOBAL_BIND_CB(xdg_activation_v1, xdg_activation_v1_interface)
+GLOBAL_BIND_CB(zwp_idle_inhibit_manager_v1, zwp_idle_inhibit_manager_v1_interface)
GLOBAL_BIND_CB(action_route, action_route_interface,
e_binding_key_list_cb = _action_route_key_list_cb;
key_bindings = eina_hash_string_superfast_new(NULL);
@@ -1410,6 +1513,7 @@ e_comp_wl_extensions_init(void)
GLOBAL_CREATE_OR_RETURN(action_route, action_route_interface, 1);
GLOBAL_CREATE_OR_RETURN(zxdg_output_manager_v1, zxdg_output_manager_v1_interface, 3);
GLOBAL_CREATE_OR_RETURN(xdg_activation_v1, xdg_activation_v1_interface, 1);
+ GLOBAL_CREATE_OR_RETURN(zwp_idle_inhibit_manager_v1, zwp_idle_inhibit_manager_v1_interface, 1);
ecore_event_handler_add(ECORE_WL2_EVENT_SYNC_DONE, _dmabuf_add, NULL);
diff --git a/src/bin/generated/meson.build b/src/bin/generated/meson.build
index 4bc09f12c..d928e370d 100644
--- a/src/bin/generated/meson.build
+++ b/src/bin/generated/meson.build
@@ -8,6 +8,7 @@ protos = [
'@0@/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/xdg-output/xdg-output-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/staging/xdg-activation/xdg-activation-v1.xml'.format(dir_wayland_protocols),
+ '@0@/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/primary-selection/primary-selection-unstable-v1.xml'.format(dir_wayland_protocols),
]
diff --git a/src/tests/wayland/globals.expected b/src/tests/wayland/globals.expected
index 22740208e..2b42ab8e1 100644
--- a/src/tests/wayland/globals.expected
+++ b/src/tests/wayland/globals.expected
@@ -10,6 +10,7 @@ wl_subcompositor 1
xdg_activation_v1 1
xdg_wm_base 6
zwp_e_session_recovery 1
+zwp_idle_inhibit_manager_v1 1
zwp_pointer_constraints_v1 1
zwp_primary_selection_device_manager_v1 1
zwp_relative_pointer_manager_v1 1
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index 9f16a9d29..f749b4e97 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -30,6 +30,7 @@ foreach p: [
'@0@/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/xdg-output/xdg-output-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/staging/xdg-activation/xdg-activation-v1.xml'.format(dir_wayland_protocols),
+ '@0@/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
'@0@/unstable/primary-selection/primary-selection-unstable-v1.xml'.format(dir_wayland_protocols),
]
test_proto_src += gen_scanner_client.process(p)
@@ -78,6 +79,7 @@ wl_protocol_tests = [
['activation-expiry', 'test_activation.c',
{'E_TEST_ACTIVATION_TOKEN_LIFETIME': '1'}],
['primary-selection', 'test_primary_selection.c'],
+ ['idle-inhibit', 'test_idle_inhibit.c'],
['client-iconify', 'test_client_iconify.c',
{'ELM_TRANSITION_DURATION_FACTOR': '4'}],
]
diff --git a/src/tests/wayland/test_idle_inhibit.c b/src/tests/wayland/test_idle_inhibit.c
new file mode 100644
index 000000000..9d214555e
--- /dev/null
+++ b/src/tests/wayland/test_idle_inhibit.c
@@ -0,0 +1,130 @@
+/* zwp_idle_inhibitor_v1 keeps the screensaver off only while its surface
+ * is visible. */
+#include <stdio.h>
+#include <time.h>
+
+#include "e_wl_testkit.h"
+#include "idle-inhibit-unstable-v1-client-protocol.h"
+
+#define PROG "test-idle-inhibit"
+#define APP_ID "e.test.idle-inhibit"
+#define TIMEOUT 1
+#define MASK (WL_TEST_CLIENT_STATE_ICONIFIED | WL_TEST_CLIENT_STATE_VISIBLE)
+
+typedef struct
+{
+ Tk *tk;
+ struct wl_test *tester;
+ int on;
+} Saver;
+
+static void
+_screensaver(void *data, struct wl_test *t __attribute__((unused)), uint32_t on)
+{
+ Saver *saver = data;
+
+ saver->on = !!on;
+}
+
+/* Only the requests this test sends are answered on its own wl_test. */
+static const struct wl_test_listener _tester_listener =
+{
+ .screensaver = _screensaver
+};
+
+static int
+_saver_get(Saver *saver)
+{
+ saver->on = -1;
+ wl_test_get_screensaver(saver->tester);
+ tk_sync(saver->tk);
+ if (saver->on < 0) tk_fail(saver->tk, "no answer to get_screensaver");
+ return saver->on;
+}
+
+static void
+_saver_wait(Saver *saver, int on, const char *what)
+{
+ struct timespec step = { 0, 50000000 };
+ int i;
+
+ for (i = 0; i < TK_WAIT_SECONDS * 20; i++)
+ {
+ if (_saver_get(saver) == on) return;
+ nanosleep(&step, NULL);
+ }
+ tk_fail(saver->tk, "screensaver still %s: %s", on ? "off" : "on", what);
+}
+
+/* Nothing to wait for when the screensaver must stay off: wait well past
+ * its timeout and look. */
+static void
+_saver_stays_off(Saver *saver, const char *what)
+{
+ struct timespec wait = { (TIMEOUT * 2) + 1, 0 };
+
+ nanosleep(&wait, NULL);
+ if (_saver_get(saver)) tk_fail(saver->tk, "screensaver came on: %s", what);
+}
+
+static void
+_wake(Saver *saver)
+{
+ tk_pointer_move(saver->tk, 1, 0);
+ _saver_wait(saver, 0, "input wakes the screen");
+}
+
+int
+main(void)
+{
+ struct zwp_idle_inhibit_manager_v1 *manager;
+ struct zwp_idle_inhibitor_v1 *inhibitor;
+ struct wl_surface *bare;
+ Tk_Toplevel *top;
+ Saver saver;
+ unsigned int id;
+
+ saver.tk = tk_connect(PROG);
+ saver.tester = tk_bind(saver.tk, &wl_test_interface, 7);
+ manager = tk_bind(saver.tk, &zwp_idle_inhibit_manager_v1_interface, 1);
+ if ((!saver.tester) || (!manager)) tk_fail(saver.tk, "missing global");
+ wl_test_add_listener(saver.tester, &_tester_listener, &saver);
+ top = tk_toplevel_new(saver.tk, APP_ID, APP_ID, 200, 150);
+ id = tk_expect(saver.tk, APP_ID)->id;
+
+ wl_test_screensaver_configure(saver.tester, TIMEOUT);
+ _saver_wait(&saver, 1, "no inhibitor");
+ _wake(&saver);
+
+ inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(manager, tk_toplevel_surface(top));
+ tk_sync(saver.tk);
+ _saver_stays_off(&saver, "with an inhibitor on a visible window");
+
+ tk_action(saver.tk, id, "window_iconic_toggle", NULL);
+ tk_wait_states(saver.tk, APP_ID, MASK, WL_TEST_CLIENT_STATE_ICONIFIED, "iconified");
+ _saver_wait(&saver, 1, "the inhibiting window is iconified");
+
+ tk_action(saver.tk, id, "window_iconic_toggle", NULL);
+ tk_wait_states(saver.tk, APP_ID, MASK, WL_TEST_CLIENT_STATE_VISIBLE, "restored");
+ _wake(&saver);
+ _saver_stays_off(&saver, "the inhibiting window is shown again");
+
+ zwp_idle_inhibitor_v1_destroy(inhibitor);
+ _saver_wait(&saver, 1, "the inhibitor is destroyed");
+ _wake(&saver);
+
+ /* An unmapped surface inhibits nothing, and its inhibitor outlives it. */
+ bare = tk_surface_new(saver.tk);
+ inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(manager, bare);
+ tk_sync(saver.tk);
+ _saver_wait(&saver, 1, "the inhibiting surface is not mapped");
+ wl_surface_destroy(bare);
+ _wake(&saver);
+ _saver_wait(&saver, 1, "the inhibiting surface is destroyed");
+ zwp_idle_inhibitor_v1_destroy(inhibitor);
+ tk_sync(saver.tk);
+
+ tk_disconnect(saver.tk);
+ printf(PROG ": ok\n");
+ return 0;
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.