void App_Startup(object sender, StartupEventArgs e) { // Check for duplicate launch of application String thisprocessname = Process.GetCurrentProcess().ProcessName; if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1) { App.Current.Shutdown(); } // Initiating each screen tooltip CommonData.dataInstance.Screen1TooltipData = Screen.AllScreens[0].Bounds; CommonData.dataInstance.Screen2TooltipData = (Screen.AllScreens.Length > 1) ? Screen.AllScreens[1].Bounds : new Rectangle(); CommonData.dataInstance.Screen3TooltipData = (Screen.AllScreens.Length > 2) ? Screen.AllScreens[2].Bounds : new Rectangle(); CommonData.dataInstance.Screen4TooltipData = (Screen.AllScreens.Length > 3) ? Screen.AllScreens[3].Bounds : new Rectangle(); CommonData.dataInstance.Screen5TooltipData = (Screen.AllScreens.Length > 4) ? Screen.AllScreens[4].Bounds : new Rectangle(); CommonData.dataInstance.Screen6TooltipData = (Screen.AllScreens.Length > 5) ? Screen.AllScreens[5].Bounds : new Rectangle(); //bool result = System.Windows.UI.ViewManagement.ApplicationViewScaling.TrySetDisableLayoutScaling(true); // Hook for listen to Windows Keys kh = new KeyboardHook(false); kh.KeyDown += Kh_KeyDown; kh.hook(); try { CommonData.dataInstance.Displays = PathDisplayTarget.GetDisplayTargets(); } catch (Exception) { } }
public PathDisplayTarget GetTargetInfo() { return (PathDisplayTarget.GetDisplayTargets() .Where(target => target.DevicePath.StartsWith(Path)) .OrderByDescending(target => target.IsAvailable) .FirstOrDefault()); }
private void PrintDisplayInfo() //debugging print method { Console.WriteLine("Friendly Name: " + state.FriendlyName); Console.WriteLine("Manufacture ID: " + state.MId); Console.WriteLine("Manufacture Code: " + state.MCode); Console.WriteLine("Product Code: " + state.ProductId); Console.WriteLine("Display Amount: " + PathDisplayTarget.GetDisplayTargets().Count()); }
public static List <PathDisplayTarget> GetMonitors() { //WindowsDisplayAPI does not return disabled monitors, while PathDisplayTarget does. Hence we use WindowsDisplayAPI to filter out the //inactive monitors that PathDisplayTarget returns var formsMonitorsDevicePaths = WindowsDisplayAPI.Display.GetDisplays().Select(monitor => monitor.DevicePath); var enabledMonitors = PathDisplayTarget.GetDisplayTargets().Where(monitor => formsMonitorsDevicePaths.Contains(monitor.DevicePath)); return(enabledMonitors.OrderBy(monitor => monitor.FriendlyName).ToList()); }
private MonitorState CaptureState() //returns the monitor currently in use { string name = "", mCode = ""; int code = 0, mid = 0; var list = PathDisplayTarget.GetDisplayTargets(); var target = list[list.Length - 1]; //last monitor is the one in use name = target.FriendlyName; mCode = target.EDIDManufactureCode; mid = target.EDIDManufactureId; code = target.EDIDProductCode; //we also attach the time the snapshot was taken so we know if we need to recheck return(new MonitorState(name, mCode, code, mid, DateTimeOffset.Now.ToUnixTimeMilliseconds())); }
public PathTargetInfo ToPathTargetInfo() { var targetDevice = PathDisplayTarget.GetDisplayTargets() .FirstOrDefault( target => target.DevicePath.StartsWith(DevicePath, StringComparison.InvariantCultureIgnoreCase)); if (targetDevice == null) { return(null); } return(new PathTargetInfo(new PathDisplayTarget(targetDevice.Adapter, targetDevice.TargetId), FrequencyInMillihertz, ScanLineOrdering, Rotation.ToDisplayConfigRotation(), Scaling)); }
public static TaskBarStuckRectangle GetCurrent(PathDisplayTarget pathTargetInfo) { var devicePath = pathTargetInfo?.DevicePath; var index = devicePath?.IndexOf("{", StringComparison.InvariantCultureIgnoreCase); if (index > 0) { devicePath = devicePath.Substring(0, index.Value).TrimEnd('#'); } index = devicePath?.IndexOf("#", StringComparison.InvariantCultureIgnoreCase); if (index > 0) { devicePath = devicePath.Substring(index.Value).TrimStart('#'); } return(GetCurrent(devicePath)); }
/// <summary> /// Update all screens names on application launch, and handle visibility of information on params window /// </summary> private void updateScreenNames() { if (Screen.AllScreens.Length > 0) { PathDisplayTarget display = CommonData.dataInstance.findDisplayByScreenName(Screen.AllScreens[0].DeviceName); if (display != null) { CommonData.dataInstance.Screen1Name = display.FriendlyName; tbScreen1Name.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); } // Case of Windows not sending back any screen 1 name if (CommonData.dataInstance.Screen1Name.Length == 0) { CommonData.dataInstance.Screen1Name = "No screen name"; } // Update label for image usage, instead of black color if (!String.IsNullOrEmpty(CommonData.dataInstance.ImageFileNameScreen1)) { tbScreen1SetImage.Text = "Stop using image"; } else { tbScreen1SetImage.Text = "Set image"; } } if (Screen.AllScreens.Length > 1) { PathDisplayTarget display = CommonData.dataInstance.findDisplayByScreenName(Screen.AllScreens[1].DeviceName); if (display != null) { CommonData.dataInstance.Screen2Name = display.FriendlyName; tbScreen1Name.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); } // Update label for image usage, instead of black color if (!String.IsNullOrEmpty(CommonData.dataInstance.ImageFileNameScreen2)) { tbScreen2SetImage.Text = "Stop using image"; } else { tbScreen2SetImage.Text = "Set image"; } } if (Screen.AllScreens.Length > 2) { PathDisplayTarget display = CommonData.dataInstance.findDisplayByScreenName(Screen.AllScreens[2].DeviceName); if (display != null) { CommonData.dataInstance.Screen3Name = display.FriendlyName; tbScreen1Name.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); } // Update label for image usage, instead of black color if (!String.IsNullOrEmpty(CommonData.dataInstance.ImageFileNameScreen3)) { tbScreen3SetImage.Text = "Stop using image"; } else { tbScreen3SetImage.Text = "Set image"; } } if (Screen.AllScreens.Length > 3) { tbScreen4Name.Visibility = Visibility.Visible; PathDisplayTarget display = CommonData.dataInstance.findDisplayByScreenName(Screen.AllScreens[3].DeviceName); if (display != null) { CommonData.dataInstance.Screen4Name = display.FriendlyName; tbScreen1Name.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); } } if (Screen.AllScreens.Length > 4) { tbScreen4Name.Visibility = Visibility.Visible; PathDisplayTarget display = CommonData.dataInstance.findDisplayByScreenName(Screen.AllScreens[4].DeviceName); if (display != null) { CommonData.dataInstance.Screen5Name = display.FriendlyName; tbScreen1Name.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); } } if (Screen.AllScreens.Length > 5) { tbScreen4Name.Visibility = Visibility.Visible; PathDisplayTarget display = CommonData.dataInstance.findDisplayByScreenName(Screen.AllScreens[5].DeviceName); if (display != null) { CommonData.dataInstance.Screen6Name = display.FriendlyName; tbScreen1Name.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); } } tbScreen2AltKeyInfo.Visibility = (Screen.AllScreens.Length > 1) ? Visibility.Visible : Visibility.Hidden; tbScreen2Name.Visibility = (Screen.AllScreens.Length > 1) ? Visibility.Visible : Visibility.Collapsed; tbScreen2SetImage.Visibility = (Screen.AllScreens.Length > 1) ? Visibility.Visible : Visibility.Collapsed; tbScreen3AltKeyInfo.Visibility = (Screen.AllScreens.Length > 2) ? Visibility.Visible : Visibility.Hidden; tbScreen3Name.Visibility = (Screen.AllScreens.Length > 2) ? Visibility.Visible : Visibility.Collapsed; tbScreen3SetImage.Visibility = (Screen.AllScreens.Length > 2) ? Visibility.Visible : Visibility.Collapsed; tbScreen4AltKeyInfo.Visibility = (Screen.AllScreens.Length > 3) ? Visibility.Visible : Visibility.Hidden; // Collapsed used to hide complete line (screen 4,5,6) if there is not at least 4 screens used (presume large majority of users cases!) tbScreen4Name.Visibility = (Screen.AllScreens.Length > 3) ? Visibility.Visible : Visibility.Collapsed; tbScreen5AltKeyInfo.Visibility = (Screen.AllScreens.Length > 4) ? Visibility.Visible : Visibility.Collapsed; tbScreen5Name.Visibility = (Screen.AllScreens.Length > 4) ? Visibility.Visible : Visibility.Collapsed; tbScreen6AltKeyInfo.Visibility = (Screen.AllScreens.Length > 5) ? Visibility.Visible : Visibility.Collapsed; tbScreen6Name.Visibility = (Screen.AllScreens.Length > 5) ? Visibility.Visible : Visibility.Collapsed; }
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."); }
/// <summary> /// Returns the corresponding PathDisplayTarget instance /// </summary> /// <returns>An instance of PathDisplayTarget, or null</returns> public PathDisplayTarget ToPathDisplayTarget() { return(PathDisplayTarget .GetDisplayTargets() .FirstOrDefault(target => target.DevicePath.Equals(DevicePath))); }
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(); }