Skip to content
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

feat(Windows): add skip taskbar methods #2177

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre

# Unreleased

- On Widnows, added `WindowExtWindows::set_skip_taskbar` and `WindowBuilderExtWindows::with_skip_taskbar`.
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
- **Breaking:** Bump `ndk` version to 0.6, ndk-sys to `v0.3`, `ndk-glue` to `0.6`.
- Remove no longer needed `WINIT_LINK_COLORSYNC` environment variable.
- **Breaking:** Rename the `Exit` variant of `ControlFlow` to `ExitWithCode`, which holds a value to control the exit code after running. Add an `Exit` constant which aliases to `ExitWithCode(0)` instead to avoid major breakage. This shouldn't affect most existing programs.
Expand Down
17 changes: 17 additions & 0 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ pub trait WindowExtWindows {

/// Returns the current window theme.
fn theme(&self) -> Theme;

/// Whether to show or hide the window icon in the taskbar.
fn set_skip_taskbar(&self, skip: bool);
}

impl WindowExtWindows for Window {
Expand Down Expand Up @@ -124,6 +127,11 @@ impl WindowExtWindows for Window {
fn theme(&self) -> Theme {
self.window.theme()
}

#[inline]
fn set_skip_taskbar(&self, skip: bool) {
self.window.set_skip_taskbar(skip)
}
}

/// Additional methods on `WindowBuilder` that are specific to Windows.
Expand Down Expand Up @@ -173,6 +181,9 @@ pub trait WindowBuilderExtWindows {

/// Forces a theme or uses the system settings if `None` was provided.
fn with_theme(self, theme: Option<Theme>) -> WindowBuilder;

/// Whether show or hide the window icon in the taskbar.
fn with_skip_taskbar(self, skip: bool) -> WindowBuilder;
}

impl WindowBuilderExtWindows for WindowBuilder {
Expand Down Expand Up @@ -217,6 +228,12 @@ impl WindowBuilderExtWindows for WindowBuilder {
self.platform_specific.preferred_theme = theme;
self
}

#[inline]
fn with_skip_taskbar(mut self, skip: bool) -> WindowBuilder {
self.platform_specific.skip_taskbar = skip;
self
}
}

/// Additional methods on `MonitorHandle` that are specific to Windows.
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub no_redirection_bitmap: bool,
pub drag_and_drop: bool,
pub preferred_theme: Option<Theme>,
pub skip_taskbar: bool,
}

impl Default for PlatformSpecificWindowBuilderAttributes {
Expand All @@ -41,6 +42,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
no_redirection_bitmap: false,
drag_and_drop: true,
preferred_theme: None,
skip_taskbar: false,
}
}
}
Expand Down
44 changes: 41 additions & 3 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use winapi::{
objbase::COINIT_APARTMENTTHREADED,
ole2,
oleidl::LPDROPTARGET,
shobjidl_core::{CLSID_TaskbarList, ITaskbarList2},
shobjidl_core::{CLSID_TaskbarList, ITaskbarList, ITaskbarList2},
wingdi::{CreateRectRgn, DeleteObject},
winnt::{LPCWSTR, SHORT},
winuser,
Expand Down Expand Up @@ -651,6 +651,41 @@ impl Window {
self.window_state.lock().current_theme
}

#[inline]
pub fn set_skip_taskbar(&self, skip: bool) {
com_initialized();
unsafe {
TASKBAR_LIST.with(|task_bar_list_ptr| {
let mut task_bar_list = task_bar_list_ptr.get();

if task_bar_list.is_null() {
use winapi::{shared::winerror::S_OK, Interface};

let hr = combaseapi::CoCreateInstance(
&CLSID_TaskbarList,
ptr::null_mut(),
combaseapi::CLSCTX_ALL,
&ITaskbarList::uuidof(),
&mut task_bar_list as *mut _ as *mut _,
);

if hr != S_OK || (*task_bar_list).HrInit() != S_OK {
// In some old windows, the taskbar object could not be created, we just ignore it
return;
}
task_bar_list_ptr.set(task_bar_list)
}

task_bar_list = task_bar_list_ptr.get();
if skip {
(*task_bar_list).DeleteTab(self.window.0);
} else {
(*task_bar_list).AddTab(self.window.0);
}
});
}
}

#[inline]
pub fn focus_window(&self) {
let window = self.window.clone();
Expand Down Expand Up @@ -828,6 +863,8 @@ impl<'a, T: 'static> InitData<'a, T> {
DeleteObject(region as _);
}

win.set_skip_taskbar(self.pl_attribs.skip_taskbar);

let attributes = self.attributes.clone();

// Set visible before setting the size to ensure the
Expand Down Expand Up @@ -994,7 +1031,8 @@ thread_local! {
}
};

static TASKBAR_LIST: Cell<*mut ITaskbarList2> = Cell::new(ptr::null_mut());
static TASKBAR_LIST: Cell<*mut ITaskbarList> = Cell::new(ptr::null_mut());
static TASKBAR_LIST2: Cell<*mut ITaskbarList2> = Cell::new(ptr::null_mut());
}

pub fn com_initialized() {
Expand All @@ -1012,7 +1050,7 @@ pub fn com_initialized() {
unsafe fn taskbar_mark_fullscreen(handle: HWND, fullscreen: bool) {
com_initialized();

TASKBAR_LIST.with(|task_bar_list_ptr| {
TASKBAR_LIST2.with(|task_bar_list_ptr| {
let mut task_bar_list = task_bar_list_ptr.get();

if task_bar_list.is_null() {
Expand Down