Skip to content

Commit

Permalink
fix: manual pause indicator initializes as static when launched w…
Browse files Browse the repository at this point in the history
…ith `--pause`

Also refactored/simplified PauseIndicator a bit.

closes #743
  • Loading branch information
tomasklaen committed Nov 1, 2023
1 parent b862387 commit 16f61eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/uosc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ time_precision=0
buffered_time_threshold=60
# Hide UI when mpv autohides the cursor
autohide=no
# Can be: none, flash, static, manual (controlled by flash-pause-indicator and decide-pause-indicator commands)
# Can be: flash, static, manual (controlled by flash-pause-indicator and decide-pause-indicator commands)
pause_indicator=flash
# Sizes to list in stream quality menu
stream_quality_options=4320,2160,1440,1080,720,480,360,240,144
Expand Down
28 changes: 10 additions & 18 deletions src/uosc/elements/PauseIndicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,30 @@ function PauseIndicator:init()
Element.init(self, 'pause_indicator', {render_order = 3})
self.ignores_curtain = true
self.paused = state.pause
self.fadeout_requested = false
self.opacity = 0
self.fadeout = false
self:init_options()
self:decide()
end

function PauseIndicator:init_options()
self.base_icon_opacity = options.pause_indicator == 'flash' and 1 or 0.8
self.type = options.pause_indicator
self.is_manual = options.pause_indicator == 'manual'
self:on_prop_pause()
end

function PauseIndicator:flash()
if not self.is_manual and self.type ~= 'flash' then return end
-- can't wait for pause property event listener to set this, because when this is used inside a binding like:
-- Can't wait for pause property event listener to set this, because when this is used inside a binding like:
-- cycle pause; script-binding uosc/flash-pause-indicator
-- the pause event is not fired fast enough, and indicator starts rendering with old icon
-- The pause event is not fired fast enough, and indicator starts rendering with old icon.
self.paused = mp.get_property_native('pause')
if self.is_manual then self.type = 'flash' end
self.opacity = 1
self.fadeout, self.opacity = false, 1
self:tween_property('opacity', 1, 0, 300)
end

-- decides whether static indicator should be visible or not
-- Decides whether static indicator should be visible or not.
function PauseIndicator:decide()
if not self.is_manual and self.type ~= 'static' then return end
self.paused = mp.get_property_native('pause') -- see flash() for why this line is necessary
if self.is_manual then self.type = 'static' end
self.opacity = self.paused and 1 or 0
self.fadeout, self.opacity = self.paused, self.paused and 1 or 0
request_render()

-- Workaround for an mpv race condition bug during pause on windows builds, which causes osd updates to be ignored.
Expand All @@ -47,32 +42,29 @@ end
function PauseIndicator:on_prop_pause()
if Elements:v('timeline', 'pressed') then return end
if options.pause_indicator == 'flash' then
if self.paused == state.pause then return end
self:flash()
if self.paused ~= state.pause then self:flash() end
elseif options.pause_indicator == 'static' then
self:decide()
end
end

function PauseIndicator:on_options()
self:init_options()
self:on_prop_pause()
if self.type == 'flash' then self.opacity = 0 end
end

function PauseIndicator:render()
if self.opacity == 0 then return end

local ass = assdraw.ass_new()
local is_static = self.type == 'static'

-- Background fadeout
if is_static then
if self.fadeout then
ass:rect(0, 0, display.width, display.height, {color = bg, opacity = self.opacity * 0.3})
end

-- Icon
local size = round(math.min(display.width, display.height) * (is_static and 0.20 or 0.15))
local size = round(math.min(display.width, display.height) * (self.fadeout and 0.20 or 0.15))
size = size + size * (1 - self.opacity)

if self.paused then
Expand Down

3 comments on commit 16f61eb

@christoph-heinrich
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that "Workaround for an mpv race condition bug during pause" still necessary? There have been a few commits over the past year that might have made that unnecessary.

@tomasklaen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless if it's needed or not, I don't think it'll hurt to support slightly older mpv versions.

@christoph-heinrich
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but if it's not necessary anymore we can leave a note and then remove it whenever the next mpv release is not supported anymore.

Please sign in to comment.