summaryrefslogtreecommitdiffstats
path: root/client/x11/red_window.cpp
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-04-21 13:40:13 +0200
committerAlexander Larsson <alexl@redhat.com>2010-04-23 16:36:31 +0200
commit9c02d1539624403506b93fc6b5cb425978fcfd92 (patch)
tree1f9188dd24021bdc2a4c512b70eac081660b72e6 /client/x11/red_window.cpp
parent43a61bb6fe1e9741e686fc57b51e782432c384de (diff)
downloadspice-9c02d1539624403506b93fc6b5cb425978fcfd92.tar.gz
spice-9c02d1539624403506b93fc6b5cb425978fcfd92.tar.xz
spice-9c02d1539624403506b93fc6b5cb425978fcfd92.zip
Client: Don't die if XIM not availible
Diffstat (limited to 'client/x11/red_window.cpp')
-rw-r--r--client/x11/red_window.cpp65
1 files changed, 39 insertions, 26 deletions
diff --git a/client/x11/red_window.cpp b/client/x11/red_window.cpp
index b3b9cace..6de86bf2 100644
--- a/client/x11/red_window.cpp
+++ b/client/x11/red_window.cpp
@@ -714,7 +714,6 @@ static inline SpiceMouseButton to_red_button(unsigned int botton, unsigned int&
void RedWindow_p::handle_key_press_event(RedWindow& window, XKeyEvent* event)
{
static int buf_size = 0;
- static char* utf8_buf = NULL;
static wchar_t* utf32_buf = NULL;
KeySym key_sym;
@@ -722,35 +721,47 @@ void RedWindow_p::handle_key_press_event(RedWindow& window, XKeyEvent* event)
int len;
window.get_listener().on_key_press(to_red_key_code(event->keycode));
- for (;;) {
- len = XwcLookupString(x_input_context, event, utf32_buf, buf_size, &key_sym, &status);
- if (status != XBufferOverflow) {
- break;
+
+ if (x_input_context != NULL) {
+ for (;;) {
+ len = XwcLookupString(x_input_context, event, utf32_buf, buf_size, &key_sym, &status);
+ if (status != XBufferOverflow) {
+ break;
+ }
+
+ if (utf32_buf) {
+ delete [] utf32_buf;
+ }
+ utf32_buf = new wchar_t[len];
+ buf_size = len;
}
- free(utf32_buf);
- free(utf32_buf);
- utf8_buf = new char[len];
- utf32_buf = new wchar_t[len];
- buf_size = len;
- }
+ switch (status) {
+ case XLookupChars:
+ case XLookupBoth: {
+ uint32_t* now = (uint32_t*)utf32_buf;
+ uint32_t* end = now + len;
+
+ for (; now < end; now++) {
+ window.get_listener().on_char(*now);
+ }
+ break;
+ }
- switch (status) {
- case XLookupChars:
- case XLookupBoth: {
- uint32_t* now = (uint32_t*)utf32_buf;
- uint32_t* end = now + len;
+ case XLookupNone:
+ case XLookupKeySym:
+ break;
+ default:
+ THROW("unexpected status %d", status);
+ }
+ } else { /* no XIM */
+ unsigned char buffer[16];
+ int i;
- for (; now < end; now++) {
- window.get_listener().on_char(*now);
+ len = XLookupString(event, (char *)buffer, sizeof(buffer), NULL, NULL);
+ for (i = 0; i < len; i++) {
+ window.get_listener().on_char((uint32_t)buffer[i]);
}
- break;
- }
- case XLookupNone:
- case XLookupKeySym:
- break;
- default:
- THROW("unexpected status %d", status);
}
}
@@ -1962,7 +1973,9 @@ void RedWindow::on_focus_in()
return;
}
_focused = true;
- XwcResetIC(x_input_context);
+ if (x_input_context) {
+ XwcResetIC(x_input_context);
+ }
XPlatform::on_focus_in();
get_listener().on_activate();
if (_trace_key_interception && _pointer_in_window) {