Linux: make accented character input work
This commit is contained in:
parent
a66e0027a9
commit
b76ea2d616
|
@ -107,6 +107,16 @@ static void closeUnicodeStructs() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setupIMEventMask() {
|
||||||
|
long im_event_mask;
|
||||||
|
XWindowAttributes win_attributes;
|
||||||
|
|
||||||
|
XGetWindowAttributes(getDisplay(), getCurrentWindow(), &win_attributes);
|
||||||
|
XGetICValues(xic, XNFilterEvents, &im_event_mask, NULL);
|
||||||
|
XSelectInput(getDisplay(), getCurrentWindow(), win_attributes.your_event_mask | im_event_mask);
|
||||||
|
XSetICFocus(xic);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
||||||
(JNIEnv * env, jclass clazz)
|
(JNIEnv * env, jclass clazz)
|
||||||
{
|
{
|
||||||
|
@ -149,7 +159,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
||||||
xim = XOpenIM(getDisplay(), NULL, NULL, NULL);
|
xim = XOpenIM(getDisplay(), NULL, NULL, NULL);
|
||||||
if (xim != NULL) {
|
if (xim != NULL) {
|
||||||
xic = XCreateIC(xim, XNClientWindow, getCurrentWindow(), XNFocusWindow, getCurrentWindow(), XNInputStyle, XIMPreeditNothing | XIMStatusNothing, NULL);
|
xic = XCreateIC(xim, XNClientWindow, getCurrentWindow(), XNFocusWindow, getCurrentWindow(), XNInputStyle, XIMPreeditNothing | XIMStatusNothing, NULL);
|
||||||
if (xic == NULL) {
|
if (xic != NULL) {
|
||||||
|
setupIMEventMask();
|
||||||
|
} else {
|
||||||
closeUnicodeStructs();
|
closeUnicodeStructs();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -190,6 +202,7 @@ static int lookupStringISO88591(XKeyEvent *event, jint *translation_buffer) {
|
||||||
|
|
||||||
static int lookupStringUnicode(XKeyEvent *event, jint *translation_buffer) {
|
static int lookupStringUnicode(XKeyEvent *event, jint *translation_buffer) {
|
||||||
char utf8_translation_buffer[KEYBOARD_BUFFER_SIZE];
|
char utf8_translation_buffer[KEYBOARD_BUFFER_SIZE];
|
||||||
|
|
||||||
jchar ucs2_translation_buffer[KEYBOARD_BUFFER_SIZE];
|
jchar ucs2_translation_buffer[KEYBOARD_BUFFER_SIZE];
|
||||||
char *utf8_buf = utf8_translation_buffer;
|
char *utf8_buf = utf8_translation_buffer;
|
||||||
jchar *ucs2_buf = ucs2_translation_buffer;
|
jchar *ucs2_buf = ucs2_translation_buffer;
|
||||||
|
@ -197,11 +210,9 @@ static int lookupStringUnicode(XKeyEvent *event, jint *translation_buffer) {
|
||||||
Status status;
|
Status status;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
XSetICFocus(xic);
|
|
||||||
size_t utf8_bytes = Xutf8LookupString(xic, event, utf8_translation_buffer, KEYBOARD_BUFFER_SIZE*sizeof(char), NULL, &status);
|
size_t utf8_bytes = Xutf8LookupString(xic, event, utf8_translation_buffer, KEYBOARD_BUFFER_SIZE*sizeof(char), NULL, &status);
|
||||||
if (status != XLookupChars && status != XLookupBoth)
|
if (status != XLookupChars && status != XLookupBoth)
|
||||||
return 0;
|
return 0;
|
||||||
XUnsetICFocus(xic);
|
|
||||||
// reset converter
|
// reset converter
|
||||||
iconv(iconv_descriptor, NULL, NULL, NULL, NULL);
|
iconv(iconv_descriptor, NULL, NULL, NULL, NULL);
|
||||||
// convert from UTF-8 to UCS-2
|
// convert from UTF-8 to UCS-2
|
||||||
|
|
|
@ -254,6 +254,8 @@ void handleMessages(void) {
|
||||||
int revert_mode;
|
int revert_mode;
|
||||||
while (XPending(getDisplay()) > 0) {
|
while (XPending(getDisplay()) > 0) {
|
||||||
XNextEvent(getDisplay(), &event);
|
XNextEvent(getDisplay(), &event);
|
||||||
|
if (XFilterEvent(&event, None) == True)
|
||||||
|
continue;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
if (event.xclient.message_type == warp_atom) {
|
if (event.xclient.message_type == warp_atom) {
|
||||||
|
|
Loading…
Reference in New Issue