Skip to content

Commit

Permalink
fix: click threshold not working when any clickable element is visible (
Browse files Browse the repository at this point in the history
#831)

This moves click threshold handling to cursor zones, which have been reworked a bit.

Resolves #820
  • Loading branch information
tomasklaen authored Feb 6, 2024
1 parent dc73278 commit 4a4d056
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 104 deletions.
4 changes: 2 additions & 2 deletions src/uosc/elements/Button.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Button:init(id, props)
end

function Button:on_coordinates() self.font_size = round((self.by - self.ay) * 0.7) end
function Button:handle_cursor_down()
function Button:handle_cursor_click()
-- We delay the callback to next tick, otherwise we are risking race
-- conditions as we are in the middle of event dispatching.
-- For example, handler might add a menu to the end of the element stack, and that
Expand All @@ -34,7 +34,7 @@ end
function Button:render()
local visibility = self:get_visibility()
if visibility <= 0 then return end
cursor:zone('primary_down', self, function() self:handle_cursor_down() end)
cursor:zone('primary_click', self, function() self:handle_cursor_click() end)

local ass = assdraw.ass_new()
local is_hover = self.proximity_raw == 0
Expand Down
2 changes: 1 addition & 1 deletion src/uosc/elements/Speed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function Speed:render()
self:handle_cursor_down()
cursor:once('primary_up', function() self:handle_cursor_up() end)
end)
cursor:zone('secondary_down', self, function() mp.set_property_native('speed', 1) end)
cursor:zone('secondary_click', self, function() mp.set_property_native('speed', 1) end)
cursor:zone('wheel_down', self, function() self:handle_wheel_down() end)
cursor:zone('wheel_up', self, function() self:handle_wheel_up() end)

Expand Down
10 changes: 5 additions & 5 deletions src/uosc/elements/TopBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function TopBarButton:init(id, props)
self.command = props.command
end

function TopBarButton:handle_cursor_down()
function TopBarButton:handle_click()
mp.command(type(self.command) == 'function' and self.command() or self.command)
end

Expand All @@ -29,7 +29,7 @@ function TopBarButton:render()
if self.proximity_raw == 0 then
ass:rect(self.ax, self.ay, self.bx, self.by, {color = self.background, opacity = visibility})
end
cursor:zone('primary_down', self, function() self:handle_cursor_down() end)
cursor:zone('primary_click', self, function() self:handle_click() end)

local width, height = self.bx - self.ax, self.by - self.ay
local icon_size = math.min(width, height) * 0.5
Expand Down Expand Up @@ -231,7 +231,7 @@ function TopBar:render()
title_ax = rect.bx + bg_margin

-- Click action
cursor:zone('primary_down', rect, function() mp.command('script-binding uosc/playlist') end)
cursor:zone('primary_click', rect, function() mp.command('script-binding uosc/playlist') end)
end

-- Skip rendering titles if there's not enough horizontal space
Expand All @@ -253,7 +253,7 @@ function TopBar:render()
local title_rect = {ax = title_ax, ay = title_ay, bx = bx, by = by}

if options.top_bar_alt_title_place == 'toggle' then
cursor:zone('primary_down', title_rect, function() self:toggle_title() end)
cursor:zone('primary_click', title_rect, function() self:toggle_title() end)
end

ass:rect(title_rect.ax, title_rect.ay, title_rect.bx, title_rect.by, {
Expand Down Expand Up @@ -324,7 +324,7 @@ function TopBar:render()
ass:txt(rect.ax + padding, rect.ay + height / 2, 4, text, opts)

-- Click action
cursor:zone('primary_down', rect, function() mp.command('script-binding uosc/chapters') end)
cursor:zone('primary_click', rect, function() mp.command('script-binding uosc/chapters') end)

-- Time
rect.ax = rect.bx + spacing
Expand Down
2 changes: 1 addition & 1 deletion src/uosc/elements/Updater.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function Updater:render()
local y = round(button_rect.ay + (button_rect.by - button_rect.ay) / 2)
ass:icon(x, y, icon_size * 0.8, 'close', {color = bg})

cursor:zone('primary_down', button_rect, function() self:destroy() end)
cursor:zone('primary_click', button_rect, function() self:destroy() end)
end

return ass
Expand Down
4 changes: 2 additions & 2 deletions src/uosc/elements/Volume.lua
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ function Volume:render()
if visibility <= 0 then return end

-- Reset volume on secondary click
cursor:zone('secondary_down', self, function()
cursor:zone('secondary_click', self, function()
mp.set_property_native('mute', false)
mp.set_property_native('volume', 100)
end)

-- Mute button
local mute_rect = {ax = self.ax, ay = self.mute_ay, bx = self.bx, by = self.by}
cursor:zone('primary_down', mute_rect, function() mp.commandv('cycle', 'mute') end)
cursor:zone('primary_click', mute_rect, function() mp.commandv('cycle', 'mute') end)
local ass = assdraw.ass_new()
local width_half = (mute_rect.bx - mute_rect.ax) / 2
local height_half = (mute_rect.by - mute_rect.ay) / 2
Expand Down
Loading

0 comments on commit 4a4d056

Please sign in to comment.