From cab39b481c459d485dc5e1e4cd2a632d6f2a7e26 Mon Sep 17 00:00:00 2001 From: Harold L Hunt II Date: Thu, 8 Jan 2004 05:10:33 +0000 Subject: [PATCH] Synch with Cygwin/X release 4.3.0-33. Major clipboard rework. Start moving functions out of InitOutput.c. Start referencing external globals only in files that use them. Rework multi-window mode startup to prevent some crashes and race conditions. (Harold L Hunt II, assisted on clipboard work by Keith Packard) --- hw/xwin/InitInput.c | 70 ++- hw/xwin/InitOutput.c | 125 ++-- hw/xwin/win.h | 42 +- hw/xwin/winallpriv.c | 11 + hw/xwin/winauth.c | 127 ++++ hw/xwin/winblock.c | 10 + hw/xwin/winclipboard.h | 42 +- hw/xwin/winclipboardinit.c | 57 +- hw/xwin/winclipboardthread.c | 216 +++---- hw/xwin/winclipboardwndproc.c | 257 +++++++- hw/xwin/winclipboardwrappers.c | 498 ++++++++++++++++ hw/xwin/winclipboardxevents.c | 446 ++++++-------- hw/xwin/wincmap.c | 8 + hw/xwin/winconfig.c | 6 +- hw/xwin/wincursor.c | 8 + hw/xwin/winfillsp.c | 10 + hw/xwin/wingc.c | 10 + hw/xwin/wingetsp.c | 9 + hw/xwin/winglobals.c | 92 +++ hw/xwin/winmisc.c | 7 + hw/xwin/winmultiwindowwm.c | 209 ++++--- hw/xwin/winpixmap.c | 8 + hw/xwin/winprocarg.c | 1017 ++++++++++++++++++++++++++++++++ hw/xwin/winscrinit.c | 32 +- hw/xwin/winsetsp.c | 10 + hw/xwin/winwakeup.c | 9 + hw/xwin/winwindow.c | 9 + hw/xwin/winwndproc.c | 9 +- 28 files changed, 2744 insertions(+), 610 deletions(-) create mode 100644 hw/xwin/winauth.c create mode 100755 hw/xwin/winclipboardwrappers.c create mode 100644 hw/xwin/winglobals.c create mode 100755 hw/xwin/winprocarg.c diff --git a/hw/xwin/InitInput.c b/hw/xwin/InitInput.c index de84a7aee..0eb1cfec3 100644 --- a/hw/xwin/InitInput.c +++ b/hw/xwin/InitInput.c @@ -30,8 +30,33 @@ #include "win.h" #include "../../Xext/xf86miscproc.h" +#include "dixstruct.h" -CARD32 g_c32LastInputEventTime = 0; + +/* + * Local function prototypes + */ + +DISPATCH_PROC(winProcEstablishConnection); +DISPATCH_PROC(winProcQueryTree); +DISPATCH_PROC(winProcSetSelectionOwner); + + +/* + * Local global declarations + */ + +CARD32 g_c32LastInputEventTime = 0; + + +/* + * References to external symbols + */ + +extern int g_fdMessageQueue; +extern Bool g_fXdmcpEnabled; +extern winDispatchProcPtr winProcEstablishConnectionOrig; +extern winDispatchProcPtr winProcQueryTreeOrig; /* Called from dix/devices.c */ @@ -90,6 +115,21 @@ InitInput (int argc, char *argv[]) ErrorF ("InitInput\n"); #endif + /* + * Wrap some functions at every generation of the server. + */ + if (InitialVector[2] != winProcEstablishConnection) + { + winProcEstablishConnectionOrig = InitialVector[2]; + InitialVector[2] = winProcEstablishConnection; + } + if (g_fXdmcpEnabled + && ProcVector[X_QueryTree] != winProcQueryTree) + { + winProcQueryTreeOrig = ProcVector[X_QueryTree]; + ProcVector[X_QueryTree] = winProcQueryTree; + } + pMouse = AddInputDevice (winMouseProc, TRUE); pKeyboard = AddInputDevice (winKeybdProc, TRUE); @@ -118,34 +158,6 @@ InitInput (int argc, char *argv[]) AddEnabledDevice (g_fdMessageQueue); } -#if 0 - { - MiscExtReturn ret; - pointer kbd; - -#if 0 - if ((kbd = MiscExtCreateStruct(MISC_KEYBOARD)) == (pointer) 0) - return BadAlloc; -#else - kbd = MiscExtCreateStruct (MISC_KEYBOARD); -#endif - - MiscExtSetKbdValue(kbd, MISC_KBD_TYPE, 0); - MiscExtSetKbdValue(kbd, MISC_KBD_RATE, 0); - MiscExtSetKbdValue(kbd, MISC_KBD_DELAY, 0); - MiscExtSetKbdValue(kbd, MISC_KBD_SERVNUMLOCK, 0); - - switch ((ret = MiscExtApply (kbd, MISC_KEYBOARD))) - { - case MISC_RET_SUCCESS: break; - case MISC_RET_BADVAL: - case MISC_RET_BADKBDTYPE: - default: - ErrorF ("Unexpected return from MiscExtApply(KEYBOARD) = %d\n", ret); - } - } -#endif - #if CYGDEBUG ErrorF ("InitInput - returning\n"); #endif diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index 69a639118..edbf1bc79 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -33,52 +33,47 @@ from The Open Group. #include "winconfig.h" #include "winprefs.h" + /* - * General global variables + * References to external symbols */ -int g_iNumScreens = 0; -winScreenInfo g_ScreenInfo[MAXSCREENS]; -int g_iLastScreen = -1; -int g_fdMessageQueue = WIN_FD_INVALID; -int g_iScreenPrivateIndex = -1; -int g_iCmapPrivateIndex = -1; -int g_iGCPrivateIndex = -1; -int g_iPixmapPrivateIndex = -1; -int g_iWindowPrivateIndex = -1; -unsigned long g_ulServerGeneration = 0; -Bool g_fInitializedDefaultScreens = FALSE; -DWORD g_dwEnginesSupported = 0; -HINSTANCE g_hInstance = 0; -HWND g_hDlgDepthChange = NULL; -HWND g_hDlgExit = NULL; -Bool g_fCalledSetLocale = FALSE; -Bool g_fCalledXInitThreads = FALSE; +extern int g_iNumScreens; +extern winScreenInfo g_ScreenInfo[]; +extern int g_iLastScreen; +extern Bool g_fInitializedDefaultScreens; +extern FILE *g_pfLog; +extern Bool g_fUnicodeClipboard; +extern Bool g_fXdmcpEnabled; +extern int g_iScreenPrivateIndex; +extern int g_fdMessageQueue; +extern const char * g_pszQueryHost; +extern HINSTANCE g_hInstance; + int g_iLogVerbose = 4; char * g_pszLogFile = WIN_LOG_FNAME; Bool g_fLogInited = FALSE; -const char * g_pszQueryHost = NULL; -Bool g_fUnicodeClipboard = TRUE; - +extern HMODULE g_hmodDirectDraw; +extern FARPROC g_fpDirectDrawCreate; +extern FARPROC g_fpDirectDrawCreateClipper; + +extern HMODULE g_hmodCommonControls; +extern FARPROC g_fpTrackMouseEvent; + + /* - * Global variables for dynamically loaded libraries and - * their function pointers + * Function prototypes */ -HMODULE g_hmodDirectDraw = NULL; -FARPROC g_fpDirectDrawCreate = NULL; -FARPROC g_fpDirectDrawCreateClipper = NULL; - -HMODULE g_hmodCommonControls = NULL; -FARPROC g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; - - -/* Function prototypes */ - #ifdef DDXOSVERRORF void OsVendorVErrorF (const char *pszFormat, va_list va_args); #endif + +#if defined(DDXOSRESET) +void OsVendorReset (); +#endif + void winInitializeDefaultScreens (void); @@ -109,6 +104,51 @@ static PixmapFormatRec g_PixmapFormats[] = { const int NUMFORMATS = sizeof (g_PixmapFormats) / sizeof (g_PixmapFormats[0]); +#if defined(DDXOSRESET) +/* + * Called right before KillAllClients when the server is going to reset, + * allows us to shutdown our seperate threads cleanly. + */ + +void +OsVendorReset () +{ + int i; + + ErrorF ("OsVendorReset - Hello\n"); + + /* Walk the list of screens */ + for (i = 0; i < g_iNumScreens; i++) + { + ScreenPtr pScreen = g_ScreenInfo[i].pScreen; + winScreenPriv(pScreen); + + /* Close down clipboard resources */ + if (g_ScreenInfo[i].fClipboard) + { + HWND hwndClipboard = pScreenPriv->hwndClipboard; + + /* Prevent our wrapped SetSelectionOwner function from segfaulting */ + pScreenPriv->hwndClipboard = NULL; + pScreenPriv->pClipboardDisplay = NULL; + pScreenPriv->iClipboardWindow = 0; + pScreenPriv->fCBCInitialized = FALSE; + + /* Synchronously destroy the clipboard window */ + if (hwndClipboard != NULL) + SendMessage (hwndClipboard, WM_DESTROY, 0, 0); + + /* Wait for the clipboard thread to exit */ + pthread_join (pScreenPriv->ptClipboardProc, NULL); + + ErrorF ("OsVendorReset - Clipboard thread has exited.\n"); + } + } +} +#endif + + + void winInitializeDefaultScreens (void) { @@ -246,6 +286,9 @@ AbortDDX (void) void OsVendorInit (void) { + /* Re-initialize global variables on server reset */ + winInitializeGlobals (); + #ifdef DDXOSVERRORF if (!OsVendorVErrorFProc) OsVendorVErrorFProc = OsVendorVErrorF; @@ -1234,10 +1277,21 @@ ddxProcessArgument (int argc, char *argv[], int i) if (IS_OPTION ("-query")) { CHECK_ARGS (1); + g_fXdmcpEnabled = TRUE; g_pszQueryHost = argv[++i]; return 0; /* Let DIX parse this again */ } + /* + * Look for the '-indirect' or '-broadcast' arguments + */ + if (IS_OPTION ("-indirect") + || IS_OPTION ("-broadcast")) + { + g_fXdmcpEnabled = TRUE; + return 0; /* Let DIX parse this again */ + } + /* * Look for the '-xf86config' argument */ @@ -1409,8 +1463,13 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) } } + /* Load preferences from XWinrc file */ LoadPreferences(); + /* Generate a cookie used by internal clients for authorization */ + if (g_fXdmcpEnabled) + winGenerateAuthorization (); + #if CYGDEBUG || YES winErrorFVerb (2, "InitOutput - Returning.\n"); #endif diff --git a/hw/xwin/win.h b/hw/xwin/win.h index 5a8cf3788..3ada18bd4 100644 --- a/hw/xwin/win.h +++ b/hw/xwin/win.h @@ -52,6 +52,7 @@ #define WIN_EMULATE_PSEUDO_SUPPORT YES #define WIN_UPDATE_STATS NO + /* Turn debug messages on or off */ #define CYGDEBUG NO @@ -311,6 +312,10 @@ typedef Bool (*winReleasePrimarySurfaceProcPtr)(ScreenPtr); typedef Bool (*winFinishCreateWindowsWindowProcPtr)(WindowPtr pWin); +/* Typedef for DIX wrapper functions */ +typedef int (*winDispatchProcPtr) (ClientPtr); + + /* * GC (graphics context) privates */ @@ -441,12 +446,13 @@ typedef struct _winPrivScreenRec /* Clipboard support */ pthread_t ptClipboardProc; - -#if 0 - HWND hwndNextViewer; - void *display; - int window; -#endif + Bool fClipboardStarted; + HWND hwndClipboard; + void *pClipboardDisplay; + Window iClipboardWindow; + HWND hwndClipboardNextViewer; + Bool fCBCInitialized; + Atom atomLastOwnedSelection; /* Last width, height, and depth of the Windows display */ DWORD dwLastWindowsWidth; @@ -736,6 +742,14 @@ Bool winAllocateCmapPrivates (ColormapPtr pCmap); +/* + * winauth.c + */ + +Bool +winGenerateAuthorization (); + + /* * winblock.c */ @@ -761,7 +775,13 @@ winPixmapToRegionNativeGDI (PixmapPtr pPix); Bool winInitClipboard (pthread_t *ptClipboardProc, - pthread_mutex_t *ppmServerStarted, + Bool *pfClipboardStarted, + HWND *phwndClipboard, + void **ppClipboardDisplay, + Window *piClipboardWindow, + HWND *phwndClipboardNextViewer, + Bool *pfCBCInitialized, + Atom *patomLastOwnedSelection, DWORD dwScreen); /* @@ -944,6 +964,14 @@ winGetSpansNativeGDI (DrawablePtr pDrawable, char *pDst); +/* + * winglobals.c + */ + +void +winInitializeGlobals (); + + /* * winkeybd.c */ diff --git a/hw/xwin/winallpriv.c b/hw/xwin/winallpriv.c index a27309598..c9e831bab 100644 --- a/hw/xwin/winallpriv.c +++ b/hw/xwin/winallpriv.c @@ -33,6 +33,17 @@ #include "win.h" +/* + * References to external symbols + */ + +extern int g_iScreenPrivateIndex; +extern int g_iCmapPrivateIndex; +extern int g_iGCPrivateIndex; +extern int g_iPixmapPrivateIndex; +extern int g_iWindowPrivateIndex; +extern unsigned long g_ulServerGeneration; + /* See Porting Layer Definition - p. 58 */ /* diff --git a/hw/xwin/winauth.c b/hw/xwin/winauth.c new file mode 100644 index 000000000..1c9eaaa5a --- /dev/null +++ b/hw/xwin/winauth.c @@ -0,0 +1,127 @@ +/* + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. + * + *Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + *"Software"), to deal in the Software without restriction, including + *without limitation the rights to use, copy, modify, merge, publish, + *distribute, sublicense, and/or sell copies of the Software, and to + *permit persons to whom the Software is furnished to do so, subject to + *the following conditions: + * + *The above copyright notice and this permission notice shall be + *included in all copies or substantial portions of the Software. + * + *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR + *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *Except as contained in this notice, the name of Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" + +/* Includes for authorization */ +#include "Xauth.h" +#define _SECURITY_SERVER +#include "security.h" +#include "securstr.h" + + +/* + * Constants + */ + +#define AUTH_NAME "MIT-MAGIC-COOKIE-1" + + +/* + * Globals + */ + +XID g_authId = 0; +unsigned int g_uiAuthDataLen = 0; +char *g_pAuthData = NULL; + + +/* + * Generate authorization cookie for internal server clients + */ + +Bool +winGenerateAuthorization () +{ + Bool fFreeAuth = FALSE; + SecurityAuthorizationPtr pAuth = NULL; + + /* Call OS layer to generate authorization key */ + g_authId = GenerateAuthorization (strlen (AUTH_NAME), + AUTH_NAME, + 0, + NULL, + &g_uiAuthDataLen, + &g_pAuthData); + if ((XID) ~0L == g_authId) + { + ErrorF ("winGenerateAuthorization - GenerateAuthorization failed\n"); + goto auth_bailout; + } +#if 0 + else + { + ErrorF ("winGenerateAuthorization - GenerateAuthorization success!\n" + "AuthDataLen: %d AuthData: %s\n", + g_uiAuthDataLen, g_pAuthData); + } +#endif + + /* Allocate structure for additional auth information */ + pAuth = (SecurityAuthorizationPtr) + xalloc (sizeof (SecurityAuthorizationRec)); + if (!(pAuth)) + { + ErrorF ("winGenerateAuthorization - Failed allocating " + "SecurityAuthorizationPtr.\n"); + goto auth_bailout; + } + + /* Fill in the auth fields */ + pAuth->id = g_authId; + pAuth->timeout = 0; /* live for x seconds after refcnt == 0 */ + pAuth->group = None; + pAuth->trustLevel = XSecurityClientTrusted; + pAuth->refcnt = 1; /* this auth must stick around */ + pAuth->secondsRemaining = 0; + pAuth->timer = NULL; + pAuth->eventClients = NULL; + + /* Add the authorization to the server's auth list */ + if (!AddResource (g_authId, + SecurityAuthorizationResType, + pAuth)) + { + ErrorF ("winGenerateAuthorization - AddResource failed for auth.\n"); + fFreeAuth = TRUE; + goto auth_bailout; + } + + /* Don't free the auth data, since it is still used internally */ + pAuth = NULL; + + return TRUE; + + auth_bailout: + if (fFreeAuth) + xfree (pAuth); + + return FALSE; +} diff --git a/hw/xwin/winblock.c b/hw/xwin/winblock.c index 85b8b39d3..f86575970 100644 --- a/hw/xwin/winblock.c +++ b/hw/xwin/winblock.c @@ -31,6 +31,16 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iScreenPrivateIndex; +extern HWND g_hDlgDepthChange; +extern HWND g_hDlgExit; + + /* See Porting Layer Definition - p. 6 */ void winBlockHandler (int nScreen, diff --git a/hw/xwin/winclipboard.h b/hw/xwin/winclipboard.h index 3513f4423..842127d22 100644 --- a/hw/xwin/winclipboard.h +++ b/hw/xwin/winclipboard.h @@ -65,10 +65,12 @@ #define WIN_CLIPBOARD_WINDOW_CLASS "xwinclip" #define WIN_CLIPBOARD_WINDOW_TITLE "xwinclip" #define WIN_MSG_QUEUE_FNAME "/dev/windows" -#define WIN_CONNECT_RETRIES 3 +#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" + /* * Argument structure for Clipboard module main thread @@ -76,10 +78,29 @@ typedef struct _ClipboardProcArgRec { DWORD dwScreen; - pthread_mutex_t *ppmServerStarted; + Bool *pfClipboardStarted; + HWND *phwndClipboard; + void **ppClipboardDisplay; + Window *piClipboardWindow; + HWND *phwndClipboardNextViewer; + Bool *pfCBCInitialized; + Atom *patomLastOwnedSelection; } ClipboardProcArgRec, *ClipboardProcArgPtr; +/* + * Structure for messaging window properties + */ + +typedef struct _ClipboardWindowProp { + void **ppClipboardDisplay; + Window *piClipboardWindow; + HWND *phwndClipboardNextViewer; + Bool *pfCBCInitialized; + Atom *patomLastOwnedSelection; +} ClipboardWindowPropRec, *ClipboardWindowPropPtr; + + /* * References to external symbols */ @@ -94,11 +115,17 @@ extern void ErrorF (const char* /*f*/, ...); Bool winInitClipboard (pthread_t *ptClipboardProc, - pthread_mutex_t *ppmServerStarted, + Bool *pfClipboardStarted, + HWND *phwndClipboard, + void **ppClipboardDisplay, + Window *piClipboardWindow, + HWND *phwndClipboardNextViewer, + Bool *pfCBCInitialized, + Atom *patomLastOwnedSelection, DWORD dwScreen); HWND -winClipboardCreateMessagingWindow (void); +winClipboardCreateMessagingWindow (ClipboardProcArgPtr pProcArg); /* @@ -122,6 +149,7 @@ winClipboardProc (void *pArg); void winDeinitClipboard (void); + /* * winclipboardunicode.c */ @@ -148,12 +176,6 @@ winClipboardWindowProc (HWND hwnd, UINT message, Bool winClipboardFlushXEvents (HWND hwnd, - Atom atomClipboard, - Atom atomLocalProperty, - Atom atomUTF8String, - Atom atomCompoundText, - Atom atomTargets, - Atom atomDeleteWindow, int iWindow, Display *pDisplay, Bool fUnicodeSupport); diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c index abe97d2d5..f248d6129 100644 --- a/hw/xwin/winclipboardinit.c +++ b/hw/xwin/winclipboardinit.c @@ -29,8 +29,20 @@ */ /* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardinit.c,v 1.2 2003/07/29 21:25:16 dawes Exp $ */ +#include "dixstruct.h" + #include "winclipboard.h" +/* + * Local typedefs + */ + +typedef int (*winDispatchProcPtr) (ClientPtr); + +DISPATCH_PROC(winProcSetSelectionOwner); + +extern winDispatchProcPtr winProcSetSelectionOwnerOrig; + /* * Intialize the Clipboard module @@ -38,7 +50,13 @@ Bool winInitClipboard (pthread_t *ptClipboardProc, - pthread_mutex_t *ppmServerStarted, + Bool *pfClipboardStarted, + HWND *phwndClipboard, + void **ppClipboardDisplay, + Window *piClipboardWindow, + HWND *phwndClipboardNextViewer, + Bool *pfCBCInitialized, + Atom *patomLastOwnedSelection, DWORD dwScreen) { ClipboardProcArgPtr pArg; @@ -52,10 +70,23 @@ winInitClipboard (pthread_t *ptClipboardProc, ErrorF ("winInitClipboard - malloc for ClipboardProcArgRec failed.\n"); return FALSE; } + + /* Wrap some internal server functions */ + if (ProcVector[X_SetSelectionOwner] != winProcSetSelectionOwner) + { + winProcSetSelectionOwnerOrig = ProcVector[X_SetSelectionOwner]; + ProcVector[X_SetSelectionOwner] = winProcSetSelectionOwner; + } /* Setup the argument structure for the thread function */ pArg->dwScreen = dwScreen; - pArg->ppmServerStarted = ppmServerStarted; + pArg->pfClipboardStarted = pfClipboardStarted; + pArg->phwndClipboard = phwndClipboard; + pArg->ppClipboardDisplay = ppClipboardDisplay; + pArg->piClipboardWindow = piClipboardWindow; + pArg->phwndClipboardNextViewer = phwndClipboardNextViewer; + pArg->patomLastOwnedSelection = patomLastOwnedSelection; + pArg->pfCBCInitialized = pfCBCInitialized; /* Spawn a thread for the Clipboard module */ if (pthread_create (ptClipboardProc, NULL, winClipboardProc, pArg)) @@ -74,10 +105,11 @@ winInitClipboard (pthread_t *ptClipboardProc, */ HWND -winClipboardCreateMessagingWindow (void) +winClipboardCreateMessagingWindow (ClipboardProcArgPtr pProcArg) { - WNDCLASS wc; - HWND hwnd; + WNDCLASS wc; + HWND hwnd; + ClipboardWindowPropPtr pWindowProp = NULL; /* Setup our window class */ wc.style = CS_HREDRAW | CS_VREDRAW; @@ -92,6 +124,19 @@ winClipboardCreateMessagingWindow (void) wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS; RegisterClass (&wc); + /* Allocate and setup window property structure */ + pWindowProp = malloc (sizeof (ClipboardWindowPropRec)); + if (pWindowProp == NULL) + { + ErrorF ("winClipboardCreateMessagingWindow - malloc failed!\n"); + pthread_exit (NULL); + } + pWindowProp->ppClipboardDisplay = pProcArg->ppClipboardDisplay; + pWindowProp->piClipboardWindow = pProcArg->piClipboardWindow; + pWindowProp->phwndClipboardNextViewer = pProcArg->phwndClipboardNextViewer; + pWindowProp->pfCBCInitialized = pProcArg->pfCBCInitialized; + pWindowProp->patomLastOwnedSelection = pProcArg->patomLastOwnedSelection; + /* Create the window */ hwnd = CreateWindowExA (0, /* Extended styles */ WIN_CLIPBOARD_WINDOW_CLASS,/* Class name */ @@ -104,7 +149,7 @@ winClipboardCreateMessagingWindow (void) (HWND) NULL, /* No parent or owner window */ (HMENU) NULL, /* No menu */ GetModuleHandle (NULL),/* Instance handle */ - NULL); /* ScreenPrivates */ + pWindowProp); /* Creation data */ assert (hwnd != NULL); /* I'm not sure, but we may need to call this to start message processing */ diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c index 96e920926..88835ca54 100644 --- a/hw/xwin/winclipboardthread.c +++ b/hw/xwin/winclipboardthread.c @@ -30,13 +30,24 @@ /* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardthread.c,v 1.3 2003/10/02 13:30:10 eich Exp $ */ #include "winclipboard.h" +#include "Xauth.h" + +/* + * Constants + */ + +#define AUTH_NAME "MIT-MAGIC-COOKIE-1" + /* * References to external symbols */ -extern Bool g_fCalledSetLocale; -extern Bool g_fUnicodeClipboard; +extern Bool g_fCalledSetLocale; +extern Bool g_fUnicodeClipboard; +extern unsigned long serverGeneration; +extern unsigned int g_uiAuthDataLen; +extern char *g_pAuthData; /* @@ -44,7 +55,7 @@ extern Bool g_fUnicodeClipboard; */ static jmp_buf g_jmpEntry; -static Bool g_shutdown = FALSE; +Bool g_fUnicodeSupport = FALSE; /* @@ -66,8 +77,6 @@ void * winClipboardProc (void *pArg) { Atom atomClipboard, atomClipboardManager; - Atom atomLocalProperty, atomCompoundText; - Atom atomUTF8String, atomTargets; int iReturn; HWND hwnd = NULL; int iConnectionNumber; @@ -76,7 +85,6 @@ winClipboardProc (void *pArg) int iMaxDescriptor; Display *pDisplay; Window iWindow; - Atom atomDeleteWindow; Bool fReturn; int iRetries; Bool fUnicodeSupport; @@ -92,22 +100,12 @@ winClipboardProc (void *pArg) pthread_exit (NULL); } - ErrorF ("winClipboardProc - Calling pthread_mutex_lock ()\n"); - - /* Grab the server started mutex - pause until we get it */ - iReturn = pthread_mutex_lock (pProcArg->ppmServerStarted); - if (iReturn != 0) - { - ErrorF ("winClipboardProc - pthread_mutex_lock () failed: %d\n", - iReturn); - pthread_exit (NULL); - } - - ErrorF ("winClipboardProc - pthread_mutex_lock () returned.\n"); - /* Do we have Unicode support? */ fUnicodeSupport = g_fUnicodeClipboard && winClipboardDetectUnicodeSupport (); + /* Save the Unicode support flag in a global */ + g_fUnicodeSupport = fUnicodeSupport; + /* Set the current locale? What does this do? */ if (!g_fCalledSetLocale) { @@ -139,11 +137,6 @@ winClipboardProc (void *pArg) ErrorF ("winClipboardProc - XInitThreads () returned.\n"); - /* Release the server started mutex */ - pthread_mutex_unlock (pProcArg->ppmServerStarted); - - ErrorF ("winClipboardProc - pthread_mutex_unlock () returned.\n"); - /* Set jump point for Error exits */ iReturn = setjmp (g_jmpEntry); @@ -156,16 +149,22 @@ winClipboardProc (void *pArg) iReturn); pthread_exit (NULL); } - else if (g_shutdown) - { - /* Shutting down, the X server severed out connection! */ - ErrorF ("winClipboardProc - Detected shutdown in progress\n"); - pthread_exit (NULL); - } else if (iReturn == WIN_JMP_ERROR_IO) { - ErrorF ("winClipboardProc - setjmp returned and hwnd: %08x\n", hwnd); + /* TODO: Cleanup the Win32 window and free any allocated memory */ + ErrorF ("winClipboardProc - setjmp returned for IO Error Handler.\n"); + pthread_exit (NULL); } + + /* Use our generated cookie for authentication */ + XSetAuthorization (AUTH_NAME, + strlen (AUTH_NAME), + g_pAuthData, + g_uiAuthDataLen); + + /* Set error handler */ + XSetErrorHandler (winClipboardErrorHandler); + XSetIOErrorHandler (winClipboardIOErrorHandler); /* Initialize retry count */ iRetries = 0; @@ -205,12 +204,12 @@ winClipboardProc (void *pArg) pthread_exit (NULL); } + /* Save the display in the screen privates */ + *(pProcArg->ppClipboardDisplay) = pDisplay; + ErrorF ("winClipboardProc - XOpenDisplay () returned and " "successfully opened the display.\n"); - /* Create Windows messaging window */ - hwnd = winClipboardCreateMessagingWindow (); - /* Get our connection number */ iConnectionNumber = ConnectionNumber (pDisplay); @@ -234,6 +233,13 @@ winClipboardProc (void *pArg) ErrorF ("winClipboardProc - XSelectInput generated BadWindow " "on RootWindow\n\n"); + /* Create atoms */ + atomClipboard = XInternAtom (pDisplay, "CLIPBOARD", False); + atomClipboardManager = XInternAtom (pDisplay, "CLIPBOARD_MANAGER", False); + + /* FIXME: Save some values as globals for the window proc */ + g_fUnicodeSupport = fUnicodeSupport; + /* Create a messaging window */ iWindow = XCreateSimpleWindow (pDisplay, DefaultRootWindow (pDisplay), @@ -244,27 +250,20 @@ winClipboardProc (void *pArg) BlackPixel (pDisplay, 0)); if (iWindow == 0) { - ErrorF ("winClipboardProc - Could not create a window\n"); + ErrorF ("winClipboardProc - Could not create an X window.\n"); pthread_exit (NULL); } - /* This looks like our only hope for getting a message before shutdown */ - /* Register for WM_DELETE_WINDOW message from window manager */ - atomDeleteWindow = XInternAtom (pDisplay, "WM_DELETE_WINDOW", False); - XSetWMProtocols (pDisplay, iWindow, &atomDeleteWindow, 1); + /* Save the window in the screen privates */ + *(pProcArg->piClipboardWindow) = iWindow; - /* Set error handler */ - XSetErrorHandler (winClipboardErrorHandler); - XSetIOErrorHandler (winClipboardIOErrorHandler); - - /* Create an atom for CLIPBOARD_MANAGER */ - atomClipboardManager = XInternAtom (pDisplay, "CLIPBOARD_MANAGER", False); - if (atomClipboardManager == None) - { - ErrorF ("winClipboardProc - Could not create CLIPBOARD_MANAGER atom\n"); - pthread_exit (NULL); - } + /* Create Windows messaging window */ + hwnd = winClipboardCreateMessagingWindow (pProcArg); + + /* Save copy of HWND in screen privates */ + *(pProcArg->phwndClipboard) = hwnd; +#if 0 /* Assert ownership of CLIPBOARD_MANAGER */ iReturn = XSetSelectionOwner (pDisplay, atomClipboardManager, iWindow, CurrentTime); @@ -273,63 +272,28 @@ winClipboardProc (void *pArg) ErrorF ("winClipboardProc - Could not set CLIPBOARD_MANAGER owner\n"); pthread_exit (NULL); } +#endif - /* Create an atom for CLIPBOARD */ - atomClipboard = XInternAtom (pDisplay, "CLIPBOARD", False); - if (atomClipboard == None) + /* Assert ownership of selections if Win32 clipboard is owned */ + if (NULL != GetClipboardOwner ()) { - ErrorF ("winClipboardProc - Could not create CLIPBOARD atom\n"); - pthread_exit (NULL); - } + /* PRIMARY */ + iReturn = XSetSelectionOwner (pDisplay, XA_PRIMARY, + iWindow, CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardProc - Could not set PRIMARY owner\n"); + pthread_exit (NULL); + } - /* Assert ownership of CLIPBOARD */ - iReturn = XSetSelectionOwner (pDisplay, atomClipboard, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardProc - Could not set CLIPBOARD owner\n"); - pthread_exit (NULL); - } - - /* Assert ownership of PRIMARY */ - iReturn = XSetSelectionOwner (pDisplay, XA_PRIMARY, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardProc - Could not set PRIMARY owner\n"); - pthread_exit (NULL); - } - - /* Local property to hold pasted data */ - atomLocalProperty = XInternAtom (pDisplay, "CYGX_CUT_BUFFER", False); - if (atomLocalProperty == None) - { - ErrorF ("winClipboardProc - Could not create CYGX_CUT_BUFFER atom\n"); - pthread_exit (NULL); - } - - /* Create an atom for UTF8_STRING */ - atomUTF8String = XInternAtom (pDisplay, "UTF8_STRING", False); - if (atomUTF8String == None) - { - ErrorF ("winClipboardProc - Could not create UTF8_STRING atom\n"); - pthread_exit (NULL); - } - - /* Create an atom for COMPOUND_TEXT */ - atomCompoundText = XInternAtom (pDisplay, "COMPOUND_TEXT", False); - if (atomCompoundText == None) - { - ErrorF ("winClipboardProc - Could not create COMPOUND_TEXT atom\n"); - pthread_exit (NULL); - } - - /* Create an atom for TARGETS */ - atomTargets = XInternAtom (pDisplay, "TARGETS", False); - if (atomTargets == None) - { - ErrorF ("winClipboardProc - Could not create TARGETS atom\n"); - pthread_exit (NULL); + /* CLIPBOARD */ + iReturn = XSetSelectionOwner (pDisplay, atomClipboard, + iWindow, CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardProc - Could not set CLIPBOARD owner\n"); + pthread_exit (NULL); + } } /* Pre-flush X events */ @@ -339,12 +303,6 @@ winClipboardProc (void *pArg) * already. */ winClipboardFlushXEvents (hwnd, - atomClipboard, - atomLocalProperty, - atomUTF8String, - atomCompoundText, - atomTargets, - atomDeleteWindow, iWindow, pDisplay, fUnicodeSupport); @@ -353,6 +311,9 @@ winClipboardProc (void *pArg) if (!winClipboardFlushWindowsMessageQueue (hwnd)) return 0; + /* Signal that the clipboard client has started */ + *(pProcArg->pfClipboardStarted) = TRUE; + /* Loop for X events */ while (1) { @@ -378,7 +339,7 @@ winClipboardProc (void *pArg) "Bailing.\n", iReturn); break; } - + /* Branch on which descriptor became active */ if (FD_ISSET (iConnectionNumber, &fdsRead)) { @@ -390,19 +351,13 @@ winClipboardProc (void *pArg) /* Process X events */ /* Exit when we see that server is shutting down */ fReturn = winClipboardFlushXEvents (hwnd, - atomClipboard, - atomLocalProperty, - atomUTF8String, - atomCompoundText, - atomTargets, - atomDeleteWindow, iWindow, pDisplay, fUnicodeSupport); if (!fReturn) { - ErrorF ("winClipboardProc - Caught WM_DELETE_WINDOW - " - "shutting down\n"); + ErrorF ("winClipboardProc - winClipboardFlushXEvents " + "trapped shutdown event, exiting main loop.\n"); break; } } @@ -414,14 +369,19 @@ winClipboardProc (void *pArg) #if 0 ErrorF ("winClipboardProc - Windows event ready\n"); #endif - + /* Process Windows messages */ if (!winClipboardFlushWindowsMessageQueue (hwnd)) - break; + { + ErrorF ("winClipboardProc - " + "winClipboardFlushWindowsMessageQueue trapped " + "WM_QUIT message, exiting main loop.\n"); + break; + } } } - return 0; + return NULL; } @@ -440,16 +400,14 @@ winClipboardErrorHandler (Display *pDisplay, XErrorEvent *pErr) sizeof (pszErrorMsg)); ErrorF ("winClipboardErrorHandler - ERROR: \n\t%s\n", pszErrorMsg); +#if 0 if (pErr->error_code == BadWindow || pErr->error_code == BadMatch || pErr->error_code == BadDrawable) { -#if 0 pthread_exit (NULL); -#endif } -#if 0 pthread_exit (NULL); #endif @@ -464,7 +422,7 @@ winClipboardErrorHandler (Display *pDisplay, XErrorEvent *pErr) static int winClipboardIOErrorHandler (Display *pDisplay) { - printf ("\nwinClipboardIOErrorHandler!\n\n"); + ErrorF ("\nwinClipboardIOErrorHandler!\n\n"); /* Restart at the main entry point */ longjmp (g_jmpEntry, WIN_JMP_ERROR_IO); @@ -478,8 +436,10 @@ winClipboardIOErrorHandler (Display *pDisplay) */ void -winDeinitClipboard (void) +winDeinitClipboard () { ErrorF ("winDeinitClipboard - Noting shutdown in progress\n"); - g_shutdown = TRUE; +#if 0 + g_fShutdown = TRUE; +#endif } diff --git a/hw/xwin/winclipboardwndproc.c b/hw/xwin/winclipboardwndproc.c index c577d060e..8e55ad3e7 100644 --- a/hw/xwin/winclipboardwndproc.c +++ b/hw/xwin/winclipboardwndproc.c @@ -32,6 +32,42 @@ #include "winclipboard.h" +/* + * Constants + */ + +#define WIN_CLIPBOARD_PROP "cyg_clipboard_prop" + + +/* + * References to external symbols + */ + +extern Bool g_fUnicodeSupport; + + +/* + * Local function prototypes + */ + +static Bool +winLookForSelectionNotify (Display *pDisplay, XEvent *pEvent, XPointer pArg); + + +/* + * Signal that we found a SelectionNotify event + */ + +static Bool +winLookForSelectionNotify (Display *pDisplay, XEvent *pEvent, XPointer pArg) +{ + if (pEvent->type == SelectionNotify) + return TRUE; + + return FALSE; +} + + /* * Process a given Windows message */ @@ -40,18 +76,231 @@ LRESULT CALLBACK winClipboardWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { + ClipboardWindowPropPtr pWindowProp = GetProp (hwnd, + WIN_CLIPBOARD_PROP); + /* Branch on message type */ switch (message) { case WM_DESTROY: - PostQuitMessage (0); + { + ErrorF ("winClipboardWindowProc - WM_DESTROY\n"); + + HWND *phwndNextViewer = pWindowProp->phwndClipboardNextViewer; + + /* Remove ourselves from the clipboard chain */ + ChangeClipboardChain (hwnd, *phwndNextViewer); + + *phwndNextViewer = NULL; + + /* Free the window property data */ + free (pWindowProp); + pWindowProp = NULL; + SetProp (hwnd, WIN_CLIPBOARD_PROP, NULL); + + PostQuitMessage (0); + } return 0; + case WM_CREATE: -#if 0 - ErrorF ("WindowProc - WM_CREATE\n"); -#endif + { + ErrorF ("winClipboardWindowProc - WM_CREATE\n"); + + /* Fetch window data from creation data */ + pWindowProp = ((LPCREATESTRUCT) lParam)->lpCreateParams; + + /* Save data as a window property */ + SetProp (hwnd, WIN_CLIPBOARD_PROP, pWindowProp); + + /* Add ourselves to the clipboard viewer chain */ + *(pWindowProp->phwndClipboardNextViewer) = SetClipboardViewer (hwnd); + } return 0; + + + case WM_CHANGECBCHAIN: + { + HWND *phwndNextViewer = pWindowProp->phwndClipboardNextViewer; + + if ((HWND) wParam == *phwndNextViewer) + *phwndNextViewer = (HWND) lParam; + else if (*phwndNextViewer) + SendMessage (*phwndNextViewer, message, wParam, lParam); + } + return 0; + + + case WM_DRAWCLIPBOARD: + { + HWND *phwndNextViewer = pWindowProp->phwndClipboardNextViewer; + Bool *pfCBCInitialized = pWindowProp->pfCBCInitialized; + Display *pDisplay = *(pWindowProp->ppClipboardDisplay); + Window iWindow = *(pWindowProp->piClipboardWindow); + int iReturn; + + /* Pass the message on the next window in the clipboard viewer chain */ + if (*phwndNextViewer) + SendMessage (*phwndNextViewer, message, 0, 0); + + /* Bail on first message */ + if (!*pfCBCInitialized) + { + ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Initializing - Returning.\n"); + *pfCBCInitialized = TRUE; + return 0; + } + + /* Bail when clipboard is unowned */ + if (NULL == GetClipboardOwner ()) + { + ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Clipboard is unowned.\n"); + return 0; + } + + /* Bail when we still own the clipboard */ + if (hwnd == GetClipboardOwner ()) + { + ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "We own the clipboard, returning.\n"); + return 0; + } + + /* Reassert ownership of PRIMARY */ + iReturn = XSetSelectionOwner (pDisplay, + XA_PRIMARY, + iWindow, + CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Could not reassert ownership of PRIMARY\n"); + } + else + { + ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Reasserted ownership of PRIMARY\n"); + } + + /* Reassert ownership of the CLIPBOARD */ + iReturn = XSetSelectionOwner (pDisplay, + XInternAtom (pDisplay, + "CLIPBOARD", + FALSE), + iWindow, + CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Could not reassert ownership of CLIPBOARD\n"); + } + else + { + ErrorF ("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + "Reasserted ownership of CLIPBOARD\n"); + } + + /* Flush the pending SetSelectionOwner event now */ + XFlush (pDisplay); + } + return 0; + + + case WM_RENDERFORMAT: + case WM_RENDERALLFORMATS: + { + XEvent event; + int iReturn; + Display *pDisplay = *(pWindowProp->ppClipboardDisplay); + Window iWindow = *(pWindowProp->piClipboardWindow); + +#if 0 + ErrorF ("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n"); +#endif + + /* Request the selection contents */ + iReturn = XConvertSelection (pDisplay, + *(pWindowProp->patomLastOwnedSelection), + XInternAtom (pDisplay, + "COMPOUND_TEXT", False), + XInternAtom (pDisplay, + "CYGX_CUT_BUFFER", False), + iWindow, + CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardWindowProc - WM_RENDER*FORMAT - " + "XConvertSelection () failed\n"); + break; + } + + /* Wait for the SelectionNotify event */ + XPeekIfEvent (pDisplay, &event, winLookForSelectionNotify, NULL); + + /* Special handling for WM_RENDERALLFORMATS */ + if (message == WM_RENDERALLFORMATS) + { + /* We must open and empty the clipboard */ + + if (!OpenClipboard (hwnd)) + { + ErrorF ("winClipboardWindowProc - WM_RENDER*FORMATS - " + "OpenClipboard () failed: %08x\n", + GetLastError ()); + break; + } + + if (!EmptyClipboard ()) + { + ErrorF ("winClipboardWindowProc - WM_RENDER*FORMATS - " + "EmptyClipboard () failed: %08x\n", + GetLastError ()); + break; + } + } + + /* Process the SelectionNotify event */ + if (!winClipboardFlushXEvents (hwnd, + iWindow, + pDisplay, + g_fUnicodeSupport)) + { + /* + * The selection was offered for conversion first, so we have + * to process a second SelectionNotify event to get the actual + * data in the selection. + */ + + /* Wait for the second SelectionNotify event */ + XPeekIfEvent (pDisplay, &event, winLookForSelectionNotify, NULL); + + winClipboardFlushXEvents (hwnd, + iWindow, + pDisplay, + g_fUnicodeSupport); + } + + /* Special handling for WM_RENDERALLFORMATS */ + if (message == WM_RENDERALLFORMATS) + { + /* We must close the clipboard */ + + if (!CloseClipboard ()) + { + ErrorF ("winClipboardWindowProc - WM_RENDERALLFORMATS - " + "CloseClipboard () failed: %08x\n", + GetLastError ()); + break; + } + } + +#if 0 + ErrorF ("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n"); +#endif + return 0; + } } /* Let Windows perform default processing for unhandled messages */ diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c new file mode 100755 index 000000000..b0aefad27 --- /dev/null +++ b/hw/xwin/winclipboardwrappers.c @@ -0,0 +1,498 @@ +/* + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. + * + *Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + *"Software"), to deal in the Software without restriction, including + *without limitation the rights to use, copy, modify, merge, publish, + *distribute, sublicense, and/or sell copies of the Software, and to + *permit persons to whom the Software is furnished to do so, subject to + *the following conditions: + * + *The above copyright notice and this permission notice shall be + *included in all copies or substantial portions of the Software. + * + *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR + *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *Except as contained in this notice, the name of Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" +#include "dixstruct.h" + + +/* + * Local function prototypes + */ + +DISPATCH_PROC(winProcEstablishConnection); +DISPATCH_PROC(winProcQueryTree); +DISPATCH_PROC(winProcSetSelectionOwner); + +/* + * References to external symbols + */ + +extern Bool g_fUnicodeSupport; +extern int g_iNumScreens; +extern unsigned int g_uiAuthDataLen; +extern char *g_pAuthData; +extern Bool g_fXdmcpEnabled; +extern Bool g_fClipboardLaunched; + +extern winDispatchProcPtr winProcEstablishConnectionOrig; +extern winDispatchProcPtr winProcQueryTreeOrig; +extern winDispatchProcPtr winProcSetSelectionOwnerOrig; + + + +/* + * Wrapper for internal QueryTree function. + * Hides the clipboard client when it is the only client remaining. + */ + +int +winProcQueryTree (ClientPtr client) +{ + int i; + int iReturn; + + /* + * This procedure is only used for initialization. + * We can unwrap the original procedure at this point + * so that this function is no longer called until the + * server resets and the function is wrapped again. + */ + ProcVector[X_QueryTree] = winProcQueryTreeOrig; + + /* + * Call original function and bail if it fails. + * NOTE: We must do this first, since we need XdmcpOpenDisplay + * to be called before we initialize our clipboard client. + */ + iReturn = (*winProcQueryTreeOrig) (client); + if (iReturn != 0) + { + ErrorF ("winProcQueryTree - ProcQueryTree failed, bailing.\n"); + return iReturn; + } + + /* If the clipboard client has already been started, abort */ + if (g_fClipboardLaunched) + { + ErrorF ("winProcQueryTree - Clipboard client already " + "launched, returning.\n"); + return iReturn; + } + + /* Walk the list of screens */ + for (i = 0; i < g_iNumScreens; i++) + { + ScreenPtr pScreen = g_ScreenInfo[i].pScreen; + winScreenPriv(pScreen); + + /* Startup the clipboard client if clipboard mode is being used */ + if (g_fXdmcpEnabled + && g_ScreenInfo[i].fClipboard) + { + /* + * NOTE: The clipboard client is started here for a reason: + * 1) Assume you are using XDMCP (e.g. XWin -query %hostname%) + * 2) If the clipboard client attaches during X Server startup, + * then it becomes the "magic client" that causes the X Server + * to reset if it exits. + * 3) XDMCP calls KillAllClients when it starts up. + * 4) The clipboard client is a client, so it is killed. + * 5) The clipboard client is the "magic client", so the X Server + * resets itself. + * 6) This repeats ad infinitum. + * 7) We avoid this by waiting until at least one client (could + * be XDM, could be another client) connects, which makes it + * almost certain that the clipboard client will not connect + * until after XDM when using XDMCP. + * 8) Unfortunately, there is another problem. + * 9) XDM walks the list of windows with XQueryTree, + * killing any client it finds with a window. + * 10)Thus, when using XDMCP we wait until the first call + * to ProcQueryTree before we startup the clipboard client. + * This should prevent XDM from finding the clipboard client, + * since it has not yet created a window. + * 11)Startup when not using XDMCP is handled in + * winProcEstablishConnection. + */ + + /* Create the clipboard client thread */ + if (!winInitClipboard (&pScreenPriv->ptClipboardProc, + &pScreenPriv->fClipboardStarted, + &pScreenPriv->hwndClipboard, + &pScreenPriv->pClipboardDisplay, + &pScreenPriv->iClipboardWindow, + &pScreenPriv->hwndClipboardNextViewer, + &pScreenPriv->fCBCInitialized, + &pScreenPriv->atomLastOwnedSelection, + g_ScreenInfo[i].dwScreen)) + { + ErrorF ("winProcQueryTree - winClipboardInit " + "failed.\n"); + return iReturn; + } + + ErrorF ("winProcQueryTree - winInitClipboard returned.\n"); + } + } + + /* Flag that clipboard client has been launched */ + g_fClipboardLaunched = TRUE; + + return iReturn; +} + + +/* + * Wrapper for internal EstablishConnection function. + * Initializes internal clients that must not be started until + * an external client has connected. + */ + +int +winProcEstablishConnection (ClientPtr client) +{ + int i; + int iReturn; + static int s_iCallCount = 0; + static unsigned long s_ulServerGeneration = 0; + + ErrorF ("winProcEstablishConnection - Hello\n"); + + /* Watch for server reset */ + if (s_ulServerGeneration != serverGeneration) + { + /* Save new generation number */ + s_ulServerGeneration = serverGeneration; + + /* Reset call count */ + s_iCallCount = 0; + } + + /* Increment call count */ + ++s_iCallCount; + + /* Wait for second call when Xdmcp is enabled */ + if (g_fXdmcpEnabled + && !g_fClipboardLaunched + && s_iCallCount < 3) + { + ErrorF ("winProcEstablishConnection - Xdmcp enabled, waiting to " + "start clipboard client until third call.\n"); + return (*winProcEstablishConnectionOrig) (client); + } + + /* + * This procedure is only used for initialization. + * We can unwrap the original procedure at this point + * so that this function is no longer called until the + * server resets and the function is wrapped again. + */ + InitialVector[2] = winProcEstablishConnectionOrig; + + /* + * Call original function and bail if it fails. + * NOTE: We must do this first, since we need XdmcpOpenDisplay + * to be called before we initialize our clipboard client. + */ + iReturn = (*winProcEstablishConnectionOrig) (client); + if (iReturn != 0) + { + ErrorF ("winProcEstablishConnection - ProcEstablishConnection " + "failed, bailing.\n"); + return iReturn; + } + + /* Clear original function pointer */ + winProcEstablishConnectionOrig = NULL; + + /* If the clipboard client has already been started, abort */ + if (g_fClipboardLaunched) + { + ErrorF ("winProcEstablishConnection - Clipboard client already " + "launched, returning.\n"); + return iReturn; + } + + /* Walk the list of screens */ + for (i = 0; i < g_iNumScreens; i++) + { + ScreenPtr pScreen = g_ScreenInfo[i].pScreen; + winScreenPriv(pScreen); + + /* Startup the clipboard client if clipboard mode is being used */ + if (g_ScreenInfo[i].fClipboard) + { + /* + * NOTE: The clipboard client is started here for a reason: + * 1) Assume you are using XDMCP (e.g. XWin -query %hostname%) + * 2) If the clipboard client attaches during X Server startup, + * then it becomes the "magic client" that causes the X Server + * to reset if it exits. + * 3) XDMCP calls KillAllClients when it starts up. + * 4) The clipboard client is a client, so it is killed. + * 5) The clipboard client is the "magic client", so the X Server + * resets itself. + * 6) This repeats ad infinitum. + * 7) We avoid this by waiting until at least one client (could + * be XDM, could be another client) connects, which makes it + * almost certain that the clipboard client will not connect + * until after XDM when using XDMCP. + * 8) Unfortunately, there is another problem. + * 9) XDM walks the list of windows with XQueryTree, + * killing any client it finds with a window. + * 10)Thus, when using XDMCP we wait until the second call + * to ProcEstablishCeonnection before we startup the clipboard + * client. This should prevent XDM from finding the clipboard + * client, since it has not yet created a window. + */ + + /* Create the clipboard client thread */ + if (!winInitClipboard (&pScreenPriv->ptClipboardProc, + &pScreenPriv->fClipboardStarted, + &pScreenPriv->hwndClipboard, + &pScreenPriv->pClipboardDisplay, + &pScreenPriv->iClipboardWindow, + &pScreenPriv->hwndClipboardNextViewer, + &pScreenPriv->fCBCInitialized, + &pScreenPriv->atomLastOwnedSelection, + g_ScreenInfo[i].dwScreen)) + { + ErrorF ("winProcEstablishConnection - winClipboardInit " + "failed.\n"); + return iReturn; + } + + ErrorF ("winProcEstablishConnection - winInitClipboard returned.\n"); + } + } + + /* Flag that clipboard client has been launched */ + g_fClipboardLaunched = TRUE; + + return iReturn; +} + + +/* + * Wrapper for internal SetSelectionOwner function. + * Grabs ownership of Windows clipboard when X11 clipboard owner changes. + */ + +int +winProcSetSelectionOwner (ClientPtr client) +{ + DrawablePtr pDrawable; + ScreenPtr pScreen = NULL; + winPrivScreenPtr pScreenPriv = NULL; + HWND hwndClipboard = NULL; + WindowPtr pWindow = None; + REQUEST(xSetSelectionOwnerReq); + + REQUEST_SIZE_MATCH(xSetSelectionOwnerReq); + +#if 0 + ErrorF ("winProcSetSelectionOwner - Hello.\n"); +#endif + + /* Grab the Window from the request */ + if (stuff->window != None) + { + pWindow = (WindowPtr) SecurityLookupWindow (stuff->window, client, + SecurityReadAccess); + + if (!pWindow) + { + ErrorF ("winProcSetSelectionOwner - Found BadWindow, aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + } + else + { +#if 0 + ErrorF ("winProcSetSelectionOwner - No window specified, aborting.\n"); +#endif + + /* Abort if we don't have a drawable for the client */ + if ((pDrawable = client->lastDrawable) == NULL) + { + ErrorF ("winProcSetSelectionOwner - Client has no " + "lastDrawable, aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if we don't have a screen for the drawable */ + if ((pScreen = pDrawable->pScreen) == NULL) + { + ErrorF ("winProcSetSelectionOwner - Drawable has no screen, " + "aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if no screen privates */ + if ((pScreenPriv = winGetScreenPriv (pScreen)) == NULL) + { + ErrorF ("winProcSetSelectionOwner - Screen has no privates, " + "aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if clipboard not completely initialized yet */ + if (!pScreenPriv->fClipboardStarted) + { + ErrorF ("winProcSetSelectionOwner - Clipboard not yet started, " + "aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if WM_DRAWCLIPBOARD disowned the selection */ + if (pScreenPriv->iClipboardWindow == client->lastDrawableID) + { + ErrorF ("winProcSetSelectionOwner - WM_DRAWCLIPBOARD disowned " + "the selection, aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Check if we own the clipboard */ + if (pScreenPriv->hwndClipboard != NULL + && pScreenPriv->hwndClipboard == GetClipboardOwner ()) + { + ErrorF ("winProcSetSelectionOwner - We currently own the " + "clipboard, releasing ownership.\n"); + + /* Release ownership of the Windows clipboard */ + OpenClipboard (NULL); + EmptyClipboard (); + CloseClipboard (); + } + + goto winProcSetSelectionOwner_Done; + } + + /* Abort if invalid selection */ + if (!ValidAtom (stuff->selection)) + { + ErrorF ("winProcSetSelectionOwner - Found BadAtom, aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Cast Window to Drawable */ + pDrawable = (DrawablePtr) pWindow; + + + /* + * Get the screen pointer from the client pointer + */ + + /* Abort if we don't have a screen for the window */ + if ((pScreen = pDrawable->pScreen) == NULL) + { + ErrorF ("winProcSetSelectionOwner - Window has no screen.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if no screen privates */ + if ((pScreenPriv = winGetScreenPriv (pScreen)) == NULL) + { + ErrorF ("winProcSetSelectionOwner - Screen has no privates.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if clipboard not completely initialized yet */ + if (!pScreenPriv->fClipboardStarted) + { + ErrorF ("\nwinProcSetSelectionOwner - Clipboard not yet started.\n\n"); + goto winProcSetSelectionOwner_Done; + } + +#if 0 + ErrorF ("winProcSetSelectionOwner - " + "iWindow: %d client->lastDrawableID: %d target: %d\n", + pScreenPriv->iClipboardWindow, pDrawable->id, stuff->selection); +#endif + + /* Abort if no clipboard manager window */ + if (pScreenPriv->iClipboardWindow == 0) + { + ErrorF ("winProcSetSelectionOwner - No X clipboard window.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if clipboard manager is owning the selection */ + if (pDrawable->id == pScreenPriv->iClipboardWindow) + { + ErrorF ("winProcSetSelectionOwner - We changed ownership, " + "aborting.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if root window is taking ownership */ + if (pDrawable->id == 0) + { + ErrorF ("winProcSetSelectionOwner - Root window taking ownership, " + "aborting\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Abort if no clipboard window */ + if ((hwndClipboard = pScreenPriv->hwndClipboard) == NULL + || !IsWindow (hwndClipboard)) + { + ErrorF ("winProcSetSelectionOwner - No valid clipboard window " + "handle.\n"); + goto winProcSetSelectionOwner_Done; + } + + /* Access the Windows clipboard */ + if (!OpenClipboard (hwndClipboard)) + { + ErrorF ("winProcSetSelectionOwner - OpenClipboard () failed: %08x\n", + (int) GetLastError ()); + goto winProcSetSelectionOwner_Done; + } + + /* Take ownership of the Windows clipboard */ + if (!EmptyClipboard ()) + { + ErrorF ("winProcSetSelectionOwner - EmptyClipboard () failed: %08x\n", + (int) GetLastError ()); + goto winProcSetSelectionOwner_Done; + } + + /* Setup supported clipboard formats */ + if (g_fUnicodeSupport) + SetClipboardData (CF_UNICODETEXT, NULL); + else + SetClipboardData (CF_TEXT, NULL); + + /* Save handle to last owned selection */ + pScreenPriv->atomLastOwnedSelection = stuff->selection; + + /* Release the clipboard */ + if (!CloseClipboard ()) + { + ErrorF ("winProcSetSelectionOwner - CloseClipboard () failed: " + "%08x\n", + (int) GetLastError ()); + goto winProcSetSelectionOwner_Done; + } + + winProcSetSelectionOwner_Done: + return (*winProcSetSelectionOwnerOrig) (client); +} diff --git a/hw/xwin/winclipboardxevents.c b/hw/xwin/winclipboardxevents.c index 7484941f0..7b40aa783 100644 --- a/hw/xwin/winclipboardxevents.c +++ b/hw/xwin/winclipboardxevents.c @@ -38,21 +38,10 @@ Bool winClipboardFlushXEvents (HWND hwnd, - Atom atomClipboard, - Atom atomLocalProperty, - Atom atomUTF8String, - Atom atomCompoundText, - Atom atomTargets, - Atom atomDeleteWindow, int iWindow, Display *pDisplay, Bool fUnicodeSupport) { -#if 0 - Atom atomReturnType; - int iReturnFormat; - unsigned long ulReturnItems; -#endif XTextProperty xtpText; XEvent event; XSelectionEvent eventSelection; @@ -72,6 +61,18 @@ winClipboardFlushXEvents (HWND hwnd, int iUnicodeLen = 0; int iReturnDataLen = 0; int i; + Atom atomLocalProperty = XInternAtom (pDisplay, + WIN_LOCAL_PROPERTY, + False); + Atom atomUTF8String = XInternAtom (pDisplay, + "UTF8_STRING", + False); + Atom atomCompoundText = XInternAtom (pDisplay, + "COMPOUND_TEXT", + False); + Atom atomTargets = XInternAtom (pDisplay, + "TARGETS", + False); /* Process all pending events */ while (XPending (pDisplay)) @@ -82,50 +83,24 @@ winClipboardFlushXEvents (HWND hwnd, /* Branch on the event type */ switch (event.type) { - case ClientMessage: - if (event.xclient.data.l[0] == atomDeleteWindow) - { - ErrorF ("\nwinClipboardFlushXEvents - Received " - "WM_DELETE_WINDOW\n\n"); - fReturn = FALSE; - } - else - ErrorF ("\nwinClipboardFlushXEvents - Unknown ClientMessage\n\n"); - break; - - case SelectionClear: - /* Request the lost selection contents */ - iReturn = XConvertSelection (pDisplay, - event.xselectionclear.selection, - atomCompoundText, - atomLocalProperty, - iWindow, - CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - SelectionClear - " - "XConvertSelection () failed\n"); - pthread_exit (NULL); - } - break; - - /* * SelectionRequest */ case SelectionRequest: #if 0 - char *pszAtomName = NULL - - ErrorF ("SelectionRequest - target %d\n", - event.xselectionrequest.target); - - pszAtomName = XGetAtomName (pDisplay, - event.xselectionrequest.target); - ErrorF ("SelectionRequest - Target atom name %s\n", pszAtomName); - XFree (pszAtomName); - pszAtomName = NULL; + { + char *pszAtomName = NULL; + + ErrorF ("SelectionRequest - target %d\n", + event.xselectionrequest.target); + + pszAtomName = XGetAtomName (pDisplay, + event.xselectionrequest.target); + ErrorF ("SelectionRequest - Target atom name %s\n", pszAtomName); + XFree (pszAtomName); + pszAtomName = NULL; + } #endif /* Abort if invalid target type */ @@ -189,14 +164,14 @@ winClipboardFlushXEvents (HWND hwnd, } /* Setup selection notify xevent */ - eventSelection.type = SelectionNotify; - eventSelection.send_event = True; - eventSelection.display = pDisplay; - eventSelection.requestor = event.xselectionrequest.requestor; - eventSelection.selection = event.xselectionrequest.selection; - eventSelection.target = event.xselectionrequest.target; - eventSelection.property = event.xselectionrequest.property; - eventSelection.time = event.xselectionrequest.time; + eventSelection.type = SelectionNotify; + eventSelection.send_event = True; + eventSelection.display = pDisplay; + eventSelection.requestor = event.xselectionrequest.requestor; + eventSelection.selection = event.xselectionrequest.selection; + eventSelection.target = event.xselectionrequest.target; + eventSelection.property = event.xselectionrequest.property; + eventSelection.time = event.xselectionrequest.time; /* * Notify the requesting window that @@ -238,7 +213,7 @@ winClipboardFlushXEvents (HWND hwnd, * FIXME: Can't pass CF_UNICODETEXT on Windows 95/98/Me */ - /* Get a pointer to the clipboard text */ + /* Get a pointer to the clipboard text, in desired format */ if (fUnicodeSupport) hGlobal = GetClipboardData (CF_UNICODETEXT); else @@ -256,13 +231,13 @@ winClipboardFlushXEvents (HWND hwnd, if (fUnicodeSupport) { iConvertDataLen = WideCharToMultiByte (CP_UTF8, - 0, - (LPCWSTR)pszGlobalData, - -1, - NULL, - 0, - NULL, - NULL); + 0, + (LPCWSTR)pszGlobalData, + -1, + NULL, + 0, + NULL, + NULL); /* NOTE: iConvertDataLen includes space for null terminator */ pszConvertData = (char *) malloc (iConvertDataLen); WideCharToMultiByte (CP_UTF8, @@ -283,14 +258,14 @@ winClipboardFlushXEvents (HWND hwnd, /* Convert DOS string to UNIX string */ winClipboardDOStoUNIX (pszConvertData, strlen (pszConvertData)); - /* Setup our text list */ + /* Setup our text list */ pszTextList[0] = pszConvertData; - pszTextList[1] = NULL; - - /* Initialize the text property */ - xtpText.value = NULL; - - /* Create the text property from the text list */ + pszTextList[1] = NULL; + + /* Initialize the text property */ + xtpText.value = NULL; + + /* Create the text property from the text list */ if (fUnicodeSupport) { iReturn = Xutf8TextListToTextProperty (pDisplay, @@ -307,26 +282,26 @@ winClipboardFlushXEvents (HWND hwnd, xiccesStyle, &xtpText); } - if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) - { - ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) + { + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " "X*TextListToTextProperty failed: %d\n", - iReturn); - exit(1); - } - + iReturn); + pthread_exit (NULL); + } + /* Free the converted string */ free (pszConvertData); /* Copy the clipboard text to the requesting window */ - iReturn = XChangeProperty (pDisplay, - event.xselectionrequest.requestor, - event.xselectionrequest.property, - event.xselectionrequest.target, - 8, - PropModeReplace, - xtpText.value, - xtpText.nitems); + iReturn = XChangeProperty (pDisplay, + event.xselectionrequest.requestor, + event.xselectionrequest.property, + event.xselectionrequest.target, + 8, + PropModeReplace, + xtpText.value, + xtpText.nitems); if (iReturn == BadAlloc || iReturn == BadAtom || iReturn == BadMatch || iReturn == BadValue || iReturn == BadWindow) @@ -343,8 +318,8 @@ winClipboardFlushXEvents (HWND hwnd, CloseClipboard (); /* Clean up */ - XFree (xtpText.value); - xtpText.value = NULL; + XFree (xtpText.value); + xtpText.value = NULL; /* Setup selection notify event */ eventSelection.type = SelectionNotify; @@ -369,7 +344,7 @@ winClipboardFlushXEvents (HWND hwnd, pthread_exit (NULL); } break; - + /* * SelectionNotify @@ -377,7 +352,7 @@ winClipboardFlushXEvents (HWND hwnd, case SelectionNotify: #if 0 - ErrorF ("SelectionNotify\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify\n"); #endif { char *pszAtomName; @@ -391,86 +366,86 @@ winClipboardFlushXEvents (HWND hwnd, XFree (pszAtomName); } -#if 0 /* - * TEMP: Bail if selection is anything other than CLIPBOARD + * Request conversion of UTF8 and CompoundText targets. */ - - if (event.xselection.selection != atomClipboard) - break; -#endif - - /* - * - * What are we doing here? - * - */ - if (event.xselection.property == None) + if (event.xselection.property == None) + { + if (event.xselection.target == XA_STRING) { - if(event.xselection.target == XA_STRING) - { #if 0 - ErrorF ("winClipboardFlushXEvents - SelectionNotify - " - "XA_STRING\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XA_STRING\n"); #endif - return fReturn; - } - else if (event.xselection.target == atomUTF8String) - { - ErrorF ("winClipboardFlushXEvents - SelectionNotify " - "UTF8\n"); - iReturn = XConvertSelection (pDisplay, - event.xselection.selection, - XA_STRING, - atomLocalProperty, - iWindow, - CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - SelectionNotify " - "- XConvertSelection () failed\n"); - pthread_exit (NULL); - } - return fReturn; - } - else if (event.xselection.target == atomCompoundText) - { - ErrorF ("winClipboardFlushXEvents - SelectionNotify " - "CompoundText\n"); - iReturn = XConvertSelection (pDisplay, - event.xselection.selection, - atomUTF8String, - atomLocalProperty, - iWindow, - CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - SelectionNotify " - "- XConvertSelection () failed\n"); - pthread_exit (NULL); - } - return fReturn; - } - else - { - ErrorF ("winClipboardFlushXEvents - Unknown format\n"); - return fReturn; - } + return FALSE; } + else if (event.xselection.target == atomUTF8String) + { +#if 0 + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "Requesting conversion of UTF8 target.\n"); +#endif + iReturn = XConvertSelection (pDisplay, + event.xselection.selection, + XA_STRING, + atomLocalProperty, + iWindow, + CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XConvertSelection () failed\n"); + pthread_exit (NULL); + } + + /* Process the ConvertSelection event */ + XFlush (pDisplay); + return FALSE; + } + else if (event.xselection.target == atomCompoundText) + { +#if 0 + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "Requesting conversion of CompoundText target.\n"); +#endif + iReturn = XConvertSelection (pDisplay, + event.xselection.selection, + atomUTF8String, + atomLocalProperty, + iWindow, + CurrentTime); + if (iReturn == BadAtom || iReturn == BadWindow) + { + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XConvertSelection () failed\n"); + pthread_exit (NULL); + } + + /* Process the ConvertSelection event */ + XFlush (pDisplay); + return FALSE; + } + else + { + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "Unknown format. Cannot request conversion.\n"); + return FALSE; + } + } /* Retrieve the size of the stored data */ - iReturn = XGetWindowProperty (pDisplay, - iWindow, - atomLocalProperty, - 0, - 0, /* Don't get data, just size */ - False, - AnyPropertyType, - &xtpText.encoding, - &xtpText.format, - &xtpText.nitems, - &ulReturnBytesLeft, - &xtpText.value); + iReturn = XGetWindowProperty (pDisplay, + iWindow, + atomLocalProperty, + 0, + 0, /* Don't get data, just size */ + False, + AnyPropertyType, + &xtpText.encoding, + &xtpText.format, + &xtpText.nitems, + &ulReturnBytesLeft, + &xtpText.value); if (iReturn != Success) { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " @@ -479,23 +454,23 @@ winClipboardFlushXEvents (HWND hwnd, } #if 0 - ErrorF ("SelectionNotify - returned data %d left %d\n", - xtpText.nitems, ulReturnBytesLeft); + ErrorF ("SelectionNotify - returned data %d left %d\n", + xtpText.nitems, ulReturnBytesLeft); #endif /* Request the selection data */ - iReturn = XGetWindowProperty (pDisplay, - iWindow, - atomLocalProperty, - 0, - ulReturnBytesLeft, - False, - AnyPropertyType, - &xtpText.encoding, - &xtpText.format, - &xtpText.nitems, - &ulReturnBytesLeft, - &xtpText.value); + iReturn = XGetWindowProperty (pDisplay, + iWindow, + atomLocalProperty, + 0, + ulReturnBytesLeft, + False, + AnyPropertyType, + &xtpText.encoding, + &xtpText.format, + &xtpText.nitems, + &ulReturnBytesLeft, + &xtpText.value); if (iReturn != Success) { ErrorF ("winClipboardFlushXEvents - SelectionNotify - " @@ -516,7 +491,7 @@ winClipboardFlushXEvents (HWND hwnd, pszAtomName = NULL; } #endif - + if (fUnicodeSupport) { /* Convert the text property to a text list */ @@ -528,9 +503,9 @@ winClipboardFlushXEvents (HWND hwnd, else { iReturn = XmbTextPropertyToTextList (pDisplay, - &xtpText, - &ppszTextList, - &iCount); + &xtpText, + &ppszTextList, + &iCount); } if (iReturn == Success || iReturn > 0) { @@ -544,7 +519,7 @@ winClipboardFlushXEvents (HWND hwnd, pszReturnData = malloc (iReturnDataLen + 1); pszReturnData[0] = '\0'; for (i = 0; i < iCount; i++) - { + { strcat (pszReturnData, ppszTextList[i]); } } @@ -561,23 +536,26 @@ winClipboardFlushXEvents (HWND hwnd, switch (iReturn) { case XNoMemory: - ErrorF ("winClipboardFlushXEvents - SelectionNotify - XNoMemory\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XNoMemory\n"); break; case XConverterNotFound: - ErrorF ("winClipboardFlushXEvents - SelectionNotify - XConverterNotFound\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XConverterNotFound\n"); break; default: - ErrorF ("winClipboardFlushXEvents - SelectionNotify - Unknown Error\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "Unknown Error\n"); break; } pszReturnData = malloc (1); pszReturnData[0] = '\0'; - } - - /* Free the data returned from XGetWindowProperty */ - XFreeStringList (ppszTextList); - XFree (xtpText.value); - + } + + /* Free the data returned from XGetWindowProperty */ + XFreeStringList (ppszTextList); + XFree (xtpText.value); + /* Convert the X clipboard string to DOS format */ winClipboardUNIXtoDOS (&pszReturnData, strlen (pszReturnData)); @@ -590,11 +568,11 @@ winClipboardFlushXEvents (HWND hwnd, -1, NULL, 0); - + /* Allocate memory for the Unicode string */ pwszUnicodeStr = (wchar_t*) malloc (sizeof (wchar_t) * (iUnicodeLen + 1)); - + /* Do the actual conversion */ MultiByteToWideChar (CP_UTF8, 0, @@ -609,22 +587,6 @@ winClipboardFlushXEvents (HWND hwnd, iConvertDataLen = strlen (pszConvertData) + 1; } - /* Access the Windows clipboard */ - if (!OpenClipboard (hwnd)) - { - ErrorF ("winClipboardFlushXEvents - OpenClipboard () failed: " - "%08x\n", GetLastError ()); - pthread_exit (NULL); - } - - /* Take ownership of the Window clipboard */ - if (!EmptyClipboard ()) - { - ErrorF ("winClipboardFlushXEvents - EmptyClipboard () failed: " - "%08x\n", GetLastError ()); - pthread_exit (NULL); - } - /* Allocate global memory for the X clipboard data */ if (fUnicodeSupport) hGlobal = GlobalAlloc (GMEM_MOVEABLE, @@ -669,78 +631,14 @@ winClipboardFlushXEvents (HWND hwnd, if (fUnicodeSupport) SetClipboardData (CF_UNICODETEXT, hGlobal); else - SetClipboardData (CF_TEXT, hGlobal); + SetClipboardData (CF_TEXT, hGlobal); /* * NOTE: Do not try to free pszGlobalData, it is owned by * Windows after the call to SetClipboardData (). */ - - /* Release the clipboard */ - if (!CloseClipboard ()) - { - ErrorF ("winClipboardFlushXEvents - CloseClipboard () failed: " - "%08x\n", - GetLastError ()); - pthread_exit (NULL); - } - - /* Reassert ownership of the selection */ - iReturn = XSetSelectionOwner (pDisplay, - event.xselection.selection, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - char *pszAtomName = NULL; - - pszAtomName = XGetAtomName (pDisplay, - event.xselection.selection); - ErrorF ("winClipboardFlushXEvents - SelectionNotify - " - "Could not reassert ownership of selection ATOM: %s\n", - pszAtomName); - XFree (pszAtomName); - pszAtomName = NULL; - pthread_exit (NULL); - } - else - { -#if 0 - char *pszAtomName = NULL; - - pszAtomName = XGetAtomName (pDisplay, - event.xselection.selection); - ErrorF ("SelectionNotify - Reasserted ownership of ATOM: %s\n", - pszAtomName); - XFree (pszAtomName); - pszAtomName = NULL; -#endif - } -#if 0 - /* Reassert ownership of the CLIPBOARD */ - iReturn = XSetSelectionOwner (pDisplay, - atomClipboard, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow) - { - ErrorF ("winClipboardFlushXEvents - Could not reassert " - "ownership of selection\n"); - pthread_exit (NULL); - } -#endif break; -#if 0 - case CreateNotify: - ErrorF ("FlushXEvents - CreateNotify parent: %ld\twindow: %ld\n", - event.xcreatewindow.parent, event.xcreatewindow.window); - break; - - case DestroyNotify: - ErrorF ("FlushXEvents - DestroyNotify window: %ld\tevent: %ld\n", - event.xdestroywindow.window, event.xdestroywindow.event); - break; -#endif - default: break; } diff --git a/hw/xwin/wincmap.c b/hw/xwin/wincmap.c index ddf162feb..081f59811 100644 --- a/hw/xwin/wincmap.c +++ b/hw/xwin/wincmap.c @@ -35,6 +35,14 @@ #include "win.h" +/* + * References to external symbols + */ + +extern int g_iCmapPrivateIndex; +extern int g_iScreenPrivateIndex; + + /* See Porting Layer Definition - p. 30 */ /* * Walk the list of installed colormaps, filling the pmaps list diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c index 4b6d63d86..be06f7f4c 100644 --- a/hw/xwin/winconfig.c +++ b/hw/xwin/winconfig.c @@ -265,7 +265,6 @@ winConfigKeyboard (DeviceIntPtr pDevice) g_winInfo.xkb.options = NULL; # endif /* PC98 */ -#ifdef XKB /* * Query the windows autorepeat settings and change the xserver defaults. * If XKB is disabled then windows handles the autorepeat and the special @@ -273,7 +272,7 @@ winConfigKeyboard (DeviceIntPtr pDevice) */ { int kbd_delay; - DWORD kbd_speed; + DWORD kbd_speed; if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &kbd_delay, 0) && SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &kbd_speed, 0)) { @@ -282,7 +281,7 @@ winConfigKeyboard (DeviceIntPtr pDevice) case 0: g_winInfo.keyboard.delay = 250; break; case 1: g_winInfo.keyboard.delay = 500; break; case 2: g_winInfo.keyboard.delay = 750; break; - default: + default: case 3: g_winInfo.keyboard.delay = 1000; break; } g_winInfo.keyboard.rate = max(1,kbd_speed); @@ -290,7 +289,6 @@ winConfigKeyboard (DeviceIntPtr pDevice) g_winInfo.keyboard.delay, g_winInfo.keyboard.rate); } } -#endif keyboardType = GetKeyboardType (0); diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c index e7c3ba7e7..4fc7d3cda 100644 --- a/hw/xwin/wincursor.c +++ b/hw/xwin/wincursor.c @@ -34,6 +34,14 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iScreenPrivateIndex; + + miPointerScreenFuncRec g_winPointerCursorFuncs = { winCursorOffScreen, diff --git a/hw/xwin/winfillsp.c b/hw/xwin/winfillsp.c index 1b7f3c0ca..7f1cd8719 100644 --- a/hw/xwin/winfillsp.c +++ b/hw/xwin/winfillsp.c @@ -32,6 +32,16 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iPixmapPrivateIndex; +extern int g_iGCPrivateIndex; +extern int g_copyROP[]; + + extern void ROP16(HDC hdc, int rop); #define TRANSLATE_COLOR(color) \ diff --git a/hw/xwin/wingc.c b/hw/xwin/wingc.c index a4e2a53cb..fe1e42d3c 100644 --- a/hw/xwin/wingc.c +++ b/hw/xwin/wingc.c @@ -30,6 +30,16 @@ /* $XFree86: xc/programs/Xserver/hw/xwin/wingc.c,v 1.11 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" + + +/* + * References to external symbols + */ + +extern int g_iScreenPrivateIndex; +extern int g_iGCPrivateIndex; + + void winPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, int dx, int dy, int xOrg, int yOrg); diff --git a/hw/xwin/wingetsp.c b/hw/xwin/wingetsp.c index 49ba7f2fb..ecb6e1cba 100644 --- a/hw/xwin/wingetsp.c +++ b/hw/xwin/wingetsp.c @@ -32,6 +32,15 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iScreenPrivateIndex; +extern int g_iPixmapPrivateIndex; + + /* See Porting Layer Definition - p. 55 */ void winGetSpansNativeGDI (DrawablePtr pDrawable, diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c new file mode 100644 index 000000000..44f794eae --- /dev/null +++ b/hw/xwin/winglobals.c @@ -0,0 +1,92 @@ +/* + *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. + * + *Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + *"Software"), to deal in the Software without restriction, including + *without limitation the rights to use, copy, modify, merge, publish, + *distribute, sublicense, and/or sell copies of the Software, and to + *permit persons to whom the Software is furnished to do so, subject to + *the following conditions: + * + *The above copyright notice and this permission notice shall be + *included in all copies or substantial portions of the Software. + * + *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR + *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *Except as contained in this notice, the name of Harold L Hunt II + *shall not be used in advertising or otherwise to promote the sale, use + *or other dealings in this Software without prior written authorization + *from Harold L Hunt II. + * + * Authors: Harold L Hunt II + */ + +#include "win.h" + + +/* + * General global variables + */ + +int g_iNumScreens = 0; +winScreenInfo g_ScreenInfo[MAXSCREENS]; +int g_iLastScreen = -1; +int g_fdMessageQueue = WIN_FD_INVALID; +int g_iScreenPrivateIndex = -1; +int g_iCmapPrivateIndex = -1; +int g_iGCPrivateIndex = -1; +int g_iPixmapPrivateIndex = -1; +int g_iWindowPrivateIndex = -1; +unsigned long g_ulServerGeneration = 0; +Bool g_fInitializedDefaultScreens = FALSE; +FILE *g_pfLog = NULL; +DWORD g_dwEnginesSupported = 0; +HINSTANCE g_hInstance = 0; +HWND g_hDlgDepthChange = NULL; +HWND g_hDlgExit = NULL; +Bool g_fCalledSetLocale = FALSE; +const char * g_pszQueryHost = NULL; +Bool g_fUnicodeClipboard = TRUE; +Bool g_fXdmcpEnabled = FALSE; +Bool g_fClipboardLaunched = FALSE; + + +/* + * Global variables for dynamically loaded libraries and + * their function pointers + */ + +HMODULE g_hmodDirectDraw = NULL; +FARPROC g_fpDirectDrawCreate = NULL; +FARPROC g_fpDirectDrawCreateClipper = NULL; + +HMODULE g_hmodCommonControls = NULL; +FARPROC g_fpTrackMouseEvent = (FARPROC) (void (*)())NoopDDA; + + +/* + * Wrapped DIX functions + */ +winDispatchProcPtr winProcEstablishConnectionOrig = NULL; +winDispatchProcPtr winProcQueryTreeOrig = NULL; +winDispatchProcPtr winProcSetSelectionOwnerOrig = NULL; + + +/* + * Re-initialize global variables that are invalidated + * by a server reset. + */ + +void +winInitializeGlobals () +{ + g_fCalledSetLocale = FALSE; + g_fClipboardLaunched = FALSE; +} diff --git a/hw/xwin/winmisc.c b/hw/xwin/winmisc.c index ea8303ea9..f2dbadc86 100644 --- a/hw/xwin/winmisc.c +++ b/hw/xwin/winmisc.c @@ -32,6 +32,13 @@ #include "win.h" +/* + * References to external symbols + */ + +extern int g_iScreenPrivateIndex; + + /* See Porting Layer Definition - p. 33 */ /* * Called by clients, returns the best size for a cursor, tile, or diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index 188485178..ed87019eb 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -115,7 +115,6 @@ typedef struct _XMsgProcArgRec { extern char *display; extern void ErrorF (const char* /*f*/, ...); extern Bool g_fCalledSetLocale; -extern Bool g_fCalledXInitThreads; /* @@ -144,16 +143,22 @@ static void* winMultiWindowWMProc (void* pArg); static int -winMultiWindowWMErrorHandler (Display *pDisp, XErrorEvent *e); +winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr); + +static int +winMutliWindowWMIOErrorHandler (Display *pDisplay); static void * winMultiWindowXMsgProc (void *pArg); -static void -winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg); +static int +winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr); static int -winMutliWindowWMIOErrorHandler (Display *pDisplay); +winMutliWindowXMsgProcIOErrorHandler (Display *pDisplay); + +static void +winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg); /* @@ -161,7 +166,8 @@ winMutliWindowWMIOErrorHandler (Display *pDisplay); */ static int g_nQueueSize; -static jmp_buf g_jmpEntry; +static jmp_buf g_jmpWMEntry; +static jmp_buf g_jmpXMsgProcEntry; static Bool g_shutdown = FALSE; @@ -684,49 +690,9 @@ winMultiWindowWMProc (void *pArg) } -/* - * winMultiWindowWMErrorHandler - Our application specific error handler - */ - -static int -winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) -{ - char pszErrorMsg[100]; - - if (pErr->request_code == X_ChangeWindowAttributes - && pErr->error_code == BadAccess) - { - ErrorF ("winMultiWindowWMErrorHandler - ChangeWindowAttributes " - "BadAccess.\n"); -#if 0 - pthread_exit (NULL); -#endif - return 0; - } - - XGetErrorText (pDisplay, - pErr->error_code, - pszErrorMsg, - sizeof (pszErrorMsg)); - ErrorF ("winMultiWindowWMErrorHandler - ERROR: %s\n", pszErrorMsg); - - if (pErr->error_code == BadWindow - || pErr->error_code == BadMatch - || pErr->error_code == BadDrawable) - { -#if 0 - pthread_exit (NULL); -#endif - return 0; - } - - pthread_exit (NULL); - return 0; -} - /* - * + * X message procedure */ static void * @@ -765,27 +731,40 @@ winMultiWindowXMsgProc (void *pArg) ErrorF ("winMultiWindowXMsgProc - pthread_mutex_lock () returned.\n"); - /* Only call XInitThreads once for the whole process */ - if (!g_fCalledXInitThreads) + /* Allow multiple threads to access Xlib */ + if (XInitThreads () == 0) { - /* Allow multiple threads to access Xlib */ - if (XInitThreads () == 0) - { - ErrorF ("winMultiWindowXMsgProc - XInitThreads () failed.\n"); - pthread_exit (NULL); - } - - /* Flag that XInitThreads has been called */ - g_fCalledXInitThreads = TRUE; - - ErrorF ("winMultiWindowXMsgProc - XInitThreads () returned.\n"); + ErrorF ("winMultiWindowXMsgProc - XInitThreads () failed.\n"); + pthread_exit (NULL); } - + /* Release the server started mutex */ pthread_mutex_unlock (pProcArg->ppmServerStarted); ErrorF ("winMultiWindowXMsgProc - pthread_mutex_unlock () returned.\n"); + /* Set jump point for IO Error exits */ + iReturn = setjmp (g_jmpXMsgProcEntry); + + /* Check if we should continue operations */ + if (iReturn != WIN_JMP_ERROR_IO + && iReturn != WIN_JMP_OKAY) + { + /* setjmp returned an unknown value, exit */ + ErrorF ("winInitMultiWindowXMsgProc - setjmp returned: %d exiting\n", + iReturn); + pthread_exit (NULL); + } + else if (iReturn == WIN_JMP_ERROR_IO) + { + ErrorF ("winInitMultiWindowXMsgProc - Caught IO Error, shutting down\n"); + pthread_exit (NULL); + } + + /* Install our error handler */ + XSetErrorHandler (winMultiWindowXMsgProcErrorHandler); + XSetIOErrorHandler (winMutliWindowXMsgProcIOErrorHandler); + /* Setup the display connection string x */ snprintf (pszDisplay, 512, "127.0.0.1:%s.%d", display, (int)pProcArg->dwScreen); @@ -793,6 +772,7 @@ winMultiWindowXMsgProc (void *pArg) /* Print the display connection string */ ErrorF ("winMultiWindowXMsgProc - DISPLAY=%s\n", pszDisplay); + /* Initialize retry count */ iRetries = 0; /* Open the X display */ @@ -824,10 +804,6 @@ winMultiWindowXMsgProc (void *pArg) ErrorF ("winMultiWindowXMsgProc - XOpenDisplay () returned and " "successfully opened the display.\n"); - - /* Install our error handler */ - XSetErrorHandler (winMultiWindowWMErrorHandler); - XSetIOErrorHandler (winMutliWindowWMIOErrorHandler); XSelectInput (pProcArg->pDisplay, RootWindow(pProcArg->pDisplay, pProcArg->dwScreen), @@ -976,7 +952,7 @@ winInitWM (void **ppWMInfo, /* - * winInitMultiWindowWM - + * Window manager thread - setup */ static void @@ -1030,20 +1006,11 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) /* Flag that we have called setlocale */ g_fCalledSetLocale = TRUE; - /* Only call XInitThreads once for the whole process */ - if (!g_fCalledXInitThreads) + /* Allow multiple threads to access Xlib */ + if (XInitThreads () == 0) { - /* Allow multiple threads to access Xlib */ - if (XInitThreads () == 0) - { - ErrorF ("winInitMultiWindowWM - XInitThreads () failed.\n"); - pthread_exit (NULL); - } - - /* Flag that XInitThreads has been called */ - g_fCalledXInitThreads = TRUE; - - ErrorF ("winInitMultiWindowWM - XInitThreads () returned.\n"); + ErrorF ("winInitMultiWindowWM - XInitThreads () failed.\n"); + pthread_exit (NULL); } /* Release the server started mutex */ @@ -1052,7 +1019,7 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) ErrorF ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n"); /* Set jump point for IO Error exits */ - iReturn = setjmp (g_jmpEntry); + iReturn = setjmp (g_jmpWMEntry); /* Check if we should continue operations */ if (iReturn != WIN_JMP_ERROR_IO @@ -1063,17 +1030,16 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) iReturn); pthread_exit (NULL); } - else if (g_shutdown) - { - /* Shutting down, the X server severed out connection! */ - ErrorF ("winInitMultiWindowWM - Detected shutdown in progress\n"); - pthread_exit (NULL); - } else if (iReturn == WIN_JMP_ERROR_IO) { - ErrorF ("winInitMultiWindowWM - setjmp returned WIN_JMP_ERROR_IO\n"); + ErrorF ("winInitMultiWindowWM - Caught IO Error, shutting down\n"); + pthread_exit (NULL); } + /* Install our error handler */ + XSetErrorHandler (winMultiWindowWMErrorHandler); + XSetIOErrorHandler (winMutliWindowWMIOErrorHandler); + /* Setup the display connection string x */ snprintf (pszDisplay, 512, @@ -1114,9 +1080,6 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) ErrorF ("winInitMultiWindowWM - XOpenDisplay () returned and " "successfully opened the display.\n"); - /* Install our error handler */ - XSetErrorHandler (winMultiWindowWMErrorHandler); - XSetIOErrorHandler (winMutliWindowWMIOErrorHandler); /* Create some atoms */ pWMInfo->atmWmProtos = XInternAtom (pWMInfo->pDisplay, @@ -1154,7 +1117,34 @@ winSendMessageToWM (void *pWMInfo, winWMMessagePtr pMsg) /* - * winMutliWindowWMIOErrorHandler - Our application specific IO error handler + * Window manager error handler + */ + +static int +winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) +{ + char pszErrorMsg[100]; + + if (pErr->request_code == X_ChangeWindowAttributes + && pErr->error_code == BadAccess) + { + ErrorF ("winMultiWindowWMErrorHandler - ChangeWindowAttributes " + "BadAccess.\n"); + return 0; + } + + XGetErrorText (pDisplay, + pErr->error_code, + pszErrorMsg, + sizeof (pszErrorMsg)); + ErrorF ("winMultiWindowWMErrorHandler - ERROR: %s\n", pszErrorMsg); + + return 0; +} + + +/* + * Window manager IO error handler */ static int @@ -1163,7 +1153,42 @@ winMutliWindowWMIOErrorHandler (Display *pDisplay) printf ("\nwinMutliWindowWMIOErrorHandler!\n\n"); /* Restart at the main entry point */ - longjmp (g_jmpEntry, WIN_JMP_ERROR_IO); + longjmp (g_jmpWMEntry, WIN_JMP_ERROR_IO); + + return 0; +} + + +/* + * X message procedure error handler + */ + +static int +winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr) +{ + char pszErrorMsg[100]; + + XGetErrorText (pDisplay, + pErr->error_code, + pszErrorMsg, + sizeof (pszErrorMsg)); + ErrorF ("winMultiWindowXMsgProcErrorHandler - ERROR: %s\n", pszErrorMsg); + + return 0; +} + + +/* + * X message procedure IO error handler + */ + +static int +winMutliWindowXMsgProcIOErrorHandler (Display *pDisplay) +{ + printf ("\nwinMutliWindowXMsgProcIOErrorHandler!\n\n"); + + /* Restart at the main entry point */ + longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO); return 0; } diff --git a/hw/xwin/winpixmap.c b/hw/xwin/winpixmap.c index 43ade059b..22c0fbdcc 100644 --- a/hw/xwin/winpixmap.c +++ b/hw/xwin/winpixmap.c @@ -32,6 +32,14 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iPixmapPrivateIndex; + + /* See Porting Layer Definition - p. 34 */ /* See mfb/mfbpixmap.c - mfbCreatePixmap() */ PixmapPtr diff --git a/hw/xwin/winprocarg.c b/hw/xwin/winprocarg.c new file mode 100755 index 000000000..642282040 --- /dev/null +++ b/hw/xwin/winprocarg.c @@ -0,0 +1,1017 @@ +/* + +Copyright 1993, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from The Open Group. + +*/ + +#include "win.h" +#include "winconfig.h" +#include "winprefs.h" + + +/* + * References to external symbols + */ + +extern int g_iNumScreens; +extern winScreenInfo g_ScreenInfo[]; +extern int g_iLastScreen; +extern Bool g_fInitializedDefaultScreens; +extern FILE *g_pfLog; +extern Bool g_fUnicodeClipboard; +extern Bool g_fXdmcpEnabled; + + +/* + * Function prototypes + */ + +#ifdef DDXOSVERRORF +void OsVendorVErrorF (const char *pszFormat, va_list va_args); +#endif + + +/* + * Process arguments on the command line + */ + +void +winInitializeDefaultScreens (void) +{ + int i; + DWORD dwWidth, dwHeight; + + /* Bail out early if default screens have already been initialized */ + + if (g_fInitializedDefaultScreens) + return; + + /* Zero the memory used for storing the screen info */ + ZeroMemory (g_ScreenInfo, MAXSCREENS * sizeof (winScreenInfo)); + + /* Get default width and height */ + /* + * NOTE: These defaults will cause the window to cover only + * the primary monitor in the case that we have multiple monitors. + */ + dwWidth = GetSystemMetrics (SM_CXSCREEN); + dwHeight = GetSystemMetrics (SM_CYSCREEN); + + ErrorF ("winInitializeDefaultScreens - w %ld h %ld\n", dwWidth, dwHeight); + + /* Set a default DPI, if no parameter was passed */ + if (monitorResolution == 0) + monitorResolution = WIN_DEFAULT_DPI; + + for (i = 0; i < MAXSCREENS; ++i) + { + g_ScreenInfo[i].dwScreen = i; + g_ScreenInfo[i].dwWidth = dwWidth; + g_ScreenInfo[i].dwHeight = dwHeight; + g_ScreenInfo[i].dwUserWidth = dwWidth; + g_ScreenInfo[i].dwUserHeight = dwHeight; + g_ScreenInfo[i].fUserGaveHeightAndWidth + = WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH; + g_ScreenInfo[i].dwBPP = WIN_DEFAULT_BPP; + g_ScreenInfo[i].dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES; + g_ScreenInfo[i].fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO; + g_ScreenInfo[i].dwRefreshRate = WIN_DEFAULT_REFRESH; + g_ScreenInfo[i].pfb = NULL; + g_ScreenInfo[i].fFullScreen = FALSE; + g_ScreenInfo[i].fDecoration = TRUE; + g_ScreenInfo[i].fRootless = FALSE; + g_ScreenInfo[i].fMultiWindow = FALSE; + g_ScreenInfo[i].fMultipleMonitors = FALSE; + g_ScreenInfo[i].fClipboard = FALSE; + g_ScreenInfo[i].fLessPointer = FALSE; + g_ScreenInfo[i].fScrollbars = FALSE; + g_ScreenInfo[i].fNoTrayIcon = FALSE; + g_ScreenInfo[i].iE3BTimeout = WIN_E3B_OFF; + g_ScreenInfo[i].dwWidth_mm = (dwWidth / WIN_DEFAULT_DPI) + * 25.4; + g_ScreenInfo[i].dwHeight_mm = (dwHeight / WIN_DEFAULT_DPI) + * 25.4; + g_ScreenInfo[i].fUseWinKillKey = WIN_DEFAULT_WIN_KILL; + g_ScreenInfo[i].fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL; + g_ScreenInfo[i].fIgnoreInput = FALSE; + g_ScreenInfo[i].fExplicitScreen = FALSE; + } + + /* Signal that the default screens have been initialized */ + g_fInitializedDefaultScreens = TRUE; + + ErrorF ("winInitializeDefaultScreens - Returning\n"); +} + + +/* See Porting Layer Definition - p. 57 */ +/* + * INPUT + * argv: pointer to an array of null-terminated strings, one for + * each token in the X Server command line; the first token + * is 'XWin.exe', or similar. + * argc: a count of the number of tokens stored in argv. + * i: a zero-based index into argv indicating the current token being + * processed. + * + * OUTPUT + * return: return the number of tokens processed correctly. + * + * NOTE + * When looking for n tokens, check that i + n is less than argc. Or, + * you may check if i is greater than or equal to argc, in which case + * you should display the UseMsg () and return 0. + */ + +/* Check if enough arguments are given for the option */ +#define CHECK_ARGS(count) if (i + count >= argc) { UseMsg (); return 0; } + +/* Compare the current option with the string. */ +#define IS_OPTION(name) (strcmp (argv[i], name) == 0) + +int +ddxProcessArgument (int argc, char *argv[], int i) +{ + static Bool s_fBeenHere = FALSE; + + /* Initialize once */ + if (!s_fBeenHere) + { +#ifdef DDXOSVERRORF + /* + * This initialises our hook into VErrorF () for catching log messages + * that are generated before OsInit () is called. + */ + OsVendorVErrorFProc = OsVendorVErrorF; + + /* Open log file if not yet open */ + if (g_pfLog == NULL) + g_pfLog = fopen (WIN_LOG_FNAME, "w"); +#endif + + s_fBeenHere = TRUE; + + /* + * Initialize default screen settings. We have to do this before + * OsVendorInit () gets called, otherwise we will overwrite + * settings changed by parameters such as -fullscreen, etc. + */ + ErrorF ("ddxProcessArgument - Initializing default screens\n"); + winInitializeDefaultScreens (); + } + +#if CYGDEBUG + ErrorF ("ddxProcessArgument - arg: %s\n", argv[i]); +#endif + + /* + * Look for the '-screen scr_num [width height]' argument + */ + if (strcmp (argv[i], "-screen") == 0) + { + int iArgsProcessed = 1; + int nScreenNum; + int iWidth, iHeight; + +#if CYGDEBUG + ErrorF ("ddxProcessArgument - screen - argc: %d i: %d\n", + argc, i); +#endif + + /* Display the usage message if the argument is malformed */ + if (i + 1 >= argc) + { + return 0; + } + + /* Grab screen number */ + nScreenNum = atoi (argv[i + 1]); + + /* Validate the specified screen number */ + if (nScreenNum < 0 || nScreenNum >= MAXSCREENS) + { + ErrorF ("ddxProcessArgument - screen - Invalid screen number %d\n", + nScreenNum); + UseMsg (); + return 0; + } + + /* Look for 'WxD' or 'W D' */ + if (i + 2 < argc + && 2 == sscanf (argv[i + 2], "%dx%d", + (int *) &iWidth, + (int *) &iHeight)) + { + ErrorF ("ddxProcessArgument - screen - Found ``WxD'' arg\n"); + iArgsProcessed = 3; + g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE; + g_ScreenInfo[nScreenNum].dwWidth = iWidth; + g_ScreenInfo[nScreenNum].dwHeight = iHeight; + g_ScreenInfo[nScreenNum].dwUserWidth = iWidth; + g_ScreenInfo[nScreenNum].dwUserHeight = iHeight; + } + else if (i + 3 < argc + && 1 == sscanf (argv[i + 2], "%d", + (int *) &iWidth) + && 1 == sscanf (argv[i + 3], "%d", + (int *) &iHeight)) + { + ErrorF ("ddxProcessArgument - screen - Found ``W D'' arg\n"); + iArgsProcessed = 4; + g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE; + g_ScreenInfo[nScreenNum].dwWidth = iWidth; + g_ScreenInfo[nScreenNum].dwHeight = iHeight; + g_ScreenInfo[nScreenNum].dwUserWidth = iWidth; + g_ScreenInfo[nScreenNum].dwUserHeight = iHeight; + } + else + { + ErrorF ("ddxProcessArgument - screen - Did not find size arg. " + "dwWidth: %ld dwHeight: %ld\n", + g_ScreenInfo[nScreenNum].dwWidth, + g_ScreenInfo[nScreenNum].dwHeight); + iArgsProcessed = 2; + g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE; + } + + /* Calculate the screen width and height in millimeters */ + if (g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth) + { + g_ScreenInfo[nScreenNum].dwWidth_mm + = (g_ScreenInfo[nScreenNum].dwWidth + / monitorResolution) * 25.4; + g_ScreenInfo[nScreenNum].dwHeight_mm + = (g_ScreenInfo[nScreenNum].dwHeight + / monitorResolution) * 25.4; + } + + /* Flag that this screen was explicity specified by the user */ + g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE; + + /* + * Keep track of the last screen number seen, as parameters seen + * before a screen number apply to all screens, whereas parameters + * seen after a screen number apply to that screen number only. + */ + g_iLastScreen = nScreenNum; + + /* Keep a count of the number of screens */ + ++g_iNumScreens; + + return iArgsProcessed; + } + + /* + * Look for the '-engine n' argument + */ + if (strcmp (argv[i], "-engine") == 0) + { + DWORD dwEngine = 0; + CARD8 c8OnBits = 0; + + /* Display the usage message if the argument is malformed */ + if (++i >= argc) + { + UseMsg (); + return 0; + } + + /* Grab the argument */ + dwEngine = atoi (argv[i]); + + /* Count the one bits in the engine argument */ + c8OnBits = winCountBits (dwEngine); + + /* Argument should only have a single bit on */ + if (c8OnBits != 1) + { + UseMsg (); + return 0; + } + + /* Is this parameter attached to a screen or global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].dwEnginePreferred = dwEngine; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].dwEnginePreferred = dwEngine; + } + + /* Indicate that we have processed the argument */ + return 2; + } + + /* + * Look for the '-fullscreen' argument + */ + if (strcmp (argv[i], "-fullscreen") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fFullScreen = TRUE; + + /* + * No scrollbars in fullscreen mode. Later, we may want to have + * a fullscreen with a bigger virtual screen? + */ + g_ScreenInfo[j].fScrollbars = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fFullScreen = TRUE; + + /* + * No scrollbars in fullscreen mode. Later, we may want to have + * a fullscreen with a bigger virtual screen? + */ + g_ScreenInfo[g_iLastScreen].fScrollbars = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-lesspointer' argument + */ + if (strcmp (argv[i], "-lesspointer") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fLessPointer = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fLessPointer = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-nodecoration' argument + */ + if (strcmp (argv[i], "-nodecoration") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fDecoration = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fDecoration = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-rootless' argument + */ + if (strcmp (argv[i], "-rootless") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fRootless = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fRootless = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-multiwindow' argument + */ + if (strcmp (argv[i], "-multiwindow") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fMultiWindow = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fMultiWindow = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-multiplemonitors' argument + */ + if (strcmp (argv[i], "-multiplemonitors") == 0 + || strcmp (argv[i], "-multimonitors") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fMultipleMonitors = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-scrollbars' argument + */ + if (strcmp (argv[i], "-scrollbars") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + /* No scrollbar in fullscreen mode */ + if (!g_ScreenInfo[j].fFullScreen) + g_ScreenInfo[j].fScrollbars = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + if (!g_ScreenInfo[g_iLastScreen].fFullScreen) + { + /* No scrollbar in fullscreen mode */ + g_ScreenInfo[g_iLastScreen].fScrollbars = TRUE; + } + } + + /* Indicate that we have processed this argument */ + return 1; + } + + + + /* + * Look for the '-clipboard' argument + */ + if (strcmp (argv[i], "-clipboard") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fClipboard = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fClipboard = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-ignoreinput' argument + */ + if (strcmp (argv[i], "-ignoreinput") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fIgnoreInput = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fIgnoreInput = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-emulate3buttons' argument + */ + if (strcmp (argv[i], "-emulate3buttons") == 0) + { + int iArgsProcessed = 1; + int iE3BTimeout = WIN_DEFAULT_E3B_TIME; + + /* Grab the optional timeout value */ + if (i + 1 < argc + && 1 == sscanf (argv[i + 1], "%d", + &iE3BTimeout)) + { + /* Indicate that we have processed the next argument */ + iArgsProcessed++; + } + else + { + /* + * sscanf () won't modify iE3BTimeout if it doesn't find + * the specified format; however, I want to be explicit + * about setting the default timeout in such cases to + * prevent some programs (me) from getting confused. + */ + iE3BTimeout = WIN_DEFAULT_E3B_TIME; + } + + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].iE3BTimeout = iE3BTimeout; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].iE3BTimeout = iE3BTimeout; + } + + /* Indicate that we have processed this argument */ + return iArgsProcessed; + } + + /* + * Look for the '-depth n' argument + */ + if (strcmp (argv[i], "-depth") == 0) + { + DWORD dwBPP = 0; + + /* Display the usage message if the argument is malformed */ + if (++i >= argc) + { + UseMsg (); + return 0; + } + + /* Grab the argument */ + dwBPP = atoi (argv[i]); + + /* Is this parameter attached to a screen or global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].dwBPP = dwBPP; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].dwBPP = dwBPP; + } + + /* Indicate that we have processed the argument */ + return 2; + } + + /* + * Look for the '-refresh n' argument + */ + if (strcmp (argv[i], "-refresh") == 0) + { + DWORD dwRefreshRate = 0; + + /* Display the usage message if the argument is malformed */ + if (++i >= argc) + { + UseMsg (); + return 0; + } + + /* Grab the argument */ + dwRefreshRate = atoi (argv[i]); + + /* Is this parameter attached to a screen or global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].dwRefreshRate = dwRefreshRate; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].dwRefreshRate = dwRefreshRate; + } + + /* Indicate that we have processed the argument */ + return 2; + } + + /* + * Look for the '-clipupdates num_boxes' argument + */ + if (strcmp (argv[i], "-clipupdates") == 0) + { + DWORD dwNumBoxes = 0; + + /* Display the usage message if the argument is malformed */ + if (++i >= argc) + { + UseMsg (); + return 0; + } + + /* Grab the argument */ + dwNumBoxes = atoi (argv[i]); + + /* Is this parameter attached to a screen or global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].dwClipUpdatesNBoxes = dwNumBoxes; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].dwClipUpdatesNBoxes = dwNumBoxes; + } + + /* Indicate that we have processed the argument */ + return 2; + } + + /* + * Look for the '-emulatepseudo' argument + */ + if (strcmp (argv[i], "-emulatepseudo") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fEmulatePseudo = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fEmulatePseudo = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-nowinkill' argument + */ + if (strcmp (argv[i], "-nowinkill") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fUseWinKillKey = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fUseWinKillKey = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-winkill' argument + */ + if (strcmp (argv[i], "-winkill") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fUseWinKillKey = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fUseWinKillKey = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-nounixkill' argument + */ + if (strcmp (argv[i], "-nounixkill") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fUseUnixKillKey = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-unixkill' argument + */ + if (strcmp (argv[i], "-unixkill") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fUseUnixKillKey = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-notrayicon' argument + */ + if (strcmp (argv[i], "-notrayicon") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fNoTrayIcon = TRUE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fNoTrayIcon = TRUE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-trayicon' argument + */ + if (strcmp (argv[i], "-trayicon") == 0) + { + /* Is this parameter attached to a screen or is it global? */ + if (-1 == g_iLastScreen) + { + int j; + + /* Parameter is for all screens */ + for (j = 0; j < MAXSCREENS; j++) + { + g_ScreenInfo[j].fNoTrayIcon = FALSE; + } + } + else + { + /* Parameter is for a single screen */ + g_ScreenInfo[g_iLastScreen].fNoTrayIcon = FALSE; + } + + /* Indicate that we have processed this argument */ + return 1; + } + + /* + * Look for the '-fp' argument + */ + if (IS_OPTION ("-fp")) + { + CHECK_ARGS (1); + g_cmdline.fontPath = argv[++i]; + return 0; /* Let DIX parse this again */ + } + + /* + * Look for the '-co' argument + */ + if (IS_OPTION ("-co")) + { + CHECK_ARGS (1); + g_cmdline.rgbPath = argv[++i]; + return 0; /* Let DIX parse this again */ + } + + /* + * Look for the '-query' argument + */ + if (IS_OPTION ("-query")) + { + CHECK_ARGS (1); + g_fXdmcpEnabled = TRUE; + g_pszQueryHost = argv[++i]; + return 0; /* Let DIX parse this again */ + } + + /* + * Look for the '-indirect' or '-broadcast' arguments + */ + if (IS_OPTION ("-indirect") + || IS_OPTION ("-broadcast")) + { + g_fXdmcpEnabled = TRUE; + return 0; /* Let DIX parse this again */ + } + + /* + * Look for the '-xf86config' argument + */ + if (IS_OPTION ("-xf86config")) + { + CHECK_ARGS (1); + g_cmdline.configFile = argv[++i]; + return 2; + } + + /* + * Look for the '-keyboard' argument + */ + if (IS_OPTION ("-keyboard")) + { + CHECK_ARGS (1); + g_cmdline.keyboard = argv[++i]; + return 2; + } + + /* + * Look for the '-nounicodeclipboard' argument + */ + if (IS_OPTION ("-nounicodeclipboard")) + { + g_fUnicodeClipboard = FALSE; + /* Indicate that we have processed the argument */ + return 1; + } + +#ifdef XKB + /* + * Look for the '-kb' argument + */ + if (IS_OPTION ("-kb")) + { + g_cmdline.noXkbExtension = TRUE; + return 0; /* Let DIX parse this again */ + } +#endif + + return 0; +} diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c index ceb358552..73ae83d58 100644 --- a/hw/xwin/winscrinit.c +++ b/hw/xwin/winscrinit.c @@ -63,6 +63,15 @@ winWin32RootlessProcs = { }; +/* + * References to external symbols + */ + +extern winScreenInfo g_ScreenInfo[]; +extern miPointerScreenFuncRec g_winPointerCursorFuncs; +extern int g_iScreenPrivateIndex; + + /* * Determine what type of screen we are initializing * and call the appropriate procedure to intiailize @@ -78,8 +87,8 @@ winScreenInit (int index, winPrivScreenPtr pScreenPriv; HDC hdc; -#if CYGDEBUG - ErrorF ("winScreenInit - dwWidth: %d dwHeight: %d\n", +#if CYGDEBUG || YES + ErrorF ("winScreenInit - dwWidth: %ld dwHeight: %ld\n", pScreenInfo->dwWidth, pScreenInfo->dwHeight); #endif @@ -552,7 +561,7 @@ winFinishScreenInitFB (int index, pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; - /* Create a mutex for modules in seperate threads to wait for */ + /* Create a mutex for modules in separate threads to wait for */ iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL); if (iReturn != 0) { @@ -561,7 +570,7 @@ winFinishScreenInitFB (int index, return FALSE; } - /* Own the mutex for modules in seperate threads */ + /* Own the mutex for modules in separate threads */ iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted); if (iReturn != 0) { @@ -595,21 +604,6 @@ winFinishScreenInitFB (int index, return FALSE; } -#if CYGDEBUG || YES - if (pScreenInfo->fClipboard) - ErrorF ("winFinishScreenInitFB - Calling winInitClipboard.\n"); -#endif - - /* Initialize the clipboard manager */ - if (pScreenInfo->fClipboard - && !winInitClipboard (&pScreenPriv->ptClipboardProc, - &pScreenPriv->pmServerStarted, - pScreenInfo->dwScreen)) - { - ErrorF ("winFinishScreenInitFB - winClipboardInit () failed.\n"); - return FALSE; - } - /* Tell the server that we are enabled */ pScreenPriv->fEnabled = TRUE; diff --git a/hw/xwin/winsetsp.c b/hw/xwin/winsetsp.c index c0340e47b..e313a14c4 100644 --- a/hw/xwin/winsetsp.c +++ b/hw/xwin/winsetsp.c @@ -32,6 +32,16 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iPixmapPrivateIndex; +extern int g_iGCPrivateIndex; +extern int g_copyROP[]; + + /* See Porting Layer Definition - p. 55 */ void winSetSpansNativeGDI (DrawablePtr pDrawable, diff --git a/hw/xwin/winwakeup.c b/hw/xwin/winwakeup.c index 5e9fd8326..a480215e2 100644 --- a/hw/xwin/winwakeup.c +++ b/hw/xwin/winwakeup.c @@ -34,6 +34,15 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern HWND g_hDlgDepthChange; +extern HWND g_hDlgExit; + + /* See Porting Layer Definition - p. 7 */ void winWakeupHandler (int nScreen, diff --git a/hw/xwin/winwindow.c b/hw/xwin/winwindow.c index 378465bc4..6a4eb8a79 100644 --- a/hw/xwin/winwindow.c +++ b/hw/xwin/winwindow.c @@ -32,6 +32,15 @@ #include "win.h" + +/* + * References to external symbols + */ + +extern int g_iScreenPrivateIndex; +extern int g_iWindowPrivateIndex; + + /* * Prototypes for local functions */ diff --git a/hw/xwin/winwndproc.c b/hw/xwin/winwndproc.c index b1b59e9bb..2f384890b 100644 --- a/hw/xwin/winwndproc.c +++ b/hw/xwin/winwndproc.c @@ -1051,15 +1051,16 @@ winWindowProc (HWND hwnd, UINT message, default: /* It's probably one of the custom menus... */ return HandleCustomWM_COMMAND (0, LOWORD (wParam)); - } break; case WM_ENDSESSION: case WM_GIVEUP: - /* Tell X that we are giving up */ - winDeinitClipboard (); - winDeinitMultiWindowWM (); + /* Tell X that we are giving up */ + if (s_pScreenInfo->fClipboard) + winDeinitClipboard (); + if (s_pScreenInfo->fMultiWindow) + winDeinitMultiWindowWM (); GiveUp (0); return 0;