Commit Graph

49 Commits

Author SHA1 Message Date
Alan Coopersmith
23e83724df Fix spelling/wording issues
Most (but not all) of these were found by using
  codespell --builtin clear,rare,usage,informal,code,names
but not everything reported by that was fixed.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-07-05 13:07:33 -07:00
Jon Turney
f269e01e1a hw/xwin: Consistently use BOOL type from Xmd.h
This avoids including Xdefs.h, which means we avoid all the issues with
_XSERVER64 effecting how types are defined by that.
2020-04-15 14:13:58 +00:00
Jon Turney
9e02e023b0 hw/xwin: xcbify clipboard integration
Convert clipboard integration code from libX11 to xcb

This drops support for COMPOUND_TEXT.  Presumably some ancient
(pre-2000) clients exist which support that, but not UTF8_STRING, but we
don't have an example to test with. (Given the nature of the thing, the
users of those clients probably work in CJK languages)

Supporting COMPOUND_TEXT would also involve writing (or extracting from
Xlib) support for the ISO 2022 encoding.

v2:
Fix the length of text property set by a SelectionRequest

The length of the text property is not neccessarily the same as the
length of the clipboard text before it is d2u converted (specifically,
if that contains any '\r\n' sequences, it will be shorter as they are
now just '\n')
2020-04-15 14:13:58 +00:00
Jon Turney
f4936de73c hw/xwin: Remove nounicodeclipboard option
Always use CF_UNICODETEXT clipboard format.  Windows will automatically
down-convert to CF_TEXT for clients which request that.

This is subtly different in one way: if CF_TEXT is requested, we now
post CF_UNICODETEXT and it is converted to CF_TEXT *in the locale of the
requesting process*.  Previously, we would convert to CF_TEXT *in our
locale* and post that.

It looks like the code in the !X_HAVE_UTF8_STRING case didn't actually
work correctly, but fortunately that has never been true...
2020-04-15 14:13:58 +00:00
Jon Turney
9f51dfdec3 hw/xwin: Remove support for pre-Vista Win32 clipboard API
The original Win32 clipboard API is widely regarded as terrible, since
it relies on clients co-operatively managing the clipboard viewer chain,
and a single buggy client can break it for all other clients.

The last Windows version only supporting that API was Windows XP (5.1),
EOLed in 2014.

(This requires MinGW-w64 w32api 6.0.0 or later for
Add/RemoveClipboardListener correctly exported by the x86_64 user32
implib)
2020-04-15 14:13:58 +00:00
Jon Turney
d7010cd93a hw/xwin: Warn about too large Windows -> X clipboard pastes
XChangeProperty() requests larger than the ~16MB permitted even with
BigReq will fail BadLength
2020-04-15 14:13:58 +00:00
Jon Turney
56a91f2067 hw/xwin: Implement INCR protocol for X clipboard -> Windows clipboard
Also, relax the timeout mechanism so it allows 1 second between events,
rather than 1 second for the entire transfer, as transfers of large
pastes can take more than 1 second.

Also, prefer UTF8_STRING encoding to COMPOUND_TEXT encoding
2020-04-15 14:13:58 +00:00
Jon Turney
92a52611f6 meson: Link with ws2_32 for socket functions on Windows 2019-04-30 20:07:51 +00:00
Jon Turney
a9a5bd0020 hw/xwin: Fix 'make distcheck'
Add internal.h to SOURCES, omitted from 126c1cfa

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-31 08:37:51 +10:00
Jon Turney
08a3583b5b meson: install xwinclip and Xwinrc man pages
Omitted from a1e8dc05

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2018-05-14 14:13:32 -04:00
Adam Jackson
2e497bf887 man: s/__/@/g
A cosmetic change for automake (though we have to replicate some of
xorg-macros.m4 in manpages.am now), but meson's configure_file() wants
@-delimited strings.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2018-03-27 10:13:17 -04:00
Jon Turney
2d29daf4c6 meson.build: Fix hw/xwin build when dependencies are installed in a non-default location
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Reviewed-by: Eric Anholt <eric@anholt.net>
2018-01-22 13:50:20 -05:00
Daniel Martin
d5379b350f Use ARRAY_SIZE all over the tree
Roundhouse kick replacing the various (sizeof(foo)/sizeof(foo[0])) with
the ARRAY_SIZE macro from dix.h when possible. A semantic patch for
coccinelle has been used first. Additionally, a few macros have been
inlined as they had only one or two users.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-10-30 13:45:20 -04:00
Jon Turney
1f38a31ed3 Add meson.build for XWin server (v2)
This needs a meson with PRs #1784, #1792 and #1794

Future work: remove conditionals which are always on, and simplify redundant
CYGDEBUG conditionals

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Reviewed-by: Eric Anholt <eric@anholt.net>
2017-06-02 09:32:35 -07:00
Jon Turney
008efebda8 xwin: Use WM_CLIPBOARDUPDATE clipboard API
Windows Vista and later have a saner clipboard API where the clipboard
viewer linked list is no longer maintained by applications.  Use it
where available.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2016-02-29 14:04:31 -05:00
Jon TURNEY
e3cfeb949a hw/xwin: printf format fixes for WPARAM and LPARAM types
Some Win32 API types are different fundamental types in the 32-bit and 64-bit

