video: cache some more atoms under X11

This patch adds the caching of some atoms used by the clipboard.
This commit is contained in:
David Fort
2024-09-30 16:42:38 +02:00
committed by Sam Lantinga
parent dcc7560a5c
commit 801870c8cf
4 changed files with 11 additions and 19 deletions

View File

@@ -174,7 +174,6 @@ static void *GetSelectionData(SDL_VideoDevice *_this, Atom selection_type,
unsigned char *src = NULL;
bool incr_success = false;
Atom XA_MIME = X11_XInternAtom(display, mime_type, False);
Atom XA_INCR = X11_XInternAtom(display, "INCR", False);
*length = 0;
@@ -199,7 +198,7 @@ static void *GetSelectionData(SDL_VideoDevice *_this, Atom selection_type,
} else {
// Request that the selection owner copy the data to our window
owner = window;
selection = X11_XInternAtom(display, "SDL_SELECTION", False);
selection = videodata->SDL_SELECTION;
X11_XConvertSelection(display, selection_type, XA_MIME, selection, owner,
CurrentTime);
@@ -213,7 +212,7 @@ static void *GetSelectionData(SDL_VideoDevice *_this, Atom selection_type,
if (seln_type == XA_MIME) {
*length = (size_t)count;
data = CloneDataBuffer(src, count);
} else if (seln_type == XA_INCR) {
} else if (seln_type == videodata->INCR) {
while (1) {
// Only delete the property after being done with the previous "chunk".
X11_XDeleteProperty(display, owner, selection);
@@ -268,23 +267,13 @@ const char **X11_GetTextMimeTypes(SDL_VideoDevice *_this, size_t *num_mime_types
bool X11_SetClipboardData(SDL_VideoDevice *_this)
{
SDL_VideoData *videodata = _this->internal;
Atom XA_CLIPBOARD = X11_XInternAtom(videodata->display, "CLIPBOARD", 0);
if (XA_CLIPBOARD == None) {
return SDL_SetError("Couldn't access X clipboard");
}
return SetSelectionData(_this, XA_CLIPBOARD, _this->clipboard_callback, _this->clipboard_userdata, (const char **)_this->clipboard_mime_types, _this->num_clipboard_mime_types, _this->clipboard_sequence);
return SetSelectionData(_this, videodata->CLIPBOARD, _this->clipboard_callback, _this->clipboard_userdata, (const char **)_this->clipboard_mime_types, _this->num_clipboard_mime_types, _this->clipboard_sequence);
}
void *X11_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *length)
{
SDL_VideoData *videodata = _this->internal;
Atom XA_CLIPBOARD = X11_XInternAtom(videodata->display, "CLIPBOARD", 0);
if (XA_CLIPBOARD == None) {
SDL_SetError("Couldn't access X clipboard");
*length = 0;
return NULL;
}
return GetSelectionData(_this, XA_CLIPBOARD, mime_type, length);
return GetSelectionData(_this, videodata->CLIPBOARD, mime_type, length);
}
bool X11_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type)

View File

@@ -989,16 +989,13 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
xevent->type == X11_GetXFixesSelectionNotifyEvent()) {
XFixesSelectionNotifyEvent *ev = (XFixesSelectionNotifyEvent *)xevent;
// !!! FIXME: cache atoms
Atom XA_CLIPBOARD = X11_XInternAtom(display, "CLIPBOARD", 0);
#ifdef DEBUG_XEVENTS
SDL_Log("window CLIPBOARD: XFixesSelectionNotify (selection = %s)\n",
X11_XGetAtomName(display, ev->selection));
#endif
if (ev->selection == XA_PRIMARY ||
(XA_CLIPBOARD != None && ev->selection == XA_CLIPBOARD)) {
(videodata->CLIPBOARD != None && ev->selection == videodata->CLIPBOARD)) {
SDL_SendClipboardUpdate();
return;
}

View File

@@ -417,6 +417,9 @@ static bool X11_VideoInit(SDL_VideoDevice *_this)
GET_ATOM(_SDL_WAKEUP);
GET_ATOM(UTF8_STRING);
GET_ATOM(PRIMARY);
GET_ATOM(CLIPBOARD);
GET_ATOM(INCR);
GET_ATOM(SDL_SELECTION);
GET_ATOM(XdndEnter);
GET_ATOM(XdndPosition);
GET_ATOM(XdndStatus);

View File

@@ -94,6 +94,9 @@ struct SDL_VideoData
Atom _SDL_WAKEUP;
Atom UTF8_STRING;
Atom PRIMARY;
Atom CLIPBOARD;
Atom INCR;
Atom SDL_SELECTION;
Atom XdndEnter;
Atom XdndPosition;
Atom XdndStatus;