Skip to content

Commit

Permalink
osc.lua: allow adding custom buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
guidocella committed Dec 14, 2024
1 parent d4a1199 commit 18db7f6
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 4 deletions.
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
56 changes: 52 additions & 4 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 @@ -1574,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 @@ -2065,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

0 comments on commit 18db7f6

Please sign in to comment.