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

git pushed a commit to branch up/10-subsurface-input
in repository enlightenment.

View the commit online.

commit fabc47192a7938dcd255f1ce5885f307101ea5e5
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 25 19:00:15 2026 -0600

    e_comp_wl - add the input method keyboard grab and virtual keyboard
    
    An input method that composes from the keyboard, as every CJK one does,
    needs the keys before the window. It takes them with
    zwp_input_method_v2.grab_keyboard and gives back the ones it did not use
    through zwp_virtual_keyboard_v1. One without the other is worse than
    neither: a grab with no way back swallows every key, and a virtual
    keyboard with no grab is only a way to type into another client.
    
    The grab only takes keys while a text input is enabled. The protocol
    describes an exclusive grab of the seat's keyboard, and then an input
    method that hangs or crashes takes the whole keyboard with it, including
    the terminal to fix it. Restricted this way it only costs the text fields.
    The cost is that an input method sees no key outside a text field, which
    only matters for a toggle shortcut pressed there. Key bindings run
    before the grab, so it never takes them.
    
    A key the grab took is not in kbd.keys: those are the keys the focused
    client is told are down, and the same key coming back from the input
    method while still held would be dropped as a repeat. A repeat of a key
    the grab holds is not sent again, as the input method repeats it from
    the repeat info it got. A release goes where its press went, so a field
    disabled while a key is down, which is what committing text often does,
    does not leave the window with a key that never comes up. A release
    whose grab is gone goes nowhere, as the window never saw the press.
    
    A key from the virtual keyboard goes to the focused window through
    e_comp_wl_key_down, so E's pressed keys and modifiers stay right, but
    neither key bindings, which it already went through, nor the grab it
    came from see it. A virtual keyboard can then type into the focused
    window, which is what the protocol is for, but cannot drive E. Its
    keymap is not applied, since that would change what every window's keys
    mean; an input method sends back keycodes of the keymap the grab gave it.
    
    zwp_virtual_keyboard_manager_v1 is only advertised to the programs
    wayland-privileges grants virtual_keyboard to, as the protocol asks for
    an untrusted client. fcitx5.desktop grants it.
    
    virtual-keyboard-unstable-v1.xml is vendored from wlroots: it has never
    been in wayland-protocols.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 data/wayland-privileges/fcitx5.desktop         |   8 +-
 src/bin/e_comp_wl.c                            |  36 +++
 src/bin/e_comp_wl.h                            |   9 +
 src/bin/e_comp_wl_input.c                      |   2 +
 src/bin/e_comp_wl_privileges.c                 |   4 +-
 src/bin/e_comp_wl_text_input.c                 | 207 +++++++++++++-
 src/bin/generated/meson.build                  |   1 +
 src/protocol/virtual-keyboard-unstable-v1.xml  | 112 ++++++++
 src/tests/wayland/meson.build                  |   2 +
 src/tests/wayland/test_input_method_keyboard.c | 376 +++++++++++++++++++++++++
 src/tests/wayland/test_privileges.c            |  45 +--
 src/tests/wlcs/e_wlcs.c                        |   2 +-
 12 files changed, 775 insertions(+), 29 deletions(-)

diff --git a/data/wayland-privileges/fcitx5.desktop b/data/wayland-privileges/fcitx5.desktop
index b4d7123a9..7b783a75d 100644
--- a/data/wayland-privileges/fcitx5.desktop
+++ b/data/wayland-privileges/fcitx5.desktop
@@ -2,12 +2,14 @@
 # ~/.e/e/wayland-privileges, may use the Wayland protocols listed in their
 # X-Enlightenment-Wayland-Privileges key. No other program is told they
 # exist:
-#   input_method  zwp_input_method_v2, which reads the keys typed in a
-#                 text field
+#   input_method      zwp_input_method_v2, which reads the keys typed in
+#                     a text field
+#   virtual_keyboard  zwp_virtual_keyboard_v1, which types in the focused
+#                     window
 # Exec names the program, as an absolute path or a name looked up in PATH.
 [Desktop Entry]
 Type=Application
 Name=Fcitx 5
 Exec=fcitx5
 NoDisplay=true
-X-Enlightenment-Wayland-Privileges=input_method;
+X-Enlightenment-Wayland-Privileges=input_method;virtual_keyboard;
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index aeb66e47c..04eccd2f5 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -3941,6 +3941,10 @@ e_comp_wl_output_remove(const char *id)
      }
 }
 
+/* Set while e_comp_wl_key_inject runs, to keep a key out of the grab it
+ * came back from. */
+static Eina_Bool _key_injected = EINA_FALSE;
+
 EINTERN Eina_Bool
 e_comp_wl_key_down(Ecore_Event_Key *ev, E_Client *ec)
 {
@@ -3970,6 +3974,16 @@ e_comp_wl_key_down(Ecore_Event_Key *ev, E_Client *ec)
         if (*k == keycode) return EINA_FALSE;
      }
 
