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)
This commit is contained in:
Harold L Hunt II 2004-01-08 05:10:33 +00:00
parent 8fec9f9cbc
commit cab39b481c
28 changed files with 2744 additions and 610 deletions

View file

@ -30,8 +30,33 @@
#include "win.h" #include "win.h"
#include "../../Xext/xf86miscproc.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 */ /* Called from dix/devices.c */
@ -90,6 +115,21 @@ InitInput (int argc, char *argv[])
ErrorF ("InitInput\n"); ErrorF ("InitInput\n");
#endif #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); pMouse = AddInputDevice (winMouseProc, TRUE);
pKeyboard = AddInputDevice (winKeybdProc, TRUE); pKeyboard = AddInputDevice (winKeybdProc, TRUE);
@ -118,34 +158,6 @@ InitInput (int argc, char *argv[])
AddEnabledDevice (g_fdMessageQueue); 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 #if CYGDEBUG
ErrorF ("InitInput - returning\n"); ErrorF ("InitInput - returning\n");
#endif #endif

View file

@ -33,52 +33,47 @@ from The Open Group.
#include "winconfig.h" #include "winconfig.h"
#include "winprefs.h" #include "winprefs.h"
/* /*
* General global variables * References to external symbols
*/ */
int g_iNumScreens = 0; extern int g_iNumScreens;
winScreenInfo g_ScreenInfo[MAXSCREENS]; extern winScreenInfo g_ScreenInfo[];
int g_iLastScreen = -1; extern int g_iLastScreen;
int g_fdMessageQueue = WIN_FD_INVALID; extern Bool g_fInitializedDefaultScreens;
int g_iScreenPrivateIndex = -1; extern FILE *g_pfLog;
int g_iCmapPrivateIndex = -1; extern Bool g_fUnicodeClipboard;
int g_iGCPrivateIndex = -1; extern Bool g_fXdmcpEnabled;
int g_iPixmapPrivateIndex = -1; extern int g_iScreenPrivateIndex;
int g_iWindowPrivateIndex = -1; extern int g_fdMessageQueue;
unsigned long g_ulServerGeneration = 0; extern const char * g_pszQueryHost;
Bool g_fInitializedDefaultScreens = FALSE; extern HINSTANCE g_hInstance;
DWORD g_dwEnginesSupported = 0;
HINSTANCE g_hInstance = 0;
HWND g_hDlgDepthChange = NULL;
HWND g_hDlgExit = NULL;
Bool g_fCalledSetLocale = FALSE;
Bool g_fCalledXInitThreads = FALSE;
int g_iLogVerbose = 4; int g_iLogVerbose = 4;
char * g_pszLogFile = WIN_LOG_FNAME; char * g_pszLogFile = WIN_LOG_FNAME;
Bool g_fLogInited = FALSE; 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 * Function prototypes
* their function pointers
*/ */
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 #ifdef DDXOSVERRORF
void OsVendorVErrorF (const char *pszFormat, va_list va_args); void OsVendorVErrorF (const char *pszFormat, va_list va_args);
#endif #endif
#if defined(DDXOSRESET)
void OsVendorReset ();
#endif
void winInitializeDefaultScreens (void); void winInitializeDefaultScreens (void);
@ -109,6 +104,51 @@ static PixmapFormatRec g_PixmapFormats[] = {
const int NUMFORMATS = sizeof (g_PixmapFormats) / sizeof (g_PixmapFormats[0]); 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 void
winInitializeDefaultScreens (void) winInitializeDefaultScreens (void)
{ {
@ -246,6 +286,9 @@ AbortDDX (void)
void void
OsVendorInit (void) OsVendorInit (void)
{ {
/* Re-initialize global variables on server reset */
winInitializeGlobals ();
#ifdef DDXOSVERRORF #ifdef DDXOSVERRORF
if (!OsVendorVErrorFProc) if (!OsVendorVErrorFProc)
OsVendorVErrorFProc = OsVendorVErrorF; OsVendorVErrorFProc = OsVendorVErrorF;
@ -1234,10 +1277,21 @@ ddxProcessArgument (int argc, char *argv[], int i)
if (IS_OPTION ("-query")) if (IS_OPTION ("-query"))
{ {
CHECK_ARGS (1); CHECK_ARGS (1);
g_fXdmcpEnabled = TRUE;
g_pszQueryHost = argv[++i]; g_pszQueryHost = argv[++i];
return 0; /* Let DIX parse this again */ 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 * Look for the '-xf86config' argument
*/ */
@ -1409,8 +1463,13 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[])
} }
} }
/* Load preferences from XWinrc file */
LoadPreferences(); LoadPreferences();
/* Generate a cookie used by internal clients for authorization */
if (g_fXdmcpEnabled)
winGenerateAuthorization ();
#if CYGDEBUG || YES #if CYGDEBUG || YES
winErrorFVerb (2, "InitOutput - Returning.\n"); winErrorFVerb (2, "InitOutput - Returning.\n");
#endif #endif

View file

@ -52,6 +52,7 @@
#define WIN_EMULATE_PSEUDO_SUPPORT YES #define WIN_EMULATE_PSEUDO_SUPPORT YES
#define WIN_UPDATE_STATS NO #define WIN_UPDATE_STATS NO
/* Turn debug messages on or off */ /* Turn debug messages on or off */
#define CYGDEBUG NO #define CYGDEBUG NO
@ -311,6 +312,10 @@ typedef Bool (*winReleasePrimarySurfaceProcPtr)(ScreenPtr);
typedef Bool (*winFinishCreateWindowsWindowProcPtr)(WindowPtr pWin); typedef Bool (*winFinishCreateWindowsWindowProcPtr)(WindowPtr pWin);
/* Typedef for DIX wrapper functions */
typedef int (*winDispatchProcPtr) (ClientPtr);
/* /*
* GC (graphics context) privates * GC (graphics context) privates
*/ */
@ -441,12 +446,13 @@ typedef struct _winPrivScreenRec
/* Clipboard support */ /* Clipboard support */
pthread_t ptClipboardProc; pthread_t ptClipboardProc;
Bool fClipboardStarted;
#if 0 HWND hwndClipboard;
HWND hwndNextViewer; void *pClipboardDisplay;
void *display; Window iClipboardWindow;
int window; HWND hwndClipboardNextViewer;
#endif Bool fCBCInitialized;
Atom atomLastOwnedSelection;
/* Last width, height, and depth of the Windows display */ /* Last width, height, and depth of the Windows display */
DWORD dwLastWindowsWidth; DWORD dwLastWindowsWidth;
@ -736,6 +742,14 @@ Bool
winAllocateCmapPrivates (ColormapPtr pCmap); winAllocateCmapPrivates (ColormapPtr pCmap);
/*
* winauth.c
*/
Bool
winGenerateAuthorization ();
/* /*
* winblock.c * winblock.c
*/ */
@ -761,7 +775,13 @@ winPixmapToRegionNativeGDI (PixmapPtr pPix);
Bool Bool
winInitClipboard (pthread_t *ptClipboardProc, winInitClipboard (pthread_t *ptClipboardProc,
pthread_mutex_t *ppmServerStarted, Bool *pfClipboardStarted,
HWND *phwndClipboard,
void **ppClipboardDisplay,
Window *piClipboardWindow,
HWND *phwndClipboardNextViewer,
Bool *pfCBCInitialized,
Atom *patomLastOwnedSelection,
DWORD dwScreen); DWORD dwScreen);
/* /*
@ -944,6 +964,14 @@ winGetSpansNativeGDI (DrawablePtr pDrawable,
char *pDst); char *pDst);
/*
* winglobals.c
*/
void
winInitializeGlobals ();
/* /*
* winkeybd.c * winkeybd.c
*/ */

View file

@ -33,6 +33,17 @@
#include "win.h" #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 */ /* See Porting Layer Definition - p. 58 */
/* /*

127
hw/xwin/winauth.c Normal file
View file

@ -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;
}

View file

@ -31,6 +31,16 @@
#include "win.h" #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 */ /* See Porting Layer Definition - p. 6 */
void void
winBlockHandler (int nScreen, winBlockHandler (int nScreen,

View file

@ -65,10 +65,12 @@
#define WIN_CLIPBOARD_WINDOW_CLASS "xwinclip" #define WIN_CLIPBOARD_WINDOW_CLASS "xwinclip"
#define WIN_CLIPBOARD_WINDOW_TITLE "xwinclip" #define WIN_CLIPBOARD_WINDOW_TITLE "xwinclip"
#define WIN_MSG_QUEUE_FNAME "/dev/windows" #define WIN_MSG_QUEUE_FNAME "/dev/windows"
#define WIN_CONNECT_RETRIES 3 #define WIN_CONNECT_RETRIES 40
#define WIN_CONNECT_DELAY 4 #define WIN_CONNECT_DELAY 4
#define WIN_JMP_OKAY 0 #define WIN_JMP_OKAY 0
#define WIN_JMP_ERROR_IO 2 #define WIN_JMP_ERROR_IO 2
#define WIN_LOCAL_PROPERTY "CYGX_CUT_BUFFER"
/* /*
* Argument structure for Clipboard module main thread * Argument structure for Clipboard module main thread
@ -76,10 +78,29 @@
typedef struct _ClipboardProcArgRec { typedef struct _ClipboardProcArgRec {
DWORD dwScreen; DWORD dwScreen;
pthread_mutex_t *ppmServerStarted; Bool *pfClipboardStarted;
HWND *phwndClipboard;
void **ppClipboardDisplay;
Window *piClipboardWindow;
HWND *phwndClipboardNextViewer;
Bool *pfCBCInitialized;
Atom *patomLastOwnedSelection;
} ClipboardProcArgRec, *ClipboardProcArgPtr; } 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 * References to external symbols
*/ */
@ -94,11 +115,17 @@ extern void ErrorF (const char* /*f*/, ...);
Bool Bool
winInitClipboard (pthread_t *ptClipboardProc, winInitClipboard (pthread_t *ptClipboardProc,
pthread_mutex_t *ppmServerStarted, Bool *pfClipboardStarted,
HWND *phwndClipboard,
void **ppClipboardDisplay,
Window *piClipboardWindow,
HWND *phwndClipboardNextViewer,
Bool *pfCBCInitialized,
Atom *patomLastOwnedSelection,
DWORD dwScreen); DWORD dwScreen);
HWND HWND
winClipboardCreateMessagingWindow (void); winClipboardCreateMessagingWindow (ClipboardProcArgPtr pProcArg);
/* /*
@ -122,6 +149,7 @@ winClipboardProc (void *pArg);
void void
winDeinitClipboard (void); winDeinitClipboard (void);
/* /*
* winclipboardunicode.c * winclipboardunicode.c
*/ */
@ -148,12 +176,6 @@ winClipboardWindowProc (HWND hwnd, UINT message,
Bool Bool
winClipboardFlushXEvents (HWND hwnd, winClipboardFlushXEvents (HWND hwnd,
Atom atomClipboard,
Atom atomLocalProperty,
Atom atomUTF8String,
Atom atomCompoundText,
Atom atomTargets,
Atom atomDeleteWindow,
int iWindow, int iWindow,
Display *pDisplay, Display *pDisplay,
Bool fUnicodeSupport); Bool fUnicodeSupport);

View file

@ -29,8 +29,20 @@
*/ */
/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardinit.c,v 1.2 2003/07/29 21:25:16 dawes Exp $ */ /* $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" #include "winclipboard.h"
/*
* Local typedefs
*/
typedef int (*winDispatchProcPtr) (ClientPtr);
DISPATCH_PROC(winProcSetSelectionOwner);
extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
/* /*
* Intialize the Clipboard module * Intialize the Clipboard module
@ -38,7 +50,13 @@
Bool Bool
winInitClipboard (pthread_t *ptClipboardProc, winInitClipboard (pthread_t *ptClipboardProc,
pthread_mutex_t *ppmServerStarted, Bool *pfClipboardStarted,
HWND *phwndClipboard,
void **ppClipboardDisplay,
Window *piClipboardWindow,
HWND *phwndClipboardNextViewer,
Bool *pfCBCInitialized,
Atom *patomLastOwnedSelection,
DWORD dwScreen) DWORD dwScreen)
{ {
ClipboardProcArgPtr pArg; ClipboardProcArgPtr pArg;
@ -52,10 +70,23 @@ winInitClipboard (pthread_t *ptClipboardProc,
ErrorF ("winInitClipboard - malloc for ClipboardProcArgRec failed.\n"); ErrorF ("winInitClipboard - malloc for ClipboardProcArgRec failed.\n");
return FALSE; 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 */ /* Setup the argument structure for the thread function */
pArg->dwScreen = dwScreen; 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 */ /* Spawn a thread for the Clipboard module */
if (pthread_create (ptClipboardProc, NULL, winClipboardProc, pArg)) if (pthread_create (ptClipboardProc, NULL, winClipboardProc, pArg))
@ -74,10 +105,11 @@ winInitClipboard (pthread_t *ptClipboardProc,
*/ */
HWND HWND
winClipboardCreateMessagingWindow (void) winClipboardCreateMessagingWindow (ClipboardProcArgPtr pProcArg)
{ {
WNDCLASS wc; WNDCLASS wc;
HWND hwnd; HWND hwnd;
ClipboardWindowPropPtr pWindowProp = NULL;
/* Setup our window class */ /* Setup our window class */
wc.style = CS_HREDRAW | CS_VREDRAW; wc.style = CS_HREDRAW | CS_VREDRAW;
@ -92,6 +124,19 @@ winClipboardCreateMessagingWindow (void)
wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS; wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS;
RegisterClass (&wc); 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 */ /* Create the window */
hwnd = CreateWindowExA (0, /* Extended styles */ hwnd = CreateWindowExA (0, /* Extended styles */
WIN_CLIPBOARD_WINDOW_CLASS,/* Class name */ WIN_CLIPBOARD_WINDOW_CLASS,/* Class name */
@ -104,7 +149,7 @@ winClipboardCreateMessagingWindow (void)
(HWND) NULL, /* No parent or owner window */ (HWND) NULL, /* No parent or owner window */
(HMENU) NULL, /* No menu */ (HMENU) NULL, /* No menu */
GetModuleHandle (NULL),/* Instance handle */ GetModuleHandle (NULL),/* Instance handle */
NULL); /* ScreenPrivates */ pWindowProp); /* Creation data */
assert (hwnd != NULL); assert (hwnd != NULL);
/* I'm not sure, but we may need to call this to start message processing */ /* I'm not sure, but we may need to call this to start message processing */

View file

@ -30,13 +30,24 @@
/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardthread.c,v 1.3 2003/10/02 13:30:10 eich Exp $ */ /* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardthread.c,v 1.3 2003/10/02 13:30:10 eich Exp $ */
#include "winclipboard.h" #include "winclipboard.h"
#include "Xauth.h"
/*
* Constants
*/
#define AUTH_NAME "MIT-MAGIC-COOKIE-1"
/* /*
* References to external symbols * References to external symbols
*/ */
extern Bool g_fCalledSetLocale; extern Bool g_fCalledSetLocale;
extern Bool g_fUnicodeClipboard; 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 jmp_buf g_jmpEntry;
static Bool g_shutdown = FALSE; Bool g_fUnicodeSupport = FALSE;
/* /*
@ -66,8 +77,6 @@ void *
winClipboardProc (void *pArg) winClipboardProc (void *pArg)
{ {
Atom atomClipboard, atomClipboardManager; Atom atomClipboard, atomClipboardManager;
Atom atomLocalProperty, atomCompoundText;
Atom atomUTF8String, atomTargets;
int iReturn; int iReturn;
HWND hwnd = NULL; HWND hwnd = NULL;
int iConnectionNumber; int iConnectionNumber;
@ -76,7 +85,6 @@ winClipboardProc (void *pArg)
int iMaxDescriptor; int iMaxDescriptor;
Display *pDisplay; Display *pDisplay;
Window iWindow; Window iWindow;
Atom atomDeleteWindow;
Bool fReturn; Bool fReturn;
int iRetries; int iRetries;
Bool fUnicodeSupport; Bool fUnicodeSupport;
@ -92,22 +100,12 @@ winClipboardProc (void *pArg)
pthread_exit (NULL); 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? */ /* Do we have Unicode support? */
fUnicodeSupport = g_fUnicodeClipboard && winClipboardDetectUnicodeSupport (); fUnicodeSupport = g_fUnicodeClipboard && winClipboardDetectUnicodeSupport ();
/* Save the Unicode support flag in a global */
g_fUnicodeSupport = fUnicodeSupport;
/* Set the current locale? What does this do? */ /* Set the current locale? What does this do? */
if (!g_fCalledSetLocale) if (!g_fCalledSetLocale)
{ {
@ -139,11 +137,6 @@ winClipboardProc (void *pArg)
ErrorF ("winClipboardProc - XInitThreads () returned.\n"); 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 */ /* Set jump point for Error exits */
iReturn = setjmp (g_jmpEntry); iReturn = setjmp (g_jmpEntry);
@ -156,16 +149,22 @@ winClipboardProc (void *pArg)
iReturn); iReturn);
pthread_exit (NULL); 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) 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 */ /* Initialize retry count */
iRetries = 0; iRetries = 0;
@ -205,12 +204,12 @@ winClipboardProc (void *pArg)
pthread_exit (NULL); pthread_exit (NULL);
} }
/* Save the display in the screen privates */
*(pProcArg->ppClipboardDisplay) = pDisplay;
ErrorF ("winClipboardProc - XOpenDisplay () returned and " ErrorF ("winClipboardProc - XOpenDisplay () returned and "
"successfully opened the display.\n"); "successfully opened the display.\n");
/* Create Windows messaging window */
hwnd = winClipboardCreateMessagingWindow ();
/* Get our connection number */ /* Get our connection number */
iConnectionNumber = ConnectionNumber (pDisplay); iConnectionNumber = ConnectionNumber (pDisplay);
@ -234,6 +233,13 @@ winClipboardProc (void *pArg)
ErrorF ("winClipboardProc - XSelectInput generated BadWindow " ErrorF ("winClipboardProc - XSelectInput generated BadWindow "
"on RootWindow\n\n"); "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 */ /* Create a messaging window */
iWindow = XCreateSimpleWindow (pDisplay, iWindow = XCreateSimpleWindow (pDisplay,
DefaultRootWindow (pDisplay), DefaultRootWindow (pDisplay),
@ -244,27 +250,20 @@ winClipboardProc (void *pArg)
BlackPixel (pDisplay, 0)); BlackPixel (pDisplay, 0));
if (iWindow == 0) if (iWindow == 0)
{ {
ErrorF ("winClipboardProc - Could not create a window\n"); ErrorF ("winClipboardProc - Could not create an X window.\n");
pthread_exit (NULL); pthread_exit (NULL);
} }
/* This looks like our only hope for getting a message before shutdown */ /* Save the window in the screen privates */
/* Register for WM_DELETE_WINDOW message from window manager */ *(pProcArg->piClipboardWindow) = iWindow;
atomDeleteWindow = XInternAtom (pDisplay, "WM_DELETE_WINDOW", False);
XSetWMProtocols (pDisplay, iWindow, &atomDeleteWindow, 1);
/* Set error handler */ /* Create Windows messaging window */
XSetErrorHandler (winClipboardErrorHandler); hwnd = winClipboardCreateMessagingWindow (pProcArg);
XSetIOErrorHandler (winClipboardIOErrorHandler);
/* Save copy of HWND in screen privates */
/* Create an atom for CLIPBOARD_MANAGER */ *(pProcArg->phwndClipboard) = hwnd;
atomClipboardManager = XInternAtom (pDisplay, "CLIPBOARD_MANAGER", False);
if (atomClipboardManager == None)
{
ErrorF ("winClipboardProc - Could not create CLIPBOARD_MANAGER atom\n");
pthread_exit (NULL);
}
#if 0
/* Assert ownership of CLIPBOARD_MANAGER */ /* Assert ownership of CLIPBOARD_MANAGER */
iReturn = XSetSelectionOwner (pDisplay, atomClipboardManager, iReturn = XSetSelectionOwner (pDisplay, atomClipboardManager,
iWindow, CurrentTime); iWindow, CurrentTime);
@ -273,63 +272,28 @@ winClipboardProc (void *pArg)
ErrorF ("winClipboardProc - Could not set CLIPBOARD_MANAGER owner\n"); ErrorF ("winClipboardProc - Could not set CLIPBOARD_MANAGER owner\n");
pthread_exit (NULL); pthread_exit (NULL);
} }
#endif
/* Create an atom for CLIPBOARD */ /* Assert ownership of selections if Win32 clipboard is owned */
atomClipboard = XInternAtom (pDisplay, "CLIPBOARD", False); if (NULL != GetClipboardOwner ())
if (atomClipboard == None)
{ {
ErrorF ("winClipboardProc - Could not create CLIPBOARD atom\n"); /* PRIMARY */
pthread_exit (NULL); 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 */ /* CLIPBOARD */
iReturn = XSetSelectionOwner (pDisplay, atomClipboard, iReturn = XSetSelectionOwner (pDisplay, atomClipboard,
iWindow, CurrentTime); iWindow, CurrentTime);
if (iReturn == BadAtom || iReturn == BadWindow) if (iReturn == BadAtom || iReturn == BadWindow)
{ {
ErrorF ("winClipboardProc - Could not set CLIPBOARD owner\n"); ErrorF ("winClipboardProc - Could not set CLIPBOARD owner\n");
pthread_exit (NULL); 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);
} }
/* Pre-flush X events */ /* Pre-flush X events */
@ -339,12 +303,6 @@ winClipboardProc (void *pArg)
* already. * already.
*/ */
winClipboardFlushXEvents (hwnd, winClipboardFlushXEvents (hwnd,
atomClipboard,
atomLocalProperty,
atomUTF8String,
atomCompoundText,
atomTargets,
atomDeleteWindow,
iWindow, iWindow,
pDisplay, pDisplay,
fUnicodeSupport); fUnicodeSupport);
@ -353,6 +311,9 @@ winClipboardProc (void *pArg)
if (!winClipboardFlushWindowsMessageQueue (hwnd)) if (!winClipboardFlushWindowsMessageQueue (hwnd))
return 0; return 0;
/* Signal that the clipboard client has started */
*(pProcArg->pfClipboardStarted) = TRUE;
/* Loop for X events */ /* Loop for X events */
while (1) while (1)
{ {
@ -378,7 +339,7 @@ winClipboardProc (void *pArg)
"Bailing.\n", iReturn); "Bailing.\n", iReturn);
break; break;
} }
/* Branch on which descriptor became active */ /* Branch on which descriptor became active */
if (FD_ISSET (iConnectionNumber, &fdsRead)) if (FD_ISSET (iConnectionNumber, &fdsRead))
{ {
@ -390,19 +351,13 @@ winClipboardProc (void *pArg)
/* Process X events */ /* Process X events */
/* Exit when we see that server is shutting down */ /* Exit when we see that server is shutting down */
fReturn = winClipboardFlushXEvents (hwnd, fReturn = winClipboardFlushXEvents (hwnd,
atomClipboard,
atomLocalProperty,
atomUTF8String,
atomCompoundText,
atomTargets,
atomDeleteWindow,
iWindow, iWindow,
pDisplay, pDisplay,
fUnicodeSupport); fUnicodeSupport);
if (!fReturn) if (!fReturn)
{ {
ErrorF ("winClipboardProc - Caught WM_DELETE_WINDOW - " ErrorF ("winClipboardProc - winClipboardFlushXEvents "
"shutting down\n"); "trapped shutdown event, exiting main loop.\n");
break; break;
} }
} }
@ -414,14 +369,19 @@ winClipboardProc (void *pArg)
#if 0 #if 0
ErrorF ("winClipboardProc - Windows event ready\n"); ErrorF ("winClipboardProc - Windows event ready\n");
#endif #endif
/* Process Windows messages */ /* Process Windows messages */
if (!winClipboardFlushWindowsMessageQueue (hwnd)) 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)); sizeof (pszErrorMsg));
ErrorF ("winClipboardErrorHandler - ERROR: \n\t%s\n", pszErrorMsg); ErrorF ("winClipboardErrorHandler - ERROR: \n\t%s\n", pszErrorMsg);
#if 0
if (pErr->error_code == BadWindow if (pErr->error_code == BadWindow
|| pErr->error_code == BadMatch || pErr->error_code == BadMatch
|| pErr->error_code == BadDrawable) || pErr->error_code == BadDrawable)
{ {
#if 0
pthread_exit (NULL); pthread_exit (NULL);
#endif
} }
#if 0
pthread_exit (NULL); pthread_exit (NULL);
#endif #endif
@ -464,7 +422,7 @@ winClipboardErrorHandler (Display *pDisplay, XErrorEvent *pErr)
static int static int
winClipboardIOErrorHandler (Display *pDisplay) winClipboardIOErrorHandler (Display *pDisplay)
{ {
printf ("\nwinClipboardIOErrorHandler!\n\n"); ErrorF ("\nwinClipboardIOErrorHandler!\n\n");
/* Restart at the main entry point */ /* Restart at the main entry point */
longjmp (g_jmpEntry, WIN_JMP_ERROR_IO); longjmp (g_jmpEntry, WIN_JMP_ERROR_IO);
@ -478,8 +436,10 @@ winClipboardIOErrorHandler (Display *pDisplay)
*/ */
void void
winDeinitClipboard (void) winDeinitClipboard ()
{ {
ErrorF ("winDeinitClipboard - Noting shutdown in progress\n"); ErrorF ("winDeinitClipboard - Noting shutdown in progress\n");
g_shutdown = TRUE; #if 0
g_fShutdown = TRUE;
#endif
} }

View file

@ -32,6 +32,42 @@
#include "winclipboard.h" #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 * Process a given Windows message
*/ */
@ -40,18 +76,231 @@ LRESULT CALLBACK
winClipboardWindowProc (HWND hwnd, UINT message, winClipboardWindowProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam) WPARAM wParam, LPARAM lParam)
{ {
ClipboardWindowPropPtr pWindowProp = GetProp (hwnd,
WIN_CLIPBOARD_PROP);
/* Branch on message type */ /* Branch on message type */
switch (message) switch (message)
{ {
case WM_DESTROY: 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; return 0;
case WM_CREATE: case WM_CREATE:
#if 0 {
ErrorF ("WindowProc - WM_CREATE\n"); ErrorF ("winClipboardWindowProc - WM_CREATE\n");
#endif
/* 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; 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 */ /* Let Windows perform default processing for unhandled messages */

498
hw/xwin/winclipboardwrappers.c Executable file
View file

@ -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);
}

View file

@ -38,21 +38,10 @@
Bool Bool
winClipboardFlushXEvents (HWND hwnd, winClipboardFlushXEvents (HWND hwnd,
Atom atomClipboard,
Atom atomLocalProperty,
Atom atomUTF8String,
Atom atomCompoundText,
Atom atomTargets,
Atom atomDeleteWindow,
int iWindow, int iWindow,
Display *pDisplay, Display *pDisplay,
Bool fUnicodeSupport) Bool fUnicodeSupport)
{ {
#if 0
Atom atomReturnType;
int iReturnFormat;
unsigned long ulReturnItems;
#endif
XTextProperty xtpText; XTextProperty xtpText;
XEvent event; XEvent event;
XSelectionEvent eventSelection; XSelectionEvent eventSelection;
@ -72,6 +61,18 @@ winClipboardFlushXEvents (HWND hwnd,
int iUnicodeLen = 0; int iUnicodeLen = 0;
int iReturnDataLen = 0; int iReturnDataLen = 0;
int i; 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 */ /* Process all pending events */
while (XPending (pDisplay)) while (XPending (pDisplay))
@ -82,50 +83,24 @@ winClipboardFlushXEvents (HWND hwnd,
/* Branch on the event type */ /* Branch on the event type */
switch (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 * SelectionRequest
*/ */
case SelectionRequest: case SelectionRequest:
#if 0 #if 0
char *pszAtomName = NULL {
char *pszAtomName = NULL;
ErrorF ("SelectionRequest - target %d\n",
event.xselectionrequest.target); ErrorF ("SelectionRequest - target %d\n",
event.xselectionrequest.target);
pszAtomName = XGetAtomName (pDisplay,
event.xselectionrequest.target); pszAtomName = XGetAtomName (pDisplay,
ErrorF ("SelectionRequest - Target atom name %s\n", pszAtomName); event.xselectionrequest.target);
XFree (pszAtomName); ErrorF ("SelectionRequest - Target atom name %s\n", pszAtomName);
pszAtomName = NULL; XFree (pszAtomName);
pszAtomName = NULL;
}
#endif #endif
/* Abort if invalid target type */ /* Abort if invalid target type */
@ -189,14 +164,14 @@ winClipboardFlushXEvents (HWND hwnd,
} }
/* Setup selection notify xevent */ /* Setup selection notify xevent */
eventSelection.type = SelectionNotify; eventSelection.type = SelectionNotify;
eventSelection.send_event = True; eventSelection.send_event = True;
eventSelection.display = pDisplay; eventSelection.display = pDisplay;
eventSelection.requestor = event.xselectionrequest.requestor; eventSelection.requestor = event.xselectionrequest.requestor;
eventSelection.selection = event.xselectionrequest.selection; eventSelection.selection = event.xselectionrequest.selection;
eventSelection.target = event.xselectionrequest.target; eventSelection.target = event.xselectionrequest.target;
eventSelection.property = event.xselectionrequest.property; eventSelection.property = event.xselectionrequest.property;
eventSelection.time = event.xselectionrequest.time; eventSelection.time = event.xselectionrequest.time;
/* /*
* Notify the requesting window that * Notify the requesting window that
@ -238,7 +213,7 @@ winClipboardFlushXEvents (HWND hwnd,
* FIXME: Can't pass CF_UNICODETEXT on Windows 95/98/Me * 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) if (fUnicodeSupport)
hGlobal = GetClipboardData (CF_UNICODETEXT); hGlobal = GetClipboardData (CF_UNICODETEXT);
else else
@ -256,13 +231,13 @@ winClipboardFlushXEvents (HWND hwnd,
if (fUnicodeSupport) if (fUnicodeSupport)
{ {
iConvertDataLen = WideCharToMultiByte (CP_UTF8, iConvertDataLen = WideCharToMultiByte (CP_UTF8,
0, 0,
(LPCWSTR)pszGlobalData, (LPCWSTR)pszGlobalData,
-1, -1,
NULL, NULL,
0, 0,
NULL, NULL,
NULL); NULL);
/* NOTE: iConvertDataLen includes space for null terminator */ /* NOTE: iConvertDataLen includes space for null terminator */
pszConvertData = (char *) malloc (iConvertDataLen); pszConvertData = (char *) malloc (iConvertDataLen);
WideCharToMultiByte (CP_UTF8, WideCharToMultiByte (CP_UTF8,
@ -283,14 +258,14 @@ winClipboardFlushXEvents (HWND hwnd,
/* Convert DOS string to UNIX string */ /* Convert DOS string to UNIX string */
winClipboardDOStoUNIX (pszConvertData, strlen (pszConvertData)); winClipboardDOStoUNIX (pszConvertData, strlen (pszConvertData));
/* Setup our text list */ /* Setup our text list */
pszTextList[0] = pszConvertData; pszTextList[0] = pszConvertData;
pszTextList[1] = NULL; pszTextList[1] = NULL;
/* Initialize the text property */ /* Initialize the text property */
xtpText.value = NULL; xtpText.value = NULL;
/* Create the text property from the text list */ /* Create the text property from the text list */
if (fUnicodeSupport) if (fUnicodeSupport)
{ {
iReturn = Xutf8TextListToTextProperty (pDisplay, iReturn = Xutf8TextListToTextProperty (pDisplay,
@ -307,26 +282,26 @@ winClipboardFlushXEvents (HWND hwnd,
xiccesStyle, xiccesStyle,
&xtpText); &xtpText);
} }
if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) if (iReturn == XNoMemory || iReturn == XLocaleNotSupported)
{ {
ErrorF ("winClipboardFlushXEvents - SelectionRequest - " ErrorF ("winClipboardFlushXEvents - SelectionRequest - "
"X*TextListToTextProperty failed: %d\n", "X*TextListToTextProperty failed: %d\n",
iReturn); iReturn);
exit(1); pthread_exit (NULL);
} }
/* Free the converted string */ /* Free the converted string */
free (pszConvertData); free (pszConvertData);
/* Copy the clipboard text to the requesting window */ /* Copy the clipboard text to the requesting window */
iReturn = XChangeProperty (pDisplay, iReturn = XChangeProperty (pDisplay,
event.xselectionrequest.requestor, event.xselectionrequest.requestor,
event.xselectionrequest.property, event.xselectionrequest.property,
event.xselectionrequest.target, event.xselectionrequest.target,
8, 8,
PropModeReplace, PropModeReplace,
xtpText.value, xtpText.value,
xtpText.nitems); xtpText.nitems);
if (iReturn == BadAlloc || iReturn == BadAtom if (iReturn == BadAlloc || iReturn == BadAtom
|| iReturn == BadMatch || iReturn == BadValue || iReturn == BadMatch || iReturn == BadValue
|| iReturn == BadWindow) || iReturn == BadWindow)
@ -343,8 +318,8 @@ winClipboardFlushXEvents (HWND hwnd,
CloseClipboard (); CloseClipboard ();
/* Clean up */ /* Clean up */
XFree (xtpText.value); XFree (xtpText.value);
xtpText.value = NULL; xtpText.value = NULL;
/* Setup selection notify event */ /* Setup selection notify event */
eventSelection.type = SelectionNotify; eventSelection.type = SelectionNotify;
@ -369,7 +344,7 @@ winClipboardFlushXEvents (HWND hwnd,
pthread_exit (NULL); pthread_exit (NULL);
} }
break; break;
/* /*
* SelectionNotify * SelectionNotify
@ -377,7 +352,7 @@ winClipboardFlushXEvents (HWND hwnd,
case SelectionNotify: case SelectionNotify:
#if 0 #if 0
ErrorF ("SelectionNotify\n"); ErrorF ("winClipboardFlushXEvents - SelectionNotify\n");
#endif #endif
{ {
char *pszAtomName; char *pszAtomName;
@ -391,86 +366,86 @@ winClipboardFlushXEvents (HWND hwnd,
XFree (pszAtomName); XFree (pszAtomName);
} }
#if 0
/* /*
* TEMP: Bail if selection is anything other than CLIPBOARD * Request conversion of UTF8 and CompoundText targets.
*/ */
if (event.xselection.property == None)
if (event.xselection.selection != atomClipboard) {
break; if (event.xselection.target == XA_STRING)
#endif
/*
*
* What are we doing here?
*
*/
if (event.xselection.property == None)
{ {
if(event.xselection.target == XA_STRING)
{
#if 0 #if 0
ErrorF ("winClipboardFlushXEvents - SelectionNotify - " ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
"XA_STRING\n"); "XA_STRING\n");
#endif #endif
return fReturn; return FALSE;
}
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;
}
} }
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 */ /* Retrieve the size of the stored data */
iReturn = XGetWindowProperty (pDisplay, iReturn = XGetWindowProperty (pDisplay,
iWindow, iWindow,
atomLocalProperty, atomLocalProperty,
0, 0,
0, /* Don't get data, just size */ 0, /* Don't get data, just size */
False, False,
AnyPropertyType, AnyPropertyType,
&xtpText.encoding, &xtpText.encoding,
&xtpText.format, &xtpText.format,
&xtpText.nitems, &xtpText.nitems,
&ulReturnBytesLeft, &ulReturnBytesLeft,
&xtpText.value); &xtpText.value);
if (iReturn != Success) if (iReturn != Success)
{ {
ErrorF ("winClipboardFlushXEvents - SelectionNotify - " ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
@ -479,23 +454,23 @@ winClipboardFlushXEvents (HWND hwnd,
} }
#if 0 #if 0
ErrorF ("SelectionNotify - returned data %d left %d\n", ErrorF ("SelectionNotify - returned data %d left %d\n",
xtpText.nitems, ulReturnBytesLeft); xtpText.nitems, ulReturnBytesLeft);
#endif #endif
/* Request the selection data */ /* Request the selection data */
iReturn = XGetWindowProperty (pDisplay, iReturn = XGetWindowProperty (pDisplay,
iWindow, iWindow,
atomLocalProperty, atomLocalProperty,
0, 0,
ulReturnBytesLeft, ulReturnBytesLeft,
False, False,
AnyPropertyType, AnyPropertyType,
&xtpText.encoding, &xtpText.encoding,
&xtpText.format, &xtpText.format,
&xtpText.nitems, &xtpText.nitems,
&ulReturnBytesLeft, &ulReturnBytesLeft,
&xtpText.value); &xtpText.value);
if (iReturn != Success) if (iReturn != Success)
{ {
ErrorF ("winClipboardFlushXEvents - SelectionNotify - " ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
@ -516,7 +491,7 @@ winClipboardFlushXEvents (HWND hwnd,
pszAtomName = NULL; pszAtomName = NULL;
} }
#endif #endif
if (fUnicodeSupport) if (fUnicodeSupport)
{ {
/* Convert the text property to a text list */ /* Convert the text property to a text list */
@ -528,9 +503,9 @@ winClipboardFlushXEvents (HWND hwnd,
else else
{ {
iReturn = XmbTextPropertyToTextList (pDisplay, iReturn = XmbTextPropertyToTextList (pDisplay,
&xtpText, &xtpText,
&ppszTextList, &ppszTextList,
&iCount); &iCount);
} }
if (iReturn == Success || iReturn > 0) if (iReturn == Success || iReturn > 0)
{ {
@ -544,7 +519,7 @@ winClipboardFlushXEvents (HWND hwnd,
pszReturnData = malloc (iReturnDataLen + 1); pszReturnData = malloc (iReturnDataLen + 1);
pszReturnData[0] = '\0'; pszReturnData[0] = '\0';
for (i = 0; i < iCount; i++) for (i = 0; i < iCount; i++)
{ {
strcat (pszReturnData, ppszTextList[i]); strcat (pszReturnData, ppszTextList[i]);
} }
} }
@ -561,23 +536,26 @@ winClipboardFlushXEvents (HWND hwnd,
switch (iReturn) switch (iReturn)
{ {
case XNoMemory: case XNoMemory:
ErrorF ("winClipboardFlushXEvents - SelectionNotify - XNoMemory\n"); ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
"XNoMemory\n");
break; break;
case XConverterNotFound: case XConverterNotFound:
ErrorF ("winClipboardFlushXEvents - SelectionNotify - XConverterNotFound\n"); ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
"XConverterNotFound\n");
break; break;
default: default:
ErrorF ("winClipboardFlushXEvents - SelectionNotify - Unknown Error\n"); ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
"Unknown Error\n");
break; break;
} }
pszReturnData = malloc (1); pszReturnData = malloc (1);
pszReturnData[0] = '\0'; pszReturnData[0] = '\0';
} }
/* Free the data returned from XGetWindowProperty */ /* Free the data returned from XGetWindowProperty */
XFreeStringList (ppszTextList); XFreeStringList (ppszTextList);
XFree (xtpText.value); XFree (xtpText.value);
/* Convert the X clipboard string to DOS format */ /* Convert the X clipboard string to DOS format */
winClipboardUNIXtoDOS (&pszReturnData, strlen (pszReturnData)); winClipboardUNIXtoDOS (&pszReturnData, strlen (pszReturnData));
@ -590,11 +568,11 @@ winClipboardFlushXEvents (HWND hwnd,
-1, -1,
NULL, NULL,
0); 0);
/* Allocate memory for the Unicode string */ /* Allocate memory for the Unicode string */
pwszUnicodeStr pwszUnicodeStr
= (wchar_t*) malloc (sizeof (wchar_t) * (iUnicodeLen + 1)); = (wchar_t*) malloc (sizeof (wchar_t) * (iUnicodeLen + 1));
/* Do the actual conversion */ /* Do the actual conversion */
MultiByteToWideChar (CP_UTF8, MultiByteToWideChar (CP_UTF8,
0, 0,
@ -609,22 +587,6 @@ winClipboardFlushXEvents (HWND hwnd,
iConvertDataLen = strlen (pszConvertData) + 1; 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 */ /* Allocate global memory for the X clipboard data */
if (fUnicodeSupport) if (fUnicodeSupport)
hGlobal = GlobalAlloc (GMEM_MOVEABLE, hGlobal = GlobalAlloc (GMEM_MOVEABLE,
@ -669,78 +631,14 @@ winClipboardFlushXEvents (HWND hwnd,
if (fUnicodeSupport) if (fUnicodeSupport)
SetClipboardData (CF_UNICODETEXT, hGlobal); SetClipboardData (CF_UNICODETEXT, hGlobal);
else else
SetClipboardData (CF_TEXT, hGlobal); SetClipboardData (CF_TEXT, hGlobal);
/* /*
* NOTE: Do not try to free pszGlobalData, it is owned by * NOTE: Do not try to free pszGlobalData, it is owned by
* Windows after the call to SetClipboardData (). * 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; 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: default:
break; break;
} }

View file

@ -35,6 +35,14 @@
#include "win.h" #include "win.h"
/*
* References to external symbols
*/
extern int g_iCmapPrivateIndex;
extern int g_iScreenPrivateIndex;
/* See Porting Layer Definition - p. 30 */ /* See Porting Layer Definition - p. 30 */
/* /*
* Walk the list of installed colormaps, filling the pmaps list * Walk the list of installed colormaps, filling the pmaps list

View file

@ -265,7 +265,6 @@ winConfigKeyboard (DeviceIntPtr pDevice)
g_winInfo.xkb.options = NULL; g_winInfo.xkb.options = NULL;
# endif /* PC98 */ # endif /* PC98 */
#ifdef XKB
/* /*
* Query the windows autorepeat settings and change the xserver defaults. * Query the windows autorepeat settings and change the xserver defaults.
* If XKB is disabled then windows handles the autorepeat and the special * If XKB is disabled then windows handles the autorepeat and the special
@ -273,7 +272,7 @@ winConfigKeyboard (DeviceIntPtr pDevice)
*/ */
{ {
int kbd_delay; int kbd_delay;
DWORD kbd_speed; DWORD kbd_speed;
if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &kbd_delay, 0) && if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &kbd_delay, 0) &&
SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &kbd_speed, 0)) SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &kbd_speed, 0))
{ {
@ -282,7 +281,7 @@ winConfigKeyboard (DeviceIntPtr pDevice)
case 0: g_winInfo.keyboard.delay = 250; break; case 0: g_winInfo.keyboard.delay = 250; break;
case 1: g_winInfo.keyboard.delay = 500; break; case 1: g_winInfo.keyboard.delay = 500; break;
case 2: g_winInfo.keyboard.delay = 750; break; case 2: g_winInfo.keyboard.delay = 750; break;
default: default:
case 3: g_winInfo.keyboard.delay = 1000; break; case 3: g_winInfo.keyboard.delay = 1000; break;
} }
g_winInfo.keyboard.rate = max(1,kbd_speed); g_winInfo.keyboard.rate = max(1,kbd_speed);
@ -290,7 +289,6 @@ winConfigKeyboard (DeviceIntPtr pDevice)
g_winInfo.keyboard.delay, g_winInfo.keyboard.rate); g_winInfo.keyboard.delay, g_winInfo.keyboard.rate);
} }
} }
#endif
keyboardType = GetKeyboardType (0); keyboardType = GetKeyboardType (0);

View file

@ -34,6 +34,14 @@
#include "win.h" #include "win.h"
/*
* References to external symbols
*/
extern int g_iScreenPrivateIndex;
miPointerScreenFuncRec g_winPointerCursorFuncs = miPointerScreenFuncRec g_winPointerCursorFuncs =
{ {
winCursorOffScreen, winCursorOffScreen,

View file

@ -32,6 +32,16 @@
#include "win.h" #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); extern void ROP16(HDC hdc, int rop);
#define TRANSLATE_COLOR(color) \ #define TRANSLATE_COLOR(color) \

View file

@ -30,6 +30,16 @@
/* $XFree86: xc/programs/Xserver/hw/xwin/wingc.c,v 1.11 2003/08/07 23:47:58 alanh Exp $ */ /* $XFree86: xc/programs/Xserver/hw/xwin/wingc.c,v 1.11 2003/08/07 23:47:58 alanh Exp $ */
#include "win.h" #include "win.h"
/*
* References to external symbols
*/
extern int g_iScreenPrivateIndex;
extern int g_iGCPrivateIndex;
void void
winPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, int dx, int dy, int xOrg, int yOrg); winPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, int dx, int dy, int xOrg, int yOrg);

View file

@ -32,6 +32,15 @@
#include "win.h" #include "win.h"
/*
* References to external symbols
*/
extern int g_iScreenPrivateIndex;
extern int g_iPixmapPrivateIndex;
/* See Porting Layer Definition - p. 55 */ /* See Porting Layer Definition - p. 55 */
void void
winGetSpansNativeGDI (DrawablePtr pDrawable, winGetSpansNativeGDI (DrawablePtr pDrawable,

92
hw/xwin/winglobals.c Normal file
View file

@ -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;
}

View file

@ -32,6 +32,13 @@
#include "win.h" #include "win.h"
/*
* References to external symbols
*/
extern int g_iScreenPrivateIndex;
/* See Porting Layer Definition - p. 33 */ /* See Porting Layer Definition - p. 33 */
/* /*
* Called by clients, returns the best size for a cursor, tile, or * Called by clients, returns the best size for a cursor, tile, or

View file

@ -115,7 +115,6 @@ typedef struct _XMsgProcArgRec {
extern char *display; extern char *display;
extern void ErrorF (const char* /*f*/, ...); extern void ErrorF (const char* /*f*/, ...);
extern Bool g_fCalledSetLocale; extern Bool g_fCalledSetLocale;
extern Bool g_fCalledXInitThreads;
/* /*
@ -144,16 +143,22 @@ static void*
winMultiWindowWMProc (void* pArg); winMultiWindowWMProc (void* pArg);
static int static int
winMultiWindowWMErrorHandler (Display *pDisp, XErrorEvent *e); winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr);
static int
winMutliWindowWMIOErrorHandler (Display *pDisplay);
static void * static void *
winMultiWindowXMsgProc (void *pArg); winMultiWindowXMsgProc (void *pArg);
static void static int
winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg); winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr);
static int 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 int g_nQueueSize;
static jmp_buf g_jmpEntry; static jmp_buf g_jmpWMEntry;
static jmp_buf g_jmpXMsgProcEntry;
static Bool g_shutdown = FALSE; 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 * static void *
@ -765,27 +731,40 @@ winMultiWindowXMsgProc (void *pArg)
ErrorF ("winMultiWindowXMsgProc - pthread_mutex_lock () returned.\n"); ErrorF ("winMultiWindowXMsgProc - pthread_mutex_lock () returned.\n");
/* Only call XInitThreads once for the whole process */ /* Allow multiple threads to access Xlib */
if (!g_fCalledXInitThreads) if (XInitThreads () == 0)
{ {
/* Allow multiple threads to access Xlib */ ErrorF ("winMultiWindowXMsgProc - XInitThreads () failed.\n");
if (XInitThreads () == 0) pthread_exit (NULL);
{
ErrorF ("winMultiWindowXMsgProc - XInitThreads () failed.\n");
pthread_exit (NULL);
}
/* Flag that XInitThreads has been called */
g_fCalledXInitThreads = TRUE;
ErrorF ("winMultiWindowXMsgProc - XInitThreads () returned.\n");
} }
/* Release the server started mutex */ /* Release the server started mutex */
pthread_mutex_unlock (pProcArg->ppmServerStarted); pthread_mutex_unlock (pProcArg->ppmServerStarted);
ErrorF ("winMultiWindowXMsgProc - pthread_mutex_unlock () returned.\n"); 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 */ /* Setup the display connection string x */
snprintf (pszDisplay, snprintf (pszDisplay,
512, "127.0.0.1:%s.%d", display, (int)pProcArg->dwScreen); 512, "127.0.0.1:%s.%d", display, (int)pProcArg->dwScreen);
@ -793,6 +772,7 @@ winMultiWindowXMsgProc (void *pArg)
/* Print the display connection string */ /* Print the display connection string */
ErrorF ("winMultiWindowXMsgProc - DISPLAY=%s\n", pszDisplay); ErrorF ("winMultiWindowXMsgProc - DISPLAY=%s\n", pszDisplay);
/* Initialize retry count */
iRetries = 0; iRetries = 0;
/* Open the X display */ /* Open the X display */
@ -824,10 +804,6 @@ winMultiWindowXMsgProc (void *pArg)
ErrorF ("winMultiWindowXMsgProc - XOpenDisplay () returned and " ErrorF ("winMultiWindowXMsgProc - XOpenDisplay () returned and "
"successfully opened the display.\n"); "successfully opened the display.\n");
/* Install our error handler */
XSetErrorHandler (winMultiWindowWMErrorHandler);
XSetIOErrorHandler (winMutliWindowWMIOErrorHandler);
XSelectInput (pProcArg->pDisplay, XSelectInput (pProcArg->pDisplay,
RootWindow(pProcArg->pDisplay, pProcArg->dwScreen), RootWindow(pProcArg->pDisplay, pProcArg->dwScreen),
@ -976,7 +952,7 @@ winInitWM (void **ppWMInfo,
/* /*
* winInitMultiWindowWM - * Window manager thread - setup
*/ */
static void static void
@ -1030,20 +1006,11 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
/* Flag that we have called setlocale */ /* Flag that we have called setlocale */
g_fCalledSetLocale = TRUE; g_fCalledSetLocale = TRUE;
/* Only call XInitThreads once for the whole process */ /* Allow multiple threads to access Xlib */
if (!g_fCalledXInitThreads) if (XInitThreads () == 0)
{ {
/* Allow multiple threads to access Xlib */ ErrorF ("winInitMultiWindowWM - XInitThreads () failed.\n");
if (XInitThreads () == 0) pthread_exit (NULL);
{
ErrorF ("winInitMultiWindowWM - XInitThreads () failed.\n");
pthread_exit (NULL);
}
/* Flag that XInitThreads has been called */
g_fCalledXInitThreads = TRUE;
ErrorF ("winInitMultiWindowWM - XInitThreads () returned.\n");
} }
/* Release the server started mutex */ /* Release the server started mutex */
@ -1052,7 +1019,7 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
ErrorF ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n"); ErrorF ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n");
/* Set jump point for IO Error exits */ /* Set jump point for IO Error exits */
iReturn = setjmp (g_jmpEntry); iReturn = setjmp (g_jmpWMEntry);
/* Check if we should continue operations */ /* Check if we should continue operations */
if (iReturn != WIN_JMP_ERROR_IO if (iReturn != WIN_JMP_ERROR_IO
@ -1063,17 +1030,16 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
iReturn); iReturn);
pthread_exit (NULL); 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) 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 */ /* Setup the display connection string x */
snprintf (pszDisplay, snprintf (pszDisplay,
512, 512,
@ -1114,9 +1080,6 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
ErrorF ("winInitMultiWindowWM - XOpenDisplay () returned and " ErrorF ("winInitMultiWindowWM - XOpenDisplay () returned and "
"successfully opened the display.\n"); "successfully opened the display.\n");
/* Install our error handler */
XSetErrorHandler (winMultiWindowWMErrorHandler);
XSetIOErrorHandler (winMutliWindowWMIOErrorHandler);
/* Create some atoms */ /* Create some atoms */
pWMInfo->atmWmProtos = XInternAtom (pWMInfo->pDisplay, 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 static int
@ -1163,7 +1153,42 @@ winMutliWindowWMIOErrorHandler (Display *pDisplay)
printf ("\nwinMutliWindowWMIOErrorHandler!\n\n"); printf ("\nwinMutliWindowWMIOErrorHandler!\n\n");
/* Restart at the main entry point */ /* 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; return 0;
} }

View file

@ -32,6 +32,14 @@
#include "win.h" #include "win.h"
/*
* References to external symbols
*/
extern int g_iPixmapPrivateIndex;
/* See Porting Layer Definition - p. 34 */ /* See Porting Layer Definition - p. 34 */
/* See mfb/mfbpixmap.c - mfbCreatePixmap() */ /* See mfb/mfbpixmap.c - mfbCreatePixmap() */
PixmapPtr PixmapPtr

1017
hw/xwin/winprocarg.c Executable file

File diff suppressed because it is too large Load diff

View file

@ -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 * Determine what type of screen we are initializing
* and call the appropriate procedure to intiailize * and call the appropriate procedure to intiailize
@ -78,8 +87,8 @@ winScreenInit (int index,
winPrivScreenPtr pScreenPriv; winPrivScreenPtr pScreenPriv;
HDC hdc; HDC hdc;
#if CYGDEBUG #if CYGDEBUG || YES
ErrorF ("winScreenInit - dwWidth: %d dwHeight: %d\n", ErrorF ("winScreenInit - dwWidth: %ld dwHeight: %ld\n",
pScreenInfo->dwWidth, pScreenInfo->dwHeight); pScreenInfo->dwWidth, pScreenInfo->dwHeight);
#endif #endif
@ -552,7 +561,7 @@ winFinishScreenInitFB (int index,
pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreenPriv->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; 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); iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL);
if (iReturn != 0) if (iReturn != 0)
{ {
@ -561,7 +570,7 @@ winFinishScreenInitFB (int index,
return FALSE; return FALSE;
} }
/* Own the mutex for modules in seperate threads */ /* Own the mutex for modules in separate threads */
iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted); iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted);
if (iReturn != 0) if (iReturn != 0)
{ {
@ -595,21 +604,6 @@ winFinishScreenInitFB (int index,
return FALSE; 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 */ /* Tell the server that we are enabled */
pScreenPriv->fEnabled = TRUE; pScreenPriv->fEnabled = TRUE;

View file

@ -32,6 +32,16 @@
#include "win.h" #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 */ /* See Porting Layer Definition - p. 55 */
void void
winSetSpansNativeGDI (DrawablePtr pDrawable, winSetSpansNativeGDI (DrawablePtr pDrawable,

View file

@ -34,6 +34,15 @@
#include "win.h" #include "win.h"
/*
* References to external symbols
*/
extern HWND g_hDlgDepthChange;
extern HWND g_hDlgExit;
/* See Porting Layer Definition - p. 7 */ /* See Porting Layer Definition - p. 7 */
void void
winWakeupHandler (int nScreen, winWakeupHandler (int nScreen,

View file

@ -32,6 +32,15 @@
#include "win.h" #include "win.h"
/*
* References to external symbols
*/
extern int g_iScreenPrivateIndex;
extern int g_iWindowPrivateIndex;
/* /*
* Prototypes for local functions * Prototypes for local functions
*/ */

View file

@ -1051,15 +1051,16 @@ winWindowProc (HWND hwnd, UINT message,
default: default:
/* It's probably one of the custom menus... */ /* It's probably one of the custom menus... */
return HandleCustomWM_COMMAND (0, LOWORD (wParam)); return HandleCustomWM_COMMAND (0, LOWORD (wParam));
} }
break; break;
case WM_ENDSESSION: case WM_ENDSESSION:
case WM_GIVEUP: case WM_GIVEUP:
/* Tell X that we are giving up */ /* Tell X that we are giving up */
winDeinitClipboard (); if (s_pScreenInfo->fClipboard)
winDeinitMultiWindowWM (); winDeinitClipboard ();
if (s_pScreenInfo->fMultiWindow)
winDeinitMultiWindowWM ();
GiveUp (0); GiveUp (0);
return 0; return 0;