Skip to content

feat: add Display Profiles tab to switch resolution and refresh rate - #1079

Merged
laurentiu021 merged 1 commit into
mainfrom
feat/display-profiles
Jun 26, 2026
Merged

laurentiu021 merged 1 commit into
mainfrom
feat/display-profiles

Conversation

@laurentiu021

@laurentiu021 laurentiu021 commented Jun 26, 2026 •

Copy link
Copy Markdown
Owner

What

Implements Display Profiles (Gaming & Profiles), replacing its WIP placeholder. Closes #328.

Quick-switch resolution + refresh rate per monitor — e.g. 165 Hz for gaming, 60 Hz for work — from the list of modes the display actually supports.

How

  • DisplayProfileService — user32 display APIs: EnumDisplayDevicesW (list adapters), EnumDisplaySettingsW (current + supported modes), ChangeDisplaySettingsExW (apply). Validates each mode with CDS_TEST before applying. Applies for the session only (dwflags=0) so a reboot reverts; no admin required. Uses only Windows APIs — no NVIDIA/AMD SDK, so no vendor-tool conflict.
  • Interop note — classic [DllImport] with explicit EntryPoint="...W" + CharSet.Unicode (not [LibraryImport]): DEVMODE/DISPLAY_DEVICE have inline ByValTStr buffers (non-blittable) → SYSLIB1051. dmSize is set from Marshal.SizeOf before every call; the DEVMODE union is sized correctly for x64.
  • Safety (the important part) — applying starts a 15-second in-tab auto-revert (DispatcherTimer): the user must click Keep to retain the change, otherwise it restores the previous mode. A bad mode (e.g. unsupported refresh) can blank the panel, so a modal the user can't see would be useless — the countdown bar + session-only apply + reboot-reverts give three layers of safety.

Preview

Marked PREVIEW (sidebar pill + banner).

Tests

  • DisplayModeTests — resolution/refresh formatting, value equality, primary-display tagging.
  • Integration: NavLeaf_DisplayProfiles_IsImplementedAndMarkedPreview pins the WIP→real-view swap + preview flag.

Verification

  • Build main + unit + integration: 0/0. No generic/empty catch, no debug code. A/W P/Invokes have explicit ...W EntryPoints.
  • README + ARCHITECTURE updated (counts 42→43 implemented / 15→14 WIP; new service/VM described). feat: -> minor 1.37.0.

Future follow-up (out of scope)

HDR toggle + color profile use a different API family (CCD DisplayConfigSetDeviceInfo) and are noted for a later pass.

Implements Display Profiles (replaces its WIP placeholder in Gaming &
Profiles). Closes #328.

- DisplayProfileService: user32 display APIs (EnumDisplayDevicesW /
  EnumDisplaySettingsW / ChangeDisplaySettingsExW) to enumerate displays,
  list supported resolution+refresh modes, and apply one. Validates with
  CDS_TEST before applying; applies for the session (reverts on reboot);
  no admin. Classic [DllImport] with explicit ...W EntryPoint because
  DEVMODE/DISPLAY_DEVICE have non-blittable inline buffers (SYSLIB1051).
- DisplayProfileViewModel: per-display mode list + apply, with a
  15-second in-tab auto-revert (DispatcherTimer) that restores the
  previous mode unless the user confirms "Keep" — a bad mode can never
  strand the user on a blank screen.
- DisplayMode/DisplayDevice models hold the pure display formatting,
  unit-tested.
- Marked PREVIEW via the badge mechanism.

Uses only Windows display APIs (no NVIDIA/AMD SDK), so no vendor conflict.
HDR + color profile are noted as a future follow-up (separate CCD API).
try
{
var dd = new NativeMethods.DISPLAY_DEVICE { cb = (uint)Marshal.SizeOf<NativeMethods.DISPLAY_DEVICE>() };
for (uint i = 0; NativeMethods.EnumDisplayDevices(null, i, ref dd, 0); i++)
string friendly = dd.DeviceString;

var mon = new NativeMethods.DISPLAY_DEVICE { cb = (uint)Marshal.SizeOf<NativeMethods.DISPLAY_DEVICE>() };
if (NativeMethods.EnumDisplayDevices(adapter, 0, ref mon, 0) && !string.IsNullOrWhiteSpace(mon.DeviceString))
try
{
var dm = new NativeMethods.DEVMODE { dmSize = (ushort)Marshal.SizeOf<NativeMethods.DEVMODE>() };
if (NativeMethods.EnumDisplaySettings(deviceName, NativeMethods.EnumCurrentSettings, ref dm))
try
{
var dm = new NativeMethods.DEVMODE { dmSize = (ushort)Marshal.SizeOf<NativeMethods.DEVMODE>() };
for (int i = 0; NativeMethods.EnumDisplaySettings(deviceName, i, ref dm); i++)
try
{
var dm = new NativeMethods.DEVMODE { dmSize = (ushort)Marshal.SizeOf<NativeMethods.DEVMODE>() };
if (!NativeMethods.EnumDisplaySettings(deviceName, NativeMethods.EnumCurrentSettings, ref dm))
dm.dmDisplayFrequency = (uint)refreshHz;
dm.dmFields = NativeMethods.DM_PELSWIDTH | NativeMethods.DM_PELSHEIGHT | NativeMethods.DM_DISPLAYFREQUENCY;

int test = NativeMethods.ChangeDisplaySettingsEx(deviceName, ref dm, IntPtr.Zero, NativeMethods.CDS_TEST, IntPtr.Zero);
return false;
}

int apply = NativeMethods.ChangeDisplaySettingsEx(deviceName, ref dm, IntPtr.Zero, 0, IntPtr.Zero);

[DllImport("user32.dll", EntryPoint = "EnumDisplayDevicesW", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumDisplayDevices(string? lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);

[DllImport("user32.dll", EntryPoint = "EnumDisplaySettingsW", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
public static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);

[DllImport("user32.dll", EntryPoint = "ChangeDisplaySettingsExW", CharSet = CharSet.Unicode)]
public static extern int ChangeDisplaySettingsEx(string lpszDeviceName, ref DEVMODE lpDevMode, IntPtr hwnd, uint dwflags, IntPtr lParam);
@laurentiu021
laurentiu021 merged commit 0794256 into main Jun 26, 2026
4 checks passed
@laurentiu021
laurentiu021 deleted the feat/display-profiles branch June 26, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Gaming — Display Profile Switcher (refresh rate, HDR, resolution presets)

2 participants