Skip to content

Commit

Permalink
refactor: move set_skip_taskbar to Window
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed May 29, 2021
1 parent 8334170 commit d344825
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 22 deletions.
7 changes: 0 additions & 7 deletions src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@ pub use crate::platform_impl::hit_test;
pub trait WindowExtUnix {
/// Returns the `ApplicatonWindow` from gtk crate that is used by this window.
fn gtk_window(&self) -> &gtk::ApplicationWindow;

/// Removes the window icon from the task bar.
fn skip_taskbar(&self);
}

impl WindowExtUnix for Window {
fn gtk_window(&self) -> &gtk::ApplicationWindow {
&self.window.window
}

fn skip_taskbar(&self) {
self.window.skip_taskbar()
}
}
8 changes: 0 additions & 8 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ pub trait WindowExtWindows {

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

/// Removes the window icon from the task bar.
fn skip_taskbar(&self);
}

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

#[inline]
fn skip_taskbar(&self) {
self.window.skip_taskbar();
}
}

/// Additional methods on `WindowBuilder` that are specific to Windows.
Expand Down
3 changes: 3 additions & 0 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ impl Window {

pub fn request_user_attention(&self, _request_type: Option<window::UserAttentionType>) {}

#[inline]
pub fn set_skip_taskbar(&self, _skip: bool) {}

pub fn set_cursor_icon(&self, _: window::CursorIcon) {}

pub fn set_cursor_position(&self, _: Position) -> Result<(), error::ExternalError> {
Expand Down
4 changes: 4 additions & 0 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ impl Inner {
warn!("`Window::set_ime_position` is ignored on iOS")
}

pub fn set_skip_taskbar(&self, _skip: bool) {
warn!("`Window::set_skip_taskbar` is ignored on iOS")
}

pub fn request_user_attention(&self, _request_type: Option<UserAttentionType>) {
warn!("`Window::request_user_attention` is ignored on iOS")
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<T: 'static> EventLoop<T> {
window.set_urgency_hint(true)
}
}
WindowRequest::SkipTaskbar => window.set_skip_taskbar_hint(true),
WindowRequest::SetSkipTaskbar(skip) => window.set_skip_taskbar_hint(skip),
WindowRequest::CursorIcon(cursor) => {
if let Some(gdk_window) = window.get_window() {
let display = window.get_display();
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ impl Window {
todo!()
}

pub fn skip_taskbar(&self) {
pub fn set_skip_taskbar(&self, skip: bool) {
if let Err(e) = self
.window_requests_tx
.send((self.window_id, WindowRequest::SkipTaskbar))
.send((self.window_id, WindowRequest::SetSkipTaskbar(skip)))
{
log::warn!("Fail to send skip taskbar request: {}", e);
}
Expand Down Expand Up @@ -632,7 +632,7 @@ pub enum WindowRequest {
AlwaysOnTop(bool),
WindowIcon(Option<Icon>),
UserAttention(Option<UserAttentionType>),
SkipTaskbar,
SetSkipTaskbar(bool),
CursorIcon(Option<CursorIcon>),
WireUpEvents,
Redraw,
Expand Down
3 changes: 3 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,9 @@ impl UnownedWindow {
}
}

#[inline]
pub fn set_skip_taskbar(&self, _skip: bool) {}

#[inline]
// Allow directly accessing the current monitor internally without unwrapping.
pub(crate) fn current_monitor_inner(&self) -> RootMonitorHandle {
Expand Down
10 changes: 7 additions & 3 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ impl Window {
}

#[inline]
pub fn skip_taskbar(&self) {
pub fn set_skip_taskbar(&self, skip: bool) {
unsafe {
let mut taskbar_list: *mut ITaskbarList = std::mem::zeroed();
CoCreateInstance(
Expand All @@ -730,7 +730,11 @@ impl Window {
&ITaskbarList::uuidof(),
&mut taskbar_list as *mut _ as *mut _,
);
(*taskbar_list).DeleteTab(self.window.0);
if skip {
(*taskbar_list).DeleteTab(self.hwnd());
} else {
(*taskbar_list).AddTab(self.hwnd());
}
(*taskbar_list).Release();
}
}
Expand Down Expand Up @@ -996,7 +1000,7 @@ unsafe fn taskbar_mark_fullscreen(handle: HWND, fullscreen: bool) {
let mut task_bar_list = task_bar_list_ptr.get();

if task_bar_list == ptr::null_mut() {
use winapi::{shared::winerror::S_OK, Interface};
use winapi::shared::winerror::S_OK;

let hr = combaseapi::CoCreateInstance(
&CLSID_TaskbarList,
Expand Down
9 changes: 9 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,15 @@ impl Window {
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
self.window.request_user_attention(request_type)
}

/// Removes the window icon from the task bar.
///
/// ## Platform-specific
///
/// - **macOS/ iOS / Android:** Unsupported.
pub fn set_skip_taskbar(&self, skip: bool) {
self.window.set_skip_taskbar(skip);
}
}

/// Cursor functions.
Expand Down

0 comments on commit d344825

Please sign in to comment.