Esempio n. 1
0
 public static Profile GetCurrent(string name = null)
 {
     _currentProfile = new Profile
     {
         Name  = name,
         Paths = PathInfo.GetActivePaths().Select(info => new Path(info)).ToArray()
     };
     return(_currentProfile);
 }
Esempio n. 2
0
        private static void DisplayConfig()
        {
            var navigation = new Dictionary <object, Action>
            {
                {
                    "DisplayConfig: Display Adapters",
                    () =>
                    {
                        ConsoleNavigation.PrintObject(PathDisplayAdapter.GetAdapters(),
                                                      "PathDisplayAdapter.GetAdapters()");
                    }
                },
                {
                    "DisplayConfig: Display Sources",
                    () =>
                    {
                        ConsoleNavigation.PrintObject(PathDisplaySource.GetDisplaySources(),
                                                      "PathDisplaySource.GetDisplaySources()");
                    }
                },
                {
                    "DisplayConfig: Display Targets",
                    () =>
                    {
                        ConsoleNavigation.PrintObject(PathDisplayTarget.GetDisplayTargets(),
                                                      "PathDisplayTarget.GetDisplayTargets()");
                    }
                },
                {
                    "DisplayConfig: Active Paths",
                    () =>
                    {
                        ConsoleNavigation.PrintObject(PathInfo.GetActivePaths(),
                                                      pathInfo =>
                        {
                            ConsoleNavigation.PrintObject(pathInfo.TargetsInfo,
                                                          targetInfo =>
                            {
                                ConsoleNavigation.PrintObject(targetInfo.SignalInfo, "PathTargetInfo.SignalInfo");
                            }, "PathInfo.TargetsInfo",
                                                          "Select a PathTargetInfo to see target signal information.");
                        },
                                                      "PathInfo.GetActivePaths()", "Select a PathInfo to see associated targets.");
                    }
                },
                {
                    "DisplayConfig: Go Saved Clone",
                    () => { PathInfo.ApplyTopology(DisplayConfigTopologyId.Clone, true); }
                },
                {
                    "DisplayConfig: Go Saved Extend",
                    () => { PathInfo.ApplyTopology(DisplayConfigTopologyId.Extend, true); }
                },
                {
                    "DisplayConfig: Extend All Displays",
                    () =>
                    {
                        var sourceId    = 0u;
                        var lastWidth   = 0;
                        var pathInfos   = new List <PathInfo>();
                        var pathTargets =
                            PathDisplayTarget.GetDisplayTargets().Select(
                                target =>
                                new Tuple <Size, PathTargetInfo>(
                                    target.PreferredResolution,
                                    new PathTargetInfo(
                                        target,
                                        target.PreferredSignalMode,
                                        DisplayConfigRotation.Identity,
                                        DisplayConfigScaling.Identity))).ToList();
                        foreach (var targetPairs in pathTargets)
                        {
                            var source = new PathDisplaySource(targetPairs.Item2.DisplayTarget.Adapter, sourceId);
                            pathInfos.Add(new PathInfo(source, new Point(lastWidth, 0), targetPairs.Item1,
                                                       DisplayConfigPixelFormat.PixelFormat32Bpp, new[] { targetPairs.Item2 }));
                            lastWidth += targetPairs.Item1.Width;
                            sourceId++;
                        }
                        PathInfo.ApplyPathInfos(pathInfos.ToArray());
                    }
                },
                {
                    "DisplayConfig: Clone All Compatible Displays Together",
                    () =>
                    {
                        var pathTargets = new Dictionary <Tuple <Size, PathDisplayAdapter>, List <PathTargetInfo> >();
                        foreach (var target in PathDisplayTarget.GetDisplayTargets())
                        {
                            var key = new Tuple <Size, PathDisplayAdapter>(target.PreferredResolution, target.Adapter);
                            if (!pathTargets.ContainsKey(key))
                            {
                                pathTargets.Add(key, new List <PathTargetInfo>());
                            }
                            pathTargets[key].Add(new PathTargetInfo(
                                                     target,
                                                     target.PreferredSignalMode,
                                                     DisplayConfigRotation.Identity,
                                                     DisplayConfigScaling.Identity));
                        }
                        var pathInfos = new List <PathInfo>();
                        var sourceId  = 0u;
                        var lastWidth = 0;
                        foreach (var targetPairs in pathTargets.OrderByDescending(pair => pair.Value.Count))
                        {
                            var source = new PathDisplaySource(targetPairs.Key.Item2, sourceId);
                            pathInfos.Add(new PathInfo(source, new Point(lastWidth, 0), targetPairs.Key.Item1,
                                                       DisplayConfigPixelFormat.PixelFormat32Bpp, targetPairs.Value.ToArray()));
                            lastWidth += targetPairs.Key.Item1.Width;
                            sourceId++;
                        }
                        PathInfo.ApplyPathInfos(pathInfos.ToArray());
                    }
                },
                {
                    "DisplayConfig: Disable All Except Primary Path",
                    () =>
                    {
                        var pathInfos = PathInfo.GetActivePaths();
                        PathInfo.ApplyPathInfos(new[] { pathInfos.First(info => info.IsGDIPrimary) });
                    }
                }
            };

            ConsoleNavigation.PrintNavigation(navigation, "DisplayConfig functions",
                                              "Select a DisplayConfig sample.");
        }
        // 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);
        }
