diff --git a/hw/xwin/winclipboard.h b/hw/xwin/winclipboard.h index cb7769510..63dce733d 100644 --- a/hw/xwin/winclipboard.h +++ b/hw/xwin/winclipboard.h @@ -60,16 +60,12 @@ #ifdef HAS_DEVWINDOWS #define WIN_MSG_QUEUE_FNAME "/dev/windows" #endif -#define WIN_CONNECT_RETRIES 40 -#define WIN_CONNECT_DELAY 4 #define WIN_JMP_OKAY 0 #define WIN_JMP_ERROR_IO 2 #define WIN_LOCAL_PROPERTY "CYGX_CUT_BUFFER" #define WIN_XEVENTS_SUCCESS 0 #define WIN_XEVENTS_CONVERT 2 #define WIN_XEVENTS_NOTIFY 3 -#define WIN_CLIPBOARD_RETRIES 40 -#define WIN_CLIPBOARD_DELAY 1 #define WM_WM_REINIT (WM_USER + 1) diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c index e6bbf17e2..a3c1261d7 100644 --- a/hw/xwin/winclipboardinit.c +++ b/hw/xwin/winclipboardinit.c @@ -31,9 +31,16 @@ #ifdef HAVE_XWIN_CONFIG_H #include #endif + +#include +#include + #include "dixstruct.h" #include "winclipboard.h" +#define WIN_CLIPBOARD_RETRIES 40 +#define WIN_CLIPBOARD_DELAY 1 + /* * Local typedefs */ @@ -58,6 +65,38 @@ extern Bool g_fClipboardStarted; static pthread_t g_ptClipboardProc; +/* + * + */ +static void * +winClipboardThreadProc(void *arg) +{ + int clipboardRestarts = 0; + + while (1) + { + ++clipboardRestarts; + + /* Flag that clipboard client has been launched */ + g_fClipboardLaunched = TRUE; + + winClipboardProc(arg); + + /* checking if we need to restart */ + if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) { + /* terminates clipboard thread but the main server still lives */ + ErrorF("winClipboardProc - the clipboard thread has restarted %d times and seems to be unstable, disabling clipboard integration\n", clipboardRestarts); + g_fClipboard = FALSE; + break; + } + + sleep(WIN_CLIPBOARD_DELAY); + ErrorF("winClipboardProc - trying to restart clipboard thread \n"); + } + + return NULL; +} + /* * Intialize the Clipboard module */ @@ -74,7 +113,7 @@ winInitClipboard(void) } /* Spawn a thread for the Clipboard module */ - if (pthread_create(&g_ptClipboardProc, NULL, winClipboardProc, NULL)) { + if (pthread_create(&g_ptClipboardProc, NULL, winClipboardThreadProc, NULL)) { /* Bail if thread creation failed */ ErrorF("winInitClipboard - pthread_create failed.\n"); return FALSE; diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c index 4a9eb4c32..fd1fc0731 100644 --- a/hw/xwin/winclipboardthread.c +++ b/hw/xwin/winclipboardthread.c @@ -44,6 +44,9 @@ #endif #include "misc.h" +#define WIN_CONNECT_RETRIES 40 +#define WIN_CONNECT_DELAY 4 + /* * References to external symbols */ @@ -61,7 +64,6 @@ extern Window g_iClipboardWindow; */ static jmp_buf g_jmpEntry; -static int clipboardRestarts = 0; static XIOErrorHandler g_winClipboardOldIOErrorHandler; static pthread_t g_winClipboardProcThread; @@ -104,7 +106,6 @@ winClipboardProc(void *pvNotUsed) int iSelectError; winDebug("winClipboardProc - Hello\n"); - ++clipboardRestarts; /* Do we use Unicode clipboard? */ fUseUnicode = g_fUnicodeClipboard; @@ -400,35 +401,6 @@ winClipboardProc(void *pvNotUsed) g_pClipboardDisplay = NULL; g_hwndClipboard = NULL; - /* checking if we need to restart */ - if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) { - /* terminates clipboard thread but the main server still lives */ - ErrorF - ("winClipboardProc - the clipboard thread has restarted %d times and seems to be unstable, disabling clipboard integration\n", - clipboardRestarts); - g_fClipboard = FALSE; - return NULL; - } - - if (g_fClipboard) { - sleep(WIN_CLIPBOARD_DELAY); - ErrorF("winClipboardProc - trying to restart clipboard thread \n"); - /* Create the clipboard client thread */ - if (!winInitClipboard()) { - ErrorF("winClipboardProc - winClipboardInit failed.\n"); - return NULL; - } - - winDebug("winClipboardProc - winInitClipboard returned.\n"); - /* Flag that clipboard client has been launched */ - g_fClipboardLaunched = TRUE; - } - else { - ErrorF("winClipboardProc - Clipboard disabled - Exit from server \n"); - /* clipboard thread has exited, stop server as well */ - raise(SIGTERM); - } - return NULL; } diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c index bfd6bff8b..05a8a2820 100644 --- a/hw/xwin/winclipboardwrappers.c +++ b/hw/xwin/winclipboardwrappers.c @@ -163,9 +163,6 @@ winProcEstablishConnection(ClientPtr client) ErrorF("winProcEstablishConnection - winInitClipboard returned.\n"); } - /* Flag that clipboard client has been launched */ - g_fClipboardLaunched = TRUE; - return iReturn; }