diff mbox

[FFmpeg-devel] gdigrab: fix HIDPI support for mouse positioning

Message ID 0fd52427-fc8c-3c9b-5708-aa4472077ae0@gmail.com
State New
Headers show

Commit Message

Dilshod Mukhtarov Jan. 27, 2019, 7:15 p.m. UTC
New version, which uses integer arithmetics

Comments

Carl Eugen Hoyos Jan. 30, 2019, 8:55 p.m. UTC | #1
2019-01-27 20:15 GMT+01:00, Dilshod Mukhtarov <dilshodm@gmail.com>:
> New version, which uses integer arithmetics

Patch applied.

Thank you, Carl Eugen
diff mbox

Patch

From 586d4b3ed3406b66e3d0bd69806bc33beaddc026 Mon Sep 17 00:00:00 2001
From: Dilshod Mukhtarov <dilshodm@gmail.com>
Date: Sun, 27 Jan 2019 23:10:37 +0400
Subject: [PATCH 2/2] libavdevice/gdigrab: fix HIDPI support for mouse
 positioning

Mouse position was not calculated properly in area or window mode

Signed-off-by: Dilshod Mukhtarov <dilshodm@gmail.com>
---
 libavdevice/gdigrab.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index 0e6ae2bd5d..b226bd0831 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -479,25 +479,26 @@  static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab)
             goto icon_error;
         }
 
-        pos.x = ci.ptScreenPos.x - clip_rect.left - info.xHotspot;
-        pos.y = ci.ptScreenPos.y - clip_rect.top - info.yHotspot;
-
         if (hwnd) {
             RECT rect;
 
             if (GetWindowRect(hwnd, &rect)) {
-                pos.x -= rect.left;
-                pos.y -= rect.top;
+                pos.x = ci.ptScreenPos.x - clip_rect.left - info.xHotspot - rect.left;
+                pos.y = ci.ptScreenPos.y - clip_rect.top - info.yHotspot - rect.top;
+
+                //that would keep the correct location of mouse with hidpi screens
+                pos.x = pos.x * desktophorzres / horzres;
+                pos.y = pos.y * desktopvertres / vertres;
             } else {
                 CURSOR_ERROR("Couldn't get window rectangle");
                 goto icon_error;
             }
+        } else {
+            //that would keep the correct location of mouse with hidpi screens
+            pos.x = ci.ptScreenPos.x * desktophorzres / horzres - clip_rect.left - info.xHotspot;
+            pos.y = ci.ptScreenPos.y * desktopvertres / vertres - clip_rect.top - info.yHotspot;
         }
 
-        //that would keep the correct location of mouse with hidpi screens
-        pos.x = pos.x * desktophorzres / horzres;
-        pos.y = pos.y * desktopvertres / vertres;
-
         av_log(s1, AV_LOG_DEBUG, "Cursor pos (%li,%li) -> (%li,%li)\n",
                 ci.ptScreenPos.x, ci.ptScreenPos.y, pos.x, pos.y);
 
-- 
2.17.1