Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Dec 2, 2024
1 parent 78533b4 commit b40ea5e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
12 changes: 12 additions & 0 deletions packages/wm/src/common/commands/platform_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ fn redraw_containers(
) {
warn!("Failed to set window position: {}", err);
}

let taskbar_visibility = if config.value.general.show_all_in_taskbar {
true
} else {
is_visible
};

if let Err(err) =
window.native().set_taskbar_visibility(taskbar_visibility)
{
warn!("Failed to set taskbar visibility: {}", err);
}
}

Ok(())
Expand Down
39 changes: 32 additions & 7 deletions packages/wm/src/common/platform/native_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ use windows::{
DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_DEFAULT, DWMWCP_DONOTROUND,
DWMWCP_ROUND, DWMWCP_ROUNDSMALL,
},
System::Threading::{
OpenProcess, QueryFullProcessImageNameW, PROCESS_NAME_WIN32,
PROCESS_QUERY_LIMITED_INFORMATION,
System::{
Com::{CoCreateInstance, CLSCTX_SERVER},
Threading::{
OpenProcess, QueryFullProcessImageNameW, PROCESS_NAME_WIN32,
PROCESS_QUERY_LIMITED_INFORMATION,
},
},
UI::{
Input::KeyboardAndMouse::{SendInput, INPUT, INPUT_MOUSE},
Shell::{ITaskbarList, TaskbarList},
WindowsAndMessaging::{
EnumWindows, GetClassNameW, GetWindow, GetWindowLongPtrW,
GetWindowRect, GetWindowTextW, GetWindowThreadProcessId, IsIconic,
Expand Down Expand Up @@ -567,6 +571,29 @@ impl NativeWindow {
})
}

/// Adds or removes the window from the native taskbar.
///
/// Hidden windows (SW_HIDE) cannot be forced to be shown in the taskbar.
/// Cloaked windows are normally always shown in the taskbar, but can be
/// manually toggled.
pub fn set_taskbar_visibility(
&self,
visible: bool,
) -> anyhow::Result<()> {
COM_INIT.with(|_| -> anyhow::Result<()> {
let taskbar_list: ITaskbarList =
unsafe { CoCreateInstance(&TaskbarList, None, CLSCTX_SERVER)? };

if visible {
unsafe { taskbar_list.AddTab(HWND(self.handle))? };
} else {
unsafe { taskbar_list.DeleteTab(HWND(self.handle))? };
}

Ok(())
})
}

pub fn set_position(
&self,
state: &WindowState,
Expand Down Expand Up @@ -671,10 +698,8 @@ impl NativeWindow {
}
};

// Whether to show or hide the window.
self.set_visible(is_visible, hide_method)?;

Ok(())
// Whether to hide or show the window.
self.set_visible(is_visible, hide_method)
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/wm/src/user_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ pub struct GeneralConfig {
/// How windows should be hidden when switching workspaces.
#[serde(default)]
pub hide_method: HideMethod,

/// Affects which windows get shown in the native Windows taskbar.
#[serde(default = "default_bool::<false>")]
pub show_all_in_taskbar: bool,
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
Expand Down
8 changes: 6 additions & 2 deletions resources/assets/sample-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ general:
trigger: 'monitor_focus'

# How windows should be hidden when switching workspaces.
# - 'cloak': Recommended. Hides windows with no animation and keeps them
# visible in the taskbar.
# - 'cloak': Recommended. Hides windows with no animation.
# - 'hide': Legacy method (v3.5 and earlier) that has a brief animation,
# but has stability issues with some apps.
hide_method: 'cloak'

# Affects which windows get shown in the native Windows taskbar.
# - 'true': Show all windows (regardless of workspace).
# - 'false': Only show windows from the currently shown workspaces.
show_all_in_taskbar: false

gaps:
# Whether to scale the gaps with the DPI of the monitor.
scale_with_dpi: true
Expand Down

0 comments on commit b40ea5e

Please sign in to comment.