+   /* Not in kbd.keys, which are the keys the client was told are pressed,
+    * and where the key coming back from the input method would be taken for
+    * a repeat. */
+   if ((!_key_injected) &&
+       e_comp_wl_text_input_key_grab(keycode, EINA_TRUE, ev->timestamp))
+     {
+        e_comp_wl_input_keyboard_state_update(keycode, EINA_TRUE);
+        return EINA_TRUE;
+     }
+
    e_comp_wl->kbd.keys.size = (const char *)end - (const char *)e_comp_wl->kbd.keys.data;
    if (!(k = wl_array_add(&e_comp_wl->kbd.keys, sizeof(*k))))
      {
@@ -4014,6 +4028,13 @@ e_comp_wl_key_up(Ecore_Event_Key *ev, E_Client *ec)
    keycode = (ev->keycode - 8);
    if (!(e_comp_wl = e_comp->wl_comp_data)) return EINA_FALSE;
 
+   if ((!_key_injected) &&
+       e_comp_wl_text_input_key_grab(keycode, EINA_FALSE, ev->timestamp))
+     {
+        e_comp_wl_input_keyboard_state_update(keycode, EINA_FALSE);
+        return EINA_TRUE;
+     }
+
    end = (uint32_t *)e_comp_wl->kbd.keys.data + (e_comp_wl->kbd.keys.size / sizeof(*k));
    for (k = e_comp_wl->kbd.keys.data; k < end; k++)
      {
@@ -4046,6 +4067,21 @@ e_comp_wl_key_up(Ecore_Event_Key *ev, E_Client *ec)
    return !!ec;
 }
 
+EINTERN void
+e_comp_wl_key_inject(uint32_t keycode, Eina_Bool pressed, uint32_t timestamp)
+{
+   Ecore_Event_Key ev;
+
+   memset(&ev, 0, sizeof(ev));
+   ev.window = ev.event_window = ev.root_window = e_comp->ee_win;
+   ev.timestamp = timestamp;
+   ev.keycode = keycode + 8;
+   _key_injected = EINA_TRUE;
+   if (pressed) e_comp_wl_key_down(&ev, NULL);
+   else e_comp_wl_key_up(&ev, NULL);
+   _key_injected = EINA_FALSE;
+}
+
 E_API Eina_Bool
 e_comp_wl_evas_handle_mouse_button(E_Client *ec, uint32_t timestamp, uint32_t button_id, uint32_t state)
 {
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index f0208c24d..cb96fef75 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -478,6 +478,9 @@ E_API void e_comp_wl_output_remove(const char *id);
 
 EINTERN Eina_Bool e_comp_wl_key_down(Ecore_Event_Key *ev, E_Client *ec);
 EINTERN Eina_Bool e_comp_wl_key_up(Ecore_Event_Key *ev, E_Client *ec);
+/* A key from a virtual keyboard, an evdev keycode, for the focused client:
+ * neither key bindings nor the input method's grab see it. */
+EINTERN void e_comp_wl_key_inject(uint32_t keycode, Eina_Bool pressed, uint32_t timestamp);
 E_API Eina_Bool e_comp_wl_evas_handle_mouse_button(E_Client *ec, uint32_t timestamp, uint32_t button_id, uint32_t state);
 EINTERN void e_comp_wl_pointer_frame_send(struct wl_resource *res);
 E_API void e_comp_wl_pointer_focus_drop(E_Client *ec);
@@ -507,6 +510,12 @@ EINTERN Eina_Bool e_comp_wl_text_input_init(void);
  * an xdg popup up to its toplevel. */
 EINTERN void e_comp_wl_text_input_focus_set(E_Client *ec);
 EINTERN void e_comp_wl_text_input_focus_unset(E_Client *ec);
+/* Offers a key to the input method's keyboard grab, keycode an evdev one.
+ * EINA_TRUE when the grab took it, and then the focused client must not get
+ * it. */
+EINTERN Eina_Bool e_comp_wl_text_input_key_grab(uint32_t keycode, Eina_Bool pressed, uint32_t timestamp);
+EINTERN void e_comp_wl_text_input_keymap_send(void);
+EINTERN void e_comp_wl_text_input_modifiers_send(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);
diff --git a/src/bin/e_comp_wl_input.c b/src/bin/e_comp_wl_input.c
index f32fee3be..7acf1de06 100644
--- a/src/bin/e_comp_wl_input.c
+++ b/src/bin/e_comp_wl_input.c
@@ -480,6 +480,7 @@ _e_comp_wl_input_keymap_update(struct xkb_keymap *keymap)
    /* send updated keymap */
    EINA_LIST_FOREACH(e_comp_wl->kbd.resources, l, res)
      e_comp_wl_input_keymap_send(res);
+   e_comp_wl_text_input_keymap_send();
 
    /* update modifiers */
    e_comp_wl_input_keyboard_modifiers_update();
@@ -642,6 +643,7 @@ e_comp_wl_input_keyboard_modifiers_update(void)
    Eina_List *l;
 
    if (!e_comp_wl_input_keyboard_modifiers_serialize()) return;
+   e_comp_wl_text_input_modifiers_send();
 
    if ((!e_comp_wl->kbd.focused) || e_comp->input_key_grabs) return;
 
diff --git a/src/bin/e_comp_wl_privileges.c b/src/bin/e_comp_wl_privileges.c
index c7926b78f..ceef92804 100644
--- a/src/bin/e_comp_wl_privileges.c
+++ b/src/bin/e_comp_wl_privileges.c
@@ -4,7 +4,7 @@
  * ~/.e/e/wayland-privileges with, for instance:
  *
  *   Exec=fcitx5
- *   X-Enlightenment-Wayland-Privileges=input_method;
+ *   X-Enlightenment-Wayland-Privileges=input_method;virtual_keyboard;
  *
  * A client that is refused does not see the global at all, as on a
  * compositor without the protocol, which every input method handles; a
@@ -15,6 +15,7 @@
 #define E_COMP_WL
 #include "e.h"
 #include "input-method-unstable-v2-server-protocol.h"
+#include "virtual-keyboard-unstable-v1-server-protocol.h"
 
 static const struct
 {
@@ -23,6 +24,7 @@ static const struct
 } _privileged_globals[] =
 {
    { &zwp_input_method_manager_v2_interface, "input_method" },
+   { &zwp_virtual_keyboard_manager_v1_interface, "virtual_keyboard" },
 };
 
 /* The program the Exec key starts, found in PATH as a shell would, or NULL */
diff --git a/src/bin/e_comp_wl_text_input.c b/src/bin/e_comp_wl_text_input.c
index 182304af5..ea854072c 100644
--- a/src/bin/e_comp_wl_text_input.c
+++ b/src/bin/e_comp_wl_text_input.c
@@ -11,6 +11,7 @@
 #include "e.h"
 #include "text-input-unstable-v3-server-protocol.h"
 #include "input-method-unstable-v2-server-protocol.h"
+#include "virtual-keyboard-unstable-v1-server-protocol.h"
 
 typedef struct
 {
@@ -36,6 +37,7 @@ typedef struct
 typedef struct
 {
    struct wl_resource *res;
+   struct wl_resource *grab;
    /* a second input method on the seat is sent unavailable and ignored */
    Eina_Bool inert;
    struct
@@ -52,6 +54,7 @@ typedef struct
 
 static struct wl_global *_text_input_manager_global;
 static struct wl_global *_input_method_manager_global;
+static struct wl_global *_virtual_keyboard_manager_global;
 static Eina_List *_text_inputs;
 /* E has one seat, so there is at most one input method and one enabled
  * text input. */
@@ -60,6 +63,9 @@ static Text_Input *_active_ti;
 static struct wl_resource *_focus_surface;
 static struct wl_client *_focus_client;
 static struct wl_listener _focus_surface_destroy;
+/* The keys the grab took, by evdev code, of which there are 0x300: their
+ * release goes where their press went. */
+static Eina_Bool _grabbed_keys[0x300];
 
 static void
 _e_text_input_state_reset(Text_Input_State *st)
@@ -395,8 +401,7 @@ static const struct zwp_input_method_keyboard_grab_v2_interface _e_input_method_
    _e_input_method_cb_resource_destroy,
 };
 
-/* Not implemented yet: the popup is never shown and the grab never gets a
- * key, so an input method composing from the keyboard does not work. */
+/* Not implemented yet: the popup is never shown. */
 static void
 _e_input_method_cb_input_popup_surface_get(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface EINA_UNUSED)
 {
@@ -413,9 +418,33 @@ _e_input_method_cb_input_popup_surface_get(struct wl_client *client, struct wl_r
                                   NULL, NULL);
 }
 
+EINTERN void
+e_comp_wl_text_input_keymap_send(void)
+{
+   Input_Method *im = _e_input_method_get();
+   int fd;
+
+   if ((!im) || (!im->grab)) return;
+   fd = _e_comp_wl_input_keymap_fd_get();
+   if (fd < 0) return;
+   zwp_input_method_keyboard_grab_v2_send_keymap(im->grab, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
+                                                 fd, e_comp_wl->xkb.map_size);
+   close(fd);
+}
+
+static void
+_e_input_method_keyboard_grab_res_destroy(struct wl_resource *resource)
+{
+   Input_Method *im = wl_resource_get_user_data(resource);
+
+   if (im && (im->grab == resource)) im->grab = NULL;
+}
+
+/* A second grab replaces the first, which then stays silent. */
 static void
 _e_input_method_cb_keyboard_grab(struct wl_client *client, struct wl_resource *resource, uint32_t id)
 {
+   Input_Method *im = wl_resource_get_user_data(resource);
    struct wl_resource *res;
 
    res = wl_resource_create(client, &zwp_input_method_keyboard_grab_v2_interface,
@@ -426,7 +455,16 @@ _e_input_method_cb_keyboard_grab(struct wl_client *client, struct wl_resource *r
         return;
      }
    wl_resource_set_implementation(res, &_e_input_method_keyboard_grab_interface,
-                                  NULL, NULL);
+                                  NULL, _e_input_method_keyboard_grab_res_destroy);
+   if (im->inert) return;
+   if (im->grab) wl_resource_set_user_data(im->grab, NULL);
+   im->grab = res;
+   wl_resource_set_user_data(res, im);
+   e_comp_wl_text_input_keymap_send();
+   zwp_input_method_keyboard_grab_v2_send_repeat_info(res,
+                                                      e_config->keyboard.repeat_rate,
+                                                      e_config->keyboard.repeat_delay);
+   e_comp_wl_text_input_modifiers_send();
 }
 
 static const struct zwp_input_method_v2_interface _e_input_method_interface =
@@ -446,6 +484,7 @@ _e_input_method_res_destroy(struct wl_resource *resource)
    Input_Method *im = wl_resource_get_user_data(resource);
 
    if (_input_method == im) _input_method = NULL;
+   if (im->grab) wl_resource_set_user_data(im->grab, NULL);
    _e_input_method_pending_clear(im);
    free(im);
 }
@@ -514,6 +553,159 @@ _e_input_method_manager_cb_bind(struct wl_client *client, void *data EINA_UNUSED
                                   NULL);
 }
 
+/* The grab only takes keys while a text input is enabled, unlike the
+ * protocol's exclusive grab of the seat's keyboard: an input method that
+ * stops answering then costs the text fields, not the whole keyboard.
+ * Key bindings already ran, so it cannot take them either. */
+EINTERN Eina_Bool
+e_comp_wl_text_input_key_grab(uint32_t keycode, Eina_Bool pressed, uint32_t timestamp)
+{
+   Input_Method *im = _e_input_method_get();
+   uint32_t serial;
+
+   if (keycode >= EINA_C_ARRAY_LENGTH(_grabbed_keys)) return EINA_FALSE;
+   if (pressed)
+     {
+        if (_grabbed_keys[keycode]) return EINA_TRUE;
+        if ((!im) || (!im->grab) || (!_active_ti)) return EINA_FALSE;
+        _grabbed_keys[keycode] = EINA_TRUE;
+     }
+   else
+     {
+        if (!_grabbed_keys[keycode]) return EINA_FALSE;
+        _grabbed_keys[keycode] = EINA_FALSE;
+        if ((!im) || (!im->grab)) return EINA_TRUE;
+     }
+
+   serial = wl_display_next_serial(e_comp_wl->wl.disp);
+   zwp_input_method_keyboard_grab_v2_send_key(im->grab, serial, timestamp, keycode,
+                                              pressed ? WL_KEYBOARD_KEY_STATE_PRESSED :
+                                              WL_KEYBOARD_KEY_STATE_RELEASED);
+   return EINA_TRUE;
+}
+
+EINTERN void
+e_comp_wl_text_input_modifiers_send(void)
+{
+   Input_Method *im = _e_input_method_get();
+
+   if ((!im) || (!im->grab)) return;
+   zwp_input_method_keyboard_grab_v2_send_modifiers(im->grab,
+                                                    wl_display_next_serial(e_comp_wl->wl.disp),
+                                                    e_comp_wl->kbd.mod_depressed,
+                                                    e_comp_wl->kbd.mod_latched,
+                                                    e_comp_wl->kbd.mod_locked,
+                                                    e_comp_wl->kbd.mod_group);
+}
+
+/* zwp_virtual_keyboard_v1 is how the input method gives back the keys it did
+ * not use. They go to the focused window as if typed, without key bindings,
+ * which they already went through, and without the grab they came from. */
+static void
+_e_virtual_keyboard_cb_keymap(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t format, int32_t fd, uint32_t size EINA_UNUSED)
+{
+   close(fd);
+   if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1)
+     {
+        wl_resource_post_error(resource, ZWP_VIRTUAL_KEYBOARD_V1_ERROR_INVALID_KEYMAP_FORMAT,
+                               "keymap format %u is not xkb_v1", format);
+        return;
+     }
+   /* Not applied, as it would change what the keys of every window mean.
+    * An input method sends back the keys of the keymap the grab gave it. */
+   *(Eina_Bool *)wl_resource_get_user_data(resource) = EINA_TRUE;
+}
+
+static void
+_e_virtual_keyboard_cb_key(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t time, uint32_t key, uint32_t state)
+{
+   if (!*(Eina_Bool *)wl_resource_get_user_data(resource))
+     {
+        wl_resource_post_error(resource, ZWP_VIRTUAL_KEYBOARD_V1_ERROR_NO_KEYMAP,
+                               "key sent before a keymap");
+        return;
+     }
+   e_comp_wl_key_inject(key, state == WL_KEYBOARD_KEY_STATE_PRESSED, time);
+}
+
+static void
+_e_virtual_keyboard_cb_modifiers(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group)
+{
+   struct wl_resource *res;
+   Eina_List *l;
+   uint32_t serial;
+
+   if (!*(Eina_Bool *)wl_resource_get_user_data(resource))
+     {
+        wl_resource_post_error(resource, ZWP_VIRTUAL_KEYBOARD_V1_ERROR_NO_KEYMAP,
+                               "modifiers sent before a keymap");
+        return;
+     }
+   serial = wl_display_next_serial(e_comp_wl->wl.disp);
+   EINA_LIST_FOREACH(e_comp_wl->kbd.focused, l, res)
+     wl_keyboard_send_modifiers(res, serial, depressed, latched, locked, group);
+}
+
+static const struct zwp_virtual_keyboard_v1_interface _e_virtual_keyboard_interface =
+{
+   _e_virtual_keyboard_cb_keymap,
+   _e_virtual_keyboard_cb_key,
+   _e_virtual_keyboard_cb_modifiers,
+   _e_input_method_cb_resource_destroy,
+};
+
+static void
+_e_virtual_keyboard_res_destroy(struct wl_resource *resource)
+{
+   free(wl_resource_get_user_data(resource));
+}
+
+/* The user data says whether a keymap was set. */
+static void
+_e_virtual_keyboard_manager_cb_create(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat EINA_UNUSED, uint32_t id)
+{
+   Eina_Bool *keymap_set;
+   struct wl_resource *res;
+
+   keymap_set = E_NEW(Eina_Bool, 1);
+   if (!keymap_set)
+     {
+        wl_resource_post_no_memory(resource);
+        return;
+     }
+   res = wl_resource_create(client, &zwp_virtual_keyboard_v1_interface,
+                            wl_resource_get_version(resource), id);
+   if (!res)
+     {
+        free(keymap_set);
+        wl_resource_post_no_memory(resource);
+        return;
+     }
+   wl_resource_set_implementation(res, &_e_virtual_keyboard_interface, keymap_set,
+                                  _e_virtual_keyboard_res_destroy);
+}
+
+static const struct zwp_virtual_keyboard_manager_v1_interface _e_virtual_keyboard_manager_interface =
+{
+   _e_virtual_keyboard_manager_cb_create,
+};
+
+static void
+_e_virtual_keyboard_manager_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t version, uint32_t id)
+{
+   struct wl_resource *res;
+
+   res = wl_resource_create(client, &zwp_virtual_keyboard_manager_v1_interface,
+                            version, id);
+   if (!res)
+     {
+        wl_client_post_no_memory(client);
+        return;
+     }
+   wl_resource_set_implementation(res, &_e_virtual_keyboard_manager_interface,
+                                  NULL, NULL);
+}
+
 static void
 _e_text_input_focus_leave(void)
 {
@@ -597,5 +789,14 @@ e_comp_wl_text_input_init(void)
         ERR("Could not add zwp_input_method_manager_v2 to wayland globals");
         return EINA_FALSE;
      }
