Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: ensure windows overlap the taskbar when fullscreen (#940)

Lars Bergerb5f1b5c5d031
diff --git a/packages/wm-platform/src/com.rs b/packages/wm-platform/src/com.rs
index 4303a480..774cef11 100644
--- a/packages/wm-platform/src/com.rs
+++ b/packages/wm-platform/src/com.rs
@@ -1,9 +1,12 @@
use anyhow::Context;
use windows::{
core::{ComInterface, IUnknown, IUnknown_Vtbl, GUID, HRESULT},
- Win32::System::Com::{
- CoCreateInstance, CoInitializeEx, CoUninitialize, IServiceProvider,
- CLSCTX_ALL, COINIT_APARTMENTTHREADED,
+ Win32::{
+ System::Com::{
+ CoCreateInstance, CoInitializeEx, CoUninitialize, IServiceProvider,
+ CLSCTX_ALL, CLSCTX_SERVER, COINIT_APARTMENTTHREADED,
+ },
+ UI::Shell::{ITaskbarList2, TaskbarList},
},
};
@@ -19,7 +22,11 @@ thread_local! {
pub static COM_INIT: ComInit = ComInit::new();
}
-pub struct ComInit();
+pub struct ComInit {
+ service_provider: Option<IServiceProvider>,
+ application_view_collection: Option<IApplicationViewCollection>,
+ taskbar_list: Option<ITaskbarList2>,
+}
impl ComInit {
/// Initializes COM on the current thread with apartment threading model.
@@ -34,7 +41,50 @@ impl ComInit {
unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) }
.expect("Unable to initialize COM.");
- Self()
+ let service_provider = unsafe {
+ CoCreateInstance(&CLSID_IMMERSIVE_SHELL, None, CLSCTX_ALL)
+ }
+ .ok();
+
+ let application_view_collection = service_provider.as_ref().and_then(
+ |provider: &IServiceProvider| unsafe {
+ provider.QueryService(&IApplicationViewCollection::IID).ok()
+ },
+ );
+
+ let taskbar_list =
+ unsafe { CoCreateInstance(&TaskbarList, None, CLSCTX_SERVER) }.ok();
+
+ Self {
+ service_provider,
+ application_view_collection,
+ taskbar_list,
+ }
+ }
+
+ /// Returns an instance of `IServiceProvider`.
+ pub fn service_provider(&self) -> anyhow::Result<IServiceProvider> {
+ self
+ .service_provider
+ .clone()
+ .context("Unable to create `IServiceProvider` instance.")
+ }
+
+ /// Returns an instance of `IApplicationViewCollection`.
+ pub fn application_view_collection(
+ &self,
+ ) -> anyhow::Result<IApplicationViewCollection> {
+ self.application_view_collection.clone().context(
+ "Failed to query for `IApplicationViewCollection` instance.",
+ )
+ }
+
+ /// Returns an instance of `ITaskbarList2`.
+ pub fn taskbar_list(&self) -> anyhow::Result<ITaskbarList2> {
+ self
+ .taskbar_list
+ .clone()
+ .context("Unable to create `ITaskbarList2` instance.")
}
}
@@ -50,26 +100,6 @@ impl Drop for ComInit {
}
}
-/// Returns an instance of `IServiceProvider`.
-pub fn iservice_provider() -> anyhow::Result<IServiceProvider> {
- COM_INIT.with(|_| unsafe {
- CoCreateInstance(&CLSID_IMMERSIVE_SHELL, None, CLSCTX_ALL)
- .context("Unable to create `IServiceProvider` instance.")
- })
-}
-
-/// Returns an instance of `IApplicationViewCollection`.
-pub fn iapplication_view_collection(
- provider: &IServiceProvider,
-) -> anyhow::Result<IApplicationViewCollection> {
- COM_INIT.with(|_| {
- unsafe { provider.QueryService(&IApplicationViewCollection::IID) }
- .context(
- "Failed to query for `IApplicationViewCollection` instance.",
- )
- })
-}
-
/// Undocumented COM interface for Windows shell functionality.
///
/// Note that filler methods are added to match the vtable layout.
diff --git a/packages/wm-platform/src/native_window.rs b/packages/wm-platform/src/native_window.rs
index f7caf2eb..e2fdb0a2 100644
--- a/packages/wm-platform/src/native_window.rs
+++ b/packages/wm-platform/src/native_window.rs
@@ -10,18 +10,14 @@ use windows::{
DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_DEFAULT, DWMWCP_DONOTROUND,
DWMWCP_ROUND, DWMWCP_ROUNDSMALL,
},
- System::{
- Com::{CoCreateInstance, CLSCTX_SERVER},
- Threading::{
- OpenProcess, QueryFullProcessImageNameW, PROCESS_NAME_WIN32,
- PROCESS_QUERY_LIMITED_INFORMATION,
- },
+ System::Threading::{
+ OpenProcess, QueryFullProcessImageNameW, PROCESS_NAME_WIN32,
+ PROCESS_QUERY_LIMITED_INFORMATION,
},
UI::{
Input::KeyboardAndMouse::{
SendInput, INPUT, INPUT_0, INPUT_MOUSE, MOUSEINPUT,
},
- Shell::{ITaskbarList, TaskbarList},
WindowsAndMessaging::{
EnumWindows, GetClassNameW, GetLayeredWindowAttributes, GetWindow,
GetWindowLongPtrW, GetWindowRect, GetWindowTextW,
@@ -47,7 +43,7 @@ use wm_common::{
Rect, RectDelta, WindowState,
};
-use super::{iapplication_view_collection, iservice_provider, COM_INIT};
+use super::COM_INIT;
/// Magic number used to identify programmatic mouse inputs from our own
/// process.
@@ -664,9 +660,8 @@ impl NativeWindow {
}
pub fn set_cloaked(&self, cloaked: bool) -> anyhow::Result<()> {
- COM_INIT.with(|_| -> anyhow::Result<()> {
- let view_collection =
- iapplication_view_collection(&iservice_provider()?)?;
+ COM_INIT.with(|com_init| -> anyhow::Result<()> {
+ let view_collection = com_init.application_view_collection()?;
let mut view = None;
unsafe { view_collection.get_view_for_hwnd(self.handle, &mut view) }
@@ -691,9 +686,8 @@ impl NativeWindow {
&self,
visible: bool,
) -> anyhow::Result<()> {
- COM_INIT.with(|_| -> anyhow::Result<()> {
- let taskbar_list: ITaskbarList =
- unsafe { CoCreateInstance(&TaskbarList, None, CLSCTX_SERVER)? };
+ COM_INIT.with(|com_init| -> anyhow::Result<()> {
+ let taskbar_list = com_init.taskbar_list()?;
if visible {
unsafe { taskbar_list.AddTab(HWND(self.handle))? };
@@ -814,6 +808,22 @@ impl NativeWindow {
Ok(())
}
+ /// Marks the window as fullscreen.
+ ///
+ /// Causes the native Windows taskbar to be moved to the bottom of the
+ /// z-order when this window is active.
+ pub fn mark_fullscreen(&self, fullscreen: bool) -> anyhow::Result<()> {
+ COM_INIT.with(|com_init| -> anyhow::Result<()> {
+ let taskbar_list = com_init.taskbar_list()?;
+
+ unsafe {
+ taskbar_list.MarkFullscreenWindow(HWND(self.handle), fullscreen)
+ }?;
+
+ Ok(())
+ })
+ }
+
pub fn set_z_order(&self, z_order: &ZOrder) -> anyhow::Result<()> {
let z_order = match z_order {
ZOrder::TopMost => HWND_TOPMOST,
diff --git a/packages/wm/src/commands/general/platform_sync.rs b/packages/wm/src/commands/general/platform_sync.rs
index 1723c386..d3e1f8d5 100644
--- a/packages/wm/src/commands/general/platform_sync.rs
+++ b/packages/wm/src/commands/general/platform_sync.rs
@@ -165,6 +165,7 @@ fn windows_to_bring_to_front(
Ok(windows_to_bring_to_front)
}
+#[allow(clippy::too_many_lines)]
fn redraw_containers(
focused_container: &Container,
state: &mut WmState,
@@ -278,6 +279,25 @@ fn redraw_containers(
warn!("Failed to set window position: {}", err);
}
+ // Whether the window is either transitioning to or from fullscreen.
+ // TODO: This check can be improved since `prev_state` can be
+ // fullscreen without it needing to be marked as not fullscreen.
+ let is_transitioning_fullscreen =
+ match (window.prev_state(), window.state()) {
+ (Some(_), WindowState::Fullscreen(s)) if !s.maximized => true,
+ (Some(WindowState::Fullscreen(_)), _) => true,
+ _ => false,
+ };
+
+ if is_transitioning_fullscreen {
+ if let Err(err) = window.native().mark_fullscreen(matches!(
+ window.state(),
+ WindowState::Fullscreen(_)
+ )) {
+ warn!("Failed to mark window as fullscreen: {}", err);
+ }
+ }
+
// Skip setting taskbar visibility if the window is hidden (has no
// effect). Since cloaked windows are normally always visible in the
// taskbar, we only need to set visibility if `show_all_in_taskbar` is