From: Zhiyi Zhang Subject: [PATCH 2/4] winex11.drv: Sort display modes with orientation considered. Message-Id: <0081871b-8e66-a7ad-2b14-0626bfbbca42@codeweavers.com> Date: Tue, 22 Sep 2020 15:01:44 +0800 Signed-off-by: Zhiyi Zhang --- dlls/winex11.drv/settings.c | 42 ++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/dlls/winex11.drv/settings.c b/dlls/winex11.drv/settings.c index 902f1ec15d9..5bbba453b95 100644 --- a/dlls/winex11.drv/settings.c +++ b/dlls/winex11.drv/settings.c @@ -359,18 +359,50 @@ BOOL get_primary_adapter(WCHAR *name) static int mode_compare(const void *p1, const void *p2) { + DWORD a_width, a_height, b_width, b_height; const DEVMODEW *a = p1, *b = p2; + /* Use the width and height in landscape mode for comparison */ + if (a->u1.s2.dmDisplayOrientation == DMDO_DEFAULT || a->u1.s2.dmDisplayOrientation == DMDO_180) + { + a_width = a->dmPelsWidth; + a_height = a->dmPelsHeight; + } + else + { + a_width = a->dmPelsHeight; + a_height = a->dmPelsWidth; + } + + if (b->u1.s2.dmDisplayOrientation == DMDO_DEFAULT || b->u1.s2.dmDisplayOrientation == DMDO_180) + { + b_width = b->dmPelsWidth; + b_height = b->dmPelsHeight; + } + else + { + b_width = b->dmPelsHeight; + b_height = b->dmPelsWidth; + } + + /* Depth in descending order */ if (a->dmBitsPerPel != b->dmBitsPerPel) return b->dmBitsPerPel - a->dmBitsPerPel; - if (a->dmPelsWidth != b->dmPelsWidth) - return a->dmPelsWidth - b->dmPelsWidth; + /* Width in ascending order */ + if (a_width != b_width) + return a_width - b_width; - if (a->dmPelsHeight != b->dmPelsHeight) - return a->dmPelsHeight - b->dmPelsHeight; + /* Height in ascending order */ + if (a_height != b_height) + return a_height - b_height; - return b->dmDisplayFrequency - a->dmDisplayFrequency; + /* Frequency in descending order */ + if (a->dmDisplayFrequency != b->dmDisplayFrequency) + return b->dmDisplayFrequency - a->dmDisplayFrequency; + + /* Orientation in ascending order */ + return a->u1.s2.dmDisplayOrientation - b->u1.s2.dmDisplayOrientation; } /*********************************************************************** -- 2.25.1