workaround problem when unable to get input context

This commit is contained in:
David Rose 2008-03-24 18:19:57 +00:00
parent 89d07d7c4a
commit 81bef7355c

View File

@ -699,13 +699,17 @@ open_window() {
// nicer if we could support fancy IM's that want preedit callbacks, // nicer if we could support fancy IM's that want preedit callbacks,
// etc., but that can wait until we have an X server that actually // etc., but that can wait until we have an X server that actually
// supports these to test it on. // supports these to test it on.
_ic = XCreateIC XIM im = glx_pipe->get_im();
(glx_pipe->get_im(), _ic = NULL;
XNInputStyle, XIMPreeditNothing | XIMStatusNothing, if (im) {
NULL); _ic = XCreateIC
if (_ic == (XIC)NULL) { (im,
glxdisplay_cat.warning() XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
<< "Couldn't create input context.\n"; NULL);
if (_ic == (XIC)NULL) {
glxdisplay_cat.warning()
<< "Couldn't create input context.\n";
}
} }
if (_properties.get_cursor_hidden()) { if (_properties.get_cursor_hidden()) {
@ -1205,21 +1209,30 @@ void glxGraphicsWindow::
handle_keystroke(XKeyEvent &event) { handle_keystroke(XKeyEvent &event) {
_input_devices[0].set_pointer_in_window(event.x, event.y); _input_devices[0].set_pointer_in_window(event.x, event.y);
// First, get the keystroke as a wide-character sequence. if (_ic) {
static const int buffer_size = 256; // First, get the keystroke as a wide-character sequence.
wchar_t buffer[buffer_size]; static const int buffer_size = 256;
Status status; wchar_t buffer[buffer_size];
int len = XwcLookupString(_ic, &event, buffer, buffer_size, NULL, Status status;
&status); int len = XwcLookupString(_ic, &event, buffer, buffer_size, NULL,
if (status == XBufferOverflow) { &status);
glxdisplay_cat.error() if (status == XBufferOverflow) {
<< "Overflowed input buffer.\n"; glxdisplay_cat.error()
} << "Overflowed input buffer.\n";
}
// Now each of the returned wide characters represents a
// keystroke. // Now each of the returned wide characters represents a
for (int i = 0; i < len; i++) { // keystroke.
_input_devices[0].keystroke(buffer[i]); for (int i = 0; i < len; i++) {
_input_devices[0].keystroke(buffer[i]);
}
} else {
// Without an input context, just get the ascii keypress.
ButtonHandle button = get_button(event);
if (button.has_ascii_equivalent()) {
_input_devices[0].keystroke(button.get_ascii_equivalent());
}
} }
} }