|
29 | 29 | using System.Windows; |
30 | 30 | using System.Windows.Controls; |
31 | 31 | using System.Windows.Input; |
| 32 | +using System.Windows.Interop; |
32 | 33 | using System.Windows.Media; |
33 | 34 | using System.Windows.Threading; |
34 | 35 | using Wpf.Ui.Controls; |
| 36 | +using WinForms = System.Windows.Forms; |
35 | 37 | using MenuItem = System.Windows.Controls.MenuItem; |
36 | 38 |
|
37 | 39 | namespace QuickLook; |
@@ -62,6 +64,70 @@ internal void RunAndClose() |
62 | 64 | Close(); |
63 | 65 | } |
64 | 66 |
|
| 67 | + internal void ToggleFullscreen() |
| 68 | + { |
| 69 | + if (_isFullscreen) |
| 70 | + { |
| 71 | + // Exit fullscreen |
| 72 | + _isFullscreen = false; |
| 73 | + |
| 74 | + // Restore window properties |
| 75 | + WindowStyle = _preFullscreenWindowStyle; |
| 76 | + ResizeMode = _preFullscreenResizeMode; |
| 77 | + |
| 78 | + // Restore position and size |
| 79 | + Left = _preFullscreenBounds.Left; |
| 80 | + Top = _preFullscreenBounds.Top; |
| 81 | + Width = _preFullscreenBounds.Width; |
| 82 | + Height = _preFullscreenBounds.Height; |
| 83 | + |
| 84 | + // Restore window state last to avoid flicker |
| 85 | + WindowState = _preFullscreenWindowState; |
| 86 | + } |
| 87 | + else |
| 88 | + { |
| 89 | + // Enter fullscreen |
| 90 | + _isFullscreen = true; |
| 91 | + |
| 92 | + // Save current window properties before any changes |
| 93 | + _preFullscreenWindowState = WindowState; |
| 94 | + _preFullscreenWindowStyle = WindowStyle; |
| 95 | + _preFullscreenResizeMode = ResizeMode; |
| 96 | + |
| 97 | + // Get current bounds (account for maximized state) |
| 98 | + if (WindowState == WindowState.Maximized) |
| 99 | + { |
| 100 | + _preFullscreenBounds = RestoreBounds; |
| 101 | + } |
| 102 | + else |
| 103 | + { |
| 104 | + _preFullscreenBounds = new Rect(Left, Top, Width, Height); |
| 105 | + } |
| 106 | + |
| 107 | + // Get the screen bounds where the window is currently located |
| 108 | + var screen = WinForms.Screen.FromHandle(new WindowInteropHelper(this).Handle); |
| 109 | + var screenBounds = screen.Bounds; |
| 110 | + |
| 111 | + // Get DPI scale factor for proper coordinate conversion |
| 112 | + // scale.Horizontal and scale.Vertical contain the DPI scaling ratios (e.g., 1.5 for 150%) |
| 113 | + var scale = DisplayDeviceHelper.GetScaleFactorFromWindow(this); |
| 114 | + |
| 115 | + // Set to normal state first to allow manual positioning |
| 116 | + WindowState = WindowState.Normal; |
| 117 | + |
| 118 | + // Hide window chrome for true fullscreen |
| 119 | + WindowStyle = WindowStyle.None; |
| 120 | + ResizeMode = ResizeMode.NoResize; |
| 121 | + |
| 122 | + // Convert screen bounds from physical pixels to DIPs for WPF |
| 123 | + var dipWidth = screenBounds.Width / scale.Horizontal; |
| 124 | + var dipHeight = screenBounds.Height / scale.Vertical; |
| 125 | + |
| 126 | + // Use MoveWindow to set position and size with proper DPI handling |
| 127 | + this.MoveWindow(screenBounds.Left, screenBounds.Top, dipWidth, dipHeight); |
| 128 | + } |
| 129 | + } |
| 130 | + |
65 | 131 | private void PositionWindow(Size size) |
66 | 132 | { |
67 | 133 | // If the window is now maximized, do not move it |
|
0 commit comments