2013-06-17 19:27:56 +02:00
|
|
|
/*
|
|
|
|
*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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WINCLIPBOARD_INTERNAL_H
|
|
|
|
#define WINCLIPBOARD_INTERNAL_H
|
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
#include <xcb/xproto.h>
|
|
|
|
#include <X11/Xfuncproto.h> // for _X_ATTRIBUTE_PRINTF
|
|
|
|
#include <X11/Xdefs.h> // for Bool type
|
2013-06-17 19:27:56 +02:00
|
|
|
|
|
|
|
/* Windows headers */
|
|
|
|
#include <X11/Xwindows.h>
|
|
|
|
|
2015-11-18 22:27:23 +01:00
|
|
|
#define WIN_XEVENTS_SUCCESS 0 // more like 'CONTINUE'
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
#define WIN_XEVENTS_FAILED 1
|
|
|
|
#define WIN_XEVENTS_NOTIFY_DATA 3
|
|
|
|
#define WIN_XEVENTS_NOTIFY_TARGETS 4
|
2013-06-17 19:27:56 +02:00
|
|
|
|
hw/xwin: Fix clipboard thread restart
It seems that the clipboard thread restart mechanism has been broken for a
while, which can be demonstrated using XDMCP with KDM (e.g. to a Kubutunu 12.04
host)
KDM kills all attached clients, including the clipboard integration client,
which restarts, but then exits on WM_QUIT.
Using PostQuitMessage() in WM_DESTROY is unhelpful, as we may not actually be
quitting the thread, if we just destroyed the window because the clipboard
thread is about to retry, because he WM_QUIT message sticks around, and is
noticed the next time we look at the window message queue and confuses us into
thinking we need to quit.
Sending a WM_DESTROY is apparently never correct anyhow, see [1]
So:
1/ Use DestroyWindow() to destroy the clipboard messaging window when cleaning
up for retry or exit in winClipboardProc (the clipboard thread main proc)
2/ Send a special WM_WM_QUIT message in winClipboardWindowDestroy() from the X
server thread when the X server is resetting.
3/ When processing that WM_WM_QUIT message in the clipboard thread, cause the
clipboard window to PostQuitMessage(), which causes the clipboard thread to
exit.
[1] http://blogs.msdn.com/b/oldnewthing/archive/2011/09/26/10216420.aspx
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-02-22 00:20:00 +01:00
|
|
|
#define WM_WM_QUIT (WM_USER + 2)
|
2013-06-17 19:27:56 +02:00
|
|
|
|
2017-10-27 16:11:56 +02:00
|
|
|
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
|
|
|
|
|
2013-06-17 19:27:56 +02:00
|
|
|
/*
|
|
|
|
* References to external symbols
|
|
|
|
*/
|
|
|
|
|
2014-10-01 23:12:26 +02:00
|
|
|
extern void winDebug(const char *format, ...) _X_ATTRIBUTE_PRINTF(1, 2);
|
|
|
|
extern void ErrorF(const char *format, ...) _X_ATTRIBUTE_PRINTF(1, 2);
|
2013-06-17 19:27:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* winclipboardtextconv.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
winClipboardDOStoUNIX(char *pszData, int iLength);
|
|
|
|
|
|
|
|
void
|
|
|
|
winClipboardUNIXtoDOS(char **ppszData, int iLength);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* winclipboardthread.c
|
|
|
|
*/
|
|
|
|
|
2013-06-17 20:58:20 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_atom_t atomClipboard;
|
|
|
|
xcb_atom_t atomLocalProperty;
|
|
|
|
xcb_atom_t atomUTF8String;
|
|
|
|
xcb_atom_t atomCompoundText;
|
|
|
|
xcb_atom_t atomTargets;
|
|
|
|
xcb_atom_t atomIncr;
|
2013-06-17 20:58:20 +02:00
|
|
|
} ClipboardAtoms;
|
|
|
|
|
2013-06-17 19:27:56 +02:00
|
|
|
/*
|
|
|
|
* winclipboardwndproc.c
|
|
|
|
*/
|
|
|
|
|
2013-06-20 13:50:18 +02:00
|
|
|
Bool winClipboardFlushWindowsMessageQueue(HWND hwnd);
|
2013-06-17 19:27:56 +02:00
|
|
|
|
|
|
|
LRESULT CALLBACK
|
|
|
|
winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_connection_t *pClipboardDisplay;
|
|
|
|
xcb_window_t iClipboardWindow;
|
2013-06-17 20:58:20 +02:00
|
|
|
ClipboardAtoms *atoms;
|
2013-06-17 19:27:56 +02:00
|
|
|
} ClipboardWindowCreationParams;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* winclipboardxevents.c
|
|
|
|
*/
|
|
|
|
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_atom_t *targetList;
|
2015-11-18 22:27:23 +01:00
|
|
|
unsigned char *incr;
|
|
|
|
unsigned long int incrsize;
|
hw/xwin: Retrieve TARGETS to avoid unnecessary failing conversion attempts
See http://cygwin.com/ml/cygwin-xfree/2013-07/msg00016.html
It looks like the change in a9aca218f557c723e637287272819a7c17174e1e had some
unforseen consequences.
If the X11 selection contents are not convertable to COMPOUND_TEXT, UTF8_STRING
or STRING format (for example, if it is an image), after those conversion
attempts have failed, we sit in winProcessXEventsTimeout() until the timeout
expires.
It also seems that maybe gnuplot doesn't respond correctly to this sequence of
conversion requests and doesn't reply to some of them, which also causes us to
sit in winProcessXEventsTimeout() until the timeout expires.
The Windows application which has requested the clipboard contents via
GetClipboardContents() is blocked until we return from WM_RENDERFORMAT, so
sitting waiting for this timeout to expire should be avoided.
So instead, explicitly request conversion to the TARGETS target, choose
the most preferred format, and request conversion to that.
Also: if there is no owned selection, there is nothing to paste, so don't bother
trying to convert it.
v2: Fix compilation with -Werror=declaration-after-statement
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2013-09-24 17:02:37 +02:00
|
|
|
} ClipboardConversionData;
|
|
|
|
|
2013-06-17 19:27:56 +02:00
|
|
|
int
|
|
|
|
winClipboardFlushXEvents(HWND hwnd,
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_window_t iWindow, xcb_connection_t * pDisplay,
|
|
|
|
ClipboardConversionData *data, ClipboardAtoms *atoms);
|
2013-06-17 19:27:56 +02:00
|
|
|
|
2018-06-30 17:00:16 +02:00
|
|
|
xcb_atom_t
|
2013-06-17 20:58:20 +02:00
|
|
|
winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms);
|
2013-06-17 19:27:56 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
winClipboardInitMonitoredSelections(void);
|
|
|
|
|
|
|
|
#endif
|