-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add F11 fullscreen toggle support #1879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4c866cd
98d50c2
d29ebc8
2a86c7d
626340a
553c343
83e4db2
8e55092
b21a007
806504e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,9 +29,11 @@ | |
| using System.Windows; | ||
| using System.Windows.Controls; | ||
| using System.Windows.Input; | ||
| using System.Windows.Interop; | ||
| using System.Windows.Media; | ||
| using System.Windows.Threading; | ||
| using Wpf.Ui.Controls; | ||
| using WinForms = System.Windows.Forms; | ||
| using MenuItem = System.Windows.Controls.MenuItem; | ||
|
|
||
| namespace QuickLook; | ||
|
|
@@ -62,6 +64,70 @@ internal void RunAndClose() | |
| Close(); | ||
| } | ||
|
|
||
| internal void ToggleFullscreen() | ||
| { | ||
| if (_isFullscreen) | ||
| { | ||
| // Exit fullscreen | ||
| _isFullscreen = false; | ||
|
|
||
| // Restore window properties | ||
| WindowStyle = _preFullscreenWindowStyle; | ||
| ResizeMode = _preFullscreenResizeMode; | ||
|
|
||
| // Restore position and size | ||
| Left = _preFullscreenBounds.Left; | ||
| Top = _preFullscreenBounds.Top; | ||
| Width = _preFullscreenBounds.Width; | ||
| Height = _preFullscreenBounds.Height; | ||
|
|
||
|
Comment on lines
+79
to
+83
|
||
| // Restore window state last to avoid flicker | ||
| WindowState = _preFullscreenWindowState; | ||
| } | ||
| else | ||
| { | ||
| // Enter fullscreen | ||
| _isFullscreen = true; | ||
|
|
||
| // Save current window properties before any changes | ||
| _preFullscreenWindowState = WindowState; | ||
| _preFullscreenWindowStyle = WindowStyle; | ||
| _preFullscreenResizeMode = ResizeMode; | ||
|
|
||
|
Comment on lines
+89
to
+96
|
||
| // Get current bounds (account for maximized state) | ||
| if (WindowState == WindowState.Maximized) | ||
| { | ||
| _preFullscreenBounds = RestoreBounds; | ||
| } | ||
| else | ||
| { | ||
| _preFullscreenBounds = new Rect(Left, Top, Width, Height); | ||
| } | ||
|
|
||
| // Get the screen bounds where the window is currently located | ||
| var screen = WinForms.Screen.FromHandle(new WindowInteropHelper(this).Handle); | ||
| var screenBounds = screen.Bounds; | ||
|
|
||
| // Get DPI scale factor for proper coordinate conversion | ||
| // scale.Horizontal and scale.Vertical contain the DPI scaling ratios (e.g., 1.5 for 150%) | ||
| var scale = DisplayDeviceHelper.GetScaleFactorFromWindow(this); | ||
|
|
||
| // Set to normal state first to allow manual positioning | ||
| WindowState = WindowState.Normal; | ||
|
|
||
| // Hide window chrome for true fullscreen | ||
| WindowStyle = WindowStyle.None; | ||
| ResizeMode = ResizeMode.NoResize; | ||
|
|
||
| // Convert screen bounds from physical pixels to DIPs for WPF | ||
| var dipWidth = screenBounds.Width / scale.Horizontal; | ||
| var dipHeight = screenBounds.Height / scale.Vertical; | ||
|
|
||
| // Use MoveWindow to set position and size with proper DPI handling | ||
| this.MoveWindow(screenBounds.Left, screenBounds.Top, dipWidth, dipHeight); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Screen coordinates are mixed between physical pixels and DIPs when calling Here |
||
| } | ||
| } | ||
|
|
||
| private void PositionWindow(Size size) | ||
| { | ||
| // If the window is now maximized, do not move it | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
F11 is handled on KeyDown, but low-level hooks receive auto-repeat WM_KEYDOWN events while the key is held. Holding F11 will likely spam toggle requests and rapidly flip fullscreen on/off. Consider de-bouncing (track an "F11 is down" flag like Space) or triggering fullscreen on KeyUp instead.