Skip to content

Commit

Permalink
fix GetResolution() and therefore QT resolutions combobox and ambilight
Browse files Browse the repository at this point in the history
- Looks like we can't rely on SystemInformation.ScreenOrientation nor devMode.dmDisplayOrientation. Implemented a terrible hotfix...
  • Loading branch information
Valkirie committed Dec 7, 2023
1 parent 2fc0c6c commit 2bcfb34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
20 changes: 12 additions & 8 deletions HandheldCompanion/Managers/Desktop/DesktopScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,28 @@ public bool HasResolution(ScreenResolution resolution)
return resolutions.Count(a => a.Width == resolution.Width && a.Height == resolution.Height) > 0;
}

public ScreenResolution GetResolution(DMDO dmDisplayOrientation, int dmPelsWidth, int dmPelsHeight)
public ScreenResolution GetResolution(int dmPelsWidth, int dmPelsHeight)
{
int width = 0;
int height = 0;
// improve me
int width = dmPelsWidth > dmPelsHeight ? dmPelsWidth : dmPelsHeight;
int height = dmPelsWidth > dmPelsHeight ? dmPelsHeight : dmPelsWidth;

switch(dmDisplayOrientation)
// unreliable !
/*
switch(SystemInformation.ScreenOrientation)
{
case DMDO.DEFAULT:
case DMDO.D180:
case ScreenOrientation.Angle0:
case ScreenOrientation.Angle180:
width = dmPelsWidth;
height = dmPelsHeight;
break;
case DMDO.D270:
case DMDO.D90:
case ScreenOrientation.Angle90:
case ScreenOrientation.Angle270:
height = dmPelsWidth;
width = dmPelsHeight;
break;
}
*/

return resolutions.FirstOrDefault(a => a.Width == width && a.Height == height);
}
Expand Down
12 changes: 6 additions & 6 deletions HandheldCompanion/Managers/SystemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,24 @@ private static void onWMIEvent(object sender, EventArrivedEventArgs e)

private static void SystemEvents_DisplaySettingsChanged(object? sender, EventArgs e)
{
var PrimaryScreen = Screen.PrimaryScreen;
Screen PrimaryScreen = Screen.PrimaryScreen;

if (DesktopScreen is null || DesktopScreen.PrimaryScreen.DeviceName != PrimaryScreen.DeviceName)
{
// update current desktop screen
DesktopScreen = new DesktopScreen(PrimaryScreen);

// pull resolutions details
var resolutions = GetResolutions(DesktopScreen.PrimaryScreen.DeviceName);
List<Display> resolutions = GetResolutions(DesktopScreen.PrimaryScreen.DeviceName);

foreach (var mode in resolutions)
{
var res = new ScreenResolution(mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel);
ScreenResolution res = new ScreenResolution(mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel);

var frequencies = resolutions
List<int> frequencies = resolutions
.Where(a => a.dmPelsWidth == mode.dmPelsWidth && a.dmPelsHeight == mode.dmPelsHeight)
.Select(b => b.dmDisplayFrequency).Distinct().ToList();
foreach (var frequency in frequencies)
foreach (int frequency in frequencies)
res.Frequencies[frequency] = new ScreenFrequency(frequency);

if (!DesktopScreen.HasResolution(res))
Expand All @@ -223,7 +223,7 @@ private static void SystemEvents_DisplaySettingsChanged(object? sender, EventArg

// update current desktop resolution
DesktopScreen.devMode = GetDisplay(DesktopScreen.PrimaryScreen.DeviceName);
ScreenResolution ScreenResolution = DesktopScreen.GetResolution(DesktopScreen.devMode.dmDisplayOrientation, DesktopScreen.devMode.dmPelsWidth, DesktopScreen.devMode.dmPelsHeight);
ScreenResolution ScreenResolution = DesktopScreen.GetResolution(DesktopScreen.devMode.dmPelsWidth, DesktopScreen.devMode.dmPelsHeight);

ScreenRotation.Rotations oldOrientation = ScreenOrientation.rotation;

Expand Down

0 comments on commit 2bcfb34

Please sign in to comment.