+   _virtual_keyboard_manager_global =
+     wl_global_create(e_comp_wl->wl.disp,
+                      &zwp_virtual_keyboard_manager_v1_interface, 1, NULL,
+                      _e_virtual_keyboard_manager_cb_bind);
+   if (!_virtual_keyboard_manager_global)
+     {
+        ERR("Could not add zwp_virtual_keyboard_manager_v1 to wayland globals");
+        return EINA_FALSE;
+     }
    return EINA_TRUE;
 }
diff --git a/src/bin/generated/meson.build b/src/bin/generated/meson.build
index 61e1df38b..9adcb4c06 100644
--- a/src/bin/generated/meson.build
+++ b/src/bin/generated/meson.build
@@ -16,6 +16,7 @@ protos = [
   '@0@/unstable/text-input/text-input-unstable-v3.xml'.format(dir_wayland_protocols),
   # not in wayland-protocols, vendored from wlroots
   '../../protocol/input-method-unstable-v2.xml',
+  '../../protocol/virtual-keyboard-unstable-v1.xml',
 ]
 
 proto_c = []
diff --git a/src/protocol/virtual-keyboard-unstable-v1.xml b/src/protocol/virtual-keyboard-unstable-v1.xml
new file mode 100644
index 000000000..a888e5f87
--- /dev/null
+++ b/src/protocol/virtual-keyboard-unstable-v1.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="virtual_keyboard_unstable_v1">
+  <copyright>
+    Copyright © 2008-2011  Kristian Høgsberg
+    Copyright © 2010-2013  Intel Corporation
+    Copyright © 2012-2013  Collabora, Ltd.
+    Copyright © 2018       Purism SPC
+
+    Permission is hereby granted, free of charge, to any person obtaining a
+    copy of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom the
+    Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice (including the next
+    paragraph) shall be included in all copies or substantial portions of the
+    Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+    DEALINGS IN THE SOFTWARE.
+  </copyright>
+
+  <interface name="zwp_virtual_keyboard_v1" version="1">
+    <description summary="virtual keyboard">
+      The virtual keyboard provides an application with requests which emulate
+      the behaviour of a physical keyboard.
+
+      This interface can be used by clients on its own to provide raw input
+      events, or it can accompany the input method protocol.
+    </description>
+
+    <request name="keymap">
+      <description summary="keyboard mapping">
+        Provide a file descriptor to the compositor which can be
+        memory-mapped to provide a keyboard mapping description.
+      </description>
+      <arg name="format" type="uint" enum="wl_keyboard.keymap_format" summary="keymap format"/>
+      <arg name="fd" type="fd" summary="keymap file descriptor"/>
+      <arg name="size" type="uint" summary="keymap size, in bytes"/>
+    </request>
+
+    <enum name="error">
+      <entry name="no_keymap" value="0" summary="No keymap was set"/>
+      <entry name="invalid_keymap_format" value="1" summary="Invalid keymap format"/>
+    </enum>
+
+    <request name="key">
+      <description summary="key event">
+        A key was pressed or released.
+        The time argument is a timestamp with millisecond granularity, with an
+        undefined base. All requests regarding a single object must share the
+        same clock.
+
+        Keymap must be set before issuing this request.
+
+        State carries a value from the key_state enumeration.
+      </description>
+      <arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
+      <arg name="key" type="uint" summary="key that produced the event"/>
+      <arg name="state" type="uint" summary="physical state of the key"/>
+    </request>
+
+    <request name="modifiers">
+      <description summary="modifier and group state">
+        Notifies the compositor that the modifier and/or group state has
+        changed, and it should update state.
+
+        The client should use wl_keyboard.modifiers event to synchronize its
+        internal state with seat state.
+
+        Keymap must be set before issuing this request.
+      </description>
+      <arg name="mods_depressed" type="uint" summary="depressed modifiers"/>
+      <arg name="mods_latched" type="uint" summary="latched modifiers"/>
+      <arg name="mods_locked" type="uint" summary="locked modifiers"/>
+      <arg name="group" type="uint" summary="keyboard layout"/>
+    </request>
+
+    <request name="destroy" type="destructor" since="1">
+      <description summary="destroy the virtual keyboard keyboard object"/>
+    </request>
+  </interface>
+
+  <interface name="zwp_virtual_keyboard_manager_v1" version="1">
+    <description summary="virtual keyboard manager">
+      A virtual keyboard manager allows an application to provide keyboard
+      input events as if they came from a physical keyboard.
+    </description>
+
+    <enum name="error">
+      <entry name="unauthorized" value="0" summary="client not authorized to use the interface"/>
+    </enum>
+
+    <request name="create_virtual_keyboard">
+      <description summary="Create a new virtual keyboard">
+        Creates a new virtual keyboard associated to a seat.
+
+        If the compositor enables a keyboard to perform arbitrary actions, it
+        should present an error when an untrusted client requests a new
+        keyboard.
+      </description>
+      <arg name="seat" type="object" interface="wl_seat"/>
+      <arg name="id" type="new_id" interface="zwp_virtual_keyboard_v1"/>
+    </request>
+  </interface>
+</protocol>
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index 04f5b7fa3..44df7ceb7 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -38,6 +38,7 @@ foreach p: [
   '@0@/unstable/primary-selection/primary-selection-unstable-v1.xml'.format(dir_wayland_protocols),
   '@0@/unstable/text-input/text-input-unstable-v3.xml'.format(dir_wayland_protocols),
   '../../protocol/input-method-unstable-v2.xml',
+  '../../protocol/virtual-keyboard-unstable-v1.xml',
 ]
   test_proto_src += gen_scanner_client.process(p)
   test_proto_src += gen_scanner_impl.process(p)
