From 957e9a37db6611fe0879bd2097131df5e09afd47 Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Tue, 8 Aug 2017 21:34:38 +1000 Subject: input: use mnemonic names for mouse buttons 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 --- player/command.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'player/command.c') diff --git a/player/command.c b/player/command.c index 184d7d51d2..6056fb8d8c 100644 --- a/player/command.c +++ b/player/command.c @@ -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; -- cgit v1.2.3