This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository enlightenment.
View the commit online.
commit 0ee7f31295136e51879dc057e61d4372d775f1f8
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 22 19:05:16 2026 -0600
e_comp_wl - add xdg_activation_v1
Without it, opening a link in a browser that is already running or
raising another application does nothing: the receiving client has no
way to ask for the focus.
A token only carries the right to take the focus if the client asking
for it held the focus at that moment. Otherwise any client could mint
a token and give itself the focus whenever it liked. A refused request
marks the window urgent, so the user still sees it. The serial a client
may offer is not used, because a click normally moves the focus to
that client first. A client that takes input without ever taking the
focus can therefore only mark the target urgent.
A token is good once and for 30 seconds, so one obtained while focused
cannot be saved for later. The table keeps the newest 32, because a
client can ask for as many as it wants. A committed token shares nothing
with the object that made it, as the two can be destroyed in any order.
What happens next follows window_activehint_policy, as
_NET_ACTIVE_WINDOW does on X11, so a user who told E to ignore these
requests is obeyed on both backends.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bin/e_comp_wl.h | 4 +
src/bin/e_comp_wl_extensions.c | 197 ++++++++++++++++++++++++++++++++
src/bin/generated/meson.build | 1 +
src/tests/wayland/globals.expected | 1 +
src/tests/wayland/meson.build | 4 +
src/tests/wayland/test_activation.c | 222 ++++++++++++++++++++++++++++++++++++
6 files changed, 429 insertions(+)
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index 8623c6684..36d16ff41 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -150,6 +150,10 @@ typedef struct E_Comp_Wl_Extension_Data
{
struct wl_global *global;
} zxdg_output_manager_v1;
+ struct
+ {
+ struct wl_global *global;
+ } xdg_activation_v1;
} E_Comp_Wl_Extension_Data;
struct _E_Comp_Wl_Data
diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index ffbc98375..c177df7e1 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -8,6 +8,7 @@
#include "pointer-constraints-unstable-v1-server-protocol.h"
#include "action_route-server-protocol.h"
#include "xdg-output-unstable-v1-server-protocol.h"
+#include "xdg-activation-v1-server-protocol.h"
/* mutter uses 32, seems reasonable */
#define HANDLE_LEN 32
@@ -1091,6 +1092,200 @@ static const struct zxdg_output_manager_v1_interface _e_zxdg_output_manager_v1_i
_e_zxdg_output_manager_v1_cb_xdg_output_get,
};
+/* A token is what lets one client give the focus to another, so it only
+ * carries that right if its maker held the focus when asking for it. Any other
+ * token can only mark the window urgent. A token is good once, for a limited
+ * time, and the table is bounded because a client can ask for any number. */
+#define ACTIVATION_TOKENS_MAX 32
+#define ACTIVATION_TOKEN_LIFETIME 30.0
+
+typedef struct Activation_Token
+{
+ char token[37]; /* uuid_unparse writes 36 + NUL */
+ double expires;
+ Eina_Bool may_focus E_BITFIELD;
+} Activation_Token;
+
+static Eina_List *xdg_activation_tokens;
+
+/* User data of a token object once committed: the string it produced outlives
+ * the object, so the two share nothing else. */
+static char xdg_activation_committed;
+
+static double
+_e_xdg_activation_token_lifetime(void)
+{
+#ifdef E_TESTS
+ const char *lifetime = getenv("E_TEST_ACTIVATION_TOKEN_LIFETIME");
+
+ if (lifetime) return atof(lifetime);
+#endif
+ return ACTIVATION_TOKEN_LIFETIME;
+}
+
+static Eina_Bool
+_e_xdg_activation_token_unused_check(struct wl_resource *resource)
+{
+ if (!wl_resource_get_user_data(resource)) return EINA_TRUE;
+ wl_resource_post_error(resource, XDG_ACTIVATION_TOKEN_V1_ERROR_ALREADY_USED,
+ "token has already been committed");
+ return EINA_FALSE;
+}
+
+static void
+_e_xdg_activation_token_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static void
+_e_xdg_activation_token_cb_set_serial(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t serial EINA_UNUSED, struct wl_resource *seat EINA_UNUSED)
+{
+ _e_xdg_activation_token_unused_check(resource);
+}
+
+static void
+_e_xdg_activation_token_cb_set_app_id(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, const char *app_id EINA_UNUSED)
+{
+ _e_xdg_activation_token_unused_check(resource);
+}
+
+static void
+_e_xdg_activation_token_cb_set_surface(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, struct wl_resource *surface EINA_UNUSED)
+{
+ _e_xdg_activation_token_unused_check(resource);
+}
+
+static void
+_e_xdg_activation_token_cb_commit(struct wl_client *client, struct wl_resource *resource)
+{
+ Activation_Token *t;
+ E_Client *focused;
+ uuid_t u;
+
+ if (!_e_xdg_activation_token_unused_check(resource)) return;
+
+ t = E_NEW(Activation_Token, 1);
+ uuid_generate(u);
+ uuid_unparse_lower(u, t->token);
+ t->expires = ecore_loop_time_get() + _e_xdg_activation_token_lifetime();
+ focused = e_client_focused_get();
+ t->may_focus = focused && focused->comp_data && focused->comp_data->surface &&
+ (wl_resource_get_client(focused->comp_data->surface) == client);
+
+ xdg_activation_tokens = eina_list_append(xdg_activation_tokens, t);
+ if (eina_list_count(xdg_activation_tokens) > ACTIVATION_TOKENS_MAX)
+ {
+ free(eina_list_data_get(xdg_activation_tokens));
+ xdg_activation_tokens = eina_list_remove_list(xdg_activation_tokens,
+ xdg_activation_tokens);
+ }
+
+ wl_resource_set_user_data(resource, &xdg_activation_committed);
+ xdg_activation_token_v1_send_done(resource, t->token);
+}
+
+/* Named: destroy comes last in this interface. */
+static const struct xdg_activation_token_v1_interface _e_xdg_activation_token_v1_interface =
+{
+ .set_serial = _e_xdg_activation_token_cb_set_serial,
+ .set_app_id = _e_xdg_activation_token_cb_set_app_id,
+ .set_surface = _e_xdg_activation_token_cb_set_surface,
+ .commit = _e_xdg_activation_token_cb_commit,
+ .destroy = _e_xdg_activation_token_cb_destroy,
+};
+
+static void
+_e_xdg_activation_v1_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static void
+_e_xdg_activation_v1_cb_get_activation_token(struct wl_client *client, struct wl_resource *resource, uint32_t id)
+{
+ struct wl_resource *res;
+
+ res = wl_resource_create(client, &xdg_activation_token_v1_interface,
+ wl_resource_get_version(resource), id);
+ if (!res)
+ {
+ wl_client_post_no_memory(client);
+ return;
+ }
+ wl_resource_set_implementation(res, &_e_xdg_activation_token_v1_interface,
+ NULL, NULL);
+}
+
+/* Removes the token from the table and hands it to the caller, dropping the
+ * expired ones met on the way. */
+static Activation_Token *
+_e_xdg_activation_token_take(const char *token)
+{
+ Activation_Token *t;
+ Eina_List *l, *ll;
+ double now = ecore_loop_time_get();
+
+ EINA_LIST_FOREACH_SAFE(xdg_activation_tokens, l, ll, t)
+ {
+ if (t->expires <= now)
+ {
+ xdg_activation_tokens = eina_list_remove_list(xdg_activation_tokens, l);
+ free(t);
+ }
+ else if (!strcmp(t->token, token))
+ {
+ xdg_activation_tokens = eina_list_remove_list(xdg_activation_tokens, l);
+ return t;
+ }
+ }
+ return NULL;
+}
+
+/* Follows the policy _NET_ACTIVE_WINDOW follows on X11. */
+static void
+_e_xdg_activation_client_activate(E_Client *ec, Eina_Bool may_focus)
+{
+ int policy = e_config->window_activehint_policy;
+
+ if (policy == E_ACTIVEHINT_POLICY_IGNORE) return;
+ if ((!may_focus) || (policy == E_ACTIVEHINT_POLICY_ANIMATE) ||
+ e_client_action_get() || e_comp->nocomp ||
+ ((policy == E_ACTIVEHINT_POLICY_ACTIVATE_EXCLUDE) && (!ec->desk->visible)))
+ e_client_urgent_set(ec, 1);
+ else if (ec->focused)
+ evas_object_raise(ec->frame);
+ else
+ e_client_activate(ec, EINA_TRUE);
+}
+
+static void
+_e_xdg_activation_v1_cb_activate(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED, const char *token, struct wl_resource *surface)
+{
+ Activation_Token *t;
+ Eina_Bool may_focus;
+ E_Client *ec;
+
+ /* The protocol lets a compositor ignore an unknown token. */
+ if (!(t = _e_xdg_activation_token_take(token))) return;
+ may_focus = t->may_focus;
+ free(t);
+
+ ec = wl_resource_get_user_data(surface);
+ if ((!ec) || e_object_is_del(E_OBJECT(ec))) return;
+ if ((!ec->comp_data->mapped) || (!ec->comp_data->shell.surface) ||
+ e_client_util_is_popup(ec))
+ return;
+ _e_xdg_activation_client_activate(ec, may_focus);
+}
+
+static const struct xdg_activation_v1_interface _e_xdg_activation_v1_interface =
+{
+ .destroy = _e_xdg_activation_v1_cb_destroy,
+ .get_activation_token = _e_xdg_activation_v1_cb_get_activation_token,
+ .activate = _e_xdg_activation_v1_cb_activate,
+};
+
#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) \
@@ -1114,6 +1309,7 @@ GLOBAL_BIND_CB(zxdg_importer_v1, zxdg_importer_v1_interface)
GLOBAL_BIND_CB(zwp_relative_pointer_manager_v1, zwp_relative_pointer_manager_v1_interface)
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(action_route, action_route_interface,
e_binding_key_list_cb = _action_route_key_list_cb;
key_bindings = eina_hash_string_superfast_new(NULL);
@@ -1213,6 +1409,7 @@ e_comp_wl_extensions_init(void)
e_comp_wl->extensions->zwp_pointer_constraints_v1.constraints = eina_hash_pointer_new(NULL);
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);
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 c7672156b..f291b057b 100644
--- a/src/bin/generated/meson.build
+++ b/src/bin/generated/meson.build
@@ -7,6 +7,7 @@ protos = [
'@0@/unstable/relative-pointer/relative-pointer-unstable-v1.xml'.format(dir_wayland_protocols),
'@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),
]
proto_c = []
diff --git a/src/tests/wayland/globals.expected b/src/tests/wayland/globals.expected
index 61e95e9c7..72a18fa9d 100644
--- a/src/tests/wayland/globals.expected
+++ b/src/tests/wayland/globals.expected
@@ -7,6 +7,7 @@ wl_seat 8
wl_shell 1
wl_shm >=1
wl_subcompositor 1
+xdg_activation_v1 1
xdg_wm_base 6
zwp_e_session_recovery 1
zwp_pointer_constraints_v1 1
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index d23d6567f..72bce326a 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -29,6 +29,7 @@ foreach p: [
'@0@/unstable/xdg-foreign/xdg-foreign-unstable-v1.xml'.format(dir_wayland_protocols),
'@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),
]
test_proto_src += gen_scanner_client.process(p)
test_proto_src += gen_scanner_impl.process(p)
@@ -72,6 +73,9 @@ wl_protocol_tests = [
['xdg-decoration', 'test_xdg_decoration.c'],
['shm-truncate', 'test_shm_truncate.c'],
['output', 'test_output.c'],
+ ['activation', 'test_activation.c'],
+ ['activation-expiry', 'test_activation.c',
+ {'E_TEST_ACTIVATION_TOKEN_LIFETIME': '1'}],
['client-iconify', 'test_client_iconify.c',
{'ELM_TRANSITION_DURATION_FACTOR': '4'}],
]
diff --git a/src/tests/wayland/test_activation.c b/src/tests/wayland/test_activation.c
new file mode 100644
index 000000000..546a31b3c
--- /dev/null
+++ b/src/tests/wayland/test_activation.c
@@ -0,0 +1,222 @@
+/* xdg_activation_v1 between two clients: who may hand the focus over, and
+ * how long and how often a token is good for. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "e_wl_testkit.h"
+#include "xdg-activation-v1-client-protocol.h"
+
+#define PROG "test-activation"
+#define APP_A "e.test.activation.a"
+#define APP_B "e.test.activation.b"
+#define TOKENS_MAX 32
+#define FOCUS WL_TEST_CLIENT_STATE_FOCUSED
+#define URGENT WL_TEST_CLIENT_STATE_URGENT
+
+typedef struct
+{
+ Tk *tk;
+ struct xdg_activation_v1 *activation;
+ Tk_Toplevel *top;
+ const char *app_id;
+} Peer;
+
+typedef struct
+{
+ char str[64];
+ int dones;
+} Token;
+
+static void
+_token_done(void *data, struct xdg_activation_token_v1 *o __attribute__((unused)),
+ const char *token)
+{
+ Token *t = data;
+
+ snprintf(t->str, sizeof(t->str), "%s", token);
+ t->dones++;
+}
+
+static const struct xdg_activation_token_v1_listener _token_listener =
+{
+ _token_done
+};
+
+static struct xdg_activation_token_v1 *
+_token_commit(Peer *p, Token *t)
+{
+ struct xdg_activation_token_v1 *obj;
+
+ memset(t, 0, sizeof(*t));
+ obj = xdg_activation_v1_get_activation_token(p->activation);
+ xdg_activation_token_v1_add_listener(obj, &_token_listener, t);
+ xdg_activation_token_v1_commit(obj);
+ tk_sync(p->tk);
+ if (t->dones != 1) tk_fail(p->tk, "%d done events for a token", t->dones);
+ if (!t->str[0]) tk_fail(p->tk, "empty token");
+ return obj;
+}
+
+static void
+_token_new(Peer *p, Token *t)
+{
+ xdg_activation_token_v1_destroy(_token_commit(p, t));
+ tk_sync(p->tk);
+}
+
+static void
+_activate(Peer *p, const char *token)
+{
+ xdg_activation_v1_activate(p->activation, token, tk_toplevel_surface(p->top));
+ tk_settle(p->tk);
+}
+
+static void
+_peer_new(Peer *p, const char *app_id)
+{
+ p->tk = tk_connect(PROG);
+ p->app_id = app_id;
+ p->top = tk_toplevel_new(p->tk, app_id, app_id, 200, 150);
+ p->activation = tk_bind(p->tk, &xdg_activation_v1_interface, 1);
+ if (!p->activation) tk_fail(p->tk, "no xdg_activation_v1");
+}
+
+static void
+_expect_focus(Peer *p, Peer *other, const char *what)
+{
+ tk_wait_states(p->tk, p->app_id, FOCUS, FOCUS, what);
+ tk_wait_states(other->tk, other->app_id, FOCUS, 0, what);
+}
+
+static void
+_expect_refused(Peer *focused, Peer *p, unsigned int urgent, const char *what)
+{
+ tk_sync(p->tk);
+ tk_wait_states(focused->tk, focused->app_id, FOCUS, FOCUS, what);
+ tk_wait_states(p->tk, p->app_id, FOCUS | URGENT, urgent, what);
+}
+
+static void
+_test_double_commit(void)
+{
+ const struct wl_interface *iface = NULL;
+ struct xdg_activation_v1 *activation;
+ struct xdg_activation_token_v1 *obj;
+ Token t = { "", 0 };
+ Tk *tk;
+
+ tk = tk_connect(PROG);
+ activation = tk_bind(tk, &xdg_activation_v1_interface, 1);
+ obj = xdg_activation_v1_get_activation_token(activation);
+ xdg_activation_token_v1_add_listener(obj, &_token_listener, &t);
+ xdg_activation_token_v1_commit(obj);
+ xdg_activation_token_v1_commit(obj);
+ if ((tk_protocol_error(tk, &iface) != XDG_ACTIVATION_TOKEN_V1_ERROR_ALREADY_USED) ||
+ (iface != &xdg_activation_token_v1_interface))
+ tk_fail(tk, "a second commit is not an already_used error");
+ tk_disconnect(tk);
+}
+
+static void
+_test_set_after_commit(void)
+{
+ const struct wl_interface *iface = NULL;
+ struct xdg_activation_v1 *activation;
+ struct xdg_activation_token_v1 *obj;
+ Token t = { "", 0 };
+ Tk *tk;
+
+ tk = tk_connect(PROG);
+ activation = tk_bind(tk, &xdg_activation_v1_interface, 1);
+ obj = xdg_activation_v1_get_activation_token(activation);
+ xdg_activation_token_v1_add_listener(obj, &_token_listener, &t);
+ xdg_activation_token_v1_commit(obj);
+ xdg_activation_token_v1_set_app_id(obj, "too.late");
+ if ((tk_protocol_error(tk, &iface) != XDG_ACTIVATION_TOKEN_V1_ERROR_ALREADY_USED) ||
+ (iface != &xdg_activation_token_v1_interface))
+ tk_fail(tk, "set_app_id after commit is not an already_used error");
+ tk_disconnect(tk);
+}
+
+static void
+_test_expiry(Peer *a, Peer *b)
+{
+ struct timespec wait = { 1, 200000000 };
+ Token t;
+
+ _token_new(b, &t);
+ nanosleep(&wait, NULL);
+ tk_sync(a->tk);
+ _activate(a, t.str);
+ _expect_refused(b, a, 0, "an expired token");
+}
+
+int
+main(void)
+{
+ struct xdg_activation_token_v1 *obj;
+ Peer a, b;
+ Token t, t2, first;
+ int i;
+
+ _peer_new(&a, APP_A);
+ _peer_new(&b, APP_B);
+ _expect_focus(&b, &a, "the newest window has the focus");
+
+ if (getenv("E_TEST_ACTIVATION_TOKEN_LIFETIME"))
+ {
+ _test_expiry(&a, &b);
+ printf(PROG ": ok (expiry)\n");
+ tk_disconnect(b.tk);
+ tk_disconnect(a.tk);
+ return 0;
+ }
+
+ /* The focused client hands the focus over, from a token object it
+ * already destroyed. */
+ _token_new(&b, &t);
+ _activate(&a, t.str);
+ _expect_focus(&a, &b, "a token from the focused client");
+
+ /* Back, and the first token is spent. */
+ _token_new(&a, &t2);
+ if (!strcmp(t.str, t2.str)) tk_fail(a.tk, "two tokens are identical");
+ _activate(&b, t2.str);
+ _expect_focus(&b, &a, "a second token");
+ _activate(&a, t.str);
+ _expect_refused(&b, &a, 0, "a token used twice");
+
+ _activate(&a, "never-issued");
+ _expect_refused(&b, &a, 0, "an unknown token");
+
+ /* A client without the focus cannot give it to itself. */
+ _token_new(&a, &t);
+ _activate(&a, t.str);
+ _expect_refused(&b, &a, URGENT, "a token from an unfocused client");
+
+ /* The maker may destroy its object after the token was used. */
+ obj = _token_commit(&b, &t);
+ _activate(&a, t.str);
+ _expect_focus(&a, &b, "a token used before its object is gone");
+ tk_wait_states(a.tk, APP_A, URGENT, 0, "focus ended the urgency");
+ xdg_activation_token_v1_destroy(obj);
+ tk_sync(b.tk);
+
+ /* The table is bounded: the oldest token goes first. */
+ _token_new(&a, &first);
+ for (i = 0; i < TOKENS_MAX; i++) _token_new(&a, &t);
+ _activate(&b, first.str);
+ _expect_refused(&a, &b, 0, "a token pushed out of the table");
+ _activate(&b, t.str);
+ _expect_focus(&b, &a, "the newest token");
+
+ _test_double_commit();
+ _test_set_after_commit();
+
+ printf(PROG ": ok\n");
+ tk_disconnect(b.tk);
+ tk_disconnect(a.tk);
+ return 0;
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.