This problem is then further compounded by the fact that whilst both 32-bit
Cygwin and 32-bit MinGW use the ILP32 data model, 64-bit MinGW uses the LLP64
data model, but 64-bit Cygwin uses the LP64 data model.

This makes it impossible to write printf format specifiers which are correct for
all those targets, so we use some macros to provide the correct specifier for
the target.

LPARAM and WPARAM are integer types which can contain a pointer

LPARAM is long in ILP32 and long long in LLP64
WPARAM is unsigned int in ILP32 and unsigned long long in LLP64

Generally, these are just used to passs integer parameters, so for simplicity,
cast to int and use an int-compatible format

In the specific case of WM_CHANGECBCHAIN, they are used to pass HWND, so cast to
that type and print using an appropriate format.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2015-07-07 16:52:50 +01:00
Jon TURNEY
aa83c61f51 hw/xwin: printf format fixes for DWORD type
Some Win32 API types are different fundamental types in the 32-bit and 64-bit
versions.

This problem is then further compounded by the fact that whilst both 32-bit
Cygwin and 32-bit MinGW use the ILP32 data model, 64-bit MinGW uses the LLP64
data model, but 64-bit Cygwin uses the LP64 data model.

This makes it impossible to write printf format specifiers which are correct for
all those targets

In the Win32 API, DWORD is an unsigned, 32-bit type.  It is defined in terms of
an unsigned long, except in the LP64 data model, where it is an unsigned int.

It should always be safe to cast it to unsigned int and use %u or %x.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2015-07-07 16:52:44 +01:00
Jon TURNEY
487f2595c9 hw/xwin: printf format fixes in xevents.c
Window and Atom types derive from XID, which is always unsigned long in client
code, so use %ld format specifier

XTextProperty.nitems is of type unsigned long, so use %lu format specifier

ulReturnBytesLeft is of type unsigned long, so use %lu format specifier

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2015-07-07 16:52:41 +01:00
Jon TURNEY
98798fcf0d hw/xwin: printf format fix in winProcessXEventsTimeout()
remainingTime is computed as a long int, so use %ld format specifier

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2015-07-07 16:52:38 +01:00
Jon TURNEY
dcb797b31f hw/xwin: printf format fixes for HWND type
HWND derives from HANDLE, a pointer type, so we should use the %p format

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2015-07-07 16:52:23 +01:00
Jon TURNEY
f1d1426667 hw/xwin: Ensure format warnings in winclipboard/
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2015-07-07 16:52:20 +01:00
Jon TURNEY
5bf3e5c832 hw/xwin/winclipboard: Link xwinclip with -lpthread
Link xwinclip with -lpthread to fix build for MinGW

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2015-04-22 12:55:25 +01:00
Colin Harrison
5920433c3a hw/xwin: Don't allocate one wchar_t too much for unicode text placed on the Windows clipboard
The count of wchar_t returned by MultiByteToWideChar() includes the terminating
null character, so don't add one to it.

Also, reduce the scope of various length variables

Signed-off-by: Colin Harrison <colin.harrison@virgin.net>
Reviewed-by: Jon TURNEY <jon.turney@dronecode.org.uk>
2014-11-09 14:24:44 +00:00
Jon TURNEY
d172cd630d hw/xwin: Fix hang on shutdown when we own the clipboard.
If we are the clipboard owner when we are shutdown, we recieve a
WM_RENDERALLFORMATS, to render the clipboard, so it's contents will remain
available to other applications.  Unfortunately, this is far too late to do
anything useful with, as the server is waiting for the clipboard thread to exit,
and so can't process requests to convert clipboard contents.

Change so we just do nothing on WM_RENDERALLFORMATS. (I'm not convinced that
WM_RENDERALLFORMATS has ever worked usefully, in any case).

(To make this work, I guess we would need to rearrange the way shutdown works
completely: first synchronously stop the clipboard, then stop the X server)

We also then receive a WM_DRAWCLIPBOARD, perhaps telling us that the available
clipboard formats have changed (as ones which haven't been rendered are now
removed), but the clipboard owner is now the system, not us, which we have to
arrange to ignore.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-11-09 14:22:53 +00:00
Jon TURNEY
94d433c8cb 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-11-09 14:22:51 +00:00
Jon TURNEY
b4a08e642b hw/xwin: Improve reliability of clipboard X->Windows pastes
Sometimes, particularly with large clipboard pastes to Windows, we could end up
waiting for the timeout to expire, rather than pasting the data.

Various changes to improve reliability:

1. Use XFlush() not XSync() in winProcessXEventsTimeout().

It makes no sense to ensure we have received replies to outstanding requests if
we are going to wait for them using select()

2. Add XFlush() to winClipboardProc()

Make sure we have sent any requests before we wait using select()

3. Don't use FD_ISSET() to check which fd is ready

