[PATCH v2 4/4] winex11.drv: Avoid requesting current mode in X11DRV_desktop_get_modes.
Rémi Bernon
wine at gitlab.winehq.org
Tue Jun 28 02:13:07 CDT 2022
From: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/winex11.drv/desktop.c | 81 ++++++++++++++++++++++++++++++++++++--
1 file changed, 77 insertions(+), 4 deletions(-)
diff --git a/dlls/winex11.drv/desktop.c b/dlls/winex11.drv/desktop.c
index bc2ba60397b..d24c0b6fe62 100644
--- a/dlls/winex11.drv/desktop.c
+++ b/dlls/winex11.drv/desktop.c
@@ -83,6 +83,78 @@ static struct screen_size {
#define _NET_WM_STATE_REMOVE 0
#define _NET_WM_STATE_ADD 1
+static HKEY open_hkcu(void)
+{
+ char buffer[256];
+ WCHAR bufferW[256];
+ DWORD_PTR sid_data[(sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE) / sizeof(DWORD_PTR)];
+ DWORD i, len = sizeof(sid_data);
+ SID *sid;
+
+ if (NtQueryInformationToken( GetCurrentThreadEffectiveToken(), TokenUser, sid_data, len, &len ))
+ return 0;
+
+ sid = ((TOKEN_USER *)sid_data)->User.Sid;
+ len = sprintf( buffer, "\\Registry\\User\\S-%u-%u", sid->Revision,
+ (unsigned)MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5], sid->IdentifierAuthority.Value[4] ),
+ MAKEWORD( sid->IdentifierAuthority.Value[3], sid->IdentifierAuthority.Value[2] )));
+ for (i = 0; i < sid->SubAuthorityCount; i++)
+ len += sprintf( buffer + len, "-%u", (unsigned)sid->SubAuthority[i] );
+ ascii_to_unicode( bufferW, buffer, len + 1 );
+
+ return reg_open_key( NULL, bufferW, len * sizeof(WCHAR) );
+}
+
+static HKEY reg_open_hkcu_key( const WCHAR *name, ULONG name_len )
+{
+ HKEY hkcu = open_hkcu(), key;
+
+ key = reg_open_key( hkcu, name, name_len );
+ NtClose( hkcu );
+
+ return key;
+}
+
+/* parse the desktop size specification */
+static BOOL parse_size( const WCHAR *size, unsigned int *width, unsigned int *height )
+{
+ WCHAR *end;
+
+ *width = wcstoul( size, &end, 10 );
+ if (end == size) return FALSE;
+ if (*end != 'x') return FALSE;
+ size = end + 1;
+ *height = wcstoul( size, &end, 10 );
+ return !*end;
+}
+
+/* retrieve the default desktop size from the registry */
+static BOOL get_default_desktop_size( unsigned int *width, unsigned int *height )
+{
+ static const WCHAR desktop_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
+ 'E','x','p','l','o','r','e','r','\\',
+ 'D','e','s','k','t','o','p','s',0};
+ static const WCHAR defaultW[] = {'D','e','f','a','u','l','t',0};
+ WCHAR buffer[4096];
+ KEY_VALUE_PARTIAL_INFORMATION *value = (void *)buffer;
+ DWORD size;
+ HKEY hkey;
+
+ *width = 800;
+ *height = 600;
+
+ /* @@ Wine registry key: HKCU\Software\Wine\Explorer\Desktops */
+ if (!(hkey = reg_open_hkcu_key( desktop_keyW, sizeof(desktop_keyW) )))
+ return FALSE;
+
+ size = query_reg_value( hkey, defaultW, value, sizeof(buffer) );
+ if (!size || value->Type != REG_SZ) return FALSE;
+ NtClose( hkey );
+
+ if (!parse_size( (const WCHAR *)value->Data, width, height )) return FALSE;
+ return TRUE;
+}
+
/* Return TRUE if Wine is currently in virtual desktop mode */
BOOL is_virtual_desktop(void)
{
@@ -118,12 +190,13 @@ static BOOL X11DRV_desktop_get_modes( ULONG_PTR id, DWORD flags, DEVMODEW **new_
{
UINT depth_idx, size_idx, mode_idx = 0;
UINT screen_width, screen_height;
- RECT primary_rect;
DEVMODEW *modes;
- primary_rect = NtUserGetPrimaryMonitorRect();
- screen_width = primary_rect.right - primary_rect.left;
- screen_height = primary_rect.bottom - primary_rect.top;
+ if (!get_default_desktop_size( &screen_width, &screen_height ))
+ {
+ screen_width = max_width;
+ screen_height = max_height;
+ }
/* Allocate memory for modes in different color depths */
if (!(modes = calloc( (ARRAY_SIZE(screen_sizes) + 2) * DEPTH_COUNT, sizeof(*modes))) )
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/322
More information about the wine-devel
mailing list