Although tests show that their order are not always guaranteed on Windows, most of the time it is sorted. It also makes sure that when a 0Hz or 1Hz display mode is specified for ChangeDisplaySettingsExW(), the chosen display mode is the one with the highest frequency.
Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/winex11.drv/settings.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/dlls/winex11.drv/settings.c b/dlls/winex11.drv/settings.c index 28c405ae0e0..02495756179 100644 --- a/dlls/winex11.drv/settings.c +++ b/dlls/winex11.drv/settings.c @@ -20,6 +20,7 @@ */
#include "config.h" +#include <stdlib.h>
#define NONAMELESSUNION #define NONAMELESSSTRUCT @@ -333,6 +334,22 @@ BOOL get_primary_adapter(WCHAR *name) return FALSE; }
+static int mode_compare(const void *p1, const void *p2) +{ + const DEVMODEW *a = p1, *b = p2; + + if (a->dmBitsPerPel != b->dmBitsPerPel) + return b->dmBitsPerPel - a->dmBitsPerPel; + + if (a->dmPelsWidth != b->dmPelsWidth) + return a->dmPelsWidth - b->dmPelsWidth; + + if (a->dmPelsHeight != b->dmPelsHeight) + return a->dmPelsHeight - b->dmPelsHeight; + + return b->dmDisplayFrequency - a->dmDisplayFrequency; +} + /*********************************************************************** * EnumDisplaySettingsEx (X11DRV.@) * @@ -379,6 +396,8 @@ BOOL CDECL X11DRV_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmo return FALSE; }
+ qsort(modes, mode_count, sizeof(*modes) + modes[0].dmDriverExtra, mode_compare); + if (cached_modes) handler.free_modes(cached_modes); lstrcpyW(cached_device_name, name); @@ -477,6 +496,7 @@ static DEVMODEW *get_full_mode(ULONG_PTR id, const DEVMODEW *dev_mode) if (!handler.get_modes(id, 0, &modes, &mode_count)) return NULL;
+ qsort(modes, mode_count, sizeof(*modes) + modes[0].dmDriverExtra, mode_compare); for (mode_idx = 0; mode_idx < mode_count; ++mode_idx) { found_mode = (DEVMODEW *)((BYTE *)modes + (sizeof(*modes) + modes[0].dmDriverExtra) * mode_idx);