Switch to using XKB for keycode translation. - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 4b8e52f78d6efadffefb275c547bc20ba17b65c9
(DIR) parent a6a8872246e8634d884b0ce52bc3be9770ab1b0f
(HTM) Author: Rob King <jking@deadpixi.com>
Date: Mon, 19 Sep 2016 00:50:27 -0500
Switch to using XKB for keycode translation.
Diffstat:
libXg/gwin.c | 15 ++++++++-------
libXg/libgint.h | 4 ++++
libXg/xtbinit.c | 5 ++++-
3 files changed, 16 insertions(+), 8 deletions(-)
---
(DIR) diff --git a/libXg/gwin.c b/libXg/gwin.c
@@ -6,6 +6,7 @@
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Xatom.h>
+#include <X11/XKBlib.h>
#include <X11/keysym.h>
#ifndef XtSpecificationRelease
@@ -16,6 +17,7 @@
#endif
#include "GwinP.h"
+#include "libgint.h"
/* Forward declarations */
static void Realize(Widget, XtValueMask *, XSetWindowAttributes *);
@@ -245,21 +247,20 @@ Keyaction(Widget w, XEvent *e, String *p, Cardinal *np)
static int composing = -2;
int kind = Kraw;
- int c, minmod;
+ int c, len, minmod;
KeySym k, mk;
Charfunc f;
Modifiers md;
+ char buf[100] = {0};
c = 0;
+ len = 0;
- /*
- * I tried using XtGetActionKeysym, but it didn't seem to
- * do case conversion properly
- * (at least, with Xterminal servers and R4 intrinsics)
- */
+ /* Translate the keycode into a key symbol. */
if(e->xany.type != KeyPress)
return;
- XtTranslateKeycode(e->xany.display, (KeyCode)e->xkey.keycode, e->xkey.state, &md, &k);
+ XkbTranslateKeyCode(xkb, (KeyCode)e->xkey.keycode, e->xkey.state, &md, &k);
+ XkbTranslateKeySym(e->xany.display, &k, e->xkey.state, buf, sizeof(buf) - 1, &len);
/* Check to see if it's a specially-handled key first. */
for (Keymapping *m = keymappings; m; m = m->next){
(DIR) diff --git a/libXg/libgint.h b/libXg/libgint.h
@@ -24,11 +24,15 @@ typedef char* caddr_t;
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
+#include <X11/XKBlib.h>
#include <X11/Xft/Xft.h>
#undef Font
#undef Event
+/* keyboard info */
+extern XkbDescPtr xkb;
+
/* binding and chord management */
void freechords(void);
void freebindings(void);
(DIR) diff --git a/libXg/xtbinit.c b/libXg/xtbinit.c
@@ -14,6 +14,7 @@
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
+#include <X11/XKBlib.h>
#include "Gwin.h"
#ifndef XtSpecificationRelease
@@ -48,6 +49,7 @@
#endif
/* libg globals */
+XkbDescPtr xkb;
Bitmap screen;
XftFont *font;
XftColor fontcolor;
@@ -138,7 +140,6 @@ static XtActionsRec wmpactions[] = {
static XrmOptionDescRec optable[] = {
};
-
void
xtbinit(Errfunc f, char *class, int *pargc, char **argv, char **fallbacks)
{
@@ -216,6 +217,8 @@ xtbinit(Errfunc f, char *class, int *pargc, char **argv, char **fallbacks)
atexit(freebindings);
atexit(freechords);
+ xkb = XkbGetKeyboard(_dpy, XkbAllComponentsMask, XkbUseCoreKbd);
+
font = XftFontOpenName(_dpy, DefaultScreen(_dpy), fontspec[0] ? fontspec : getenv("FONT") ? getenv("FONT") : "monospace");
screen.id = 0;
XtRealizeWidget(_toplevel);