Skip to content

Commit

Permalink
refactor: Revert d344825, move set_skip_taskbar behind platform-ext (
Browse files Browse the repository at this point in the history
…#118)

* refactor: Revert d344825, move `set_skip_taskbar` behind platform-ext

* fmt
  • Loading branch information
amrbashir committed Jul 6, 2021
1 parent a0ac707 commit a641d3a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .changes/skip_taskbar_platformext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"tao": patch
---
Revert d344825 and move `set_skip_taskbar` back behind a `WindowExtWindows` and `WindowExtUnix`.
7 changes: 7 additions & 0 deletions src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ use crate::window::Window;
pub trait WindowExtUnix {
/// Returns the `ApplicatonWindow` from gtk crate that is used by this window.
fn gtk_window(&self) -> &gtk::ApplicationWindow;

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

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

fn set_skip_taskbar(&self, skip: bool) {
self.window.set_skip_taskbar(skip);
}
}
30 changes: 30 additions & 0 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ pub trait WindowExtWindows {
/// this function can be called to reset the dead key state so that
/// follow-up text input won't be affected by the dead key.
fn reset_dead_keys(&self);

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

impl WindowExtWindows for Window {
Expand Down Expand Up @@ -143,6 +146,33 @@ impl WindowExtWindows for Window {
fn reset_dead_keys(&self) {
self.window.reset_dead_keys();
}

#[inline]
fn set_skip_taskbar(&self, skip: bool) {
use winapi::{
um::{
combaseapi::{CoCreateInstance, CLSCTX_SERVER},
shobjidl_core::{CLSID_TaskbarList, ITaskbarList},
},
Interface,
};
unsafe {
let mut taskbar_list: *mut ITaskbarList = std::mem::zeroed();
CoCreateInstance(
&CLSID_TaskbarList,
std::ptr::null_mut(),
CLSCTX_SERVER,
&ITaskbarList::uuidof(),
&mut taskbar_list as *mut _ as *mut _,
);
if skip {
(*taskbar_list).DeleteTab(self.hwnd() as _);
} else {
(*taskbar_list).AddTab(self.hwnd() as _);
}
(*taskbar_list).Release();
}
}
}

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

pub fn show_menu(&self) {}

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: 0 additions & 4 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,6 @@ 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
4 changes: 1 addition & 3 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ impl Window {
window.hide();
}

window.set_skip_taskbar_hint(attributes.skip_taskbar);

let w_pos = window.get_position();
let position: Rc<(AtomicI32, AtomicI32)> = Rc::new((w_pos.0.into(), w_pos.1.into()));
let position_clone = position.clone();
Expand Down Expand Up @@ -641,7 +639,7 @@ impl Window {
todo!()
}

pub fn set_skip_taskbar(&self, skip: bool) {
pub(crate) fn set_skip_taskbar(&self, skip: bool) {
if let Err(e) = self
.window_requests_tx
.send((self.window_id, WindowRequest::SetSkipTaskbar(skip)))
Expand Down
3 changes: 0 additions & 3 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,6 @@ impl UnownedWindow {
#[inline]
pub fn show_menu(&self) {}

#[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
22 changes: 0 additions & 22 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,26 +733,6 @@ impl Window {
self.window_state.lock().current_theme
}

#[inline]
pub fn set_skip_taskbar(&self, skip: bool) {
unsafe {
let mut taskbar_list: *mut ITaskbarList = std::mem::zeroed();
CoCreateInstance(
&CLSID_TaskbarList,
ptr::null_mut(),
CLSCTX_SERVER,
&ITaskbarList::uuidof(),
&mut taskbar_list as *mut _ as *mut _,
);
if skip {
(*taskbar_list).DeleteTab(self.hwnd());
} else {
(*taskbar_list).AddTab(self.hwnd());
}
(*taskbar_list).Release();
}
}

#[inline]
pub fn hide_menu(&self) {
unsafe {
Expand Down Expand Up @@ -973,8 +953,6 @@ unsafe fn init<T: 'static>(
force_window_active(win.window.0);
}

win.set_skip_taskbar(attributes.skip_taskbar);

Ok(win)
}

Expand Down
31 changes: 0 additions & 31 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,6 @@ pub struct WindowAttributes {
///
/// The default is `None`.
pub window_menu: Option<platform_impl::Menu>,

/// Whether or not the window icon should be added to the taskbar.
///
/// The default is `false`.
pub skip_taskbar: bool,
}

impl Default for WindowAttributes {
Expand All @@ -228,7 +223,6 @@ impl Default for WindowAttributes {
always_on_top: false,
window_icon: None,
window_menu: None,
skip_taskbar: false,
}
}
}
Expand Down Expand Up @@ -402,17 +396,6 @@ impl WindowBuilder {
self
}

/// Sets whether or not the window icon should be added to the taskbar.
///
/// See [`Window::set_skip_taskbar`] for details.
///
/// [`Window::set_skip_taskbar`]: crate::window::Window::set_skip_taskbar
#[inline]
pub fn with_skip_taskbar(mut self, skip: bool) -> Self {
self.window.skip_taskbar = skip;
self
}

/// Builds the window.
///
/// Possible causes of error include denied permission, incompatible system, and lack of memory.
Expand Down Expand Up @@ -854,20 +837,6 @@ impl Window {
pub fn show_menu(&self) {
self.window.show_menu();
}

/// Whether to show the window icon in the task bar or not.
///
/// ## Platform-specific
///
/// - **iOS / Android:** Unsupported.
///
/// On macOS, you need to change the activation policy with
/// `event_loop.set_activation_policy(ActivationPolicy::Accessory);`
/// The `set_skip_taskbar` have no effect.
///
pub fn set_skip_taskbar(&self, skip: bool) {
self.window.set_skip_taskbar(skip);
}
}

/// Cursor functions.
Expand Down

0 comments on commit a641d3a

Please sign in to comment.