changeset: 63:d045f7fc239f
tag: tip
user: Aur?lien Aptel <aurelien.aptel_AT_gmail.com>
date: Sun Jun 21 19:37:12 2009 +0200
files: config.h st.c
description:
updated "key" to a lookup table.
diff -r a8c13209607a -r d045f7fc239f config.h
--- a/config.h Wed Jun 17 20:44:36 2009 +0200
+++ b/config.h Sun Jun 21 19:37:12 2009 +0200
@@ -24,16 +24,15 @@
#define DefaultCS 1
#define BellCol DefaultFG
-
/* special keys */
-static Key key[] = {
- { XK_Delete, "\033[3~" },
- { XK_Home, "\033[1~" },
- { XK_End, "\033[4~" },
- { XK_Prior, "\033[5~" },
- { XK_Next, "\033[6~" },
- { XK_Left, "\033[D" },
- { XK_Right, "\033[C" },
- { XK_Up, "\033[A" },
- { XK_Down, "\033[B" },
+static char* key[] = {
+ [XK_Delete] = "\033[3~",
+ [XK_Home] = "\033[1~",
+ [XK_End] = "\033[4~",
+ [XK_Prior] = "\033[5~",
+ [XK_Next] = "\033[6~",
+ [XK_Left] = "\033[D",
+ [XK_Right] = "\033[C",
+ [XK_Up] = "\033[A",
+ [XK_Down] = "\033[B",
};
diff -r a8c13209607a -r d045f7fc239f st.c
--- a/st.c Wed Jun 17 20:44:36 2009 +0200
+++ b/st.c Sun Jun 21 19:37:12 2009 +0200
@@ -40,12 +40,9 @@
enum { TMwrap=1, TMinsert=2 };
enum { SCupdate, SCredraw };
+#include "config.h"
+
typedef int Color;
-
-typedef struct {
- KeySym k;
- char s[ESCSIZ];
-} Key;
typedef struct {
char c; /* character code */
@@ -97,8 +94,6 @@
int ch; /* char height */
int cw; /* char width */
} XWindow;
-
-#include "config.h"
/* Drawing Context */
typedef struct {
@@ -997,15 +992,6 @@
xcursor(CSdraw);
}
-char*
-kmap(KeySym k) {
- int i;
- for(i = 0; i < LEN(key); i++)
- if(key[i].k == k)
- return (char*)key[i].s;
- return NULL;
-}
-
void
kpress(XKeyEvent *e) {
KeySym ksym;
@@ -1018,7 +1004,7 @@
meta = e->state & Mod1Mask;
shift = e->state & ShiftMask;
len = XLookupString(e, buf, sizeof(buf), &ksym, NULL);
- if(skmap = kmap(ksym))
+ if(skmap = key[ksym])
ttywrite(skmap, strlen(skmap));
else if(len > 0) {
buf[sizeof(buf)-1] = '\0';
Received on Sun Jun 21 2009 - 15:37:19 UTC
This archive was generated by hypermail 2.2.0 : Sun Jun 21 2009 - 15:48:05 UTC