remove nkeys: keys is now a linked list

This commit is contained in:
Julien Danjou 2007-11-12 17:22:40 +01:00
parent f3d0ada5df
commit 0c5c5ce426
4 changed files with 47 additions and 31 deletions

View File

@ -56,6 +56,7 @@ cleanup_screen(awesome_config *awesomeconf)
{
int i;
Button *b, *bn;
Key *k, *kn;
XftFontClose(awesomeconf->display, awesomeconf->font);
XUngrabKey(awesomeconf->display, AnyKey, AnyModifier, RootWindow(awesomeconf->display, awesomeconf->phys_screen));
@ -66,8 +67,11 @@ cleanup_screen(awesome_config *awesomeconf)
for(i = 0; i < awesomeconf->ntags; i++)
p_delete(&awesomeconf->tags[i].name);
for(i = 0; i < awesomeconf->nkeys; i++)
p_delete(&awesomeconf->keys[i].arg);
for(k = awesomeconf->keys; k; k = kn)
{
kn = k->next;
p_delete(&k);
}
for(b = awesomeconf->buttons.tag; b; b = bn)
{
bn = b->next;
@ -101,7 +105,6 @@ cleanup_screen(awesome_config *awesomeconf)
p_delete(&awesomeconf->tags);
p_delete(&awesomeconf->layouts);
p_delete(&awesomeconf->rules);
p_delete(&awesomeconf->keys);
p_delete(&awesomeconf->configpath);
}

View File

@ -336,10 +336,11 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar,
*cfg_tags, *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp;
int i = 0, k = 0, ret;
unsigned int j = 0;
unsigned int j = 0, l = 0;
const char *tmp, *homedir;
char *confpath, buf[2];
ssize_t confpath_len;
Key *key = NULL;
if(confpatharg)
confpath = a_strdup(confpatharg);
@ -502,17 +503,30 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
/* Keys */
awesomeconf->numlockmask = get_numlockmask(awesomeconf->display);
awesomeconf->nkeys = cfg_size(cfg_keys, "key");
awesomeconf->keys = p_new(Key, awesomeconf->nkeys);
for(i = 0; i < awesomeconf->nkeys; i++)
if(cfg_size(cfg_keys, "key"))
{
cfgsectmp = cfg_getnsec(cfg_keys, "key", i);
for(j = 0; j < cfg_size(cfgsectmp, "modkey"); j++)
awesomeconf->keys[i].mod |= key_mask_lookup(cfg_getnstr(cfgsectmp, "modkey", j));
awesomeconf->keys[i].keysym = XStringToKeysym(cfg_getstr(cfgsectmp, "key"));
awesomeconf->keys[i].func = name_func_lookup(cfg_getstr(cfgsectmp, "command"), UicbList);
awesomeconf->keys[i].arg = a_strdup(cfg_getstr(cfgsectmp, "arg"));
awesomeconf->keys = key = p_new(Key, 1);
for(j = 0; j < cfg_size(cfg_keys, "key"); j++)
{
cfgsectmp = cfg_getnsec(cfg_keys, "key", j);
for(l = 0; l < cfg_size(cfgsectmp, "modkey"); l++)
key->mod |= key_mask_lookup(cfg_getnstr(cfgsectmp, "modkey", l));
key->keysym = XStringToKeysym(cfg_getstr(cfgsectmp, "key"));
key->func = name_func_lookup(cfg_getstr(cfgsectmp, "command"), UicbList);
key->arg = a_strdup(cfg_getstr(cfgsectmp, "arg"));
if(j < cfg_size(cfg_keys, "key") - 1)
{
key->next = p_new(Key, 1);
key = key->next;
}
else
key->next = NULL;
}
}
else
awesomeconf->keys = NULL;
/* Free! Like a river! */
cfg_free(cfg);

View File

@ -53,13 +53,15 @@ typedef struct
void (*arrange) (awesome_config *);
} Layout;
typedef struct
typedef struct Key Key;
struct Key
{
unsigned long mod;
KeySym keysym;
void (*func) (awesome_config *, char *);
char *arg;
} Key;
Key *next;
};
typedef struct Button Button;
struct Button
@ -179,8 +181,6 @@ struct awesome_config
Button *layout;
Button *root;
} buttons;
/** Number of keys binding in *keys */
int nkeys;
/** Default modkey */
KeySym modkey;
/** Numlock mask */

27
event.c
View File

@ -391,11 +391,12 @@ handle_event_expose(XEvent * e, awesome_config *awesomeconf)
void
handle_event_keypress(XEvent * e, awesome_config *awesomeconf)
{
int i, screen, x, y, d;
int screen, x, y, d;
unsigned int m;
KeySym keysym;
XKeyEvent *ev = &e->xkey;
Window dummy;
Key *k;
keysym = XKeycodeToKeysym(e->xany.display, (KeyCode) ev->keycode, 0);
@ -412,11 +413,10 @@ handle_event_keypress(XEvent * e, awesome_config *awesomeconf)
break;
}
for(i = 0; i < awesomeconf[screen].nkeys; i++)
if(keysym == awesomeconf[screen].keys[i].keysym
&& CLEANMASK(awesomeconf[screen].keys[i].mod, awesomeconf[screen])
== CLEANMASK(ev->state, awesomeconf[screen]) && awesomeconf[screen].keys[i].func)
awesomeconf[screen].keys[i].func(&awesomeconf[screen], awesomeconf[screen].keys[i].arg);
for(k = awesomeconf[screen].keys; k; k = k->next)
if(keysym == k->keysym && k->func
&& CLEANMASK(k->mod, awesomeconf[screen]) == CLEANMASK(ev->state, awesomeconf[screen]))
k->func(&awesomeconf[screen], k->arg);
}
void
@ -529,19 +529,18 @@ handle_event_randr_screen_change_notify(XEvent *e,
void
grabkeys(awesome_config *awesomeconf)
{
int i;
Key *k;
KeyCode code;
XUngrabKey(awesomeconf->display, AnyKey, AnyModifier, RootWindow(awesomeconf->display, awesomeconf->phys_screen));
for(i = 0; i < awesomeconf->nkeys; i++)
for(k = awesomeconf->keys; k; k = k->next)
{
if((code = XKeysymToKeycode(awesomeconf->display, awesomeconf->keys[i].keysym)) == NoSymbol)
if((code = XKeysymToKeycode(awesomeconf->display, k->keysym)) == NoSymbol)
continue;
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod | LockMask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod | awesomeconf->numlockmask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod | awesomeconf->numlockmask | LockMask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True,
GrabModeAsync, GrabModeAsync);
XGrabKey(awesomeconf->display, code, k->mod, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(awesomeconf->display, code, k->mod | LockMask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(awesomeconf->display, code, k->mod | awesomeconf->numlockmask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(awesomeconf->display, code, k->mod | awesomeconf->numlockmask | LockMask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
}
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99