[FFmpeg-devel] [PATCH] avdevice/gdigrab: client_only option to discard decorations such as titlebar or borders

Calvin Walton calvin.walton at kepstin.ca
Thu Jul 9 19:52:06 EEST 2020


On Fri, 2020-06-19 at 10:33 +0200, Sergio Acereda wrote:
> +/**
> + * Fetch titlebar height from handle.
> + *
> + * @param hwnd Handle of the window.
> + * @return titlebar height
> + */
> +static int
> +calc_titlebar_height(HWND hwnd) {
> +    TITLEBARINFOEX tinfo;
> +    tinfo.cbSize = sizeof(tinfo);
> +    SendMessage(hwnd, WM_GETTITLEBARINFOEX, 0, (LPARAM)&tinfo);
> +    return tinfo.rcTitleBar.bottom - tinfo.rcTitleBar.top;
> +}
> +
> /**
>  * Initializes the gdi grab device demuxer (public device demuxer
> API).
>  *
> @@ -284,6 +299,15 @@ gdigrab_read_header(AVFormatContext *s1)
> 
>     if (hwnd) {
>         GetClientRect(hwnd, &virtual_rect);
> +        if (gdigrab->client_only) {
> +            int cxborder = GetSystemMetrics(SM_CXBORDER);
> +            int cyborder = GetSystemMetrics(SM_CYBORDER);
> +            int titlebar_height = calc_titlebar_height(hwnd);
> +            virtual_rect.left   += cxborder;
> +            virtual_rect.right  += -cxborder;
> +            virtual_rect.top    += cxborder + titlebar_height;
> +            virtual_rect.bottom += -cyborder;
> +        }

This seems fine - my only comment is that you need to test this with
high DPI support (display scale values >100%) on both native high-dpi
applications and legacy (scaled by windows) applications to ensure the
correct adjustments are being applied where needed.


-- 
Calvin Walton <calvin.walton at kepstin.ca>



More information about the ffmpeg-devel mailing list