From 0be08c6a4a4a77e1fe4db48f08793746edc07070 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Fri, 5 Aug 2011 15:33:09 +0200 Subject: [PATCH] add config.* --- wmfs2/src/client.c | 17 +++++++++++++++++ wmfs2/src/client.h | 2 ++ wmfs2/src/config.c | 10 ++++++++++ wmfs2/src/config.h | 21 +++++++++++++++++++++ wmfs2/src/event.c | 34 ++++++++++++++++++++++++++++++++++ wmfs2/src/wmfs.c | 18 ++++++++++++++++++ wmfs2/src/wmfs.h | 13 +++++++++---- 7 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 wmfs2/src/config.c create mode 100644 wmfs2/src/config.h diff --git a/wmfs2/src/client.c b/wmfs2/src/client.c index 9b413c7..1d3d109 100755 --- a/wmfs2/src/client.c +++ b/wmfs2/src/client.c @@ -28,6 +28,17 @@ client_configure(Client *c) XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ev); } +Client* +client_gb_win(Window *w) +{ + Client *c = SLIST_FIRST(&W->h.client); + + while(c && c->win != w) + c = SLIST_NEXT(c, next); + + return c; +} + /** Map a client * \param c Client pointer */ @@ -46,6 +57,12 @@ client_unmap(Client *c) XUnmapWindow(W->dpy, c->win); } +void +client_focus(Client *c) +{ + +} + /** Close a client * \param c Client pointer */ diff --git a/wmfs2/src/client.h b/wmfs2/src/client.h index 7a581c2..152d8c3 100755 --- a/wmfs2/src/client.h +++ b/wmfs2/src/client.h @@ -21,8 +21,10 @@ typedef struct Client } Client; void client_configure(Client *c); +Client *client_gb_win(Window *w); void client_map(Client *c); void client_unmap(Client *c); +void client_focus(Client *c); void client_close(Client *c); Client *client_new(Window w, XWindowAttributes *wa); void client_remove(Client *c); diff --git a/wmfs2/src/config.c b/wmfs2/src/config.c new file mode 100644 index 0000000..93cd014 --- /dev/null +++ b/wmfs2/src/config.c @@ -0,0 +1,10 @@ +/* + * wmfs2 by Martin Duquesnoy { for(i = 2011; i < 2111; ++i) ©(i); } + * For license, see COPYING. + */ + +void +config_init(void) +{ + +} diff --git a/wmfs2/src/config.h b/wmfs2/src/config.h new file mode 100644 index 0000000..e2f1e35 --- /dev/null +++ b/wmfs2/src/config.h @@ -0,0 +1,21 @@ +/* + * wmfs2 by Martin Duquesnoy { for(i = 2011; i < 2111; ++i) ©(i); } + * For license, see COPYING. + */ + + +#ifndef CONFIG_H +#define CONFIG_H + +#include "wmfs.h" + +typedef struct Keybind +{ + unsigned int mod; + KeySym keysym; + void (*func)(Uicb); + Uicb cmd; + SLIST_ENTRY(Keybind) next; +} Keybind; + +#endif /* CONFIG_H */ diff --git a/wmfs2/src/event.c b/wmfs2/src/event.c index 57b4336..f557c1f 100755 --- a/wmfs2/src/event.c +++ b/wmfs2/src/event.c @@ -7,6 +7,40 @@ #include "util.h" #include "wmfs.h" +#define EVDPY(e) (e)->xany.display + +static void +event_enternotify(XEvent *e) +{ + XCrossingEvent *ev = &e->xcrossing; + Client *c; + int n; + + if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) + && ev->window != W->root) + return; + + if((c = client_gb_win(ev->window))) + client_focus(c); +} + +static void +event_maprequest(XEvent *e) +{ + XMapRequestEvent *ev = &e->xmaprequest; + XWindowAttributes at; + + /* Which windows to manage */ + if(!XGetWindowAttributes(EVDPY(e), ev->window, &at) + || at.overried_redirect + || client_gb_win(ev->window)) + return; + + (Client*)client_new(ev->window, at); +} + + + static void event_dummy(XEvent *e) { diff --git a/wmfs2/src/wmfs.c b/wmfs2/src/wmfs.c index 673c508..cc3ad2c 100755 --- a/wmfs2/src/wmfs.c +++ b/wmfs2/src/wmfs.c @@ -108,6 +108,24 @@ wmfs_xinit(void) } +void +wmfs_grab_keys(void) +{ + KeyCode c; + Keybind *k; + + XUngrabKey(W->dpy, AnyKey, AnyModifier, W->root); + + FOREACH(k, &W->h.keybind, next) + if((c = XKeysymToKeycode(dpy, k->keysym))) + { + XGrabKey(W->dpy, c, k->mod, W->root, True, GrabModeAsync, GrabModeAsync); + XGrabKey(W->dpy, c, k->mod | LockMask, W->root, True, GrabModeAsync, GrabModeAsync); + XGrabKey(W->dpy, c, k->mod | numlockmask, W->root, True, GrabModeAsync, GrabModeAsync); + XGrabKey(W->dpy, c, k->mod | LockMask | numlockmask, W->root, True, GrabModeAsync, GrabModeAsync); + } +} + static void wmfs_loop(void) { diff --git a/wmfs2/src/wmfs.h b/wmfs2/src/wmfs.h index 551aa07..081c15f 100755 --- a/wmfs2/src/wmfs.h +++ b/wmfs2/src/wmfs.h @@ -24,10 +24,14 @@ /* Local */ #include "screen.h" #include "client.h" +#include "config.h" -#define ButtonMask (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask) -#define MouseMask (ButtonMask | PointerMotionMask) -#define KeyMask (KeyPressMask | KeyReleaseMask) +#define ButtonMask (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask) +#define MouseMask (ButtonMask | PointerMotionMask) +#define KeyMask (KeyPressMask | KeyReleaseMask) + +typedef unsigned int Flags; +typedef const char* Uicb; typedef struct { @@ -55,6 +59,7 @@ typedef struct { SLIST_HEAD(, Screen) screen; SLIST_HEAD(, Client) client; + SLIST_HEAD(, Keybind) keybind; } h; /* @@ -65,9 +70,9 @@ typedef struct } Wmfs; - int wmfs_error_handler(Display *d, XErrorEvent *event); int wmfs_error_handler_dummy(Display *d, XErrorEvent *event); +void wmfs_grab_keys(void); void wmfs_quit(void); /* Single global variable */