summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2013-07-23 12:59:29 -0700
committerSam Lantinga <slouken@libsdl.org>2013-07-23 12:59:29 -0700
commit0c14b5139919e8ef2a6926cfbb58be38d535adab (patch)
tree0c482ed82dff4587dca622c3cc3675fc5973fc02
parent47d7ee2ccd1002c4a4c6b941790b3a7f2306071e (diff)
downloadsdl-0c14b5139919e8ef2a6926cfbb58be38d535adab.tar.gz
Add a timeout to the clipboard code to avoid hangs when using synergy. When a timeout is detected we set the clipboard so that we own it so that future timeouts are avoided. Testing has confirmed that this timeout and setting only occurs when the clipboard contains text from my Windows machine.macosx_10_4_supported
That is, if you copy from the Windows clipboard and then launch Dota and then repeatedly paste to a terminal window then the text will disappear when Dota hits the timeout. If you then select on the Linux side you can repeatedly paste. If you select again on Windows then the text will get cleared again. Note that Dota only looks at the clipboard when it has focus. CR: Saml
-rw-r--r--[-rwxr-xr-x]src/thread/windows/SDL_systhread.c0
-rw-r--r--src/video/x11/SDL_x11clipboard.c20
2 files changed, 18 insertions, 2 deletions
diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c
index 6cf826ec7..6cf826ec7 100755..100644
--- a/src/thread/windows/SDL_systhread.c
+++ b/src/thread/windows/SDL_systhread.c
diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c
index bdeb4da8a..54b5eb602 100644
--- a/src/video/x11/SDL_x11clipboard.c
+++ b/src/video/x11/SDL_x11clipboard.c
@@ -26,6 +26,7 @@
#include "SDL_events.h"
#include "SDL_x11video.h"
+#include "SDL_timer.h"
/* If you don't support UTF-8, you might use XA_STRING here */
@@ -94,10 +95,12 @@ X11_GetClipboardText(_THIS)
unsigned long overflow;
unsigned char *src;
char *text;
+ Uint32 waitStart;
+ Uint32 waitElapsed;
Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);
if (XA_CLIPBOARD == None) {
SDL_SetError("Couldn't access X clipboard");
- return NULL;
+ return SDL_strdup("");
}
text = NULL;
@@ -116,10 +119,23 @@ X11_GetClipboardText(_THIS)
XConvertSelection(display, XA_CLIPBOARD, format, selection, owner,
CurrentTime);
- /* FIXME: Should we have a timeout here? */
+ /* When using synergy on Linux and when data has been put in the clipboard
+ on the remote (Windows anyway) machine then selection_waiting may never
+ be set to False. Time out after a while. */
+ waitStart = SDL_GetTicks();
videodata->selection_waiting = SDL_TRUE;
while (videodata->selection_waiting) {
SDL_PumpEvents();
+ waitElapsed = SDL_GetTicks() - waitStart;
+ /* Wait one second for a clipboard response. */
+ if (waitElapsed > 1000) {
+ videodata->selection_waiting = SDL_FALSE;
+ SDL_SetError("Clipboard timeout");
+ /* We need to set the clipboard text so that next time we won't
+ timeout, otherwise we will hang on every call to this function. */
+ X11_SetClipboardText(_this, "");
+ return SDL_strdup("");
+ }
}
}