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
2add script-opts to configure what OSC buttons do when clicked2add script-opts to configure what OSC buttons do when clicked
3remove `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`3remove `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`
4remove `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`4remove `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`
5add 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
578 578
579``fullscreen_mbtn_right_command="cycle window-maximized"``579``fullscreen_mbtn_right_command="cycle window-maximized"``
580 580
581Custom Buttons
582~~~~~~~~~~~~~~
583
584Additional script-opts are available to define custom buttons in ``bottombar``
585and ``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
581Script Commands596Script Commands
582~~~~~~~~~~~~~~~597~~~~~~~~~~~~~~~
583 598
player/lua/osc.lua+36−4
@@ -119,6 +119,13 @@ local user_opts = { · 118 unmodified lines
119 -- luacheck: pop119 -- luacheck: pop
120}120}
121 121
122for 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"] = ""
127end
128
122local osc_param = { -- calculated by osc_init()129local osc_param = { -- calculated by osc_init()
123 playresy = 0, -- canvas size Y130 playresy = 0, -- canvas size Y
124 playresx = 0, -- canvas size X131 playresx = 0, -- canvas size X
@@ -144,6 +151,7 @@ local window_control_box_width = 80 · 19 unmodified lines
144local layouts = {}151local layouts = {}
145local is_december = os.date("*t").month == 12152local is_december = os.date("*t").month == 12
146local UNICODE_MINUS = string.char(0xe2, 0x88, 0x92) -- UTF-8 for U+2212 MINUS SIGN153local UNICODE_MINUS = string.char(0xe2, 0x88, 0x92) -- UTF-8 for U+2212 MINUS SIGN
154local last_custom_button = 0
147 155
148local function osc_color_convert(color)156local function osc_color_convert(color)
149 return color:sub(6,7) .. color:sub(4,5) .. color:sub(2,3)157 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
1574 1582
1575 local t_l = geo.x + geo.w + padX1583 local t_l = geo.x + geo.w + padX
1576 1584
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
1577 -- Cache1597 -- Cache
1578 geo = { x = osc_geo.x + osc_geo.w - padX, y = geo.y,1598 t_r = t_r - padX
1579 an = 6, w = 150, h = geo.h }1599 geo = { x = t_r, y = geo.y, an = 6, w = 150, h = geo.h }
1600 t_r = t_r - geo.w - padX
1580 lo = add_layout("cache")1601 lo = add_layout("cache")
1581 lo.geometry = geo1602 lo.geometry = geo
1582 lo.style = osc_styles.vidtitleBar1603 lo.style = osc_styles.vidtitleBar
1583 1604
1584 local t_r = geo.x - geo.w - padX*2
1585
1586 -- Title1605 -- Title
1587 geo = { x = t_l, y = geo.y, an = 4,1606 geo = { x = t_l, y = geo.y, an = 4,
1588 w = t_r - t_l, h = geo.h }1607 w = t_r - t_l, h = geo.h }
@@ -2065,6 +2084,19 @@ local function osc_init() · 476 unmodified lines
2065 bind_mouse_buttons("volume")2084 bind_mouse_buttons("volume")
2066 2085
2067 2086
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
2068 -- load layout2100 -- load layout
2069 layouts[user_opts.layout]()2101 layouts[user_opts.layout]()
2070 2102

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