[mutter/wip/carlosg/text-input-ignore-unfocused: 116/116] wayland: Ignore text_input requests from unfocused clients




commit a9ae43ff437542813d5bfd1dab6d6263334bc916
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 18 18:53:52 2022 +0200

    wayland: Ignore text_input requests from unfocused clients
    
    This is what the protocol says we should do, and even though normally
    an out of focus client should not have any reason to create IM requests,
    there is a bit of a grey area around focus changes, as both the client
    losing focus and the client gaining focus may respectively try to
    disable/enable in an undetermined order.
    
    Anyways, since in that situation the client losing focus is not aware
    of the requests being ignored, the serial should always be incremented
    in order not to break accounting of .done/.commit for that specific
    client.
    
    Fixes the IM focus being possibly "lost" after changing focus between
    clients, if the race condition turned the odds in that direction.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2585>

 src/wayland/meta-wayland-text-input.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/src/wayland/meta-wayland-text-input.c b/src/wayland/meta-wayland-text-input.c
index 949ec4dda7..1cfeb35777 100644
--- a/src/wayland/meta-wayland-text-input.c
+++ b/src/wayland/meta-wayland-text-input.c
@@ -412,12 +412,25 @@ text_input_destroy (struct wl_client   *client,
   wl_resource_destroy (resource);
 }
 
+static gboolean
+client_matches_focus (MetaWaylandTextInput *text_input,
+                      struct wl_client     *client)
+{
+  if (!text_input->surface)
+    return FALSE;
+
+  return client == wl_resource_get_client (text_input->surface->resource);
+}
+
 static void
 text_input_enable (struct wl_client   *client,
                    struct wl_resource *resource)
 {
   MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
 
+  if (!client_matches_focus (text_input, client))
+    return;
+
   text_input->enabled = TRUE;
   text_input->pending_state |= META_WAYLAND_PENDING_STATE_ENABLED;
 }
@@ -428,6 +441,9 @@ text_input_disable (struct wl_client   *client,
 {
   MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
 
+  if (!client_matches_focus (text_input, client))
+    return;
+
   text_input->enabled = FALSE;
   text_input->pending_state |= META_WAYLAND_PENDING_STATE_ENABLED;
 }
@@ -441,6 +457,9 @@ text_input_set_surrounding_text (struct wl_client   *client,
 {
   MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
 
+  if (!client_matches_focus (text_input, client))
+    return;
+
   g_free (text_input->surrounding.text);
   text_input->surrounding.text = g_strdup (text);
   text_input->surrounding.cursor = cursor;
@@ -450,11 +469,14 @@ text_input_set_surrounding_text (struct wl_client   *client,
 
 static void
 text_input_set_text_change_cause (struct wl_client   *client,
-                                 struct wl_resource *resource,
-                                 uint32_t            cause)
+                                  struct wl_resource *resource,
+                                  uint32_t            cause)
 {
   MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
 
+  if (!client_matches_focus (text_input, client))
+    return;
+
   text_input->text_change_cause = cause;
   text_input->pending_state |= META_WAYLAND_PENDING_STATE_CHANGE_CAUSE;
 }
@@ -533,7 +555,7 @@ text_input_set_content_type (struct wl_client   *client,
 {
   MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
 
-  if (!text_input->surface)
+  if (!client_matches_focus (text_input, client))
     return;
 
   text_input->content_type_hint = hint;
@@ -551,7 +573,7 @@ text_input_set_cursor_rectangle (struct wl_client   *client,
 {
   MetaWaylandTextInput *text_input = wl_resource_get_user_data (resource);
 
-  if (!text_input->surface)
+  if (!client_matches_focus (text_input, client))
     return;
 
   text_input->cursor_rect = (cairo_rectangle_int_t) { x, y, width, height };
@@ -580,7 +602,7 @@ text_input_commit_state (struct wl_client   *client,
 
   increment_serial (text_input, resource);
 
-  if (text_input->surface == NULL)
+  if (!client_matches_focus (text_input, client))
     return;
 
   input_method = clutter_backend_get_input_method (clutter_get_default_backend ());


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]