[mutter/wip/carlosg/cancel-unfocused-sources: 101/101] wayland: Cancel selection data sources that are set while unfocused




commit 4bee25d8e64c7e2f994e7d1875627424a473ecde
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Mar 11 11:16:52 2021 +0100

    wayland: Cancel selection data sources that are set while unfocused
    
    If a client is naive enough to assume that it can set the selection while
    it has got no surfaces, mutter will simply ignore the request and leave
    the selection unchanged.
    
    This is good and the expected behavior, however the poor client that did
    this will enter in an inconsistent state where it "claimed" the selection,
    but nobody told it that the wl_data_source is not current.
    
    So, when the client is focused the next time, it will receive wl_data_offers
    as usual, but it will still think all the time that it is owning the
    selection. In the case of GTK, that takes client-side shortcuts, so any
    attempted paste will still bring back the client-side aborted selection.
    
    To fix this, cancel the selection right away if it happened while unfocused,
    the client will be able to undo its own failed selection, and not assume
    that future offers are its own.
    
    Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1469
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1772>

 src/wayland/meta-wayland-data-device-primary-legacy.c | 6 +++++-
 src/wayland/meta-wayland-data-device-primary.c        | 6 +++++-
 src/wayland/meta-wayland-data-device.c                | 6 +++++-
 3 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/src/wayland/meta-wayland-data-device-primary-legacy.c 
b/src/wayland/meta-wayland-data-device-primary-legacy.c
index 26d432357c..684247e042 100644
--- a/src/wayland/meta-wayland-data-device-primary-legacy.c
+++ b/src/wayland/meta-wayland-data-device-primary-legacy.c
@@ -172,7 +172,11 @@ primary_device_set_selection (struct wl_client   *client,
 
   if (wl_resource_get_client (resource) !=
       meta_wayland_keyboard_get_focus_client (seat->keyboard))
-    return;
+    {
+      if (source)
+        meta_wayland_data_source_cancel (source);
+      return;
+    }
 
   meta_wayland_data_device_primary_legacy_set_selection (data_device, source, serial);
 }
diff --git a/src/wayland/meta-wayland-data-device-primary.c b/src/wayland/meta-wayland-data-device-primary.c
index ef1c5d9648..9592e8f772 100644
--- a/src/wayland/meta-wayland-data-device-primary.c
+++ b/src/wayland/meta-wayland-data-device-primary.c
@@ -172,7 +172,11 @@ primary_device_set_selection (struct wl_client   *client,
 
   if (wl_resource_get_client (resource) !=
       meta_wayland_keyboard_get_focus_client (seat->keyboard))
-    return;
+    {
+      if (source)
+        meta_wayland_data_source_cancel (source);
+      return;
+    }
 
   meta_wayland_data_device_primary_set_selection (data_device, source, serial);
 }
diff --git a/src/wayland/meta-wayland-data-device.c b/src/wayland/meta-wayland-data-device.c
index 3e54cfa3c9..61b4435d42 100644
--- a/src/wayland/meta-wayland-data-device.c
+++ b/src/wayland/meta-wayland-data-device.c
@@ -938,7 +938,11 @@ data_device_set_selection (struct wl_client *client,
 
   if (wl_resource_get_client (resource) !=
       meta_wayland_keyboard_get_focus_client (seat->keyboard))
-    return;
+    {
+      if (source)
+        meta_wayland_data_source_cancel (source);
+      return;
+    }
 
   /* FIXME: Store serial and check against incoming serial here. */
   meta_wayland_data_device_set_selection (data_device, source, serial);


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