Add conf parsage: keybind section available, config.h associative struct/func
This commit is contained in:
parent
7f346c150c
commit
05aafde11a
@ -3,8 +3,67 @@
|
||||
* For license, see COPYING.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "wmfs.h"
|
||||
#include "parse.h"
|
||||
|
||||
#define CONFIG_DEFAULT_PATH ".config/wmfs/wmfsrc2" /* tmp */
|
||||
|
||||
static void
|
||||
config_keybind(void)
|
||||
{
|
||||
int i;
|
||||
size_t j, n;
|
||||
struct conf_sec *sec, **ks;
|
||||
struct opt_type *opt;
|
||||
Keybind *k;
|
||||
|
||||
sec = fetch_section_first(NULL, "keys");
|
||||
ks = fetch_section(sec, "key");
|
||||
n = fetch_section_count(ks);
|
||||
|
||||
SLIST_INIT(&W->h.keybind);
|
||||
|
||||
for(i = 0; i < n; ++i)
|
||||
{
|
||||
opt = fetch_opt(ks[i], "", "mod");
|
||||
|
||||
k = xcalloc(1, sizeof(Keybind));
|
||||
|
||||
for(j = 0; j < fetch_opt_count(opt); ++j)
|
||||
k->mod |= modkey_keysym(opt[j].str);
|
||||
|
||||
free(opt);
|
||||
|
||||
k->keysym = XStringToKeysym(fetch_opt_first(ks[i], "None", "key").str);
|
||||
|
||||
if(!(k->func = uicb_name_func(fetch_opt_first(ks[i], "", "func").str)))
|
||||
{
|
||||
warnx("configuration : Unknown Function \"%s\".", fetch_opt_first(ks[i], "", "func").str);
|
||||
k->func = uicb_spawn;
|
||||
}
|
||||
|
||||
k->cmd = fetch_opt_first(ks[i], "", "cmd").str;
|
||||
|
||||
SLIST_INSERT_HEAD(&W->h.keybind, k, next);
|
||||
|
||||
k = NULL;
|
||||
}
|
||||
|
||||
free(ks);
|
||||
}
|
||||
|
||||
void
|
||||
config_init(void)
|
||||
{
|
||||
char *path;
|
||||
|
||||
xasprintf(&path, "%s/"CONFIG_DEFAULT_PATH, getenv("HOME"));
|
||||
|
||||
if(get_conf(path) == -1)
|
||||
errx(1, "parsing configuration file (%s) failed.", path);
|
||||
|
||||
config_keybind();
|
||||
|
||||
free(path);
|
||||
}
|
||||
|
||||
@ -7,6 +7,59 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "wmfs.h"
|
||||
#include "util.h"
|
||||
|
||||
static const struct { char *name; void (*func)(Uicb cmd); } uicb_list[] =
|
||||
{
|
||||
{ "spawn", uicb_spawn },
|
||||
{ "quit", uicb_quit },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static inline void*
|
||||
uicb_name_func(Uicb name)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(; uicb_list[i].func; ++i)
|
||||
if(!strcmp(name, uicb_list[i].name))
|
||||
return uicb_list[i].func;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const struct { const char *name; KeySym keysym; } key_list[] =
|
||||
{
|
||||
{"Control", ControlMask },
|
||||
{"Shift", ShiftMask },
|
||||
{"Lock", LockMask },
|
||||
{"Alt", Mod1Mask },
|
||||
{"Mod1", Mod1Mask },
|
||||
{"Mod2", Mod2Mask },
|
||||
{"Mod3", Mod3Mask },
|
||||
{"Mod4", Mod4Mask },
|
||||
{"Super", Mod4Mask },
|
||||
{"Home", Mod4Mask },
|
||||
{"Mod5", Mod5Mask },
|
||||
{NULL, NoSymbol }
|
||||
};
|
||||
|
||||
static inline KeySym
|
||||
modkey_keysym(const char *name)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for(; key_list[i].name; ++i)
|
||||
if(!strcmp(name, key_list[i].name))
|
||||
return key_list[i].keysym;
|
||||
|
||||
return NoSymbol;
|
||||
}
|
||||
|
||||
void config_init(void);
|
||||
|
||||
#endif /* CONFIG_H */
|
||||
|
||||
@ -184,14 +184,12 @@ static void
|
||||
event_keypress(XEvent *e)
|
||||
{
|
||||
XKeyPressedEvent *ev = &e->xkey;
|
||||
KeySym keysym;
|
||||
Keybind *k;
|
||||
KeySym keysym = XKeycodeToKeysym(EVDPY(e), (KeyCode)ev->keycode, 0);
|
||||
Flags m = ~(W->numlockmask | LockMask);
|
||||
|
||||
keysym = XKeycodeToKeysym(EVDPY(e), (KeyCode)ev->keycode, 0);
|
||||
Keybind *k;
|
||||
|
||||
SLIST_FOREACH(k, &W->h.keybind, next)
|
||||
if(k->keysym == keysym && (k->mod & m) == (ev->state & m))
|
||||
if(k->keysym == keysym && KEYPRESS_MASK(k->mod) == KEYPRESS_MASK(ev->state))
|
||||
if(k->func)
|
||||
k->func(k->cmd);
|
||||
}
|
||||
@ -201,13 +199,13 @@ event_expose(XEvent *e)
|
||||
{
|
||||
XExposeEvent *ev = &e->xexpose;
|
||||
Barwin *b;
|
||||
/*
|
||||
|
||||
SLIST_FOREACH(b, &W->h.barwin, next)
|
||||
if(b->win == ev->window)
|
||||
{
|
||||
barwin_refresh(b);
|
||||
return;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#define MAX_EV 256
|
||||
|
||||
#define KEYPRESS_MASK(m) (m & ~(W->numlockmask | LockMask))
|
||||
#define HANDLE_EVENT(e) event_handle[(e)->type](e);
|
||||
|
||||
void event_init(void);
|
||||
|
||||
@ -118,3 +118,9 @@ spawn(const char *format, ...)
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_spawn(Uicb cmd)
|
||||
{
|
||||
spawn("%s", cmd);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
/* Todo FREE_LIST(type, head, function_remove) */
|
||||
#define FREE_LIST(type, head) \
|
||||
do { \
|
||||
type *t; \
|
||||
struct type *t; \
|
||||
while(!SLIST_EMPTY(&head)) { \
|
||||
t = SLIST_FIRST(&head); \
|
||||
SLIST_REMOVE_HEAD(&head, next); \
|
||||
@ -26,5 +26,6 @@ void *xcalloc(size_t nmemb, size_t size);
|
||||
int xasprintf(char **strp, const char *fmt, ...);
|
||||
char *xstrdup(const char *str);
|
||||
pid_t spawn(const char *format, ...);
|
||||
void uicb_spawn(Uicb cmd);
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
||||
@ -3,13 +3,14 @@
|
||||
* For license, see COPYING.
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/cursorfont.h>
|
||||
|
||||
#include "wmfs.h"
|
||||
#include "event.h"
|
||||
#include "util.h"
|
||||
/*#include "infobar.h" */
|
||||
#include "config.h"
|
||||
|
||||
int
|
||||
wmfs_error_handler(Display *d, XErrorEvent *event)
|
||||
@ -56,7 +57,7 @@ static void
|
||||
wmfs_xinit(void)
|
||||
{
|
||||
char **misschar, **names, *defstring;
|
||||
int d, i = 0, j = 0;
|
||||
int d, i, j;
|
||||
XModifierKeymap *mm;
|
||||
XFontStruct **xfs = NULL;
|
||||
XSetWindowAttributes at;
|
||||
@ -108,8 +109,8 @@ wmfs_xinit(void)
|
||||
*/
|
||||
mm = XGetModifierMapping(W->dpy);
|
||||
|
||||
for(; i < 8; i++)
|
||||
for(; j < mm->max_keypermod; ++j)
|
||||
for(i = 0; i < 8; i++)
|
||||
for(j = 0; j < mm->max_keypermod; ++j)
|
||||
if(mm->modifiermap[i * mm->max_keypermod + j]
|
||||
== XKeysymToKeycode(W->dpy, XK_Num_Lock))
|
||||
W->numlockmask = (1 << i);
|
||||
@ -217,6 +218,8 @@ wmfs_init(void)
|
||||
/* EWMH init */
|
||||
ewmh_init();
|
||||
|
||||
config_init();
|
||||
|
||||
/* Event init */
|
||||
event_init();
|
||||
|
||||
@ -232,7 +235,6 @@ void
|
||||
wmfs_quit(void)
|
||||
{
|
||||
/* X stuffs */
|
||||
XFreeGC(W->dpy, W->gc);
|
||||
XFreeFontSet(W->dpy, W->font.fontset);
|
||||
|
||||
screen_free();
|
||||
@ -242,9 +244,18 @@ wmfs_quit(void)
|
||||
free(W->net_atom);
|
||||
free(W);
|
||||
|
||||
/* Conf stuffs */
|
||||
FREE_LIST(Keybind, W->h.keybind);
|
||||
|
||||
W->running = false;
|
||||
}
|
||||
|
||||
void
|
||||
uicb_quit(Uicb cmd)
|
||||
{
|
||||
(void)cmd;
|
||||
W->running = false;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@ -259,6 +270,21 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Opt */
|
||||
/*
|
||||
int i;
|
||||
while((i = getopt(argc, argv, "hviC:")) != -1)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 'h':
|
||||
break;
|
||||
case 'v':
|
||||
break;
|
||||
case 'C':
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* Core */
|
||||
wmfs_init();
|
||||
|
||||
@ -187,6 +187,8 @@ 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);
|
||||
void uicb_quit(Uicb cmd);
|
||||
|
||||
|
||||
/* Single global variable */
|
||||
struct Wmfs *W;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user