mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-15 14:26:01 +00:00
video: cache some more atoms under X11
This patch adds the caching of some atoms used by the clipboard.
This commit is contained in:
@@ -174,7 +174,6 @@ static void *GetSelectionData(SDL_VideoDevice *_this, Atom selection_type,
|
|||||||
unsigned char *src = NULL;
|
unsigned char *src = NULL;
|
||||||
bool incr_success = false;
|
bool incr_success = false;
|
||||||
Atom XA_MIME = X11_XInternAtom(display, mime_type, False);
|
Atom XA_MIME = X11_XInternAtom(display, mime_type, False);
|
||||||
Atom XA_INCR = X11_XInternAtom(display, "INCR", False);
|
|
||||||
|
|
||||||
*length = 0;
|
*length = 0;
|
||||||
|
|
||||||
@@ -199,7 +198,7 @@ static void *GetSelectionData(SDL_VideoDevice *_this, Atom selection_type,
|
|||||||
} else {
|
} else {
|
||||||
// Request that the selection owner copy the data to our window
|
// Request that the selection owner copy the data to our window
|
||||||
owner = window;
|
owner = window;
|
||||||
selection = X11_XInternAtom(display, "SDL_SELECTION", False);
|
selection = videodata->SDL_SELECTION;
|
||||||
X11_XConvertSelection(display, selection_type, XA_MIME, selection, owner,
|
X11_XConvertSelection(display, selection_type, XA_MIME, selection, owner,
|
||||||
CurrentTime);
|
CurrentTime);
|
||||||
|
|
||||||
@@ -213,7 +212,7 @@ static void *GetSelectionData(SDL_VideoDevice *_this, Atom selection_type,
|
|||||||
if (seln_type == XA_MIME) {
|
if (seln_type == XA_MIME) {
|
||||||
*length = (size_t)count;
|
*length = (size_t)count;
|
||||||
data = CloneDataBuffer(src, count);
|
data = CloneDataBuffer(src, count);
|
||||||
} else if (seln_type == XA_INCR) {
|
} else if (seln_type == videodata->INCR) {
|
||||||
while (1) {
|
while (1) {
|
||||||
// Only delete the property after being done with the previous "chunk".
|
// Only delete the property after being done with the previous "chunk".
|
||||||
X11_XDeleteProperty(display, owner, selection);
|
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)
|
bool X11_SetClipboardData(SDL_VideoDevice *_this)
|
||||||
{
|
{
|
||||||
SDL_VideoData *videodata = _this->internal;
|
SDL_VideoData *videodata = _this->internal;
|
||||||
Atom XA_CLIPBOARD = X11_XInternAtom(videodata->display, "CLIPBOARD", 0);
|
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);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *X11_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *length)
|
void *X11_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *length)
|
||||||
{
|
{
|
||||||
SDL_VideoData *videodata = _this->internal;
|
SDL_VideoData *videodata = _this->internal;
|
||||||
Atom XA_CLIPBOARD = X11_XInternAtom(videodata->display, "CLIPBOARD", 0);
|
return GetSelectionData(_this, videodata->CLIPBOARD, mime_type, length);
|
||||||
if (XA_CLIPBOARD == None) {
|
|
||||||
SDL_SetError("Couldn't access X clipboard");
|
|
||||||
*length = 0;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return GetSelectionData(_this, XA_CLIPBOARD, mime_type, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool X11_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type)
|
bool X11_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type)
|
||||||
|
@@ -989,16 +989,13 @@ static void X11_DispatchEvent(SDL_VideoDevice *_this, XEvent *xevent)
|
|||||||
xevent->type == X11_GetXFixesSelectionNotifyEvent()) {
|
xevent->type == X11_GetXFixesSelectionNotifyEvent()) {
|
||||||
XFixesSelectionNotifyEvent *ev = (XFixesSelectionNotifyEvent *)xevent;
|
XFixesSelectionNotifyEvent *ev = (XFixesSelectionNotifyEvent *)xevent;
|
||||||
|
|
||||||
// !!! FIXME: cache atoms
|
|
||||||
Atom XA_CLIPBOARD = X11_XInternAtom(display, "CLIPBOARD", 0);
|
|
||||||
|
|
||||||
#ifdef DEBUG_XEVENTS
|
#ifdef DEBUG_XEVENTS
|
||||||
SDL_Log("window CLIPBOARD: XFixesSelectionNotify (selection = %s)\n",
|
SDL_Log("window CLIPBOARD: XFixesSelectionNotify (selection = %s)\n",
|
||||||
X11_XGetAtomName(display, ev->selection));
|
X11_XGetAtomName(display, ev->selection));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ev->selection == XA_PRIMARY ||
|
if (ev->selection == XA_PRIMARY ||
|
||||||
(XA_CLIPBOARD != None && ev->selection == XA_CLIPBOARD)) {
|
(videodata->CLIPBOARD != None && ev->selection == videodata->CLIPBOARD)) {
|
||||||
SDL_SendClipboardUpdate();
|
SDL_SendClipboardUpdate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -417,6 +417,9 @@ static bool X11_VideoInit(SDL_VideoDevice *_this)
|
|||||||
GET_ATOM(_SDL_WAKEUP);
|
GET_ATOM(_SDL_WAKEUP);
|
||||||
GET_ATOM(UTF8_STRING);
|
GET_ATOM(UTF8_STRING);
|
||||||
GET_ATOM(PRIMARY);
|
GET_ATOM(PRIMARY);
|
||||||
|
GET_ATOM(CLIPBOARD);
|
||||||
|
GET_ATOM(INCR);
|
||||||
|
GET_ATOM(SDL_SELECTION);
|
||||||
GET_ATOM(XdndEnter);
|
GET_ATOM(XdndEnter);
|
||||||
GET_ATOM(XdndPosition);
|
GET_ATOM(XdndPosition);
|
||||||
GET_ATOM(XdndStatus);
|
GET_ATOM(XdndStatus);
|
||||||
|
@@ -94,6 +94,9 @@ struct SDL_VideoData
|
|||||||
Atom _SDL_WAKEUP;
|
Atom _SDL_WAKEUP;
|
||||||
Atom UTF8_STRING;
|
Atom UTF8_STRING;
|
||||||
Atom PRIMARY;
|
Atom PRIMARY;
|
||||||
|
Atom CLIPBOARD;
|
||||||
|
Atom INCR;
|
||||||
|
Atom SDL_SELECTION;
|
||||||
Atom XdndEnter;
|
Atom XdndEnter;
|
||||||
Atom XdndPosition;
|
Atom XdndPosition;
|
||||||
Atom XdndStatus;
|
Atom XdndStatus;
|
||||||
|
Reference in New Issue
Block a user