aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xwin
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2014-10-06 10:07:50 +0200
committermarha <marha@users.sourceforge.net>2014-10-06 10:09:07 +0200
commitc774a734a9d990789abfe25c2f2dcbd74f4afe44 (patch)
treeeae4a2a0f19cc59dda6e4dadf96de32d22b3e174 /xorg-server/hw/xwin
parent37facdad11007fb89d30d7de5328ad900de7760d (diff)
downloadvcxsrv-c774a734a9d990789abfe25c2f2dcbd74f4afe44.tar.gz
vcxsrv-c774a734a9d990789abfe25c2f2dcbd74f4afe44.tar.bz2
vcxsrv-c774a734a9d990789abfe25c2f2dcbd74f4afe44.zip
Some more synchronisation with released branch
Diffstat (limited to 'xorg-server/hw/xwin')
-rwxr-xr-xxorg-server/hw/xwin/InitOutput.c36
-rw-r--r--xorg-server/hw/xwin/win.h2
-rwxr-xr-xxorg-server/hw/xwin/winclipboard/internal.h10
-rwxr-xr-xxorg-server/hw/xwin/winclipboard/thread.c57
-rw-r--r--xorg-server/hw/xwin/winclipboard/winclipboard.h1
-rwxr-xr-xxorg-server/hw/xwin/winclipboard/wndproc.c12
-rw-r--r--xorg-server/hw/xwin/winclipboardinit.c102
-rw-r--r--xorg-server/hw/xwin/winglobals.h5
8 files changed, 120 insertions, 105 deletions
diff --git a/xorg-server/hw/xwin/InitOutput.c b/xorg-server/hw/xwin/InitOutput.c
index 640195993..9622db5a2 100755
--- a/xorg-server/hw/xwin/InitOutput.c
+++ b/xorg-server/hw/xwin/InitOutput.c
@@ -61,24 +61,11 @@ typedef HRESULT (__stdcall * SHGETFOLDERPATHPROC)(HWND hwndOwner,
/*
* References to external symbols
*/
-#ifdef XWIN_CLIPBOARD
-extern Bool g_fUnicodeClipboard;
-extern Bool g_fClipboardLaunched;
-extern Bool g_fClipboardStarted;
-extern pthread_t g_ptClipboardProc;
-extern HWND g_hwndClipboard;
-extern Bool g_fClipboard;
-#endif
/*
* Function prototypes
*/
-#ifdef XWIN_CLIPBOARD
-static void
- winClipboardShutdown(void);
-#endif
-
static Bool
winCheckDisplayNumber(void);
@@ -120,29 +107,6 @@ static PixmapFormatRec g_PixmapFormats[] = {
const int NUMFORMATS = sizeof(g_PixmapFormats) / sizeof(g_PixmapFormats[0]);
-#ifdef XWIN_CLIPBOARD
-static void
-winClipboardShutdown(void)
-{
- /* Close down clipboard resources */
- if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) {
- /* Synchronously destroy the clipboard window */
- if (g_hwndClipboard != NULL) {
- g_fClipboardStarted=FALSE; /* This is to avoid dead-locls caused by the clipboard thread still doing some stuff */
- SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
- /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
- }
- else
- return;
-
- /* Wait for the clipboard thread to exit */
- pthread_join(g_ptClipboardProc, NULL);
-
- winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
- }
-}
-#endif
-
static const ExtensionModule xwinExtensions[] = {
#ifdef GLXEXT
{ GlxExtensionInit, "GLX", &noGlxExtension },
diff --git a/xorg-server/hw/xwin/win.h b/xorg-server/hw/xwin/win.h
index 47e8f36eb..d070ea485 100644
--- a/xorg-server/hw/xwin/win.h
+++ b/xorg-server/hw/xwin/win.h
@@ -758,7 +758,7 @@ Bool
winInitClipboard(void);
void
- winFixClipboardChain (int Removed);
+ winClipboardShutdown(void);
#endif
/*
diff --git a/xorg-server/hw/xwin/winclipboard/internal.h b/xorg-server/hw/xwin/winclipboard/internal.h
index fece50740..55c7771af 100755
--- a/xorg-server/hw/xwin/winclipboard/internal.h
+++ b/xorg-server/hw/xwin/winclipboard/internal.h
@@ -1,5 +1,3 @@
-#ifndef _WINCLIPBOARD_H_
-#define _WINCLIPBOARD_H_
/*
*Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
*
@@ -30,6 +28,9 @@
* Authors: Harold L Hunt II
*/
+#ifndef WINCLIPBOARD_INTERNAL_H
+#define WINCLIPBOARD_INTERNAL_H
+
/* Standard library headers */
#include <assert.h>
#include <stdio.h>
@@ -79,8 +80,6 @@ extern char *display;
Bool
winInitClipboard(void);
-HWND winClipboardCreateMessagingWindow(void);
-
/*
* winclipboardtextconv.c
*/
@@ -95,13 +94,12 @@ void
* winclipboardthread.c
*/
-void *winClipboardProc(void *);
/*
* winclipboardwndproc.c
*/
-BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd);
+Bool winClipboardFlushWindowsMessageQueue(HWND hwnd);
LRESULT CALLBACK
winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
diff --git a/xorg-server/hw/xwin/winclipboard/thread.c b/xorg-server/hw/xwin/winclipboard/thread.c
index 1ba687eb1..50cf997fb 100755
--- a/xorg-server/hw/xwin/winclipboard/thread.c
+++ b/xorg-server/hw/xwin/winclipboard/thread.c
@@ -89,6 +89,9 @@ Bool g_fUseUnicode = FALSE;
* Local function prototypes
*/
+static HWND
+winClipboardCreateMessagingWindow(void);
+
static int
winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr);
@@ -101,8 +104,8 @@ winClipboardThreadExit(void *arg);
* Main thread function
*/
-void *
-winClipboardProc(void *pvNotUsed)
+Bool
+winClipboardProc(Bool fUseUnicode, char *szDisplay)
{
Atom atomClipboard;
int iReturn;
@@ -118,30 +121,25 @@ winClipboardProc(void *pvNotUsed)
int iMaxDescriptor;
Display *pDisplay = NULL;
Window iWindow = None;
- int iRetries;
- Bool fUseUnicode;
- char szDisplay[512];
int iSelectError;
pthread_cleanup_push(&winClipboardThreadExit, NULL);
winDebug ("winClipboardProc - Hello\n");
- /* Do we use Unicode clipboard? */
- fUseUnicode = g_fUnicodeClipboard;
-
/* Save the Unicode support flag in a global */
g_fUseUnicode = fUseUnicode;
/* Create Windows messaging window */
hwnd = winClipboardCreateMessagingWindow ();
-
+
/* Save copy of HWND in screen privates */
g_hwndClipboard = hwnd;
+ g_winClipboardProcThread = pthread_self();
+
/* Set error handler */
XSetErrorHandler(winClipboardErrorHandler);
- g_winClipboardProcThread = pthread_self();
g_winClipboardOldIOErrorHandler =
XSetIOErrorHandler(winClipboardIOErrorHandler);
@@ -159,41 +157,8 @@ winClipboardProc(void *pvNotUsed)
ErrorF("winClipboardProc - setjmp returned for IO Error Handler.\n");
}
- /* Use our generated cookie for authentication */
- winSetAuthorization();
-
- /* Initialize retry count */
- iRetries = 0;
-
- /* Setup the display connection string x */
- /*
- * 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 */
- winDebug ("winClipboardProc - DISPLAY=%s\n", szDisplay);
-
- /* Open the X display */
- do {
- pDisplay = XOpenDisplay(szDisplay);
- if (pDisplay == NULL) {
- ErrorF("winClipboardProc - Could not open display, "
- "try: %d, sleeping: %d\n", iRetries + 1, WIN_CONNECT_DELAY);
- ++iRetries;
- sleep(WIN_CONNECT_DELAY);
- continue;
- }
- else
- break;
- }
- while (pDisplay == NULL && iRetries < WIN_CONNECT_RETRIES);
-
/* Make sure that the display opened */
+ pDisplay = XOpenDisplay(szDisplay);
if (pDisplay == NULL) {
ErrorF("winClipboardProc - Failed opening the display, giving up\n");
goto thread_errorexit;
@@ -282,7 +247,7 @@ winClipboardProc(void *pvNotUsed)
}
/* Pre-flush X events */
- /*
+ /*
* NOTE: Apparently you'll freeze if you don't do this,
* because there may be events in local data structures
* already.
@@ -432,7 +397,7 @@ commonexit:
pthread_cleanup_pop(0);
- return NULL;
+ return FALSE;
}
/*
diff --git a/xorg-server/hw/xwin/winclipboard/winclipboard.h b/xorg-server/hw/xwin/winclipboard/winclipboard.h
index e4011a172..7b172739a 100644
--- a/xorg-server/hw/xwin/winclipboard/winclipboard.h
+++ b/xorg-server/hw/xwin/winclipboard/winclipboard.h
@@ -27,5 +27,6 @@
#ifndef WINCLIPBOARD_H
#define WINCLIPBOARD_H
+void winFixClipboardChain (int Removed);
#endif
diff --git a/xorg-server/hw/xwin/winclipboard/wndproc.c b/xorg-server/hw/xwin/winclipboard/wndproc.c
index 0819de4a5..f5f931f74 100755
--- a/xorg-server/hw/xwin/winclipboard/wndproc.c
+++ b/xorg-server/hw/xwin/winclipboard/wndproc.c
@@ -33,6 +33,16 @@
#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
+
+/*
+ * Including any server header might define the macro _XSERVER64 on 64 bit machines.
+ * That macro must _NOT_ be defined for Xlib client code, otherwise bad things happen.
+ * So let's undef that macro if necessary.
+ */
+#ifdef _XSERVER64
+#undef _XSERVER64
+#endif
+
#include <sys/types.h>
#include <sys/time.h>
#include "winclipboard.h"
@@ -494,7 +504,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
* Process any pending Windows messages
*/
-BOOL
+Bool
winClipboardFlushWindowsMessageQueue(HWND hwnd)
{
MSG msg;
diff --git a/xorg-server/hw/xwin/winclipboardinit.c b/xorg-server/hw/xwin/winclipboardinit.c
index d4d9926ac..1a4899978 100644
--- a/xorg-server/hw/xwin/winclipboardinit.c
+++ b/xorg-server/hw/xwin/winclipboardinit.c
@@ -31,29 +31,79 @@
#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
-#include "dixstruct.h"
-#include "winclipboard.h"
-#include "objbase.h"
-#include "ddraw.h"
-#include "winwindow.h"
-#include "internal.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 */ );
/*
- * 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);
-extern pthread_t g_ptClipboardProc;
-extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
-extern Bool g_fClipboard;
-extern HWND g_hwndClipboard;
+ /* 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
@@ -71,7 +121,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;
@@ -79,3 +129,25 @@ winInitClipboard(void)
return TRUE;
}
+
+void
+winClipboardShutdown(void)
+{
+ /* Close down clipboard resources */
+ if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) {
+ /* Synchronously destroy the clipboard window */
+ if (g_hwndClipboard != NULL) {
+ g_fClipboardStarted=FALSE; /* This is to avoid dead-locls caused by the clipboard thread still doing some stuff */
+ SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
+ /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
+ }
+ else
+ return;
+
+ /* Wait for the clipboard thread to exit */
+ pthread_join(g_ptClipboardProc, NULL);
+
+ winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
+ }
+}
+
diff --git a/xorg-server/hw/xwin/winglobals.h b/xorg-server/hw/xwin/winglobals.h
index ffec0acf4..f697085bc 100644
--- a/xorg-server/hw/xwin/winglobals.h
+++ b/xorg-server/hw/xwin/winglobals.h
@@ -79,6 +79,11 @@ extern Bool g_fUnicodeClipboard;
extern Bool g_fClipboard;
extern Bool g_fClipboardStarted;
+extern Bool g_fClipboardLaunched;
+
+extern pthread_t g_ptClipboardProc;
+extern HWND g_hwndClipboard;
+
/* The global X default icons */
#if defined(XWIN_MULTIWINDOW)
extern HICON g_hIconX;