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 09490e04d859fbaa1aa2cf48142e18640bb84cb0
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 25 19:32:31 2026 -0600

    e_comp_wl - show the input method's candidate popup
    
    zwp_input_popup_surface_v2 is the input method's candidate list. It was
    created and never shown, so fcitx5 composed with its candidates
    invisible: the object exists, so it has no reason to fall back to a
    window of its own. Only the compositor knows where the text cursor of
    another client is, so it places the popup.
    
    It is shown if and only if its input method is active, as the protocol
    says, so not for an unavailable one and not once the input method is
    gone. It goes below the text cursor with the left edges aligned, where
    every input method puts its candidates so they do not cover the text,
    above the cursor when there is no room below, and within the zone
    otherwise. The cursor is relative to the surface, ec->client, not to the
    frame or the window geometry. text_input_rectangle then gives the cursor
    in the popup's own coordinates, which the input method uses to lay out
    its list.
    
    The popup is placed again when the text input commits, which is how a
    client reports its cursor moving, and when it resizes itself. Like the
    input panel of wl_desktop_shell it is neither decorated nor focused: a
    click on a candidate must not move the focus, as that would deactivate
    the input method and hide the very list being clicked. It is in the
    popup layer, above the window it belongs to.
    
    A client may attach a buffer before giving the surface the role, and
    that commit found no map to call, so the role catches up.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/bin/e_comp_wl_text_input.c       | 204 ++++++++++++++++++-
 src/tests/wayland/e_wl_testkit.c     |  11 +-
 src/tests/wayland/e_wl_testkit.h     |   2 +
 src/tests/wayland/meson.build        |   1 +
 src/tests/wayland/test_input_popup.c | 379 +++++++++++++++++++++++++++++++++++
 5 files changed, 587 insertions(+), 10 deletions(-)

diff --git a/src/bin/e_comp_wl_text_input.c b/src/bin/e_comp_wl_text_input.c
index ea854072c..2c1900feb 100644
--- a/src/bin/e_comp_wl_text_input.c
+++ b/src/bin/e_comp_wl_text_input.c
@@ -23,6 +23,8 @@ typedef struct
    Eina_Bool change_cause_set;
    uint32_t content_hint, content_purpose;
    Eina_Bool content_set;
+   /* in the focused surface's coordinates */
+   int32_t cursor_x, cursor_y, cursor_w, cursor_h;
 } Text_Input_State;
 
 typedef struct
@@ -40,6 +42,7 @@ typedef struct
    struct wl_resource *grab;
    /* a second input method on the seat is sent unavailable and ignored */
    Eina_Bool inert;
+   Eina_List *popups;
    struct
    {
       char *preedit;
@@ -118,12 +121,15 @@ _e_input_method_state_send(Input_Method *im, Text_Input *ti)
    zwp_input_method_v2_send_done(im->res);
 }
 
+static void _e_input_popups_update(Input_Method *im);
+
 static void
 _e_input_method_activate(Input_Method *im, Text_Input *ti)
 {
    zwp_input_method_v2_send_activate(im->res);
    _e_input_method_pending_clear(im);
    _e_input_method_state_send(im, ti);
+   _e_input_popups_update(im);
 }
 
 static void
@@ -139,6 +145,7 @@ _e_input_method_deactivate(void)
    zwp_input_method_v2_send_done(im->res);
    /* text composed for this field must not reach the next one */
    _e_input_method_pending_clear(im);
+   _e_input_popups_update(im);
 }
 
 static void
@@ -200,8 +207,15 @@ _e_text_input_cb_content_type_set(struct wl_client *client EINA_UNUSED, struct w
 }
 
 static void
-_e_text_input_cb_cursor_rectangle_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED, int32_t x EINA_UNUSED, int32_t y EINA_UNUSED, int32_t w EINA_UNUSED, int32_t h EINA_UNUSED)
+_e_text_input_cb_cursor_rectangle_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h)
 {
+   Text_Input *ti = wl_resource_get_user_data(resource);
+
+   if (!ti->entered) return;
+   ti->pending.cursor_x = x;
+   ti->pending.cursor_y = y;
+   ti->pending.cursor_w = w;
+   ti->pending.cursor_h = h;
 }
 
 static void
