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