diff options
author | Pace Willisson <pace@alum.mit.edu> | 2022-06-03 09:22:08 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-06-03 15:00:10 -0400 |
commit | 2e0fb50d3fb5008e6cabcef28e14177b64e678bd (patch) | |
tree | dd8f507e609c24482f6cf16c8c15345e460ae83f /src | |
parent | abdf052c7c3c206511878aa10bce700cfb9701b5 (diff) | |
download | pugl-2e0fb50d3fb5008e6cabcef28e14177b64e678bd.tar.gz pugl-2e0fb50d3fb5008e6cabcef28e14177b64e678bd.tar.bz2 pugl-2e0fb50d3fb5008e6cabcef28e14177b64e678bd.zip |
X11: Fix crash when input context is unavailable due to locales
Calling X*ICFocus on NULL segfaults. This can happen if XCreateIC failed, for
example due to missing locales on minimal Docker images.
Diffstat (limited to 'src')
-rw-r--r-- | src/x11.c | 28 |
1 files changed, 17 insertions, 11 deletions
@@ -457,14 +457,16 @@ puglRealize(PuglView* const view) } // Create input context - impl->xic = XCreateIC(world->impl->xim, - XNInputStyle, - XIMPreeditNothing | XIMStatusNothing, - XNClientWindow, - impl->win, - XNFocusWindow, - impl->win, - (XIM)0); + if (world->impl->xim) { + impl->xic = XCreateIC(world->impl->xim, + XNInputStyle, + XIMPreeditNothing | XIMStatusNothing, + XNClientWindow, + impl->win, + XNFocusWindow, + impl->win, + (XIM)0); + } puglDispatchSimpleEvent(view, PUGL_CREATE); @@ -619,7 +621,7 @@ translateKey(PuglView* const view, XEvent* const xevent, PuglEvent* const event) event->key.key = ((special || ufound <= 0) ? special : puglDecodeUTF8((const uint8_t*)ustr)); - if (xevent->type == KeyPress && !filter && !special) { + if (xevent->type == KeyPress && !filter && !special && view->impl->xic) { // Lookup shifted key for possible text event xevent->xkey.state = state; @@ -1393,9 +1395,13 @@ dispatchX11Events(PuglWorld* const world) continue; } } else if (xevent.type == FocusIn) { - XSetICFocus(impl->xic); + if (impl->xic) { + XSetICFocus(impl->xic); + } } else if (xevent.type == FocusOut) { - XUnsetICFocus(impl->xic); + if (impl->xic) { + XUnsetICFocus(impl->xic); + } } else if (xevent.type == SelectionClear) { PuglX11Clipboard* const board = getX11SelectionClipboard(view, xevent.xselectionclear.selection); |