public static List <DisplayInfo> GetDisplays() { var list = new List <DisplayInfo>(); try { User32.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, (IntPtr hMonitor, IntPtr hdcMonitor, ref NativeRect lprcMonitor, IntPtr dwData) => { var mi = new MonitorInfoEx(); mi.Init(); mi.size = Marshal.SizeOf(mi); mi.size = 72; var success = User32.GetMonitorInfo(hMonitor, ref mi); if (success) { var di = new DisplayInfo(); di.MonitorArea = mi.monitor; di.WorkArea = mi.work; di.PrimaryDisplay = (mi.flags & 1) != 0; di.LogicalScreenHeight = GDI32.GetDeviceCaps(hMonitor, (int)GDI32.DeviceCap.VERTRES); di.PhysicalScreenHeight = GDI32.GetDeviceCaps(hMonitor, (int)GDI32.DeviceCap.DESKTOPVERTRES); // TransformToPixels(0, 0, out var x, out var y); uint dpiX; uint dpiY; try { ShCore.GetDpiForMonitor( hMonitor, MonitorDpiType.MDT_EFFECTIVE_DPI, out dpiX, out dpiY ); } catch { dpiX = 96; dpiY = 96; } di.scaleFactor2 = dpiX / 96f; list.Add(di); } else { Logger.Debug("Getting monitor info failed"); } return(true); }, IntPtr.Zero); AddAdditionalInfos(list); } catch (Exception e) { Logger.Exception(e); } return(list); }
/// <summary>Returns the rect of a given display index.</summary> public static Rect GetMonitorRect(int index) { if (!FullscreenUtility.IsWindows) { return(GetMainDisplayRect()); } var d = DisplayInfo.GetDisplay(index); if (d == null) { Logger.Error("Display {0} not connected", index + 1); return(GetMainDisplayRect()); } return(d.DpiCorrectedArea); }
/// <summary>Returns a rect with the dimensions of the main screen. /// (Note that the position may not be right for multiple screen setups)</summary> public static Rect GetMainDisplayRect() { if (FullscreenUtility.IsWindows) { var mainDisplay = DisplayInfo .GetDisplays() .FirstOrDefault(d => d.PrimaryDisplay); if (mainDisplay != null) { return(mainDisplay.DpiCorrectedArea); } Logger.Error("No main display??? This should not happen, falling back to Screen.currentResolution"); } // Screen.currentResolution returns the resolution of the screen where // the currently focused window is located, not the main display resolution. // This caused the bug #53 on windows. // The same behaviour was not tested on Linux as macOS return(new Rect(0f, 0f, Screen.currentResolution.width, Screen.currentResolution.height)); }
private static void MosaicMenuItem() { var openFullscreens = Fullscreen.GetAllFullscreen(); if (openFullscreens.Length > 0) { foreach (var fs in openFullscreens) { fs.Close(); } return; } var displays = DisplayInfo .GetDisplays() .Where(d => (d.displayDevice.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) != 0) .ToList(); for (var i = 0; i < displays.Count && i < 8; i++) { var candidate = FindCandidateForFullscreen(Types.GameView, FullscreenUtility.GetMainGameView()); if (candidate) { candidate = EditorWindow.Instantiate(candidate); candidate.Show(); } var fs = Fullscreen.MakeFullscreen(Types.GameView, candidate, true); var gameView = fs.ActualViewPyramid.Window; var targetDisplay = FullscreenPreferences.MosaicMapping.Value[i]; fs.Rect = displays[i].DpiCorrectedArea; FullscreenUtility.SetGameViewDisplayTarget(gameView, targetDisplay); } }