remove nkeys: keys is now a linked list
This commit is contained in:
parent
f3d0ada5df
commit
0c5c5ce426
|
@ -56,6 +56,7 @@ cleanup_screen(awesome_config *awesomeconf)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
Button *b, *bn;
|
Button *b, *bn;
|
||||||
|
Key *k, *kn;
|
||||||
|
|
||||||
XftFontClose(awesomeconf->display, awesomeconf->font);
|
XftFontClose(awesomeconf->display, awesomeconf->font);
|
||||||
XUngrabKey(awesomeconf->display, AnyKey, AnyModifier, RootWindow(awesomeconf->display, awesomeconf->phys_screen));
|
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++)
|
for(i = 0; i < awesomeconf->ntags; i++)
|
||||||
p_delete(&awesomeconf->tags[i].name);
|
p_delete(&awesomeconf->tags[i].name);
|
||||||
for(i = 0; i < awesomeconf->nkeys; i++)
|
for(k = awesomeconf->keys; k; k = kn)
|
||||||
p_delete(&awesomeconf->keys[i].arg);
|
{
|
||||||
|
kn = k->next;
|
||||||
|
p_delete(&k);
|
||||||
|
}
|
||||||
for(b = awesomeconf->buttons.tag; b; b = bn)
|
for(b = awesomeconf->buttons.tag; b; b = bn)
|
||||||
{
|
{
|
||||||
bn = b->next;
|
bn = b->next;
|
||||||
|
@ -101,7 +105,6 @@ cleanup_screen(awesome_config *awesomeconf)
|
||||||
p_delete(&awesomeconf->tags);
|
p_delete(&awesomeconf->tags);
|
||||||
p_delete(&awesomeconf->layouts);
|
p_delete(&awesomeconf->layouts);
|
||||||
p_delete(&awesomeconf->rules);
|
p_delete(&awesomeconf->rules);
|
||||||
p_delete(&awesomeconf->keys);
|
|
||||||
p_delete(&awesomeconf->configpath);
|
p_delete(&awesomeconf->configpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
34
config.c
34
config.c
|
@ -336,10 +336,11 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
|
||||||
cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar,
|
cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar,
|
||||||
*cfg_tags, *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp;
|
*cfg_tags, *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp;
|
||||||
int i = 0, k = 0, ret;
|
int i = 0, k = 0, ret;
|
||||||
unsigned int j = 0;
|
unsigned int j = 0, l = 0;
|
||||||
const char *tmp, *homedir;
|
const char *tmp, *homedir;
|
||||||
char *confpath, buf[2];
|
char *confpath, buf[2];
|
||||||
ssize_t confpath_len;
|
ssize_t confpath_len;
|
||||||
|
Key *key = NULL;
|
||||||
|
|
||||||
if(confpatharg)
|
if(confpatharg)
|
||||||
confpath = a_strdup(confpatharg);
|
confpath = a_strdup(confpatharg);
|
||||||
|
@ -502,17 +503,30 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf)
|
||||||
|
|
||||||
/* Keys */
|
/* Keys */
|
||||||
awesomeconf->numlockmask = get_numlockmask(awesomeconf->display);
|
awesomeconf->numlockmask = get_numlockmask(awesomeconf->display);
|
||||||
awesomeconf->nkeys = cfg_size(cfg_keys, "key");
|
|
||||||
awesomeconf->keys = p_new(Key, awesomeconf->nkeys);
|
if(cfg_size(cfg_keys, "key"))
|
||||||
for(i = 0; i < awesomeconf->nkeys; i++)
|
|
||||||
{
|
{
|
||||||
cfgsectmp = cfg_getnsec(cfg_keys, "key", i);
|
awesomeconf->keys = key = p_new(Key, 1);
|
||||||
for(j = 0; j < cfg_size(cfgsectmp, "modkey"); j++)
|
for(j = 0; j < cfg_size(cfg_keys, "key"); j++)
|
||||||
awesomeconf->keys[i].mod |= key_mask_lookup(cfg_getnstr(cfgsectmp, "modkey", j));
|
{
|
||||||
awesomeconf->keys[i].keysym = XStringToKeysym(cfg_getstr(cfgsectmp, "key"));
|
cfgsectmp = cfg_getnsec(cfg_keys, "key", j);
|
||||||
awesomeconf->keys[i].func = name_func_lookup(cfg_getstr(cfgsectmp, "command"), UicbList);
|
for(l = 0; l < cfg_size(cfgsectmp, "modkey"); l++)
|
||||||
awesomeconf->keys[i].arg = a_strdup(cfg_getstr(cfgsectmp, "arg"));
|
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! */
|
/* Free! Like a river! */
|
||||||
cfg_free(cfg);
|
cfg_free(cfg);
|
||||||
|
|
8
config.h
8
config.h
|
@ -53,13 +53,15 @@ typedef struct
|
||||||
void (*arrange) (awesome_config *);
|
void (*arrange) (awesome_config *);
|
||||||
} Layout;
|
} Layout;
|
||||||
|
|
||||||
typedef struct
|
typedef struct Key Key;
|
||||||
|
struct Key
|
||||||
{
|
{
|
||||||
unsigned long mod;
|
unsigned long mod;
|
||||||
KeySym keysym;
|
KeySym keysym;
|
||||||
void (*func) (awesome_config *, char *);
|
void (*func) (awesome_config *, char *);
|
||||||
char *arg;
|
char *arg;
|
||||||
} Key;
|
Key *next;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct Button Button;
|
typedef struct Button Button;
|
||||||
struct Button
|
struct Button
|
||||||
|
@ -179,8 +181,6 @@ struct awesome_config
|
||||||
Button *layout;
|
Button *layout;
|
||||||
Button *root;
|
Button *root;
|
||||||
} buttons;
|
} buttons;
|
||||||
/** Number of keys binding in *keys */
|
|
||||||
int nkeys;
|
|
||||||
/** Default modkey */
|
/** Default modkey */
|
||||||
KeySym modkey;
|
KeySym modkey;
|
||||||
/** Numlock mask */
|
/** Numlock mask */
|
||||||
|
|
27
event.c
27
event.c
|
@ -391,11 +391,12 @@ handle_event_expose(XEvent * e, awesome_config *awesomeconf)
|
||||||
void
|
void
|
||||||
handle_event_keypress(XEvent * e, awesome_config *awesomeconf)
|
handle_event_keypress(XEvent * e, awesome_config *awesomeconf)
|
||||||
{
|
{
|
||||||
int i, screen, x, y, d;
|
int screen, x, y, d;
|
||||||
unsigned int m;
|
unsigned int m;
|
||||||
KeySym keysym;
|
KeySym keysym;
|
||||||
XKeyEvent *ev = &e->xkey;
|
XKeyEvent *ev = &e->xkey;
|
||||||
Window dummy;
|
Window dummy;
|
||||||
|
Key *k;
|
||||||
|
|
||||||
keysym = XKeycodeToKeysym(e->xany.display, (KeyCode) ev->keycode, 0);
|
keysym = XKeycodeToKeysym(e->xany.display, (KeyCode) ev->keycode, 0);
|
||||||
|
|
||||||
|
@ -412,11 +413,10 @@ handle_event_keypress(XEvent * e, awesome_config *awesomeconf)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < awesomeconf[screen].nkeys; i++)
|
for(k = awesomeconf[screen].keys; k; k = k->next)
|
||||||
if(keysym == awesomeconf[screen].keys[i].keysym
|
if(keysym == k->keysym && k->func
|
||||||
&& CLEANMASK(awesomeconf[screen].keys[i].mod, awesomeconf[screen])
|
&& CLEANMASK(k->mod, awesomeconf[screen]) == CLEANMASK(ev->state, awesomeconf[screen]))
|
||||||
== CLEANMASK(ev->state, awesomeconf[screen]) && awesomeconf[screen].keys[i].func)
|
k->func(&awesomeconf[screen], k->arg);
|
||||||
awesomeconf[screen].keys[i].func(&awesomeconf[screen], awesomeconf[screen].keys[i].arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -529,19 +529,18 @@ handle_event_randr_screen_change_notify(XEvent *e,
|
||||||
void
|
void
|
||||||
grabkeys(awesome_config *awesomeconf)
|
grabkeys(awesome_config *awesomeconf)
|
||||||
{
|
{
|
||||||
int i;
|
Key *k;
|
||||||
KeyCode code;
|
KeyCode code;
|
||||||
|
|
||||||
XUngrabKey(awesomeconf->display, AnyKey, AnyModifier, RootWindow(awesomeconf->display, awesomeconf->phys_screen));
|
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;
|
continue;
|
||||||
XGrabKey(awesomeconf->display, code, awesomeconf->keys[i].mod, 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, awesomeconf->keys[i].mod | LockMask, 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, awesomeconf->keys[i].mod | awesomeconf->numlockmask, 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, awesomeconf->keys[i].mod | awesomeconf->numlockmask | LockMask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True,
|
XGrabKey(awesomeconf->display, code, k->mod | awesomeconf->numlockmask | LockMask, RootWindow(awesomeconf->display, awesomeconf->phys_screen), True, GrabModeAsync, GrabModeAsync);
|
||||||
GrabModeAsync, GrabModeAsync);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
|
||||||
|
|
Loading…
Reference in New Issue