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:
commit
a6b5b60c20
@ -104,6 +104,8 @@ void ClipboardPush(char * text)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventProcess(SDL_Event event);
|
||||||
|
|
||||||
char * ClipboardPull()
|
char * ClipboardPull()
|
||||||
{
|
{
|
||||||
#ifdef MACOSX
|
#ifdef MACOSX
|
||||||
@ -135,7 +137,6 @@ char * ClipboardPull()
|
|||||||
Atom type;
|
Atom type;
|
||||||
int format, result;
|
int format, result;
|
||||||
unsigned long len, bytesLeft;
|
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);
|
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);
|
XFlush(sdl_wminfo.info.x11.display);
|
||||||
sdl_wminfo.info.x11.unlock_func();
|
sdl_wminfo.info.x11.unlock_func();
|
||||||
@ -148,13 +149,11 @@ char * ClipboardPull()
|
|||||||
XEvent xevent = event.syswm.msg->event.xevent;
|
XEvent xevent = event.syswm.msg->event.xevent;
|
||||||
if (xevent.type == SelectionNotify && xevent.xselection.requestor == sdl_wminfo.info.x11.window)
|
if (xevent.type == SelectionNotify && xevent.xselection.requestor == sdl_wminfo.info.x11.window)
|
||||||
break;
|
break;
|
||||||
evlist.push_back(event);
|
else
|
||||||
|
EventProcess(event);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
for (std::list<SDL_Event>::iterator iter = evlist.begin(), end = evlist.end(); iter != end; iter++)
|
EventProcess(event);
|
||||||
{
|
|
||||||
SDL_Event event = *iter;
|
|
||||||
SDL_PushEvent(&event); // replay the missed events
|
|
||||||
}
|
}
|
||||||
sdl_wminfo.info.x11.lock_func();
|
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);
|
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);
|
text = strdup((const char*) data);
|
||||||
XFree(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);
|
XDeleteProperty(sdl_wminfo.info.x11.display, sdl_wminfo.info.x11.window, XA_CLIPBOARD);
|
||||||
}
|
}
|
||||||
sdl_wminfo.info.x11.unlock_func();
|
sdl_wminfo.info.x11.unlock_func();
|
||||||
@ -425,17 +431,8 @@ unsigned int lastTick = 0;
|
|||||||
float fps = 0, delta = 1.0f, inputScale = 1.0f;
|
float fps = 0, delta = 1.0f, inputScale = 1.0f;
|
||||||
ui::Engine * engine = NULL;
|
ui::Engine * engine = NULL;
|
||||||
float currentWidth, currentHeight;
|
float currentWidth, currentHeight;
|
||||||
void EngineProcess()
|
|
||||||
{
|
void EventProcess(SDL_Event event)
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
@ -520,12 +517,12 @@ void EngineProcess()
|
|||||||
if (xe.xselectionrequest.target==XA_TARGETS)
|
if (xe.xselectionrequest.target==XA_TARGETS)
|
||||||
{
|
{
|
||||||
// send list of supported formats
|
// 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;
|
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)));
|
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
|
// 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);
|
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);
|
XSendEvent(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, 0, 0, &xr);
|
||||||
}
|
}
|
||||||
sdl_wminfo.info.x11.unlock_func();
|
sdl_wminfo.info.x11.unlock_func();
|
||||||
continue;
|
|
||||||
#endif
|
#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
|
event.type = 0; //Clear last event
|
||||||
}
|
}
|
||||||
if(engine->Broken()) { engine->UnBreak(); break; }
|
if(engine->Broken()) { engine->UnBreak(); break; }
|
||||||
|
Loading…
Reference in New Issue
Block a user