Skip to content

Commit 102f96a

Browse files
committed
osc.lua: fix element touch handling
On some compositors, when all touch points disappear the compositors reset the mouse position, which moves the mouse out of the osc element trigger area so mouse up events do not happen. Fix this by tracking the last touch position and use that as the virt mouse position if the screen is recently touched.
1 parent 27c08af commit 102f96a

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

player/lua/osc.lua

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ end
227227
local state = {
228228
showtime = nil, -- time of last invocation (last mouse move)
229229
touchtime = nil, -- time of last invocation (last touch event)
230+
touchpoints = {}, -- current touch points
230231
osc_visible = false,
231232
anistart = nil, -- time when the animation started
232233
anitype = nil, -- current type of animation
@@ -240,6 +241,7 @@ local state = {
240241
initREQ = false, -- is a re-init request pending?
241242
marginsREQ = false, -- is a margins update pending?
242243
last_mouseX = nil, last_mouseY = nil, -- last mouse position, to detect significant mouse movement
244+
last_touchX = -1, last_touchY = -1, -- last touch position
243245
mouse_in_window = false,
244246
fullscreen = false,
245247
tick_timer = nil,
@@ -333,9 +335,19 @@ local function get_virt_scale_factor()
333335
return osc_param.playresx / w, osc_param.playresy / h
334336
end
335337

338+
local function recently_touched()
339+
if state.touchtime == nil then
340+
return false
341+
end
342+
return state.touchtime + 1 >= mp.get_time()
343+
end
344+
336345
-- return mouse position in virtual ASS coordinates (playresx/y)
337346
local function get_virt_mouse_pos()
338-
if state.mouse_in_window then
347+
if recently_touched() then
348+
local sx, sy = get_virt_scale_factor()
349+
return state.last_touchX * sx, state.last_touchY * sy
350+
elseif state.mouse_in_window then
339351
local sx, sy = get_virt_scale_factor()
340352
local x, y = mp.get_mouse_pos()
341353
return x * sx, y * sy
@@ -2242,9 +2254,17 @@ local function mouse_leave()
22422254
state.mouse_in_window = false
22432255
end
22442256

2245-
local function handle_touch()
2246-
--remember last time of invocation (touch event)
2247-
state.touchtime = mp.get_time()
2257+
local function handle_touch(_, touchpoints)
2258+
--remember last touch points
2259+
if touchpoints then
2260+
state.touchpoints = touchpoints
2261+
if #touchpoints > 0 then
2262+
--remember last time of invocation (touch event)
2263+
state.touchtime = mp.get_time()
2264+
state.last_touchX = touchpoints[1].x
2265+
state.last_touchY = touchpoints[1].y
2266+
end
2267+
end
22482268
end
22492269

22502270

0 commit comments

Comments
 (0)