mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
move validation of pointer Button into conf_mousebind so we check
validity during the parse phase and not bother adding it to the queue, instead of each time a client needs to grab (when it's too late); furthermore, make this a config error, stop parsing and load the default config.
This commit is contained in:
parent
866f5af9c7
commit
532f132194
2
calmwm.h
2
calmwm.h
@ -439,7 +439,7 @@ void conf_grab(struct conf *, struct keybinding *);
|
|||||||
void conf_grab_mouse(struct client_ctx *);
|
void conf_grab_mouse(struct client_ctx *);
|
||||||
void conf_init(struct conf *);
|
void conf_init(struct conf *);
|
||||||
void conf_ignore(struct conf *, char *);
|
void conf_ignore(struct conf *, char *);
|
||||||
void conf_mousebind(struct conf *, char *, char *);
|
int conf_mousebind(struct conf *, char *, char *);
|
||||||
void conf_screen(struct screen_ctx *);
|
void conf_screen(struct screen_ctx *);
|
||||||
void conf_ungrab(struct conf *, struct keybinding *);
|
void conf_ungrab(struct conf *, struct keybinding *);
|
||||||
|
|
||||||
|
44
conf.c
44
conf.c
@ -577,11 +577,14 @@ static struct {
|
|||||||
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT },
|
{ "menu_cmd", mousefunc_menu_cmd, MOUSEBIND_CTX_ROOT },
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
static unsigned int mouse_btns[] = { Button1, Button2, Button3 };
|
||||||
|
|
||||||
|
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;
|
char *substring, *tmp;
|
||||||
|
u_int button;
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
@ -600,16 +603,27 @@ conf_mousebind(struct conf *c, char *name, char *binding)
|
|||||||
} else
|
} else
|
||||||
substring = name;
|
substring = name;
|
||||||
|
|
||||||
current_binding->button = strtonum(substring, 1, 3, &errstr);
|
button = strtonum(substring, 1, 3, &errstr);
|
||||||
if (errstr)
|
if (errstr)
|
||||||
warnx("number of buttons is %s: %s", errstr, substring);
|
warnx("button number is %s: %s", errstr, substring);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/* We now have the correct binding, remove duplicates. */
|
/* We now have the correct binding, remove duplicates. */
|
||||||
conf_mouseunbind(c, current_binding);
|
conf_mouseunbind(c, current_binding);
|
||||||
|
|
||||||
if (strcmp("unmap", binding) == 0) {
|
if (strcmp("unmap", binding) == 0) {
|
||||||
free(current_binding);
|
free(current_binding);
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nitems(name_to_mousefunc); i++) {
|
for (i = 0; i < nitems(name_to_mousefunc); i++) {
|
||||||
@ -619,8 +633,10 @@ conf_mousebind(struct conf *c, char *name, char *binding)
|
|||||||
current_binding->context = name_to_mousefunc[i].context;
|
current_binding->context = name_to_mousefunc[i].context;
|
||||||
current_binding->callback = name_to_mousefunc[i].handler;
|
current_binding->callback = name_to_mousefunc[i].handler;
|
||||||
TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
|
TAILQ_INSERT_TAIL(&c->mousebindingq, current_binding, entry);
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -646,26 +662,10 @@ void
|
|||||||
conf_grab_mouse(struct client_ctx *cc)
|
conf_grab_mouse(struct client_ctx *cc)
|
||||||
{
|
{
|
||||||
struct mousebinding *mb;
|
struct mousebinding *mb;
|
||||||
u_int button;
|
|
||||||
|
|
||||||
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
TAILQ_FOREACH(mb, &Conf.mousebindingq, entry) {
|
||||||
if (mb->context != MOUSEBIND_CTX_WIN)
|
if (mb->context != MOUSEBIND_CTX_WIN)
|
||||||
continue;
|
continue;
|
||||||
|
xu_btn_grab(cc->win, mb->modmask, mb->button);
|
||||||
switch(mb->button) {
|
|
||||||
case 1:
|
|
||||||
button = Button1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
button = Button2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
button = Button3;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
warnx("strange button in mousebinding\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
xu_btn_grab(cc->win, mb->modmask, button);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
parse.y
7
parse.y
@ -171,7 +171,12 @@ main : FONTNAME STRING {
|
|||||||
conf->gap.right = $5;
|
conf->gap.right = $5;
|
||||||
}
|
}
|
||||||
| MOUSEBIND STRING string {
|
| MOUSEBIND STRING string {
|
||||||
conf_mousebind(conf, $2, $3);
|
if (!conf_mousebind(conf, $2, $3)) {
|
||||||
|
yyerror("invalid mousebind: %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