Merge pull request #178 from mniip/x11-clipboard

fix copy and paste in the same tpt window on SDL/Linux/X11
This commit is contained in:
jacob1 2013-10-24 14:08:52 -07:00
commit a6b5b60c20

View File

@ -104,6 +104,8 @@ void ClipboardPush(char * text)
#endif
}
void EventProcess(SDL_Event event);
char * ClipboardPull()
{
#ifdef MACOSX
@ -135,7 +137,6 @@ char * ClipboardPull()
Atom type;
int format, result;
unsigned long len, bytesLeft;
std::list<SDL_Event> evlist; // if there arrive any events while fetching keyboard
XConvertSelection(sdl_wminfo.info.x11.display, XA_CLIPBOARD, XA_UTF8_STRING, XA_CLIPBOARD, sdl_wminfo.info.x11.window, CurrentTime);
XFlush(sdl_wminfo.info.x11.display);
sdl_wminfo.info.x11.unlock_func();
@ -148,13 +149,11 @@ char * ClipboardPull()
XEvent xevent = event.syswm.msg->event.xevent;
if (xevent.type == SelectionNotify && xevent.xselection.requestor == sdl_wminfo.info.x11.window)
break;
evlist.push_back(event);
else
EventProcess(event);
}
}
for (std::list<SDL_Event>::iterator iter = evlist.begin(), end = evlist.end(); iter != end; iter++)
{
SDL_Event event = *iter;
SDL_PushEvent(&event); // replay the missed events
else
EventProcess(event);
}
sdl_wminfo.info.x11.lock_func();
XGetWindowProperty(sdl_wminfo.info.x11.display, sdl_wminfo.info.x11.window, XA_CLIPBOARD, 0, 0, 0, AnyPropertyType, &type, &format, &len, &bytesLeft, &data);
@ -171,7 +170,14 @@ char * ClipboardPull()
text = strdup((const char*) data);
XFree(data);
}
else
{
printf("Failed to pull from clipboard\n");
return mystrdup("?");
}
}
else
return mystrdup("");
XDeleteProperty(sdl_wminfo.info.x11.display, sdl_wminfo.info.x11.window, XA_CLIPBOARD);
}
sdl_wminfo.info.x11.unlock_func();
@ -425,17 +431,8 @@ unsigned int lastTick = 0;
float fps = 0, delta = 1.0f, inputScale = 1.0f;
ui::Engine * engine = NULL;
float currentWidth, currentHeight;
void EngineProcess()
{
int frameStart = SDL_GetTicks();
float frameTime;
float frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f;
SDL_Event event;
while(engine->Running())
{
if(engine->Broken()) { engine->UnBreak(); break; }
event.type = 0;
while (SDL_PollEvent(&event))
void EventProcess(SDL_Event event)
{
switch (event.type)
{
@ -520,12 +517,12 @@ void EngineProcess()
if (xe.xselectionrequest.target==XA_TARGETS)
{
// send list of supported formats
Atom targets[] = {XA_TARGETS, XA_STRING};
Atom targets[] = {XA_TARGETS, XA_STRING, XA_UTF8_STRING};
xr.xselection.property = xe.xselectionrequest.property;
XChangeProperty(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, xe.xselectionrequest.property, XA_ATOM, 32, PropModeReplace, (unsigned char*)targets, (int)(sizeof(targets)/sizeof(Atom)));
}
// TODO: Supporting more targets would be nice
else if (xe.xselectionrequest.target==XA_STRING && clipboardText)
else if ((xe.xselectionrequest.target==XA_STRING || xe.xselectionrequest.target==XA_UTF8_STRING) && clipboardText)
{
XChangeProperty(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, xe.xselectionrequest.property, xe.xselectionrequest.target, 8, PropModeReplace, (unsigned char*)clipboardText, strlen(clipboardText)+1);
}
@ -537,9 +534,23 @@ void EngineProcess()
XSendEvent(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, 0, 0, &xr);
}
sdl_wminfo.info.x11.unlock_func();
continue;
#endif
}
}
void EngineProcess()
{
int frameStart = SDL_GetTicks();
float frameTime;
float frameTimeAvg = 0.0f, correctedFrameTimeAvg = 0.0f;
SDL_Event event;
while(engine->Running())
{
if(engine->Broken()) { engine->UnBreak(); break; }
event.type = 0;
while (SDL_PollEvent(&event))
{
EventProcess(event);
event.type = 0; //Clear last event
}
if(engine->Broken()) { engine->UnBreak(); break; }