* Source/x11/XIMInputServer.m: Remove the locale setting code.

Use the correct #ifdef check for Xutf8LookupString, and use
that function if available; otherwise use XLookupString.
Interpret the return value of XLookupString as Latin-1.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@35152 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Eric Wasylishen 2012-05-13 02:41:30 +00:00
parent 091480978b
commit a8860a1493
3 changed files with 39 additions and 63 deletions

View file

@ -1,3 +1,10 @@
2012-05-12 Eric Wasylishen <ewasylishen@gmail.com>
* Source/x11/XIMInputServer.m: Remove the locale setting code.
Use the correct #ifdef check for Xutf8LookupString, and use
that function if available; otherwise use XLookupString.
Interpret the return value of XLookupString as Latin-1.
2012-03-22 Eric Wasylishen <ewasylishen@gmail.com> 2012-03-22 Eric Wasylishen <ewasylishen@gmail.com>
* Source/x11/XGServerEvent.m: Make the GSModifiersAreKeys * Source/x11/XGServerEvent.m: Make the GSModifiersAreKeys

View file

@ -44,8 +44,6 @@
NSString *server_name; NSString *server_name;
XIM xim; XIM xim;
XIMStyle xim_style; XIMStyle xim_style;
NSMutableData *dbuf;
NSStringEncoding encoding;
/* Track the XIC:s and destroy them explicitly to work around an XFree86 /* Track the XIC:s and destroy them explicitly to work around an XFree86
bug: bug:

View file

@ -68,32 +68,8 @@
display: (Display *)dpy display: (Display *)dpy
name: (NSString *)name name: (NSString *)name
{ {
char *locale;
delegate = aDelegate; delegate = aDelegate;
ASSIGN(server_name, name); ASSIGN(server_name, name);
dbuf = RETAIN([NSMutableData dataWithCapacity: BUF_LEN]);
/* Use X11 version of setlocale since many people just set the locale
for X. Also just get CTYPE locale (which is typically the one that
deals with character handling */
locale = setlocale(LC_CTYPE, "");
if (XSupportsLocale() != True)
{
NSLog(@"Xlib does not support locale setting %s", locale);
/* FIXME: Should we reset the locale or just hope that X
can deal with it? */
}
encoding = GSEncodingFromLocale(locale);
#ifndef HAVE_UTF8
if (encoding == NSUTF8StringEncoding)
encoding = GSUndefinedEncoding;
#endif
if (encoding == GSUndefinedEncoding)
{
encoding = [NSString defaultCStringEncoding];
}
NSDebugLLog(@"XIM", @"XIM locale encoding for %s is %@", locale,
[NSString localizedNameOfStringEncoding: encoding]);
#ifdef USE_XIM #ifdef USE_XIM
if ([self ximInit: dpy] == NO) if ([self ximInit: dpy] == NO)
@ -107,7 +83,6 @@
- (void) dealloc - (void) dealloc
{ {
DESTROY(server_name); DESTROY(server_name);
DESTROY(dbuf);
[self ximClose]; [self ximClose];
[super dealloc]; [super dealloc];
} }
@ -129,56 +104,52 @@
window: (gswindow_device_t *)windev window: (gswindow_device_t *)windev
keysym: (KeySym *)keysymptr keysym: (KeySym *)keysymptr
{ {
int count; int count = 0;
Status status; NSString *keys = nil;
NSString *keys; KeySym keysym = 0;
KeySym keysym; char buf[BUF_LEN];
XComposeStatus compose;
char *buf = [dbuf mutableBytes];
/* Process characters */ /* Process characters */
keys = nil;
/* N.B. The Xutf8LookupString manpage says this macro will be defined
in the X headers if that function is available. */
#if defined(X_HAVE_UTF8_STRING)
if (windev->ic && event->type == KeyPress) if (windev->ic && event->type == KeyPress)
{ {
[dbuf setLength: BUF_LEN]; Status status = 0;
#ifdef HAVE_UTF8 count = Xutf8LookupString(windev->ic, event, buf, BUF_LEN,
#ifdef HAVE_XUTF8LOOKUPSTRING &keysym, &status);
if (encoding == NSUTF8StringEncoding)
count = Xutf8LookupString(windev->ic, event, buf, BUF_LEN,
&keysym, &status);
else
#endif
#endif
count = XmbLookupString(windev->ic, event, buf, BUF_LEN,
&keysym, &status);
if (status==XBufferOverflow) if (status==XBufferOverflow)
NSDebugLLog(@"NSKeyEvent",@"XmbLookupString buffer overflow\n"); NSDebugLLog(@"NSKeyEvent",@"XmbLookupString buffer overflow\n");
if (count) if (count)
{ {
[dbuf setLength: count]; keys = [[[NSString alloc] initWithBytes: buf
keys = AUTORELEASE([[NSString alloc] initWithData: dbuf encoding: encoding]); length: count
encoding: NSUTF8StringEncoding] autorelease];
} }
} if (status == XLookupKeySym
else || status == XLookupBoth)
{
count = XLookupString (event, buf, BUF_LEN, &keysym, &compose);
/* Make sure that the string is properly terminated */
if (count > BUF_LEN)
buf[BUF_LEN] = '\0';
else
{ {
if (count < 1) if (keysymptr)
buf[0] = '\0'; *keysymptr = keysym;
else
buf[count] = '\0';
} }
if (count)
keys = [NSString stringWithCString: buf];
} }
else
#endif
{
/* Always returns a Latin-1 string according to the manpage */
count = XLookupString (event, buf, BUF_LEN, &keysym, NULL);
if (count)
{
keys = [[[NSString alloc] initWithBytes: buf
length: count
encoding: NSISOLatin1StringEncoding] autorelease];
}
if (keysymptr) if (keysymptr)
*keysymptr = keysym; *keysymptr = keysym;
}
return keys; return keys;
} }