From bdc4a8b7151496ced08c7910dec9194a009499a4 Mon Sep 17 00:00:00 2001 From: dimbor Date: Thu, 25 Jan 2018 15:29:38 +0300 Subject: [PATCH] nxagent: add setlocale for nxwin windows titles recoding (UTF8_STRING <-> COMPOUND_TEXT) --- nx-X11/config/cf/host.def | 5 +++ nx-X11/programs/Xserver/hw/nxagent/Init.c | 17 +++++++ nx-X11/programs/Xserver/hw/nxagent/Rootless.c | 44 ++++++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/nx-X11/config/cf/host.def b/nx-X11/config/cf/host.def index 3638e0528c..8d3e25de4d 100644 --- a/nx-X11/config/cf/host.def +++ b/nx-X11/config/cf/host.def @@ -541,3 +541,8 @@ * #define X86EMU_LIBPATH /usr/local/lib */ + +/* Build locales for nxagent */ +#define MotifDir $(LIBDIR) +#define XLocaleDir /usr/share/locale +#define XLocaleLibDir $(LIBDIR) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Init.c b/nx-X11/programs/Xserver/hw/nxagent/Init.c index e8e2309561..6ca764972f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Init.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Init.c @@ -90,6 +90,9 @@ is" without express or implied warranty. #undef DEBUG #undef DUMP +/* by dimbor */ +#include + /* * ProcVector array defined in tables.c. */ @@ -385,6 +388,20 @@ FIXME: These variables, if not removed at all because have probably if (!whiteRoot) blackRoot = TRUE; + /* by dimbor */ + char *locale = setlocale(LC_ALL, ""); + if (!locale) + fprintf(stderr, "InitOutput: failed to set locale, reverting to \"C\"\n"); + else + { + if (!XSupportsLocale()) + fprintf(stderr, "InitOutput: Locale %s not supported by X\n",locale); + else + fprintf(stderr, "InitOutput: Set %s locale\n",locale); + } + if (!XSetLocaleModifiers("")) + fprintf(stderr,"InitOutput: cannot set locale modifiers.\n"); + nxagentInitKeystrokes(False); #ifdef NXAGENT_CLIPBOARD diff --git a/nx-X11/programs/Xserver/hw/nxagent/Rootless.c b/nx-X11/programs/Xserver/hw/nxagent/Rootless.c index 72cb13042e..c6bbe12bb6 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Rootless.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Rootless.c @@ -43,6 +43,10 @@ #include "compext/Compext.h" +/* by dimbor */ +#include "Xatom.h" +#include + /* * Set here the required log level. */ @@ -109,6 +113,10 @@ static TopLevelParentMap topLevelParentMap = { NULL, 0, 0 }; static void nxagentRemovePropertyFromList(void); +/* by dimbor */ +static char szAgentUTF8_STRING[] = "UTF8_STRING"; +static Atom agentUTF8_STRING; + #if 0 /* * This is currently unused. @@ -400,6 +408,28 @@ Window nxagentRootlessWindowParent(WindowPtr pWin) } } +/* by dimbor */ +char *textToUTF8String(char *text, int nitems) +{ + XTextProperty t_prop; + char *ret=NULL; + t_prop.value=((unsigned char *)text); + t_prop.nitems=nitems; + if (!t_prop.nitems) + return ret; + t_prop.format=8; + t_prop.encoding=XInternAtom(nxagentDisplay, "COMPOUND_TEXT", 0); + char **list; + int num; + int r = XmbTextPropertyToTextList(nxagentDisplay, &t_prop,&list, &num); + if ((r == Success || r > 0) && num > 0 && *list) + { + ret=(char *)strdup (*list); + XFreeStringList(list); + } + return ret; +} + int nxagentExportAllProperty(WindowPtr pWin) { int total = 0; @@ -445,6 +475,7 @@ int nxagentExportProperty(WindowPtr pWin, if (strncmp(propertyS, "WM_", 3) != 0 && strncmp(propertyS, "_NET_", 5) != 0 && + strncmp(propertyS, "_MOTIF_", 7) != 0 && strcmp(propertyS, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR") != 0) { #ifdef TEST @@ -456,6 +487,7 @@ int nxagentExportProperty(WindowPtr pWin, } else if (strcmp(typeS, "STRING") == 0 || #ifndef _XSERVER64 + strcmp(typeS, "_MOTIF_WM_HINTS") == 0 || strcmp(typeS, "CARDINAL") == 0 || strcmp(typeS, "WM_SIZE_HINTS") == 0 || #endif @@ -464,8 +496,18 @@ int nxagentExportProperty(WindowPtr pWin, output = value; export = True; } + /* add by dimbor */ + else if (strcmp(typeS, "COMPOUND_TEXT") == 0) + { + output = textToUTF8String(value, nUnits); + nUnits = strlen((char *) output); + type = MakeAtom(szAgentUTF8_STRING, strlen(szAgentUTF8_STRING), True); + freeMem = True; + export = True; + } #ifdef _XSERVER64 - else if (strcmp(typeS, "CARDINAL") == 0 || strcmp(typeS, "WM_SIZE_HINTS") == 0) + else if (strcmp(typeS, "CARDINAL") == 0 || strcmp(typeS, "WM_SIZE_HINTS") == 0 || + strcmp(typeS, "_MOTIF_WM_HINTS") == 0) { unsigned long *buffer = malloc(nUnits * sizeof(*buffer)); if (buffer == NULL)