@@ -228,10 +242,13 @@ _e_text_input_cb_commit(struct wl_client *client EINA_UNUSED, struct wl_resource
         _active_ti = ti;
         im = _e_input_method_get();
         if (!im) return;
-        if (was_enabled)
-          _e_input_method_state_send(im, ti);
-        else
+        if (!was_enabled)
           _e_input_method_activate(im, ti);
+        else
+          {
+             _e_input_method_state_send(im, ti);
+             _e_input_popups_update(im);
+          }
      }
    else if (was_enabled)
      _e_input_method_deactivate();
@@ -396,26 +413,189 @@ static const struct zwp_input_popup_surface_v2_interface _e_input_popup_surface_
    _e_input_method_cb_resource_destroy,
 };
 
+/* An input popup, the candidate list, is shown if and only if its input
+ * method is active, below the text cursor, or above it when there is no room
+ * below. */
+typedef struct
+{
+   struct wl_resource *res;
+   E_Client *ec;
+   Input_Method *im;
+} Input_Popup;
+
+static void
+_e_input_popup_place(Input_Popup *ip)
+{
+   E_Client *ec = ip->ec, *focus = wl_resource_get_user_data(_focus_surface);
+   const Text_Input_State *st = &_active_ti->current;
+   int cx, cy, x, y, zx, zy, zw, zh;
+
+   cx = focus->client.x + st->cursor_x;
+   cy = focus->client.y + st->cursor_y;
+   x = cx;
+   y = cy + st->cursor_h;
+   e_zone_useful_geometry_get(focus->zone, &zx, &zy, &zw, &zh);
+   if (x + ec->w > zx + zw) x = zx + zw - ec->w;
+   if (x < zx) x = zx;
+   if (y + ec->h > zy + zh) y = cy - ec->h;
+   if (y + ec->h > zy + zh) y = zy + zh - ec->h;
+   if (y < zy) y = zy;
+   e_client_util_move_without_frame(ec, x, y);
+   zwp_input_popup_surface_v2_send_text_input_rectangle(ip->res, cx - x, cy - y,
+                                                        st->cursor_w, st->cursor_h);
+}
+
+static void
+_e_input_popup_visible_update(Input_Popup *ip)
+{
+   E_Client *ec = ip->ec;
+
+   if (e_object_is_del(E_OBJECT(ec))) return;
+   if (ip->im && (ip->im == _e_input_method_get()) && _active_ti &&
+       ec->comp_data->mapped)
+     {
+        _e_input_popup_place(ip);
+        ec->visible = EINA_TRUE;
+        evas_object_show(ec->frame);
+        e_comp_object_damage(ec->frame, 0, 0, ec->w, ec->h);
+     }
+   else
+     {
+        ec->visible = EINA_FALSE;
+        evas_object_hide(ec->frame);
+     }
+}
+
+static void
+_e_input_popups_update(Input_Method *im)
+{
+   Input_Popup *ip;
+   Eina_List *l;
+
+   EINA_LIST_FOREACH(im->popups, l, ip)
+     _e_input_popup_visible_update(ip);
+}
+
+static void
+_e_input_popup_shell_map(struct wl_resource *resource)
+{
+   Input_Popup *ip = wl_resource_get_user_data(resource);
+
+   ip->ec->comp_data->mapped = EINA_TRUE;
+   _e_input_popup_visible_update(ip);
+}
+
+static void
+_e_input_popup_shell_unmap(struct wl_resource *resource)
+{
+   Input_Popup *ip = wl_resource_get_user_data(resource);
+
+   ip->ec->comp_data->mapped = EINA_FALSE;
+   _e_input_popup_visible_update(ip);
+}
+
+/* The client chooses its size, which moves it when it is against an edge. */
+static void
+_e_input_popup_shell_configure(struct wl_resource *resource, Evas_Coord x EINA_UNUSED, Evas_Coord y EINA_UNUSED, Evas_Coord w EINA_UNUSED, Evas_Coord h EINA_UNUSED)
+{
+   _e_input_popup_visible_update(wl_resource_get_user_data(resource));
+}
+
+static void
+_e_input_popup_res_destroy(struct wl_resource *resource)
+{
+   Input_Popup *ip = wl_resource_get_user_data(resource);
+   E_Client *ec = ip->ec;
+
+   if (ip->im) ip->im->popups = eina_list_remove(ip->im->popups, ip);
+   if (!e_object_is_del(E_OBJECT(ec)))
+     {
+        ec->visible = EINA_FALSE;
+        evas_object_hide(ec->frame);
+        ec->comp_data->mapped = EINA_FALSE;
+        ec->comp_data->shell.surface = NULL;
+        ec->comp_data->shell.configure = NULL;
+        ec->comp_data->shell.map = NULL;
+        ec->comp_data->shell.unmap = NULL;
+     }
+   e_object_unref(E_OBJECT(ec));
+   free(ip);
+}
+
 static const struct zwp_input_method_keyboard_grab_v2_interface _e_input_method_keyboard_grab_interface =
 {
    _e_input_method_cb_resource_destroy,
 };
 
