Skip to content

Commit

Permalink
Update build.
Browse files Browse the repository at this point in the history
  • Loading branch information
torque committed Jun 19, 2024
1 parent 695ccb4 commit 00759cb
Showing 1 changed file with 62 additions and 14 deletions.
76 changes: 62 additions & 14 deletions progressbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ the way the chapter markers are currently implemented, videos with a large
number of chapters may slow down the script somewhat, but I have yet to run
into this being a problem.
]]
settings['enable-chapter-seek'] = false
helpText['enable-chapter-seek'] = [[If enabled and the item being played back has chapters, using the
`chapter-seek-button` while the progress bar is hovered will seek the video to
the chapter that is closest to the mouse cursor's position.
]]
settings['chapter-seek-button'] = 'MBTN_RIGHT'
helpText['chapter-seek-button'] = [[The button to register for chapter seeking, if enabled. Since chapter seeking
is based on the mouse position, this should probably be bound to a mouse button,
but it doesn't have to be.
]]
settings['chapter-marker-width'] = 2
helpText['chapter-marker-width'] = [[Controls the width of each chapter marker when the progress bar is inactive.
]]
Expand Down Expand Up @@ -706,33 +716,39 @@ do
if self.dead and (oldX ~= self.x or oldY ~= self.y) then
self.dead = false
end
if not self.dead and self.clickPending then
if not self.dead and self.clickPending ~= false then
local button = self.clickPending
self.clickPending = false
return true
return button
end
return false
end
self.cacheClick = function(self)
self.cacheClick = function(self, button)
if not self.dead then
self.clickX, self.clickY = scaledPosition(self)
self.clickPending = true
self.clickPending = button
else
self.dead = false
end
end
Mouse = _class_0
end
mp.add_key_binding("mouse_btn0", "left-click", function()
return Mouse:cacheClick()
mp.add_key_binding('MBTN_LEFT', 'left-click', function()
return Mouse:cacheClick(0)
end)
if settings['enable-chapter-seek'] then
mp.add_key_binding(settings['chapter-seek-button'], 'chapter-seek-click', function()
return Mouse:cacheClick(2)
end)
end
mp.observe_property('fullscreen', 'bool', function()
Mouse:update()
Mouse.dead = true
end)
mp.add_forced_key_binding("mouse_leave", "mouse-leave", function()
mp.add_forced_key_binding('mouse_leave', 'mouse-leave', function()
Mouse.inWindow = false
end)
mp.add_forced_key_binding("mouse_enter", "mouse-enter", function()
mp.add_forced_key_binding('mouse_enter', 'mouse-enter', function()
Mouse.inWindow = true
end)
local Rect
Expand Down Expand Up @@ -820,12 +836,12 @@ do
removeUIElement = function(self, element)
return self.elements:remove(element)
end,
clickHandler = function(self)
clickHandler = function(self, button)
if not (self:containsPoint(Mouse.clickX, Mouse.clickY)) then
return
end
for _, element in ipairs(self.elements) do
if element.clickHandler and not element:clickHandler() then
if element.clickHandler and element:clickHandler(button) == false then
break
end
end
Expand All @@ -850,8 +866,8 @@ do
element:activate(nowActive)
end
end
if clickPending then
self:clickHandler()
if clickPending ~= false then
self:clickHandler(clickPending)
end
return nowActive
end
Expand Down Expand Up @@ -1418,8 +1434,14 @@ do
self.line[7] = [[]]
self.line[8] = self.line[8]:format(settings['bar-foreground-style'])
end,
clickHandler = function(self)
return mp.commandv("seek", Mouse.clickX * 100 / Window.w, seekString)
clickHandler = function(self, button)
if button == 0 then
self:seek(Mouse.clickX * 100 / Window.w)
return false
end
end,
seek = function(self, percent)
return mp.commandv('seek', percent, seekString)
end,
resize = function(self)
_class_0.__parent.__base.resize(self)
Expand Down Expand Up @@ -1775,6 +1797,32 @@ do
end
end)())
end,
clickHandler = function(self, button)
if button == 2 then
self:seekNearestChapter(Mouse.clickX / Window.w)
return false
end
end,
seekNearestChapter = function(self, frac)
local chapters = mp.get_property_native('chapter-list', { })
if #chapters == 0 then
return
end
local duration = mp.get_property_number('duration', 0)
local time = duration * frac
local mindist = duration
local minidx = #chapters
for idx, chap in ipairs(chapters) do
local dist = math.abs(chap.time - time)
if dist < mindist then
mindist = dist
minidx = idx
elseif dist > mindist then
break
end
end
return mp.set_property_native('chapter', minidx - 1)
end,
resize = function(self)
for i, marker in ipairs(self.markers) do
marker:resize()
Expand Down

0 comments on commit 00759cb

Please sign in to comment.