[client] all: use the defined keyboard mapping for keybinds

Fixes #1007
This commit is contained in:
Geoffrey McRae
2022-06-29 18:24:53 +10:00
parent ed0cae84c8
commit da04a6dd54
12 changed files with 151 additions and 76 deletions

View File

@@ -209,6 +209,16 @@ done:
close(fd);
}
static int getCharcode(uint32_t key)
{
xkb_keysym_t sym = xkb_state_key_get_one_sym(wlWm.xkbState, key);
if (sym == XKB_KEY_NoSymbol)
return 0;
sym = xkb_keysym_to_upper(sym);
return xkb_keysym_to_utf32(sym);
}
static void keyboardEnterHandler(void * data, struct wl_keyboard * keyboard,
uint32_t serial, struct wl_surface * surface, struct wl_array * keys)
{
@@ -221,7 +231,7 @@ static void keyboardEnterHandler(void * data, struct wl_keyboard * keyboard,
uint32_t * key;
wl_array_for_each(key, keys)
app_handleKeyPress(*key);
app_handleKeyPress(*key, getCharcode(*key));
}
static void keyboardLeaveHandler(void * data, struct wl_keyboard * keyboard,
@@ -242,9 +252,9 @@ static void keyboardKeyHandler(void * data, struct wl_keyboard * keyboard,
return;
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
app_handleKeyPress(key);
app_handleKeyPress(key, getCharcode(key));
else
app_handleKeyRelease(key);
app_handleKeyRelease(key, getCharcode(key));
if (!wlWm.xkbState || !app_isOverlayMode() || state != WL_KEYBOARD_KEY_STATE_PRESSED)
return;

View File

@@ -36,6 +36,8 @@
#include <X11/extensions/Xpresent.h>
#include <X11/Xcursor/Xcursor.h>
#include <xkbcommon/xkbcommon.h>
#include <GL/glx.h>
#include <GL/glxext.h>
@@ -514,6 +516,10 @@ static bool x11Init(const LG_DSInitParams params)
goto fail_window;
}
XDisplayKeycodes(x11.display, &x11.minKeycode, &x11.maxKeycode);
x11.keysyms = XGetKeyboardMapping(x11.display, x11.minKeycode,
x11.maxKeycode - x11.minKeycode, &x11.symsPerKeycode);
XIFreeDeviceInfo(devinfo);
XQueryExtension(x11.display, "XInputExtension", &x11.xinputOp, &event, &error);
@@ -738,6 +744,9 @@ static void x11Free(void)
if (x11.cursors[i])
XFreeCursor(x11.display, x11.cursors[i]);
if (x11.keysyms)
XFree(x11.keysyms);
XCloseDisplay(x11.display);
}
@@ -1035,6 +1044,17 @@ static void setFocus(bool focused, double x, double y)
app_handleFocusEvent(focused);
}
static int getCharcode(int detail)
{
if (detail < x11.minKeycode || detail > x11.maxKeycode)
return 0;
KeySym sym = x11.keysyms[(detail - x11.minKeycode) *
x11.symsPerKeycode];
sym = xkb_keysym_to_upper(sym);
return xkb_keysym_to_utf32(sym);
}
static void x11XInputEvent(XGenericEventCookie *cookie)
{
static int button_state = 0;
@@ -1126,7 +1146,8 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
return;
XIDeviceEvent *device = cookie->data;
app_handleKeyPress(device->detail - 8);
app_handleKeyPress(device->detail - x11.minKeycode,
getCharcode(device->detail));
if (!x11.xic || !app_isOverlayMode())
return;
@@ -1176,7 +1197,8 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
return;
XIDeviceEvent *device = cookie->data;
app_handleKeyRelease(device->detail - 8);
app_handleKeyRelease(device->detail - x11.minKeycode,
getCharcode(device->detail));
if (!x11.xic || !app_isOverlayMode())
return;
@@ -1205,7 +1227,8 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
return;
XIRawEvent *raw = cookie->data;
app_handleKeyPress(raw->detail - 8);
app_handleKeyPress(raw->detail - x11.minKeycode,
getCharcode(raw->detail));
return;
}
@@ -1215,7 +1238,8 @@ static void x11XInputEvent(XGenericEventCookie *cookie)
return;
XIRawEvent *raw = cookie->data;
app_handleKeyRelease(raw->detail - 8);
app_handleKeyRelease(raw->detail - x11.minKeycode,
getCharcode(raw->detail));
return;
}

View File

@@ -54,6 +54,10 @@ struct X11DSState
Window window;
XVisualInfo * visual;
int minKeycode, maxKeycode;
int symsPerKeycode;
KeySym * keysyms;
//Extended Window Manager Hints
//ref: https://specifications.freedesktop.org/wm-spec/latest/
bool ewmhSupport;