This looks like a Cygwin select() bug in that it sometimes returns 0 with an
empty fd set before the timeout expires, but a fd appears to be ready.

Add select() return value to debug output when we are warning that this has
happened.

4. Drain event queues before entering select()

Unconditionally drain event queues before entering select().  This seems to be
the recommended way of writing select() and X event processing loops.

winClipboardFlushXEvents() checks using XPending(), and
winClipboardFlushWindowsMessageQueue() checks using PeekMessage() so this is
safe against blocking, but means that may not need to enter select() at all
sometimes.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-11-09 14:22:48 +00:00
Jon TURNEY
c03f9e23c2 hw/xwin: Add controls for enabling/disabling monitoring of PRIMARY selection
xwinclip: Add -noprimary option
Xwin: Add -primary and -noprimary options and tray-menu control

v2:
Use Bool type for fPrimarySelection
Add -noprimary to usage message
Fix indentation in hw/xwin/winwndproc.c

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-11-09 14:22:35 +00:00
Jon TURNEY
851b504199 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 a9aca218f5 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>
2014-11-06 12:23:03 +00:00
Jon TURNEY
4db1241037 hw/xwin: In SelectionNotify, don't pointlessly retrieve just the size of the property
Don't pointlessly retrieve just the size of the property, if we are then going
to assume we can retrieve the whole property in one request anyhow...

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-11-06 12:10:08 +00:00
Jon TURNEY
c5ad92077e hw/xwin: In SelectionNotify, delete the property containing returned data after we have retrieved it
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-11-06 12:09:12 +00:00
Jon TURNEY
329e8125aa hw/xwin: Fix compilation with -Werror=declaration-after-statement
xevents.c: In function 'winClipboardInitMonitoredSelections':
xevents.c:129:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for (int i = 0; i < CLIP_NUM_SELECTIONS; ++i)

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-10-09 16:30:49 +01:00
Jon TURNEY
1d6334dd0c hw/xwin: Undefine _XSERVER64 in hw/xwin/winclipboard
Including any server header might define the macro _XSERVER64 on 64 bit
machines. That macro must _NOT_ be defined for Xlib client code, otherwise bad
things happen. So let's undef that macro if necessary.

Remove server directories from include path to ensure no server includes are
included

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:19:06 +01:00
Jon TURNEY
7ca9330194 hw/xwin: Only add to XSetIOErrorHandler() handler chain once
Only use XSetIOErrorHandler() to add to the global XSetIOErrorHandler() chain
once.  If we do it every restart, then we make a loop in the handler chain, and
we end up with a thread spinning in that loop when the server shuts down...

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:19:04 +01:00
Jon TURNEY
5819a02d46 hw/xwin: Add a basic manpage for xwinclip
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:19:01 +01:00
Jon TURNEY
492c924c85 hw/xwin: In clipboard function prototypes, use Window type, not int type
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:18:58 +01:00
Jon TURNEY
4a38c3bda2 hw/xwin: Remove XOpenDisplay() retry code
Remove XOpenDisplay() retry code.  This isn't a sensible thing for the
application to be doing, and XWin server needs to retry much more than just
XOpenDisplay().

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:18:56 +01:00
Jon TURNEY
4fc62aef80 hw/xwin: Improve comment about why we can't XCloseDisplay()
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:18:53 +01:00
Jon TURNEY
89eb7bdcad hw/xwin: Remove setjmp()/longjmp() error constants
Check specially that setjmp() returned a value which we don't pass to longjmp()
seems a bit over-complex.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:18:51 +01:00
Jon TURNEY
d0353bbe57 hw/xwin: Move WIN_MSG_QUEUE_FNAME to where it's used
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:18:48 +01:00
Jon TURNEY
fa0da5a020 hw/xwin: Use header for prototypes in textconv.c
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:18:46 +01:00
Jon TURNEY
cbe133752d hw/xwin: Remove unused X includes from internal.h and add them where needed
Also removing server headers we might clash with and no longer need.  Make
a few adjustments to allow for this change:

- provide a prototype of ErrorF()
- use the MAX() macro provided by sys/param.h, not the max() macro provided by misc.h
- use the X 'Bool' type rather than the unwrapped Windows 'BOOL' type

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
2014-09-13 14:18:43 +01:00
Jon TURNEY
52f3cf3c61 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>
2014-09-13 14:18:41 +01:00
Jon TURNEY
5992550c4c 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>
2014-09-13 14:18:38 +01:00
Jon TURNEY
5ae674ae6d 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>
2014-09-13 14:18:36 +01:00
Jon TURNEY
e1cf2b47be 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>
2014-09-13 14:18:33 +01:00
Jon TURNEY
be61a1fc7e 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>
2014-09-13 14:18:30 +01:00
Jon TURNEY
126c1cfaa5 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>
2014-09-13 14:13:07 +01:00
Jon TURNEY
30c535219e 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>
2014-09-13 14:06:30 +01:00
Jon TURNEY
88d4459704 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>
2014-09-13 14:06:28 +01:00