@@ -91,6 +92,7 @@ wl_protocol_tests = [
   ['primary-selection', 'test_primary_selection.c'],
   ['idle-inhibit', 'test_idle_inhibit.c'],
   ['text-input', 'test_text_input.c'],
+  ['input-method-keyboard', 'test_input_method_keyboard.c'],
   ['privileges', 'test_privileges.c',
    {'PATH': meson.current_build_dir()}],
   ['client-iconify', 'test_client_iconify.c',
diff --git a/src/tests/wayland/test_input_method_keyboard.c b/src/tests/wayland/test_input_method_keyboard.c
new file mode 100644
index 000000000..2e1fbdea2
--- /dev/null
+++ b/src/tests/wayland/test_input_method_keyboard.c
@@ -0,0 +1,376 @@
+/* The input method's keyboard grab takes the keys while a text field is
+ * enabled, and gives back those it does not use through
+ * zwp_virtual_keyboard_v1. The test profile binds Super+i to
+ * window_maximized_toggle. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/input-event-codes.h>
+
+#include "e_wl_testkit.h"
+#include "text-input-unstable-v3-client-protocol.h"
+#include "input-method-unstable-v2-client-protocol.h"
+#include "virtual-keyboard-unstable-v1-client-protocol.h"
+
+#define PROG "test-input-method-keyboard"
+#define APP_ID "e.test.input-method-keyboard"
+#define FOCUS WL_TEST_CLIENT_STATE_FOCUSED
+#define MAX (WL_TEST_CLIENT_STATE_MAXIMIZED_H | WL_TEST_CLIENT_STATE_MAXIMIZED_V)
+
+/* "+30" for a press of key 30, "-30" for its release, "m" for modifiers */
+typedef struct
+{
+   char log[256];
+   uint32_t mods;
+   int keymap_fd;
+   int repeat_info;
+} Keys;
+
+static Tk *app, *ime;
+static struct wl_test *tester;
+static Keys app_keys, grab_keys;
+
+static void
+_log_key(Keys *k, uint32_t key, uint32_t state)
+{
+   size_t n = strlen(k->log);
+
+   snprintf(k->log + n, sizeof(k->log) - n, "%c%u",
+            state == WL_KEYBOARD_KEY_STATE_PRESSED ? '+' : '-', key);
+}
+
+static void
+_expect(Tk *tk, Keys *k, const char *expected, const char *what)
+{
+   if (strcmp(k->log, expected))
+     tk_fail(tk, "%s: got keys \"%s\", expected \"%s\"", what, k->log, expected);
+   k->log[0] = 0;
+}
+
+static void
+_kbd_keymap(void *data __attribute__((unused)), struct wl_keyboard *kbd __attribute__((unused)),
+            uint32_t format __attribute__((unused)), int32_t fd, uint32_t size __attribute__((unused)))
+{
+   close(fd);
+}
+
+static void
+_kbd_enter(void *data __attribute__((unused)), struct wl_keyboard *kbd __attribute__((unused)),
+           uint32_t serial __attribute__((unused)), struct wl_surface *surface __attribute__((unused)),
+           struct wl_array *keys __attribute__((unused)))
+{
+}
+
+static void
+_kbd_leave(void *data __attribute__((unused)), struct wl_keyboard *kbd __attribute__((unused)),
+           uint32_t serial __attribute__((unused)), struct wl_surface *surface __attribute__((unused)))
+{
+}
+
+static void
+_kbd_key(void *data, struct wl_keyboard *kbd __attribute__((unused)), uint32_t serial __attribute__((unused)),
+         uint32_t time __attribute__((unused)), uint32_t key, uint32_t state)
+{
+   _log_key(data, key, state);
+}
+
+static void
+_kbd_modifiers(void *data, struct wl_keyboard *kbd __attribute__((unused)), uint32_t serial __attribute__((unused)),
+               uint32_t depressed, uint32_t latched __attribute__((unused)),
+               uint32_t locked __attribute__((unused)), uint32_t group __attribute__((unused)))
+{
+   ((Keys *)data)->mods = depressed;
+}
+
+static void
+_kbd_repeat_info(void *data __attribute__((unused)), struct wl_keyboard *kbd __attribute__((unused)),
+                 int32_t rate __attribute__((unused)), int32_t delay __attribute__((unused)))
+{
+}
+
+static const struct wl_keyboard_listener _kbd_listener =
+{
+   _kbd_keymap, _kbd_enter, _kbd_leave, _kbd_key, _kbd_modifiers, _kbd_repeat_info
+};
+
+static void
+_grab_keymap(void *data, struct zwp_input_method_keyboard_grab_v2 *grab __attribute__((unused)),
+             uint32_t format __attribute__((unused)), int32_t fd, uint32_t size __attribute__((unused)))
+{
+   Keys *k = data;
+
+   if (k->keymap_fd >= 0) close(k->keymap_fd);
+   k->keymap_fd = fd;
+}
+
+static void
+_grab_key(void *data, struct zwp_input_method_keyboard_grab_v2 *grab __attribute__((unused)),
+          uint32_t serial __attribute__((unused)), uint32_t time __attribute__((unused)),
+          uint32_t key, uint32_t state)
+{
+   _log_key(data, key, state);
+}
+
+static void
+_grab_modifiers(void *data, struct zwp_input_method_keyboard_grab_v2 *grab __attribute__((unused)),
+                uint32_t serial __attribute__((unused)), uint32_t depressed,
+                uint32_t latched __attribute__((unused)), uint32_t locked __attribute__((unused)),
+                uint32_t group __attribute__((unused)))
+{
+   ((Keys *)data)->mods = depressed;
+}
+
+static void
+_grab_repeat_info(void *data, struct zwp_input_method_keyboard_grab_v2 *grab __attribute__((unused)),
+                  int32_t rate __attribute__((unused)), int32_t delay __attribute__((unused)))
+{
+   ((Keys *)data)->repeat_info++;
+}
+
+static const struct zwp_input_method_keyboard_grab_v2_listener _grab_listener =
+{
+   _grab_keymap, _grab_key, _grab_modifiers, _grab_repeat_info
+};
+
+static void
+_settle(void)
+{
+   tk_sync(app);
+   tk_sync(ime);
+   tk_sync(app);
+}
+
+static void
+_key(const char *name, int pressed)
+{
+   wl_test_key(tester, name, pressed);
+   wl_display_flush(tk_display(app));
+   _settle();
+}
+
+static void
+_type(const char *name)
+{
+   _key(name, 1);
+   _key(name, 0);
+}
+
+static void
+_enable(struct zwp_text_input_v3 *ti, int enable)
+{
+   if (enable) zwp_text_input_v3_enable(ti);
+   else zwp_text_input_v3_disable(ti);
+   zwp_text_input_v3_commit(ti);
+   _settle();
+}
+
+static struct zwp_input_method_keyboard_grab_v2 *
+_grab_new(struct zwp_input_method_v2 *im)
+{
+   struct zwp_input_method_keyboard_grab_v2 *grab;
+
+   grab = zwp_input_method_v2_grab_keyboard(im);
+   zwp_input_method_keyboard_grab_v2_add_listener(grab, &_grab_listener, &grab_keys);
+   _settle();
+   return grab;
+}
+
+static void
+_vk_error(int set_keymap, uint32_t format, int expected, const char *what)
+{
+   struct zwp_virtual_keyboard_manager_v1 *manager;
+   struct zwp_virtual_keyboard_v1 *vk;
+   const struct wl_interface *iface;
+   struct wl_seat *seat;
+   Tk *tk;
+
+   tk = tk_connect(PROG);
+   seat = tk_bind(tk, &wl_seat_interface, 1);
+   manager = tk_bind(tk, &zwp_virtual_keyboard_manager_v1_interface, 1);
+   if ((!seat) || (!manager)) tk_fail(tk, "missing global");
+   vk = zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(manager, seat);
+   if (set_keymap)
+     zwp_virtual_keyboard_v1_keymap(vk, format, grab_keys.keymap_fd, 1);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_A, WL_KEYBOARD_KEY_STATE_PRESSED);
+   if ((tk_protocol_error(tk, &iface) != expected) ||
+       (iface != &zwp_virtual_keyboard_v1_interface))
+     tk_fail(tk, "%s is not the expected protocol error", what);
+   tk_disconnect(tk);
+}
+
+static Tk *_ime_seat_tk;
+static struct wl_seat *_ime_seat;
+static struct zwp_input_method_manager_v2 *_im_manager;
+
+static void
+_inert_grab(void)
+{
+   struct zwp_input_method_keyboard_grab_v2 *grab;
+   struct zwp_input_method_v2 *im;
+   Keys keys = { .keymap_fd = -1 };
+
+   im = zwp_input_method_manager_v2_get_input_method(_im_manager, _ime_seat);
+   grab = zwp_input_method_v2_grab_keyboard(im);
+   zwp_input_method_keyboard_grab_v2_add_listener(grab, &_grab_listener, &keys);
+   _settle();
+   if ((keys.keymap_fd >= 0) || keys.repeat_info)
+     tk_fail(ime, "the grab of an unavailable input method got events");
+   _type("a");
+   _expect(_ime_seat_tk, &keys, "", "the grab of an unavailable input method");
+   _expect(ime, &grab_keys, "+30-30", "the grab, with an unavailable input method");
+   zwp_input_method_keyboard_grab_v2_release(grab);
+   zwp_input_method_v2_destroy(im);
+   if (keys.keymap_fd >= 0) close(keys.keymap_fd);
+}
+
+int
+main(void)
+{
+   struct zwp_text_input_manager_v3 *ti_manager;
+   struct zwp_input_method_manager_v2 *im_manager;
+   struct zwp_virtual_keyboard_manager_v1 *vk_manager;
+   struct zwp_input_method_keyboard_grab_v2 *grab, *old;
+   struct zwp_input_method_v2 *im;
+   struct zwp_virtual_keyboard_v1 *vk;
+   struct zwp_text_input_v3 *ti;
+   struct wl_seat *app_seat, *ime_seat;
+   unsigned int id;
+
+   grab_keys.keymap_fd = -1;
+   tk_privileges_file("test-input-method-keyboard", NULL, "input_method;virtual_keyboard;");
+   app = tk_connect(PROG);
+   ime = tk_connect(PROG);
+   tester = tk_bind(app, &wl_test_interface, 8);
+   app_seat = tk_bind(app, &wl_seat_interface, 1);
+   ime_seat = tk_bind(ime, &wl_seat_interface, 1);
+   ti_manager = tk_bind(app, &zwp_text_input_manager_v3_interface, 1);
+   im_manager = tk_bind(ime, &zwp_input_method_manager_v2_interface, 1);
+   vk_manager = tk_bind(ime, &zwp_virtual_keyboard_manager_v1_interface, 1);
+   if ((!tester) || (!app_seat) || (!ime_seat) || (!ti_manager) || (!im_manager) || (!vk_manager))
+     tk_fail(app, "missing global");
+
+   _ime_seat_tk = ime;
+   _ime_seat = ime_seat;
+   _im_manager = im_manager;
+   wl_keyboard_add_listener(wl_seat_get_keyboard(app_seat), &_kbd_listener, &app_keys);
+   ti = zwp_text_input_manager_v3_get_text_input(ti_manager, app_seat);
+   tk_toplevel_new(app, APP_ID, APP_ID, 200, 200);
+   tk_wait_states(app, APP_ID, FOCUS, FOCUS, "a new window has the focus");
+   id = tk_expect(app, APP_ID)->id;
+
+   im = zwp_input_method_manager_v2_get_input_method(im_manager, ime_seat);
+   grab = _grab_new(im);
+   if ((grab_keys.keymap_fd < 0) || (grab_keys.repeat_info != 1))
+     tk_fail(ime, "the grab got no keymap or no repeat info");
+
+   _type("a");
+   _expect(app, &app_keys, "+30-30", "no field enabled, the window");
+   _expect(ime, &grab_keys, "", "no field enabled, the grab");
+
+   _enable(ti, 1);
+   _type("a");
+   _expect(app, &app_keys, "", "a field enabled, the window");
+   _expect(ime, &grab_keys, "+30-30", "a field enabled, the grab");
+
+   _key("a", 1);
+   _key("a", 1);
+   _key("a", 0);
+   _expect(ime, &grab_keys, "+30-30", "a repeated key");
+
+   _key("Shift_L", 1);
+   _expect(ime, &grab_keys, "+42", "shift");
+   if (!grab_keys.mods) tk_fail(ime, "the grab got no modifiers for shift");
+   _key("Shift_L", 0);
+   _expect(ime, &grab_keys, "-42", "shift released");
+   if (grab_keys.mods) tk_fail(ime, "the grab still has shift");
+
+   /* The release goes where its press went. */
+   _key("a", 1);
+   _enable(ti, 0);
+   _key("a", 0);
+   _expect(app, &app_keys, "", "a release after the field was disabled, the window");
+   _expect(ime, &grab_keys, "+30-30", "a release after the field was disabled, the grab");
+   _enable(ti, 1);
+
+   /* Key bindings run before the grab. */
+   wl_test_key_modified(tester, "i", WL_TEST_MODIFIER_WIN, 1);
+   wl_test_key_modified(tester, "i", WL_TEST_MODIFIER_WIN, 0);
+   tk_wait_states(app, APP_ID, MAX, MAX, "Super+i maximized with the grab");
+   _settle();
+   _expect(ime, &grab_keys, "+125-125", "Super+i, the grab");
+   tk_action(app, id, "window_maximized_toggle", NULL);
+   tk_wait_states(app, APP_ID, MAX, 0, "unmaximized");
+
+   /* The way back reaches the window, not the grab, nor the bindings. */
+   vk = zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(vk_manager, ime_seat);
+   zwp_virtual_keyboard_v1_keymap(vk, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, grab_keys.keymap_fd, 1);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_A, WL_KEYBOARD_KEY_STATE_PRESSED);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_A, WL_KEYBOARD_KEY_STATE_RELEASED);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_LEFTMETA, WL_KEYBOARD_KEY_STATE_PRESSED);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_I, WL_KEYBOARD_KEY_STATE_PRESSED);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_I, WL_KEYBOARD_KEY_STATE_RELEASED);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_LEFTMETA, WL_KEYBOARD_KEY_STATE_RELEASED);
+   _settle();
+   _expect(app, &app_keys, "+30-30+125+23-23-125", "keys from the virtual keyboard, the window");
+   _expect(ime, &grab_keys, "", "keys from the virtual keyboard, the grab");
+   tk_wait_states(app, APP_ID, MAX, 0, "Super+i from the virtual keyboard");
+
+   /* An input method gives a key back while it is still held. */
+   _key("a", 1);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_A, WL_KEYBOARD_KEY_STATE_PRESSED);
+   zwp_virtual_keyboard_v1_key(vk, 0, KEY_A, WL_KEYBOARD_KEY_STATE_RELEASED);
+   _settle();
+   _key("a", 0);
+   _expect(app, &app_keys, "+30-30", "a key given back while held, the window");
+   _expect(ime, &grab_keys, "+30-30", "a key given back while held, the grab");
+
+   /* A second input method's grab gets nothing. */
+   _inert_grab();
+
+   /* E's own keyboard move gets the keys. */
+   tk_action(app, id, "window_move", NULL);
+   _type("a");
+   _expect(ime, &grab_keys, "", "a key during a keyboard move");
+   tk_action_end(app, id, "window_move", NULL);
+   tk_wait_states(app, APP_ID, FOCUS, FOCUS, "the focus after the keyboard move");
+   _enable(ti, 1);
+   _type("a");
+   _expect(ime, &grab_keys, "+30-30", "a key after the keyboard move");
+   app_keys.log[0] = 0;
+
+   /* A second grab replaces the first. */
+   old = grab;
+   grab = _grab_new(im);
+   _type("a");
+   _expect(ime, &grab_keys, "+30-30", "the second grab");
+   zwp_input_method_keyboard_grab_v2_release(old);
+
+   /* A grab released with a key down: the release goes nowhere. */
+   _key("a", 1);
+   zwp_input_method_keyboard_grab_v2_release(grab);
+   _settle();
+   _key("a", 0);
+   _expect(app, &app_keys, "", "a release after the grab was gone, the window");
+   _expect(ime, &grab_keys, "+30", "a release after the grab was gone, the grab");
+   _type("a");
+   _expect(app, &app_keys, "+30-30", "no grab, the window");
+
+   /* The input method goes first, then its grab. */
+   grab = _grab_new(im);
+   zwp_input_method_v2_destroy(im);
+   _settle();
+   _type("a");
+   _expect(app, &app_keys, "+30-30", "no input method, the window");
+   zwp_input_method_keyboard_grab_v2_release(grab);
+   _settle();
+
+   _vk_error(0, 0, ZWP_VIRTUAL_KEYBOARD_V1_ERROR_NO_KEYMAP, "a key before the keymap");
+   _vk_error(1, 0, ZWP_VIRTUAL_KEYBOARD_V1_ERROR_INVALID_KEYMAP_FORMAT,
+             "a keymap that is not xkb");
+
+   tk_disconnect(ime);
+   tk_disconnect(app);
+   printf(PROG ": ok\n");
+   return 0;
+}
diff --git a/src/tests/wayland/test_privileges.c b/src/tests/wayland/test_privileges.c
index 6b03e969d..e6c089e05 100644
--- a/src/tests/wayland/test_privileges.c
+++ b/src/tests/wayland/test_privileges.c
@@ -1,7 +1,8 @@
-/* zwp_input_method_manager_v2 is only advertised to a program a .desktop
- * file in wayland-privileges grants input_method to. The files are read
- * again for every client, so each case is a new connection. The test runs
- * with its directory in E's PATH. */
+/* zwp_input_method_manager_v2 and zwp_virtual_keyboard_manager_v1 are only
+ * advertised to a program a .desktop file in wayland-privileges grants
+ * input_method or virtual_keyboard to. The files are read again for every
+ * client, so each case is a new connection. The test runs with its
+ * directory in E's PATH. */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -14,17 +15,17 @@
 #define FILE_NAME "test-privileges"
 
 static void
