aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-11 11:50:18 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-11 11:50:18 +0200
commit366d81e313e6dd4e9e6c61ed8dfca4b4b40ccde6 (patch)
tree78ac7ac7de2fb2b4373dc5d6f67a70e2642ed347
parent8a8b7956b6de80decbfd3bff6d2ad6e5bb69b2bd (diff)
downloaddwm-366d81e313e6dd4e9e6c61ed8dfca4b4b40ccde6.tar.gz
added key handling
-rw-r--r--Makefile2
-rw-r--r--config.h2
-rw-r--r--key.c26
-rw-r--r--wm.c29
-rw-r--r--wm.h15
5 files changed, 44 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index c5c8db4..32c9492 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
include config.mk
-WMSRC = bar.c client.c draw.c event.c util.c wm.c
+WMSRC = bar.c client.c cmd.c draw.c event.c key.c util.c wm.c
WMOBJ = ${WMSRC:.c=.o}
MENSRC = menu.c draw.c util.c
MENOBJ = ${MENSRC:.c=.o}
diff --git a/config.h b/config.h
index 58ed8ea..d37034d 100644
--- a/config.h
+++ b/config.h
@@ -9,3 +9,5 @@
#define BORDERCOLOR "#000000"
#define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
" `acpi | awk '{print $4}' | sed 's/,//'`"
+#define KEYS \
+ { Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn -*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" },
diff --git a/key.c b/key.c
new file mode 100644
index 0000000..a8742da
--- /dev/null
+++ b/key.c
@@ -0,0 +1,26 @@
+/*
+ * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
+ * See LICENSE file for license details.
+ */
+
+#include "wm.h"
+
+#include <X11/keysym.h>
+
+static Key key[] = {
+ KEYS
+};
+
+void
+update_keys()
+{
+ unsigned int i, len;
+ KeyCode code;
+
+ len = sizeof(key) / sizeof(key[0]);
+ for(i = 0; i < len; i++) {
+ code = XKeysymToKeycode(dpy, key[i].keysym);
+ XUngrabKey(dpy, code, key[i].mod, root);
+ XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
+ }
+}
diff --git a/wm.c b/wm.c
index a4caf64..038e6b9 100644
--- a/wm.c
+++ b/wm.c
@@ -24,7 +24,6 @@ Client *client = NULL;
char *bartext, tag[256];
int screen, sel_screen;
-unsigned int lock_mask, numlock_mask;
/* draw structs */
Brush brush = {0};
@@ -144,32 +143,6 @@ startup_error_handler(Display *dpy, XErrorEvent *error)
}
static void
-init_lock_keys()
-{
- XModifierKeymap *modmap;
- KeyCode numlock;
- int i;
- static int masks[] = {
- ShiftMask, LockMask, ControlMask, Mod1Mask,
- Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
- };
-
- numlock_mask = 0;
- modmap = XGetModifierMapping(dpy);
- numlock = XKeysymToKeycode(dpy, XStringToKeysym("Num_Lock"));
-
- if(modmap && modmap->max_keypermod > 0) {
- int max = (sizeof(masks) / sizeof(int)) * modmap->max_keypermod;
- for(i = 0; i < max; i++)
- if(numlock && (modmap->modifiermap[i] == numlock))
- numlock_mask = masks[i / modmap->max_keypermod];
- }
- XFreeModifiermap(modmap);
-
- lock_mask = 255 & ~(numlock_mask | LockMask);
-}
-
-static void
cleanup()
{
/*
@@ -243,7 +216,7 @@ main(int argc, char *argv[])
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
- init_lock_keys();
+ update_keys();
brush.drawable = XCreatePixmap(dpy, root, rect.width, rect.height,
DefaultDepth(dpy, screen));
diff --git a/wm.h b/wm.h
index 01bbee4..454f7bf 100644
--- a/wm.h
+++ b/wm.h
@@ -20,6 +20,7 @@ enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
enum { RFloat, RGrid, RLast };
typedef struct Client Client;
+typedef struct Key Key;
struct Client {
char name[256];
@@ -36,6 +37,13 @@ struct Client {
Client *snext;
};
+struct Key {
+ unsigned long mod;
+ KeySym keysym;
+ void (*func)(char *arg);
+ char *arg;
+};
+
extern Display *dpy;
extern Window root, barwin;
extern Atom wm_atom[WMLast], net_atom[NetLast];
@@ -46,7 +54,6 @@ extern Bool grid;
extern void (*handler[LASTEvent]) (XEvent *);
extern int screen, sel_screen;
-extern unsigned int lock_mask, numlock_mask;
extern char *bartext, tag[256];
extern Brush brush;
@@ -55,9 +62,15 @@ extern Client *client;
/* bar.c */
extern void draw_bar();
+/* cmd.c */
+extern void run(char *arg);
+
/* client.c */
extern Client *create_client(Window w, XWindowAttributes *wa);
extern void manage(Client *c);
+/* key.c */
+extern void update_keys();
+
/* wm.c */
extern int win_proto(Window w);
remember that computers suck.