I’m looking to fullscreen 3rd-party windows in a (hopefully) reliable and consistent way for a window manager project. The goal is to have the fullscreen window cover the taskbar completely.
My current approach is to set the window’s position and dimensions to match the current monitor. This works well for some windows, but for others, the taskbar ends up covering the bottom part of the window (see vid). Implementation:
use windows::Win32::{
Foundation::HWND,
Graphics::Gdi::{
GetMonitorInfoW, MonitorFromWindow, MONITORINFOEXW,
MONITOR_DEFAULTTONEAREST,
},
UI::WindowsAndMessaging::{
SetWindowPos, HWND_NOTOPMOST, SWP_FRAMECHANGED, SWP_NOACTIVATE,
SWP_NOCOPYBITS, SWP_NOSENDCHANGING,
},
};
pub fn set_fullscreen(window_handle: isize) -> anyhow::Result<()> {
let monitor_handle = unsafe {
MonitorFromWindow(HWND(window_handle), MONITOR_DEFAULTTONEAREST)
};
let mut monitor = MONITORINFOEXW::default();
monitor.monitorInfo.cbSize =
std::mem::size_of::<MONITORINFOEXW>() as u32;
unsafe {
GetMonitorInfoW(monitor_handle, &mut monitor as *mut _ as _)
}
.ok()?;
let monitor_rect = monitor.monitorInfo.rcMonitor;
unsafe {
SetWindowPos(
HWND(window_handle),
HWND_NOTOPMOST,
monitor_rect.left,
monitor_rect.top,
monitor_rect.right - monitor_rect.left,
monitor_rect.top - monitor_rect.bottom,
SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOCOPYBITS
| SWP_NOSENDCHANGING,
)
}?;
Ok(())
}
I’ve tried a couple other approaches based on Raymond Chen’s post on implementing fullscreen:
- Removing the
WS_OVERLAPPEDWINDOW
style: This does make the windows cover the taskbar, but it’s an intrusive change and sometimes causes the window to bug out. - Setting the z-order to
HWND_TOPMOST
: This also works to cover the taskbar, but forcing the window to be always on top isn’t ideal.
Interestingly, some windows (like Spotify and Visual Studio) can successfully overlap the taskbar despite having the WS_OVERLAPPEDWINDOW
style. Here’s a comparison of window styles for various apps in normal and fullscreen modes:
VSCode (normal) - Fullscreen with above implementation covers taskbar ✅
styles: MaximizeBox | Group | SizeBox | Caption | ClipSiblings | Visible
styles ex: WindowEdge
VSCode (built-in f11 fullscreen)
styles: MaximizeBox | Group | ClipSiblings | Visible
styles ex: Left
Chrome (normal) - Fullscreen with above implementation does not cover taskbar ❌
styles: OverlappedWindow | ClipChildren | ClipSiblings | Visible
styles ex: WindowEdge
Chrome (built-in f11 fullscreen)
styles: MaximizeBox | Group | SysMenu | ClipChildren | ClipSiblings | Visible
styles ex: Left
Obsidian (normal) - Fullscreen with above implementation covers taskbar ✅
styles: MaximizeBox | Group | SizeBox | Caption | ClipSiblings | Visible
styles ex: WindowEdge
Obsidian (built-in f11 fullscreen)
styles: MaximizeBox | Group | ClipSiblings | Visible
styles ex: Left
Spotify (normal) - Fullscreen with above implementation covers taskbar ✅
styles: OverlappedWindow | ClipChildren | ClipSiblings | Visible
styles ex: WindowEdge
File explorer (normal) - Fullscreen with above implementation does not cover taskbar ❌
styles: OverlappedWindow | ClipSiblings | Visible
styles ex: WindowEdge
File explorer (built-in f11 fullscreen)
styles: Group | SysMenu | ClipSiblings | Visible
styles ex: Left
Visual studio (normal) - Fullscreen with above implementation covers taskbar ✅
styles: OverlappedWindow | ClipChildren | ClipSiblings | Visible
styles ex: WindowEdge | AppWindow
Visual studio (built-in f11 fullscreen) - interestingly, no change
styles: OverlappedWindow | ClipChildren | ClipSiblings | Visible
styles ex: WindowEdge | AppWindow
Since some apps can properly fullscreen with WS_OVERLAPPEDWINDOW
, I’m wondering if there’s a way to achieve this behavior consistently across all windows.
What is the most reliable and consistent way to fullscreen a window so that it covers the taskbar completely?