Allow binding mouse buttons

Instead of hardcoding mouse button actions, allow the user to
bind mouse buttons to extended commands.  For example the new
defaults are:

BIND=mouse1:therecmdmenu
BIND=mouse2:clicklook

Currently a bit rudimentary; the defaults should be OK, but
documentation is bit lacking, and in-game binding and option
saving are missing.

Allowed commands to bind are "nothing", "therecmdmenu", "clicklook",
and "mouseaction". Clicklook replaces the "clicklook" boolean option,
and mouseaction does what mouse 1 button used to do - a context sensitive
action.
This commit is contained in:
Pasi Kallinen
2022-08-23 23:06:26 +03:00
parent 3a255e86c4
commit c42e73fd9c
11 changed files with 135 additions and 78 deletions

View File

@@ -6632,6 +6632,9 @@ parsebindings(char *bindings)
uchar key;
int i;
boolean ret = TRUE; /* assume success */
static const char *const mousebtn_names[NUM_MOUSE_BUTTONS] = {
"mouse1", "mouse2"
};
/* look for first comma, then decide whether it is the key being bound
or a list element separator; if it's a key, find separator beyond it */
@@ -6660,6 +6663,17 @@ parsebindings(char *bindings)
return FALSE; /* it's not a binding */
*bind++ = 0;
bind = trimspaces(bind);
for (i = 0; i < SIZE(mousebtn_names); i++)
if (!strcmp(bindings, mousebtn_names[i])) {
if (!bind_mousebtn(i + 1, bind)) {
config_error_add("Error binding mouse button %i", i + 1);
} else {
return ret;
}
}
/* read the key to be bound */
key = txt2key(bindings);
if (!key) {
@@ -6667,8 +6681,6 @@ parsebindings(char *bindings)
return FALSE;
}
bind = trimspaces(bind);
/* is it a special key? */
if (bind_specialkey(key, bind))
return ret;