Esempio n. 4
0
        private static void Main(string[] args)
        {
            _writer = new StreamWriter(new FileStream(
                                           string.Format("HeliosDisplayManagement.Reporting.{0}.log", Process.GetCurrentProcess().Id),
                                           FileMode.CreateNew));

            try
            {
                Dump(DisplayAdapter.GetDisplayAdapters(), "WindowsDisplayAPI.DisplayAdapter.GetDisplayAdapters()");
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(Display.GetDisplays(), "WindowsDisplayAPI.Display.GetDisplays()", new[]
                {
                    new Tuple <Func <Display, object>, string>(display => display.GetPossibleSettings(),
                                                               "GetPossibleSettings()")
                });
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(UnAttachedDisplay.GetUnAttachedDisplays(),
                     "WindowsDisplayAPI.UnAttachedDisplay.GetUnAttachedDisplays()");
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(PathDisplayAdapter.GetAdapters(),
                     "WindowsDisplayAPI.DisplayConfig.PathDisplayAdapter.GetAdapters()",
                     new[]
                {
                    new Tuple <Func <PathDisplayAdapter, object>, string>(adapter => adapter.ToDisplayAdapter(),
                                                                          "ToDisplayAdapter()")
                });
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(PathDisplaySource.GetDisplaySources(),
                     "WindowsDisplayAPI.DisplayConfig.PathDisplaySource.GetDisplaySources()", new[]
                {
                    new Tuple <Func <PathDisplaySource, object>, string>(source => source.ToDisplayDevices(),
                                                                         "ToDisplayDevices()")
                });
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(PathDisplayTarget.GetDisplayTargets(),
                     "WindowsDisplayAPI.DisplayConfig.PathDisplayTarget.GetDisplayTargets()", new[]
                {
                    new Tuple <Func <PathDisplayTarget, object>, string>(target => target.ToDisplayDevice(),
                                                                         "ToDisplayDevice()")
                });
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                if (PathInfo.IsSupported)
                {
                    Dump(PathInfo.GetActivePaths(), "WindowsDisplayAPI.DisplayConfig.PathInfo.GetActivePaths()", null,
                         2);
                }
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(LogicalGPU.GetLogicalGPUs(), "NvAPIWrapper.GPU.LogicalGPU.GetLogicalGPUs()", null, 1);
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(PhysicalGPU.GetPhysicalGPUs(), "NvAPIWrapper.GPU.PhysicalGPU.GetPhysicalGPUs()");
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(NvAPIWrapper.Display.Display.GetDisplays(), "NvAPIWrapper.Display.Display.GetDisplays()", new[]
                {
                    new Tuple <Func <NvAPIWrapper.Display.Display, object>, string>(
                        display => display.GetSupportedViews(),
                        "GetSupportedViews()")
                });
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(NvAPIWrapper.Display.UnAttachedDisplay.GetUnAttachedDisplays(),
                     "NvAPIWrapper.Display.UnAttachedDisplay.GetUnAttachedDisplays()");
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(NvAPIWrapper.Display.PathInfo.GetDisplaysConfig(),
                     "NvAPIWrapper.Display.PathInfo.GetDisplaysConfig()",
                     null, 3);
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            try
            {
                Dump(GridTopology.GetGridTopologies(), "NvAPIWrapper.Mosaic.GridTopology.GetGridTopologies()", null, 3);
            }
            catch (Exception e)
            {
                WriteException(e);
            }


            try
            {
                Dump(Profile.GetAllProfiles(), "HeliosDisplayManagement.Shared.Profile.GetAllProfiles()", null, 99);
            }
            catch (Exception e)
            {
                WriteException(e);
            }

            _writer.Flush();
            _writer.Close();
            _writer.Dispose();

            Console.WriteLine(@"Done, press enter to exit.");
            Console.ReadLine();
        }