mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
- remove redundant range check for buttons in conf_bind_mouse.
- make conf_bind_kbd return error on non-matches to match what conf_bind_mouse does. - rename some variables while here for clarity. - constify bind and cmd. from Tiago Cunha.
This commit is contained in:
parent
720b5452aa
commit
7263fb4c84
6
calmwm.h
6
calmwm.h
@ -515,8 +515,10 @@ int parse_config(const char *, struct conf *);
|
|||||||
|
|
||||||
void conf_atoms(void);
|
void conf_atoms(void);
|
||||||
void conf_autogroup(struct conf *, int, char *);
|
void conf_autogroup(struct conf *, int, char *);
|
||||||
void conf_bind_kbd(struct conf *, char *, char *);
|
int conf_bind_kbd(struct conf *, const char *,
|
||||||
int conf_bind_mouse(struct conf *, char *, char *);
|
const char *);
|
||||||
|
int conf_bind_mouse(struct conf *, const char *,
|
||||||
|
const char *);
|
||||||
void conf_clear(struct conf *);
|
void conf_clear(struct conf *);
|
||||||
void conf_client(struct client_ctx *);
|
void conf_client(struct client_ctx *);
|
||||||
void conf_cmd_add(struct conf *, char *, char *);
|
void conf_cmd_add(struct conf *, char *, char *);
|
||||||
|
108
conf.c
108
conf.c
@ -472,48 +472,50 @@ conf_bind_getmask(const char *name, unsigned int *mask)
|
|||||||
return (dash + 1);
|
return (dash + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
conf_bind_kbd(struct conf *c, char *name, char *binding)
|
conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
|
||||||
{
|
{
|
||||||
struct keybinding *current_binding;
|
struct keybinding *kb;
|
||||||
const char *substring;
|
const char *key;
|
||||||
unsigned int i, mask;
|
unsigned int i, mask;
|
||||||
|
|
||||||
current_binding = xcalloc(1, sizeof(*current_binding));
|
kb = xcalloc(1, sizeof(*kb));
|
||||||
substring = conf_bind_getmask(name, &mask);
|
key = conf_bind_getmask(bind, &mask);
|
||||||
current_binding->modmask |= mask;
|
kb->modmask |= mask;
|
||||||
|
|
||||||
current_binding->keysym = XStringToKeysym(substring);
|
kb->keysym = XStringToKeysym(key);
|
||||||
if (current_binding->keysym == NoSymbol) {
|
if (kb->keysym == NoSymbol) {
|
||||||
free(current_binding);
|
warnx("unknown symbol: %s", key);
|
||||||
return;
|
free(kb);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We now have the correct binding, remove duplicates. */
|
/* We now have the correct binding, remove duplicates. */
|
||||||
conf_unbind_kbd(c, current_binding);
|
conf_unbind_kbd(c, kb);
|
||||||
|
|
||||||
if (strcmp("unmap", binding) == 0) {
|
if (strcmp("unmap", cmd) == 0) {
|
||||||
free(current_binding);
|
free(kb);
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nitems(name_to_kbfunc); i++) {
|
for (i = 0; i < nitems(name_to_kbfunc); i++) {
|
||||||
if (strcmp(name_to_kbfunc[i].tag, binding) != 0)
|
if (strcmp(name_to_kbfunc[i].tag, cmd) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
current_binding->callback = name_to_kbfunc[i].handler;
|
kb->callback = name_to_kbfunc[i].handler;
|
||||||
current_binding->flags = name_to_kbfunc[i].flags;
|
kb->flags = name_to_kbfunc[i].flags;
|
||||||
current_binding->argument = name_to_kbfunc[i].argument;
|
kb->argument = name_to_kbfunc[i].argument;
|
||||||
current_binding->argtype |= ARG_INT;
|
kb->argtype |= ARG_INT;
|
||||||
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
|
TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry);
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_binding->callback = kbfunc_cmdexec;
|
kb->callback = kbfunc_cmdexec;
|
||||||
current_binding->flags = 0;
|
kb->flags = 0;
|
||||||
current_binding->argument.c = xstrdup(binding);
|
kb->argument.c = xstrdup(cmd);
|
||||||
current_binding->argtype |= ARG_CHAR;
|
kb->argtype |= ARG_CHAR;
|
||||||
TAILQ_INSERT_TAIL(&c->keybindingq, current_binding, entry);
|
TAILQ_INSERT_TAIL(&c->keybindingq, kb, entry);
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -555,52 +557,40 @@ static struct {
|
|||||||
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT, {0} },
|
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT, {0} },
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int mouse_btns[] = {
|
|
||||||
Button1, Button2, Button3, Button4, Button5
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
int
|
||||||
conf_bind_mouse(struct conf *c, char *name, char *binding)
|
conf_bind_mouse(struct conf *c, const char *bind, const char *cmd)
|
||||||
{
|
{
|
||||||
struct mousebinding *current_binding;
|
struct mousebinding *mb;
|
||||||
const char *errstr, *substring;
|
const char *button, *errstr;
|
||||||
unsigned int button, i, mask;
|
unsigned int i, mask;
|
||||||
|
|
||||||
current_binding = xcalloc(1, sizeof(*current_binding));
|
mb = xcalloc(1, sizeof(*mb));
|
||||||
substring = conf_bind_getmask(name, &mask);
|
button = conf_bind_getmask(bind, &mask);
|
||||||
current_binding->modmask |= mask;
|
mb->modmask |= mask;
|
||||||
|
|
||||||
button = strtonum(substring, 1, 5, &errstr);
|
mb->button = strtonum(button, Button1, Button5, &errstr);
|
||||||
if (errstr)
|
if (errstr) {
|
||||||
warnx("button number is %s: %s", errstr, substring);
|
warnx("button number is %s: %s", errstr, button);
|
||||||
|
free(mb);
|
||||||
for (i = 0; i < nitems(mouse_btns); i++) {
|
|
||||||
if (button == mouse_btns[i]) {
|
|
||||||
current_binding->button = button;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!current_binding->button || errstr) {
|
|
||||||
free(current_binding);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We now have the correct binding, remove duplicates. */
|
/* We now have the correct binding, remove duplicates. */
|
||||||
conf_unbind_mouse(c, current_binding);
|
conf_unbind_mouse(c, mb);
|
||||||
|
|
||||||
if (strcmp("unmap", binding) == 0) {
|
if (strcmp("unmap", cmd) == 0) {
|
||||||
free(current_binding);
|
free(mb);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nitems(name_to_mousefunc); i++) {
|
for (i = 0; i < nitems(name_to_mousefunc); i++) {
|
||||||
if (strcmp(name_to_mousefunc[i].tag, binding) != 0)
|
if (strcmp(name_to_mousefunc[i].tag, cmd) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
current_binding->callback = name_to_mousefunc[i].handler;
|
mb->callback = name_to_mousefunc[i].handler;
|
||||||
current_binding->flags = name_to_mousefunc[i].flags;
|
mb->flags = name_to_mousefunc[i].flags;
|
||||||
current_binding->argument = name_to_mousefunc[i].argument;
|
mb->argument = name_to_mousefunc[i].argument;
|
||||||
TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
|
TAILQ_INSERT_TAIL(&c->mousebindingq, mb, entry);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
parse.y
7
parse.y
@ -155,7 +155,12 @@ main : FONTNAME STRING {
|
|||||||
free($2);
|
free($2);
|
||||||
}
|
}
|
||||||
| BIND STRING string {
|
| BIND STRING string {
|
||||||
conf_bind_kbd(conf, $2, $3);
|
if (!conf_bind_kbd(conf, $2, $3)) {
|
||||||
|
yyerror("invalid bind: %s %s", $2, $3);
|
||||||
|
free($2);
|
||||||
|
free($3);
|
||||||
|
YYERROR;
|
||||||
|
}
|
||||||
free($2);
|
free($2);
|
||||||
free($3);
|
free($3);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user