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...
This commit is contained in:
Jon Turney 2018-07-01 12:11:19 +01:00
parent 9f51dfdec3
commit f4936de73c
13 changed files with 50 additions and 147 deletions

View File

@ -796,9 +796,6 @@ winUseMsg(void)
"\tDo not draw a window border, title bar, etc. Windowed\n" "\tDo not draw a window border, title bar, etc. Windowed\n"
"\tmode only.\n"); "\tmode only.\n");
ErrorF("-nounicodeclipboard\n"
"\tDo not use Unicode clipboard even if on a NT-based platform.\n");
ErrorF("-[no]primary\n" ErrorF("-[no]primary\n"
"\tWhen clipboard integration is enabled, map the X11 PRIMARY selection\n" "\tWhen clipboard integration is enabled, map the X11 PRIMARY selection\n"
"\tto the Windows clipboard. Default is enabled.\n"); "\tto the Windows clipboard. Default is enabled.\n");

View File

@ -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\-notrayicon\fP, then enable it for specific screens with
\fB\-trayicon\fP for those screens. \fB\-trayicon\fP for those screens.
.TP 8 .TP 8
.B \-nounicodeclipboard
Do not use Unicode clipboard even if on a NT-based platform.
.TP 8
.B \-[no]unixkill .B \-[no]unixkill
Enable or disable the \fICtrl-Alt-Backspace\fP key combination as a 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 signal to exit the X Server. The \fICtrl-Alt-Backspace\fP key combination

View File

@ -100,7 +100,6 @@ typedef struct
typedef struct typedef struct
{ {
Bool fUseUnicode;
Atom *targetList; Atom *targetList;
unsigned char *incr; unsigned char *incr;
unsigned long int incrsize; unsigned long int incrsize;

View File

@ -104,7 +104,7 @@ static int
*/ */
Bool Bool
winClipboardProc(Bool fUseUnicode, char *szDisplay) winClipboardProc(char *szDisplay)
{ {
ClipboardAtoms atoms; ClipboardAtoms atoms;
int iReturn; int iReturn;
@ -256,7 +256,6 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
} }
} }
data.fUseUnicode = fUseUnicode;
data.incr = NULL; data.incr = NULL;
data.incrsize = 0; data.incrsize = 0;

View File

@ -27,7 +27,7 @@
#ifndef WINCLIPBOARD_H #ifndef WINCLIPBOARD_H
#define WINCLIPBOARD_H #define WINCLIPBOARD_H
Bool winClipboardProc(Bool fUseUnicode, char *szDisplay); Bool winClipboardProc(char *szDisplay);
void winFixClipboardChain(void); void winFixClipboardChain(void);

View File

