Treat keyboard events as structured events. - sam - An updated version of the s… | |
git clone git://vernunftzentrum.de/sam.git | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 7dbd2384a6bb71e4f846fd69ce323a43d1bccec6 | |
parent 008130285693511e05f4b8da9b3331af5bc0a7ad | |
Author: Rob King <[email protected]> | |
Date: Tue, 17 May 2016 17:43:08 -0500 | |
Treat keyboard events as structured events. | |
Keyboard events are now structures with two members: c, the | |
(possibly composed) key that was pressed; and composed, which | |
is nonzero if the key was composed of multiple keystrokes. | |
This was done so that we can reliabily differentiate between | |
composed and "normal" keystrokes. This makes it possible to | |
insert tabs even when tab expansion is enabled (meaning a user | |
could turn it on by default and still edit Makefiles easily). | |
Diffstat: | |
include/libg.h | 11 +++++++++-- | |
libXg/Gwin.h | 2 +- | |
libXg/GwinP.h | 3 +++ | |
libXg/arith.c | 4 ++++ | |
libXg/clipline.c | 2 +- | |
libXg/gcs.c | 2 +- | |
libXg/gwin.c | 14 +++++++++----- | |
libXg/latin1.c | 4 ++-- | |
libXg/rectclip.c | 2 +- | |
libXg/xtbinit.c | 22 +++++++++++++--------- | |
10 files changed, 44 insertions(+), 22 deletions(-) | |
--- | |
diff --git a/include/libg.h b/include/libg.h | |
@@ -23,6 +23,7 @@ typedef struct Bitmap Bitmap; | |
typedef struct Point Point; | |
typedef struct Rectangle Rectangle; | |
typedef struct Cursor Cursor; | |
+typedef struct Keystroke Keystroke; | |
typedef struct Mouse Mouse; | |
typedef struct Menu Menu; | |
typedef struct Event Event; | |
@@ -57,6 +58,12 @@ struct Mouse | |
unsigned long msec; | |
}; | |
+struct Keystroke | |
+{ | |
+ int c; | |
+ int composed; | |
+}; | |
+ | |
struct Cursor | |
{ | |
Point offset; | |
@@ -74,7 +81,7 @@ struct Menu | |
struct Event | |
{ | |
- int kbdc; | |
+ Keystroke keystroke; | |
Mouse mouse; | |
int n; /* number of characters in mesage… | |
unsigned char data[EMAXMSG]; /* message from an arbitrar… | |
@@ -182,7 +189,7 @@ extern unsigned long etimer(unsigned long, long); | |
extern unsigned long event(Event*); | |
extern unsigned long eread(unsigned long, Event*); | |
extern Mouse emouse(void); | |
-extern int ekbd(void); | |
+extern Keystroke ekbd(void); | |
extern int ecanread(unsigned long); | |
extern int ecanmouse(void); | |
extern int ecankbd(void); | |
diff --git a/libXg/Gwin.h b/libXg/Gwin.h | |
@@ -34,7 +34,7 @@ typedef struct { | |
} Gwinmouse; | |
typedef void (*Reshapefunc)(int, int, int, int); | |
-typedef void (*Charfunc)(int); | |
+typedef void (*Charfunc)(int, int); | |
typedef void (*Mousefunc)(Gwinmouse*); | |
/* Method declarations */ | |
diff --git a/libXg/GwinP.h b/libXg/GwinP.h | |
@@ -42,4 +42,7 @@ typedef struct _GwinClassRec { | |
/* External definition for class record */ | |
extern GwinClassRec gwinClassRec; | |
+int unicode(unsigned char *k); | |
+int latin1(unsigned char *k); | |
+ | |
#endif /* GWINP_H */ | |
diff --git a/libXg/arith.c b/libXg/arith.c | |
@@ -108,17 +108,20 @@ rshift(Rectangle r, int a) | |
return r; | |
} | |
+int | |
eqpt(Point p, Point q) | |
{ | |
return p.x==q.x && p.y==q.y; | |
} | |
+int | |
eqrect(Rectangle r, Rectangle s) | |
{ | |
return r.min.x==s.min.x && r.max.x==s.max.x && | |
r.min.y==s.min.y && r.max.y==s.max.y; | |
} | |
+int | |
rectXrect(Rectangle r, Rectangle s) | |
{ | |
return r.min.x<s.max.x && s.min.x<r.max.x && | |
@@ -135,6 +138,7 @@ rectinrect(Rectangle r, Rectangle s) | |
return r.max.x<=s.max.x && r.max.y<=s.max.y; | |
} | |
+int | |
ptinrect(Point p, Rectangle r) | |
{ | |
return p.x>=r.min.x && p.x<r.max.x && | |
diff --git a/libXg/clipline.c b/libXg/clipline.c | |
@@ -133,7 +133,7 @@ gsetline(Point *pp0, Point *pp1, Linedesc *l) | |
* Newman & Sproull 124 (1st edition) | |
*/ | |
-static | |
+static int | |
code(Point *p, Rectangle *r) | |
{ | |
return( (p->x<r->min.x? 1 : p->x>=r->max.x? 2 : 0) | | |
diff --git a/libXg/gcs.c b/libXg/gcs.c | |
@@ -161,7 +161,7 @@ GC | |
_getgc(Bitmap *b, unsigned long gcvm, XGCValues *pgcv) | |
{ | |
static GC gc0, gcn; | |
- static clipset = 0; | |
+ static int clipset = 0; | |
GC g; | |
XRectangle xr; | |
diff --git a/libXg/gwin.c b/libXg/gwin.c | |
@@ -10,6 +10,7 @@ typedef char* caddr_t; | |
#include <X11/Xatom.h> | |
#include <X11/keysym.h> | |
+ | |
#ifndef XtSpecificationRelease | |
#define R3 | |
#define XtPointer caddr_t | |
@@ -161,13 +162,14 @@ Mappingaction(Widget w, XEvent *e, String *p, Cardinal *n… | |
f = ((GwinWidget)w)->gwin.gotchar; \ | |
if (f) \ | |
for (c = 0; c < composing; c++) \ | |
- (*f)(compose[c]) | |
+ (*f)(compose[c], 0) | |
static void | |
Keyaction(Widget w, XEvent *e, String *p, Cardinal *np) | |
{ | |
static unsigned char compose[5]; | |
static int composing = -2; | |
+ int composed = 0; | |
int c, minmod; | |
KeySym k, mk; | |
@@ -275,11 +277,12 @@ Keyaction(Widget w, XEvent *e, String *p, Cardinal *np) | |
c = (unsigned short)k; | |
composing = -2; | |
} else if (composing == 4) { | |
- c = (int)unicode(compose); | |
+ c = unicode(compose); | |
if (c == -1) { | |
STUFFCOMPOSE(); | |
c = (unsigned short)compose[4]; | |
- } | |
+ } else | |
+ composed = 1; | |
composing = -2; | |
} | |
} else if (composing == 1) { | |
@@ -287,7 +290,8 @@ Keyaction(Widget w, XEvent *e, String *p, Cardinal *np) | |
if (c == -1) { | |
STUFFCOMPOSE(); | |
c = (unsigned short)compose[1]; | |
- } | |
+ } else | |
+ composed = 1; | |
composing = -2; | |
} | |
} else { | |
@@ -304,7 +308,7 @@ Keyaction(Widget w, XEvent *e, String *p, Cardinal *np) | |
f = ((GwinWidget)w)->gwin.gotchar; | |
if(f) | |
- (*f)(c); | |
+ (*f)(c, composed); | |
} | |
static void | |
diff --git a/libXg/latin1.c b/libXg/latin1.c | |
@@ -291,10 +291,10 @@ latin1(unsigned char *k) | |
return -1; | |
} | |
-long | |
+int | |
unicode(unsigned char *k) | |
{ | |
- long i, c; | |
+ int i, c; | |
k++; /* skip 'X' */ | |
c = 0; | |
diff --git a/libXg/rectclip.c b/libXg/rectclip.c | |
@@ -3,7 +3,7 @@ | |
#include <libc.h> | |
#include <libg.h> | |
-rectclip(Rectangle *rp, Rectangle b) /* first by reference, sec… | |
+int rectclip(Rectangle *rp, Rectangle b) /* first by reference,… | |
{ | |
Rectangle *bp = &b; | |
/* | |
diff --git a/libXg/xtbinit.c b/libXg/xtbinit.c | |
@@ -59,7 +59,7 @@ static Mouse lastmouse; | |
typedef struct Ebuf { | |
struct Ebuf *next; | |
int n; | |
- unsigned char buf[2]; | |
+ unsigned char buf[20]; /* note that this must be at least as large … | |
} Ebuf; | |
typedef struct Esrc { | |
@@ -84,7 +84,7 @@ static int Stimer = -1; | |
static void reshaped(int, int, int, int); | |
-static void gotchar(int); | |
+static void gotchar(int, int); | |
static void gotmouse(Gwinmouse *); | |
static int ilog2(int); | |
static void pixtocolor(Pixel, XColor *); | |
@@ -278,16 +278,19 @@ reshaped(int minx, int miny, int maxx, int maxy) | |
} | |
static void | |
-gotchar(int c) | |
+gotchar(int c, int composed) | |
{ | |
Ebuf *eb; | |
+ Keystroke k; | |
if(!einitcalled || Skeyboard == -1) | |
return; | |
eb = ebadd(&esrc[Skeyboard]); | |
if (eb == 0) | |
berror("eballoc can't malloc"); | |
- BPSHORT(eb->buf, (unsigned short)(c & 0xffff)); | |
+ k.c = c; | |
+ k.composed = composed; | |
+ memcpy(eb->buf, &k, sizeof(Keystroke)); | |
esrc[Skeyboard].count++; | |
} | |
@@ -541,7 +544,7 @@ einit(unsigned long keys) | |
if(keys&Ekeyboard){ | |
Skeyboard = 1; | |
esrc[Skeyboard].inuse = 1; | |
- esrc[Skeyboard].size = 1; | |
+ esrc[Skeyboard].size = sizeof(Keystroke); | |
esrc[Skeyboard].count = 0; | |
if(Skeyboard >= nsrc) | |
nsrc = Skeyboard+1; | |
@@ -619,7 +622,7 @@ eread(unsigned long keys, Event *e) | |
if(i == Smouse) | |
e->mouse = emouse(); | |
else if(i == Skeyboard) | |
- e->kbdc = ekbd(); | |
+ e->keystroke = ekbd(); | |
else if(i == Stimer) { | |
esrc[i].head = 0; | |
esrc[i].count = 0; | |
@@ -671,18 +674,19 @@ emouse(void) | |
return m; | |
} | |
-int | |
+Keystroke | |
ekbd(void) | |
{ | |
Ebuf *eb; | |
int c; | |
+ Keystroke k; | |
if(!esrc[Skeyboard].inuse) | |
berror("keyboard events not selected"); | |
eb = ebread(&esrc[Skeyboard]); | |
- c = BGSHORT(eb->buf); | |
+ memcpy(&k, eb->buf, sizeof(Keystroke)); | |
free(eb); | |
- return c; | |
+ return k; | |
} | |
int |