Zhiyi Zhang : winex11.drv: Sort display modes.

Alexandre Julliard julliard at winehq.org
Fri Jul 24 17:05:10 CDT 2020


Module: wine
Branch: master
Commit: a8b4cf7f2d3d1fbd79308a106a84e753cdac69e8
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=a8b4cf7f2d3d1fbd79308a106a84e753cdac69e8

Author: Zhiyi Zhang <zzhang at codeweavers.com>
Date:   Fri Jul 24 17:22:43 2020 +0800

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: Zhiyi Zhang <zzhang at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 28c405ae0e..0249575617 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);




More information about the wine-cvs mailing list