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 *), void conf_bindkey(struct conf *, void (*)(struct client_ctx *, void *),
int, int, int, void *); int, int, int, void *);
void conf_bindname(struct conf *, char *, char *); void conf_bindname(struct conf *, char *, char *);
void conf_unbind(struct conf *, struct keybinding *);
void conf_parsekeys(struct conf *, char *); void conf_parsekeys(struct conf *, char *);
void conf_parsesettings(struct conf *, char *); void conf_parsesettings(struct conf *, char *);
void conf_parseignores(struct conf *, char *); void conf_parseignores(struct conf *, char *);

31
conf.c
View File

@ -181,10 +181,7 @@ conf_setup(struct conf *c)
conf_cmd_init(c); conf_cmd_init(c);
TAILQ_INIT(&c->keybindingq); TAILQ_INIT(&c->keybindingq);
snprintf(dir_keydefs, sizeof(dir_keydefs), "%s/.calmwm/.keys", home);
if (dirent_isdir(dir_keydefs)) {
conf_parsekeys(c, dir_keydefs);
} else {
conf_bindname(c, "CM-Return", "terminal"); conf_bindname(c, "CM-Return", "terminal");
conf_bindname(c, "CM-Delete", "lock"); conf_bindname(c, "CM-Delete", "lock");
conf_bindname(c, "M-question", "exec"); conf_bindname(c, "M-question", "exec");
@ -203,7 +200,6 @@ conf_setup(struct conf *c)
conf_bindname(c, "CM-1", "group1"); conf_bindname(c, "CM-1", "group1");
conf_bindname(c, "CM-2", "group2"); conf_bindname(c, "CM-2", "group2");
conf_bindname(c, "CM-3", "group3"); conf_bindname(c, "CM-3", "group3");
conf_bindname(c, "CM-4", "group4");
conf_bindname(c, "CM-5", "group5"); conf_bindname(c, "CM-5", "group5");
conf_bindname(c, "CM-6", "group6"); conf_bindname(c, "CM-6", "group6");
conf_bindname(c, "CM-7", "group7"); conf_bindname(c, "CM-7", "group7");
@ -241,7 +237,9 @@ conf_setup(struct conf *c)
conf_bindname(c, "CS-Up", "bigptrmoveup"); conf_bindname(c, "CS-Up", "bigptrmoveup");
conf_bindname(c, "CS-Right", "bigptrmoveright"); conf_bindname(c, "CS-Right", "bigptrmoveright");
} snprintf(dir_keydefs, sizeof(dir_keydefs), "%s/.calmwm/.keys", home);
if (dirent_isdir(dir_keydefs))
conf_parsekeys(c, dir_keydefs);
snprintf(dir_settings, sizeof(dir_settings), snprintf(dir_settings, sizeof(dir_settings),
"%s/.calmwm/.settings", home); "%s/.calmwm/.settings", home);
@ -499,6 +497,12 @@ conf_bindname(struct conf *c, char *name, char *binding)
return; 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++) { for (iter = 0; name_to_kbfunc[iter].tag != NULL; iter++) {
if (strcmp(name_to_kbfunc[iter].tag, binding) != 0) if (strcmp(name_to_kbfunc[iter].tag, binding) != 0)
continue; continue;
@ -520,6 +524,21 @@ conf_bindname(struct conf *c, char *name, char *binding)
return; 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 void
conf_parsesettings(struct conf *c, char *filename) 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. to not have borders.
.It Pa ~/.calmwm/.keys .It Pa ~/.calmwm/.keys
Symlinks in this directory cause the creation of keyboard shortcuts. Symlinks in this directory cause the creation of keyboard shortcuts.
If the directory does not exist, then the default shortcuts will be The default shortcuts will always be created. In case of conflict,
created; otherwise only the shortcuts defined will be created. user-defined shortcuts take precidence.
The name of a link here is first the modifier keys, followed by a ``-''. The name of a link here is first the modifier keys, followed by a ``-''.
The following modifiers are recognised: The following modifiers are recognised:
.Bl -tag -width Ds .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 structure in
.Pa /usr/src/xenocara/app/cwm/conf.c , .Pa /usr/src/xenocara/app/cwm/conf.c ,
or, alternatively it should be the commandline that is wished to be executed. 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 For example, to cause
.Ic C-M-r .Ic C-M-r
to add a label to a window: to add a label to a window:
@ -324,6 +327,10 @@ with C-S-Enter:
.Bd -literal -offset indent .Bd -literal -offset indent
$ ln -s "/usr/X11R6/bin/xterm -e top" ~/.calmwm/.keys/CS-Return $ ln -s "/usr/X11R6/bin/xterm -e top" ~/.calmwm/.keys/CS-Return
.Ed .Ed
Remove a keybinding for Mod4-o
.Bd -literal -offset indent
$ ln -s "unmap" 4-o
.Ed
.El .El
.Sh AUTHORS .Sh AUTHORS
.An -nosplit .An -nosplit