Skip to content

Commit

Permalink
input: use mnemonic names for mouse buttons
Browse files Browse the repository at this point in the history
mpv's mouse button numbering is based on X11 button numbering, which
allows for an arbitrary number of buttons and includes mouse wheel input
as buttons 3-6. This button numbering was used throughout the codebase
and exposed in input.conf, and it was difficult to remember which
physical button each number actually referred to and which referred to
the scroll wheel.

In practice, PC mice only have between two and five buttons and one or
two scroll wheel axes, which are more or less in the same location and
have more or less the same function. This allows us to use names to
refer to the buttons instead of numbers, which makes input.conf syntax a
lot easier to remember. It also makes the syntax robust to changes in
mpv's underlying numbering. The old MOUSE_BTNx names are still
understood as deprecated aliases of the named buttons.

This changes both the input.conf syntax and the MP_MOUSE_BTNx symbols in
the codebase, since I think both would benefit from using names over
numbers, especially since some platforms don't use X11 button numbering
and handle different mouse buttons in different windowing system events.

This also makes the names shorter, since otherwise they would be pretty
long, and it removes the high-numbered MOUSE_BTNx_DBL names, since they
weren't used.

Names are the same as used in Qt:
https://doc.qt.io/qt-5/qt.html#MouseButton-enum
  • Loading branch information
rossy committed Sep 3, 2017
1 parent 449d972 commit 957e9a3
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 171 deletions.
4 changes: 4 additions & 0 deletions DOCS/interface-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Interface changes
obscure use that stopped working with the change above. It was also
prone to be confused with a feature not implemented by it: auto did _not_
mean that deinterlacing was enabled on demand.)
- add shortened mnemonic names for mouse button bindings, eg. mbtn_left
the old numeric names (mouse_btn0) are deprecated
- remove mouse_btn3_dbl and up, since they are only generated for buttons
0-2 (these now print an error when sent from the 'mouse' command)
--- mpv 0.26.0 ---
- remove remaining deprecated audio device options, like --alsa-device
Some of them were removed in earlier releases.
Expand Down
14 changes: 7 additions & 7 deletions etc/input.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
# If this is enabled, treat all the following bindings as default.
#default-bindings start

#MOUSE_BTN0 ignore # don't do anything
#MOUSE_BTN0_DBL cycle fullscreen # toggle fullscreen on/off
#MOUSE_BTN2 cycle pause # toggle pause on/off
#MOUSE_BTN3 seek 10
#MOUSE_BTN4 seek -10
#MOUSE_BTN5 add volume -2
#MOUSE_BTN6 add volume 2
#MBTN_LEFT ignore # don't do anything
#MBTN_LEFT_DBL cycle fullscreen # toggle fullscreen on/off
#MBTN_RIGHT cycle pause # toggle pause on/off
#WHEEL_UP seek 10
#WHEEL_DOWN seek -10
#WHEEL_LEFT add volume -2
#WHEEL_RIGHT add volume 2

