aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11.c
diff options
context:
space:
mode:
authorPace Willisson <pace@alum.mit.edu>2022-06-03 09:22:08 -0400
committerDavid Robillard <d@drobilla.net>2022-06-03 15:00:10 -0400
commit2e0fb50d3fb5008e6cabcef28e14177b64e678bd (patch)
treedd8f507e609c24482f6cf16c8c15345e460ae83f /src/x11.c
parentabdf052c7c3c206511878aa10bce700cfb9701b5 (diff)
downloadpugl-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/x11.c')
-rw-r--r--src/x11.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/x11.c b/src/x11.c
index cd3fbb0..b9845fc 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -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);