Skip to content

Commit

Permalink
fix: touch input (#412)
Browse files Browse the repository at this point in the history
`mouse-pos.hover` may or may not be false during touch input
(contrary to mouse input, where false means the cursor left the window)

Detecting a change to false as a leave event, while allowing any
other mouse-pos update to cause an enter event solves this.
  • Loading branch information
christoph-heinrich authored Jan 2, 2023
1 parent e66c8fb commit 5a02c6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions scripts/uosc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ end
--[[ STATE ]]

display = {width = 1280, height = 720, scale_x = 1, scale_y = 1, initialized = false}
cursor = {hidden = true, x = 0, y = 0}
cursor = {hidden = true, hover_raw = false, x = 0, y = 0}
state = {
os = (function()
if os.getenv('windir') ~= nil then return 'windows' end
Expand Down Expand Up @@ -545,11 +545,14 @@ if options.click_threshold > 0 then
mp.enable_key_bindings('mouse_movement', 'allow-vo-dragging+allow-hide-cursor')
end

function update_mouse_pos(_, mouse, ignore_hover)
if ignore_hover or mouse.hover then
function update_mouse_pos(_, mouse)
if cursor.hover_raw and not mouse.hover then
handle_mouse_leave()
else
if cursor.hidden then handle_mouse_enter(mouse.x, mouse.y) end
handle_mouse_move(mouse.x, mouse.y)
else handle_mouse_leave() end
end
cursor.hover_raw = mouse.hover
end
mp.observe_property('mouse-pos', 'native', update_mouse_pos)
mp.observe_property('osc', 'bool', function(name, value) if value == true then mp.set_property('osc', 'no') end end)
Expand Down
2 changes: 1 addition & 1 deletion scripts/uosc_shared/elements/Elements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ mp.set_key_bindings({
'mbtn_left',
Elements:create_proximity_dispatcher('mbtn_left_up'),
function(...)
update_mouse_pos(nil, mp.get_property_native('mouse-pos'), true)
update_mouse_pos(nil, mp.get_property_native('mouse-pos'))
Elements:proximity_trigger('mbtn_left_down', ...)
end,
},
Expand Down

0 comments on commit 5a02c6d

Please sign in to comment.