Skip to content

Commit

Permalink
Provide for the case when XCreateIC fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
gijsbers committed Jun 15, 2024
1 parent e969d47 commit db637d7
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions src/yinputline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,27 @@ bool YInputLine::handleKey(const XKeyEvent &key) {
}

int YInputLine::getWCharFromEvent(const XKeyEvent& key, wchar_t* s, int maxLen) {
KeySym keysym = None;
Status status = None;
int len = XwcLookupString(inputContext, const_cast<XKeyEvent*>(&key),
s, maxLen, &keysym, &status);

if (inrange(len, 0, maxLen - 1)) {
s[len] = None;
if (inputContext) {
KeySym keysym = None;
Status status = None;
int len = XwcLookupString(inputContext, const_cast<XKeyEvent*>(&key),
s, maxLen, &keysym, &status);

if (inrange(len, 0, maxLen - 1)) {
s[len] = None;
}
return len;
} else {
int len = 0;
char buf[16];
if (getCharFromEvent(key, buf, 16)) {
for (; len + 1 < 16 && len + 1 < maxLen; ++len) {
s[len] = wchar_t(((unsigned char *) buf)[len]);
s[len + 1] = 0;
}
}
return len;
}
return len;
}

void YInputLine::handleButton(const XButtonEvent &button) {
Expand Down Expand Up @@ -894,16 +906,25 @@ void YInputLine::gotFocus() {
XNClientWindow, handle(),
XNFocusWindow, handle(),
nullptr);
unsigned long mask = None;
XGetICValues(inputContext, XNFilterEvents, &mask, nullptr);
if (mask) {
addEventMask(mask);
if (inputContext == nullptr) {
if (ONCE)
warn("Cannot create input context with XCreateIC");
} else {
unsigned long mask = None;
const char* name = XGetICValues(inputContext,
XNFilterEvents, &mask, nullptr);
if (name) {
warn("XGetICValues fails for %s", name);
} else if (mask) {
addEventMask(mask);
}
eventFiltering(true);
}
eventFiltering(true);
}

XSetICFocus(inputContext);
XwcResetIC(inputContext);
if (inputContext) {
XSetICFocus(inputContext);
XwcResetIC(inputContext);
}
}

void YInputLine::lostFocus() {
Expand Down

0 comments on commit db637d7

Please sign in to comment.