aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xwin/winclipboardinit.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/hw/xwin/winclipboardinit.c')
-rw-r--r--xorg-server/hw/xwin/winclipboardinit.c150
1 files changed, 79 insertions, 71 deletions
diff --git a/xorg-server/hw/xwin/winclipboardinit.c b/xorg-server/hw/xwin/winclipboardinit.c
index 157006dab..8aef8fe02 100644
--- a/xorg-server/hw/xwin/winclipboardinit.c
+++ b/xorg-server/hw/xwin/winclipboardinit.c
@@ -31,25 +31,79 @@
#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
-#include "dixstruct.h"
-#include "winclipboard.h"
+
+#include <unistd.h>
+#include <pthread.h>
+
+#include "win.h"
+#include "winclipboard/winclipboard.h"
+#include "windisplay.h"
+
+#define WIN_CLIPBOARD_RETRIES 40
+#define WIN_CLIPBOARD_DELAY 1
/*
- * Local typedefs
+ * Local variables
*/
-typedef int (*winDispatchProcPtr) (ClientPtr);
-
-int winProcSetSelectionOwner(ClientPtr /* client */ );
+static pthread_t g_ptClipboardProc;
/*
- * References to external symbols
+ *
*/
+static void *
+winClipboardThreadProc(void *arg)
+{
+ char szDisplay[512];
+ int clipboardRestarts = 0;
+
+ while (1)
+ {
+ Bool fShutdown;
+
+ ++clipboardRestarts;
-extern pthread_t g_ptClipboardProc;
-extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
-extern Bool g_fClipboard;
-extern HWND g_hwndClipboard;
+ /* Use our generated cookie for authentication */
+ winSetAuthorization();
+
+ /* Setup the display connection string */
+ /*
+ * NOTE: Always connect to screen 0 since we require that screen
+ * numbers start at 0 and increase without gaps. We only need
+ * to connect to one screen on the display to get events
+ * for all screens on the display. That is why there is only
+ * one clipboard client thread.
+ */
+ winGetDisplayName(szDisplay, 0);
+
+ /* Print the display connection string */
+ ErrorF("winClipboardThreadProc - DISPLAY=%s\n", szDisplay);
+
+ /* Flag that clipboard client has been launched */
+ g_fClipboardStarted = TRUE;
+
+ fShutdown = winClipboardProc(g_fUnicodeClipboard, szDisplay);
+
+ /* Flag that clipboard client has stopped */
+ g_fClipboardStarted = FALSE;
+
+ if (fShutdown)
+ break;
+
+ /* 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
@@ -60,14 +114,8 @@ winInitClipboard(void)
{
winDebug("winInitClipboard ()\n");
- /* Wrap some internal server functions */
- if (ProcVector[X_SetSelectionOwner] != winProcSetSelectionOwner) {
- winProcSetSelectionOwnerOrig = ProcVector[X_SetSelectionOwner];
- ProcVector[X_SetSelectionOwner] = winProcSetSelectionOwner;
- }
-
/* 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;
@@ -76,59 +124,19 @@ winInitClipboard(void)
return TRUE;
}
-/*
- * Create the Windows window that we use to receive Windows messages
- */
-
-HWND
-winClipboardCreateMessagingWindow(void)
-{
- WNDCLASSEX wc;
- HWND hwnd;
-
- /* Setup our window class */
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = winClipboardWindowProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = GetModuleHandle(NULL);
- wc.hIcon = 0;
- wc.hCursor = 0;
- wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS;
- wc.hIconSm = 0;
- RegisterClassEx(&wc);
-
- /* Create the window */
- hwnd = CreateWindowExA(0, /* Extended styles */
- WIN_CLIPBOARD_WINDOW_CLASS, /* Class name */
- WIN_CLIPBOARD_WINDOW_TITLE, /* Window name */
- WS_OVERLAPPED, /* Not visible anyway */
- CW_USEDEFAULT, /* Horizontal position */
- CW_USEDEFAULT, /* Vertical position */
- CW_USEDEFAULT, /* Right edge */
- CW_USEDEFAULT, /* Bottom edge */
- (HWND) NULL, /* No parent or owner window */
- (HMENU) NULL, /* No menu */
- GetModuleHandle(NULL), /* Instance handle */
- NULL); /* Creation data */
- assert(hwnd != NULL);
-
- /* I'm not sure, but we may need to call this to start message processing */
- ShowWindow(hwnd, SW_HIDE);
-
- /* Similarly, we may need a call to this even though we don't paint */
- UpdateWindow(hwnd);
-
- return hwnd;
-}
-
void
-winFixClipboardChain(void)
+winClipboardShutdown(void)
{
- if (g_fClipboard && g_hwndClipboard) {
- PostMessage(g_hwndClipboard, WM_WM_REINIT, 0, 0);
- }
+ /* Close down clipboard resources */
+ if (g_fClipboard && g_fClipboardStarted) {
+ /* Synchronously destroy the clipboard window */
+ winClipboardWindowDestroy();
+
+ /* Wait for the clipboard thread to exit */
+ pthread_join(g_ptClipboardProc, NULL);
+
+ g_fClipboardStarted = FALSE;
+
+ winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
+ }
}