diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2019-06-17 18:12:24 +0100 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2019-06-17 18:12:24 +0100 |
commit | e3c5faf77564bf9ed61a35baef505f0a25dacb25 (patch) | |
tree | a1880e828aa44ae34d113c9e942ca9ae40d231aa | |
parent | de6b928db83bf8d2b705583d89b5ad3c702bef15 (diff) | |
parent | d356dfc55d00b2a230d2798da0822325b995dfa9 (diff) |
Merge branch 'cygwin-patches-for-1.20' into cygwin-release-1.20xserver-cygwin-1.20.5-1
-rw-r--r-- | .appveyor.yml | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | doc/c-extensions | 2 | ||||
-rw-r--r-- | hw/xwin/InitOutput.c | 4 | ||||
-rw-r--r-- | hw/xwin/man/XWin.man | 3 | ||||
-rw-r--r-- | hw/xwin/meson.build | 1 | ||||
-rw-r--r-- | hw/xwin/win.h | 8 | ||||
-rw-r--r-- | hw/xwin/winauth.c | 27 | ||||
-rw-r--r-- | hw/xwin/winauth.h | 26 | ||||
-rw-r--r-- | hw/xwin/winclipboard/internal.h | 42 | ||||
-rw-r--r-- | hw/xwin/winclipboard/meson.build | 7 | ||||
-rw-r--r-- | hw/xwin/winclipboard/textconv.c | 9 | ||||
-rw-r--r-- | hw/xwin/winclipboard/thread.c | 298 | ||||
-rw-r--r-- | hw/xwin/winclipboard/winclipboard.h | 7 | ||||
-rw-r--r-- | hw/xwin/winclipboard/wndproc.c | 325 | ||||
-rw-r--r-- | hw/xwin/winclipboard/xevents.c | 753 | ||||
-rw-r--r-- | hw/xwin/winclipboard/xwinclip.c | 53 | ||||
-rw-r--r-- | hw/xwin/winclipboard/xwinclip.man | 3 | ||||
-rw-r--r-- | hw/xwin/winclipboardinit.c | 10 | ||||
-rw-r--r-- | hw/xwin/winglobals.c | 1 | ||||
-rw-r--r-- | hw/xwin/winglobals.h | 1 | ||||
-rw-r--r-- | hw/xwin/winmultiwindowicons.c | 3 | ||||
-rw-r--r-- | hw/xwin/winmultiwindowicons.h | 2 | ||||
-rw-r--r-- | hw/xwin/winmultiwindowwm.c | 4 | ||||
-rw-r--r-- | hw/xwin/winprocarg.c | 9 | ||||
-rw-r--r-- | hw/xwin/winwindow.h | 2 | ||||
-rw-r--r-- | hw/xwin/winwndproc.c | 3 |
27 files changed, 581 insertions, 1026 deletions
diff --git a/.appveyor.yml b/.appveyor.yml index 632b78b6e..71d35ae20 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -15,7 +15,7 @@ install: - if "%BUILD%"=="i686-pc-cygwin" set SETUP=setup-x86.exe && set CYGWIN_ROOT=C:\cygwin - curl -fsSL https://gist.githubusercontent.com/jon-turney/0338af595313f598bfab15a0ac0df847/raw/bd0eeca6be899e7846aa988fbcf15e4e12f5f842/zp_libtool_cleanlafiles.sh -o %CYGWIN_ROOT%\etc\postinstall\zp_libtool_cleanlafiles.sh - echo Updating Cygwin and installing build prerequisites -- '%CYGWIN_ROOT%\%SETUP% -qnNdO -R "%CYGWIN_ROOT%" -s "%CYGWIN_MIRROR%" -l "%CACHE%" -g -P "meson,binutils,bison,bzip2,diffutils,fileutils,findutils,flex,gawk,gcc-core,make,patch,pkg-config,python3,sed,tar,xorgproto,windowsdriproto,libdmx-devel,libfontenc-devel,libfreetype-devel,libGL-devel,libpixman1-devel,libX11-devel,libXRes-devel,libXau-devel,libXaw-devel,libXdmcp-devel,libXext-devel,libXfont2-devel,libXi-devel,libXinerama-devel,libXmu-devel,libXpm-devel,libXrender-devel,libXtst-devel,libxcb-ewmh-devel,libxcb-icccm-devel,libxcb-image-devel,libxcb-keysyms-devel,libxcb-randr-devel,libxcb-render-devel,libxcb-render-util-devel,libxcb-shape-devel,libxcb-util-devel,libxcb-xkb-devel,libxkbfile-devel,zlib-devel,font-util,khronos-opengl-registry,python3-lxml,xorg-util-macros,xtrans,xkbcomp-devel,xkeyboard-config,libnettle-devel,libepoxy-devel,libtirpc-devel,libxcb-composite-devel,ImageMagick"' +- '%CYGWIN_ROOT%\%SETUP% -qnNdO -R "%CYGWIN_ROOT%" -s "%CYGWIN_MIRROR%" -l "%CACHE%" -g -P "meson,binutils,bison,bzip2,diffutils,fileutils,findutils,flex,gawk,gcc-core,make,patch,pkg-config,python3,sed,tar,xorgproto,windowsdriproto,libdmx-devel,libfontenc-devel,libfreetype-devel,libGL-devel,libpixman1-devel,libXRes-devel,libXaw-devel,libXdmcp-devel,libXext-devel,libXfont2-devel,libXi-devel,libXinerama-devel,libXmu-devel,libXpm-devel,libXrender-devel,libXtst-devel,libxcb-ewmh-devel,libxcb-icccm-devel,libxcb-image-devel,libxcb-keysyms-devel,libxcb-randr-devel,libxcb-render-devel,libxcb-render-util-devel,libxcb-shape-devel,libxcb-util-devel,libxcb-xkb-devel,libxkbfile-devel,zlib-devel,font-util,khronos-opengl-registry,python3-lxml,xorg-util-macros,xtrans,xkbcomp-devel,xkeyboard-config,libnettle-devel,libepoxy-devel,libtirpc-devel,libxcb-composite-devel,ImageMagick"' - echo Install done cache: - C:\cache diff --git a/configure.ac b/configure.ac index f6e3fa275..8c134ba11 100644 --- a/configure.ac +++ b/configure.ac @@ -2142,7 +2142,7 @@ if test "x$XWIN" = xyes; then AC_DEFINE_UNQUOTED(__VENDORDWEBSUPPORT__, ["$VENDOR_WEB"], [Vendor web address for support]) AC_CHECK_TOOL(WINDRES, windres) - PKG_CHECK_MODULES([XWINMODULES],[x11 xau xdmcp xfixes x11-xcb xcb-aux xcb-composite xcb-image xcb-ewmh xcb-icccm]) + PKG_CHECK_MODULES([XWINMODULES],[xcb-aux xcb-composite xcb-image xcb-ewmh xcb-icccm xcb-xfixes]) if test "x$WINDOWSDRI" = xauto; then PKG_CHECK_EXISTS([windowsdriproto], [WINDOWSDRI=yes], [WINDOWSDRI=no]) diff --git a/doc/c-extensions b/doc/c-extensions index e5fde3440..7dc58a215 100644 --- a/doc/c-extensions +++ b/doc/c-extensions @@ -62,7 +62,7 @@ TODO: Solaris. TODO: *BSD. -Windows-dependent code assumes at least NT 5.1. +Windows-dependent code assumes at least NT 6.0. OSX support is generally limited to the most recent version. Currently that means 10.5. diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index bf34466ad..53ba658d9 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -66,6 +66,7 @@ typedef WINAPI HRESULT(*SHGETFOLDERPATHPROC) (HWND hwndOwner, #include "glx/glwindows.h" #include "dri/windowsdri.h" #endif +#include "winauth.h" /* * References to external symbols @@ -820,9 +821,6 @@ winUseMsg(void) "\tDo not draw a window border, title bar, etc. Windowed\n" "\tmode only.\n"); - ErrorF("-nounicodeclipboard\n" - "\tDo not use Unicode clipboard even if on a NT-based platform.\n"); - ErrorF("-[no]primary\n" "\tWhen clipboard integration is enabled, map the X11 PRIMARY selection\n" "\tto the Windows clipboard. Default is enabled.\n"); diff --git a/hw/xwin/man/XWin.man b/hw/xwin/man/XWin.man index ac45108a3..3e10db3e5 100644 --- a/hw/xwin/man/XWin.man +++ b/hw/xwin/man/XWin.man @@ -233,9 +233,6 @@ icon per screen. You can globally disable tray icons with \fB\-notrayicon\fP, then enable it for specific screens with \fB\-trayicon\fP for those screens. .TP 8 -.B \-nounicodeclipboard -Do not use Unicode clipboard even if on a NT-based platform. -.TP 8 .B \-[no]unixkill Enable or disable the \fICtrl-Alt-Backspace\fP key combination as a signal to exit the X Server. The \fICtrl-Alt-Backspace\fP key combination diff --git a/hw/xwin/meson.build b/hw/xwin/meson.build index 34efcb2aa..2f5891191 100644 --- a/hw/xwin/meson.build +++ b/hw/xwin/meson.build @@ -144,7 +144,6 @@ srcs_windows += pfiles xwin_dep = [ common_dep, - dependency('x11-xcb'), dependency('xcb-aux'), dependency('xcb-image'), dependency('xcb-ewmh'), diff --git a/hw/xwin/win.h b/hw/xwin/win.h index 9790cbe7e..d68e56ad7 100644 --- a/hw/xwin/win.h +++ b/hw/xwin/win.h @@ -670,14 +670,6 @@ Bool winAllocateCmapPrivates(ColormapPtr pCmap); /* - * winauth.c - */ - -Bool - winGenerateAuthorization(void); -void winSetAuthorization(void); - -/* * winblock.c */ diff --git a/hw/xwin/winauth.c b/hw/xwin/winauth.c index 14278390f..4764d4bfb 100644 --- a/hw/xwin/winauth.c +++ b/hw/xwin/winauth.c @@ -32,7 +32,8 @@ #include <xwin-config.h> #endif -#include "win.h" +#include "winauth.h" +#include "winmsg.h" /* Includes for authorization */ #include "securitysrv.h" @@ -40,14 +41,6 @@ #include <xcb/xcb.h> -/* Need to get this from Xlib.h */ -extern void XSetAuthorization( - const char * /* name */, - int /* namelen */, - const char * /* data */, - int /* datalen */ -); - /* * Constants */ @@ -68,9 +61,7 @@ static xcb_auth_info_t auth_info; */ #ifndef XCSECURITY - -static - XID +static XID GenerateAuthorization(unsigned name_length, const char *name, unsigned data_length, @@ -86,10 +77,12 @@ GenerateAuthorization(unsigned name_length, * Generate authorization cookie for internal server clients */ -Bool +BOOL winGenerateAuthorization(void) { +#ifdef XCSECURITY SecurityAuthorizationPtr pAuth = NULL; +#endif /* Call OS layer to generate authorization key */ g_authId = GenerateAuthorization(strlen(AUTH_NAME), @@ -141,14 +134,6 @@ winGenerateAuthorization(void) return TRUE; } -/* Use our generated cookie for authentication */ -void -winSetAuthorization(void) -{ - XSetAuthorization(AUTH_NAME, - strlen(AUTH_NAME), g_pAuthData, g_uiAuthDataLen); -} - xcb_auth_info_t * winGetXcbAuthInfo(void) { diff --git a/hw/xwin/winauth.h b/hw/xwin/winauth.h new file mode 100644 index 000000000..97cfe52a1 --- /dev/null +++ b/hw/xwin/winauth.h @@ -0,0 +1,26 @@ +/* + * 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 (including the next + * paragraph) 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 + * THE AUTHORS OR COPYRIGHT HOLDERS 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. + */ + +#include <xcb/xcb.h> +#include <X11/Xmd.h> // for BOOL + +BOOL winGenerateAuthorization(void); +xcb_auth_info_t * winGetXcbAuthInfo(void); diff --git a/hw/xwin/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h index 766a836ae..368fa7057 100644 --- a/hw/xwin/winclipboard/internal.h +++ b/hw/xwin/winclipboard/internal.h @@ -31,8 +31,9 @@ #ifndef WINCLIPBOARD_INTERNAL_H #define WINCLIPBOARD_INTERNAL_H -/* X headers */ -#include <X11/Xlib.h> +#include <xcb/xproto.h> +#include <X11/Xfuncproto.h> // for _X_ATTRIBUTE_PRINTF +#include <X11/Xmd.h> // for BOOL /* Windows headers */ #include <X11/Xwindows.h> @@ -42,7 +43,6 @@ #define WIN_XEVENTS_NOTIFY_DATA 3 #define WIN_XEVENTS_NOTIFY_TARGETS 4 -#define WM_WM_REINIT (WM_USER + 1) #define WM_WM_QUIT (WM_USER + 2) #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) @@ -68,38 +68,29 @@ void * winclipboardthread.c */ - typedef struct { - Atom atomClipboard; - Atom atomLocalProperty; - Atom atomUTF8String; - Atom atomCompoundText; - Atom atomTargets; - Atom atomIncr; + xcb_atom_t atomClipboard; + xcb_atom_t atomLocalProperty; + xcb_atom_t atomUTF8String; + xcb_atom_t atomCompoundText; + xcb_atom_t atomTargets; + xcb_atom_t atomIncr; } ClipboardAtoms; -/* Modern clipboard API functions */ -typedef wBOOL WINAPI (*ADDCLIPBOARDFORMATLISTENERPROC)(HWND hwnd); -typedef wBOOL WINAPI (*REMOVECLIPBOARDFORMATLISTENERPROC)(HWND hwnd); - -extern Bool g_fHasModernClipboardApi; -extern ADDCLIPBOARDFORMATLISTENERPROC g_fpAddClipboardFormatListener; -extern REMOVECLIPBOARDFORMATLISTENERPROC g_fpRemoveClipboardFormatListener; - /* * winclipboardwndproc.c */ -Bool winClipboardFlushWindowsMessageQueue(HWND hwnd); +BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd); LRESULT CALLBACK winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); typedef struct { - Display *pClipboardDisplay; - Window iClipboardWindow; + xcb_connection_t *pClipboardDisplay; + xcb_window_t iClipboardWindow; ClipboardAtoms *atoms; } ClipboardWindowCreationParams; @@ -109,18 +100,17 @@ typedef struct typedef struct { - Bool fUseUnicode; - Atom *targetList; + xcb_atom_t *targetList; unsigned char *incr; unsigned long int incrsize; } ClipboardConversionData; int winClipboardFlushXEvents(HWND hwnd, - Window iWindow, Display * pDisplay, ClipboardConversionData *data, ClipboardAtoms *atom); - + xcb_window_t iWindow, xcb_connection_t * pDisplay, + ClipboardConversionData *data, ClipboardAtoms *atoms); -Atom +xcb_atom_t winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms); void diff --git a/hw/xwin/winclipboard/meson.build b/hw/xwin/winclipboard/meson.build index 0395eb32d..c239f5325 100644 --- a/hw/xwin/winclipboard/meson.build +++ b/hw/xwin/winclipboard/meson.build @@ -12,8 +12,10 @@ xwin_clipboard = static_library( include_directories: inc, c_args: '-DHAVE_XWIN_CONFIG_H', dependencies: [ - dependency('x11'), - dependency('xfixes'), + dependency('xcb'), + dependency('xcb-aux'), + dependency('xcb-icccm'), + dependency('xcb-xfixes'), ], ) @@ -27,7 +29,6 @@ executable( srcs_xwinclip, link_with: xwin_clipboard, link_args: ['-lgdi32', '-lpthread'], - dependencies: [dependency('x11')], install: true, ) diff --git a/hw/xwin/winclipboard/textconv.c b/hw/xwin/winclipboard/textconv.c index 9c9cb3529..651ccc666 100644 --- a/hw/xwin/winclipboard/textconv.c +++ b/hw/xwin/winclipboard/textconv.c @@ -32,15 +32,6 @@ #include <xwin-config.h> #endif -/* - * 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. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - #include <stdlib.h> #include "internal.h" diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c index 221776567..cf908c600 100644 --- a/hw/xwin/winclipboard/thread.c +++ b/hw/xwin/winclipboard/thread.c @@ -36,19 +36,9 @@ #define HAS_WINSOCK 1 #endif -/* - * 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. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - #include <assert.h> #include <unistd.h> #include <fcntl.h> -#include <setjmp.h> #include <pthread.h> #include <locale.h> #include <sys/param.h> // for MAX() macro @@ -59,9 +49,11 @@ #include <errno.h> #endif -#include <X11/Xatom.h> -#include <X11/Xlocale.h> -#include <X11/extensions/Xfixes.h> +#include <xcb/xcb.h> +#include <xcb/xcb_aux.h> +#include <xcb/xcb_icccm.h> +#include <xcb/xfixes.h> + #include "winclipboard.h" #include "internal.h" @@ -79,29 +71,32 @@ */ static HWND g_hwndClipboard = NULL; -static jmp_buf g_jmpEntry; -static XIOErrorHandler g_winClipboardOldIOErrorHandler; -static pthread_t g_winClipboardProcThread; int xfixes_event_base; int xfixes_error_base; -Bool g_fHasModernClipboardApi = FALSE; -ADDCLIPBOARDFORMATLISTENERPROC g_fpAddClipboardFormatListener; -REMOVECLIPBOARDFORMATLISTENERPROC g_fpRemoveClipboardFormatListener; - /* * Local function prototypes */ static HWND -winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow, ClipboardAtoms *atoms); +winClipboardCreateMessagingWindow(xcb_connection_t *conn, xcb_window_t iWindow, ClipboardAtoms *atoms); -static int - winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr); - -static int - winClipboardIOErrorHandler(Display * pDisplay); +static xcb_atom_t +intern_atom(xcb_connection_t *conn, const char *atomName) +{ + xcb_intern_atom_reply_t *atom_reply; + xcb_intern_atom_cookie_t atom_cookie; + xcb_atom_t atom = XCB_ATOM_NONE; + + atom_cookie = xcb_intern_atom(conn, 0, strlen(atomName), atomName); + atom_reply = xcb_intern_atom_reply(conn, atom_cookie, NULL); + if (atom_reply) { + atom = atom_reply->atom; + free(atom_reply); + } + return atom; +} /* * Create X11 and Win32 messaging windows, and run message processing loop @@ -109,14 +104,13 @@ static int * returns TRUE if shutdown was signalled to loop, FALSE if some error occurred */ -Bool -winClipboardProc(Bool fUseUnicode, char *szDisplay) +BOOL +winClipboardProc(char *szDisplay, xcb_auth_info_t *auth_info) { ClipboardAtoms atoms; int iReturn; HWND hwnd = NULL; int iConnectionNumber = 0; - #ifdef HAS_DEVWINDOWS int fdMessageQueue = 0; #else @@ -124,72 +118,27 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay) #endif fd_set fdsRead; int iMaxDescriptor; - Display *pDisplay = NULL; - Window iWindow = None; + xcb_connection_t *conn; + xcb_window_t iWindow = XCB_NONE; int iSelectError; - Bool fShutdown = FALSE; - static Bool fErrorHandlerSet = FALSE; + BOOL fShutdown = FALSE; ClipboardConversionData data; + int screen; winDebug("winClipboardProc - Hello\n"); - { - const char *locale; - - /* Allow multiple threads to access Xlib */ - if (XInitThreads() == 0) { - ErrorF("winClipboardProc - XInitThreads failed.\n"); - } - - /* - * setlocale applies to all threads in the current process. - * Apply locale specified in LANG environment variable. - */ - locale = setlocale(LC_ALL, ""); - if (!locale) { - ErrorF("winClipboardProc - setlocale failed.\n"); - } - - /* See if X supports the current locale */ - if (XSupportsLocale() == FALSE) { - ErrorF("Warning: Locale '%s' not supported by X, falling back to 'C' locale.\n", locale); - setlocale(LC_ALL, "C"); - } - } - - g_fpAddClipboardFormatListener = (ADDCLIPBOARDFORMATLISTENERPROC)GetProcAddress(GetModuleHandle("user32"),"AddClipboardFormatListener"); - g_fpRemoveClipboardFormatListener = (REMOVECLIPBOARDFORMATLISTENERPROC)GetProcAddress(GetModuleHandle("user32"),"RemoveClipboardFormatListener"); - g_fHasModernClipboardApi = g_fpAddClipboardFormatListener && g_fpRemoveClipboardFormatListener; - ErrorF("OS maintains clipboard viewer chain: %s\n", g_fHasModernClipboardApi ? "yes" : "no"); - - g_winClipboardProcThread = pthread_self(); - - /* Set error handler */ - if (!fErrorHandlerSet) { - XSetErrorHandler(winClipboardErrorHandler); - g_winClipboardOldIOErrorHandler = - XSetIOErrorHandler(winClipboardIOErrorHandler); - fErrorHandlerSet = TRUE; - } - - /* Set jump point for Error exits */ - if (setjmp(g_jmpEntry)) { - ErrorF("winClipboardProc - setjmp returned for IO Error Handler.\n"); - goto winClipboardProc_Done; - } - /* Make sure that the display opened */ - pDisplay = XOpenDisplay(szDisplay); - if (pDisplay == NULL) { + conn = xcb_connect_to_display_with_auth_info(szDisplay, auth_info, &screen); + if (xcb_connection_has_error(conn)) { ErrorF("winClipboardProc - Failed opening the display, giving up\n"); goto winClipboardProc_Done; } - ErrorF("winClipboardProc - XOpenDisplay () returned and " + ErrorF("winClipboardProc - xcb_connect () returned and " "successfully opened the display.\n"); /* Get our connection number */ - iConnectionNumber = XConnectionNumber(pDisplay); + iConnectionNumber = xcb_get_file_descriptor(conn); #ifdef HAS_DEVWINDOWS /* Open a file descriptor for the windows message queue */ @@ -205,56 +154,75 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay) iMaxDescriptor = iConnectionNumber + 1; #endif - if (!XFixesQueryExtension(pDisplay, &xfixes_event_base, &xfixes_error_base)) + const xcb_query_extension_reply_t *xfixes_query; + xfixes_query = xcb_get_extension_data(conn, &xcb_xfixes_id); + if (!xfixes_query->present) ErrorF ("winClipboardProc - XFixes extension not present\n"); + xfixes_event_base = xfixes_query->first_event; + xfixes_error_base = xfixes_query->first_error; + /* Must advise server of XFIXES version we require */ + xcb_xfixes_query_version_unchecked(conn, 1, 0); /* 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); - atoms.atomIncr = XInternAtom (pDisplay, "INCR", False); + atoms.atomClipboard = intern_atom(conn, "CLIPBOARD"); + atoms.atomLocalProperty = intern_atom(conn, "CYGX_CUT_BUFFER"); + atoms.atomUTF8String = intern_atom(conn, "UTF8_STRING"); + atoms.atomCompoundText = intern_atom(conn, "COMPOUND_TEXT"); + atoms.atomTargets = intern_atom(conn, "TARGETS"); + atoms.atomIncr = intern_atom(conn, "INCR"); + + xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screen); + xcb_window_t root_window_id = root_screen->root; /* Create a messaging window */ - iWindow = XCreateSimpleWindow(pDisplay, - XDefaultRootWindow(pDisplay), - 1, 1, - 500, 500, - 0, - XBlackPixel(pDisplay, 0), - XBlackPixel(pDisplay, 0)); - if (iWindow == 0) { + iWindow = xcb_generate_id(conn); + xcb_void_cookie_t cookie = xcb_create_window_checked(conn, + XCB_COPY_FROM_PARENT, + iWindow, + root_window_id, + 1, 1, + 500, 500, + 0, + XCB_WINDOW_CLASS_INPUT_ONLY, + XCB_COPY_FROM_PARENT, + 0, + NULL); + + xcb_generic_error_t *error; + if ((error = xcb_request_check(conn, cookie))) { ErrorF("winClipboardProc - Could not create an X window.\n"); + free(error); goto winClipboardProc_Done; } - XStoreName(pDisplay, iWindow, "xwinclip"); + xcb_icccm_set_wm_name(conn, iWindow, XCB_ATOM_STRING, 8, strlen("xwinclip"), "xwinclip"); /* Select event types to watch */ - if (XSelectInput(pDisplay, iWindow, PropertyChangeMask) == BadWindow) - ErrorF("winClipboardProc - XSelectInput generated BadWindow " - "on messaging window\n"); - - XFixesSelectSelectionInput (pDisplay, - iWindow, - XA_PRIMARY, - XFixesSetSelectionOwnerNotifyMask | - XFixesSelectionWindowDestroyNotifyMask | - XFixesSelectionClientCloseNotifyMask); + const static uint32_t values[] = { XCB_EVENT_MASK_PROPERTY_CHANGE }; + cookie = xcb_change_window_attributes_checked(conn, iWindow, XCB_CW_EVENT_MASK, values); + if ((error = xcb_request_check(conn, cookie))) { + ErrorF("winClipboardProc - Could not set event mask on messaging window\n"); + free(error); + } - XFixesSelectSelectionInput (pDisplay, - iWindow, - atoms.atomClipboard, - XFixesSetSelectionOwnerNotifyMask | - XFixesSelectionWindowDestroyNotifyMask | - XFixesSelectionClientCloseNotifyMask); + xcb_xfixes_select_selection_input(conn, + iWindow, + XCB_ATOM_PRIMARY, + XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER | + XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY | + XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE); + xcb_xfixes_select_selection_input(conn, + iWindow, + atoms.atomClipboard, + XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER | + XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY | + XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE); /* Initialize monitored selection state */ winClipboardInitMonitoredSelections(); /* Create Windows messaging window */ - hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow, &atoms); + hwnd = winClipboardCreateMessagingWindow(conn, iWindow, &atoms); /* Save copy of HWND */ g_hwndClipboard = hwnd; @@ -262,25 +230,22 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay) /* Assert ownership of selections if Win32 clipboard is owned */ if (NULL != GetClipboardOwner()) { /* PRIMARY */ - iReturn = XSetSelectionOwner(pDisplay, XA_PRIMARY, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow || - XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) { + cookie = xcb_set_selection_owner_checked(conn, iWindow, XCB_ATOM_PRIMARY, XCB_CURRENT_TIME); + if ((error = xcb_request_check(conn, cookie))) { ErrorF("winClipboardProc - Could not set PRIMARY owner\n"); + free(error); goto winClipboardProc_Done; } /* CLIPBOARD */ - iReturn = XSetSelectionOwner(pDisplay, atoms.atomClipboard, - iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow || - XGetSelectionOwner(pDisplay, atoms.atomClipboard) != iWindow) { + cookie = xcb_set_selection_owner_checked(conn, iWindow, atoms.atomClipboard, XCB_CURRENT_TIME); + if ((error = xcb_request_check(conn, cookie))) { ErrorF("winClipboardProc - Could not set CLIPBOARD owner\n"); + free(error); goto winClipboardProc_Done; } } - data.fUseUnicode = fUseUnicode; data.incr = NULL; data.incrsize = 0; @@ -288,8 +253,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay) while (1) { /* Process X events */ - winClipboardFlushXEvents(hwnd, - iWindow, pDisplay, &data, &atoms); + winClipboardFlushXEvents(hwnd, iWindow, conn, &data, &atoms); /* Process Windows messages */ if (!winClipboardFlushWindowsMessageQueue(hwnd)) { @@ -299,7 +263,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay) } /* We need to ensure that all pending requests are sent */ - XFlush(pDisplay); + xcb_flush(conn); /* Setup the file descriptor set */ /* @@ -381,12 +345,13 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay) } /* Close our X window */ - if (pDisplay && iWindow) { - iReturn = XDestroyWindow(pDisplay, iWindow); - if (iReturn == BadWindow) - ErrorF("winClipboardProc - XDestroyWindow returned BadWindow.\n"); + if (!xcb_connection_has_error(conn) && iWindow) { + cookie = xcb_destroy_window_checked(conn, iWindow); + if ((error = xcb_request_check(conn, cookie))) + ErrorF("winClipboardProc - XDestroyWindow failed.\n"); else ErrorF("winClipboardProc - XDestroyWindow succeeded.\n"); + free(error); } #ifdef HAS_DEVWINDOWS @@ -395,26 +360,15 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay) close(fdMessageQueue); #endif -#if 0 /* - * FIXME: XCloseDisplay hangs if we call it - * - * XCloseDisplay() calls XSync(), so any outstanding errors are reported. - * If we are built into the server, this can deadlock if the server is - * in the process of exiting and waiting for this thread to exit. + * xcb_disconnect() does not sync, so is safe to call even when we are built + * into the server. Unlike XCloseDisplay() there will be no deadlock if the + * server is in the process of exiting and waiting for this thread to exit. */ - - /* Discard any remaining events */ - XSync(pDisplay, TRUE); - - /* Select event types to watch */ - XSelectInput(pDisplay, XDefaultRootWindow(pDisplay), None); - - /* Close our X display */ - if (pDisplay) { - XCloseDisplay(pDisplay); + if (!xcb_connection_has_error(conn)) { + /* Close our X display */ + xcb_disconnect(conn); } -#endif /* global clipboard variable reset */ g_hwndClipboard = NULL; @@ -427,7 +381,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay) */ static HWND -winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow, ClipboardAtoms *atoms) +winClipboardCreateMessagingWindow(xcb_connection_t *conn, xcb_window_t iWindow, ClipboardAtoms *atoms) { WNDCLASSEX wc; ClipboardWindowCreationParams cwcp; @@ -449,7 +403,7 @@ winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow, ClipboardAt RegisterClassEx(&wc); /* Information to be passed to WM_CREATE */ - cwcp.pClipboardDisplay = pDisplay; + cwcp.pClipboardDisplay = conn; cwcp.iClipboardWindow = iWindow; cwcp.atoms = atoms; @@ -477,42 +431,6 @@ winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow, ClipboardAt return hwnd; } -/* - * winClipboardErrorHandler - Our application specific error handler - */ - -static int -winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr) -{ - char pszErrorMsg[100]; - - XGetErrorText(pDisplay, pErr->error_code, pszErrorMsg, sizeof(pszErrorMsg)); - ErrorF("winClipboardErrorHandler - ERROR: \n\t%s\n" - "\tSerial: %lu, Request Code: %d, Minor Code: %d\n", - pszErrorMsg, pErr->serial, pErr->request_code, pErr->minor_code); - return 0; -} - -/* - * winClipboardIOErrorHandler - Our application specific IO error handler - */ - -static int -winClipboardIOErrorHandler(Display * pDisplay) -{ - ErrorF("winClipboardIOErrorHandler!\n"); - - if (pthread_equal(pthread_self(), g_winClipboardProcThread)) { - /* Restart at the main entry point */ - longjmp(g_jmpEntry, 2); - } - - if (g_winClipboardOldIOErrorHandler) - g_winClipboardOldIOErrorHandler(pDisplay); - - return 0; -} - void winClipboardWindowDestroy(void) { @@ -520,11 +438,3 @@ winClipboardWindowDestroy(void) SendMessage(g_hwndClipboard, WM_WM_QUIT, 0, 0); } } - -void -winFixClipboardChain(void) -{ - if (g_hwndClipboard) { - PostMessage(g_hwndClipboard, WM_WM_REINIT, 0, 0); - } -} diff --git a/hw/xwin/winclipboard/winclipboard.h b/hw/xwin/winclipboard/winclipboard.h index 9c5c568a7..243aa24dc 100644 --- a/hw/xwin/winclipboard/winclipboard.h +++ b/hw/xwin/winclipboard/winclipboard.h @@ -27,12 +27,15 @@ #ifndef WINCLIPBOARD_H #define WINCLIPBOARD_H -Bool winClipboardProc(Bool fUseUnicode, char *szDisplay); +#include <xcb/xcb.h> +#include <X11/Xmd.h> // for BOOL type + +BOOL winClipboardProc(char *szDisplay, xcb_auth_info_t *auth_info); void winFixClipboardChain(void); void winClipboardWindowDestroy(void); -extern Bool fPrimarySelection; +extern BOOL fPrimarySelection; #endif diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c index ec5543ab6..bc954c0c6 100644 --- a/hw/xwin/winclipboard/wndproc.c +++ b/hw/xwin/winclipboard/wndproc.c @@ -30,24 +30,18 @@ * Colin Harrison */ +#define WINVER 0x0600 + #ifdef HAVE_XWIN_CONFIG_H #include <xwin-config.h> #endif -/* - * 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. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - #include <sys/types.h> #include <sys/time.h> #include <limits.h> -#include <X11/Xatom.h> +#include <xcb/xproto.h> +#include <xcb/xcb_aux.h> #include "internal.h" #include "winclipboard.h" @@ -58,16 +52,12 @@ #define WIN_POLL_TIMEOUT 1 -#ifndef WM_CLIPBOARDUPDATE -#define WM_CLIPBOARDUPDATE 0x031D -#endif - /* * Process X events up to specified timeout */ static int -winProcessXEventsTimeout(HWND hwnd, Window iWindow, Display * pDisplay, +winProcessXEventsTimeout(HWND hwnd, xcb_window_t iWindow, xcb_connection_t *conn, ClipboardConversionData *data, ClipboardAtoms *atoms, int iTimeoutSec) { int iConnNumber; @@ -78,7 +68,7 @@ winProcessXEventsTimeout(HWND hwnd, Window iWindow, Display * pDisplay, iTimeoutSec); /* Get our connection number */ - iConnNumber = XConnectionNumber(pDisplay); + iConnNumber = xcb_get_file_descriptor(conn); /* Loop for X events */ while (1) { @@ -86,7 +76,7 @@ winProcessXEventsTimeout(HWND hwnd, Window iWindow, Display * pDisplay, long remainingTime; /* Process X events */ - iReturn = winClipboardFlushXEvents(hwnd, iWindow, pDisplay, data, atoms); + iReturn = winClipboardFlushXEvents(hwnd, iWindow, conn, data, atoms); winDebug("winProcessXEventsTimeout () - winClipboardFlushXEvents returned %d\n", iReturn); @@ -96,7 +86,7 @@ winProcessXEventsTimeout(HWND hwnd, Window iWindow, Display * pDisplay, } /* We need to ensure that all pending requests are sent */ - XFlush(pDisplay); + xcb_flush(conn); /* Setup the file descriptor set */ FD_ZERO(&fdsRead); @@ -138,12 +128,10 @@ winProcessXEventsTimeout(HWND hwnd, Window iWindow, Display * pDisplay, LRESULT CALLBACK winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - static HWND s_hwndNextViewer; - static Bool s_fCBCInitialized; - static Display *pDisplay; - static Window iWindow; + static xcb_connection_t *conn; + static xcb_window_t iWindow; static ClipboardAtoms *atoms; - static Bool fRunning; + static BOOL fRunning; /* Branch on message type */ switch (message) { @@ -151,18 +139,11 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { winDebug("winClipboardWindowProc - WM_DESTROY\n"); - if (g_fHasModernClipboardApi) - { - /* Remove clipboard listener */ - g_fpRemoveClipboardFormatListener(hwnd); - } - else - { - /* Remove ourselves from the clipboard chain */ - ChangeClipboardChain(hwnd, s_hwndNextViewer); - } - - s_hwndNextViewer = NULL; + /* Remove clipboard listener */ + typedef WINBOOL WINAPI (*REMOVECLIPBOARDFORMATLISTENERPROC)(HWND hwnd); + REMOVECLIPBOARDFORMATLISTENERPROC fpRemoveClipboardFormatListener = (REMOVECLIPBOARDFORMATLISTENERPROC)GetProcAddress(GetModuleHandle("user32"),"RemoveClipboardFormatListener"); + if (fpRemoveClipboardFormatListener) + fpRemoveClipboardFormatListener(hwnd); } return 0; @@ -180,143 +161,24 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) winDebug("winClipboardWindowProc - WM_CREATE\n"); - pDisplay = cwcp->pClipboardDisplay; + conn = cwcp->pClipboardDisplay; iWindow = cwcp->iClipboardWindow; atoms = cwcp->atoms; fRunning = TRUE; - if (g_fHasModernClipboardApi) - { - g_fpAddClipboardFormatListener(hwnd); - } - else - { - HWND first, next; - DWORD error_code = 0; - - first = GetClipboardViewer(); /* Get handle to first viewer in chain. */ - if (first == hwnd) - return 0; /* Make sure it's not us! */ - /* Add ourselves to the clipboard viewer chain */ - next = SetClipboardViewer(hwnd); - error_code = GetLastError(); - if (SUCCEEDED(error_code) && (next == first)) /* SetClipboardViewer must have succeeded, and the handle */ - s_hwndNextViewer = next; /* it returned must have been the first window in the chain */ - else - s_fCBCInitialized = FALSE; - } - } - return 0; - - case WM_CHANGECBCHAIN: - { - winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%p) " - "lParam(%p) s_hwndNextViewer(%p)\n", - (HWND)wParam, (HWND)lParam, s_hwndNextViewer); - - if ((HWND) wParam == s_hwndNextViewer) { - s_hwndNextViewer = (HWND) lParam; - if (s_hwndNextViewer == hwnd) { - s_hwndNextViewer = NULL; - ErrorF("winClipboardWindowProc - WM_CHANGECBCHAIN: " - "attempted to set next window to ourselves."); - } - } - else if (s_hwndNextViewer) - SendMessage(s_hwndNextViewer, message, wParam, lParam); - - } - winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: Exit\n"); - return 0; - - case WM_WM_REINIT: - { - /* Ensure that we're in the clipboard chain. Some apps, - * WinXP's remote desktop for one, don't play nice with the - * chain. This message is called whenever we receive a - * WM_ACTIVATEAPP message to ensure that we continue to - * receive clipboard messages. - * - * It might be possible to detect if we're still in the chain - * by calling SendMessage (GetClipboardViewer(), - * WM_DRAWCLIPBOARD, 0, 0); and then seeing if we get the - * WM_DRAWCLIPBOARD message. That, however, might be more - * expensive than just putting ourselves back into the chain. - */ - - HWND first, next; - DWORD error_code = 0; - - winDebug("winClipboardWindowProc - WM_WM_REINIT: Enter\n"); - - if (g_fHasModernClipboardApi) - { - return 0; - } - - first = GetClipboardViewer(); /* Get handle to first viewer in chain. */ - if (first == hwnd) - return 0; /* Make sure it's not us! */ - winDebug(" WM_WM_REINIT: Replacing us(%p) with %p at head " - "of chain\n", hwnd, s_hwndNextViewer); - s_fCBCInitialized = FALSE; - ChangeClipboardChain(hwnd, s_hwndNextViewer); - s_hwndNextViewer = NULL; - s_fCBCInitialized = FALSE; - winDebug(" WM_WM_REINIT: Putting us back at head of chain.\n"); - first = GetClipboardViewer(); /* Get handle to first viewer in chain. */ - if (first == hwnd) - return 0; /* Make sure it's not us! */ - next = SetClipboardViewer(hwnd); - error_code = GetLastError(); - if (SUCCEEDED(error_code) && (next == first)) /* SetClipboardViewer must have succeeded, and the handle */ - s_hwndNextViewer = next; /* it returned must have been the first window in the chain */ - else - s_fCBCInitialized = FALSE; + typedef WINBOOL WINAPI (*ADDCLIPBOARDFORMATLISTENERPROC)(HWND hwnd); + ADDCLIPBOARDFORMATLISTENERPROC fpAddClipboardFormatListener = (ADDCLIPBOARDFORMATLISTENERPROC)GetProcAddress(GetModuleHandle("user32"),"AddClipboardFormatListener"); + if (fpAddClipboardFormatListener) + fpAddClipboardFormatListener(hwnd); } - winDebug("winClipboardWindowProc - WM_WM_REINIT: Exit\n"); return 0; - case WM_DRAWCLIPBOARD: case WM_CLIPBOARDUPDATE: { - static Bool s_fProcessingDrawClipboard = FALSE; - int iReturn; + xcb_generic_error_t *error; + xcb_void_cookie_t cookie_set; - if (message == WM_DRAWCLIPBOARD) - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n"); - else - winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE: Enter\n"); - - if (!g_fHasModernClipboardApi) - { - /* - * We've occasionally seen a loop in the clipboard chain. - * Try and fix it on the first hint of recursion. - */ - if (!s_fProcessingDrawClipboard) { - s_fProcessingDrawClipboard = TRUE; - } - else { - /* Attempt to break the nesting by getting out of the chain, twice?, and then fix and bail */ - s_fCBCInitialized = FALSE; - ChangeClipboardChain(hwnd, s_hwndNextViewer); - winFixClipboardChain(); - ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - " - "Nested calls detected. Re-initing.\n"); - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); - s_fProcessingDrawClipboard = FALSE; - return 0; - } - - /* Bail on first message */ - if (!s_fCBCInitialized) { - s_fCBCInitialized = TRUE; - s_fProcessingDrawClipboard = FALSE; - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); - return 0; - } - } + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE: Enter\n"); /* * NOTE: We cannot bail out when NULL == GetClipboardOwner () @@ -329,12 +191,10 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) /* Bail when we still own the clipboard */ if (hwnd == GetClipboardOwner()) { - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE - " "We own the clipboard, returning.\n"); - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); - s_fProcessingDrawClipboard = FALSE; - if (s_hwndNextViewer) - SendMessage(s_hwndNextViewer, message, wParam, lParam); + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE: Exit\n"); + return 0; } @@ -350,7 +210,10 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if (!IsClipboardFormatAvailable(CF_TEXT) && !IsClipboardFormatAvailable(CF_UNICODETEXT)) { - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + xcb_get_selection_owner_cookie_t cookie_get; + xcb_get_selection_owner_reply_t *reply; + + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE - " "Clipboard does not contain CF_TEXT nor " "CF_UNICODETEXT.\n"); @@ -358,87 +221,78 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) * We need to make sure that the X Server has processed * previous XSetSelectionOwner messages. */ - XSync(pDisplay, FALSE); + xcb_aux_sync(conn); winDebug("winClipboardWindowProc - XSync done.\n"); /* Release PRIMARY selection if owned */ - iReturn = XGetSelectionOwner(pDisplay, XA_PRIMARY); - if (iReturn == iWindow) { - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - " - "PRIMARY selection is owned by us.\n"); - XSetSelectionOwner(pDisplay, XA_PRIMARY, None, CurrentTime); + cookie_get = xcb_get_selection_owner(conn, XCB_ATOM_PRIMARY); + reply = xcb_get_selection_owner_reply(conn, cookie_get, NULL); + if (reply) { + if (reply->owner == iWindow) { + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE - " + "PRIMARY selection is owned by us, releasing.\n"); + xcb_set_selection_owner(conn, XCB_NONE, XCB_ATOM_PRIMARY, XCB_CURRENT_TIME); + } + free(reply); } - else if (BadWindow == iReturn || BadAtom == iReturn) - ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - " - "XGetSelectionOwner failed for PRIMARY: %d\n", - iReturn); /* Release CLIPBOARD selection if owned */ - iReturn = XGetSelectionOwner(pDisplay, atoms->atomClipboard); - if (iReturn == iWindow) { - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - " - "CLIPBOARD selection is owned by us, releasing\n"); - XSetSelectionOwner(pDisplay, atoms->atomClipboard, None, CurrentTime); + cookie_get = xcb_get_selection_owner(conn, atoms->atomClipboard); + reply = xcb_get_selection_owner_reply(conn, cookie_get, NULL); + if (reply) { + if (reply->owner == iWindow) { + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE - " + "CLIPBOARD selection is owned by us, releasing\n"); + xcb_set_selection_owner(conn, XCB_NONE, atoms->atomClipboard, XCB_CURRENT_TIME); + } + free(reply); } - else if (BadWindow == iReturn || BadAtom == iReturn) - ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - " - "XGetSelectionOwner failed for CLIPBOARD: %d\n", - iReturn); - - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); - s_fProcessingDrawClipboard = FALSE; - if (s_hwndNextViewer) - SendMessage(s_hwndNextViewer, message, wParam, lParam); + + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE: Exit\n"); + return 0; } /* Reassert ownership of PRIMARY */ - iReturn = XSetSelectionOwner(pDisplay, - XA_PRIMARY, iWindow, CurrentTime); - if (iReturn == BadAtom || iReturn == BadWindow || - XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) { - ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + cookie_set = xcb_set_selection_owner_checked(conn, iWindow, XCB_ATOM_PRIMARY, XCB_CURRENT_TIME); + error = xcb_request_check(conn, cookie_set); + if (error) { + ErrorF("winClipboardWindowProc - WM_CLIPBOARDUPDATE - " "Could not reassert ownership of PRIMARY\n"); - } - else { - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + free(error); + } else { + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE - " "Reasserted ownership of PRIMARY\n"); } /* Reassert ownership of the CLIPBOARD */ - iReturn = XSetSelectionOwner(pDisplay, - atoms->atomClipboard, iWindow, CurrentTime); - - if (iReturn == BadAtom || iReturn == BadWindow || - XGetSelectionOwner(pDisplay, atoms->atomClipboard) != iWindow) { - ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + cookie_set = xcb_set_selection_owner_checked(conn, iWindow, atoms->atomClipboard, XCB_CURRENT_TIME); + error = xcb_request_check(conn, cookie_set); + if (error) { + ErrorF("winClipboardWindowProc - WM_CLIPBOARDUPDATE - " "Could not reassert ownership of CLIPBOARD\n"); + free(error); } else { - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - " + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE - " "Reasserted ownership of CLIPBOARD\n"); } /* Flush the pending SetSelectionOwner event now */ - XFlush(pDisplay); - - s_fProcessingDrawClipboard = FALSE; + xcb_flush(conn); } - winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n"); - /* Pass the message on the next window in the clipboard viewer chain */ - if (s_hwndNextViewer) - SendMessage(s_hwndNextViewer, message, wParam, lParam); + winDebug("winClipboardWindowProc - WM_CLIPBOARDUPDATE: Exit\n"); return 0; case WM_DESTROYCLIPBOARD: /* * NOTE: Intentionally do nothing. - * Changes in the Win32 clipboard are handled by WM_DRAWCLIPBOARD + * Changes in the Win32 clipboard are handled by WM_CLIPBOARDUPDATE * above. We only process this message to conform to the specs * for delayed clipboard rendering in Win32. You might think * that we need to release ownership of the X11 selections, but - * we do not, because a WM_DRAWCLIPBOARD message will closely + * we do not, because a WM_CLIPBOARDUPDATE message will closely * follow this message and reassert ownership of the X11 * selections, handling the issue for us. */ @@ -462,20 +316,16 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_RENDERFORMAT: { int iReturn; - Bool fConvertToUnicode; - Bool pasted = FALSE; - Atom selection; + BOOL pasted = FALSE; + xcb_atom_t selection; ClipboardConversionData data; int best_target = 0; winDebug("winClipboardWindowProc - WM_RENDERFORMAT %d - Hello.\n", (int)wParam); - /* Flag whether to convert to Unicode or not */ - fConvertToUnicode = (CF_UNICODETEXT == wParam); - selection = winClipboardGetLastOwnedSelectionAtom(atoms); - if (selection == None) { + if (selection == XCB_NONE) { ErrorF("winClipboardWindowProc - no monitored selection is owned\n"); goto fake_paste; } @@ -483,20 +333,16 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) winDebug("winClipboardWindowProc - requesting targets for selection from owner\n"); /* Request the selection's supported conversion targets */ - XConvertSelection(pDisplay, - selection, - atoms->atomTargets, - atoms->atomLocalProperty, - iWindow, CurrentTime); + xcb_convert_selection(conn, iWindow, selection, atoms->atomTargets, + atoms->atomLocalProperty, XCB_CURRENT_TIME); /* Process X events */ - data.fUseUnicode = fConvertToUnicode; data.incr = NULL; data.incrsize = 0; iReturn = winProcessXEventsTimeout(hwnd, iWindow, - pDisplay, + conn, &data, atoms, WIN_POLL_TIMEOUT); @@ -511,17 +357,15 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { struct target_priority { - Atom target; + xcb_atom_t target; unsigned int priority; }; struct target_priority target_priority_table[] = { -#ifdef X_HAVE_UTF8_STRING { atoms->atomUTF8String, 0 }, -#endif - { atoms->atomCompoundText, 1 }, - { XA_STRING, 2 }, + // { atoms->atomCompoundText, 1 }, not implemented (yet?) + { XCB_ATOM_STRING, 2 }, }; int best_priority = INT_MAX; @@ -553,16 +397,13 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) winDebug("winClipboardWindowProc - requesting selection from owner\n"); /* Request the selection contents */ - XConvertSelection(pDisplay, - selection, - best_target, - atoms->atomLocalProperty, - iWindow, CurrentTime); + xcb_convert_selection(conn, iWindow, selection, best_target, + atoms->atomLocalProperty, XCB_CURRENT_TIME); /* Process X events */ iReturn = winProcessXEventsTimeout(hwnd, iWindow, - pDisplay, + conn, &data, atoms, WIN_POLL_TIMEOUT); @@ -605,7 +446,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) * Process any pending Windows messages */ -Bool +BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd) { MSG msg; diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c index 7d55f3d92..af956679b 100644 --- a/hw/xwin/winclipboard/xevents.c +++ b/hw/xwin/winclipboard/xevents.c @@ -34,20 +34,11 @@ #include <xwin-config.h> #endif -/* - * 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. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - #include <limits.h> #include <wchar.h> -#include <X11/Xutil.h> -#include <X11/Xatom.h> -#include <X11/extensions/Xfixes.h> + +#include <xcb/xcb.h> +#include <xcb/xfixes.h> #include "winclipboard.h" #include "internal.h" @@ -57,32 +48,34 @@ */ #define CLIP_NUM_SELECTIONS 2 -#define CLIP_OWN_NONE -1 +#define CLIP_OWN_NONE -1 #define CLIP_OWN_PRIMARY 0 #define CLIP_OWN_CLIPBOARD 1 +#define CP_ISO_8559_1 28591 + /* * Global variables */ extern int xfixes_event_base; -Bool fPrimarySelection = TRUE; +BOOL fPrimarySelection = TRUE; /* * Local variables */ -static Window s_iOwners[CLIP_NUM_SELECTIONS] = { None, None }; +static xcb_window_t s_iOwners[CLIP_NUM_SELECTIONS] = { XCB_NONE, XCB_NONE }; static const char *szSelectionNames[CLIP_NUM_SELECTIONS] = { "PRIMARY", "CLIPBOARD" }; static unsigned int lastOwnedSelectionIndex = CLIP_OWN_NONE; static void -MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i) +MonitorSelection(xcb_xfixes_selection_notify_event_t * e, unsigned int i) { /* Look for owned -> not owned transition */ - if (None == e->owner && None != s_iOwners[i]) { + if ((XCB_NONE == e->owner) && (XCB_NONE != s_iOwners[i])) { unsigned int other_index; winDebug("MonitorSelection - %s - Going from owned to not owned.\n", @@ -94,36 +87,36 @@ MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i) other_index = CLIP_OWN_CLIPBOARD; if (i == CLIP_OWN_CLIPBOARD) other_index = CLIP_OWN_PRIMARY; - if (None != s_iOwners[other_index]) + if (XCB_NONE != s_iOwners[other_index]) lastOwnedSelectionIndex = other_index; else lastOwnedSelectionIndex = CLIP_OWN_NONE; } /* Save last owned selection */ - if (None != e->owner) { + if (XCB_NONE != e->owner) { lastOwnedSelectionIndex = i; } /* Save new selection owner or None */ s_iOwners[i] = e->owner; - winDebug("MonitorSelection - %s - Now owned by XID %lx\n", + winDebug("MonitorSelection - %s - Now owned by XID %x\n", szSelectionNames[i], e->owner); } -Atom +xcb_atom_t winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms) { if (lastOwnedSelectionIndex == CLIP_OWN_NONE) - return None; + return XCB_NONE; if (lastOwnedSelectionIndex == CLIP_OWN_PRIMARY) - return XA_PRIMARY; + return XCB_ATOM_PRIMARY; if (lastOwnedSelectionIndex == CLIP_OWN_CLIPBOARD) return atoms->atomClipboard; - return None; + return XCB_NONE; } @@ -133,103 +126,116 @@ winClipboardInitMonitoredSelections(void) /* Initialize static variables */ int i; for (i = 0; i < CLIP_NUM_SELECTIONS; ++i) - s_iOwners[i] = None; + s_iOwners[i] = XCB_NONE; lastOwnedSelectionIndex = CLIP_OWN_NONE; } -static int -winClipboardSelectionNotifyTargets(HWND hwnd, Window iWindow, Display *pDisplay, ClipboardConversionData *data, ClipboardAtoms *atoms) +static char *get_atom_name(xcb_connection_t *conn, xcb_atom_t atom) { - Atom type; - int format; - unsigned long nitems; - unsigned long after; - Atom *prop; + char *ret; + xcb_get_atom_name_cookie_t cookie = xcb_get_atom_name(conn, atom); + xcb_get_atom_name_reply_t *reply = xcb_get_atom_name_reply(conn, cookie, NULL); + if (!reply) + return NULL; + ret = malloc(xcb_get_atom_name_name_length(reply) + 1); + if (ret) { + memcpy(ret, xcb_get_atom_name_name(reply), xcb_get_atom_name_name_length(reply)); + ret[xcb_get_atom_name_name_length(reply)] = '\0'; + } + free(reply); + return ret; +} +static int +winClipboardSelectionNotifyTargets(HWND hwnd, xcb_window_t iWindow, xcb_connection_t *conn, ClipboardConversionData *data, ClipboardAtoms *atoms) +{ /* Retrieve the selection data and delete the property */ - int iReturn = XGetWindowProperty(pDisplay, - iWindow, - atoms->atomLocalProperty, - 0, - INT_MAX, - True, - AnyPropertyType, - &type, - &format, - &nitems, - &after, - (unsigned char **)&prop); - if (iReturn != Success) { - ErrorF("winClipboardFlushXEvents - SelectionNotify - " - "XGetWindowProperty () failed, aborting: %d\n", iReturn); + xcb_get_property_cookie_t cookie = xcb_get_property(conn, + TRUE, + iWindow, + atoms->atomLocalProperty, + XCB_GET_PROPERTY_TYPE_ANY, + 0, + INT_MAX); + xcb_get_property_reply_t *reply = xcb_get_property_reply(conn, cookie, NULL); + if (!reply) { + ErrorF("winClipboardFlushXEvents - SelectionNotify - " + "XGetWindowProperty () failed\n"); } else { - int i; - data->targetList = malloc((nitems+1)*sizeof(Atom)); - - for (i = 0; i < nitems; i++) - { - Atom atom = prop[i]; - char *pszAtomName = XGetAtomName(pDisplay, atom); - data->targetList[i] = atom; - winDebug("winClipboardFlushXEvents - SelectionNotify - target[%d] %ld = %s\n", i, atom, pszAtomName); - XFree(pszAtomName); + xcb_atom_t *prop = xcb_get_property_value(reply); + int nitems = xcb_get_property_value_length(reply)/sizeof(xcb_atom_t); + int i; + data->targetList = malloc((nitems+1)*sizeof(xcb_atom_t)); + + for (i = 0; i < nitems; i++) + { + xcb_atom_t atom = prop[i]; + char *pszAtomName = get_atom_name(conn, atom); + data->targetList[i] = atom; + winDebug("winClipboardFlushXEvents - SelectionNotify - target[%d] %d = %s\n", i, atom, pszAtomName); + free(pszAtomName); } data->targetList[nitems] = 0; - XFree(prop); + free(reply); } return WIN_XEVENTS_NOTIFY_TARGETS; } static int -winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, ClipboardConversionData *data, ClipboardAtoms *atoms) +winClipboardSelectionNotifyData(HWND hwnd, xcb_window_t iWindow, xcb_connection_t *conn, ClipboardConversionData *data, ClipboardAtoms *atoms) { - Atom encoding; + xcb_atom_t encoding; int format; unsigned long int nitems; unsigned long int after; unsigned char *value; - XTextProperty xtpText = { 0 }; - Bool fSetClipboardData = TRUE; - int iReturn; - char **ppszTextList = NULL; - int iCount; + + unsigned char *xtpText_value; + xcb_atom_t xtpText_encoding; + int xtpText_nitems; + + BOOL fSetClipboardData = TRUE; char *pszReturnData = NULL; + UINT codepage; wchar_t *pwszUnicodeStr = NULL; HGLOBAL hGlobal = NULL; - char *pszConvertData = NULL; char *pszGlobalData = NULL; /* Retrieve the selection data and delete the property */ - iReturn = XGetWindowProperty(pDisplay, - iWindow, - atoms->atomLocalProperty, - 0, - INT_MAX, - True, - AnyPropertyType, - &encoding, - &format, - &nitems, - &after, - &value); - if (iReturn != Success) { + xcb_get_property_cookie_t cookie = xcb_get_property(conn, + TRUE, + iWindow, + atoms->atomLocalProperty, + XCB_GET_PROPERTY_TYPE_ANY, + 0, + INT_MAX); + xcb_get_property_reply_t *reply = xcb_get_property_reply(conn, cookie, NULL); + if (!reply) { ErrorF("winClipboardFlushXEvents - SelectionNotify - " - "XGetWindowProperty () failed, aborting: %d\n", iReturn); + "XGetWindowProperty () failed\n"); goto winClipboardFlushXEvents_SelectionNotify_Done; + } else { + nitems = xcb_get_property_value_length(reply); + value = xcb_get_property_value(reply); + after = reply->bytes_after; + encoding = reply->type; + format = reply->format; + // We assume format == 8 (i.e. data is a sequence of bytes). It's not + // clear how anything else should be handled. + if (format != 8) + ErrorF("SelectionNotify: format is %d, proceeding as if it was 8\n", format); } { - char *pszAtomName = NULL; - + char *pszAtomName; winDebug("SelectionNotify - returned data %lu left %lu\n", nitems, after); - pszAtomName = XGetAtomName(pDisplay, encoding); + pszAtomName = get_atom_name(conn, encoding); winDebug("Notify atom name %s\n", pszAtomName); - XFree(pszAtomName); - pszAtomName = NULL; + free(pszAtomName); } /* INCR reply indicates the start of a incremental transfer */ @@ -245,10 +251,12 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl if (nitems == 0) { winDebug("winClipboardSelectionNotifyData: ending INCR, actual size %ld\n", data->incrsize); /* a zero-length property indicates the end of the data */ - xtpText.value = data->incr; - xtpText.encoding = encoding; - xtpText.format = format; // XXX: The type of the converted selection is the type of the first partial property. The remaining partial properties must have the same type. - xtpText.nitems = data->incrsize; + xtpText_value = data->incr; + xtpText_encoding = encoding; + // XXX: The type of the converted selection is the type of the first + // partial property. The remaining partial properties must have the + // same type. + xtpText_nitems = data->incrsize; } else { /* Otherwise, continue appending the INCR data */ @@ -262,76 +270,34 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl else { /* Otherwise, the data is just contained in the property */ winDebug("winClipboardSelectionNotifyData: non-INCR, %ld bytes\n", nitems); - xtpText.value = value; - xtpText.encoding = encoding; - xtpText.format = format; - xtpText.nitems = nitems; + xtpText_value = value; + xtpText_encoding = encoding; + xtpText_nitems = nitems; } - if (data->fUseUnicode) { -#ifdef X_HAVE_UTF8_STRING - /* Convert the text property to a text list */ - iReturn = Xutf8TextPropertyToTextList(pDisplay, - &xtpText, - &ppszTextList, &iCount); -#endif - } - else { - iReturn = XmbTextPropertyToTextList(pDisplay, - &xtpText, - &ppszTextList, &iCount); - } - if (iReturn == Success || iReturn > 0) { - /* Conversion succeeded or some unconvertible characters */ - if (ppszTextList != NULL) { - int i; - int iReturnDataLen = 0; - for (i = 0; i < iCount; i++) { - iReturnDataLen += strlen(ppszTextList[i]); - } - pszReturnData = malloc(iReturnDataLen + 1); - pszReturnData[0] = '\0'; - for (i = 0; i < iCount; i++) { - strcat(pszReturnData, ppszTextList[i]); - } - } - else { - ErrorF("winClipboardFlushXEvents - SelectionNotify - " - "X*TextPropertyToTextList list_return is NULL.\n"); - pszReturnData = malloc(1); - pszReturnData[0] = '\0'; - } - } - else { - ErrorF("winClipboardFlushXEvents - SelectionNotify - " - "X*TextPropertyToTextList returned: "); - switch (iReturn) { - case XNoMemory: - ErrorF("XNoMemory\n"); - break; - case XLocaleNotSupported: - ErrorF("XLocaleNotSupported\n"); - break; - case XConverterNotFound: - ErrorF("XConverterNotFound\n"); - break; - default: - ErrorF("%d\n", iReturn); - break; - } + if (xtpText_encoding == atoms->atomUTF8String) { + pszReturnData = malloc(xtpText_nitems + 1); + memcpy(pszReturnData, xtpText_value, xtpText_nitems); + pszReturnData[xtpText_nitems] = 0; + codepage = CP_UTF8; // code page identifier for utf8 + } else if (xtpText_encoding == XCB_ATOM_STRING) { + // STRING encoding is Latin1 (ISO8859-1) plus tab and newline + pszReturnData = malloc(xtpText_nitems + 1); + memcpy(pszReturnData, xtpText_value, xtpText_nitems); + pszReturnData[xtpText_nitems] = 0; + codepage = CP_ISO_8559_1; // code page identifier for iso-8559-1 + } else if (xtpText_encoding == atoms->atomCompoundText) { + // COMPOUND_TEXT is complex, based on ISO 2022 + ErrorF("SelectionNotify: data in COMPOUND_TEXT encoding which is not implemented, discarding\n"); + pszReturnData = malloc(1); + pszReturnData[0] = '\0'; + } else { // shouldn't happen as we accept no other encodings pszReturnData = malloc(1); pszReturnData[0] = '\0'; } - - if (ppszTextList) - XFreeStringList(ppszTextList); - ppszTextList = NULL; - - /* Free the data returned from XGetWindowProperty */ - XFree(value); - value = NULL; - nitems = 0; + /* Free the data returned from xcb_get_property */ + free(reply); /* Free any INCR data */ if (data->incr) { @@ -343,40 +309,26 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl /* Convert the X clipboard string to DOS format */ winClipboardUNIXtoDOS(&pszReturnData, strlen(pszReturnData)); - if (data->fUseUnicode) { - /* Find out how much space needed to convert MBCS to Unicode */ - int iUnicodeLen = MultiByteToWideChar(CP_UTF8, - 0, - pszReturnData, -1, NULL, 0); + /* Find out how much space needed when converted to UTF-16 */ + int iUnicodeLen = MultiByteToWideChar(codepage, 0, + pszReturnData, -1, NULL, 0); - /* NOTE: iUnicodeLen includes space for null terminator */ - pwszUnicodeStr = malloc(sizeof(wchar_t) * iUnicodeLen); - if (!pwszUnicodeStr) { - ErrorF("winClipboardFlushXEvents - SelectionNotify " - "malloc failed for pwszUnicodeStr, aborting.\n"); - - /* Abort */ - goto winClipboardFlushXEvents_SelectionNotify_Done; - } - - /* Do the actual conversion */ - MultiByteToWideChar(CP_UTF8, - 0, - pszReturnData, - -1, pwszUnicodeStr, iUnicodeLen); + /* NOTE: iUnicodeLen includes space for null terminator */ + pwszUnicodeStr = malloc(sizeof(wchar_t) * iUnicodeLen); + if (!pwszUnicodeStr) { + ErrorF("winClipboardFlushXEvents - SelectionNotify " + "malloc failed for pwszUnicodeStr, aborting.\n"); - /* Allocate global memory for the X clipboard data */ - hGlobal = GlobalAlloc(GMEM_MOVEABLE, - sizeof(wchar_t) * iUnicodeLen); + /* Abort */ + goto winClipboardFlushXEvents_SelectionNotify_Done; } - else { - int iConvertDataLen = 0; - pszConvertData = strdup(pszReturnData); - iConvertDataLen = strlen(pszConvertData) + 1; - /* Allocate global memory for the X clipboard data */ - hGlobal = GlobalAlloc(GMEM_MOVEABLE, iConvertDataLen); - } + /* Do the actual conversion */ + MultiByteToWideChar(codepage, 0, + pszReturnData, -1, pwszUnicodeStr, iUnicodeLen); + + /* Allocate global memory for the X clipboard data */ + hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * iUnicodeLen); free(pszReturnData); @@ -400,26 +352,16 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl } /* Copy the returned string into the global memory */ - if (data->fUseUnicode) { - wcscpy((wchar_t *)pszGlobalData, pwszUnicodeStr); - free(pwszUnicodeStr); - pwszUnicodeStr = NULL; - } - else { - strcpy(pszGlobalData, pszConvertData); - free(pszConvertData); - pszConvertData = NULL; - } + wcscpy((wchar_t *)pszGlobalData, pwszUnicodeStr); + free(pwszUnicodeStr); + pwszUnicodeStr = NULL; /* Release the pointer to the global memory */ GlobalUnlock(hGlobal); pszGlobalData = NULL; /* Push the selection data to the Windows clipboard */ - if (data->fUseUnicode) - SetClipboardData(CF_UNICODETEXT, hGlobal); - else - SetClipboardData(CF_TEXT, hGlobal); + SetClipboardData(CF_UNICODETEXT, hGlobal); /* Flag that SetClipboardData has been called */ fSetClipboardData = FALSE; @@ -431,14 +373,6 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl winClipboardFlushXEvents_SelectionNotify_Done: /* Free allocated resources */ - if (ppszTextList) - XFreeStringList(ppszTextList); - if (value) { - XFree(value); - value = NULL; - nitems = 0; - } - free(pszConvertData); free(pwszUnicodeStr); if (hGlobal && pszGlobalData) GlobalUnlock(hGlobal); @@ -455,105 +389,97 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl int winClipboardFlushXEvents(HWND hwnd, - Window iWindow, Display * pDisplay, ClipboardConversionData *data, ClipboardAtoms *atoms) + xcb_window_t iWindow, xcb_connection_t *conn, + ClipboardConversionData *data, ClipboardAtoms *atoms) { - Atom atomClipboard = atoms->atomClipboard; - Atom atomUTF8String = atoms->atomUTF8String; - Atom atomCompoundText = atoms->atomCompoundText; - Atom atomTargets = atoms->atomTargets; + xcb_atom_t atomClipboard = atoms->atomClipboard; + xcb_atom_t atomUTF8String = atoms->atomUTF8String; + xcb_atom_t atomCompoundText = atoms->atomCompoundText; + xcb_atom_t atomTargets = atoms->atomTargets; /* Process all pending events */ - while (XPending(pDisplay)) { - XTextProperty xtpText = { 0 }; - XEvent event; - XSelectionEvent eventSelection; + xcb_generic_event_t *event; + while ((event = xcb_poll_for_event(conn))) { char *pszGlobalData = NULL; - int iReturn; HGLOBAL hGlobal = NULL; - XICCEncodingStyle xiccesStyle; char *pszConvertData = NULL; - char *pszTextList[2] = { NULL }; - Bool fAbort = FALSE; - Bool fCloseClipboard = FALSE; - - /* Get the next event - will not block because one is ready */ - XNextEvent(pDisplay, &event); + BOOL fAbort = FALSE; + BOOL fCloseClipboard = FALSE; /* Branch on the event type */ - switch (event.type) { - /* - * SelectionRequest - */ + switch (event->response_type & ~0x80) { + case XCB_SELECTION_REQUEST: + { + char *xtpText_value = NULL; + int xtpText_nitems; + UINT codepage; - case SelectionRequest: + xcb_selection_request_event_t *selection_request = (xcb_selection_request_event_t *)event; { char *pszAtomName = NULL; - winDebug("SelectionRequest - target %ld\n", - event.xselectionrequest.target); + winDebug("SelectionRequest - target %d\n", selection_request->target); - pszAtomName = XGetAtomName(pDisplay, - event.xselectionrequest.target); + pszAtomName = get_atom_name(conn, selection_request->target); winDebug("SelectionRequest - Target atom name %s\n", pszAtomName); - XFree(pszAtomName); - pszAtomName = NULL; + free(pszAtomName); } /* Abort if invalid target type */ - if (event.xselectionrequest.target != XA_STRING - && event.xselectionrequest.target != atomUTF8String - && event.xselectionrequest.target != atomCompoundText - && event.xselectionrequest.target != atomTargets) { + if (selection_request->target != XCB_ATOM_STRING + && selection_request->target != atomUTF8String + && selection_request->target != atomCompoundText + && selection_request->target != atomTargets) { /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } /* Handle targets type of request */ - if (event.xselectionrequest.target == atomTargets) { - Atom atomTargetArr[] = { atomTargets, - atomCompoundText, - atomUTF8String, - XA_STRING - }; + if (selection_request->target == atomTargets) { + xcb_atom_t atomTargetArr[] = + { + atomTargets, + atomUTF8String, + XCB_ATOM_STRING, + // atomCompoundText, not implemented (yet?) + }; /* Try to change the property */ - iReturn = XChangeProperty(pDisplay, - event.xselectionrequest.requestor, - event.xselectionrequest.property, - XA_ATOM, + xcb_void_cookie_t cookie = xcb_change_property_checked(conn, + XCB_PROP_MODE_REPLACE, + selection_request->requestor, + selection_request->property, + XCB_ATOM_ATOM, 32, - PropModeReplace, - (unsigned char *) atomTargetArr, - ARRAY_SIZE(atomTargetArr)); - if (iReturn == BadAlloc - || iReturn == BadAtom - || iReturn == BadMatch - || iReturn == BadValue || iReturn == BadWindow) { + ARRAY_SIZE(atomTargetArr), + (unsigned char *) atomTargetArr); + xcb_generic_error_t *error; + if ((error = xcb_request_check(conn, cookie))) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " - "XChangeProperty failed: %d\n", iReturn); + "xcb_change_property failed"); + free(error); } /* Setup selection notify xevent */ - eventSelection.type = SelectionNotify; - eventSelection.send_event = True; - eventSelection.display = pDisplay; - eventSelection.requestor = event.xselectionrequest.requestor; - eventSelection.selection = event.xselectionrequest.selection; - eventSelection.target = event.xselectionrequest.target; - eventSelection.property = event.xselectionrequest.property; - eventSelection.time = event.xselectionrequest.time; + xcb_selection_notify_event_t eventSelection; + eventSelection.response_type = XCB_SELECTION_NOTIFY; + eventSelection.requestor = selection_request->requestor; + eventSelection.selection = selection_request->selection; + eventSelection.target = selection_request->target; + eventSelection.property = selection_request->property; + eventSelection.time = selection_request->time; /* * Notify the requesting window that * the operation has completed */ - iReturn = XSendEvent(pDisplay, - eventSelection.requestor, - False, 0L, (XEvent *) &eventSelection); - if (iReturn == BadValue || iReturn == BadWindow) { + cookie = xcb_send_event_checked(conn, FALSE, + eventSelection.requestor, + 0, (char *) &eventSelection); + if ((error = xcb_request_check(conn, cookie))) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " - "XSendEvent () failed\n"); + "xcb_send_event() failed\n"); } break; } @@ -577,7 +503,7 @@ winClipboardFlushXEvents(HWND hwnd, fCloseClipboard = TRUE; /* Check that clipboard format is available */ - if (data->fUseUnicode && !IsClipboardFormatAvailable(CF_UNICODETEXT)) { + if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) { static int count; /* Hack to stop acroread spamming the log */ static HWND lasthwnd; /* I've not seen any other client get here repeatedly? */ @@ -594,36 +520,11 @@ winClipboardFlushXEvents(HWND hwnd, fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } - else if (!data->fUseUnicode && !IsClipboardFormatAvailable(CF_TEXT)) { - ErrorF("winClipboardFlushXEvents - CF_TEXT is not " - "available from Win32 clipboard. Aborting.\n"); - - /* Abort */ - fAbort = TRUE; - goto winClipboardFlushXEvents_SelectionRequest_Done; - } - - /* Setup the string style */ - if (event.xselectionrequest.target == XA_STRING) - xiccesStyle = XStringStyle; -#ifdef X_HAVE_UTF8_STRING - else if (event.xselectionrequest.target == atomUTF8String) - xiccesStyle = XUTF8StringStyle; -#endif - else if (event.xselectionrequest.target == atomCompoundText) - xiccesStyle = XCompoundTextStyle; - else - xiccesStyle = XStringStyle; /* Get a pointer to the clipboard text, in desired format */ - if (data->fUseUnicode) { - /* Retrieve clipboard data */ - hGlobal = GetClipboardData(CF_UNICODETEXT); - } - else { - /* Retrieve clipboard data */ - hGlobal = GetClipboardData(CF_TEXT); - } + /* Retrieve clipboard data */ + hGlobal = GetClipboardData(CF_UNICODETEXT); + if (!hGlobal) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " "GetClipboardData () failed: %08x\n", (unsigned int)GetLastError()); @@ -634,73 +535,42 @@ winClipboardFlushXEvents(HWND hwnd, } pszGlobalData = (char *) GlobalLock(hGlobal); - /* Convert the Unicode string to UTF8 (MBCS) */ - if (data->fUseUnicode) { - int iConvertDataLen = WideCharToMultiByte(CP_UTF8, - 0, - (LPCWSTR) pszGlobalData, - -1, NULL, 0, NULL, NULL); - /* NOTE: iConvertDataLen includes space for null terminator */ - pszConvertData = malloc(iConvertDataLen); - WideCharToMultiByte(CP_UTF8, - 0, - (LPCWSTR) pszGlobalData, - -1, - pszConvertData, - iConvertDataLen, NULL, NULL); - } - else { - pszConvertData = strdup(pszGlobalData); + /* Convert to target string style */ + if (selection_request->target == XCB_ATOM_STRING) { + codepage = CP_ISO_8559_1; // code page identifier for iso-8559-1 + } else if (selection_request->target == atomUTF8String) { + codepage = CP_UTF8; // code page identifier for utf8 + } else if (selection_request->target == atomCompoundText) { + // COMPOUND_TEXT is complex, not (yet) implemented + pszGlobalData = "COMPOUND_TEXT not implemented"; + codepage = CP_UTF8; // code page identifier for utf8 } + /* Convert the UTF16 string to required encoding */ + int iConvertDataLen = WideCharToMultiByte(codepage, 0, + (LPCWSTR) pszGlobalData, -1, + NULL, 0, NULL, NULL); + /* NOTE: iConvertDataLen includes space for null terminator */ + pszConvertData = malloc(iConvertDataLen); + WideCharToMultiByte(codepage, 0, + (LPCWSTR) pszGlobalData, -1, + pszConvertData, iConvertDataLen, NULL, NULL); + /* Convert DOS string to UNIX string */ winClipboardDOStoUNIX(pszConvertData, strlen(pszConvertData)); - /* Setup our text list */ - pszTextList[0] = pszConvertData; - pszTextList[1] = NULL; - - /* Initialize the text property */ - xtpText.value = NULL; - xtpText.nitems = 0; + xtpText_value = strdup(pszConvertData); + xtpText_nitems = iConvertDataLen - 1; - /* Create the text property from the text list */ - if (data->fUseUnicode) { -#ifdef X_HAVE_UTF8_STRING - iReturn = Xutf8TextListToTextProperty(pDisplay, - pszTextList, - 1, xiccesStyle, &xtpText); -#endif - } - else { - iReturn = XmbTextListToTextProperty(pDisplay, - pszTextList, - 1, xiccesStyle, &xtpText); - } - if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) { - ErrorF("winClipboardFlushXEvents - SelectionRequest - " - "X*TextListToTextProperty failed: %d\n", iReturn); - - /* Abort */ - fAbort = TRUE; - goto winClipboardFlushXEvents_SelectionRequest_Done; - } - - /* Free the converted string */ - free(pszConvertData); - pszConvertData = NULL; - - /* data will fit into a single X request (INCR not yet supported) */ + /* data will fit into a single X request? (INCR not yet supported) */ { - long unsigned int maxreqsize = XExtendedMaxRequestSize(pDisplay); - if (maxreqsize == 0) - maxreqsize = XMaxRequestSize(pDisplay); + uint32_t maxreqsize = xcb_get_maximum_request_length(conn); /* covert to bytes and allow for allow for X_ChangeProperty request */ maxreqsize = maxreqsize*4 - 24; - if (xtpText.nitems > maxreqsize) { - ErrorF("winClipboardFlushXEvents - clipboard data size %lu greater than maximum %lu\n", xtpText.nitems, maxreqsize); + if (xtpText_nitems > maxreqsize) { + ErrorF("winClipboardFlushXEvents - clipboard data size %d greater than maximum %u\n", xtpText_nitems, maxreqsize); /* Abort */ fAbort = TRUE; @@ -709,24 +579,27 @@ winClipboardFlushXEvents(HWND hwnd, } /* Copy the clipboard text to the requesting window */ - iReturn = XChangeProperty(pDisplay, - event.xselectionrequest.requestor, - event.xselectionrequest.property, - event.xselectionrequest.target, + xcb_void_cookie_t cookie = xcb_change_property_checked(conn, + XCB_PROP_MODE_REPLACE, + selection_request->requestor, + selection_request->property, + selection_request->target, 8, - PropModeReplace, - xtpText.value, xtpText.nitems); - if (iReturn == BadAlloc || iReturn == BadAtom - || iReturn == BadMatch || iReturn == BadValue - || iReturn == BadWindow) { + xtpText_nitems, xtpText_value); + xcb_generic_error_t *error; + if ((error = xcb_request_check(conn, cookie))) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " - "XChangeProperty failed: %d\n", iReturn); + "xcb_change_property failed\n"); /* Abort */ fAbort = TRUE; goto winClipboardFlushXEvents_SelectionRequest_Done; } + /* Free the converted string */ + free(pszConvertData); + pszConvertData = NULL; + /* Release the clipboard data */ GlobalUnlock(hGlobal); pszGlobalData = NULL; @@ -734,27 +607,25 @@ winClipboardFlushXEvents(HWND hwnd, CloseClipboard(); /* Clean up */ - XFree(xtpText.value); - xtpText.value = NULL; - xtpText.nitems = 0; + free(xtpText_value); + xtpText_value = NULL; /* Setup selection notify event */ - eventSelection.type = SelectionNotify; - eventSelection.send_event = True; - eventSelection.display = pDisplay; - eventSelection.requestor = event.xselectionrequest.requestor; - eventSelection.selection = event.xselectionrequest.selection; - eventSelection.target = event.xselectionrequest.target; - eventSelection.property = event.xselectionrequest.property; - eventSelection.time = event.xselectionrequest.time; + xcb_selection_notify_event_t eventSelection; + eventSelection.response_type = XCB_SELECTION_NOTIFY; + eventSelection.requestor = selection_request->requestor; + eventSelection.selection = selection_request->selection; + eventSelection.target = selection_request->target; + eventSelection.property = selection_request->property; + eventSelection.time = selection_request->time; /* Notify the requesting window that the operation has completed */ - iReturn = XSendEvent(pDisplay, - eventSelection.requestor, - False, 0L, (XEvent *) &eventSelection); - if (iReturn == BadValue || iReturn == BadWindow) { + cookie = xcb_send_event_checked(conn, FALSE, + eventSelection.requestor, + 0, (char *) &eventSelection); + if ((error = xcb_request_check(conn, cookie))) { ErrorF("winClipboardFlushXEvents - SelectionRequest - " - "XSendEvent () failed\n"); + "xcb_send_event() failed\n"); /* Abort */ fAbort = TRUE; @@ -763,12 +634,11 @@ winClipboardFlushXEvents(HWND hwnd, winClipboardFlushXEvents_SelectionRequest_Done: /* Free allocated resources */ - if (xtpText.value) { - XFree(xtpText.value); - xtpText.value = NULL; - xtpText.nitems = 0; + if (xtpText_value) { + free(xtpText_value); } - free(pszConvertData); + if (pszConvertData) + free(pszConvertData); if (hGlobal && pszGlobalData) GlobalUnlock(hGlobal); @@ -778,26 +648,24 @@ winClipboardFlushXEvents(HWND hwnd, */ if (fAbort) { /* Setup selection notify event */ - eventSelection.type = SelectionNotify; - eventSelection.send_event = True; - eventSelection.display = pDisplay; - eventSelection.requestor = event.xselectionrequest.requestor; - eventSelection.selection = event.xselectionrequest.selection; - eventSelection.target = event.xselectionrequest.target; - eventSelection.property = None; - eventSelection.time = event.xselectionrequest.time; + eventSelection.response_type = XCB_SELECTION_NOTIFY; + eventSelection.requestor = selection_request->requestor; + eventSelection.selection = selection_request->selection; + eventSelection.target = selection_request->target; + eventSelection.property = XCB_NONE; + eventSelection.time = selection_request->time; /* Notify the requesting window that the operation is complete */ - iReturn = XSendEvent(pDisplay, - eventSelection.requestor, - False, 0L, (XEvent *) &eventSelection); - if (iReturn == BadValue || iReturn == BadWindow) { + cookie = xcb_send_event_checked(conn, FALSE, + eventSelection.requestor, + 0, (char *) &eventSelection); + if ((error = xcb_request_check(conn, cookie))) { /* * Should not be a problem if XSendEvent fails because * the client may simply have exited. */ ErrorF("winClipboardFlushXEvents - SelectionRequest - " - "XSendEvent () failed for abort event.\n"); + "xcb_send_event() failed for abort event.\n"); } } @@ -807,71 +675,79 @@ winClipboardFlushXEvents(HWND hwnd, CloseClipboard(); } break; + } - /* - * SelectionNotify - */ - - case SelectionNotify: + case XCB_SELECTION_NOTIFY: + { + xcb_selection_notify_event_t *selection_notify = (xcb_selection_notify_event_t *)event; winDebug("winClipboardFlushXEvents - SelectionNotify\n"); { char *pszAtomName; - - pszAtomName = XGetAtomName(pDisplay, - event.xselection.selection); - - winDebug - ("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n", - pszAtomName); - XFree(pszAtomName); + pszAtomName = get_atom_name(conn, selection_notify->selection); + winDebug("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n", pszAtomName); + free(pszAtomName); } /* - SelectionNotify with property of None indicates either: + SelectionNotify with property of XCB_NONE indicates either: (i) Generated by the X server if no owner for the specified selection exists (perhaps it's disappeared on us mid-transaction), or (ii) Sent by the selection owner when the requested selection conversion could not be performed or server errors prevented the conversion data being returned */ - if (event.xselection.property == None) { + if (selection_notify->property == XCB_NONE) { ErrorF("winClipboardFlushXEvents - SelectionNotify - " - "Conversion to format %ld refused.\n", - event.xselection.target); + "Conversion to format %d refused.\n", + selection_notify->target); return WIN_XEVENTS_FAILED; } - if (event.xselection.target == atomTargets) { - return winClipboardSelectionNotifyTargets(hwnd, iWindow, pDisplay, data, atoms); + if (selection_notify->target == atomTargets) { + return winClipboardSelectionNotifyTargets(hwnd, iWindow, conn, data, atoms); } - return winClipboardSelectionNotifyData(hwnd, iWindow, pDisplay, data, atoms); + return winClipboardSelectionNotifyData(hwnd, iWindow, conn, data, atoms); + } - case SelectionClear: + case XCB_SELECTION_CLEAR: winDebug("SelectionClear - doing nothing\n"); break; - case PropertyNotify: + case XCB_PROPERTY_NOTIFY: + { + xcb_property_notify_event_t *property_notify = (xcb_property_notify_event_t *)event; + /* If INCR is in progress, collect the data */ if (data->incr && - (event.xproperty.atom == atoms->atomLocalProperty) && - (event.xproperty.state == PropertyNewValue)) - return winClipboardSelectionNotifyData(hwnd, iWindow, pDisplay, data, atoms); + (property_notify->atom == atoms->atomLocalProperty) && + (property_notify->state == XCB_PROPERTY_NEW_VALUE)) + return winClipboardSelectionNotifyData(hwnd, iWindow, conn, data, atoms); break; + } - case MappingNotify: + case XCB_MAPPING_NOTIFY: break; - default: - if (event.type == XFixesSetSelectionOwnerNotify + xfixes_event_base) { - XFixesSelectionNotifyEvent *e = - (XFixesSelectionNotifyEvent *) & event; + case 0: + /* This is just laziness rather than making sure we used _checked everywhere */ + { + xcb_generic_error_t *err = (xcb_generic_error_t *)event; + ErrorF("winClipboardFlushXEvents - Error code: %i, ID: 0x%08x, " + "Major opcode: %i, Minor opcode: %i\n", + err->error_code, err->resource_id, + err->major_code, err->minor_code); + } + break; + default: + if ((event->response_type & ~0x80) == XCB_XFIXES_SELECTION_EVENT_SET_SELECTION_OWNER + xfixes_event_base) { + xcb_xfixes_selection_notify_event_t *e = (xcb_xfixes_selection_notify_event_t *)event; winDebug("winClipboardFlushXEvents - XFixesSetSelectionOwnerNotify\n"); /* Save selection owners for monitored selections, ignore other selections */ - if ((e->selection == XA_PRIMARY) && fPrimarySelection) { + if ((e->selection == XCB_ATOM_PRIMARY) && fPrimarySelection) { MonitorSelection(e, CLIP_OWN_PRIMARY); } else if (e->selection == atomClipboard) { @@ -881,9 +757,8 @@ winClipboardFlushXEvents(HWND hwnd, break; /* Selection is being disowned */ - if (e->owner == None) { - winDebug - ("winClipboardFlushXEvents - No window, returning.\n"); + if (e->owner == XCB_NONE) { + winDebug("winClipboardFlushXEvents - No window, returning.\n"); break; } @@ -930,15 +805,25 @@ winClipboardFlushXEvents(HWND hwnd, break; } } - /* XFixesSelectionWindowDestroyNotifyMask */ - /* XFixesSelectionClientCloseNotifyMask */ + /* XCB_XFIXES_SELECTION_EVENT_SELECTION_WINDOW_DESTROY */ + /* XCB_XFIXES_SELECTION_EVENT_SELECTION_CLIENT_CLOSE */ else { ErrorF("winClipboardFlushXEvents - unexpected event type %d\n", - event.type); + event->response_type); } break; } + + /* I/O errors etc. */ + { + int e = xcb_connection_has_error(conn); + if (e) { + ErrorF("winClipboardFlushXEvents - Fatal error %d on xcb connection\n", e); + break; + } + } } return WIN_XEVENTS_SUCCESS; + } diff --git a/hw/xwin/winclipboard/xwinclip.c b/hw/xwin/winclipboard/xwinclip.c index 856c4dd54..4df8cd4af 100644 --- a/hw/xwin/winclipboard/xwinclip.c +++ b/hw/xwin/winclipboard/xwinclip.c @@ -35,27 +35,10 @@ #include <xwin-config.h> #endif -/* - * 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. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - #include <stdio.h> #include <stdlib.h> #include <string.h> -/* X headers */ -#include <X11/Xlib.h> -#ifdef X_LOCALE -#include <X11/Xlocale.h> -#else /* X_LOCALE */ -#include <locale.h> -#endif /* X_LOCALE */ - #include "winclipboard.h" /* @@ -67,7 +50,6 @@ main (int argc, char *argv[]) { int i; char *pszDisplay = NULL; - int fUnicodeClipboard = 1; /* Parse command-line parameters */ for (i = 1; i < argc; ++i) @@ -85,17 +67,10 @@ main (int argc, char *argv[]) continue; } - /* Look for -nounicodeclipboard */ - if (!strcmp (argv[i], "-nounicodeclipboard")) - { - fUnicodeClipboard = 0; - continue; - } - /* Look for -noprimary */ if (!strcmp (argv[i], "-noprimary")) { - fPrimarySelection = False; + fPrimarySelection = 0; continue; } @@ -104,31 +79,7 @@ main (int argc, char *argv[]) exit (1); } - /* Do we have Unicode support? */ - if (fUnicodeClipboard) - { - printf ("Unicode clipboard I/O\n"); - } - else - { - printf ("Non Unicode clipboard I/O\n"); - } - - /* Apply locale specified in the LANG environment variable */ - if (!setlocale (LC_ALL, "")) - { - printf ("setlocale() error\n"); - exit (1); - } - - /* See if X supports the current locale */ - if (XSupportsLocale () == False) - { - printf ("Locale not supported by X, falling back to 'C' locale.\n"); - setlocale(LC_ALL, "C"); - } - - winClipboardProc(fUnicodeClipboard, pszDisplay); + winClipboardProc(pszDisplay, NULL /* Use XAUTHORITY for auth data */); return 0; } diff --git a/hw/xwin/winclipboard/xwinclip.man b/hw/xwin/winclipboard/xwinclip.man index f9e0d3bfb..e3db50177 100644 --- a/hw/xwin/winclipboard/xwinclip.man +++ b/hw/xwin/winclipboard/xwinclip.man @@ -27,9 +27,6 @@ Do \fINOT\fP run \fIxwinclip\fP unless \fIXWin(1)\fP has been started with the - .B \-display [display] Specifies the X server display to connect to. .TP 8 -.B \-nounicodeclipboard -Do not use unicode text on the clipboard. -.TP 8 .B \-noprimary Do not monitor the PRIMARY selection. diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c index 8aef8fe02..814899f8e 100644 --- a/hw/xwin/winclipboardinit.c +++ b/hw/xwin/winclipboardinit.c @@ -38,6 +38,7 @@ #include "win.h" #include "winclipboard/winclipboard.h" #include "windisplay.h" +#include "winauth.h" #define WIN_CLIPBOARD_RETRIES 40 #define WIN_CLIPBOARD_DELAY 1 @@ -55,6 +56,7 @@ static void * winClipboardThreadProc(void *arg) { char szDisplay[512]; + xcb_auth_info_t *auth_info; int clipboardRestarts = 0; while (1) @@ -63,9 +65,6 @@ winClipboardThreadProc(void *arg) ++clipboardRestarts; - /* Use our generated cookie for authentication */ - winSetAuthorization(); - /* Setup the display connection string */ /* * NOTE: Always connect to screen 0 since we require that screen @@ -82,7 +81,10 @@ winClipboardThreadProc(void *arg) /* Flag that clipboard client has been launched */ g_fClipboardStarted = TRUE; - fShutdown = winClipboardProc(g_fUnicodeClipboard, szDisplay); + /* Use our generated cookie for authentication */ + auth_info = winGetXcbAuthInfo(); + + fShutdown = winClipboardProc(szDisplay, auth_info); /* Flag that clipboard client has stopped */ g_fClipboardStarted = FALSE; diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c index b0086f871..9bd6c0f5a 100644 --- a/hw/xwin/winglobals.c +++ b/hw/xwin/winglobals.c @@ -90,7 +90,6 @@ winDispatchProcPtr winProcEstablishConnectionOrig = NULL; * Clipboard variables */ -Bool g_fUnicodeClipboard = TRUE; Bool g_fClipboard = TRUE; Bool g_fClipboardStarted = FALSE; diff --git a/hw/xwin/winglobals.h b/hw/xwin/winglobals.h index fee507683..a0469e1c5 100644 --- a/hw/xwin/winglobals.h +++ b/hw/xwin/winglobals.h @@ -68,7 +68,6 @@ typedef int (*winDispatchProcPtr) (ClientPtr); * Wrapped DIX functions */ extern winDispatchProcPtr winProcEstablishConnectionOrig; -extern Bool g_fUnicodeClipboard; extern Bool g_fClipboard; extern Bool g_fClipboardStarted; diff --git a/hw/xwin/winmultiwindowicons.c b/hw/xwin/winmultiwindowicons.c index 5124b88ff..94e32a707 100644 --- a/hw/xwin/winmultiwindowicons.c +++ b/hw/xwin/winmultiwindowicons.c @@ -33,7 +33,6 @@ #endif #include <X11/Xwindows.h> -#include <X11/Xlib.h> #include "winresource.h" #include "winprefs.h" @@ -51,7 +50,7 @@ extern HINSTANCE g_hInstance; */ void -winUpdateIcon(HWND hWnd, xcb_connection_t *conn, Window id, HICON hIconNew) +winUpdateIcon(HWND hWnd, xcb_connection_t *conn, xcb_window_t id, HICON hIconNew) { HICON hIcon, hIconSmall = NULL, hIconOld; diff --git a/hw/xwin/winmultiwindowicons.h b/hw/xwin/winmultiwindowicons.h index 87ba8d1cf..8b077ab80 100644 --- a/hw/xwin/winmultiwindowicons.h +++ b/hw/xwin/winmultiwindowicons.h @@ -30,7 +30,7 @@ #include <xcb/xcb.h> void - winUpdateIcon(HWND hWnd, xcb_connection_t *conn, Window id, HICON hIconNew); + winUpdateIcon(HWND hWnd, xcb_connection_t *conn, xcb_window_t id, HICON hIconNew); void winInitGlobalIcons(void); diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index 4a28ccb8e..ec7f6707f 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -77,6 +77,7 @@ #include "winglobals.h" #include "windisplay.h" #include "winmultiwindowicons.h" +#include "winauth.h" /* We need the native HWND atom for intWM, so for consistency use the same name as extWM does */ @@ -89,7 +90,6 @@ extern void winDebug(const char *format, ...); extern void winReshapeMultiWindow(WindowPtr pWin); extern void winUpdateRgnMultiWindow(WindowPtr pWin); -extern xcb_auth_info_t *winGetXcbAuthInfo(void); extern void winUpdateWindowPosition(HWND hWnd, HWND * zstyle); #ifndef CYGDEBUG @@ -1485,7 +1485,7 @@ winMultiWindowXMsgProc(void *pArg) if ((reply->root == reply_qt->parent) && !notify->override_redirect) { xcb_reparent_notify_event_t event_send; - event_send.response_type = ReparentNotify; + event_send.response_type = XCB_REPARENT_NOTIFY; event_send.event = notify->window; event_send.window = notify->window; event_send.parent = reply_qt->parent; diff --git a/hw/xwin/winprocarg.c b/hw/xwin/winprocarg.c index a69b41853..d930f2aa7 100644 --- a/hw/xwin/winprocarg.c +++ b/hw/xwin/winprocarg.c @@ -1012,15 +1012,6 @@ ddxProcessArgument(int argc, char *argv[], int i) return 2; } - /* - * Look for the '-nounicodeclipboard' argument - */ - if (IS_OPTION("-nounicodeclipboard")) { - g_fUnicodeClipboard = FALSE; - /* Indicate that we have processed the argument */ - return 1; - } - if (IS_OPTION("-xkbrules")) { CHECK_ARGS(1); g_cmdline.xkbRules = argv[++i]; diff --git a/hw/xwin/winwindow.h b/hw/xwin/winwindow.h index e73098838..10a10205d 100644 --- a/hw/xwin/winwindow.h +++ b/hw/xwin/winwindow.h @@ -32,6 +32,8 @@ #if !defined(_WINWINDOW_H_) #define _WINWINDOW_H_ +#include <pthread.h> + #ifndef NO #define NO 0 #endif diff --git a/hw/xwin/winwndproc.c b/hw/xwin/winwndproc.c index c0c4a5ed8..b8ce7c936 100644 --- a/hw/xwin/winwndproc.c +++ b/hw/xwin/winwndproc.c @@ -1117,9 +1117,6 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ShowCursor(TRUE); } - /* Make sure the clipboard chain is ok. */ - winFixClipboardChain(); - /* Call engine specific screen activation/deactivation function */ (*s_pScreenPriv->pwinActivateApp) (s_pScreen); |