Define callbacks, then default bindings.

This commit is contained in:
okan 2016-11-14 21:25:59 +00:00
parent a78a724512
commit d18539103e
3 changed files with 85 additions and 83 deletions

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* *
* $OpenBSD: calmwm.h,v 1.330 2016/10/24 17:16:23 okan Exp $ * $OpenBSD: calmwm.h,v 1.331 2016/11/14 21:25:59 okan Exp $
*/ */
#ifndef _CALMWM_H_ #ifndef _CALMWM_H_
@ -518,7 +518,7 @@ int parse_config(const char *, struct conf *);
void conf_atoms(void); void conf_atoms(void);
void conf_autogroup(struct conf *, int, const char *, void conf_autogroup(struct conf *, int, const char *,
const char *); const char *);
int conf_bind_kbd(struct conf *, const char *, int conf_bind_key(struct conf *, const char *,
const char *); const char *);
int conf_bind_mouse(struct conf *, const char *, int conf_bind_mouse(struct conf *, const char *,
const char *); const char *);

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* *
* $OpenBSD: conf.c,v 1.221 2016/11/14 19:56:05 okan Exp $ * $OpenBSD: conf.c,v 1.222 2016/11/14 21:25:59 okan Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -34,7 +34,7 @@
static const char *conf_bind_getmask(const char *, unsigned int *); static const char *conf_bind_getmask(const char *, unsigned int *);
static void conf_cmd_remove(struct conf *, const char *); static void conf_cmd_remove(struct conf *, const char *);
static void conf_unbind_kbd(struct conf *, struct bind_ctx *); static void conf_unbind_key(struct conf *, struct bind_ctx *);
static void conf_unbind_mouse(struct conf *, struct bind_ctx *); static void conf_unbind_mouse(struct conf *, struct bind_ctx *);
static int cursor_binds[] = { static int cursor_binds[] = {
@ -54,73 +54,6 @@ static const char *color_binds[] = {
"black", /* CWM_COLOR_MENU_FONT */ "black", /* CWM_COLOR_MENU_FONT */
"", /* CWM_COLOR_MENU_FONT_SEL */ "", /* CWM_COLOR_MENU_FONT_SEL */
}; };
static const struct {
const char *key;
const char *func;
} kbd_binds[] = {
{ "CM-Return", "terminal" },
{ "CM-Delete", "lock" },
{ "M-question", "exec" },
{ "CM-w", "exec_wm" },
{ "M-period", "ssh" },
{ "M-Return", "hide" },
{ "M-Down", "lower" },
{ "M-Up", "raise" },
{ "M-slash", "search" },
{ "C-slash", "menusearch" },
{ "M-Tab", "cycle" },
{ "MS-Tab", "rcycle" },
{ "CM-n", "label" },
{ "CM-x", "delete" },
{ "CM-a", "nogroup" },
{ "CM-0", "nogroup" },
{ "CM-1", "group1" },
{ "CM-2", "group2" },
{ "CM-3", "group3" },
{ "CM-4", "group4" },
{ "CM-5", "group5" },
{ "CM-6", "group6" },
{ "CM-7", "group7" },
{ "CM-8", "group8" },
{ "CM-9", "group9" },
{ "M-Right", "cyclegroup" },
{ "M-Left", "rcyclegroup" },
{ "CM-g", "grouptoggle" },
{ "CM-f", "fullscreen" },
{ "CM-m", "maximize" },
{ "CM-s", "stick" },
{ "CM-equal", "vmaximize" },
{ "CMS-equal", "hmaximize" },
{ "CMS-f", "freeze" },
{ "CMS-r", "restart" },
{ "CMS-q", "quit" },
{ "M-h", "moveleft" },
{ "M-j", "movedown" },
{ "M-k", "moveup" },
{ "M-l", "moveright" },
{ "MS-h", "bigmoveleft" },
{ "MS-j", "bigmovedown" },
{ "MS-k", "bigmoveup" },
{ "MS-l", "bigmoveright" },
{ "CM-h", "resizeleft" },
{ "CM-j", "resizedown" },
{ "CM-k", "resizeup" },
{ "CM-l", "resizeright" },
{ "CMS-h", "bigresizeleft" },
{ "CMS-j", "bigresizedown" },
{ "CMS-k", "bigresizeup" },
{ "CMS-l", "bigresizeright" },
},
mouse_binds[] = {
{ "1", "menu_unhide" },
{ "2", "menu_group" },
{ "3", "menu_cmd" },
{ "M-1", "window_move" },
{ "CM-1", "window_grouptoggle" },
{ "M-2", "window_resize" },
{ "M-3", "window_lower" },
{ "CMS-3", "window_hide" },
};
static const struct { static const struct {
const char *tag; const char *tag;
void (*handler)(void *, union arg *, enum xev); void (*handler)(void *, union arg *, enum xev);
@ -251,6 +184,9 @@ static const struct {
{ "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SC, {0} }, { "menu_unhide", kbfunc_menu_client, CWM_CONTEXT_SC, {0} },
{ "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SC, {0} }, { "menu_cmd", kbfunc_menu_cmd, CWM_CONTEXT_SC, {0} },
}; };
static unsigned int ignore_mods[] = {
0, LockMask, Mod2Mask, Mod2Mask | LockMask
};
static const struct { static const struct {
const char ch; const char ch;
int mask; int mask;
@ -260,7 +196,73 @@ static const struct {
{ '4', Mod4Mask }, { '4', Mod4Mask },
{ 'S', ShiftMask }, { 'S', ShiftMask },
}; };
static unsigned int ign_mods[] = { 0, LockMask, Mod2Mask, Mod2Mask | LockMask }; static const struct {
const char *key;
const char *func;
} key_binds[] = {
{ "CM-Return", "terminal" },
{ "CM-Delete", "lock" },
{ "M-question", "exec" },
{ "CM-w", "exec_wm" },
{ "M-period", "ssh" },
{ "M-Return", "hide" },
{ "M-Down", "lower" },
{ "M-Up", "raise" },
{ "M-slash", "search" },
{ "C-slash", "menusearch" },
{ "M-Tab", "cycle" },
{ "MS-Tab", "rcycle" },
{ "CM-n", "label" },
{ "CM-x", "delete" },
{ "CM-a", "nogroup" },
{ "CM-0", "nogroup" },
{ "CM-1", "group1" },
{ "CM-2", "group2" },
{ "CM-3", "group3" },
{ "CM-4", "group4" },
{ "CM-5", "group5" },
{ "CM-6", "group6" },
{ "CM-7", "group7" },
{ "CM-8", "group8" },
{ "CM-9", "group9" },
{ "M-Right", "cyclegroup" },
{ "M-Left", "rcyclegroup" },
{ "CM-g", "grouptoggle" },
{ "CM-f", "fullscreen" },
{ "CM-m", "maximize" },
{ "CM-s", "stick" },
{ "CM-equal", "vmaximize" },
{ "CMS-equal", "hmaximize" },
{ "CMS-f", "freeze" },
{ "CMS-r", "restart" },
{ "CMS-q", "quit" },
{ "M-h", "moveleft" },
{ "M-j", "movedown" },
{ "M-k", "moveup" },
{ "M-l", "moveright" },
{ "MS-h", "bigmoveleft" },
{ "MS-j", "bigmovedown" },
{ "MS-k", "bigmoveup" },
{ "MS-l", "bigmoveright" },
{ "CM-h", "resizeleft" },
{ "CM-j", "resizedown" },
{ "CM-k", "resizeup" },
{ "CM-l", "resizeright" },
{ "CMS-h", "bigresizeleft" },
{ "CMS-j", "bigresizedown" },
{ "CMS-k", "bigresizeup" },
{ "CMS-l", "bigresizeright" },
},
mouse_binds[] = {
{ "1", "menu_unhide" },
{ "2", "menu_group" },
{ "3", "menu_cmd" },
{ "M-1", "window_move" },
{ "CM-1", "window_grouptoggle" },
{ "M-2", "window_resize" },
{ "M-3", "window_lower" },
{ "CMS-3", "window_hide" },
};
void void
conf_init(struct conf *c) conf_init(struct conf *c)
@ -280,8 +282,8 @@ conf_init(struct conf *c)
TAILQ_INIT(&c->autogroupq); TAILQ_INIT(&c->autogroupq);
TAILQ_INIT(&c->mousebindq); TAILQ_INIT(&c->mousebindq);
for (i = 0; i < nitems(kbd_binds); i++) for (i = 0; i < nitems(key_binds); i++)
conf_bind_kbd(c, kbd_binds[i].key, kbd_binds[i].func); conf_bind_key(c, key_binds[i].key, key_binds[i].func);
for (i = 0; i < nitems(mouse_binds); i++) for (i = 0; i < nitems(mouse_binds); i++)
conf_bind_mouse(c, mouse_binds[i].key, mouse_binds[i].func); conf_bind_mouse(c, mouse_binds[i].key, mouse_binds[i].func);
@ -502,7 +504,7 @@ conf_bind_getmask(const char *name, unsigned int *mask)
} }
int int
conf_bind_kbd(struct conf *c, const char *bind, const char *cmd) conf_bind_key(struct conf *c, const char *bind, const char *cmd)
{ {
struct bind_ctx *kb; struct bind_ctx *kb;
const char *key; const char *key;
@ -517,7 +519,7 @@ conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
return(0); return(0);
} }
/* Remove duplicates. */ /* Remove duplicates. */
conf_unbind_kbd(c, kb); conf_unbind_key(c, kb);
if (strcmp("unmap", cmd) == 0) { if (strcmp("unmap", cmd) == 0) {
free(kb); free(kb);
@ -540,7 +542,7 @@ conf_bind_kbd(struct conf *c, const char *bind, const char *cmd)
} }
static void static void
conf_unbind_kbd(struct conf *c, struct bind_ctx *unbind) conf_unbind_key(struct conf *c, struct bind_ctx *unbind)
{ {
struct bind_ctx *key = NULL, *keynxt; struct bind_ctx *key = NULL, *keynxt;
@ -620,8 +622,8 @@ conf_grab_kbd(Window win)
(XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym)) (XkbKeycodeToKeysym(X_Dpy, kc, 0, 1) == kb->press.keysym))
kb->modmask |= ShiftMask; kb->modmask |= ShiftMask;
for (i = 0; i < nitems(ign_mods); i++) for (i = 0; i < nitems(ignore_mods); i++)
XGrabKey(X_Dpy, kc, (kb->modmask | ign_mods[i]), win, XGrabKey(X_Dpy, kc, (kb->modmask | ignore_mods[i]), win,
True, GrabModeAsync, GrabModeAsync); True, GrabModeAsync, GrabModeAsync);
} }
} }
@ -637,9 +639,9 @@ conf_grab_mouse(Window win)
TAILQ_FOREACH(mb, &Conf.mousebindq, entry) { TAILQ_FOREACH(mb, &Conf.mousebindq, entry) {
if (mb->context != CWM_CONTEXT_CC) if (mb->context != CWM_CONTEXT_CC)
continue; continue;
for (i = 0; i < nitems(ign_mods); i++) { for (i = 0; i < nitems(ignore_mods); i++) {
XGrabButton(X_Dpy, mb->press.button, XGrabButton(X_Dpy, mb->press.button,
(mb->modmask | ign_mods[i]), win, False, (mb->modmask | ignore_mods[i]), win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, BUTTONMASK, GrabModeAsync, GrabModeSync,
None, None); None, None);
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.65 2016/10/03 14:42:34 okan Exp $ */ /* $OpenBSD: parse.y,v 1.66 2016/11/14 21:25:59 okan Exp $ */
/* /*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -170,7 +170,7 @@ main : FONTNAME STRING {
free($2); free($2);
} }
| BIND STRING string { | BIND STRING string {
if (!conf_bind_kbd(conf, $2, $3)) { if (!conf_bind_key(conf, $2, $3)) {
yyerror("invalid bind: %s %s", $2, $3); yyerror("invalid bind: %s %s", $2, $3);
free($2); free($2);
free($3); free($3);