From c66ed396b7242e5c24b94dce340cdf10e19f716a Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 26 Oct 2024 23:12:34 +0200 Subject: [PATCH] osc.lua: cycle tracks when there's only one When there is 1 audio or sub track, make left click select or unselect it directly without opening the selector. The script-opt command is ignored in this case. Requested by sfan5. --- DOCS/man/osc.rst | 3 +++ player/lua/osc.lua | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst index 7f2ff15e81d9e..f4a43bfc39577 100644 --- a/DOCS/man/osc.rst +++ b/DOCS/man/osc.rst @@ -497,6 +497,9 @@ Configurable Options The following options configure what commands are run when the buttons are clicked. ``mbtn_mid`` commands are also triggered with ``shift+mbtn_left``. +When there's only one track of a type, left clicks on track buttons always cycle +it instead of using the configured command. + ``title_mbtn_left_command=script-binding select/select-playlist; script-message-to osc osc-hide`` ``title_mbtn_mid_command=show-text ${filename}`` diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 4a622f91c95c9..63f2e8d464d44 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -1866,7 +1866,9 @@ local function osc_init() return ("\238\132\134" .. osc_styles.smallButtonsLlabel .. " " .. (mp.get_property_native("aid") or "-") .. "/" .. audio_track_count) end - ne.eventresponder["mbtn_left_up"] = command_callback(user_opts.audio_track_mbtn_left_command) + ne.eventresponder["mbtn_left_up"] = command_callback(audio_track_count == 1 + and "cycle audio" + or user_opts.audio_track_mbtn_left_command) ne.eventresponder["shift+mbtn_left_up"] = command_callback( user_opts.audio_track_mbtn_mid_command) ne.eventresponder["mbtn_right_up"] = command_callback(user_opts.audio_track_mbtn_right_command) @@ -1886,7 +1888,9 @@ local function osc_init() return ("\238\132\135" .. osc_styles.smallButtonsLlabel .. " " .. (mp.get_property_native("sid") or "-") .. "/" .. sub_track_count) end - ne.eventresponder["mbtn_left_up"] = command_callback(user_opts.sub_track_mbtn_left_command) + ne.eventresponder["mbtn_left_up"] = command_callback(sub_track_count == 1 + and "cycle sub" + or user_opts.sub_track_mbtn_left_command) ne.eventresponder["shift+mbtn_left_up"] = command_callback(user_opts.sub_track_mbtn_mid_command) ne.eventresponder["mbtn_right_up"] = command_callback(user_opts.sub_track_mbtn_right_command)