From 0d8ee5aca28655baf0e6954063ad61a422443d38 Mon Sep 17 00:00:00 2001
From: Dilshod Mukhtarov <dilshodm@gmail.com>
Date: Sun, 27 Jan 2019 22:30:01 +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 | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
@@ -452,10 +452,10 @@ static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab)
POINT pos;
RECT clip_rect = gdigrab->clip_rect;
HWND hwnd = gdigrab->hwnd;
- int horzres = GetDeviceCaps(gdigrab->source_hdc, HORZRES);
- int vertres = GetDeviceCaps(gdigrab->source_hdc, VERTRES);
- int desktophorzres = GetDeviceCaps(gdigrab->source_hdc, DESKTOPHORZRES);
- int desktopvertres = GetDeviceCaps(gdigrab->source_hdc, DESKTOPVERTRES);
+ AVRational h_dpr = { GetDeviceCaps(gdigrab->source_hdc, DESKTOPHORZRES),
+ GetDeviceCaps(gdigrab->source_hdc, HORZRES) }; // Horizontal device pixel ratio
+ AVRational v_dpr = { GetDeviceCaps(gdigrab->source_hdc, DESKTOPVERTRES),
+ GetDeviceCaps(gdigrab->source_hdc, VERTRES) }; // Vertical device pixel ratio
info.hbmMask = NULL;
info.hbmColor = NULL;
@@ -474,25 +474,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 *= av_q2d(h_dpr);
+ pos.y *= av_q2d(v_dpr);
} 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 * av_q2d(h_dpr) - clip_rect.left - info.xHotspot;
+ pos.y = ci.ptScreenPos.y * av_q2d(v_dpr) - 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