Make cwm default keybindings always exist. Additional keybindings now

overlap with the new ones, overriding them. Also a new "unmap" keyword
in binding definitions now unmaps a binding without adding a new one.

This seriously shrinks the ~/.calmwm/.keys directory of anyone who defines
their own bindings whilst wanting some of the defaults.

Looked over, liked and ok todd@
This commit is contained in:
oga 2007-11-19 22:18:16 +00:00
parent ebebed71bd
commit 3341229c74
3 changed files with 88 additions and 61 deletions

View File

@ -406,6 +406,7 @@ void conf_client(struct client_ctx *);
void conf_bindkey(struct conf *, void (*)(struct client_ctx *, void *),
int, int, int, void *);
void conf_bindname(struct conf *, char *, char *);
void conf_unbind(struct conf *, struct keybinding *);
void conf_parsekeys(struct conf *, char *);
void conf_parsesettings(struct conf *, char *);
void conf_parseignores(struct conf *, char *);

137
conf.c
View File

@ -181,67 +181,65 @@ conf_setup(struct conf *c)
conf_cmd_init(c);
TAILQ_INIT(&c->keybindingq);
conf_bindname(c, "CM-Return", "terminal");
conf_bindname(c, "CM-Delete", "lock");
conf_bindname(c, "M-question", "exec");
conf_bindname(c, "M-period", "ssh");
conf_bindname(c, "M-Return", "hide");
conf_bindname(c, "M-Down", "lower");
conf_bindname(c, "M-Up", "raise");
conf_bindname(c, "M-slash", "search");
conf_bindname(c, "C-slash", "menusearch");
conf_bindname(c, "M-Tab", "cycle");
conf_bindname(c, "MS-Tab", "rcycle");
conf_bindname(c, "CM-n", "label");
conf_bindname(c, "CM-x", "delete");
conf_bindname(c, "CM-Escape", "groupselect");
conf_bindname(c, "CM-0", "group0");
conf_bindname(c, "CM-1", "group1");
conf_bindname(c, "CM-2", "group2");
conf_bindname(c, "CM-3", "group3");
conf_bindname(c, "CM-5", "group5");
conf_bindname(c, "CM-6", "group6");
conf_bindname(c, "CM-7", "group7");
conf_bindname(c, "CM-8", "group8");
conf_bindname(c, "CM-9", "group9");
conf_bindname(c, "M-Right", "nextgroup");
conf_bindname(c, "M-Left", "prevgroup");
conf_bindname(c, "CM-f", "maximize");
conf_bindname(c, "CM-equal", "vmaximize");
conf_bindname(c, "M-h", "moveleft");
conf_bindname(c, "M-j", "movedown");
conf_bindname(c, "M-k", "moveup");
conf_bindname(c, "M-l", "moveright");
conf_bindname(c, "M-H", "bigmoveleft");
conf_bindname(c, "M-J", "bigmovedown");
conf_bindname(c, "M-K", "bigmoveup");
conf_bindname(c, "M-L", "bigmoveright");
conf_bindname(c, "CM-h", "resizeleft");
conf_bindname(c, "CM-j", "resizedown");
conf_bindname(c, "CM-k", "resizeup");
conf_bindname(c, "CM-l", "resizeright");
conf_bindname(c, "CM-H", "bigresizeleft");
conf_bindname(c, "CM-J", "bigresizedown");
conf_bindname(c, "CM-K", "bigresizeup");
conf_bindname(c, "CM-L", "bigresizeright");
conf_bindname(c, "C-Left", "ptrmoveleft");
conf_bindname(c, "C-Down", "ptrmovedown");
conf_bindname(c, "C-Up", "ptrmoveup");
conf_bindname(c, "C-Right", "ptrmoveright");
conf_bindname(c, "CS-Left", "bigptrmoveleft");
conf_bindname(c, "CS-Down", "bigptrmovedown");
conf_bindname(c, "CS-Up", "bigptrmoveup");
conf_bindname(c, "CS-Right", "bigptrmoveright");
snprintf(dir_keydefs, sizeof(dir_keydefs), "%s/.calmwm/.keys", home);
if (dirent_isdir(dir_keydefs)) {
if (dirent_isdir(dir_keydefs))
conf_parsekeys(c, dir_keydefs);
} else {
conf_bindname(c, "CM-Return", "terminal");
conf_bindname(c, "CM-Delete", "lock");
conf_bindname(c, "M-question", "exec");
conf_bindname(c, "M-period", "ssh");
conf_bindname(c, "M-Return", "hide");
conf_bindname(c, "M-Down", "lower");
conf_bindname(c, "M-Up", "raise");
conf_bindname(c, "M-slash", "search");
conf_bindname(c, "C-slash", "menusearch");
conf_bindname(c, "M-Tab", "cycle");
conf_bindname(c, "MS-Tab", "rcycle");
conf_bindname(c, "CM-n", "label");
conf_bindname(c, "CM-x", "delete");
conf_bindname(c, "CM-Escape", "groupselect");
conf_bindname(c, "CM-0", "group0");
conf_bindname(c, "CM-1", "group1");
conf_bindname(c, "CM-2", "group2");
conf_bindname(c, "CM-3", "group3");
conf_bindname(c, "CM-4", "group4");
conf_bindname(c, "CM-5", "group5");
conf_bindname(c, "CM-6", "group6");
conf_bindname(c, "CM-7", "group7");
conf_bindname(c, "CM-8", "group8");
conf_bindname(c, "CM-9", "group9");
conf_bindname(c, "M-Right", "nextgroup");
conf_bindname(c, "M-Left", "prevgroup");
conf_bindname(c, "CM-f", "maximize");
conf_bindname(c, "CM-equal", "vmaximize");
conf_bindname(c, "M-h", "moveleft");
conf_bindname(c, "M-j", "movedown");
conf_bindname(c, "M-k", "moveup");
conf_bindname(c, "M-l", "moveright");
conf_bindname(c, "M-H", "bigmoveleft");
conf_bindname(c, "M-J", "bigmovedown");
conf_bindname(c, "M-K", "bigmoveup");
conf_bindname(c, "M-L", "bigmoveright");
conf_bindname(c, "CM-h", "resizeleft");
conf_bindname(c, "CM-j", "resizedown");
conf_bindname(c, "CM-k", "resizeup");
conf_bindname(c, "CM-l", "resizeright");
conf_bindname(c, "CM-H", "bigresizeleft");
conf_bindname(c, "CM-J", "bigresizedown");
conf_bindname(c, "CM-K", "bigresizeup");
conf_bindname(c, "CM-L", "bigresizeright");
conf_bindname(c, "C-Left", "ptrmoveleft");
conf_bindname(c, "C-Down", "ptrmovedown");
conf_bindname(c, "C-Up", "ptrmoveup");
conf_bindname(c, "C-Right", "ptrmoveright");
conf_bindname(c, "CS-Left", "bigptrmoveleft");
conf_bindname(c, "CS-Down", "bigptrmovedown");
conf_bindname(c, "CS-Up", "bigptrmoveup");
conf_bindname(c, "CS-Right", "bigptrmoveright");
}
snprintf(dir_settings, sizeof(dir_settings),
"%s/.calmwm/.settings", home);
@ -499,6 +497,12 @@ conf_bindname(struct conf *c, char *name, char *binding)
return;
}
/* We now have the correct binding, remove duplicates. */
conf_unbind(c, current_binding);
if (strcmp("unmap",binding) == 0)
return;
for (iter = 0; name_to_kbfunc[iter].tag != NULL; iter++) {
if (strcmp(name_to_kbfunc[iter].tag, binding) != 0)
continue;
@ -520,6 +524,21 @@ conf_bindname(struct conf *c, char *name, char *binding)
return;
}
void conf_unbind(struct conf *c, struct keybinding *unbind)
{
struct keybinding *key = NULL;
TAILQ_FOREACH(key, &c->keybindingq, entry) {
if (key->modmask != unbind->modmask)
continue;
if ((key->keycode != 0 && key->keysym == NoSymbol &&
key->keycode == unbind->keycode) ||
key->keysym == unbind->keysym)
TAILQ_REMOVE(&c->keybindingq, key, entry);
}
}
void
conf_parsesettings(struct conf *c, char *filename)
{

11
cwm.1
View File

@ -286,8 +286,8 @@ will cause any instances of
to not have borders.
.It Pa ~/.calmwm/.keys
Symlinks in this directory cause the creation of keyboard shortcuts.
If the directory does not exist, then the default shortcuts will be
created; otherwise only the shortcuts defined will be created.
The default shortcuts will always be created. In case of conflict,
user-defined shortcuts take precidence.
The name of a link here is first the modifier keys, followed by a ``-''.
The following modifiers are recognised:
.Bl -tag -width Ds
@ -312,6 +312,9 @@ The target of the link should be either the name of a task from the
structure in
.Pa /usr/src/xenocara/app/cwm/conf.c ,
or, alternatively it should be the commandline that is wished to be executed.
A special case is the ``unmap'' keyword, which causes any bindings using the
named shortcut to be removed. This can be used to remove a binding which conflicts
with an application.
For example, to cause
.Ic C-M-r
to add a label to a window:
@ -324,6 +327,10 @@ with C-S-Enter:
.Bd -literal -offset indent
$ ln -s "/usr/X11R6/bin/xterm -e top" ~/.calmwm/.keys/CS-Return
.Ed
Remove a keybinding for Mod4-o
.Bd -literal -offset indent
$ ln -s "unmap" 4-o
.Ed
.El
.Sh AUTHORS
.An -nosplit