-/* Not implemented yet: the popup is never shown. */
+/* Like the input panel of wl_desktop_shell, a window E places but neither
+ * decorates nor focuses: the focus going to it would deactivate the input
+ * method, and so hide it. */
 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)
+_e_input_method_cb_input_popup_surface_get(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface)
 {
+   Input_Method *im = wl_resource_get_user_data(resource);
+   E_Client *ec = wl_resource_get_user_data(surface);
    struct wl_resource *res;
+   Input_Popup *ip;
 
+   if (ec->comp_data->shell.surface)
+     {
+        wl_resource_post_error(resource, ZWP_INPUT_METHOD_V2_ERROR_ROLE,
+                               "wl_surface already has a role");
+        return;
+     }
+   ip = E_NEW(Input_Popup, 1);
+   if (!ip)
+     {
+        wl_resource_post_no_memory(resource);
+        return;
+     }
    res = wl_resource_create(client, &zwp_input_popup_surface_v2_interface,
                             wl_resource_get_version(resource), id);
    if (!res)
      {
-        wl_client_post_no_memory(client);
+        free(ip);
+        wl_resource_post_no_memory(resource);
         return;
      }
-   wl_resource_set_implementation(res, &_e_input_popup_surface_interface,
-                                  NULL, NULL);
+   ip->res = res;
+   ip->ec = ec;
+   e_object_ref(E_OBJECT(ec));
+   wl_resource_set_implementation(res, &_e_input_popup_surface_interface, ip,
+                                  _e_input_popup_res_destroy);
+   if (!im->inert)
+     {
+        ip->im = im;
+        im->popups = eina_list_append(im->popups, ip);
+     }
+
+   EC_CHANGED(ec);
+   if (!ec->new_client)
+     {
+        ec->new_client = EINA_TRUE;
+        e_comp->new_clients++;
+     }
+   if (ec->ignored) e_client_unignore(ec);
+   ec->borderless = EINA_TRUE;
+   ec->argb = EINA_TRUE;
+   ec->lock_border = EINA_TRUE;
+   ec->lock_focus_in = ec->lock_focus_out = EINA_TRUE;
+   ec->netwm.state.skip_taskbar = EINA_TRUE;
+   ec->netwm.state.skip_pager = EINA_TRUE;
+   ec->no_shape_cut = EINA_TRUE;
+   ec->border_size = 0;
+   ec->netwm.type = E_WINDOW_TYPE_UTILITY;
+   ec->layer = E_LAYER_CLIENT_POPUP;
+   evas_object_layer_set(ec->frame, E_LAYER_CLIENT_POPUP);
+
+   ec->comp_data->shell.surface = res;
+   ec->comp_data->shell.configure_send = NULL;
+   ec->comp_data->shell.configure = _e_input_popup_shell_configure;
+   ec->comp_data->shell.ping = NULL;
+   ec->comp_data->shell.map = _e_input_popup_shell_map;
+   ec->comp_data->shell.unmap = _e_input_popup_shell_unmap;
+   /* A buffer committed before the role was given found no map to call. */
+   if (e_pixmap_usable_get(ec->pixmap)) _e_input_popup_shell_map(res);
 }
 
 EINTERN void
