diff --git a/DOCS/interface-changes/osc-down.txt b/DOCS/interface-changes/osc-down.txt index 2b5dd5e9c0..8577bc9e87 100644 --- a/DOCS/interface-changes/osc-down.txt +++ b/DOCS/interface-changes/osc-down.txt @@ -1 +1,2 @@ add `skip_{backward,forward}_mbtn_*_down_command` script-opt for osc +add `{close,minimize,maximize}_mbtn_*_command` script-opt for osc diff --git a/DOCS/man/osc.rst b/DOCS/man/osc.rst index ca00869714..696f06ff90 100644 --- a/DOCS/man/osc.rst +++ b/DOCS/man/osc.rst @@ -687,6 +687,24 @@ continuously called while the mouse button is held down. ``skip_forward_mbtn_right_down_command=seek 60`` +``close_mbtn_left_command=quit`` + +``close_mbtn_mid_command=`` + +``close_mbtn_right_command=`` + +``minimize_mbtn_left_command=cycle window-minimized`` + +``minimize_mbtn_mid_command=`` + +``minimize_mbtn_right_command=`` + +``maximize_mbtn_left_command=cycle ${?fullscreen==yes:fullscreen}${!fullscreen==yes:window-maximized}`` + +``maximize_mbtn_mid_command=`` + +``maximize_mbtn_right_command=`` + Custom Buttons ~~~~~~~~~~~~~~ diff --git a/player/lua/osc.lua b/player/lua/osc.lua index e57fccf062..e5464ea10e 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -140,6 +140,18 @@ local user_opts = { skip_forward_mbtn_left_down_command = "seek 10", skip_forward_mbtn_mid_down_command = "frame-step", skip_forward_mbtn_right_down_command = "seek 60", + + close_mbtn_left_command = "quit", + close_mbtn_mid_command = "", + close_mbtn_right_command = "", + + minimize_mbtn_left_command = "cycle window-minimized", + minimize_mbtn_mid_command = "", + minimize_mbtn_right_command = "", + + maximize_mbtn_left_command = "cycle ${?fullscreen==yes:fullscreen}${!fullscreen==yes:window-maximized}", + maximize_mbtn_mid_command = "", + maximize_mbtn_right_command = "", -- luacheck: pop } @@ -1352,6 +1364,38 @@ local function add_layout(name) end end +local function bind_mouse_buttons(element_name) + for _, button in pairs({"mbtn_left", "mbtn_mid", "mbtn_right"}) do + local up_command = user_opts[element_name .. "_" .. button .. "_command"] + + if up_command and up_command ~= "" then + elements[element_name].eventresponder[button .. "_up"] = function () + mp.command(up_command) + end + end + + local down_command = user_opts[element_name .. "_" .. button .. "_down_command"] + + if down_command and down_command ~= "" then + elements[element_name].eventresponder[button .. "_down"] = function () + mp.command(down_command) + end + end + end + + if user_opts.scrollcontrols then + for _, button in pairs({"wheel_down", "wheel_up"}) do + local command = user_opts[element_name .. "_" .. button .. "_command"] + + if command and command ~= "" then + elements[element_name].eventresponder[button .. "_press"] = function () + mp.command(command) + end + end + end + end +end + -- Window Controls local function window_controls(topbar) local wc_geo = { @@ -1438,8 +1482,7 @@ local function window_controls(topbar) ne = new_element("close", "button") ne.is_wc = true ne.content = icons.close - ne.eventresponder["mbtn_left_up"] = - function () mp.commandv("quit") end + bind_mouse_buttons("close") lo = add_layout("close") lo.geometry = alignment == "left" and first_geo or third_geo lo.style = osc_styles.wcButtons @@ -1451,8 +1494,7 @@ local function window_controls(topbar) ne = new_element("minimize", "button") ne.is_wc = true ne.content = icons.minimize - ne.eventresponder["mbtn_left_up"] = - function () mp.commandv("cycle", "window-minimized") end + bind_mouse_buttons("minimize") lo = add_layout("minimize") lo.geometry = alignment == "left" and second_geo or first_geo lo.style = osc_styles.wcButtons @@ -1465,14 +1507,7 @@ local function window_controls(topbar) else ne.content = icons.maximize end - ne.eventresponder["mbtn_left_up"] = - function () - if state.fullscreen then - mp.commandv("cycle", "fullscreen") - else - mp.commandv("cycle", "window-maximized") - end - end + bind_mouse_buttons("maximize") lo = add_layout("maximize") lo.geometry = alignment == "left" and third_geo or second_geo lo.style = osc_styles.wcButtons @@ -2271,39 +2306,6 @@ layouts["floating"] = function () lo.style = osc_styles.floatingButtons end - -local function bind_mouse_buttons(element_name) - for _, button in pairs({"mbtn_left", "mbtn_mid", "mbtn_right"}) do - local up_command = user_opts[element_name .. "_" .. button .. "_command"] - - if up_command and up_command ~= "" then - elements[element_name].eventresponder[button .. "_up"] = function () - mp.command(up_command) - end - end - - local down_command = user_opts[element_name .. "_" .. button .. "_down_command"] - - if down_command and down_command ~= "" then - elements[element_name].eventresponder[button .. "_down"] = function () - mp.command(down_command) - end - end - end - - if user_opts.scrollcontrols then - for _, button in pairs({"wheel_down", "wheel_up"}) do - local command = user_opts[element_name .. "_" .. button .. "_command"] - - if command and command ~= "" then - elements[element_name].eventresponder[button .. "_press"] = function () - mp.command(command) - end - end - end - end -end - local function to_fraction(num, den) local sup = {['0']='\226\129\176',['1']='\194\185', ['2']='\194\178', ['3']='\194\179', ['4']='\226\129\180',['5']='\226\129\181',