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.c154
1 files changed, 75 insertions, 79 deletions
diff --git a/xorg-server/hw/xwin/winclipboardinit.c b/xorg-server/hw/xwin/winclipboardinit.c
index 8aef8fe02..7eb672002 100644
--- a/xorg-server/hw/xwin/winclipboardinit.c
+++ b/xorg-server/hw/xwin/winclipboardinit.c
@@ -31,79 +31,29 @@
#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
-
-#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
+#include "dixstruct.h"
+#include "winclipboard.h"
+#include "objbase.h"
+#include "ddraw.h"
+#include "winwindow.h"
+#include "internal.h"
/*
- * Local variables
+ * Local typedefs
*/
-static pthread_t g_ptClipboardProc;
+typedef int (*winDispatchProcPtr) (ClientPtr);
+
+int winProcSetSelectionOwner(ClientPtr /* client */ );
/*
- *
+ * References to external symbols
*/
-static void *
-winClipboardThreadProc(void *arg)
-{
- char szDisplay[512];
- int clipboardRestarts = 0;
-
- while (1)
- {
- Bool fShutdown;
-
- ++clipboardRestarts;
- /* 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;
-}
+extern pthread_t g_ptClipboardProc;
+extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
+extern Bool g_fClipboard;
+extern HWND g_hwndClipboard;
/*
* Intialize the Clipboard module
@@ -114,8 +64,14 @@ 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, winClipboardThreadProc, NULL)) {
+ if (pthread_create(&g_ptClipboardProc, NULL, winClipboardProc, NULL)) {
/* Bail if thread creation failed */
ErrorF("winInitClipboard - pthread_create failed.\n");
return FALSE;
@@ -124,19 +80,59 @@ winInitClipboard(void)
return TRUE;
}
-void
-winClipboardShutdown(void)
-{
- /* 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);
+/*
+ * Create the Windows window that we use to receive Windows messages
+ */
- g_fClipboardStarted = FALSE;
+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;
+}
- winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
- }
+void
+winFixClipboardChain(int Removed)
+{
+ if (g_fClipboard && g_hwndClipboard) {
+ PostMessage (g_hwndClipboard, WM_WM_REINIT, Removed, 0);
+ }
}