hw/xwin: Eliminate g_pClipboardDisplay and g_iClipboardWindow globals

Eliminate the g_pClipboardDisplay and g_iClipboardWindow globals used to make
those values available to the clipboard wndproc, by passing them in via the
WM_CREATE message instead.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
This commit is contained in:
Jon TURNEY 2013-06-16 22:35:22 +01:00
parent 229a0a83a4
commit a3c1e405cb
4 changed files with 23 additions and 30 deletions

View File

@ -107,6 +107,12 @@ BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd);
LRESULT CALLBACK
winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
typedef struct
{
Display *pClipboardDisplay;
Window iClipboardWindow;
} ClipboardWindowCreationParams;
/*
* winclipboardxevents.c
*/

View File

@ -58,8 +58,6 @@
extern Bool g_fUnicodeClipboard;
extern Bool g_fClipboard;
extern HWND g_hwndClipboard;
extern void *g_pClipboardDisplay;
extern Window g_iClipboardWindow;
/*
* Global variables
@ -78,7 +76,7 @@ int xfixes_error_base;
*/
static HWND
winClipboardCreateMessagingWindow(void);
winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow);
static int
winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr);
@ -192,9 +190,6 @@ winClipboardProc(void *pvNotUsed)
goto winClipboardProc_Done;
}
/* Save the display in a global used by the wndproc */
g_pClipboardDisplay = pDisplay;
ErrorF("winClipboardProc - XOpenDisplay () returned and "
"successfully opened the display.\n");
@ -255,14 +250,11 @@ winClipboardProc(void *pvNotUsed)
XFixesSelectionWindowDestroyNotifyMask |
XFixesSelectionClientCloseNotifyMask);
/* Save the window in the screen privates */
g_iClipboardWindow = iWindow;
/* Initialize monitored selection state */
winClipboardInitMonitoredSelections();
/* Create Windows messaging window */
hwnd = winClipboardCreateMessagingWindow();
hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow);
/* Save copy of HWND in screen privates */
g_hwndClipboard = hwnd;
@ -419,8 +411,6 @@ winClipboardProc(void *pvNotUsed)
#endif
/* global clipboard variable reset */
g_iClipboardWindow = None;
g_pClipboardDisplay = NULL;
g_hwndClipboard = NULL;
return NULL;
@ -431,9 +421,10 @@ winClipboardProc(void *pvNotUsed)
*/
static HWND
winClipboardCreateMessagingWindow(void)
winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow)
{
WNDCLASSEX wc;
ClipboardWindowCreationParams cwcp;
HWND hwnd;
/* Setup our window class */
@ -451,6 +442,10 @@ winClipboardCreateMessagingWindow(void)
wc.hIconSm = 0;
RegisterClassEx(&wc);
/* Information to be passed to WM_CREATE */
cwcp.pClipboardDisplay = pDisplay;
cwcp.iClipboardWindow = iWindow;
/* Create the window */
hwnd = CreateWindowExA(0, /* Extended styles */
WIN_CLIPBOARD_WINDOW_CLASS, /* Class name */
@ -463,7 +458,7 @@ winClipboardCreateMessagingWindow(void)
(HWND) NULL, /* No parent or owner window */
(HMENU) NULL, /* No menu */
GetModuleHandle(NULL), /* Instance handle */
NULL); /* Creation data */
&cwcp); /* Creation data */
assert(hwnd != NULL);
/* I'm not sure, but we may need to call this to start message processing */

View File

@ -44,12 +44,6 @@
#define WIN_POLL_TIMEOUT 1
/*
* References to external symbols
*/
extern void *g_pClipboardDisplay;
extern Window g_iClipboardWindow;
/*
* Process X events up to specified timeout
@ -138,6 +132,8 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND s_hwndNextViewer;
static Bool s_fCBCInitialized;
static Display *pDisplay;
static Window iWindow;
/* Branch on message type */
switch (message) {
@ -158,9 +154,13 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND first, next;
DWORD error_code = 0;
ClipboardWindowCreationParams *cwcp = (ClipboardWindowCreationParams *)((CREATESTRUCT *)lParam)->lpCreateParams;
winDebug("winClipboardWindowProc - WM_CREATE\n");
pDisplay = cwcp->pClipboardDisplay;
iWindow = cwcp->iClipboardWindow;
first = GetClipboardViewer(); /* Get handle to first viewer in chain. */
if (first == hwnd)
return 0; /* Make sure it's not us! */
@ -243,8 +243,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
static Atom atomClipboard;
static int generation;
static Bool s_fProcessingDrawClipboard = FALSE;
Display *pDisplay = g_pClipboardDisplay;
Window iWindow = g_iClipboardWindow;
int iReturn;
winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");
@ -323,7 +321,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
/* Release PRIMARY selection if owned */
iReturn = XGetSelectionOwner(pDisplay, XA_PRIMARY);
if (iReturn == g_iClipboardWindow) {
if (iReturn == iWindow) {
winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
"PRIMARY selection is owned by us.\n");
XSetSelectionOwner(pDisplay, XA_PRIMARY, None, CurrentTime);
@ -335,7 +333,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
/* Release CLIPBOARD selection if owned */
iReturn = XGetSelectionOwner(pDisplay, atomClipboard);
if (iReturn == g_iClipboardWindow) {
if (iReturn == iWindow) {
winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
"CLIPBOARD selection is owned by us.\n");
XSetSelectionOwner(pDisplay, atomClipboard, None, CurrentTime);
@ -408,8 +406,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_RENDERALLFORMATS:
{
int iReturn;
Display *pDisplay = g_pClipboardDisplay;
Window iWindow = g_iClipboardWindow;
Bool fConvertToUnicode;
winDebug("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");

View File

@ -95,8 +95,6 @@ Bool g_fUnicodeClipboard = TRUE;
Bool g_fClipboard = TRUE;
Bool g_fClipboardStarted = FALSE;
HWND g_hwndClipboard = NULL;
void *g_pClipboardDisplay = NULL;
Window g_iClipboardWindow = None;
#endif
/*
@ -109,8 +107,6 @@ winInitializeGlobals(void)
{
g_dwCurrentThreadID = GetCurrentThreadId();
#ifdef XWIN_CLIPBOARD
g_iClipboardWindow = None;
g_pClipboardDisplay = NULL;
g_hwndClipboard = NULL;
#endif
}