[FFmpeg-devel] [patch] gdigrab-mouse-dpi-awareness

James Darnley james.darnley at gmail.com
Fri Feb 12 01:01:18 CET 2016


On 2016-02-11 23:19, Γιώργος Μεταξάκης wrote:
> Subject: [PATCH] mouse dpi awareness
> 
> ---
>  libavdevice/gdigrab.c | 28 +++++++++++++++-------------
>  1 file changed, 15 insertions(+), 13 deletions(-)
> 
> diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
> index 4428a34..60f184e 100644
> --- a/libavdevice/gdigrab.c
> +++ b/libavdevice/gdigrab.c
> @@ -71,6 +71,8 @@ struct gdigrab {
>  
>  #define REGION_WND_BORDER 3
>  
> +    
> +	
>  /**
>   * Callback to handle Windows messages for the region outline window.
>   *

Please don't add random whitespace changes.

> @@ -235,8 +237,7 @@ gdigrab_read_header(AVFormatContext *s1)
>      AVStream   *st       = NULL;
>  
>      int bpp;
> -    int vertres;
> -    int desktopvertres;
> +
>      RECT virtual_rect;
>      RECT clip_rect;
>      BITMAP bmp;
> @@ -279,8 +280,8 @@ gdigrab_read_header(AVFormatContext *s1)
>          GetClientRect(hwnd, &virtual_rect);
>      } else {
>          /* desktop -- get the right height and width for scaling DPI */
> -        vertres = GetDeviceCaps(source_hdc, VERTRES);
> -        desktopvertres = GetDeviceCaps(source_hdc, DESKTOPVERTRES);
> +        int vertres = GetDeviceCaps(source_hdc, VERTRES);
> +        int desktopvertres = GetDeviceCaps(source_hdc, DESKTOPVERTRES);
>          virtual_rect.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
>          virtual_rect.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
>          virtual_rect.right = (virtual_rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN)) * desktopvertres / vertres;

Is this change just moving the declaration?

> @@ -431,8 +432,10 @@ error:
>  static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab)
>  {
>      CURSORINFO ci = {0};
> +	int vertres = GetDeviceCaps(gdigrab->source_hdc, VERTRES);
> +    int desktopvertres = GetDeviceCaps(gdigrab->source_hdc, DESKTOPVERTRES);
>  
> -#define CURSOR_ERROR(str)                 \
> +	#define CURSOR_ERROR(str)                 \
>      if (!gdigrab->cursor_error_printed) {       \
>          WIN32_API_ERROR(str);             \
>          gdigrab->cursor_error_printed = 1;      \
> @@ -459,12 +462,7 @@ static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab)
>              icon = CopyCursor(LoadCursor(NULL, IDC_ARROW));
>          }
>  
> -        if (!GetIconInfo(icon, &info)) {
> -            CURSOR_ERROR("Could not get icon info");
> -            goto icon_error;
> -        }
> -
> -        pos.x = ci.ptScreenPos.x - clip_rect.left - info.xHotspot;
> +	   pos.x = ci.ptScreenPos.x - clip_rect.left - info.xHotspot;
>          pos.y = ci.ptScreenPos.y - clip_rect.top - info.yHotspot;
>  
>          if (hwnd) {

No Tabs!

Why did you remove the GetIconInfo() call?  You need that to fill the
info data structure you use right here.

> @@ -478,7 +476,11 @@ static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab)
>                  goto icon_error;
>              }
>          }
> -
> +	
> +		//that would keep the correct location of mouse with hidpi screens
> +        pos.x = pos.x * desktopvertres / vertres;
> +        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);
>  

You probably want to round that division and add some brackets so the
division happens last.  The change you want to make is probably right
but I would have to check the docs before signing off.

> @@ -639,4 +641,4 @@ AVInputFormat ff_gdigrab_demuxer = {
>      .read_close     = gdigrab_read_close,
>      .flags          = AVFMT_NOFILE,
>      .priv_class     = &gdigrab_class,
> -};
> +};
> \ No newline at end of file

I think you need a better editor.

What were the symptoms of the problem before your fix?  Was the cursor
being drawn too large or to small?  The second last chunk suggests it
was in the wrong position.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 603 bytes
Desc: OpenPGP digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160212/98558434/attachment.sig>


More information about the ffmpeg-devel mailing list