From 38c20d9a76e69087d3d1fe06335d8b3dc8571295 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 1 Feb 2026 18:05:26 -0800 Subject: drop incorrect mouse position events when mpv gains focus --- osd.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'osd.lua') diff --git a/osd.lua b/osd.lua index bbd4ee6..a793286 100644 --- a/osd.lua +++ b/osd.lua @@ -793,10 +793,21 @@ function mt:update_mstate(mactive) end function mt:set_mpos(mpos) - -- mpv sends (0, 0) on startup if the mouse hasn't moved yet. don't - -- trigger display of the button until the mouse has actually moved. - if not self.mpos and mpos and mpos.x == 0 and mpos.y == 0 then - return + -- when mpv gains hover, it sends the last known coordinates prior to + -- losing hover, not the actual coordinates of the mouse. these events + -- are dropped to avoid reporting an incorrect mouse state, requiring a + -- mouse move before honouring anything dependent on mouse state. + -- + -- mpv also sends coordinates of (0, 0) on startup. no special logic is + -- needed for this because it is sent with a hover state of false, + -- before a possible second event with a hover state of true. + if mpos then + if self.mpos_dehover and mpos.x == self.mpos_dehover.x and + mpos.y == self.mpos_dehover.y then + return + end + + self.mpos_dehover = not mpos.hover and mpos or nil end self.mpos = mpos -- cgit v1.2.3-70-g09d2