diff --git a/src/ActivityZone.moon b/src/ActivityZone.moon index 9eaee30..6c900f5 100644 --- a/src/ActivityZone.moon +++ b/src/ActivityZone.moon @@ -15,13 +15,13 @@ class ActivityZone extends Rect @elements\remove element -- bottom-up click propagation does not deal with mouse down/up events. - clickHandler: => + clickHandler: ( button ) => unless @containsPoint Mouse.clickX, Mouse.clickY return for _, element in ipairs @elements -- if clickHandler returns false, the click stops propagating. - if element.clickHandler and not element\clickHandler! + if element.clickHandler and element\clickHandler( button ) == false break activityCheck: ( displayRequested ) => @@ -41,7 +41,7 @@ class ActivityZone extends Rect for id, element in ipairs @elements element\activate nowActive - if clickPending - @clickHandler! + if clickPending != false + @clickHandler clickPending return nowActive diff --git a/src/Chapters.moon b/src/Chapters.moon index 6a8d1ed..6a1edbe 100644 --- a/src/Chapters.moon +++ b/src/Chapters.moon @@ -39,6 +39,32 @@ class Chapters extends BarBase @createMarkers! @animation = Animation 0, 1, @animationDuration, @\animate + clickHandler: ( button ) => + if button == 2 + @seekNearestChapter Mouse.clickX / Window.w + return false + + seekNearestChapter: ( frac ) => + chapters = mp.get_property_native 'chapter-list', { } + if #chapters == 0 + return + + duration = mp.get_property_number( 'duration', 0 ) + time = duration * frac + + -- could make this a bisection ehhhhh + mindist = duration + minidx = #chapters + for idx, chap in ipairs chapters + dist = math.abs chap.time - time + if dist < mindist + mindist = dist + minidx = idx + elseif dist > mindist + break + + mp.set_property_native 'chapter', minidx - 1 + resize: => for i, marker in ipairs @markers marker\resize! diff --git a/src/Mouse.moon b/src/Mouse.moon index 3cc2398..8820101 100644 --- a/src/Mouse.moon +++ b/src/Mouse.moon @@ -15,27 +15,33 @@ class Mouse @x, @y = scaledPosition @ if @dead and (oldX != @x or oldY != @y) @dead = false - if not @dead and @clickPending + if not @dead and @clickPending != false + button = @clickPending @clickPending = false - return true + return button return false - @cacheClick: => + @cacheClick: (button) => if not @dead @clickX, @clickY = scaledPosition @ - @clickPending = true + @clickPending = button else @dead = false -mp.add_key_binding "mouse_btn0", "left-click", -> - Mouse\cacheClick! +mp.add_key_binding 'MBTN_LEFT', 'left-click', -> + Mouse\cacheClick 0 + + +if settings['enable-chapter-seek'] + mp.add_key_binding settings['chapter-seek-button'], 'chapter-seek-click', -> + Mouse\cacheClick 2 mp.observe_property 'fullscreen', 'bool', -> Mouse\update! Mouse.dead = true -mp.add_forced_key_binding "mouse_leave", "mouse-leave", -> +mp.add_forced_key_binding 'mouse_leave', 'mouse-leave', -> Mouse.inWindow = false -mp.add_forced_key_binding "mouse_enter", "mouse-enter", -> +mp.add_forced_key_binding 'mouse_enter', 'mouse-enter', -> Mouse.inWindow = true diff --git a/src/ProgressBar.moon b/src/ProgressBar.moon index adef578..ac67a50 100644 --- a/src/ProgressBar.moon +++ b/src/ProgressBar.moon @@ -15,8 +15,13 @@ class ProgressBar extends BarBase @line[7] = [[]] @line[8] = @line[8]\format settings['bar-foreground-style'] - clickHandler: => - mp.commandv "seek", Mouse.clickX*100/Window.w, seekString + clickHandler: ( button ) => + if button == 0 + @seek Mouse.clickX * 100 / Window.w + return false + + seek: ( percent ) => + mp.commandv 'seek', percent, seekString resize: => super! diff --git a/src/settings.moon b/src/settings.moon index 984efc4..018087b 100644 --- a/src/settings.moon +++ b/src/settings.moon @@ -345,6 +345,20 @@ 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. diff --git a/torque-progressbar.conf b/torque-progressbar.conf index e694062..e1dcc33 100644 --- a/torque-progressbar.conf +++ b/torque-progressbar.conf @@ -245,6 +245,16 @@ pause-indicator-background-style=\c&H2D2D2D& # into this being a problem. enable-chapter-markers=yes +# 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. +enable-chapter-seek=no + +# 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. +chapter-seek-button=MBTN_RIGHT + # Controls the width of each chapter marker when the progress bar is inactive. chapter-marker-width=2