-_expect(int advertised, const char *what)
+_expect(int input_method, int virtual_keyboard, const char *what)
 {
    Tk *tk = tk_connect(PROG);
-   uint32_t version = tk_global_version(tk, "zwp_input_method_manager_v2");
+   int im = !!tk_global_version(tk, "zwp_input_method_manager_v2");
+   int vk = !!tk_global_version(tk, "zwp_virtual_keyboard_manager_v1");
 
    if (!tk_global_version(tk, "zwp_text_input_manager_v3"))
      tk_fail(tk, "%s: zwp_text_input_manager_v3 is hidden", what);
-   if (advertised && (!version))
-     tk_fail(tk, "%s: zwp_input_method_manager_v2 is hidden", what);
-   if ((!advertised) && version)
-     tk_fail(tk, "%s: zwp_input_method_manager_v2 is advertised", what);
+   if ((im != input_method) || (vk != virtual_keyboard))
+     tk_fail(tk, "%s: input method %s, virtual keyboard %s", what,
+             im ? "advertised" : "hidden", vk ? "advertised" : "hidden");
    tk_disconnect(tk);
 }
 
@@ -43,23 +44,25 @@ main(void)
    path[n] = 0;
    snprintf(quoted, sizeof(quoted), "\"%s\" --flag %%U", path);
 
