Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] Send mapped wchar characters to internal key press #608

Merged
merged 2 commits into from Mar 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -424,15 +430,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