hw/xwin: Remove left-over pthread_exit() in clipboard code

Commit c1bf3baa44fbd8af33a2b3ce045324485b85a7a7 removed all but one of the
pthread_exit() calls which used to call winClipboardThreadExit()

Fix the final remaining one to exit via done label on IOError instead.

Also fix a comment and report pre-flush failure to log, but do not exit

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Push winClipboardShutdown() into winclipboardinit.c

Push winClipboardShutdown() into winclipboardinit.c
This lets us make g_ptClipboardProc static

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Hoist clipboard thread restart up one level

Hoist clipboard thread restart up one level.

Note that currently g_fClipboardLaunched is set the first time in the
winProcEstablishConnection wrapper, and subsequent times when the clipboard
thread restarts itself.

Try to clarify this and just set g_fClipboardLaunched before starting the
thread.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: winProcEstablishConnection doesn't need to check if clipboard started

winProcEstablishConnection doesn't need to check if clipboard has already been
started.

It should be clear that we start the thread only once when the wrapper tells us
to, as the wrapper unhooks itself thereafter.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Hoist setting of g_fClipboardStarted flag up one level

Hoist the setting of g_fClipboardStarted flag up one level.

Also move up the clearing of the g_fClipboardLaunched at the end of clipboard
function.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Remove g_fClipboardLaunched, it's value is identical to g_fClipboardStarted

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Remove SetSelectionOwner wrapper, use XFixesSetSelectionOwnerNotify event instead

Use the XFixesSetSelectionNotify event instead of a SetSelectionOwner wrapper,
the completely equivalent client-side mechanism.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Move winClipboardCreateMessagingWindow() to winclipboardthread.c

Move winClipboardCreateMessagingWindow() from winclipboardinit.c to
winclipboardthread.c, the only place that uses it, and make it static.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
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>
hw/xwin: Hoist use of winSetAuthorization() and winGetDisplayName() up one level

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Add remaining clipboard globals to winglobals.h

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Make g_hwndClipboard static

Move winFixClipboardChain() into winclipboardthread.c
Add winCLipboardWindowDestroy() function to access it for WM_DESTROY

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Move clipboard integration code down to a subdirectory

Move clipboard integration code down to a subdirectory and build as a
convenience library

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Return a shutdown flag from winClipboardProc() if we should stop trying

Return a shutdown flag from winClipboardProc(), and use it in
winClipboardThreadProc() to determine if we should stop.

Currently this is set if the clipboard messaging window received a WM_QUIT.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Separate libwinclipboard interface and internal header files

Rename the libwinclipboard internal header from winclipboard.h to internal.h

Put libwinclipboard's public interface into winclipboard.h

This lets winclipboardinit.c partake of that public interface, and all X server
headers without clashes

winInitClipboard() prototype belongs in a server header

v2: Remove duplicate declaration of winClipboardWindowDestroy()

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Add fUseUnicode as parameter to winClipboardProc()

Add fUseUnicode as parameter to winClipboardProc()
Access g_fUseUnicode global when calling it

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
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>
hw/xwin: Changes in error logging to make libwinclipboard more useful as a library

Consistently use ErrorF() rather than winErrorFVerb()

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Add xwinclip test client

Add xwinclip test client, which includes stubs for winDebug(), ErrorF()

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Remove standard includes from internal.h and add them where needed

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>