diff options
author | James Ross-Gowan <rossy@jrg.systems> | 2017-08-08 21:34:38 +1000 |
---|---|---|
committer | James Ross-Gowan <rossy@jrg.systems> | 2017-09-03 20:31:44 +1000 |
commit | 957e9a37db6611fe0879bd2097131df5e09afd47 (patch) | |
tree | b346371417acd0476a60e2c1ecde20c8548d14ba /player | |
parent | 449d9725c91af467b154817dfd0603d80ba7f00b (diff) | |
download | mpv-957e9a37db6611fe0879bd2097131df5e09afd47.tar.bz2 mpv-957e9a37db6611fe0879bd2097131df5e09afd47.tar.xz |
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
Diffstat (limited to 'player')
-rw-r--r-- | player/command.c | 7 | ||||
-rw-r--r-- | player/lua/osc.lua | 96 |
2 files changed, 54 insertions, 49 deletions
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; diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 4169634ff8..1359260521 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -1000,7 +1000,7 @@ layouts["box"] = function () lo.style = osc_styles.smallButtonsR lo = add_layout("volume") - lo.geometry = + lo.geometry = {x = posX+pos_offsetX - (25 * 2) - osc_geo.p, y = bigbtnrowY, an = 4, w = 25, h = 25} lo.style = osc_styles.smallButtonsR @@ -1550,7 +1550,7 @@ function osc_init() return not (title == "") and title or "mpv" end - ne.eventresponder["mouse_btn0_up"] = function () + ne.eventresponder["mbtn_left_up"] = function () local title = mp.get_property_osd("media-title") if (have_pl) then title = string.format("[%d/%d] %s", countone(pl_pos - 1), @@ -1559,7 +1559,7 @@ function osc_init() show_message(title) end - ne.eventresponder["mouse_btn2_up"] = + ne.eventresponder["mbtn_right_up"] = function () show_message(mp.get_property_osd("filename")) end -- playlist buttons @@ -1569,14 +1569,14 @@ function osc_init() ne.content = "\238\132\144" ne.enabled = (pl_pos > 1) or (loop ~= "no") - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () mp.commandv("playlist-prev", "weak") show_message(get_playlist(), 3) end - ne.eventresponder["shift+mouse_btn0_up"] = + ne.eventresponder["shift+mbtn_left_up"] = function () show_message(get_playlist(), 3) end - ne.eventresponder["mouse_btn2_up"] = + ne.eventresponder["mbtn_right_up"] = function () show_message(get_playlist(), 3) end --next @@ -1584,14 +1584,14 @@ function osc_init() ne.content = "\238\132\129" ne.enabled = (have_pl and (pl_pos < pl_count)) or (loop ~= "no") - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () mp.commandv("playlist-next", "weak") show_message(get_playlist(), 3) end - ne.eventresponder["shift+mouse_btn0_up"] = + ne.eventresponder["shift+mbtn_left_up"] = function () show_message(get_playlist(), 3) end - ne.eventresponder["mouse_btn2_up"] = + ne.eventresponder["mbtn_right_up"] = function () show_message(get_playlist(), 3) end @@ -1607,7 +1607,7 @@ function osc_init() return ("\238\128\130") end end - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () mp.commandv("cycle", "pause") end --skipback @@ -1615,11 +1615,11 @@ function osc_init() ne.softrepeat = true ne.content = "\238\128\132" - ne.eventresponder["mouse_btn0_down"] = + ne.eventresponder["mbtn_left_down"] = function () mp.commandv("seek", -5, "relative", "keyframes") end - ne.eventresponder["shift+mouse_btn0_down"] = + ne.eventresponder["shift+mbtn_left_down"] = function () mp.commandv("frame-back-step") end - ne.eventresponder["mouse_btn2_down"] = + ne.eventresponder["mbtn_right_down"] = function () mp.commandv("seek", -30, "relative", "keyframes") end --skipfrwd @@ -1627,11 +1627,11 @@ function osc_init() ne.softrepeat = true ne.content = "\238\128\133" - ne.eventresponder["mouse_btn0_down"] = + ne.eventresponder["mbtn_left_down"] = function () mp.commandv("seek", 10, "relative", "keyframes") end - ne.eventresponder["shift+mouse_btn0_down"] = + ne.eventresponder["shift+mbtn_left_down"] = function () mp.commandv("frame-step") end - ne.eventresponder["mouse_btn2_down"] = + ne.eventresponder["mbtn_right_down"] = function () mp.commandv("seek", 60, "relative", "keyframes") end --ch_prev @@ -1639,14 +1639,14 @@ function osc_init() ne.enabled = have_ch ne.content = "\238\132\132" - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () mp.commandv("add", "chapter", -1) show_message(get_chapterlist(), 3) end - ne.eventresponder["shift+mouse_btn0_up"] = + ne.eventresponder["shift+mbtn_left_up"] = function () show_message(get_chapterlist(), 3) end - ne.eventresponder["mouse_btn2_up"] = + ne.eventresponder["mbtn_right_up"] = function () show_message(get_chapterlist(), 3) end --ch_next @@ -1654,14 +1654,14 @@ function osc_init() ne.enabled = have_ch ne.content = "\238\132\133" - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () mp.commandv("add", "chapter", 1) show_message(get_chapterlist(), 3) end - ne.eventresponder["shift+mouse_btn0_up"] = + ne.eventresponder["shift+mbtn_left_up"] = function () show_message(get_chapterlist(), 3) end - ne.eventresponder["mouse_btn2_up"] = + ne.eventresponder["mbtn_right_up"] = function () show_message(get_chapterlist(), 3) end -- @@ -1679,11 +1679,11 @@ function osc_init() return ("\238\132\134" .. osc_styles.smallButtonsLlabel .. " " .. aid .. "/" .. #tracks_osc.audio) end - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () set_track("audio", 1) end - ne.eventresponder["mouse_btn2_up"] = + ne.eventresponder["mbtn_right_up"] = function () set_track("audio", -1) end - ne.eventresponder["shift+mouse_btn0_down"] = + ne.eventresponder["shift+mbtn_left_down"] = function () show_message(get_tracklist("audio"), 2) end --cy_sub @@ -1698,11 +1698,11 @@ function osc_init() return ("\238\132\135" .. osc_styles.smallButtonsLlabel .. " " .. sid .. "/" .. #tracks_osc.sub) end - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () set_track("sub", 1) end - ne.eventresponder["mouse_btn2_up"] = + ne.eventresponder["mbtn_right_up"] = function () set_track("sub", -1) end - ne.eventresponder["shift+mouse_btn0_down"] = + ne.eventresponder["shift+mbtn_left_down"] = function () show_message(get_tracklist("sub"), 2) end --tog_fs @@ -1714,7 +1714,7 @@ function osc_init() return ("\238\132\136") end end - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () mp.commandv("cycle", "fullscreen") end @@ -1760,7 +1760,7 @@ function osc_init() end end - ne.eventresponder["mouse_btn0_down"] = --exact seeks on single clicks + ne.eventresponder["mbtn_left_down"] = --exact seeks on single clicks function (element) mp.commandv("seek", get_slider_value(element), "absolute-percent", "exact") end ne.eventresponder["reset"] = @@ -1777,7 +1777,7 @@ function osc_init() return (mp.get_property_osd("playback-time")) end end - ne.eventresponder["mouse_btn0_up"] = function () + ne.eventresponder["mbtn_left_up"] = function () state.tc_ms = not state.tc_ms request_init() end @@ -1801,7 +1801,7 @@ function osc_init() end end end - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () state.rightTC_trem = not state.rightTC_trem end -- cache @@ -1848,12 +1848,12 @@ function osc_init() return volicon[math.min(4,math.ceil(volume / (100/3)))] end end - ne.eventresponder["mouse_btn0_up"] = + ne.eventresponder["mbtn_left_up"] = function () mp.commandv("cycle", "mute") end - ne.eventresponder["mouse_wheel_up_press"] = + ne.eventresponder["wheel_up_press"] = function () mp.commandv("osd-auto", "add", "volume", 5) end - ne.eventresponder["mouse_wheel_down_press"] = + ne.eventresponder["wheel_down_press"] = function () mp.commandv("osd-auto", "add", "volume", -5) end @@ -2296,19 +2296,19 @@ do_enable_keybindings() --mouse input bindings mp.set_key_bindings({ - {"mouse_btn0", function(e) process_event("mouse_btn0", "up") end, - function(e) process_event("mouse_btn0", "down") end}, - {"shift+mouse_btn0", function(e) process_event("shift+mouse_btn0", "up") end, - function(e) process_event("shift+mouse_btn0", "down") end}, - {"mouse_btn2", function(e) process_event("mouse_btn2", "up") end, - function(e) process_event("mouse_btn2", "down") end}, - {"mouse_btn3", function(e) process_event("mouse_wheel_up", "press") end}, - {"mouse_btn4", function(e) process_event("mouse_wheel_down", "press") end}, - {"axis_up", function(e) process_event("mouse_wheel_up", "press") end}, - {"axis_down", function(e) process_event("mouse_wheel_down", "press") end}, - {"mouse_btn0_dbl", "ignore"}, - {"shift+mouse_btn0_dbl", "ignore"}, - {"mouse_btn2_dbl", "ignore"}, + {"mbtn_left", function(e) process_event("mbtn_left", "up") end, + function(e) process_event("mbtn_left", "down") end}, + {"shift+mbtn_left", function(e) process_event("shift+mbtn_left", "up") end, + function(e) process_event("shift+mbtn_left", "down") end}, + {"mbtn_right", function(e) process_event("mbtn_right", "up") end, + function(e) process_event("mbtn_right", "down") end}, + {"wheel_up", function(e) process_event("wheel_up", "press") end}, + {"wheel_down", function(e) process_event("wheel_down", "press") end}, + {"axis_up", function(e) process_event("wheel_up", "press") end}, + {"axis_down", function(e) process_event("wheel_down", "press") end}, + {"mbtn_left_dbl", "ignore"}, + {"shift+mbtn_left_dbl", "ignore"}, + {"mbtn_right_dbl", "ignore"}, }, "input", "force") mp.enable_key_bindings("input") |