osc: fix hovering timestamp sticking around when moving mouse away

The OSC calls this "tooltip" (and although a general mechanism, there's
only one instance using it). One particular problem was that with the
default OSC layout, moving the mouse down and out of the window, the
tooltip stuck around, because the returned mouse position was the last
pixel row in the window, which still overlaps with the seek bar.

Instead of introducing mouse_in_window, you could check last_mouse_X for
nil, but I think this is clearer.

This returns (-1, -1) to the caller if the mouse is outside. Kind of
random, but works.
This commit is contained in:
wm4 2020-05-16 13:45:16 +02:00
parent 09b68648f1
commit 152b0e2a8c
1 changed files with 11 additions and 3 deletions

View File

@ -102,6 +102,7 @@ local state = {
mp_screen_sizeX, mp_screen_sizeY, -- last screen-resolution, to detect resolution changes to issue reINITs
initREQ = false, -- is a re-init request pending?
last_mouseX, last_mouseY, -- last mouse position, to detect significant mouse movement
mouse_in_window = false,
message_text,
message_hide_timer,
fullscreen = false,
@ -160,9 +161,13 @@ end
-- return mouse position in virtual ASS coordinates (playresx/y)
function get_virt_mouse_pos()
local sx, sy = get_virt_scale_factor()
local x, y = mp.get_mouse_pos()
return x * sx, y * sy
if state.mouse_in_window then
local sx, sy = get_virt_scale_factor()
local x, y = mp.get_mouse_pos()
return x * sx, y * sy
else
return -1, -1
end
end
function set_virt_mouse_area(x0, y0, x1, y1, name)
@ -2212,6 +2217,7 @@ function mouse_leave()
end
-- reset mouse position
state.last_mouseX, state.last_mouseY = nil, nil
state.mouse_in_window = false
end
function request_init()
@ -2449,6 +2455,8 @@ function process_event(source, what)
elseif source == "mouse_move" then
state.mouse_in_window = true
local mouseX, mouseY = get_virt_mouse_pos()
if (user_opts.minmousemove == 0) or
(not ((state.last_mouseX == nil) or (state.last_mouseY == nil)) and