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"
"\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");

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\-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

View File

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

View File

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

View File

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

View File

@ -316,7 +316,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_RENDERFORMAT:
{
int iReturn;
Bool fConvertToUnicode;
Bool pasted = FALSE;
Atom selection;
ClipboardConversionData data;
@ -325,9 +324,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
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) {
ErrorF("winClipboardWindowProc - no monitored selection is owned\n");
@ -344,7 +340,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
iWindow, CurrentTime);
/* Process X events */
data.fUseUnicode = fConvertToUnicode;
data.incr = NULL;
data.incrsize = 0;

View File

@ -200,7 +200,6 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl
char *pszReturnData = NULL;
wchar_t *pwszUnicodeStr = NULL;
HGLOBAL hGlobal = NULL;
char *pszConvertData = NULL;
char *pszGlobalData = NULL;
/* Retrieve the selection data and delete the property */
@ -268,19 +267,13 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl
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);
/* 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) {
@ -343,40 +336,30 @@ 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 to convert MBCS to Unicode */
int iUnicodeLen = MultiByteToWideChar(CP_UTF8,
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");
/* 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);
/* 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(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);
@ -400,26 +383,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;
@ -438,7 +411,6 @@ winClipboardSelectionNotifyData(HWND hwnd, Window iWindow, Display *pDisplay, Cl
value = NULL;
nitems = 0;
}
free(pszConvertData);
free(pwszUnicodeStr);
if (hGlobal && pszGlobalData)
GlobalUnlock(hGlobal);
@ -577,7 +549,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,14 +566,6 @@ 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)
@ -616,14 +580,9 @@ winClipboardFlushXEvents(HWND hwnd,
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());
@ -635,23 +594,18 @@ winClipboardFlushXEvents(HWND hwnd,
pszGlobalData = (char *) GlobalLock(hGlobal);
/* Convert the Unicode string to UTF8 (MBCS) */
if (data->fUseUnicode) {
int iConvertDataLen = WideCharToMultiByte(CP_UTF8,
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);
}
/* NOTE: iConvertDataLen includes space for null terminator */
pszConvertData = malloc(iConvertDataLen);
WideCharToMultiByte(CP_UTF8,
0,
(LPCWSTR) pszGlobalData,
-1,
pszConvertData,
iConvertDataLen, NULL, NULL);
/* Convert DOS string to UNIX string */
winClipboardDOStoUNIX(pszConvertData, strlen(pszConvertData));
@ -665,18 +619,12 @@ winClipboardFlushXEvents(HWND hwnd,
xtpText.nitems = 0;
/* Create the text property from the text list */
if (data->fUseUnicode) {
#ifdef X_HAVE_UTF8_STRING
iReturn = Xutf8TextListToTextProperty(pDisplay,
pszTextList,
1, xiccesStyle, &xtpText);
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);

View File

@ -67,7 +67,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,13 +84,6 @@ 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"))
{
@ -104,16 +96,6 @@ 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, ""))
{
@ -128,7 +110,7 @@ main (int argc, char *argv[])
setlocale(LC_ALL, "C");
}
winClipboardProc(fUnicodeClipboard, pszDisplay);
winClipboardProc(pszDisplay);
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]
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.

View File

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

View File

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

View File

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

View File

@ -1004,15 +1004,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];