https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8d7a8f0ec106d5e6780cf…
commit 8d7a8f0ec106d5e6780cfd3ae974894027883a0a
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sat Jan 6 10:59:05 2024 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Jan 6 10:59:05 2024 +0900
[DESK] Find best display settings (#6288)
Based on KRosUser's desk.patch.
JIRA issue: CORE-18187, CORE-16878
- Add FindBestElement helper function.
- Use FindBestElement to find the best
display settings.
---
dll/cpl/desk/settings.c | 51 ++++++++++++++++++++++++++++++++++++-------------
1 file changed, 38 insertions(+), 13 deletions(-)
diff --git a/dll/cpl/desk/settings.c b/dll/cpl/desk/settings.c
index 602df32800b..aefaa9f6d6b 100644
--- a/dll/cpl/desk/settings.c
+++ b/dll/cpl/desk/settings.c
@@ -842,6 +842,34 @@ SwitchDisplayMode(HWND hwndDlg, PWSTR DeviceName, PSETTINGS_ENTRY
seInit, PSETTI
}
}
+static
+PSETTINGS_ENTRY
+FindBestElement(
+ _In_ PDISPLAY_DEVICE_ENTRY pDevice)
+{
+ PSETTINGS_ENTRY Request = &pDevice->InitialSettings, BestEntry = NULL,
Current;
+ LONG Distance, NearestDistance = MAXLONG;
+
+ /* Find the best entry in the list */
+ for (Current = pDevice->Settings; Current; Current = Current->Flink)
+ {
+ Distance = 0x100000 * labs(Current->dmBitsPerPel -
Request->dmBitsPerPel ) +
+ 0x100 * labs(Current->dmPelsWidth -
Request->dmPelsWidth ) +
+ 0x100 * labs(Current->dmPelsHeight -
Request->dmPelsHeight ) +
+ labs(Current->dmDisplayFrequency -
Request->dmDisplayFrequency);
+ if (Distance == 0)
+ return Current;
+
+ if (Distance < NearestDistance)
+ {
+ BestEntry = Current;
+ NearestDistance = Distance;
+ }
+ }
+
+ return BestEntry;
+}
+
static VOID
ApplyDisplaySettings(HWND hwndDlg, PSETTINGS_DATA pData)
{
@@ -866,10 +894,7 @@ ApplyDisplaySettings(HWND hwndDlg, PSETTINGS_DATA pData)
}
else
{
- pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth =
pData->CurrentDisplayDevice->InitialSettings.dmPelsWidth;
- pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight =
pData->CurrentDisplayDevice->InitialSettings.dmPelsHeight;
- pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel =
pData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel;
- pData->CurrentDisplayDevice->CurrentSettings->dmDisplayFrequency =
pData->CurrentDisplayDevice->InitialSettings.dmDisplayFrequency;
+ pData->CurrentDisplayDevice->CurrentSettings =
FindBestElement(pData->CurrentDisplayDevice);
UpdateDisplay(hwndDlg, pData, TRUE);
}
}
@@ -921,16 +946,16 @@ SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN
LPARAM lPar
DEVMODE devmode;
ZeroMemory(&devmode, sizeof(devmode));
devmode.dmSize = (WORD)sizeof(devmode);
- if
(EnumDisplaySettingsExW(pData->CurrentDisplayDevice->DeviceName,
ENUM_CURRENT_SETTINGS, &devmode, 0))
+ if
(EnumDisplaySettingsExW(pData->CurrentDisplayDevice->DeviceName,
+ ENUM_CURRENT_SETTINGS, &devmode, 0))
{
- pData->CurrentDisplayDevice->InitialSettings.dmPelsWidth =
devmode.dmPelsWidth;
- pData->CurrentDisplayDevice->InitialSettings.dmPelsHeight =
devmode.dmPelsHeight;
- pData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel =
devmode.dmBitsPerPel;
-
pData->CurrentDisplayDevice->InitialSettings.dmDisplayFrequency =
devmode.dmDisplayFrequency;
-
pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth =
pData->CurrentDisplayDevice->InitialSettings.dmPelsWidth;
-
pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight =
pData->CurrentDisplayDevice->InitialSettings.dmPelsHeight;
-
pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel =
pData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel;
-
pData->CurrentDisplayDevice->CurrentSettings->dmDisplayFrequency =
pData->CurrentDisplayDevice->InitialSettings.dmDisplayFrequency;
+ PSETTINGS_ENTRY pInitialSettings =
&pData->CurrentDisplayDevice->InitialSettings;
+ pInitialSettings->dmPelsWidth = devmode.dmPelsWidth;
+ pInitialSettings->dmPelsHeight = devmode.dmPelsHeight;
+ pInitialSettings->dmBitsPerPel = devmode.dmBitsPerPel;
+ pInitialSettings->dmDisplayFrequency =
devmode.dmDisplayFrequency;
+ pData->CurrentDisplayDevice->CurrentSettings =
+ FindBestElement(pData->CurrentDisplayDevice);
UpdateDisplay(hwndDlg, pData, TRUE);
}
}