Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only autohide UI when the cursor autohides #771

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/uosc/lib/cursor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ local cursor = {
mbtn_left_dbl_enabled = nil,
mbtn_right_enabled = nil,
wheel_enabled = nil,
autohide_fs_only = nil,
}

cursor.autohide_timer = (function()
local timer = mp.add_timeout(mp.get_property_native('cursor-autohide') / 1000, function() cursor:autohide() end)
timer:kill()
return timer
end)()
cursor.autohide_timer = mp.add_timeout(1, function() cursor:autohide() end)
cursor.autohide_timer:kill()
mp.observe_property('cursor-autohide', 'number', function(_, val)
cursor.autohide_timer.timeout = (val or 1000) / 1000
end)

-- Called at the beginning of each render
function cursor:clear_zones()
Expand Down Expand Up @@ -152,14 +153,17 @@ function cursor:decide_keybinds()
if enable_mbtn_left_dbl ~= self.mbtn_left_dbl_enabled then
mp[(enable_mbtn_left_dbl and 'enable' or 'disable') .. '_key_bindings']('mbtn_left_dbl')
self.mbtn_left_dbl_enabled = enable_mbtn_left_dbl
self:queue_autohide()
end
if enable_mbtn_right ~= self.mbtn_right_enabled then
mp[(enable_mbtn_right and 'enable' or 'disable') .. '_key_bindings']('mbtn_right')
self.mbtn_right_enabled = enable_mbtn_right
self:queue_autohide()
end
if enable_wheel ~= self.wheel_enabled then
mp[(enable_wheel and 'enable' or 'disable') .. '_key_bindings']('wheel')
self.wheel_enabled = enable_wheel
self:queue_autohide()
end
end

Expand Down Expand Up @@ -256,13 +260,23 @@ end

function cursor:leave() self:move(math.huge, math.huge) end

function cursor:is_autohide_allowed()
return options.autohide and (not self.autohide_fs_only or state.fullscreen) and
not (self.mbtn_left_dbl_enabled or self.mbtn_right_enabled or self.wheel_enabled) and
not Menu:is_open()
end
mp.observe_property('cursor-autohide-fs-only', 'bool', function(_, val) cursor.autohide_fs_only = val end)

-- Cursor auto-hiding after period of inactivity.
function cursor:autohide()
if #self.zone_handlers.primary_up == 0 and not Menu:is_open() then self:leave() end
if self:is_autohide_allowed() then
self:leave()
self.autohide_timer:kill()
end
end

function cursor:queue_autohide()
if options.autohide and #self.zone_handlers.primary_up == 0 then
if self:is_autohide_allowed() then
self.autohide_timer:kill()
self.autohide_timer:resume()
end
Expand Down