mirror of
https://github.com/mpv-player/mpv.git
synced 2026-05-07 20:02:49 +00:00
osc.lua: make window control buttons action customizable
Use bind_mouse_buttons helper. This makes it possible to bind custom actions, such as right click X button to quit with watch later.
This commit is contained in:
@@ -1 +1,2 @@
|
||||
add `skip_{backward,forward}_mbtn_*_down_command` script-opt for osc
|
||||
add `{close,minimize,maximize}_mbtn_*_command` script-opt for osc
|
||||
|
||||
@@ -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
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
+47
-45
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user