History

osc.lua: allow adding custom buttons

Guido Cella committed 1 year ago

Commit 2e1bc3c1 parent 9db941f3 files · +52 −4Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/osc-buttons.txt +1 −0
  2. DOCS/man/osc.rst +15 −0
  3. player/lua/osc.lua +36 −4
DOCS/interface-changes/osc-buttons.txt+1−0
@@ -2,3 +2,4 @@ change several OSC mouse bindings to select.lua functions · 1 unmodified line
22 add script-opts to configure what OSC buttons do when clicked
33 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`
44 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`
5+add script-opts to define custom buttons
DOCS/man/osc.rst+15−0
@@ -578,6 +578,21 @@ clicked. ``mbtn_mid`` commands are also triggered with ``shift+mbtn_left``. · 577 unmodified lines
578578
579579 ``fullscreen_mbtn_right_command="cycle window-maximized"``
580580
581+Custom Buttons
582+~~~~~~~~~~~~~~
583+
584+Additional script-opts are available to define custom buttons in ``bottombar``
585+and ``topbar`` layouts.
586+
587+.. admonition:: Example to add loop and shuffle buttons
588+
589+ custom_button_1_content=🔁
590+ custom_button_1_mbtn_left_command=cycle-values loop-file inf no
591+ custom_button_1_mbtn_right_command=cycle-values loop-playlist inf no
592+
593+ custom_button_2_content=🔀
594+ custom_button_2_mbtn_left_command=playlist-shuffle
595+
581596 Script Commands
582597 ~~~~~~~~~~~~~~~
583598
player/lua/osc.lua+36−4
@@ -119,6 +119,13 @@ local user_opts = { · 118 unmodified lines
119119 -- luacheck: pop
120120 }
121121
122+for i = 1, 99 do
123+ user_opts["custom_button_" .. i .. "_content"] = ""
124+ user_opts["custom_button_" .. i .. "_mbtn_left_command"] = ""
125+ user_opts["custom_button_" .. i .. "_mbtn_mid_command"] = ""
126+ user_opts["custom_button_" .. i .. "_mbtn_right_command"] = ""
127+end
128+
122129 local osc_param = { -- calculated by osc_init()
123130 playresy = 0, -- canvas size Y
124131 playresx = 0, -- canvas size X
@@ -144,6 +151,7 @@ local window_control_box_width = 80 · 19 unmodified lines
144151 local layouts = {}
145152 local is_december = os.date("*t").month == 12
146153 local UNICODE_MINUS = string.char(0xe2, 0x88, 0x92) -- UTF-8 for U+2212 MINUS SIGN
154+local last_custom_button = 0
147155
148156 local function osc_color_convert(color)
149157 return color:sub(6,7) .. color:sub(4,5) .. color:sub(2,3)
@@ -1574,15 +1582,26 @@ local function bar_layout(direction) · 1424 unmodified lines
15741582
15751583 local t_l = geo.x + geo.w + padX
15761584
1585+ -- Custom buttons
1586+ local t_r = osc_geo.x + osc_geo.w
1587+
1588+ for i = last_custom_button, 1, -1 do
1589+ t_r = t_r - padX
1590+ geo = { x = t_r, y = geo.y, an = 6, w = geo.w, h = geo.h }
1591+ t_r = t_r - geo.w
1592+ lo = add_layout("custom_button_" .. i)
1593+ lo.geometry = geo
1594+ lo.style = osc_styles.vidtitleBar
1595+ end
1596+
15771597 -- Cache
1578− geo = { x = osc_geo.x + osc_geo.w - padX, y = geo.y,
1579− an = 6, w = 150, h = geo.h }
1598+ t_r = t_r - padX
1599+ geo = { x = t_r, y = geo.y, an = 6, w = 150, h = geo.h }
1600+ t_r = t_r - geo.w - padX
15801601 lo = add_layout("cache")
15811602 lo.geometry = geo
15821603 lo.style = osc_styles.vidtitleBar
15831604
1584− local t_r = geo.x - geo.w - padX*2
1585−
15861605 -- Title
15871606 geo = { x = t_l, y = geo.y, an = 4,
15881607 w = t_r - t_l, h = geo.h }
@@ -2065,6 +2084,19 @@ local function osc_init() · 476 unmodified lines
20652084 bind_mouse_buttons("volume")
20662085
20672086
2087+ -- custom buttons
2088+ for i = 1, math.huge do
2089+ local content = user_opts["custom_button_" .. i .. "_content"]
2090+ if not content or content == "" then
2091+ break
2092+ end
2093+ ne = new_element("custom_button_" .. i, "button")
2094+ ne.content = content
2095+ bind_mouse_buttons("custom_button_" .. i)
2096+ last_custom_button = i
2097+ end
2098+
2099+
20682100 -- load layout
20692101 layouts[user_opts.layout]()
20702102

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t