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 <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Foxe Chen
2025-07-14 21:54:23 +02:00
committed by Christian Brabandt
parent 6865bdc914
commit d0bf380efa
2 changed files with 36 additions and 3 deletions

View File

@ -719,6 +719,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1543,
/**/
1542,
/**/

View File

@ -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
{
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))