|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
|
msg = require('mp.msg')
|
|
|
|
|
local cursor = {
|
|
|
|
|
x = math.huge,
|
|
|
|
|
y = math.huge,
|
|
|
|
@@ -154,8 +155,14 @@ function cursor:trigger(event, ...)
|
|
|
|
|
local callbacks = self.handlers[event]
|
|
|
|
|
if zone or #callbacks > 0 then
|
|
|
|
|
forward = false
|
|
|
|
|
if zone then zone.handler(...) end
|
|
|
|
|
for _, callback in ipairs(callbacks) do callback(...) end
|
|
|
|
|
if zone then
|
|
|
|
|
msg.trace("cursor:trigger zone callback: ", event, callback)
|
|
|
|
|
zone.handler(...)
|
|
|
|
|
end
|
|
|
|
|
for _, callback in ipairs(callbacks) do
|
|
|
|
|
msg.trace("cursor:trigger event callback: ", event, callback)
|
|
|
|
|
callback(...)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Call compound/parent (click) event handlers if both start and end events are within `parent_zone.hitbox`.
|
|
|
|
@@ -222,7 +229,7 @@ function cursor:decide_keybinds()
|
|
|
|
|
-- Check zones.
|
|
|
|
|
for _, zone in ipairs(self.zones) do
|
|
|
|
|
local binding = self.event_binding_map[zone.event]
|
|
|
|
|
if binding and cursor:collides_with(zone.hitbox) then
|
|
|
|
|
if binding or cursor:collides_with(zone.hitbox) then
|
|
|
|
|
local new_level = (self.window_dragging_blockers[zone.event] and zone.hitbox.window_drag ~= true) and 2
|
|
|
|
|
or math.max(new_levels[binding], zone.hitbox.window_drag == false and 2 or 1)
|
|
|
|
|
new_levels[binding] = new_level
|
|
|
|
@@ -238,6 +245,7 @@ function cursor:decide_keybinds()
|
|
|
|
|
for name, level in pairs(new_levels) do
|
|
|
|
|
if level ~= self.binding_levels[name] then
|
|
|
|
|
local flags = level == 1 and 'allow-vo-dragging+allow-hide-cursor' or ''
|
|
|
|
|
msg.trace("updating binding_level", name, level)
|
|
|
|
|
mp[(level == 0 and 'disable' or 'enable') .. '_key_bindings'](name, flags)
|
|
|
|
|
self.binding_levels[name] = level
|
|
|
|
|
self:queue_autohide()
|
|
|
|
@@ -367,19 +375,37 @@ function cursor:direction_to_rectangle_distance(rect)
|
|
|
|
|
return get_ray_to_rectangle_distance(self.x, self.y, end_x, end_y, rect)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function cursor:create_handler(event, cb)
|
|
|
|
|
function cursor:create_handler(event, cb, cb_post)
|
|
|
|
|
return function(...)
|
|
|
|
|
msg.trace("UOSC EVENT:", event)
|
|
|
|
|
-- local mouse = mp.get_property_native('mouse-pos')
|
|
|
|
|
-- msg.trace("mouse-pos:", mouse)
|
|
|
|
|
-- for k,v in pairs(mouse) do
|
|
|
|
|
-- msg.trace(k, v)
|
|
|
|
|
-- end
|
|
|
|
|
-- handle_mouse_pos(_, mouse)
|
|
|
|
|
call_maybe(cb, ...)
|
|
|
|
|
self:trigger(event, ...)
|
|
|
|
|
call_maybe(cb_post, ...)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Movement
|
|
|
|
|
function handle_mouse_pos(_, mouse)
|
|
|
|
|
function handle_mouse_pos(_, mouse, is_pre_down)
|
|
|
|
|
if not mouse then return end
|
|
|
|
|
if cursor.hover_raw and not mouse.hover then
|
|
|
|
|
msg.trace("handle_mouse_pos: x:", mouse.x, ", y:", mouse.y, ", hover:", mouse.hover, ", hover_raw:", cursor.hover_raw)
|
|
|
|
|
local last_down = cursor.last_event['primary_down'] or { time = 0 }
|
|
|
|
|
local last_up = cursor.last_event['primary_up'] or { time = 0}
|
|
|
|
|
msg.trace(" last_down/up:", last_down.time, last_up.time)
|
|
|
|
|
if is_pre_down then
|
|
|
|
|
cursor:move(mouse.x, mouse.y)
|
|
|
|
|
elseif cursor.hover_raw and not mouse.hover then
|
|
|
|
|
msg.trace("cursor leave")
|
|
|
|
|
cursor:leave()
|
|
|
|
|
else
|
|
|
|
|
elseif mouse.hover and not cursor.hover_raw then
|
|
|
|
|
msg.trace("suspected touch release while pointer is active: leaving")
|
|
|
|
|
cursor:leave()
|
|
|
|
|
elseif mouse.hover or last_down.time >= last_up.time then
|
|
|
|
|
cursor:move(mouse.x, mouse.y)
|
|
|
|
|
end
|
|
|
|
|
cursor.hover_raw = mouse.hover
|
|
|
|
@@ -390,14 +416,21 @@ mp.observe_property('mouse-pos', 'native', handle_mouse_pos)
|
|
|
|
|
mp.set_key_bindings({
|
|
|
|
|
{
|
|
|
|
|
'mbtn_left',
|
|
|
|
|
cursor:create_handler('primary_up'),
|
|
|
|
|
cursor:create_handler('primary_up', nil, function(...)
|
|
|
|
|
if not cursor.hover_raw then
|
|
|
|
|
msg.trace("touch release: simulating a leave event")
|
|
|
|
|
cursor:leave()
|
|
|
|
|
end
|
|
|
|
|
end),
|
|
|
|
|
cursor:create_handler('primary_down', function(...)
|
|
|
|
|
handle_mouse_pos(nil, mp.get_property_native('mouse-pos'))
|
|
|
|
|
local mouse = mp.get_property_native('mouse-pos')
|
|
|
|
|
handle_mouse_pos(nil, mouse, true)
|
|
|
|
|
-- handle_mouse_pos(nil, mouse, true)
|
|
|
|
|
end),
|
|
|
|
|
},
|
|
|
|
|
}, 'mbtn_left', 'force')
|
|
|
|
|
mp.set_key_bindings({
|
|
|
|
|
{'mbtn_left_dbl', 'ignore'},
|
|
|
|
|
{'mbtn_left_dbl', cursor:create_handler('secondary_up'), cursor:create_handler('secondary_down')},
|
|
|
|
|
}, 'mbtn_left_dbl', 'force')
|
|
|
|
|
mp.set_key_bindings({
|
|
|
|
|
{'mbtn_right', cursor:create_handler('secondary_up'), cursor:create_handler('secondary_down')},
|
|
|
|
|