From 2b692a34f19dd03a186f88aba9fca41de1df87a3 Mon Sep 17 00:00:00 2001 From: Ollie Date: Thu, 28 May 2026 21:36:26 +0200 Subject: [PATCH] selection: delete stale handler on Wayland so re-selection pushes fresh data --- WINGs/selection_x11.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/WINGs/selection_x11.c b/WINGs/selection_x11.c index 4380458..13428a2 100644 --- a/WINGs/selection_x11.c +++ b/WINGs/selection_x11.c @@ -337,6 +337,11 @@ Bool WMCreateSelectionHandler(WMView * view, WMNativeAtom selection, Time timest WMPostNotificationName(WMSelectionOwnerDidChangeNotification, (void *)selection, (void *)view); + /* On Wayland: delete any existing handler so fresh data is + * pushed on re-selection (e.g. double-click after paste). */ + if (vb->selection_fetch) + WMDeleteSelectionHandler(view, selection, WM_CURRENT_TIME); + /*//printf("created selection handler for %d\n", W_VIEW_DRAWABLE(view)); */ handler = wmalloc(sizeof(SelectionHandler)); @@ -357,19 +362,28 @@ Bool WMCreateSelectionHandler(WMView * view, WMNativeAtom selection, Time timest * the selection data via the clipboard store path so external * clients can paste it. The data is fetched from the view's * convertSelection callback. */ - if (vb->selection_fetch && handler->procs.convertSelection) { - WMNativeAtom textAtom = XA_STRING; - WMNativeAtom type; - WMData *data = handler->procs.convertSelection(handler->view, - selection, textAtom, handler->data, &type); - if (data) { - if (view->screen->viewBackend->clipboard_store) { - view->screen->viewBackend->clipboard_store( - view->screen->viewBackendCtx, - WMDataBytes(data), - WMGetDataLength(data)); + /* On Wayland (no X11 SelectionRequest events), push selection data + * to the compositor via the clipboard store path. If a handler + * already exists for this view+selection, just push fresh data + * so selection is always current (otherwise double-click to + * reselect would be skipped since ownsSelection is stale). */ + if (vb->selection_fetch) { + /* Delete any existing handler for this view+selection first */ + WMDeleteSelectionHandler(view, selection, WM_CURRENT_TIME); + if (handler->procs.convertSelection) { + WMNativeAtom textAtom = XA_STRING; + WMNativeAtom type; + WMData *d = handler->procs.convertSelection(handler->view, + selection, textAtom, handler->data, &type); + if (d) { + if (view->screen->viewBackend->clipboard_store) { + view->screen->viewBackend->clipboard_store( + view->screen->viewBackendCtx, + WMDataBytes(d), + WMGetDataLength(d)); + } + WMReleaseData(d); } - WMReleaseData(data); } }