Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osc.lua: allow adding custom buttons #15517

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/osc-buttons.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ change several OSC mouse bindings to select.lua functions
add script-opts to configure what OSC buttons do when clicked
remove `osc-playlist_osd` script-opt and behave as if it was off by default; `playlist_osd=yes` can be replicated with `osc-playlist_prev_mbtn_left_command=playlist-prev; show-text ${playlist} 3000` and `osc-playlist_next_mbtn_left_command=playlist-next; show-text ${playlist} 3000`
remove `osc-chapters_osd` script-opt and behave as if it was off by default; `chapter_osd=yes` can be replicated with `osc-chapter_prev_mbtn_left_command=no-osd add chapter -1; show-text ${chapter-list} 3000` and `osc-chapter_next_mbtn_left_command=no-osd add chapter 1; show-text ${chapter-list} 3000`
add script-opts to define custom buttons
52 changes: 52 additions & 0 deletions DOCS/man/osc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,58 @@ clicked. ``mbtn_mid`` commands are also triggered with ``shift+mbtn_left``.

``fullscreen_mbtn_right_command="cycle window-maximized"``

``custom_button_1_content=``

``custom_button_1_mbtn_left_command=``

``custom_button_1_mbtn_mid_command=``

``custom_button_1_mbtn_right_command=``

``custom_button_2_content=``

``custom_button_2_mbtn_left_command=``

``custom_button_2_mbtn_mid_command=``

``custom_button_2_mbtn_right_command=``

``custom_button_3_content=``

``custom_button_3_mbtn_left_command=``

``custom_button_3_mbtn_mid_command=``

``custom_button_3_mbtn_right_command=``

``custom_button_4_content=``

``custom_button_4_mbtn_left_command=``

``custom_button_4_mbtn_mid_command=``

``custom_button_4_mbtn_right_command=``

``custom_button_5_content=``

``custom_button_5_mbtn_left_command=``

``custom_button_5_mbtn_mid_command=``

``custom_button_5_mbtn_right_command=``

Custom Buttons
~~~~~~~~~~~~~~

script-opts are available to define up to 5 custom buttons in ``bottombar`` and
``topbar`` layouts.

.. admonition:: Example to add a loop button

custom_button_1_content=🔁
custom_button_1_mbtn_left_command=cycle-values loop-file inf no
custom_button_1_mbtn_right_command=cycle-values loop-playlist inf no

Script Commands
~~~~~~~~~~~~~~~

Expand Down
79 changes: 60 additions & 19 deletions player/lua/osc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ local user_opts = {
fullscreen_mbtn_left_command = "cycle fullscreen",
fullscreen_mbtn_mid_command = "",
fullscreen_mbtn_right_command = "cycle window-maximized",

custom_button_1_content = "",
custom_button_1_mbtn_left_command = "",
custom_button_1_mbtn_mid_command = "",
custom_button_1_mbtn_right_command = "",

custom_button_2_content = "",
custom_button_2_mbtn_left_command = "",
custom_button_2_mbtn_mid_command = "",
custom_button_2_mbtn_right_command = "",

custom_button_3_content = "",
custom_button_3_mbtn_left_command = "",
custom_button_3_mbtn_mid_command = "",
custom_button_3_mbtn_right_command = "",

custom_button_4_content = "",
custom_button_4_mbtn_left_command = "",
custom_button_4_mbtn_mid_command = "",
custom_button_4_mbtn_right_command = "",

custom_button_5_content = "",
custom_button_5_mbtn_left_command = "",
custom_button_5_mbtn_mid_command = "",
custom_button_5_mbtn_right_command = "",
-- luacheck: pop
}

Expand Down Expand Up @@ -451,6 +476,10 @@ local function get_touchtimeout()
return state.touchtime + (get_hidetimeout() / 1000) - mp.get_time()
end

local function cache_enabled()
return state.cache_state and #state.cache_state["seekable-ranges"] > 0
end

local function reset_margins()
if state.using_video_margins then
for _, mopt in ipairs(margins_opts) do
Expand Down Expand Up @@ -1570,15 +1599,28 @@ local function bar_layout(direction)

local t_l = geo.x + geo.w + padX

-- Custom buttons
local t_r = osc_geo.x + osc_geo.w

for i = 5, 1, -1 do
if elements["custom_button_" .. i] then
t_r = t_r - padX
geo = { x = t_r, y = geo.y, an = 6, w = geo.w, h = geo.h }
t_r = t_r - geo.w
lo = add_layout("custom_button_" .. i)
lo.geometry = geo
lo.style = osc_styles.vidtitleBar
end
end

-- Cache
geo = { x = osc_geo.x + osc_geo.w - padX, y = geo.y,
an = 6, w = 150, h = geo.h }
t_r = t_r - padX
geo = { x = t_r, y = geo.y, an = 6, w = 150, h = geo.h }
t_r = t_r - geo.w - padX
lo = add_layout("cache")
lo.geometry = geo
lo.style = osc_styles.vidtitleBar

local t_r = geo.x - geo.w - padX*2

-- Title
geo = { x = t_l, y = geo.y, an = 4,
w = t_r - t_l, h = geo.h }
Expand Down Expand Up @@ -1912,23 +1954,15 @@ local function osc_init()
end
end
ne.slider.seekRangesF = function()
if user_opts.seekrangestyle == "none" then
return nil
end
local cache_state = state.cache_state
if not cache_state then
if user_opts.seekrangestyle == "none" or not cache_enabled() then
return nil
end
local duration = mp.get_property_number("duration")
if duration == nil or duration <= 0 then
return nil
end
local ranges = cache_state["seekable-ranges"]
if #ranges == 0 then
return nil
end
local nranges = {}
for _, range in pairs(ranges) do
for _, range in pairs(state.cache_state["seekable-ranges"]) do
nranges[#nranges + 1] = {
["start"] = 100 * range["start"] / duration,
["end"] = 100 * range["end"] / duration,
Expand Down Expand Up @@ -2035,13 +2069,10 @@ local function osc_init()
ne = new_element("cache", "button")

ne.content = function ()
local cache_state = state.cache_state
if not (cache_state and cache_state["seekable-ranges"] and
#cache_state["seekable-ranges"] > 0) then
-- probably not a network stream
if not cache_enabled() then
return ""
end
local dmx_cache = cache_state and cache_state["cache-duration"]
local dmx_cache = state.cache_state["cache-duration"]
local thresh = math.min(state.dmx_cache * 0.05, 5) -- 5% or 5s
if dmx_cache and math.abs(dmx_cache - state.dmx_cache) >= thresh then
state.dmx_cache = dmx_cache
Expand Down Expand Up @@ -2072,6 +2103,16 @@ local function osc_init()
bind_mouse_buttons("volume")


-- custom buttons
for i = 1, 5 do
if user_opts["custom_button_" .. i .. "_content"] ~= "" then
ne = new_element("custom_button_" .. i, "button")
ne.content = user_opts["custom_button_" .. i .. "_content"]
bind_mouse_buttons("custom_button_" .. i)
end
end


-- load layout
layouts[user_opts.layout]()

Expand Down
Loading