hw/xwin: Look up atoms in winClipboardProc()
Look up all atoms of interest in clipboard code in winClipboardProc() and pass them down. This avoids the need to check serverGeneration to notice when we need to invalidate cached atom values. Also consistently use cached atom values everywhere, rather than sometimes just doing XInternAtom() again. Remove WIN_LOCAL_PROPERTY as unused now, as we only refer to CYGX_CUT_BUFFER once and do that directly. Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk> Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
This commit is contained in:
parent
be61a1fc7e
commit
e1cf2b47be
|
@ -61,7 +61,7 @@
|
|||
#endif
|
||||
#define WIN_JMP_OKAY 0
|
||||
#define WIN_JMP_ERROR_IO 2
|
||||
#define WIN_LOCAL_PROPERTY "CYGX_CUT_BUFFER"
|
||||
|
||||
#define WIN_XEVENTS_SUCCESS 0
|
||||
#define WIN_XEVENTS_CONVERT 2
|
||||
#define WIN_XEVENTS_NOTIFY 3
|
||||
|
@ -90,6 +90,15 @@ void
|
|||
*/
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Atom atomClipboard;
|
||||
Atom atomLocalProperty;
|
||||
Atom atomUTF8String;
|
||||
Atom atomCompoundText;
|
||||
Atom atomTargets;
|
||||
} ClipboardAtoms;
|
||||
|
||||
/*
|
||||
* winclipboardwndproc.c
|
||||
*/
|
||||
|
@ -103,6 +112,7 @@ typedef struct
|
|||
{
|
||||
Display *pClipboardDisplay;
|
||||
Window iClipboardWindow;
|
||||
ClipboardAtoms *atoms;
|
||||
} ClipboardWindowCreationParams;
|
||||
|
||||
/*
|
||||
|
@ -111,11 +121,11 @@ typedef struct
|
|||
|
||||
int
|
||||
winClipboardFlushXEvents(HWND hwnd,
|
||||
int iWindow, Display * pDisplay, Bool fUnicodeSupport);
|
||||
int iWindow, Display * pDisplay, Bool fUnicodeSupport, ClipboardAtoms *atom);
|
||||
|
||||
|
||||
Atom
|
||||
winClipboardGetLastOwnedSelectionAtom(void);
|
||||
winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms);
|
||||
|
||||
void
|
||||
winClipboardInitMonitoredSelections(void);
|
||||
|
|
|
@ -71,7 +71,7 @@ int xfixes_error_base;
|
|||
*/
|
||||
|
||||
static HWND
|
||||
winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow);
|
||||
winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow, ClipboardAtoms *atoms);
|
||||
|
||||
static int
|
||||
winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr);
|
||||
|
@ -88,7 +88,7 @@ static int
|
|||
Bool
|
||||
winClipboardProc(Bool fUseUnicode, char *szDisplay)
|
||||
{
|
||||
Atom atomClipboard;
|
||||
ClipboardAtoms atoms;
|
||||
int iReturn;
|
||||
HWND hwnd = NULL;
|
||||
int iConnectionNumber = 0;
|
||||
|
@ -188,8 +188,12 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
|
|||
if (!XFixesQueryExtension(pDisplay, &xfixes_event_base, &xfixes_error_base))
|
||||
ErrorF ("winClipboardProc - XFixes extension not present\n");
|
||||
|
||||
/* Create atom */
|
||||
atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
|
||||
/* Create atoms */
|
||||
atoms.atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
|
||||
atoms.atomLocalProperty = XInternAtom (pDisplay, "CYGX_CUT_BUFFER", False);
|
||||
atoms.atomUTF8String = XInternAtom (pDisplay, "UTF8_STRING", False);
|
||||
atoms.atomCompoundText = XInternAtom (pDisplay, "COMPOUND_TEXT", False);
|
||||
atoms.atomTargets = XInternAtom (pDisplay, "TARGETS", False);
|
||||
|
||||
/* Create a messaging window */
|
||||
iWindow = XCreateSimpleWindow(pDisplay,
|
||||
|
@ -220,7 +224,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
|
|||
|
||||
XFixesSelectSelectionInput (pDisplay,
|
||||
iWindow,
|
||||
XInternAtom (pDisplay, "CLIPBOARD", False),
|
||||
atoms.atomClipboard,
|
||||
XFixesSetSelectionOwnerNotifyMask |
|
||||
XFixesSelectionWindowDestroyNotifyMask |
|
||||
XFixesSelectionClientCloseNotifyMask);
|
||||
|
@ -229,7 +233,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
|
|||
/* Initialize monitored selection state */
|
||||
winClipboardInitMonitoredSelections();
|
||||
/* Create Windows messaging window */
|
||||
hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow);
|
||||
hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow, &atoms);
|
||||
|
||||
/* Save copy of HWND */
|
||||
g_hwndClipboard = hwnd;
|
||||
|
@ -246,10 +250,10 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
|
|||
}
|
||||
|
||||
/* CLIPBOARD */
|
||||
iReturn = XSetSelectionOwner(pDisplay, atomClipboard,
|
||||
iReturn = XSetSelectionOwner(pDisplay, atoms.atomClipboard,
|
||||
iWindow, CurrentTime);
|
||||
if (iReturn == BadAtom || iReturn == BadWindow ||
|
||||
XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
|
||||
XGetSelectionOwner(pDisplay, atoms.atomClipboard) != iWindow) {
|
||||
ErrorF("winClipboardProc - Could not set CLIPBOARD owner\n");
|
||||
goto winClipboardProc_Done;
|
||||
}
|
||||
|
@ -261,7 +265,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
|
|||
* because there may be events in local data structures
|
||||
* already.
|
||||
*/
|
||||
winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
|
||||
winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode, &atoms);
|
||||
|
||||
/* Pre-flush Windows messages */
|
||||
if (!winClipboardFlushWindowsMessageQueue(hwnd)) {
|
||||
|
@ -319,7 +323,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
|
|||
/* Branch on which descriptor became active */
|
||||
if (FD_ISSET(iConnectionNumber, &fdsRead)) {
|
||||
/* Process X events */
|
||||
winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
|
||||
winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode, &atoms);
|
||||
}
|
||||
|
||||
#ifdef HAS_DEVWINDOWS
|
||||
|
@ -393,7 +397,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
|
|||
*/
|
||||
|
||||
static HWND
|
||||
winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow)
|
||||
winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow, ClipboardAtoms *atoms)
|
||||
{
|
||||
WNDCLASSEX wc;
|
||||
ClipboardWindowCreationParams cwcp;
|
||||
|
@ -417,6 +421,7 @@ winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow)
|
|||
/* Information to be passed to WM_CREATE */
|
||||
cwcp.pClipboardDisplay = pDisplay;
|
||||
cwcp.iClipboardWindow = iWindow;
|
||||
cwcp.atoms = atoms;
|
||||
|
||||
/* Create the window */
|
||||
hwnd = CreateWindowExA(0, /* Extended styles */
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
|
||||
static int
|
||||
winProcessXEventsTimeout(HWND hwnd, int iWindow, Display * pDisplay,
|
||||
Bool fUseUnicode, int iTimeoutSec)
|
||||
Bool fUseUnicode, ClipboardAtoms *atoms, int iTimeoutSec)
|
||||
{
|
||||
int iConnNumber;
|
||||
struct timeval tv;
|
||||
|
@ -107,7 +107,7 @@ winProcessXEventsTimeout(HWND hwnd, int iWindow, Display * pDisplay,
|
|||
/* Process X events */
|
||||
/* Exit when we see that server is shutting down */
|
||||
iReturn = winClipboardFlushXEvents(hwnd,
|
||||
iWindow, pDisplay, fUseUnicode);
|
||||
iWindow, pDisplay, fUseUnicode, atoms);
|
||||
|
||||
winDebug
|
||||
("winProcessXEventsTimeout () - winClipboardFlushXEvents returned %d\n",
|
||||
|
@ -137,6 +137,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
static Bool s_fCBCInitialized;
|
||||
static Display *pDisplay;
|
||||
static Window iWindow;
|
||||
static ClipboardAtoms *atoms;
|
||||
|
||||
/* Branch on message type */
|
||||
switch (message) {
|
||||
|
@ -163,6 +164,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
pDisplay = cwcp->pClipboardDisplay;
|
||||
iWindow = cwcp->iClipboardWindow;
|
||||
atoms = cwcp->atoms;
|
||||
|
||||
first = GetClipboardViewer(); /* Get handle to first viewer in chain. */
|
||||
if (first == hwnd)
|
||||
|
@ -243,18 +245,11 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
case WM_DRAWCLIPBOARD:
|
||||
{
|
||||
static Atom atomClipboard;
|
||||
static int generation;
|
||||
static Bool s_fProcessingDrawClipboard = FALSE;
|
||||
int iReturn;
|
||||
|
||||
winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");
|
||||
|
||||
if (generation != serverGeneration) {
|
||||
generation = serverGeneration;
|
||||
atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
|
||||
}
|
||||
|
||||
/*
|
||||
* We've occasionally seen a loop in the clipboard chain.
|
||||
* Try and fix it on the first hint of recursion.
|
||||
|
@ -335,11 +330,11 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
iReturn);
|
||||
|
||||
/* Release CLIPBOARD selection if owned */
|
||||
iReturn = XGetSelectionOwner(pDisplay, atomClipboard);
|
||||
iReturn = XGetSelectionOwner(pDisplay, atoms->atomClipboard);
|
||||
if (iReturn == iWindow) {
|
||||
winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
|
||||
"CLIPBOARD selection is owned by us.\n");
|
||||
XSetSelectionOwner(pDisplay, atomClipboard, None, CurrentTime);
|
||||
"CLIPBOARD selection is owned by us, releasing\n");
|
||||
XSetSelectionOwner(pDisplay, atoms->atomClipboard, None, CurrentTime);
|
||||
}
|
||||
else if (BadWindow == iReturn || BadAtom == iReturn)
|
||||
winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
|
||||
|
@ -368,10 +363,10 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
/* Reassert ownership of the CLIPBOARD */
|
||||
iReturn = XSetSelectionOwner(pDisplay,
|
||||
atomClipboard, iWindow, CurrentTime);
|
||||
atoms->atomClipboard, iWindow, CurrentTime);
|
||||
|
||||
if (iReturn == BadAtom || iReturn == BadWindow ||
|
||||
XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
|
||||
XGetSelectionOwner(pDisplay, atoms->atomClipboard) != iWindow) {
|
||||
winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
|
||||
"Could not reassert ownership of CLIPBOARD\n");
|
||||
}
|
||||
|
@ -421,11 +416,9 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
|
||||
/* Request the selection contents */
|
||||
iReturn = XConvertSelection(pDisplay,
|
||||
winClipboardGetLastOwnedSelectionAtom(),
|
||||
XInternAtom(pDisplay,
|
||||
"COMPOUND_TEXT", False),
|
||||
XInternAtom(pDisplay,
|
||||
"CYGX_CUT_BUFFER", False),
|
||||
winClipboardGetLastOwnedSelectionAtom(atoms),
|
||||
atoms->atomCompoundText,
|
||||
atoms->atomLocalProperty,
|
||||
iWindow, CurrentTime);
|
||||
if (iReturn == BadAtom || iReturn == BadWindow) {
|
||||
winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMAT - "
|
||||
|
@ -461,7 +454,9 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
iReturn = winProcessXEventsTimeout(hwnd,
|
||||
iWindow,
|
||||
pDisplay,
|
||||
fConvertToUnicode, WIN_POLL_TIMEOUT);
|
||||
fConvertToUnicode,
|
||||
atoms,
|
||||
WIN_POLL_TIMEOUT);
|
||||
|
||||
/*
|
||||
* The last call to winProcessXEventsTimeout
|
||||
|
|
|
@ -62,7 +62,6 @@ static const char *szSelectionNames[CLIP_NUM_SELECTIONS] =
|
|||
{ "PRIMARY", "CLIPBOARD" };
|
||||
|
||||
static unsigned int lastOwnedSelectionIndex = CLIP_OWN_NONE;
|
||||
static Atom atomClipboard = None;
|
||||
|
||||
static void
|
||||
MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i)
|
||||
|
@ -98,7 +97,7 @@ MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i)
|
|||
}
|
||||
|
||||
Atom
|
||||
winClipboardGetLastOwnedSelectionAtom(void)
|
||||
winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms)
|
||||
{
|
||||
if (lastOwnedSelectionIndex == CLIP_OWN_NONE)
|
||||
return None;
|
||||
|
@ -107,7 +106,7 @@ winClipboardGetLastOwnedSelectionAtom(void)
|
|||
return XA_PRIMARY;
|
||||
|
||||
if (lastOwnedSelectionIndex == CLIP_OWN_CLIPBOARD)
|
||||
return atomClipboard;
|
||||
return atoms->atomClipboard;
|
||||
|
||||
return None;
|
||||
}
|
||||
|
@ -129,22 +128,13 @@ winClipboardInitMonitoredSelections(void)
|
|||
|
||||
int
|
||||
winClipboardFlushXEvents(HWND hwnd,
|
||||
int iWindow, Display * pDisplay, Bool fUseUnicode)
|
||||
int iWindow, Display * pDisplay, Bool fUseUnicode, ClipboardAtoms *atoms)
|
||||
{
|
||||
static Atom atomLocalProperty;
|
||||
static Atom atomCompoundText;
|
||||
static Atom atomUTF8String;
|
||||
static Atom atomTargets;
|
||||
static int generation;
|
||||
|
||||
if (generation != serverGeneration) {
|
||||
generation = serverGeneration;
|
||||
atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
|
||||
atomLocalProperty = XInternAtom(pDisplay, WIN_LOCAL_PROPERTY, False);
|
||||
atomUTF8String = XInternAtom(pDisplay, "UTF8_STRING", False);
|
||||
atomCompoundText = XInternAtom(pDisplay, "COMPOUND_TEXT", False);
|
||||
atomTargets = XInternAtom(pDisplay, "TARGETS", False);
|
||||
}
|
||||
Atom atomClipboard = atoms->atomClipboard;
|
||||
Atom atomLocalProperty = atoms->atomLocalProperty;
|
||||
Atom atomUTF8String = atoms->atomUTF8String;
|
||||
Atom atomCompoundText = atoms->atomCompoundText;
|
||||
Atom atomTargets = atoms->atomTargets;
|
||||
|
||||
/* Process all pending events */
|
||||
while (XPending(pDisplay)) {
|
||||
|
|
Loading…
Reference in New Issue