From d0bf380efa4ab0aabc5479274043f0de1115a232 Mon Sep 17 00:00:00 2001 From: Foxe Chen Date: Mon, 14 Jul 2025 21:54:23 +0200 Subject: [PATCH] patch 9.1.1543: Wayland: clipboard appears to not be working Problem: Wayland: clipboard appears to not be working (Fuad Veliev) Solution: Explicitly set selection each time (Foxe Chen) fixes: #17732 closes: #17740 Signed-off-by: Foxe Chen Signed-off-by: Christian Brabandt --- src/version.c | 2 ++ src/wayland.c | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/version.c b/src/version.c index e14de81a4c..634bf58b48 100644 --- a/src/version.c +++ b/src/version.c @@ -719,6 +719,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1543, /**/ 1542, /**/ diff --git a/src/wayland.c b/src/wayland.c index 3fef423ebc..f9af42d71c 100644 --- a/src/wayland.c +++ b/src/wayland.c @@ -2098,7 +2098,7 @@ vwl_data_device_listener_finished(vwl_data_device_T *device) { vwl_clipboard_selection_T *clip_sel = device->data; - vwl_data_device_destroy(device, FALSE); + vwl_data_device_destroy(&clip_sel->device, FALSE); vwl_data_offer_destroy(clip_sel->offer, TRUE); vwl_data_source_destroy(&clip_sel->source, FALSE); vwl_clipboard_free_mime_types(clip_sel); @@ -2246,8 +2246,39 @@ wayland_cb_own_selection( return FAIL; if (clip_sel->source.proxy != NULL) - // We already own the selection - return OK; + { + if (selection == WAYLAND_SELECTION_PRIMARY) + // We already own the selection, ignore (only do this for primary + // selection). We don't re set the selection because then we would + // be setting the selection every time the user moves the visual + // selection cursor, which is messy and inefficient. + // + // Vim doesn't have a mechanism to only set the selection + // when the user stops selecting (such as the user releasing the + // mouse button in graphical Wayland applications). So this + // behaviour in Vim differs from other Wayland applications. + return OK; + else if (selection == WAYLAND_SELECTION_REGULAR) + { + // Technically we don't need to do this as we already own the + // selection, however if a user yanks text a second time, the + // text yanked won't appear in their clipboard manager if they are + // using one. + // + // This can be unexpected behaviour for the user so its probably + // better to do it this way. Additionally other Wayland applications + // seem to set the selection every time. + // + // There should be no noticable performance change since its not + // like this is running in the background constantly in Vim, only + // runs once when the user yanks text to the system clipboard. + vwl_data_source_destroy(&clip_sel->source, FALSE); + vwl_display_flush(&vwl_display); + } + else + // Shouldn't happen + return FAIL; + } if (!wayland_client_is_connected(FALSE) || !vwl_clipboard_selection_is_ready(clip_sel))