diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index bc2c75e1f..88e5603e5 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -32,6 +32,7 @@ from The Open Group. #include "winmsg.h" #include "winconfig.h" #include "winprefs.h" +#include "Xlocale.h" /* @@ -117,8 +118,6 @@ extern Bool g_fClipboard; void OsVendorReset () { - int i; - ErrorF ("OsVendorReset - Hello\n"); /* Close down clipboard resources */ @@ -454,6 +453,16 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) if (g_fXdmcpEnabled) winGenerateAuthorization (); + /* Perform some one time initialization */ + if (1 == serverGeneration) + { + /* + * setlocale applies to all threads in the current process. + * Apply locale specified in LANG environment variable. + */ + setlocale (LC_ALL, ""); + } + #if CYGDEBUG || YES winErrorFVerb (2, "InitOutput - Returning.\n"); #endif diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c index a700e7a35..a411b2998 100644 --- a/hw/xwin/winclipboardthread.c +++ b/hw/xwin/winclipboardthread.c @@ -44,7 +44,6 @@ * References to external symbols */ -extern Bool g_fCalledSetLocale; extern Bool g_fUnicodeClipboard; extern unsigned long serverGeneration; extern unsigned int g_uiAuthDataLen; @@ -102,28 +101,6 @@ winClipboardProc () /* Save the Unicode support flag in a global */ g_fUnicodeSupport = fUnicodeSupport; - /* Set the current locale? What does this do? */ - if (!g_fCalledSetLocale) - { - ErrorF ("winClipboardProc - Calling setlocale ()\n"); - if (!setlocale (LC_ALL, "")) - { - ErrorF ("winClipboardProc - setlocale () error\n"); - pthread_exit (NULL); - } - ErrorF ("winClipboardProc - setlocale () returned\n"); - - /* See if X supports the current locale */ - if (XSupportsLocale () == False) - { - ErrorF ("winClipboardProc - Locale not supported by X\n"); - pthread_exit (NULL); - } - } - - /* Flag that we have called setlocale */ - g_fCalledSetLocale = TRUE; - /* Allow multiple threads to access Xlib */ if (XInitThreads () == 0) { @@ -131,7 +108,12 @@ winClipboardProc () pthread_exit (NULL); } - ErrorF ("winClipboardProc - XInitThreads () returned.\n"); + /* See if X supports the current locale */ + if (XSupportsLocale () == False) + { + ErrorF ("winClipboardProc - Locale not supported by X. Exiting.\n"); + pthread_exit (NULL); + } /* Set jump point for Error exits */ iReturn = setjmp (g_jmpEntry); diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c index c14b7d8e8..6a2357352 100755 --- a/hw/xwin/winclipboardwrappers.c +++ b/hw/xwin/winclipboardwrappers.c @@ -279,10 +279,12 @@ winProcEstablishConnection (ClientPtr client) int winProcSetSelectionOwner (ClientPtr client) { + int i; DrawablePtr pDrawable; WindowPtr pWindow = None; Bool fOwnedToNotOwned = FALSE; - static Window g_iOwners[CLIP_NUM_SELECTIONS] = {None}; + static Window s_iOwners[CLIP_NUM_SELECTIONS] = {None}; + static unsigned long s_ulServerGeneration = 0; REQUEST(xSetSelectionOwnerReq); REQUEST_SIZE_MATCH(xSetSelectionOwnerReq); @@ -291,6 +293,17 @@ winProcSetSelectionOwner (ClientPtr client) ErrorF ("winProcSetSelectionOwner - Hello.\n"); #endif + /* Watch for server reset */ + if (s_ulServerGeneration != serverGeneration) + { + /* Save new generation number */ + s_ulServerGeneration = serverGeneration; + + /* Initialize static variables */ + for (i = 0; i < CLIP_NUM_SELECTIONS; ++i) + s_iOwners[i] = None; + } + /* Abort if clipboard not completely initialized yet */ if (!g_fClipboardStarted) { @@ -319,37 +332,37 @@ winProcSetSelectionOwner (ClientPtr client) { /* Look for owned -> not owned transition */ if (None == stuff->window - && None != g_iOwners[CLIP_OWN_PRIMARY]) + && None != s_iOwners[CLIP_OWN_PRIMARY]) { fOwnedToNotOwned = TRUE; /* Adjust last owned selection */ - if (None != g_iOwners[CLIP_OWN_CLIPBOARD]) + if (None != s_iOwners[CLIP_OWN_CLIPBOARD]) g_atomLastOwnedSelection = MakeAtom ("CLIPBOARD", 9, FALSE); else g_atomLastOwnedSelection = None; } /* Save new selection owner or None */ - g_iOwners[CLIP_OWN_PRIMARY] = stuff->window; + s_iOwners[CLIP_OWN_PRIMARY] = stuff->window; } else if (MakeAtom ("CLIPBOARD", 9, FALSE) == stuff->selection) { /* Look for owned -> not owned transition */ if (None == stuff->window - && None != g_iOwners[CLIP_OWN_CLIPBOARD]) + && None != s_iOwners[CLIP_OWN_CLIPBOARD]) { fOwnedToNotOwned = TRUE; /* Adjust last owned selection */ - if (None != g_iOwners[CLIP_OWN_PRIMARY]) + if (None != s_iOwners[CLIP_OWN_PRIMARY]) g_atomLastOwnedSelection = XA_PRIMARY; else g_atomLastOwnedSelection = None; } /* Save new selection owner or None */ - g_iOwners[CLIP_OWN_CLIPBOARD] = stuff->window; + s_iOwners[CLIP_OWN_CLIPBOARD] = stuff->window; } else goto winProcSetSelectionOwner_Done; @@ -363,8 +376,8 @@ winProcSetSelectionOwner (ClientPtr client) */ if (None == stuff->window && g_iClipboardWindow != client->lastDrawableID - && None == g_iOwners[CLIP_OWN_PRIMARY] - && None == g_iOwners[CLIP_OWN_CLIPBOARD] + && None == s_iOwners[CLIP_OWN_PRIMARY] + && None == s_iOwners[CLIP_OWN_CLIPBOARD] && fOwnedToNotOwned && g_hwndClipboard != NULL && g_hwndClipboard == GetClipboardOwner ()) diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c index 4e8c9b798..71dddc043 100644 --- a/hw/xwin/winglobals.c +++ b/hw/xwin/winglobals.c @@ -51,7 +51,6 @@ 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_fClipboard = FALSE; @@ -91,9 +90,6 @@ HWND g_hwndClipboard; void *g_pClipboardDisplay; Window g_iClipboardWindow; Atom g_atomLastOwnedSelection; -#if 0 -Window g_iClipboardOwner[CLIP_NUM_SELECTIONS]; -#endif /* @@ -104,6 +100,5 @@ Window g_iClipboardOwner[CLIP_NUM_SELECTIONS]; void winInitializeGlobals () { - g_fCalledSetLocale = FALSE; g_fClipboardLaunched = FALSE; } diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c index 9eca558b8..118b10d0d 100644 --- a/hw/xwin/winmultiwindowwindow.c +++ b/hw/xwin/winmultiwindowwindow.c @@ -60,11 +60,6 @@ winUpdateWindowsWindow (WindowPtr pWin); static void winFindWindow (pointer value, XID id, pointer cdata); -#if 0 -static void -winRestackXWindow (WindowPtr pWin, int smode); -#endif - /* * Constant defines @@ -756,37 +751,6 @@ winFindWindow (pointer value, XID id, pointer cdata) } -#if 0 -/* - * winRestackXWindow - - */ - -static void -winRestackXWindow (WindowPtr pWin, int smode) -{ - XID *vlist = malloc(sizeof(unsigned long)); - - if (vlist == NULL) - { - ErrorF ("winRestackXWindow - malloc () failed\n"); - return; - } - - if (pWin == NULL) - { - ErrorF ("winRestackXWindow - NULL window\n"); - free(vlist); - return; - } - - *((unsigned long*)vlist) = smode; - ConfigureWindow (pWin, CWStackMode, vlist, wClient(pWin)); - - free(vlist); -} -#endif - - /* * winReorderWindowsMultiWindow - */ diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index ed87019eb..7ef8c4b2c 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -84,6 +84,7 @@ typedef struct _WMMsgQueueRec { struct _WMMsgNodeRec *pTail; pthread_mutex_t pmMutex; pthread_cond_t pcNotEmpty; + int nQueueSize; } WMMsgQueueRec, *WMMsgQueuePtr; typedef struct _WMInfo { @@ -101,9 +102,9 @@ typedef struct _WMProcArgRec { } WMProcArgRec, *WMProcArgPtr; typedef struct _XMsgProcArgRec { - Display *pDisplay; - DWORD dwScreen; - WMInfoPtr pWMInfo; + Display *pDisplay; + DWORD dwScreen; + WMInfoPtr pWMInfo; pthread_mutex_t *ppmServerStarted; } XMsgProcArgRec, *XMsgProcArgPtr; @@ -114,7 +115,6 @@ typedef struct _XMsgProcArgRec { extern char *display; extern void ErrorF (const char* /*f*/, ...); -extern Bool g_fCalledSetLocale; /* @@ -165,13 +165,11 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg); * Local globals */ -static int g_nQueueSize; static jmp_buf g_jmpWMEntry; static jmp_buf g_jmpXMsgProcEntry; static Bool g_shutdown = FALSE; - /* * PushMessage - Push a message onto the queue */ @@ -225,7 +223,7 @@ PushMessage (WMMsgQueuePtr pQueue, WMMsgNodePtr pNode) #endif /* Increase the count of elements in the queue by one */ - ++g_nQueueSize; + ++(pQueue->nQueueSize); /* Release the queue mutex */ pthread_mutex_unlock (&pQueue->pmMutex); @@ -285,10 +283,10 @@ PopMessage (WMMsgQueuePtr pQueue, WMInfoPtr pWMInfo) } /* Drop the number of elements in the queue by one */ - --g_nQueueSize; + --(pQueue->nQueueSize); #if CYGMULTIWINDOW_DEBUG - ErrorF ("Queue Size %d %d\n", g_nQueueSize, QueueSize(pQueue)); + ErrorF ("Queue Size %d %d\n", pQueue->nQueueSize, QueueSize(pQueue)); #endif /* Release the queue mutex */ @@ -339,10 +337,11 @@ InitQueue (WMMsgQueuePtr pQueue) pQueue->pTail = NULL; /* There are no elements initially */ - g_nQueueSize = 0; + pQueue->nQueueSize = 0; #if CYGMULTIWINDOW_DEBUG - ErrorF ("InitQueue - Queue Size %d %d\n", g_nQueueSize, QueueSize(pQueue)); + ErrorF ("InitQueue - Queue Size %d %d\n", pQueue->nQueueSize, + QueueSize(pQueue)); #endif ErrorF ("InitQueue - Calling pthread_mutex_init\n"); @@ -421,7 +420,6 @@ GetWindowName (Display *pDisplay, Window iWin, char **ppName) #endif } - #if CYGMULTIWINDOW_DEBUG ErrorF ("GetWindowName - Returning\n"); #endif @@ -538,7 +536,7 @@ winMultiWindowWMProc (void *pArg) { /* Bail if PopMessage returns without a message */ /* NOTE: Remember that PopMessage is a blocking function. */ - ErrorF ("winMultiWindowWMProc - Queue is Empty?\n"); + ErrorF ("winMultiWindowWMProc - Queue is Empty? Exiting.\n"); pthread_exit (NULL); } @@ -737,7 +735,15 @@ winMultiWindowXMsgProc (void *pArg) ErrorF ("winMultiWindowXMsgProc - XInitThreads () failed.\n"); pthread_exit (NULL); } - + + /* See if X supports the current locale */ + if (XSupportsLocale () == False) + { + ErrorF ("winMultiWindowXMsgProc - Locale not supported by X. " + "Exiting.\n"); + pthread_exit (NULL); + } + /* Release the server started mutex */ pthread_mutex_unlock (pProcArg->ppmServerStarted); @@ -797,7 +803,7 @@ winMultiWindowXMsgProc (void *pArg) /* Make sure that the display opened */ if (pProcArg->pDisplay == NULL) { - ErrorF ("winMultiWindowXMsgProcwinInitMultiWindowWM - " + ErrorF ("winMultiWindowXMsgProc - " "Failed opening the display, giving up.\n\f"); pthread_exit (NULL); } @@ -905,10 +911,15 @@ winInitWM (void **ppWMInfo, /* Bail if the input parameters are bad */ if (pArg == NULL || pWMInfo == NULL) { - ErrorF ("winInitWM - malloc fail.\n"); + ErrorF ("winInitWM - malloc failed.\n"); return FALSE; } + /* Zero the allocated memory */ + ZeroMemory (pArg, sizeof (WMProcArgRec)); + ZeroMemory (pWMInfo, sizeof (WMInfoRec)); + ZeroMemory (pXMsgArg, sizeof (XMsgProcArgRec)); + /* Set a return pointer to the Window Manager info structure */ *ppWMInfo = pWMInfo; @@ -984,28 +995,6 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) ErrorF ("winInitMultiWindowWM - pthread_mutex_lock () returned.\n"); - /* Set the current locale? What does this do? */ - if (!g_fCalledSetLocale) - { - ErrorF ("winInitMultiWindowWM - Calling setlocale ()\n"); - if (!setlocale (LC_ALL, "")) - { - ErrorF ("winInitMultiWindowWM - setlocale () error\n"); - pthread_exit (NULL); - } - ErrorF ("winInitMultiWindowWM - setlocale () returned\n"); - - /* See if X supports the current locale */ - if (XSupportsLocale () == False) - { - ErrorF ("winInitMultiWindowWM - Locale not supported by X\n"); - pthread_exit (NULL); - } - } - - /* Flag that we have called setlocale */ - g_fCalledSetLocale = TRUE; - /* Allow multiple threads to access Xlib */ if (XInitThreads () == 0) { @@ -1013,6 +1002,13 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) pthread_exit (NULL); } + /* See if X supports the current locale */ + if (XSupportsLocale () == False) + { + ErrorF ("winInitMultiWindowWM - Locale not supported by X. Exiting.\n"); + pthread_exit (NULL); + } + /* Release the server started mutex */ pthread_mutex_unlock (pProcArg->ppmServerStarted);