Commit a8b4cf7f authored by Zhiyi Zhang's avatar Zhiyi Zhang Committed by Alexandre Julliard

winex11.drv: Sort display modes.

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: 's avatarZhiyi Zhang <zzhang@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 46182aa5
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
*/ */
#include "config.h" #include "config.h"
#include <stdlib.h>
#define NONAMELESSUNION #define NONAMELESSUNION
#define NONAMELESSSTRUCT #define NONAMELESSSTRUCT
...@@ -333,6 +334,22 @@ BOOL get_primary_adapter(WCHAR *name) ...@@ -333,6 +334,22 @@ BOOL get_primary_adapter(WCHAR *name)
return FALSE; 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.@) * EnumDisplaySettingsEx (X11DRV.@)
* *
...@@ -379,6 +396,8 @@ BOOL CDECL X11DRV_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmo ...@@ -379,6 +396,8 @@ BOOL CDECL X11DRV_EnumDisplaySettingsEx( LPCWSTR name, DWORD n, LPDEVMODEW devmo
return FALSE; return FALSE;
} }
qsort(modes, mode_count, sizeof(*modes) + modes[0].dmDriverExtra, mode_compare);
if (cached_modes) if (cached_modes)
handler.free_modes(cached_modes); handler.free_modes(cached_modes);
lstrcpyW(cached_device_name, name); lstrcpyW(cached_device_name, name);
...@@ -477,6 +496,7 @@ static DEVMODEW *get_full_mode(ULONG_PTR id, const DEVMODEW *dev_mode) ...@@ -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)) if (!handler.get_modes(id, 0, &modes, &mode_count))
return NULL; return NULL;
qsort(modes, mode_count, sizeof(*modes) + modes[0].dmDriverExtra, mode_compare);
for (mode_idx = 0; mode_idx < mode_count; ++mode_idx) for (mode_idx = 0; mode_idx < mode_count; ++mode_idx)
{ {
found_mode = (DEVMODEW *)((BYTE *)modes + (sizeof(*modes) + modes[0].dmDriverExtra) * mode_idx); found_mode = (DEVMODEW *)((BYTE *)modes + (sizeof(*modes) + modes[0].dmDriverExtra) * mode_idx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment