This commit is contained in:
2026-08-15 17:50:48 +02:00
parent 22246060e6
commit 4dc6687de7
35 changed files with 4978 additions and 1509 deletions
+30 -2
View File
@@ -4,6 +4,8 @@ local cursor = {
x = math.huge,
y = math.huge,
hidden = true,
disabled = false,
disablers = {}, -- List of ids. When not empty, the cursor handling is disabled.
distance = 0, -- Distance traveled during current move. Reset by `cursor.distance_reset_timer`.
last_hover = false, -- Stores `mouse.hover` boolean of the last mouse event for enter/leave detection.
-- Event handlers that are only fired on zones defined during render loop.
@@ -404,11 +406,27 @@ function cursor:direction_to_rectangle_distance(rect)
return get_ray_to_rectangle_distance(self.x, self.y, end_x, end_y, rect)
end
---@param id string
function cursor:register_disabler(id)
self.disablers[#self.disablers + 1] = id
if #self.disablers > 0 then
cursor.disabled = true
self:leave()
end
end
---@param id string
function cursor:unregister_disabler(id)
self.disablers = itable_filter(self.disablers, function(item) return item ~= id end)
if #self.disablers == 0 then cursor.disabled = false end
end
---@param event string
---@param shortcut Shortcut
---@param cb? fun(shortcut: Shortcut)
function cursor:create_handler(event, shortcut, cb)
return function()
if self.disabled then return end
if cb then cb(shortcut) end
self:trigger(event, shortcut)
end
@@ -416,7 +434,7 @@ end
-- Movement
local function handle_mouse_pos(_, mouse)
if not mouse then return end
if not mouse or cursor.disabled then return end
if cursor.last_hover and not mouse.hover then
cursor:leave()
elseif not (cursor.last_hover == false and mouse.hover == false) then -- filters out duplicate mouse out events
@@ -426,7 +444,7 @@ local function handle_mouse_pos(_, mouse)
end
local function handle_touch_pos(_, touches)
if not touches then return end
if not touches or cursor.disabled then return end
local touch = touches[1]
if touch then
cursor:move(touch.x, touch.y)
@@ -466,4 +484,14 @@ mp.set_key_bindings({
{'wheel_down', cursor:create_handler('wheel_down', create_shortcut('wheel_down'))},
}, 'wheel', 'force')
-- Monitor mpv UI's and disable uosc's cursor handling when any are open
mp.observe_property('user-data/mpv/context-menu/open', 'bool', function(_, value)
if value == true then cursor:register_disabler('context-menu')
else cursor:unregister_disabler('context-menu') end
end)
mp.observe_property('user-data/mpv/console/open', 'bool', function(_, value)
if value == true then cursor:register_disabler('console')
else cursor:unregister_disabler('console') end
end)
return cursor