mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
move duplicate kbd and mouse modifier parsing to a generic function;
from Tiago Cunha
This commit is contained in:
parent
fe439f2b96
commit
912ec90ea1
64
conf.c
64
conf.c
@ -31,8 +31,9 @@
|
|||||||
|
|
||||||
#include "calmwm.h"
|
#include "calmwm.h"
|
||||||
|
|
||||||
static void conf_mouseunbind(struct conf *, struct mousebinding *);
|
static const char *conf_bind_getmask(const char *, u_int *);
|
||||||
static void conf_unbind(struct conf *, struct keybinding *);
|
static void conf_mouseunbind(struct conf *, struct mousebinding *);
|
||||||
|
static void conf_unbind(struct conf *, struct keybinding *);
|
||||||
|
|
||||||
/* Add an command menu entry to the end of the menu */
|
/* Add an command menu entry to the end of the menu */
|
||||||
void
|
void
|
||||||
@ -442,27 +443,35 @@ static struct {
|
|||||||
{ 'S', ShiftMask },
|
{ 'S', ShiftMask },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
conf_bind_getmask(const char *name, u_int *mask)
|
||||||
|
{
|
||||||
|
char *dash;
|
||||||
|
const char *ch;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
*mask = 0;
|
||||||
|
if ((dash = strchr(name, '-')) == NULL)
|
||||||
|
return (name);
|
||||||
|
for (i = 0; i < nitems(bind_mods); i++) {
|
||||||
|
if ((ch = strchr(name, bind_mods[i].chr)) != NULL && ch < dash)
|
||||||
|
*mask |= bind_mods[i].mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Skip past modifiers. */
|
||||||
|
return (dash + 1);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
conf_bindname(struct conf *c, char *name, char *binding)
|
conf_bindname(struct conf *c, char *name, char *binding)
|
||||||
{
|
{
|
||||||
struct keybinding *current_binding;
|
struct keybinding *current_binding;
|
||||||
char *substring, *tmp;
|
const char *substring;
|
||||||
u_int i;
|
u_int i, mask;
|
||||||
|
|
||||||
current_binding = xcalloc(1, sizeof(*current_binding));
|
current_binding = xcalloc(1, sizeof(*current_binding));
|
||||||
|
substring = conf_bind_getmask(name, &mask);
|
||||||
if ((substring = strchr(name, '-')) != NULL) {
|
current_binding->modmask |= mask;
|
||||||
for (i = 0; i < nitems(bind_mods); i++) {
|
|
||||||
if ((tmp = strchr(name, bind_mods[i].chr)) !=
|
|
||||||
NULL && tmp < substring) {
|
|
||||||
current_binding->modmask |= bind_mods[i].mask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* skip past the modifiers */
|
|
||||||
substring++;
|
|
||||||
} else
|
|
||||||
substring = name;
|
|
||||||
|
|
||||||
if (substring[0] == '[' &&
|
if (substring[0] == '[' &&
|
||||||
substring[strlen(substring)-1] == ']') {
|
substring[strlen(substring)-1] == ']') {
|
||||||
@ -551,25 +560,12 @@ int
|
|||||||
conf_mousebind(struct conf *c, char *name, char *binding)
|
conf_mousebind(struct conf *c, char *name, char *binding)
|
||||||
{
|
{
|
||||||
struct mousebinding *current_binding;
|
struct mousebinding *current_binding;
|
||||||
char *substring, *tmp;
|
const char *errstr, *substring;
|
||||||
u_int button;
|
u_int button, i, mask;
|
||||||
const char *errstr;
|
|
||||||
u_int i;
|
|
||||||
|
|
||||||
current_binding = xcalloc(1, sizeof(*current_binding));
|
current_binding = xcalloc(1, sizeof(*current_binding));
|
||||||
|
substring = conf_bind_getmask(name, &mask);
|
||||||
if ((substring = strchr(name, '-')) != NULL) {
|
current_binding->modmask |= mask;
|
||||||
for (i = 0; i < nitems(bind_mods); i++) {
|
|
||||||
if ((tmp = strchr(name, bind_mods[i].chr)) !=
|
|
||||||
NULL && tmp < substring) {
|
|
||||||
current_binding->modmask |= bind_mods[i].mask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* skip past the modifiers */
|
|
||||||
substring++;
|
|
||||||
} else
|
|
||||||
substring = name;
|
|
||||||
|
|
||||||
button = strtonum(substring, 1, 5, &errstr);
|
button = strtonum(substring, 1, 5, &errstr);
|
||||||
if (errstr)
|
if (errstr)
|
||||||
|
Loading…
Reference in New Issue
Block a user