# Mouse wheels, touchpad or other input devices that have axes
# if the input devices supports precise scrolling it will also scale the
Expand Down
4 changes: 2 additions & 2 deletions input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ static void mp_input_feed_key(struct input_ctx *ictx, int code, double scale,
if (ictx->last_doubleclick_key_down == code &&
now - ictx->last_doubleclick_time < opts->doubleclick_time / 1000.0)
{
if (code >= MP_MOUSE_BTN0 && code <= MP_MOUSE_BTN2) {
interpret_key(ictx, code - MP_MOUSE_BTN0 + MP_MOUSE_BTN0_DBL,
if (code >= MP_MBTN_LEFT && code <= MP_MBTN_RIGHT) {
interpret_key(ictx, code - MP_MOUSE_BASE + MP_MOUSE_DBL_BASE,
1, 1);
}
}
Expand Down
88 changes: 48 additions & 40 deletions input/keycodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,46 +78,29 @@ static const struct key_name key_names[] = {
{ MP_KEY_KPDEC, "KP_DEC" },
{ MP_KEY_KPINS, "KP_INS" },
{ MP_KEY_KPENTER, "KP_ENTER" },
{ MP_MOUSE_BTN0, "MOUSE_BTN0" },
{ MP_MOUSE_BTN1, "MOUSE_BTN1" },
{ MP_MOUSE_BTN2, "MOUSE_BTN2" },
{ MP_MOUSE_BTN3, "MOUSE_BTN3" },
{ MP_MOUSE_BTN4, "MOUSE_BTN4" },
{ MP_MOUSE_BTN5, "MOUSE_BTN5" },
{ MP_MOUSE_BTN6, "MOUSE_BTN6" },
{ MP_MOUSE_BTN7, "MOUSE_BTN7" },
{ MP_MOUSE_BTN8, "MOUSE_BTN8" },
{ MP_MOUSE_BTN9, "MOUSE_BTN9" },
{ MP_MOUSE_BTN10, "MOUSE_BTN10" },
{ MP_MOUSE_BTN11, "MOUSE_BTN11" },
{ MP_MOUSE_BTN12, "MOUSE_BTN12" },
{ MP_MOUSE_BTN13, "MOUSE_BTN13" },
{ MP_MOUSE_BTN14, "MOUSE_BTN14" },
{ MP_MOUSE_BTN15, "MOUSE_BTN15" },
{ MP_MOUSE_BTN16, "MOUSE_BTN16" },
{ MP_MOUSE_BTN17, "MOUSE_BTN17" },
{ MP_MOUSE_BTN18, "MOUSE_BTN18" },
{ MP_MOUSE_BTN19, "MOUSE_BTN19" },
{ MP_MOUSE_BTN0_DBL, "MOUSE_BTN0_DBL" },
{ MP_MOUSE_BTN1_DBL, "MOUSE_BTN1_DBL" },
{ MP_MOUSE_BTN2_DBL, "MOUSE_BTN2_DBL" },
{ MP_MOUSE_BTN3_DBL, "MOUSE_BTN3_DBL" },
{ MP_MOUSE_BTN4_DBL, "MOUSE_BTN4_DBL" },
{ MP_MOUSE_BTN5_DBL, "MOUSE_BTN5_DBL" },
{ MP_MOUSE_BTN6_DBL, "MOUSE_BTN6_DBL" },
{ MP_MOUSE_BTN7_DBL, "MOUSE_BTN7_DBL" },
{ MP_MOUSE_BTN8_DBL, "MOUSE_BTN8_DBL" },
{ MP_MOUSE_BTN9_DBL, "MOUSE_BTN9_DBL" },
{ MP_MOUSE_BTN10_DBL, "MOUSE_BTN10_DBL" },
{ MP_MOUSE_BTN11_DBL, "MOUSE_BTN11_DBL" },
{ MP_MOUSE_BTN12_DBL, "MOUSE_BTN12_DBL" },
{ MP_MOUSE_BTN13_DBL, "MOUSE_BTN13_DBL" },
{ MP_MOUSE_BTN14_DBL, "MOUSE_BTN14_DBL" },
{ MP_MOUSE_BTN15_DBL, "MOUSE_BTN15_DBL" },
{ MP_MOUSE_BTN16_DBL, "MOUSE_BTN16_DBL" },
{ MP_MOUSE_BTN17_DBL, "MOUSE_BTN17_DBL" },
{ MP_MOUSE_BTN18_DBL, "MOUSE_BTN18_DBL" },
{ MP_MOUSE_BTN19_DBL, "MOUSE_BTN19_DBL" },
{ MP_MBTN_LEFT, "MBTN_LEFT" },
{ MP_MBTN_MID, "MBTN_MID" },
{ MP_MBTN_RIGHT, "MBTN_RIGHT" },
{ MP_WHEEL_UP, "WHEEL_UP" },
{ MP_WHEEL_DOWN, "WHEEL_DOWN" },
{ MP_WHEEL_LEFT, "WHEEL_LEFT" },
{ MP_WHEEL_RIGHT, "WHEEL_RIGHT" },
{ MP_MBTN_BACK, "MBTN_BACK" },
{ MP_MBTN_FORWARD, "MBTN_FORWARD" },
{ MP_MBTN9, "MBTN9" },
{ MP_MBTN10, "MBTN10" },
{ MP_MBTN11, "MBTN11" },
{ MP_MBTN12, "MBTN12" },
{ MP_MBTN13, "MBTN13" },
{ MP_MBTN14, "MBTN14" },
{ MP_MBTN15, "MBTN15" },
{ MP_MBTN16, "MBTN16" },
{ MP_MBTN17, "MBTN17" },
{ MP_MBTN18, "MBTN18" },
{ MP_MBTN19, "MBTN19" },
{ MP_MBTN_LEFT_DBL, "MBTN_LEFT_DBL" },
{ MP_MBTN_MID_DBL, "MBTN_MID_DBL" },
{ MP_MBTN_RIGHT_DBL, "MBTN_RIGHT_DBL" },

{ MP_AR_PLAY, "AR_PLAY" },
{ MP_AR_PLAY_HOLD, "AR_PLAY_HOLD" },
Expand Down Expand Up @@ -169,6 +152,31 @@ static const struct key_name key_names[] = {
{ MP_KEY_PREV, "XF86_PREV" },
{ MP_KEY_NEXT, "XF86_NEXT" },

// Deprecated numeric aliases for the mouse buttons
{ MP_MBTN_LEFT, "MOUSE_BTN0" },
{ MP_MBTN_MID, "MOUSE_BTN1" },
{ MP_MBTN_RIGHT, "MOUSE_BTN2" },
{ MP_WHEEL_UP, "MOUSE_BTN3" },
{ MP_WHEEL_DOWN, "MOUSE_BTN4" },
{ MP_WHEEL_LEFT, "MOUSE_BTN5" },
{ MP_WHEEL_RIGHT, "MOUSE_BTN6" },
{ MP_MBTN_BACK, "MOUSE_BTN7" },
{ MP_MBTN_FORWARD, "MOUSE_BTN8" },
{ MP_MBTN9, "MOUSE_BTN9" },
{ MP_MBTN10, "MOUSE_BTN10" },
{ MP_MBTN11, "MOUSE_BTN11" },
{ MP_MBTN12, "MOUSE_BTN12" },
{ MP_MBTN13, "MOUSE_BTN13" },
{ MP_MBTN14, "MOUSE_BTN14" },
{ MP_MBTN15, "MOUSE_BTN15" },
{ MP_MBTN16, "MOUSE_BTN16" },
{ MP_MBTN17, "MOUSE_BTN17" },
{ MP_MBTN18, "MOUSE_BTN18" },
{ MP_MBTN19, "MOUSE_BTN19" },
{ MP_MBTN_LEFT_DBL, "MOUSE_BTN0_DBL" },
{ MP_MBTN_MID_DBL, "MOUSE_BTN1_DBL" },
{ MP_MBTN_RIGHT_DBL, "MOUSE_BTN2_DBL" },

{ MP_KEY_CLOSE_WIN, "CLOSE_WIN" },
{ MP_KEY_MOUSE_MOVE, "MOUSE_MOVE" },
{ MP_KEY_MOUSE_LEAVE, "MOUSE_LEAVE" },
Expand Down
77 changes: 30 additions & 47 deletions input/keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,57 +98,40 @@
#define MP_KEY_KPENTER (MP_KEY_KEYPAD+13)

// Mouse events from VOs
#define MP_MOUSE_BASE ((MP_KEY_BASE+0xA0)|MP_NO_REPEAT_KEY|MP_KEY_EMIT_ON_UP)
#define MP_MOUSE_BTN0 (MP_MOUSE_BASE+0)
#define MP_MOUSE_BTN1 (MP_MOUSE_BASE+1)
#define MP_MOUSE_BTN2 (MP_MOUSE_BASE+2)
#define MP_MOUSE_BTN3 (MP_MOUSE_BASE+3)
#define MP_MOUSE_BTN4 (MP_MOUSE_BASE+4)
#define MP_MOUSE_BTN5 (MP_MOUSE_BASE+5)
#define MP_MOUSE_BTN6 (MP_MOUSE_BASE+6)
#define MP_MOUSE_BTN7 (MP_MOUSE_BASE+7)
#define MP_MOUSE_BTN8 (MP_MOUSE_BASE+8)
#define MP_MOUSE_BTN9 (MP_MOUSE_BASE+9)
#define MP_MOUSE_BTN10 (MP_MOUSE_BASE+10)
#define MP_MOUSE_BTN11 (MP_MOUSE_BASE+11)
#define MP_MOUSE_BTN12 (MP_MOUSE_BASE+12)
#define MP_MOUSE_BTN13 (MP_MOUSE_BASE+13)
#define MP_MOUSE_BTN14 (MP_MOUSE_BASE+14)
#define MP_MOUSE_BTN15 (MP_MOUSE_BASE+15)
#define MP_MOUSE_BTN16 (MP_MOUSE_BASE+16)
#define MP_MOUSE_BTN17 (MP_MOUSE_BASE+17)
#define MP_MOUSE_BTN18 (MP_MOUSE_BASE+18)
#define MP_MOUSE_BTN19 (MP_MOUSE_BASE+19)
#define MP_MOUSE_BTN_END (MP_MOUSE_BASE+20)
#define MP_MOUSE_BASE ((MP_KEY_BASE+0xA0)|MP_NO_REPEAT_KEY|MP_KEY_EMIT_ON_UP)
#define MP_MBTN_LEFT (MP_MOUSE_BASE+0)
#define MP_MBTN_MID (MP_MOUSE_BASE+1)
#define MP_MBTN_RIGHT (MP_MOUSE_BASE+2)
#define MP_WHEEL_UP (MP_MOUSE_BASE+3)
#define MP_WHEEL_DOWN (MP_MOUSE_BASE+4)
#define MP_WHEEL_LEFT (MP_MOUSE_BASE+5)
#define MP_WHEEL_RIGHT (MP_MOUSE_BASE+6)
#define MP_MBTN_BACK (MP_MOUSE_BASE+7)
#define MP_MBTN_FORWARD (MP_MOUSE_BASE+8)
#define MP_MBTN9 (MP_MOUSE_BASE+9)
#define MP_MBTN10 (MP_MOUSE_BASE+10)
#define MP_MBTN11 (MP_MOUSE_BASE+11)
#define MP_MBTN12 (MP_MOUSE_BASE+12)
#define MP_MBTN13 (MP_MOUSE_BASE+13)
#define MP_MBTN14 (MP_MOUSE_BASE+14)
#define MP_MBTN15 (MP_MOUSE_BASE+15)
#define MP_MBTN16 (MP_MOUSE_BASE+16)
#define MP_MBTN17 (MP_MOUSE_BASE+17)
#define MP_MBTN18 (MP_MOUSE_BASE+18)
#define MP_MBTN19 (MP_MOUSE_BASE+19)
#define MP_MOUSE_END (MP_MOUSE_BASE+20)

#define MP_KEY_IS_MOUSE_BTN_SINGLE(code) \
((code) >= MP_MOUSE_BASE && (code) < MP_MOUSE_BTN_END)

#define MP_MOUSE_BASE_DBL ((MP_KEY_BASE+0xC0)|MP_NO_REPEAT_KEY)
#define MP_MOUSE_BTN0_DBL (MP_MOUSE_BASE_DBL+0)
#define MP_MOUSE_BTN1_DBL (MP_MOUSE_BASE_DBL+1)
#define MP_MOUSE_BTN2_DBL (MP_MOUSE_BASE_DBL+2)
#define MP_MOUSE_BTN3_DBL (MP_MOUSE_BASE_DBL+3)
#define MP_MOUSE_BTN4_DBL (MP_MOUSE_BASE_DBL+4)
#define MP_MOUSE_BTN5_DBL (MP_MOUSE_BASE_DBL+5)
#define MP_MOUSE_BTN6_DBL (MP_MOUSE_BASE_DBL+6)
#define MP_MOUSE_BTN7_DBL (MP_MOUSE_BASE_DBL+7)
#define MP_MOUSE_BTN8_DBL (MP_MOUSE_BASE_DBL+8)
#define MP_MOUSE_BTN9_DBL (MP_MOUSE_BASE_DBL+9)
#define MP_MOUSE_BTN10_DBL (MP_MOUSE_BASE_DBL+10)
#define MP_MOUSE_BTN11_DBL (MP_MOUSE_BASE_DBL+11)
#define MP_MOUSE_BTN12_DBL (MP_MOUSE_BASE_DBL+12)
#define MP_MOUSE_BTN13_DBL (MP_MOUSE_BASE_DBL+13)
#define MP_MOUSE_BTN14_DBL (MP_MOUSE_BASE_DBL+14)
#define MP_MOUSE_BTN15_DBL (MP_MOUSE_BASE_DBL+15)
#define MP_MOUSE_BTN16_DBL (MP_MOUSE_BASE_DBL+16)
#define MP_MOUSE_BTN17_DBL (MP_MOUSE_BASE_DBL+17)
#define MP_MOUSE_BTN18_DBL (MP_MOUSE_BASE_DBL+18)
#define MP_MOUSE_BTN19_DBL (MP_MOUSE_BASE_DBL+19)
#define MP_MOUSE_BTN_DBL_END (MP_MOUSE_BASE_DBL+20)
((code) >= MP_MOUSE_BASE && (code) < MP_MOUSE_END)

#define MP_MOUSE_DBL_BASE ((MP_KEY_BASE+0xC0)|MP_NO_REPEAT_KEY)
#define MP_MBTN_LEFT_DBL (MP_MOUSE_DBL_BASE+0)
#define MP_MBTN_MID_DBL (MP_MOUSE_DBL_BASE+1)
#define MP_MBTN_RIGHT_DBL (MP_MOUSE_DBL_BASE+2)
#define MP_MOUSE_DBL_END (MP_MOUSE_DBL_BASE+20)

#define MP_KEY_IS_MOUSE_BTN_DBL(code) \
((code) >= MP_MOUSE_BTN0_DBL && (code) < MP_MOUSE_BTN_DBL_END)
((code) >= MP_MOUSE_DBL_BASE && (code) < MP_MOUSE_DBL_END)

// Apple Remote input module
#define MP_AR_BASE (MP_KEY_BASE+0xE0)
Expand Down
7 changes: 6 additions & 1 deletion player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -5601,7 +5601,12 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
return -1;
}
const bool dbc = cmd->args[3].v.i;
button += dbc ? MP_MOUSE_BASE_DBL : MP_MOUSE_BASE;
if (dbc && button > (MP_MBTN_RIGHT - MP_MOUSE_BASE)) {
MP_ERR(mpctx, "%d is not a valid mouse button for double-clicks.\n",
button);
return -1;
}
button += dbc ? MP_MOUSE_DBL_BASE : MP_MOUSE_BASE;
mp_input_set_mouse_pos_artificial(mpctx->input, x, y);
mp_input_put_key_artificial(mpctx->input, button);
break;
Expand Down
Loading

0 comments on commit 957e9a3

Please sign in to comment.