@ -316,7 +316,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_RENDERFORMAT: case WM_RENDERFORMAT:
{ {
int iReturn; int iReturn;
Bool fConvertToUnicode;
Bool pasted = FALSE; Bool pasted = FALSE;
Atom selection; Atom selection;
ClipboardConversionData data; ClipboardConversionData data;
@ -325,9 +324,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
winDebug("winClipboardWindowProc - WM_RENDERFORMAT %d - Hello.\n", winDebug("winClipboardWindowProc - WM_RENDERFORMAT %d - Hello.\n",
(int)wParam); (int)wParam);
/* Flag whether to convert to Unicode or not */
fConvertToUnicode = (CF_UNICODETEXT == wParam);
selection = winClipboardGetLastOwnedSelectionAtom(atoms); selection = winClipboardGetLastOwnedSelectionAtom(atoms);
if (selection == None) { if (selection == None) {
ErrorF("winClipboardWindowProc - no monitored selection is owned\n"); ErrorF("winClipboardWindowProc - no monitored selection is owned\n");
@ -344,7 +340,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
iWindow, CurrentTime); iWindow, CurrentTime);
/* Process X events */ /* Process X events */
data.fUseUnicode = fConvertToUnicode;
data.incr = NULL; data.incr = NULL;
data.incrsize = 0; data.incrsize = 0;

View File

@ -200,7 +200,6 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl
char *pszReturnData = NULL; char *pszReturnData = NULL;
wchar_t *pwszUnicodeStr = NULL; wchar_t *pwszUnicodeStr = NULL;
HGLOBAL hGlobal = NULL; HGLOBAL hGlobal = NULL;
char *pszConvertData = NULL;
char *pszGlobalData = NULL; char *pszGlobalData = NULL;
/* Retrieve the selection data and delete the property */ /* Retrieve the selection data and delete the property */
@ -268,19 +267,13 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl
xtpText.nitems = nitems; xtpText.nitems = nitems;
} }
if (data->fUseUnicode) {
#ifdef X_HAVE_UTF8_STRING #ifdef X_HAVE_UTF8_STRING
/* Convert the text property to a text list */ /* Convert the text property to a text list */
iReturn = Xutf8TextPropertyToTextList(pDisplay, iReturn = Xutf8TextPropertyToTextList(pDisplay,
&xtpText, &xtpText,
&ppszTextList, &iCount); &ppszTextList, &iCount);
#endif #endif
}
else {
iReturn = XmbTextPropertyToTextList(pDisplay,
&xtpText,
&ppszTextList, &iCount);
}
if (iReturn == Success || iReturn > 0) { if (iReturn == Success || iReturn > 0) {
/* Conversion succeeded or some unconvertible characters */ /* Conversion succeeded or some unconvertible characters */
if (ppszTextList != NULL) { if (ppszTextList != NULL) {
@ -343,40 +336,30 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl
/* Convert the X clipboard string to DOS format */ /* Convert the X clipboard string to DOS format */
winClipboardUNIXtoDOS(&pszReturnData, strlen(pszReturnData)); winClipboardUNIXtoDOS(&pszReturnData, strlen(pszReturnData));
if (data->fUseUnicode) { /* Find out how much space needed to convert MBCS to Unicode */
/* Find out how much space needed to convert MBCS to Unicode */ int iUnicodeLen = MultiByteToWideChar(CP_UTF8,
int iUnicodeLen = MultiByteToWideChar(CP_UTF8, 0,
0, pszReturnData, -1, NULL, 0);
pszReturnData, -1, NULL, 0);
/* NOTE: iUnicodeLen includes space for null terminator */ /* NOTE: iUnicodeLen includes space for null terminator */
pwszUnicodeStr = malloc(sizeof(wchar_t) * iUnicodeLen); pwszUnicodeStr = malloc(sizeof(wchar_t) * iUnicodeLen);
if (!pwszUnicodeStr) { if (!pwszUnicodeStr) {
ErrorF("winClipboardFlushXEvents - SelectionNotify " ErrorF("winClipboardFlushXEvents - SelectionNotify "
"malloc failed for pwszUnicodeStr, aborting.\n"); "malloc failed for pwszUnicodeStr, aborting.\n");
/* Abort */ /* Abort */
goto winClipboardFlushXEvents_SelectionNotify_Done; goto winClipboardFlushXEvents_SelectionNotify_Done;
}
/* Do the actual conversion */
MultiByteToWideChar(CP_UTF8,
0,
pszReturnData,
-1, pwszUnicodeStr, iUnicodeLen);
/* Allocate global memory for the X clipboard data */
hGlobal = GlobalAlloc(GMEM_MOVEABLE,
sizeof(wchar_t) * iUnicodeLen);
} }
else {
int iConvertDataLen = 0;
pszConvertData = strdup(pszReturnData);
iConvertDataLen = strlen(pszConvertData) + 1;
/* Allocate global memory for the X clipboard data */ /* Do the actual conversion */
hGlobal = GlobalAlloc(GMEM_MOVEABLE, iConvertDataLen); MultiByteToWideChar(CP_UTF8,
} 0,
pszReturnData,
-1, pwszUnicodeStr, iUnicodeLen);
/* Allocate global memory for the X clipboard data */
hGlobal = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * iUnicodeLen);
free(pszReturnData); free(pszReturnData);
@ -400,26 +383,16 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl
} }
/* Copy the returned string into the global memory */ /* Copy the returned string into the global memory */
if (data->fUseUnicode) { wcscpy((wchar_t *)pszGlobalData, pwszUnicodeStr);
wcscpy((wchar_t *)pszGlobalData, pwszUnicodeStr); free(pwszUnicodeStr);
free(pwszUnicodeStr); pwszUnicodeStr = NULL;
pwszUnicodeStr = NULL;
}
else {
strcpy(pszGlobalData, pszConvertData);
free(pszConvertData);
pszConvertData = NULL;
}
/* Release the pointer to the global memory */ /* Release the pointer to the global memory */
GlobalUnlock(hGlobal); GlobalUnlock(hGlobal);
pszGlobalData = NULL; pszGlobalData = NULL;
/* Push the selection data to the Windows clipboard */ /* Push the selection data to the Windows clipboard */
if (data->fUseUnicode) SetClipboardData(CF_UNICODETEXT, hGlobal);
SetClipboardData(CF_UNICODETEXT, hGlobal);
else
SetClipboardData(CF_TEXT, hGlobal);
/* Flag that SetClipboardData has been called */ /* Flag that SetClipboardData has been called */
fSetClipboardData = FALSE; fSetClipboardData = FALSE;
@ -438,7 +411,6 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl
value = NULL; value = NULL;
nitems = 0; nitems = 0;
} }
free(pszConvertData);
free(pwszUnicodeStr); free(pwszUnicodeStr);
if (hGlobal && pszGlobalData) if (hGlobal && pszGlobalData)
GlobalUnlock(hGlobal); GlobalUnlock(hGlobal);
@ -577,7 +549,7 @@ winClipboardFlushXEvents(HWND hwnd,
fCloseClipboard = TRUE; fCloseClipboard = TRUE;
/* Check that clipboard format is available */ /* 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 int count; /* Hack to stop acroread spamming the log */
static HWND lasthwnd; /* I've not seen any other client get here repeatedly? */ static HWND lasthwnd; /* I've not seen any other client get here repeatedly? */
@ -594,14 +566,6 @@ winClipboardFlushXEvents(HWND hwnd,
fAbort = TRUE; fAbort = TRUE;
goto winClipboardFlushXEvents_SelectionRequest_Done; 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 */ /* Setup the string style */
if (event.xselectionrequest.target == XA_STRING) if (event.xselectionrequest.target == XA_STRING)
@ -616,14 +580,9 @@ winClipboardFlushXEvents(HWND hwnd,
xiccesStyle = XStringStyle; xiccesStyle = XStringStyle;
/* Get a pointer to the clipboard text, in desired format */ /* Get a pointer to the clipboard text, in desired format */
if (data->fUseUnicode) { /* Retrieve clipboard data */
/* Retrieve clipboard data */ hGlobal = GetClipboardData(CF_UNICODETEXT);
hGlobal = GetClipboardData(CF_UNICODETEXT);
}
else {
/* Retrieve clipboard data */
hGlobal = GetClipboardData(CF_TEXT);
}
if (!hGlobal) { if (!hGlobal) {
ErrorF("winClipboardFlushXEvents - SelectionRequest - " ErrorF("winClipboardFlushXEvents - SelectionRequest - "
"GetClipboardData () failed: %08x\n", (unsigned int)GetLastError()); "GetClipboardData () failed: %08x\n", (unsigned int)GetLastError());
@ -635,23 +594,18 @@ winClipboardFlushXEvents(HWND hwnd,
pszGlobalData = (char *) GlobalLock(hGlobal); pszGlobalData = (char *) GlobalLock(hGlobal);
/* Convert the Unicode string to UTF8 (MBCS) */ /* Convert the Unicode string to UTF8 (MBCS) */
if (data->fUseUnicode) { int iConvertDataLen = WideCharToMultiByte(CP_UTF8,
int iConvertDataLen = WideCharToMultiByte(CP_UTF8,
0, 0,
(LPCWSTR) pszGlobalData, (LPCWSTR) pszGlobalData,
-1, NULL, 0, NULL, NULL); -1, NULL, 0, NULL, NULL);
/* NOTE: iConvertDataLen includes space for null terminator */ /* NOTE: iConvertDataLen includes space for null terminator */
pszConvertData = malloc(iConvertDataLen); pszConvertData = malloc(iConvertDataLen);
WideCharToMultiByte(CP_UTF8, WideCharToMultiByte(CP_UTF8,
0, 0,
(LPCWSTR) pszGlobalData, (LPCWSTR) pszGlobalData,
-1, -1,
pszConvertData, pszConvertData,
iConvertDataLen, NULL, NULL); iConvertDataLen, NULL, NULL);
}
else {
pszConvertData = strdup(pszGlobalData);
}
/* Convert DOS string to UNIX string */ /* Convert DOS string to UNIX string */
winClipboardDOStoUNIX(pszConvertData, strlen(pszConvertData)); winClipboardDOStoUNIX(pszConvertData, strlen(pszConvertData));
@ -665,18 +619,12 @@ winClipboardFlushXEvents(HWND hwnd,
xtpText.nitems = 0; xtpText.nitems = 0;
/* Create the text property from the text list */ /* Create the text property from the text list */
if (data->fUseUnicode) {
#ifdef X_HAVE_UTF8_STRING #ifdef X_HAVE_UTF8_STRING
iReturn = Xutf8TextListToTextProperty(pDisplay, iReturn = Xutf8TextListToTextProperty(pDisplay,
pszTextList, pszTextList,
1, xiccesStyle, &xtpText); 1, xiccesStyle, &xtpText);
#endif #endif
}
else {
iReturn = XmbTextListToTextProperty(pDisplay,
pszTextList,
1, xiccesStyle, &xtpText);
}
if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) { if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) {
ErrorF("winClipboardFlushXEvents - SelectionRequest - " ErrorF("winClipboardFlushXEvents - SelectionRequest - "
"X*TextListToTextProperty failed: %d\n", iReturn); "X*TextListToTextProperty failed: %d\n", iReturn);

View File

@ -67,7 +67,6 @@ main (int argc, char *argv[])
{ {
int i; int i;
char *pszDisplay = NULL; char *pszDisplay = NULL;
int fUnicodeClipboard = 1;
/* Parse command-line parameters */ /* Parse command-line parameters */
for (i = 1; i < argc; ++i) for (i = 1; i < argc; ++i)
@ -85,13 +84,6 @@ main (int argc, char *argv[])
continue; continue;
} }
/* Look for -nounicodeclipboard */
if (!strcmp (argv[i], "-nounicodeclipboard"))
{
fUnicodeClipboard = 0;
continue;
}
/* Look for -noprimary */ /* Look for -noprimary */
if (!strcmp (argv[i], "-noprimary")) if (!strcmp (argv[i], "-noprimary"))
{ {
@ -104,16 +96,6 @@ main (int argc, char *argv[])
exit (1); 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 */ /* Apply locale specified in the LANG environment variable */
if (!setlocale (LC_ALL, "")) if (!setlocale (LC_ALL, ""))
{ {
@ -128,7 +110,7 @@ main (int argc, char *argv[])
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
} }
winClipboardProc(fUnicodeClipboard, pszDisplay); winClipboardProc(pszDisplay);
return 0; return 0;
} }

View File

@ -27,9 +27,6 @@ Do \fINOT\fP run \fIxwinclip\fP unless \fIXWin(1)\fP has been started with the -
.B \-display [display] .B \-display [display]
Specifies the X server display to connect to. Specifies the X server display to connect to.
.TP 8 .TP 8
.B \-nounicodeclipboard
Do not use unicode text on the clipboard.
.TP 8
.B \-noprimary .B \-noprimary
Do not monitor the PRIMARY selection. Do not monitor the PRIMARY selection.

View File

@ -82,7 +82,7 @@ winClipboardThreadProc(void *arg)
/* Flag that clipboard client has been launched */ /* Flag that clipboard client has been launched */
g_fClipboardStarted = TRUE; g_fClipboardStarted = TRUE;
fShutdown = winClipboardProc(g_fUnicodeClipboard, szDisplay); fShutdown = winClipboardProc(szDisplay);
/* Flag that clipboard client has stopped */ /* Flag that clipboard client has stopped */
g_fClipboardStarted = FALSE; g_fClipboardStarted = FALSE;

View File

@ -90,7 +90,6 @@ winDispatchProcPtr winProcEstablishConnectionOrig = NULL;
* Clipboard variables * Clipboard variables
*/ */
Bool g_fUnicodeClipboard = TRUE;
Bool g_fClipboard = TRUE; Bool g_fClipboard = TRUE;
Bool g_fClipboardStarted = FALSE; Bool g_fClipboardStarted = FALSE;

View File

@ -70,7 +70,6 @@ typedef int (*winDispatchProcPtr) (ClientPtr);
* Wrapped DIX functions * Wrapped DIX functions
*/ */
extern winDispatchProcPtr winProcEstablishConnectionOrig; extern winDispatchProcPtr winProcEstablishConnectionOrig;
extern Bool g_fUnicodeClipboard;
extern Bool g_fClipboard; extern Bool g_fClipboard;
extern Bool g_fClipboardStarted; extern Bool g_fClipboardStarted;

View File

@ -1004,15 +1004,6 @@ ddxProcessArgument(int argc, char *argv[], int i)
return 2; 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")) { if (IS_OPTION("-xkbrules")) {
CHECK_ARGS(1); CHECK_ARGS(1);
g_cmdline.xkbRules = argv[++i]; g_cmdline.xkbRules = argv[++i];