This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch up/10-browser
in repository enlightenment.
View the commit online.
commit c8418ffb9f896b793c6ec5a4600dbd1c429d9fb6
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 24 19:43:13 2026 -0600
e_comp_wl - add zwp_keyboard_shortcuts_inhibit_manager_v1
A remote desktop, a virtual machine viewer or a browser in fullscreen
wants every key, including the ones E binds, such as Alt+Tab. With this
protocol the client asks for them, and E skips its key bindings while
the inhibiting surface has the keyboard focus.
The protocol lets the compositor keep a key that restores its own
shortcuts against a client that will not let go. That is a new action,
shortcuts_inhibit_toggle, bound to Super+Escape in the standard and
tiling profiles, as in GNOME. It is never inhibited. It turns the
focused surface's inhibitor off, which the client is told with an
inactive event, and on again with active. Existing configurations do not
get the binding: it can be added in the key binding settings.
The skip is in _key_down() and _key_up() in e_comp_canvas.c, which run
on both backends for the compositor and manager key handlers. It only
asks the Wayland side when E is a Wayland compositor, so X11 behaves as
before; x11-key-binding covers that path. Up and down are skipped
alike, so that the client gets the release of every key it got pressed.
Losing the keyboard focus ends an inhibitor without an inactive event,
as the protocol says, and getting it back sends active again. E has a
single seat, so the seat argument is not needed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
data/config/standard/e_bindings.src | 7 +
data/config/tiling/e_bindings.src | 7 +
data/config/wltest/e_bindings.src | 7 +
src/bin/e_comp_canvas.c | 19 ++-
src/bin/e_comp_wl.c | 2 +
src/bin/e_comp_wl.h | 9 ++
src/bin/e_comp_wl_extensions.c | 108 +++++++++++++++
src/bin/generated/meson.build | 1 +
src/tests/wayland/globals.expected | 1 +
src/tests/wayland/meson.build | 2 +
src/tests/wayland/test_shortcuts_inhibit.c | 215 +++++++++++++++++++++++++++++
11 files changed, 376 insertions(+), 2 deletions(-)
diff --git a/data/config/standard/e_bindings.src b/data/config/standard/e_bindings.src
index 26d0d9311..9b55f457e 100644
--- a/data/config/standard/e_bindings.src
+++ b/data/config/standard/e_bindings.src
@@ -783,6 +783,13 @@ group "E_Config_Bindings" struct {
value "action" string: "everything";
value "any_mod" uchar: 0;
}
+ group "E_Config_Binding_Key" struct {
+ value "context" int: 9;
+ value "modifiers" int: 8;
+ value "key" string: "Escape";
+ value "action" string: "shortcuts_inhibit_toggle";
+ value "any_mod" uchar: 0;
+ }
group "E_Config_Binding_Key" struct {
value "context" int: 9;
value "modifiers" int: 6;
diff --git a/data/config/tiling/e_bindings.src b/data/config/tiling/e_bindings.src
index a90d990c4..20ac49d2d 100644
--- a/data/config/tiling/e_bindings.src
+++ b/data/config/tiling/e_bindings.src
@@ -731,6 +731,13 @@ group "E_Config_Bindings" struct {
value "action" string: "everything";
value "any_mod" uchar: 0;
}
+ group "E_Config_Binding_Key" struct {
+ value "context" int: 9;
+ value "modifiers" int: 8;
+ value "key" string: "Escape";
+ value "action" string: "shortcuts_inhibit_toggle";
+ value "any_mod" uchar: 0;
+ }
group "E_Config_Binding_Key" struct {
value "context" int: 9;
value "modifiers" int: 6;
diff --git a/data/config/wltest/e_bindings.src b/data/config/wltest/e_bindings.src
index 5f5e12a4a..a2499384a 100644
--- a/data/config/wltest/e_bindings.src
+++ b/data/config/wltest/e_bindings.src
@@ -11,6 +11,13 @@ group "E_Config_Bindings" struct {
}
}
group "key_bindings" list {
+ group "E_Config_Binding_Key" struct {
+ value "context" int: 9;
+ value "modifiers" int: 8;
+ value "key" string: "Escape";
+ value "action" string: "shortcuts_inhibit_toggle";
+ value "any_mod" uchar: 0;
+ }
group "E_Config_Binding_Key" struct {
value "context" int: 9;
value "modifiers" int: 8;
diff --git a/src/bin/e_comp_canvas.c b/src/bin/e_comp_canvas.c
index 9366e4449..1812989f7 100644
--- a/src/bin/e_comp_canvas.c
+++ b/src/bin/e_comp_canvas.c
@@ -175,6 +175,19 @@ _e_comp_canvas_cb_mouse_wheel(void *d EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Obj
e_bindings_wheel_evas_event_handle(E_BINDING_CONTEXT_COMPOSITOR, E_OBJECT(e_comp), event_info);
}
+/* A Wayland client can ask for the keys E would take for its bindings. */
+static Eina_Bool
+_e_comp_canvas_shortcuts_inhibited(int ctx, Ecore_Event_Key *ev)
+{
+#ifdef HAVE_WAYLAND
+ if (e_comp->comp_type == E_PIXMAP_TYPE_WL)
+ return e_comp_wl_shortcuts_inhibited(ctx, ev);
+#endif
+ (void)ctx;
+ (void)ev;
+ return EINA_FALSE;
+}
+
static Eina_Bool
_key_down(int ctx, Ecore_Event_Key *ev)
{
@@ -206,7 +219,8 @@ _key_down(int ctx, Ecore_Event_Key *ev)
}
return ((!e_comp->screen) ||
(!e_comp->screen->key_down) || (!e_comp->screen->key_down(ev))) &&
- !e_bindings_key_down_event_handle(ctx, E_OBJECT(e_comp), ev)
+ (_e_comp_canvas_shortcuts_inhibited(ctx, ev) ||
+ !e_bindings_key_down_event_handle(ctx, E_OBJECT(e_comp), ev))
#ifdef HAVE_WAYLAND
&& !e_comp_wl_key_down(ev, NULL)
#endif
@@ -244,7 +258,8 @@ _key_up(int ctx, Ecore_Event_Key *ev)
if ((e_comp->comp_type == E_PIXMAP_TYPE_X) && (ev->event_window != e_comp->root)) return ECORE_CALLBACK_PASS_ON;
return ((!e_comp->screen) ||
(!e_comp->screen->key_up) || (!e_comp->screen->key_up(ev))) &&
- !e_bindings_key_up_event_handle(ctx, E_OBJECT(e_comp), ev)
+ (_e_comp_canvas_shortcuts_inhibited(ctx, ev) ||
+ !e_bindings_key_up_event_handle(ctx, E_OBJECT(e_comp), ev))
#ifdef HAVE_WAYLAND
&& !e_comp_wl_key_up(ev, NULL)
#endif
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index ffcf85633..919c1d193 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -2977,6 +2977,8 @@ _e_comp_wl_client_cb_del(void *data EINA_UNUSED, E_Client *ec)
if (ec == e_comp_wl->wl.client_ec)
e_comp_wl->wl.client_ec = NULL;
e_comp_wl_extension_pointer_unconstrain(ec);
+ if (ec->comp_data->shortcuts_inhibitor)
+ wl_resource_set_user_data(ec->comp_data->shortcuts_inhibitor, NULL);
_e_comp_wl_touch_points_drop(ec);
/* remove sub list */
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index af77523be..40d87be21 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -171,6 +171,10 @@ typedef struct E_Comp_Wl_Extension_Data
{
struct wl_global *global;
} wp_presentation;
+ struct
+ {
+ struct wl_global *global;
+ } zwp_keyboard_shortcuts_inhibit_manager_v1;
} E_Comp_Wl_Extension_Data;
struct _E_Comp_Wl_Data
@@ -377,6 +381,10 @@ struct _E_Comp_Wl_Client_Data
Eina_List *presentation_feedbacks;
Eina_Bool presentation_late E_BITFIELD;
Eina_List *constraints;
+ /* The zwp_keyboard_shortcuts_inhibitor_v1 of this surface, and whether
+ * the user turned it off with the shortcuts_inhibit_toggle action. */
+ struct wl_resource *shortcuts_inhibitor;
+ Eina_Bool shortcuts_inhibitor_off E_BITFIELD;
struct
{
@@ -487,6 +495,7 @@ EINTERN void e_comp_wl_extension_xdg_output_update(E_Comp_Wl_Output *output);
/* Each wp_presentation_feedback ends with exactly one of presented or
* discarded. These take the list, leave it empty and destroy the
* resources. */
+EINTERN Eina_Bool e_comp_wl_shortcuts_inhibited(E_Binding_Context ctxt, Ecore_Event_Key *ev);
EINTERN void e_comp_wl_presentation_feedback_present(E_Client *ec);
EINTERN void e_comp_wl_presentation_feedback_discard(Eina_List **feedbacks);
EINTERN void e_comp_wl_presentation_feedback_commit(E_Client *ec, Eina_List **feedbacks);
diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index 21d1d299b..8282c2474 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -12,6 +12,7 @@
#include "xdg-activation-v1-server-protocol.h"
#include "idle-inhibit-unstable-v1-server-protocol.h"
#include "presentation-time-server-protocol.h"
+#include "keyboard-shortcuts-inhibit-unstable-v1-server-protocol.h"
/* mutter uses 32, seems reasonable */
#define HANDLE_LEN 32
@@ -112,10 +113,14 @@ _constraints_deactivate(E_Client *ec)
}
}
+/* active is sent each time an inhibitor comes into force. Losing the
+ * focus ends it without an inactive event, as the protocol says. */
static void
_e_comp_wl_extensions_client_focus_set(void *d EINA_UNUSED, E_Client *ec)
{
_constraints_activate(ec);
+ if ((ec->comp_data->shortcuts_inhibitor) && (!ec->comp_data->shortcuts_inhibitor_off))
+ zwp_keyboard_shortcuts_inhibitor_v1_send_active(ec->comp_data->shortcuts_inhibitor);
}
static void
@@ -1582,6 +1587,101 @@ static const struct wp_presentation_interface _e_wp_presentation_interface =
_e_wp_presentation_cb_feedback,
};
+static E_Action *shortcuts_inhibit_toggle_action;
+
+/* The toggle binding always reaches E, so that the user can take the
+ * keys back from a client that will not let go. */
+EINTERN Eina_Bool
+e_comp_wl_shortcuts_inhibited(E_Binding_Context ctxt, Ecore_Event_Key *ev)
+{
+ E_Client *ec = e_client_focused_get();
+
+ if ((!ec) || (e_object_is_del(E_OBJECT(ec)))) return EINA_FALSE;
+ if ((!ec->comp_data->shortcuts_inhibitor) || (ec->comp_data->shortcuts_inhibitor_off))
+ return EINA_FALSE;
+ return e_bindings_key_event_find(ctxt, ev, NULL) != shortcuts_inhibit_toggle_action;
+}
+
+static void
+_e_comp_wl_shortcuts_inhibit_toggle_go(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
+{
+ E_Client *ec = e_client_focused_get();
+ struct wl_resource *res;
+
+ if ((!ec) || (e_object_is_del(E_OBJECT(ec)))) return;
+ res = ec->comp_data->shortcuts_inhibitor;
+ if (!res) return;
+ ec->comp_data->shortcuts_inhibitor_off = !ec->comp_data->shortcuts_inhibitor_off;
+ if (ec->comp_data->shortcuts_inhibitor_off)
+ zwp_keyboard_shortcuts_inhibitor_v1_send_inactive(res);
+ else
+ zwp_keyboard_shortcuts_inhibitor_v1_send_active(res);
+}
+
+static void
+_e_zwp_keyboard_shortcuts_inhibitor_v1_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static const struct zwp_keyboard_shortcuts_inhibitor_v1_interface _e_zwp_keyboard_shortcuts_inhibitor_v1_interface =
+{
+ _e_zwp_keyboard_shortcuts_inhibitor_v1_cb_destroy,
+};
+
+static void
+_e_zwp_keyboard_shortcuts_inhibitor_v1_cb_resource_destroy(struct wl_resource *resource)
+{
+ E_Client *ec = wl_resource_get_user_data(resource);
+
+ if (!ec) return;
+ ec->comp_data->shortcuts_inhibitor = NULL;
+ ec->comp_data->shortcuts_inhibitor_off = EINA_FALSE;
+}
+
+static void
+_e_zwp_keyboard_shortcuts_inhibit_manager_v1_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+/* E has a single seat, so the seat argument is not needed. */
+static void
+_e_zwp_keyboard_shortcuts_inhibit_manager_v1_cb_inhibit_shortcuts(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface, struct wl_resource *seat EINA_UNUSED)
+{
+ E_Client *ec = wl_resource_get_user_data(surface);
+ struct wl_resource *res;
+
+ if ((ec) && (ec->comp_data->shortcuts_inhibitor))
+ {
+ wl_resource_post_error(resource,
+ ZWP_KEYBOARD_SHORTCUTS_INHIBIT_MANAGER_V1_ERROR_ALREADY_INHIBITED,
+ "shortcuts are already inhibited for this surface");
+ return;
+ }
+
+ res = wl_resource_create(client, &zwp_keyboard_shortcuts_inhibitor_v1_interface,
+ wl_resource_get_version(resource), id);
+ if (!res)
+ {
+ wl_resource_post_no_memory(resource);
+ return;
+ }
+ wl_resource_set_implementation(res, &_e_zwp_keyboard_shortcuts_inhibitor_v1_interface, ec,
+ _e_zwp_keyboard_shortcuts_inhibitor_v1_cb_resource_destroy);
+ /* Inert when the surface's window is already gone. */
+ if (!ec) return;
+ ec->comp_data->shortcuts_inhibitor = res;
+ if (ec == e_client_focused_get())
+ zwp_keyboard_shortcuts_inhibitor_v1_send_active(res);
+}
+
+static const struct zwp_keyboard_shortcuts_inhibit_manager_v1_interface _e_zwp_keyboard_shortcuts_inhibit_manager_v1_interface =
+{
+ _e_zwp_keyboard_shortcuts_inhibit_manager_v1_cb_destroy,
+ _e_zwp_keyboard_shortcuts_inhibit_manager_v1_cb_inhibit_shortcuts,
+};
+
#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) \
@@ -1609,6 +1709,7 @@ 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(zwp_keyboard_shortcuts_inhibit_manager_v1, zwp_keyboard_shortcuts_inhibit_manager_v1_interface)
GLOBAL_BIND_CB(wp_presentation, wp_presentation_interface,
wp_presentation_send_clock_id(res, CLOCK_MONOTONIC);
)
@@ -1716,6 +1817,7 @@ e_comp_wl_extensions_init(void)
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);
GLOBAL_CREATE_OR_RETURN(wp_presentation, wp_presentation_interface, 1);
+ GLOBAL_CREATE_OR_RETURN(zwp_keyboard_shortcuts_inhibit_manager_v1, zwp_keyboard_shortcuts_inhibit_manager_v1_interface, 1);
ecore_event_handler_add(ECORE_WL2_EVENT_SYNC_DONE, _dmabuf_add, NULL);
@@ -1725,6 +1827,12 @@ e_comp_wl_extensions_init(void)
e_client_hook_add(E_CLIENT_HOOK_FOCUS_SET, _e_comp_wl_extensions_client_focus_set, NULL);
e_client_hook_add(E_CLIENT_HOOK_FOCUS_UNSET, _e_comp_wl_extensions_client_focus_unset, NULL);
+ shortcuts_inhibit_toggle_action = e_action_add("shortcuts_inhibit_toggle");
+ shortcuts_inhibit_toggle_action->func.go = _e_comp_wl_shortcuts_inhibit_toggle_go;
+ e_action_predef_name_set(N_("Window : Actions"),
+ N_("Toggle Keyboard Shortcuts Inhibited By Window"),
+ "shortcuts_inhibit_toggle", NULL, NULL, 0);
+
act = e_action_add("key_route");
act->func.go_key = _e_comp_wl_action_route_act_key_route_go;
act->func.end_key = _e_comp_wl_action_route_act_key_route_go_end;
diff --git a/src/bin/generated/meson.build b/src/bin/generated/meson.build
index 161b3d2a4..89c671fc5 100644
--- a/src/bin/generated/meson.build
+++ b/src/bin/generated/meson.build
@@ -10,6 +10,7 @@ protos = [
'@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@/stable/presentation-time/presentation-time.xml'.format(dir_wayland_protocols),
+ '@0@/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-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 c9aab5609..f349ecb19 100644
--- a/src/tests/wayland/globals.expected
+++ b/src/tests/wayland/globals.expected
@@ -12,6 +12,7 @@ xdg_activation_v1 1
xdg_wm_base 6
zwp_e_session_recovery 1
zwp_idle_inhibit_manager_v1 1
+zwp_keyboard_shortcuts_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 d969c9706..e0e204502 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -32,6 +32,7 @@ foreach p: [
'@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@/stable/presentation-time/presentation-time.xml'.format(dir_wayland_protocols),
+ '@0@/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-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),
]
@@ -60,6 +61,7 @@ wl_protocol_tests = [
['xdg-foreign', 'test_xdg_foreign.c'],
['xdg-foreign-v2', 'test_xdg_foreign_v2.c'],
['presentation-time', 'test_presentation_time.c'],
+ ['shortcuts-inhibit', 'test_shortcuts_inhibit.c'],
['seat-capabilities', 'test_seat_capabilities.c'],
['dialog-focus', 'test_dialog_focus.c'],
['buffer-release', 'test_buffer_release.c'],
diff --git a/src/tests/wayland/test_shortcuts_inhibit.c b/src/tests/wayland/test_shortcuts_inhibit.c
new file mode 100644
index 000000000..17cb63a25
--- /dev/null
+++ b/src/tests/wayland/test_shortcuts_inhibit.c
@@ -0,0 +1,215 @@
+/* zwp_keyboard_shortcuts_inhibitor_v1: while it is in force, the keys of
+ * E's bindings go to the client, except the shortcuts_inhibit_toggle
+ * binding, which takes them back. The test profile binds Super+Escape to
+ * that toggle and Super+i to window_maximized_toggle. */
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/input-event-codes.h>
+
+#include "e_wl_testkit.h"
+#include "keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h"
+
+#define PROG "test-shortcuts-inhibit"
+#define APP_A "e.test.shortcuts.a"
+#define APP_B "e.test.shortcuts.b"
+#define APP_C "e.test.shortcuts.c"
+#define FOCUS WL_TEST_CLIENT_STATE_FOCUSED
+#define MAX (WL_TEST_CLIENT_STATE_MAXIMIZED_H | WL_TEST_CLIENT_STATE_MAXIMIZED_V)
+
+typedef struct
+{
+ Tk *tk;
+ Tk_Toplevel *top;
+ const char *app_id;
+ struct wl_seat *seat;
+ struct zwp_keyboard_shortcuts_inhibit_manager_v1 *manager;
+ int presses[KEY_MAX], releases[KEY_MAX];
+} Peer;
+
+static Tk *tester_tk;
+static struct wl_test *tester;
+static int actives, inactives;
+
+static void
+_keymap(void *d __attribute__((unused)), struct wl_keyboard *k __attribute__((unused)),
+ uint32_t format __attribute__((unused)), int32_t fd, uint32_t size __attribute__((unused)))
+{
+ close(fd);
+}
+
+static void
+_enter(void *d __attribute__((unused)), struct wl_keyboard *k __attribute__((unused)),
+ uint32_t serial __attribute__((unused)), struct wl_surface *s __attribute__((unused)),
+ struct wl_array *keys __attribute__((unused)))
+{
+}
+
+static void
+_leave(void *d __attribute__((unused)), struct wl_keyboard *k __attribute__((unused)),
+ uint32_t serial __attribute__((unused)), struct wl_surface *s __attribute__((unused)))
+{
+}
+
+static void
+_key(void *data, struct wl_keyboard *k __attribute__((unused)),
+ uint32_t serial __attribute__((unused)), uint32_t time __attribute__((unused)),
+ uint32_t key, uint32_t state)
+{
+ Peer *p = data;
+
+ if (key >= KEY_MAX) return;
+ if (state == WL_KEYBOARD_KEY_STATE_PRESSED) p->presses[key]++;
+ else p->releases[key]++;
+}
+
+static void
+_modifiers(void *d __attribute__((unused)), struct wl_keyboard *k __attribute__((unused)),
+ uint32_t serial __attribute__((unused)), uint32_t dep __attribute__((unused)),
+ uint32_t lat __attribute__((unused)), uint32_t lock __attribute__((unused)),
+ uint32_t group __attribute__((unused)))
+{
+}
+
+static const struct wl_keyboard_listener _keyboard_listener =
+{
+ _keymap, _enter, _leave, _key, _modifiers
+};
+
+static void
+_active(void *d __attribute__((unused)), struct zwp_keyboard_shortcuts_inhibitor_v1 *i __attribute__((unused)))
+{
+ actives++;
+}
+
+static void
+_inactive(void *d __attribute__((unused)), struct zwp_keyboard_shortcuts_inhibitor_v1 *i __attribute__((unused)))
+{
+ inactives++;
+}
+
+static const struct zwp_keyboard_shortcuts_inhibitor_v1_listener _inhibitor_listener =
+{
+ _active, _inactive
+};
+
+static void
+_peer_new(Peer *p, const char *app_id)
+{
+ memset(p, 0, sizeof(*p));
+ p->tk = tk_connect(PROG);
+ p->app_id = app_id;
+ p->seat = tk_bind(p->tk, &wl_seat_interface, 1);
+ p->manager = tk_bind(p->tk, &zwp_keyboard_shortcuts_inhibit_manager_v1_interface, 1);
+ if ((!p->seat) || (!p->manager)) tk_fail(p->tk, "missing global");
+ wl_keyboard_add_listener(wl_seat_get_keyboard(p->seat), &_keyboard_listener, p);
+ p->top = tk_toplevel_new(p->tk, app_id, app_id, 200, 150);
+ tk_wait_states(p->tk, app_id, FOCUS, FOCUS, "a new window has the focus");
+}
+
+static struct zwp_keyboard_shortcuts_inhibitor_v1 *
+_inhibit(Peer *p)
+{
+ struct zwp_keyboard_shortcuts_inhibitor_v1 *inhibitor;
+
+ inhibitor = zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts
+ (p->manager, tk_toplevel_surface(p->top), p->seat);
+ zwp_keyboard_shortcuts_inhibitor_v1_add_listener(inhibitor, &_inhibitor_listener, NULL);
+ tk_sync(p->tk);
+ return inhibitor;
+}
+
+/* Super+key, pressed and released, as a user would. */
+static void
+_super(Peer *p, const char *key)
+{
+ wl_test_key_modified(tester, key, WL_TEST_MODIFIER_WIN, 1);
+ wl_test_key_modified(tester, key, WL_TEST_MODIFIER_WIN, 0);
+ tk_sync(tester_tk);
+ tk_settle(p->tk);
+}
+
+static void
+_expect_binding(Peer *p, const char *what)
+{
+ int presses = p->presses[KEY_I];
+
+ _super(p, "i");
+ tk_wait_states(p->tk, p->app_id, MAX, MAX, what);
+ _super(p, "i");
+ tk_wait_states(p->tk, p->app_id, MAX, 0, what);
+ if (p->presses[KEY_I] != presses) tk_fail(p->tk, "%s: the client got the key", what);
+}
+
+static void
+_expect_client(Peer *p, const char *what)
+{
+ int presses = p->presses[KEY_I];
+
+ _super(p, "i");
+ if ((p->presses[KEY_I] != presses + 1) || (p->releases[KEY_I] != presses + 1))
+ tk_fail(p->tk, "%s: the client did not get the key", what);
+ if (tk_expect(p->tk, p->app_id)->states & MAX) tk_fail(p->tk, "%s: the binding ran", what);
+}
+
+static void
+_test_already_inhibited(void)
+{
+ const struct wl_interface *iface = NULL;
+ Peer c;
+
+ _peer_new(&c, APP_C);
+ zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(c.manager, tk_toplevel_surface(c.top), c.seat);
+ zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(c.manager, tk_toplevel_surface(c.top), c.seat);
+ if ((tk_protocol_error(c.tk, &iface) != ZWP_KEYBOARD_SHORTCUTS_INHIBIT_MANAGER_V1_ERROR_ALREADY_INHIBITED) ||
+ (iface != &zwp_keyboard_shortcuts_inhibit_manager_v1_interface))
+ tk_fail(c.tk, "a second inhibitor is not an already_inhibited error");
+ tk_disconnect(c.tk);
+}
+
+int
+main(void)
+{
+ struct zwp_keyboard_shortcuts_inhibitor_v1 *inhibitor;
+ Peer a, b;
+
+ _peer_new(&a, APP_A);
+ tester_tk = a.tk;
+ tester = tk_bind(a.tk, &wl_test_interface, 8);
+ if (!tester) tk_fail(a.tk, "no wl_test version 8");
+
+ _expect_binding(&a, "no inhibitor");
+
+ inhibitor = _inhibit(&a);
+ if ((actives != 1) || inactives) tk_fail(a.tk, "no active for a focused surface");
+ _expect_client(&a, "inhibited");
+
+ _super(&a, "Escape");
+ if ((inactives != 1) || a.presses[KEY_ESC]) tk_fail(a.tk, "the toggle did not take the keys back");
+ _expect_binding(&a, "turned off by the user");
+
+ _super(&a, "Escape");
+ if ((actives != 2) || a.presses[KEY_ESC]) tk_fail(a.tk, "the toggle did not give the keys back");
+ _expect_client(&a, "turned on again");
+
+ /* Another window takes the focus: no inactive, and its keys are E's. */
+ _peer_new(&b, APP_B);
+ tk_sync(a.tk);
+ if (inactives != 1) tk_fail(a.tk, "inactive sent on a focus change");
+ _expect_binding(&b, "another window has the focus");
+ tk_disconnect(b.tk);
+ tk_wait_states(a.tk, APP_A, FOCUS, FOCUS, "the focus came back");
+ tk_sync(a.tk);
+ if (actives != 3) tk_fail(a.tk, "no active when the focus came back");
+ _expect_client(&a, "the focus came back");
+
+ zwp_keyboard_shortcuts_inhibitor_v1_destroy(inhibitor);
+ tk_sync(a.tk);
+ _expect_binding(&a, "the inhibitor is gone");
+
+ _test_already_inhibited();
+
+ tk_disconnect(a.tk);
+ printf(PROG ": ok\n");
+ return 0;
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.