dix: Add a selection bridge callback

This is intended to be used to implement selection bridges in mixed
windowing systems such as Xwayland.

This adds a new SelectionBridgeCallback along with a new
SelectionBridgeInfoRec to convey the information from a selection
request so that a DDX such as Xwayland can bridge that to some other
clipboard implementation from another windowing system directly from the
DDX.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Assisted-by: Cursor AI
This commit is contained in:
Olivier Fourdan 2026-03-10 13:42:18 +01:00
parent 16ca2c7a11
commit b77bc02cbc
2 changed files with 42 additions and 0 deletions

View file

@ -66,6 +66,7 @@ SOFTWARE.
Selection *CurrentSelections;
CallbackListPtr SelectionCallback;
CallbackListPtr SelectionBridgeCallback;
int
dixLookupSelection(Selection ** result, Atom selectionName,
@ -247,6 +248,22 @@ ProcGetSelectionOwner(ClientPtr client)
return Success;
}
static void
CallSelectionBridgeCallback(ClientPtr pClient, Selection *pSel, xEvent *event)
{
SelectionBridgeInfoRec info = {
.screen = pSel->pWin->drawable.pScreen,
.client = pClient,
.requestor = event->u.selectionRequest.requestor,
.selection = event->u.selectionRequest.selection,
.target = event->u.selectionRequest.target,
.property = event->u.selectionRequest.property,
.time = ClientTimeToServerTime(event->u.selectionRequest.time),
};
CallCallbacks(&SelectionBridgeCallback, &info);
}
int
ProcConvertSelection(ClientPtr client)
{
@ -291,6 +308,14 @@ ProcConvertSelection(ClientPtr client)
WriteEventsToClient(pSel->client, 1, &event);
return Success;
}
/* If the selection is owned by the server client, and there are
* selection bridge callbacks registered, call them now.
*/
if (pSel->client == serverClient && SelectionBridgeCallback != NULL) {
CallSelectionBridgeCallback(client, pSel, &event);
return Success;
}
}
event.u.u.type = SelectionNotify;

View file

@ -49,6 +49,7 @@ SOFTWARE.
#include "dixstruct.h"
#include "privates.h"
#include "screenint.h"
/*
* Selection data structures
@ -87,6 +88,22 @@ typedef struct {
SelectionCallbackKind kind;
} SelectionInfoRec;
/*
* Selection bridge callback:
* can be used to bridge a selection request to the target clients.
*/
extern _X_EXPORT CallbackListPtr SelectionBridgeCallback;
typedef struct {
ScreenPtr screen;
ClientPtr client;
Window requestor;
Atom selection;
Atom target;
Atom property;
TimeStamp time;
} SelectionBridgeInfoRec;
/*
* Selection server internals
*/