Skip to content

Commit

Permalink
nxagent: add setlocale for nxwin windows titles recoding (UTF8_STRING…
Browse files Browse the repository at this point in the history
… <-> COMPOUND_TEXT)
  • Loading branch information
dimbor-ru committed Apr 7, 2021
1 parent 4917e50 commit bdc4a8b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
5 changes: 5 additions & 0 deletions nx-X11/config/cf/host.def
Expand Up @@ -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)
17 changes: 17 additions & 0 deletions nx-X11/programs/Xserver/hw/nxagent/Init.c
Expand Up @@ -90,6 +90,9 @@ is" without express or implied warranty.
#undef DEBUG
#undef DUMP

/* by dimbor */
#include <X11/Xlocale.h>

/*
* ProcVector array defined in tables.c.
*/
Expand Down Expand Up @@ -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
Expand Down
44 changes: 43 additions & 1 deletion nx-X11/programs/Xserver/hw/nxagent/Rootless.c
Expand Up @@ -43,6 +43,10 @@

#include "compext/Compext.h"

/* by dimbor */
#include "Xatom.h"
#include <X11/Xlocale.h>

/*
* Set here the required log level.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit bdc4a8b

Please sign in to comment.