internal static bool WindowIsFullscreenOnDisplay(EditorWindow editorWindow, string windowTitle, SystemDisplay display) { EWFDebugging.StartTimer("WindowIsFullscreenOnDisplay"); EWFDebugging.Log("Checking if window is fullscreen on display. " + (editorWindow == null ? "WindowTitle: " + (windowTitle == null ? "null" : windowTitle) : "EditorWindow: " + editorWindow.GetWindowTitle() + " Identifier: " + editorWindow.GetIdentifierTitle()) + "\n"); IntPtr windowHandle = GetProcessWindow(null, editorWindow); LogWin32Error("Error getting window handle."); if (windowHandle == IntPtr.Zero) { EWFDebugging.Log("Couldn't find window handle. Zero pointer.\n"); return(false); } Rect winPhysBounds = GetWindowPhysicalBounds(windowHandle); Rect displayPhysBounds = display.PhysicalBounds; float padding = 1; winPhysBounds.xMin -= padding; winPhysBounds.xMax += padding; winPhysBounds.yMin -= padding; winPhysBounds.yMax += padding; EWFDebugging.LogTime("WindowIsFullscreenOnDisplay", false); return(winPhysBounds.Contains(displayPhysBounds)); }
private static IntPtr GetProcessWindow(string withClassName, EditorWindow editorWindow) { EWFDebugging.StartTimer("Getting Process Window"); IntPtr foundWindow = IntPtr.Zero; string searchTitle = editorWindow.GetIdentifierTitle(); var windowSearchPos = editorWindow.GetContainerPosition(true); foundWindow = GetProcessWindow(withClassName, searchTitle, windowSearchPos, true); //Find window only by title if couldn't find by position and title if (foundWindow == IntPtr.Zero) { foundWindow = GetProcessWindow(withClassName, searchTitle, new Rect(0, 0, 0, 0), true); } //Find window only by position if couldn't find by title if (foundWindow == IntPtr.Zero) { foundWindow = GetProcessWindow(withClassName, null, windowSearchPos, true); } EWFDebugging.LogLine("--Found EditorWindow: " + (foundWindow != IntPtr.Zero) + " with title: '" + searchTitle + "' (" + editorWindow.GetWindowType() + ")" + ", position: " + windowSearchPos); EWFDebugging.LogTime("Getting Process Window"); return(foundWindow); }
/// Makes sure a window covers the taskbar when it is fullscreen private static bool MakeWindowCoverTaskBar(EditorWindow editorWindow, string windowClass, string windowTitle, SystemDisplay display) { IntPtr windowHandle = IntPtr.Zero; EWFDebugging.StartTimer("Making window cover taskbar"); EWFDebugging.LogLine("Making window cover taskbar. " + (editorWindow == null ? "WindowTitle: " + (windowTitle == null ? "null" : windowTitle) : "EditorWindow: '" + editorWindow.GetWindowTitle() + "' Window Type: '" + editorWindow.GetType() + "' with class: '" + (windowClass == null ? "null" : windowClass) + "'")); if (editorWindow == null) { string fullscreenWindowClass = windowClass != null ? windowClass : "UnityPopupWndClass"; windowHandle = GetProcessWindow(fullscreenWindowClass, windowTitle, true); if (windowHandle == IntPtr.Zero) { windowHandle = GetProcessWindow(null, windowTitle, true); } } else { if (windowClass == null) { windowHandle = GetProcessWindow(editorWindow); } else { windowHandle = GetProcessWindow(windowClass, editorWindow); } } if (windowHandle == IntPtr.Zero) { EWFDebugging.LogError("Couldn't find window handle."); return(false); } IntPtr existingStyle = GetWindowLongPtr(windowHandle, GWL_STYLE); IntPtr existingExStyle = GetWindowLongPtr(windowHandle, GWL_EXSTYLE); if (editorWindow != null) { var state = EditorFullscreenState.FindWindowState(editorWindow); if (state.OriginalStyle == 0) { state.OriginalStyle = (int)existingStyle; } if (state.OriginalExStyle == 0) { state.OriginalExStyle = (int)existingExStyle; } } if (EWFDebugging.Enabled) { EWFDebugging.LogLine("before Style: " + WindowStyleToString(existingStyle)); EWFDebugging.LogLine("before ExStyle: " + WindowExStyleToString(existingExStyle)); } SetWindowLongPtr(windowHandle, GWL_STYLE, (IntPtr)(WS_POPUP | WS_VISIBLE | ((uint)existingStyle & (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPED)))); LogWin32Error("Error setting window style"); SetWindowLongPtr(windowHandle, GWL_EXSTYLE, (IntPtr)((uint)existingExStyle & (WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR))); LogWin32Error("Error setting window ex style"); SetWindowPos(windowHandle, IntPtr.Zero, (int)display.Bounds.x, (int)display.Bounds.y, (int)display.Bounds.width, (int)display.Bounds.height, SWP.NOZORDER | SWP.FRAMECHANGED | SWP.NOACTIVATE); LogWin32Error("Error setting window position"); if (EWFDebugging.Enabled) { existingStyle = GetWindowLongPtr(windowHandle, GWL_STYLE); existingExStyle = GetWindowLongPtr(windowHandle, GWL_EXSTYLE); EWFDebugging.LogLine("after Style: " + WindowStyleToString(existingStyle)); EWFDebugging.LogLine("after ExStyle: " + WindowExStyleToString(existingExStyle)); EWFDebugging.LogTime("Making window cover taskbar"); } return(true); }