-   _expect(0, "no file");
+   _expect(0, 0, "no file");
    tk_privileges_file(FILE_NAME, NULL, NULL);
-   _expect(0, "a file without the key");
-   tk_privileges_file(FILE_NAME, NULL, "input_methods;virtual_keyboard;");
-   _expect(0, "a file without input_method");
-   tk_privileges_file(FILE_NAME, "/bin/true", "input_method;");
-   _expect(0, "a file for another program");
-   tk_privileges_file(FILE_NAME, "true", "input_method;");
-   _expect(0, "a file for another program found in PATH");
+   _expect(0, 0, "a file without the key");
+   tk_privileges_file(FILE_NAME, NULL, "input_methods;virtual_keyboards;");
+   _expect(0, 0, "a file with other privileges");
+   tk_privileges_file(FILE_NAME, "/bin/true", "input_method;virtual_keyboard;");
+   _expect(0, 0, "a file for another program");
+   tk_privileges_file(FILE_NAME, "true", "input_method;virtual_keyboard;");
+   _expect(0, 0, "a file for another program found in PATH");
    tk_privileges_file(FILE_NAME, quoted, "virtual_keyboard;input_method");
-   _expect(1, "a file for this program");
+   _expect(1, 1, "a file for this program");
    tk_privileges_file(FILE_NAME, strrchr(path, '/') + 1, "input_method;");
