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