From 97664100e8c9b5785513c4bdb421f0466be9508a Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Tue, 27 Dec 2022 21:40:52 +1300 Subject: [PATCH] Added ability to show display rotation for NVIDIA and Windows Added display rotation awareness to the Screen awareness parsing. This code is used to create the generic 'Screens' structures that are used to generate the display profile icons. This partially fixes #153. I still have to add the AMD configuration equivalent! --- DisplayMagician/Properties/AssemblyInfo.cs | 4 +- DisplayMagicianShared/ProfileItem.cs | 126 +++++++++++++++++++-- 2 files changed, 116 insertions(+), 14 deletions(-) diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index 5d08a1b..e647264 100644 --- a/DisplayMagician/Properties/AssemblyInfo.cs +++ b/DisplayMagician/Properties/AssemblyInfo.cs @@ -26,8 +26,8 @@ using System.Resources; [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] // Version information -[assembly: AssemblyVersion("2.5.0.332")] -[assembly: AssemblyFileVersion("2.5.0.332")] +[assembly: AssemblyVersion("2.5.0.336")] +[assembly: AssemblyFileVersion("2.5.0.336")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)] diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index 9eacca0..fddeb33 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -19,6 +19,14 @@ using System.ComponentModel; namespace DisplayMagicianShared { + public enum ScreenRotation + { + ROTATE_0, + ROTATE_90, + ROTATE_180, + ROTATE_270, + } + public struct ScreenPosition { public int ScreenX; @@ -43,6 +51,7 @@ namespace DisplayMagicianShared public int SpannedColumns; public int SpannedRows; public TaskBarLayout.TaskBarEdge TaskBarEdge; + public ScreenRotation Rotation; } public struct SpannedScreenPosition @@ -911,6 +920,7 @@ namespace DisplayMagicianShared screen.SpannedRows = (int)_nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].Rows; screen.SpannedColumns = (int)_nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].Columns; screen.Colour = spannedScreenColor; + screen.Rotation = ScreenRotation.ROTATE_0; // This is a combined surround/mosaic screen // We need to build the size of the screen to match it later so we check the MosaicViewports @@ -1021,6 +1031,7 @@ namespace DisplayMagicianShared screen.ScreenY = (int)overallY; screen.ScreenWidth = (int)overallWidth; screen.ScreenHeight = (int)overallHeight; + screen.Rotation = ScreenRotation.ROTATE_0; } } @@ -1048,8 +1059,38 @@ namespace DisplayMagicianShared screen.Name = displayId.ToString(); screen.ScreenX = displaySource.SourceModeInfo.Position.X; screen.ScreenY = displaySource.SourceModeInfo.Position.Y; - screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; - screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + //screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; + //screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + if (targetInfo.Details.Rotation == NV_ROTATE.ROTATE_0) + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.Rotation = ScreenRotation.ROTATE_0; + } + else if (targetInfo.Details.Rotation == NV_ROTATE.ROTATE_90) + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.Rotation = ScreenRotation.ROTATE_90; + } + else if (targetInfo.Details.Rotation == NV_ROTATE.ROTATE_180) + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.Rotation = ScreenRotation.ROTATE_180; + } + else if (targetInfo.Details.Rotation == NV_ROTATE.ROTATE_270) + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.Rotation = ScreenRotation.ROTATE_270; + } + else + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.Rotation = ScreenRotation.ROTATE_0; + } breakOuterLoop = true; break; } @@ -1150,8 +1191,8 @@ namespace DisplayMagicianShared screen.Colour = normalScreenColor; screen.ScreenX = displaySource.SourceModeInfo.Position.X; screen.ScreenY = displaySource.SourceModeInfo.Position.Y; - screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; - screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + //screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; + //screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; if (screen.ScreenWidth == 0) { SharedLogger.logger.Error($"ProfileItem/GetNVIDIAScreenPositions: The screen width is 0 and it shouldn't be! Skipping this display id #{targetInfo.DisplayId.ToString()}."); @@ -1161,6 +1202,37 @@ namespace DisplayMagicianShared SharedLogger.logger.Error($"ProfileItem/GetNVIDIAScreenPositions: The screen height is 0 and it shouldn't be! Skipping this display id #{targetInfo.DisplayId.ToString()}."); } + if (targetInfo.Details.Rotation == NV_ROTATE.ROTATE_0) + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.Rotation = ScreenRotation.ROTATE_0; + } + else if (targetInfo.Details.Rotation == NV_ROTATE.ROTATE_90 ) + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.Rotation = ScreenRotation.ROTATE_90; + } + else if (targetInfo.Details.Rotation == NV_ROTATE.ROTATE_180) + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.Rotation = ScreenRotation.ROTATE_180; + } + else if (targetInfo.Details.Rotation == NV_ROTATE.ROTATE_270) + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.Rotation = ScreenRotation.ROTATE_270; + } + else + { + screen.ScreenWidth = (int)displaySource.SourceModeInfo.Resolution.Width; + screen.ScreenHeight = (int)displaySource.SourceModeInfo.Resolution.Height; + screen.Rotation = ScreenRotation.ROTATE_0; + } + // If we're at the 0,0 coordinate then we're the primary monitor if (screen.ScreenX == 0 && screen.ScreenY == 0) { @@ -1539,18 +1611,48 @@ namespace DisplayMagicianShared //screen.DisplayConnector = displayMode.DisplayConnector; screen.ScreenX = displayMode.SourceMode.Position.X; screen.ScreenY = displayMode.SourceMode.Position.Y; - screen.ScreenWidth = (int)displayMode.SourceMode.Width; - screen.ScreenHeight = (int)displayMode.SourceMode.Height; - - // If we're at the 0,0 coordinate then we're the primary monitor - if (screen.ScreenX == 0 && screen.ScreenY == 0) + if (path.TargetInfo.Rotation == DISPLAYCONFIG_ROTATION.DISPLAYCONFIG_ROTATION_IDENTITY) { - screen.IsPrimary = true; - screen.Colour = primaryScreenColor; + screen.ScreenWidth = (int)displayMode.SourceMode.Width; + screen.ScreenHeight = (int)displayMode.SourceMode.Height; + screen.Rotation = ScreenRotation.ROTATE_0; + } + else if (path.TargetInfo.Rotation == DISPLAYCONFIG_ROTATION.DISPLAYCONFIG_ROTATION_ROTATE90) + { + // Portrait screen so need to change width and height + screen.ScreenWidth = (int)displayMode.SourceMode.Height; + screen.ScreenHeight = (int)displayMode.SourceMode.Width; + screen.Rotation = ScreenRotation.ROTATE_90; + } + else if (path.TargetInfo.Rotation == DISPLAYCONFIG_ROTATION.DISPLAYCONFIG_ROTATION_ROTATE180) + { + screen.ScreenWidth = (int)displayMode.SourceMode.Width; + screen.ScreenHeight = (int)displayMode.SourceMode.Height; + screen.Rotation = ScreenRotation.ROTATE_180; + } + else if (path.TargetInfo.Rotation == DISPLAYCONFIG_ROTATION.DISPLAYCONFIG_ROTATION_ROTATE270) + { + screen.ScreenWidth = (int)displayMode.SourceMode.Width; + screen.ScreenHeight = (int)displayMode.SourceMode.Height; + screen.Rotation = ScreenRotation.ROTATE_270; + } + else + { + screen.ScreenWidth = (int)displayMode.SourceMode.Width; + screen.ScreenHeight = (int)displayMode.SourceMode.Height; + screen.Rotation = ScreenRotation.ROTATE_0; } - break; } + + // If we're at the 0,0 coordinate then we're the primary monitor + if (screen.ScreenX == 0 && screen.ScreenY == 0) + { + screen.IsPrimary = true; + screen.Colour = primaryScreenColor; + } + break; } + foreach (ADVANCED_HDR_INFO_PER_PATH hdrInfo in _windowsDisplayConfig.DisplayHDRStates) {