-   _expect(1, "a file for this program found in PATH");
+   _expect(1, 0, "a file for this program found in PATH");
+   tk_privileges_file(FILE_NAME, NULL, "virtual_keyboard");
+   _expect(0, 1, "a file granting the virtual keyboard only");
 
    snprintf(path, sizeof(path), "%s/" FILE_NAME ".desktop", getenv("E_TEST_PRIVILEGES_DIR"));
    unlink(path);
-   _expect(0, "the file is gone");
+   _expect(0, 0, "the file is gone");
 
    printf(PROG ": ok\n");
    return 0;
diff --git a/src/tests/wlcs/e_wlcs.c b/src/tests/wlcs/e_wlcs.c
index da4977637..a85b1e033 100644
--- a/src/tests/wlcs/e_wlcs.c
+++ b/src/tests/wlcs/e_wlcs.c
@@ -247,7 +247,7 @@ _privileges_grant(E_Server *s)
         return;
      }
    fprintf(f, "[Desktop Entry]\nType=Application\nName=wlcs\nExec=%s\n"
-           "X-Enlightenment-Wayland-Privileges=input_method;\n", exe);
+           "X-Enlightenment-Wayland-Privileges=input_method;virtual_keyboard;\n", exe);
    fclose(f);
 }
 

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

Reply via email to