Skip to content

Commit

Permalink
Merge pull request #608 from dmitry-ant/x11-key-press
Browse files Browse the repository at this point in the history
[Linux] Send mapped wchar characters to internal key press
  • Loading branch information
RobDangerous authored Mar 19, 2021
2 parents 15ad056 + 9a8b5fd commit 3a7564d
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Backends/System/Linux/Sources/kinc/backend/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXC
#endif

_XDisplay* Kore::Linux::display = nullptr;
XIC xInputContext;

namespace {
struct MwmHints {
Expand Down Expand Up @@ -123,6 +124,11 @@ int createWindow(const char* title, int x, int y, int width, int height, kinc_wi
fatalError("could not open display");
}

XSetLocaleModifiers("@im=none");
XIM xInputMethod = XOpenIM(Kore::Linux::display, nullptr, nullptr, nullptr);
xInputContext = XCreateIC(xInputMethod, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, nullptr);
XSetICFocus(xInputContext);

XkbSetDetectableAutoRepeat(Kore::Linux::display, True, NULL);

XSetWindowAttributes swa;
Expand Down Expand Up @@ -426,15 +432,23 @@ bool kinc_internal_handle_messages() {
}

switch (event.type) {
case MappingNotify: {
XRefreshKeyboardMapping(&event.xmapping);
}
break;
case KeyPress: {
XKeyEvent* key = (XKeyEvent*)&event;
KeySym keysym;
char buffer[1];
XLookupString(key, buffer, 1, &keysym, NULL);
KeySym keysym = XkbKeycodeToKeysym(Kore::Linux::display, event.xkey.keycode, 0, 0);

if (buffer[0] >= 32 && buffer[0] <= 126) {
kinc_internal_keyboard_trigger_key_press((wchar_t)buffer[0]);
}
bool isIgnoredKeySym = keysym == XK_Escape || keysym == XK_BackSpace || keysym == XK_Delete;
if (!controlDown && !XFilterEvent(&event, win) && !isIgnoredKeySym) {

wchar_t wchar;

if (XwcLookupString(xInputContext, key, &wchar, 1, &keysym, nullptr)) {
kinc_internal_keyboard_trigger_key_press(wchar);
}
}

#define KEY(xkey, korekey) \
case xkey: \
Expand Down

0 comments on commit 3a7564d

Please sign in to comment.