Skip to content

Commit

Permalink
osc.lua: add thumbfast integration
Browse files Browse the repository at this point in the history
  • Loading branch information
po5 committed Sep 18, 2022
1 parent 1bf8a0b commit d72b88c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions player/lua/osc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ local state = {
chapter_list = {}, -- sorted by time
}

local thumbfast = {
width = 0,
height = 0,
disabled = false
}

local window_control_box_width = 80
local tick_delay = 0.03

Expand Down Expand Up @@ -832,6 +838,22 @@ function render_elements(master_ass)
ass_append_alpha(elem_ass, slider_lo.alpha, 0)
elem_ass:append(tooltiplabel)

-- thumbnail
if not thumbfast.disabled and thumbfast.width ~= 0 and thumbfast.height ~= 0 then
local osd_w = mp.get_property_number("osd-dimensions/w")
if osd_w then
local r_w, r_h = get_virt_scale_factor()
mp.commandv("script-message-to", "thumbfast", "thumb",
mp.get_property_number("duration", 0) * (sliderpos / 100),
math.min(osd_w - thumbfast.width - 10, math.max(10, tx / r_w - thumbfast.width / 2)),
((ty - (user_opts.layout == "bottombar" and 39 or 18) - user_opts.barmargin) / r_h - (user_opts.layout == "topbar" and -(57 + user_opts.barmargin) / r_h or thumbfast.height))
)
end
end
else
if thumbfast.width ~= 0 and thumbfast.height ~= 0 then
mp.commandv("script-message-to", "thumbfast", "clear")
end
end
end

Expand Down Expand Up @@ -2889,5 +2911,14 @@ mp.add_key_binding(nil, "visibility", function() visibility_mode("cycle") end)

mp.register_script_message("osc-idlescreen", idlescreen_visibility)

mp.register_script_message("thumbfast-info", function(json)
local data = utils.parse_json(json)
if type(data) ~= "table" or not data.width or not data.height then
msg.error("thumbfast-info: received json didn't produce a table with thumbnail information")
else
thumbfast = data
end
end)

set_virt_mouse_area(0, 0, 0, 0, "input")
set_virt_mouse_area(0, 0, 0, 0, "window-controls")

0 comments on commit d72b88c

Please # to comment.