user32: Optimize getting primary monitor rectangle with GetSystemMetrics().

This saves calls to GetMonitorInfo() and return from EnumDisplayMonitors() immediately
after the primary monitor is found.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zhiyi Zhang 2021-05-18 17:11:10 +08:00 committed by Alexandre Julliard
parent d7cd5587df
commit ab431c70b4
1 changed files with 26 additions and 4 deletions

View File

@ -371,6 +371,27 @@ RECT get_virtual_screen_rect(void)
return info.virtual_rect; return info.virtual_rect;
} }
static BOOL CALLBACK get_primary_monitor_proc( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp )
{
RECT *primary_rect = (RECT *)lp;
if (!rect->top && !rect->left && rect->right && rect->bottom)
{
*primary_rect = *rect;
return FALSE;
}
return TRUE;
}
static RECT get_primary_monitor_rect(void)
{
RECT rect = {0};
EnumDisplayMonitors( 0, NULL, get_primary_monitor_proc, (LPARAM)&rect );
return rect;
}
static BOOL CALLBACK get_monitor_count_proc( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp ) static BOOL CALLBACK get_monitor_count_proc( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp )
{ {
INT *count = (INT *)lp; INT *count = (INT *)lp;
@ -2510,6 +2531,7 @@ INT WINAPI GetSystemMetrics( INT index )
NONCLIENTMETRICSW ncm; NONCLIENTMETRICSW ncm;
MINIMIZEDMETRICS mm; MINIMIZEDMETRICS mm;
ICONMETRICSW im; ICONMETRICSW im;
RECT rect;
UINT ret; UINT ret;
HDC hdc; HDC hdc;
@ -2715,11 +2737,11 @@ INT WINAPI GetSystemMetrics( INT index )
case SM_MOUSEWHEELPRESENT: case SM_MOUSEWHEELPRESENT:
return 1; return 1;
case SM_CXSCREEN: case SM_CXSCREEN:
get_monitors_info( &info ); rect = get_primary_monitor_rect();
return info.primary_rect.right - info.primary_rect.left; return rect.right - rect.left;
case SM_CYSCREEN: case SM_CYSCREEN:
get_monitors_info( &info ); rect = get_primary_monitor_rect();
return info.primary_rect.bottom - info.primary_rect.top; return rect.bottom - rect.top;
case SM_XVIRTUALSCREEN: case SM_XVIRTUALSCREEN:
get_monitors_info( &info ); get_monitors_info( &info );
return info.virtual_rect.left; return info.virtual_rect.left;