@@ -482,9 +662,15 @@ static void
 _e_input_method_res_destroy(struct wl_resource *resource)
 {
    Input_Method *im = wl_resource_get_user_data(resource);
+   Input_Popup *ip;
 
    if (_input_method == im) _input_method = NULL;
    if (im->grab) wl_resource_set_user_data(im->grab, NULL);
+   EINA_LIST_FREE(im->popups, ip)
+     {
+        ip->im = NULL;
+        _e_input_popup_visible_update(ip);
+     }
    _e_input_method_pending_clear(im);
    free(im);
 }
diff --git a/src/tests/wayland/e_wl_testkit.c b/src/tests/wayland/e_wl_testkit.c
index 2be3cde92..141777712 100644
--- a/src/tests/wayland/e_wl_testkit.c
+++ b/src/tests/wayland/e_wl_testkit.c
@@ -55,6 +55,7 @@ struct _Tk
 
    struct wl_surface *info_surface;
    int info_x, info_y, info_w, info_h;
+   int info_visible;
    int info_known;
 
    int configured;
@@ -73,12 +74,13 @@ _surface_info(void *data, struct wl_test *t, struct wl_surface *s,
 {
    Tk *tk = data;
 
-   (void)t; (void)vis; (void)foc;
+   (void)t; (void)foc;
    if (s != tk->info_surface) return;
    tk->info_x = x;
    tk->info_y = y;
    tk->info_w = w;
    tk->info_h = h;
+   tk->info_visible = vis;
    tk->info_known = 1;
 }
 
@@ -755,6 +757,13 @@ tk_surface_geometry(Tk *tk, struct wl_surface *surface,
    if (h) *h = tk->info_h;
 }
 
+int
+tk_surface_visible(Tk *tk, struct wl_surface *surface)
+{
+   tk_surface_geometry(tk, surface, NULL, NULL, NULL, NULL);
+   return tk->info_visible;
+}
+
 void
 tk_touch_down(Tk *tk, int id, int x, int y)
 {
diff --git a/src/tests/wayland/e_wl_testkit.h b/src/tests/wayland/e_wl_testkit.h
index ef9c4d0ea..5005030d6 100644
--- a/src/tests/wayland/e_wl_testkit.h
+++ b/src/tests/wayland/e_wl_testkit.h
@@ -162,6 +162,8 @@ void tk_surface_paint(Tk *tk, struct wl_surface *surface, int w, int h);
 /* Where the compositor has a surface, in compositor coordinates. */
 void tk_surface_geometry(Tk *tk, struct wl_surface *surface,
                          int *x, int *y, int *w, int *h);
+/* Whether the compositor shows a surface. */
+int tk_surface_visible(Tk *tk, struct wl_surface *surface);
 
 /* Press or release a linux/input.h BTN_* button. */
 void tk_pointer_button(Tk *tk, unsigned int button, int pressed);
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index 44df7ceb7..fb14b02b6 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -93,6 +93,7 @@ wl_protocol_tests = [
   ['idle-inhibit', 'test_idle_inhibit.c'],
   ['text-input', 'test_text_input.c'],
   ['input-method-keyboard', 'test_input_method_keyboard.c'],
+  ['input-popup', 'test_input_popup.c'],
   ['privileges', 'test_privileges.c',
    {'PATH': meson.current_build_dir()}],
   ['client-iconify', 'test_client_iconify.c',
diff --git a/src/tests/wayland/test_input_popup.c b/src/tests/wayland/test_input_popup.c
new file mode 100644
index 000000000..eee600f28
--- /dev/null
+++ b/src/tests/wayland/test_input_popup.c
@@ -0,0 +1,379 @@
+/* zwp_input_popup_surface_v2, the input method's candidate list: shown if
+ * and only if the input method is active, below the text cursor of the
+ * focused window, and told where that cursor is in its own coordinates. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.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"
+
+#define PROG "test-input-popup"
+#define APP_ID "e.test.input-popup"
+#define FOCUS WL_TEST_CLIENT_STATE_FOCUSED
+#define PW 80
+#define PH 40
+
+typedef struct
+{
+   int x, y, w, h;
+   int rects;
+} Rect;
+
+static Tk *app, *ime;
+static struct wl_seat *ime_seat;
+static struct zwp_input_method_manager_v2 *im_manager;
+static struct zwp_text_input_v3 *ti;
+static int origin_x, origin_y, origin_known, zone_w, zone_h;
+static struct wl_surface *ime_pointer_surface;
+
+static void
+_rect(void *data, struct zwp_input_popup_surface_v2 *popup __attribute__((unused)),
+      int32_t x, int32_t y, int32_t w, int32_t h)
+{
+   Rect *r = data;
+
+   r->x = x;
+   r->y = y;
+   r->w = w;
+   r->h = h;
+   r->rects++;
+}
+
+static const struct zwp_input_popup_surface_v2_listener _popup_listener = { _rect };
+
+static void
+_im_event(void *data __attribute__((unused)), struct zwp_input_method_v2 *im __attribute__((unused)))
+{
+}
+
+static void
+_im_text(void *data __attribute__((unused)), struct zwp_input_method_v2 *im __attribute__((unused)),
+         const char *text __attribute__((unused)), uint32_t c __attribute__((unused)),
+         uint32_t a __attribute__((unused)))
+{
+}
+
+static void
+_im_uint(void *data __attribute__((unused)), struct zwp_input_method_v2 *im __attribute__((unused)),
+         uint32_t v __attribute__((unused)))
+{
+}
+
+static void
+_im_uint2(void *data __attribute__((unused)), struct zwp_input_method_v2 *im __attribute__((unused)),
+          uint32_t a __attribute__((unused)), uint32_t b __attribute__((unused)))
+{
+}
+
+static const struct zwp_input_method_v2_listener _im_listener =
+{
+   _im_event, _im_event, _im_text, _im_uint, _im_uint2, _im_event, _im_event
+};
+
+static void
+_ptr_enter(void *data __attribute__((unused)), struct wl_pointer *p __attribute__((unused)),
+           uint32_t serial __attribute__((unused)), struct wl_surface *s __attribute__((unused)),
+           wl_fixed_t x, wl_fixed_t y)
+{
+   if (origin_known) return;
+   origin_x = 150 - wl_fixed_to_int(x);
+   origin_y = 150 - wl_fixed_to_int(y);
+   origin_known = 1;
+}
+
+static void
+_ptr_leave(void *data __attribute__((unused)), struct wl_pointer *p __attribute__((unused)),
+           uint32_t serial __attribute__((unused)), struct wl_surface *s __attribute__((unused)))
+{
+}
+
+static void
+_ptr_motion(void *data __attribute__((unused)), struct wl_pointer *p __attribute__((unused)),
+            uint32_t time __attribute__((unused)), wl_fixed_t x __attribute__((unused)),
+            wl_fixed_t y __attribute__((unused)))
+{
+}
+
+static void
+_ptr_button(void *data __attribute__((unused)), struct wl_pointer *p __attribute__((unused)),
+            uint32_t serial __attribute__((unused)), uint32_t time __attribute__((unused)),
+            uint32_t button __attribute__((unused)), uint32_t state __attribute__((unused)))
+{
+}
+
+static void
+_ptr_axis(void *data __attribute__((unused)), struct wl_pointer *p __attribute__((unused)),
+          uint32_t time __attribute__((unused)), uint32_t axis __attribute__((unused)),
+          wl_fixed_t value __attribute__((unused)))
+{
+}
+
+static void
+_ime_ptr_enter(void *data __attribute__((unused)), struct wl_pointer *p __attribute__((unused)),
+               uint32_t serial __attribute__((unused)), struct wl_surface *s,
+               wl_fixed_t x __attribute__((unused)), wl_fixed_t y __attribute__((unused)))
+{
+   ime_pointer_surface = s;
+}
+
+static void
+_ime_ptr_leave(void *data __attribute__((unused)), struct wl_pointer *p __attribute__((unused)),
+               uint32_t serial __attribute__((unused)), struct wl_surface *s __attribute__((unused)))
+{
+   ime_pointer_surface = NULL;
+}
+
+static const struct wl_pointer_listener _ime_ptr_listener =
+{
+   _ime_ptr_enter, _ime_ptr_leave, _ptr_motion, _ptr_button, _ptr_axis,
+   NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+static const struct wl_pointer_listener _ptr_listener =
+{
+   _ptr_enter, _ptr_leave, _ptr_motion, _ptr_button, _ptr_axis,
+   NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+static void
+_output_geometry(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+                 int32_t x __attribute__((unused)), int32_t y __attribute__((unused)),
+                 int32_t pw __attribute__((unused)), int32_t ph __attribute__((unused)),
+                 int32_t subpixel __attribute__((unused)), const char *make __attribute__((unused)),
+                 const char *model __attribute__((unused)), int32_t transform __attribute__((unused)))
+{
+}
+
+static void
+_output_mode(void *data __attribute__((unused)), struct wl_output *o __attribute__((unused)),
+             uint32_t flags __attribute__((unused)), int32_t w, int32_t h,
+             int32_t refresh __attribute__((unused)))
+{
+   zone_w = w;
+   zone_h = h;
+}
+
+static const struct wl_output_listener _output_listener =
+{
+   _output_geometry, _output_mode, NULL, NULL, NULL, NULL
+};
+
+static void
+_settle(void)
+{
+   tk_sync(app);
+   tk_sync(ime);
+   tk_sync(app);
+}
+
+static void
+_cursor(int enable, int x, int y)
+{
+   if (enable) zwp_text_input_v3_enable(ti);
+   zwp_text_input_v3_set_cursor_rectangle(ti, x, y, 5, 15);
+   zwp_text_input_v3_commit(ti);
+   _settle();
+}
+
+static void
+_disable(void)
+{
+   zwp_text_input_v3_disable(ti);
+   zwp_text_input_v3_commit(ti);
+   _settle();
+}
+
+static struct zwp_input_popup_surface_v2 *
+_popup_new(struct zwp_input_method_v2 *im, struct wl_surface **surface, Rect *r, int buffer_first)
+{
+   struct zwp_input_popup_surface_v2 *popup;
+
+   *surface = tk_surface_new(ime);
+   if (buffer_first) tk_surface_paint(ime, *surface, PW, PH);
+   popup = zwp_input_method_v2_get_input_popup_surface(im, *surface);
+   zwp_input_popup_surface_v2_add_listener(popup, &_popup_listener, r);
+   if (!buffer_first) tk_surface_paint(ime, *surface, PW, PH);
+   _settle();
+   return popup;
+}
+
+/* A hide may run the theme's hide animation first. */
+static void
+_expect_hidden(struct wl_surface *surface, const char *what)
+{
+   time_t deadline = time(NULL) + 5;
+
+   while (tk_surface_visible(ime, surface))
+     {
+        if (time(NULL) > deadline) tk_fail(ime, "%s: the popup is shown", what);
+        tk_sync(ime);
+     }
+}
+
+static void
+_expect_at(struct wl_surface *surface, Rect *r, int x, int y, int rx, int ry, const char *what)
+{
+   int px, py;
+
+   if (!tk_surface_visible(ime, surface)) tk_fail(ime, "%s: the popup is hidden", what);
+   tk_surface_geometry(ime, surface, &px, &py, NULL, NULL);
+   if ((px != x) || (py != y))
+     tk_fail(ime, "%s: the popup is at %d,%d, not %d,%d", what, px, py, x, y);
+   if ((!r->rects) || (r->x != rx) || (r->y != ry) || (r->w != 5) || (r->h != 15))
+     tk_fail(ime, "%s: text_input_rectangle %d,%d %dx%d (%d sent), not %d,%d 5x15",
+             what, r->x, r->y, r->w, r->h, r->rects, rx, ry);
+}
+
+static void
+_test_role_error(void)
+{
+   struct zwp_input_method_manager_v2 *manager;
+   struct zwp_input_method_v2 *im;
+   const struct wl_interface *iface;
+   struct wl_surface *surface;
+   struct wl_seat *seat;
+   Tk *tk;
+
+   tk = tk_connect(PROG);
+   seat = tk_bind(tk, &wl_seat_interface, 1);
+   manager = tk_bind(tk, &zwp_input_method_manager_v2_interface, 1);
+   if ((!seat) || (!manager)) tk_fail(tk, "missing global");
+   im = zwp_input_method_manager_v2_get_input_method(manager, seat);
+   surface = tk_surface_new(tk);
+   zwp_input_method_v2_get_input_popup_surface(im, surface);
+   zwp_input_method_v2_get_input_popup_surface(im, surface);
+   if ((tk_protocol_error(tk, &iface) != ZWP_INPUT_METHOD_V2_ERROR_ROLE) ||
+       (iface != &zwp_input_method_v2_interface))
+     tk_fail(tk, "a second role is not a role error");
+   tk_disconnect(tk);
+}
+
+int
+main(void)
+{
+   struct zwp_text_input_manager_v3 *ti_manager;
+   struct zwp_input_popup_surface_v2 *popup, *early, *other;
+   struct zwp_input_method_v2 *im, *im2;
+   struct wl_surface *surface, *early_surface, *other_surface;
+   struct wl_test *tester;
+   struct wl_seat *app_seat;
+   struct wl_output *output;
+   Tk_Toplevel *top;
+   Rect r = { 0 }, early_r = { 0 }, other_r = { 0 };
+
+   tk_privileges_file("test-input-popup", NULL, "input_method;");
+   app = tk_connect(PROG);
+   ime = tk_connect(PROG);
+   tester = tk_bind(app, &wl_test_interface, 1);
+   app_seat = tk_bind(app, &wl_seat_interface, 1);
+   output = tk_bind(app, &wl_output_interface, 1);
+   ime_seat = tk_bind(ime, &wl_seat_interface, 1);
+   if (ime_seat)
+     wl_pointer_add_listener(wl_seat_get_pointer(ime_seat), &_ime_ptr_listener, NULL);
+   ti_manager = tk_bind(app, &zwp_text_input_manager_v3_interface, 1);
+   im_manager = tk_bind(ime, &zwp_input_method_manager_v2_interface, 1);
+   if ((!tester) || (!app_seat) || (!output) || (!ime_seat) || (!ti_manager) || (!im_manager))
+     tk_fail(app, "missing global");
+   wl_output_add_listener(output, &_output_listener, NULL);
+   wl_pointer_add_listener(wl_seat_get_pointer(app_seat), &_ptr_listener, NULL);
+
+   ti = zwp_text_input_manager_v3_get_text_input(ti_manager, app_seat);
+   top = tk_toplevel_new_shadowed(app, APP_ID, APP_ID, 200, 150, 10);
+   tk_wait_states(app, APP_ID, FOCUS, FOCUS, "a new window has the focus");
+   wl_test_move_surface(tester, tk_toplevel_surface(top), 100, 100);
+   tk_settle(app);
+   /* The window's surface origin, from where the pointer is in it. */
+   tk_pointer_warp(app, 150, 150);
+   _settle();
+   if ((!origin_known) || (!zone_w) || (!zone_h)) tk_fail(app, "no pointer enter or no output mode");
+
+   im = zwp_input_method_manager_v2_get_input_method(im_manager, ime_seat);
+   zwp_input_method_v2_add_listener(im, &_im_listener, NULL);
+   popup = _popup_new(im, &surface, &r, 0);
+   early = _popup_new(im, &early_surface, &early_r, 1);
+   _expect_hidden(surface, "no field enabled");
+   _expect_hidden(early_surface, "no field enabled, buffer before the role");
+
+   _cursor(1, 10, 20);
+   _expect_at(surface, &r, origin_x + 10, origin_y + 35, 0, -15, "enabled");
+   _expect_at(early_surface, &early_r, origin_x + 10, origin_y + 35, 0, -15,
+              "enabled, buffer before the role");
+   if (tk_surface_visible(app, tk_toplevel_surface(top)) != 1)
+     tk_fail(app, "the window is hidden");
+   tk_wait_states(app, APP_ID, FOCUS, FOCUS, "the window keeps the focus");
+
+   _cursor(0, 30, 40);
+   _expect_at(surface, &r, origin_x + 30, origin_y + 55, 0, -15, "the cursor moved");
+
+   /* No room below: above the cursor. */
+   _cursor(0, 30, zone_h - origin_y - 20);
+   _expect_at(surface, &r, origin_x + 30, zone_h - 20 - PH, 0, PH, "no room below");
+
+   /* No room above either: against the bottom edge. */
+   _cursor(0, 30, zone_h - origin_y + 100);
+   _expect_at(surface, &r, origin_x + 30, zone_h - PH, 0, 100 + PH, "no room at all");
+
+   /* No room on the right: against the right edge. */
+   _cursor(0, zone_w - origin_x - 10, 40);
+   _expect_at(surface, &r, zone_w - PW, origin_y + 55, PW - 10, -15, "no room on the right");
+
+   /* A resized popup is placed with its new size. */
+   tk_surface_paint(ime, surface, PW + 20, PH);
+   _settle();
+   _expect_at(surface, &r, zone_w - PW - 20, origin_y + 55, PW + 10, -15, "resized");
+   tk_surface_paint(ime, surface, PW, PH);
+   _cursor(0, 10, 20);
+
+   /* Above the window, even raised, and a click does not take the focus. */
+   tk_action(app, tk_expect(app, APP_ID)->id, "window_raise", NULL);
+   tk_pointer_warp(app, origin_x + 10 + PW / 2, origin_y + 35 + PH / 2);
+   _settle();
+   if (ime_pointer_surface != surface) tk_fail(ime, "the pointer is not on the popup");
+   tk_pointer_button(app, BTN_LEFT, 1);
+   tk_pointer_button(app, BTN_LEFT, 0);
+   _settle();
+   tk_wait_states(app, APP_ID, FOCUS, FOCUS, "the window keeps the focus after a click on the popup");
+   _expect_at(surface, &r, origin_x + 10, origin_y + 35, 0, -15, "clicked");
+
+   /* Unmapped by a NULL buffer, and mapped again. */
+   wl_surface_attach(surface, NULL, 0, 0);
+   wl_surface_commit(surface);
+   _settle();
+   _expect_hidden(surface, "unmapped");
+   tk_surface_paint(ime, surface, PW, PH);
+   _settle();
+   _expect_at(surface, &r, origin_x + 10, origin_y + 35, 0, -15, "mapped again");
+
+   /* A second input method is unavailable, and so is its popup. */
+   im2 = zwp_input_method_manager_v2_get_input_method(im_manager, ime_seat);
+   zwp_input_method_v2_add_listener(im2, &_im_listener, NULL);
+   other = _popup_new(im2, &other_surface, &other_r, 0);
+   _expect_hidden(other_surface, "the popup of an unavailable input method");
+   _disable();
+   _expect_hidden(surface, "disabled");
+   _cursor(1, 10, 20);
+   _expect_hidden(other_surface, "the popup of an unavailable input method, enabled again");
+   if (other_r.rects) tk_fail(ime, "the popup of an unavailable input method got a rectangle");
+   zwp_input_popup_surface_v2_destroy(other);
+   zwp_input_method_v2_destroy(im2);
+
+   /* The input method goes first. */
+   zwp_input_method_v2_destroy(im);
+   _settle();
+   _expect_hidden(surface, "the input method is gone");
+   _expect_hidden(early_surface, "the input method is gone, buffer before the role");
+   zwp_input_popup_surface_v2_destroy(popup);
+   zwp_input_popup_surface_v2_destroy(early);
+   _settle();
+
+   _test_role_error();
+
+   tk_disconnect(ime);
+   tk_disconnect(app);
+   printf(PROG ": ok\n");
+   return 0;
+}

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

Reply via email to