From a576f7a9c103946e6c85275b0ad6009d9406ef71 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 26 Oct 2024 22:25:47 +0200 Subject: [PATCH] osc.lua: cycle tracks when there's only one When there is 1 audio or sub track, if the command wasn't configured, make left click select or unselect it directly without opening the selector. Unfortunately this is awkward to implement with the command script-opts. Requested by sfan5. --- player/lua/osc.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 4a622f91c95c9..e6e8f5a3e6e8c 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -2,6 +2,9 @@ local assdraw = require 'mp.assdraw' local msg = require 'mp.msg' local opt = require 'mp.options' +local default_audio_command = "script-binding select/select-aid; script-message-to osc osc-hide" +local default_sub_command = "script-binding select/select-sid; script-message-to osc osc-hide" + -- -- Parameters -- @@ -94,13 +97,13 @@ local user_opts = { chapter_next_mbtn_mid_command = "show-text ${chapter-list} 3000", chapter_next_mbtn_right_command = "script-binding select/select-chapter; script-message-to osc osc-hide", - audio_track_mbtn_left_command = "script-binding select/select-aid; script-message-to osc osc-hide", + audio_track_mbtn_left_command = default_audio_command, audio_track_mbtn_mid_command = "show-text ${track-list/audio} 3000", audio_track_mbtn_right_command = "show-text ${track-list/audio} 3000", audio_track_wheel_down_command = "cycle audio", audio_track_wheel_up_command = "cycle audio down", - sub_track_mbtn_left_command = "script-binding select/select-sid; script-message-to osc osc-hide", + sub_track_mbtn_left_command = default_sub_command, sub_track_mbtn_mid_command = "show-text ${track-list/sub} 3000", sub_track_mbtn_right_command = "show-text ${track-list/sub} 3000", sub_track_wheel_down_command = "cycle sub", @@ -1866,7 +1869,12 @@ 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) + if audio_track_count == 1 and + user_opts.audio_track_mbtn_left_command == default_audio_command then + ne.eventresponder["mbtn_left_up"] = command_callback("cycle audio") + else + ne.eventresponder["mbtn_left_up"] = command_callback(user_opts.audio_track_mbtn_left_command) + end 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 +1894,11 @@ 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) + if sub_track_count == 1 and user_opts.sub_track_mbtn_left_command == default_sub_command then + ne.eventresponder["mbtn_left_up"] = command_callback("cycle sub") + else + ne.eventresponder["mbtn_left_up"] = command_callback(user_opts.sub_track_mbtn_left_command) + end 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)