Ejemplo n.º 1
0
        public PathTarget(PathTargetInfo targetInfo, SurroundTopology surround = null)
        {
            DevicePath = targetInfo.DisplayTarget.DevicePath;
            var index = DevicePath.IndexOf("{", StringComparison.InvariantCultureIgnoreCase);

            if (index > 0)
            {
                DevicePath = DevicePath.Substring(0, index).TrimEnd('#');
            }

            FrequencyInMillihertz = targetInfo.FrequencyInMillihertz;
            Rotation         = targetInfo.Rotation.ToRotation();
            Scaling          = targetInfo.Scaling.ToScaling();
            ScanLineOrdering = targetInfo.ScanLineOrdering.ToScanLineOrdering();

            try
            {
                DisplayName = targetInfo.DisplayTarget.FriendlyName;
            }
            catch
            {
                DisplayName = null;
            }

            SurroundTopology = surround ?? SurroundTopology.FromPathTargetInfo(targetInfo);
        }
 public static SurroundTopology FromPathTargetInfo(PathTargetInfo pathTargetInfo)
 {
     // We go through the code if only the path belongs to a NVIDIA virtual surround display
     if (pathTargetInfo.DisplayTarget.EDIDManufactureCode != "NVS")
     {
         return(null);
     }
     try
     {
         var correspondingWindowsPathInfo =
             PathInfo.GetAllPaths()
             .FirstOrDefault(
                 info =>
                 info.TargetsInfo.Any(
                     targetInfo => targetInfo.DisplayTarget == pathTargetInfo.DisplayTarget));
         if (correspondingWindowsPathInfo != null)
         {
             // If position is same, then the two paths are equal, after all position is whats important in path sources
             var correspondingNvidiaPathInfo =
                 NvAPIWrapper.Display.PathInfo.GetDisplaysConfig()
                 .FirstOrDefault(
                     info =>
                     (info.Position.X == correspondingWindowsPathInfo.Position.X) &&
                     (info.Position.Y == correspondingWindowsPathInfo.Position.Y) &&
                     (info.Resolution.Width == correspondingWindowsPathInfo.Resolution.Width) &&
                     (info.Resolution.Height == correspondingWindowsPathInfo.Resolution.Height));
             if (correspondingNvidiaPathInfo != null)
             {
                 // We now assume that there is only one target for a NVS path
                 var correspondingNvidiaTargetInfo = correspondingNvidiaPathInfo.TargetsInfo.FirstOrDefault();
                 if (correspondingNvidiaTargetInfo != null)
                 {
                     var correspondingNvidiaTopology =
                         GridTopology.GetGridTopologies()
                         .FirstOrDefault(
                             topology =>
                             topology.Displays.Select(display => display.DisplayDevice)
                             .Contains(correspondingNvidiaTargetInfo.DisplayDevice));
                     if (correspondingNvidiaTopology != null)
                     {
                         return(new SurroundTopology(correspondingNvidiaTopology));
                     }
                 }
             }
         }
     }
     catch
     {
         // ignored
     }
     return(null);
 }
		//private TargetPreferredModeInformation preferredMode;



		internal DisplayConfigMonitorInfo( DisplayConfiguration displayConfiguration, PathTargetInfo info, TargetDeviceInformation targetDeviceName, bool supportsVirtualMode )
			: base( info.AdapterId, info.Id, displayConfiguration.Topology )
		{
			this.info = info;

			int modeInfoIndex;
			if( supportsVirtualMode )
			{
				modeInfoIndex = info.ModeInfoIndex2;
				if( modeInfoIndex == PathTargetInfo.InvalidModeInfoIndex2 )
					modeInfoIndex = PathTargetInfo.InvalidModeInfoIndex;
			}
			else
				modeInfoIndex = info.ModeInfoIndex;

			if( modeInfoIndex > PathTargetInfo.InvalidModeInfoIndex && modeInfoIndex < displayConfiguration.ModeInfo.Count )
				mode = displayConfiguration.ModeInfo[ modeInfoIndex ].VideoSignalInformation;

			displayName = targetDeviceName.FriendlyName;
			connectorInstance = targetDeviceName.ConnectorInstance;
			devicePath = targetDeviceName.DevicePath;
		}
        // ReSharper disable once ExcessiveIndentation
        public static SurroundTopology FromPathTargetInfo(PathTargetInfo pathTargetInfo)
        {
            // We go through the code if only the path belongs to a NVIDIA virtual surround display
            // TODO: Should we try to resolve every target info to be sure?
            if (pathTargetInfo.DisplayTarget.EDIDManufactureCode != "NVS" &&
                pathTargetInfo.DisplayTarget.FriendlyName != "NV Surround")
            {
                return(null);
            }

            try
            {
                // Get parent DisplayConfig PathInfo by checking display targets
                var correspondingWindowsPathInfo =
                    PathInfo.GetActivePaths()
                    .FirstOrDefault(
                        info =>
                        info.TargetsInfo.Any(
                            targetInfo =>
                            targetInfo.DisplayTarget == pathTargetInfo.DisplayTarget));

                if (correspondingWindowsPathInfo != null)
                {
                    // Get corresponding NvAPI PathInfo
                    // If position is same, then the two paths are equal, after all position is whats important in path sources
                    var correspondingNvidiaPathInfo =
                        NvAPIWrapper.Display.PathInfo.GetDisplaysConfig()
                        .FirstOrDefault(
                            info =>
                            info.Position.X == correspondingWindowsPathInfo.Position.X &&
                            info.Position.Y == correspondingWindowsPathInfo.Position.Y &&
                            info.Resolution.Width == correspondingWindowsPathInfo.Resolution.Width &&
                            info.Resolution.Height == correspondingWindowsPathInfo.Resolution.Height);

                    if (correspondingNvidiaPathInfo != null)
                    {
                        // Get corresponding NvAPI PathTargetInfo
                        // We now assume that there is only one target for a NvAPI PathInfo, in an other word, for now, it is not possible to have a cloned surround display
                        var correspondingNvidiaTargetInfo = correspondingNvidiaPathInfo.TargetsInfo.FirstOrDefault();

                        if (correspondingNvidiaTargetInfo != null)
                        {
                            // Get corresponding NvAPI Grid Topology
                            // We also assume that the NVS monitor uses a similar display id to one of real physical monitors
                            var correspondingNvidiaTopology =
                                GridTopology.GetGridTopologies()
                                .FirstOrDefault(
                                    topology => topology.Displays.Any(display =>
                                                                      display.DisplayDevice == correspondingNvidiaTargetInfo.DisplayDevice));

                            if (correspondingNvidiaTopology != null)
                            {
                                return(new SurroundTopology(correspondingNvidiaTopology));
                            }
                        }
                    }
                }
            }
            catch
            {
                // ignored
            }

            return(null);
        }