selection: delete stale handler on Wayland so re-selection pushes fresh data

This commit is contained in:
Ollie 2026-05-28 21:36:26 +02:00
parent 1bcd815001
commit 2b692a34f1
1 changed files with 26 additions and 12 deletions

View File

@ -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);
}
}