refactor: move set_skip_taskbar to Window

This commit is contained in:
amrbashir
2021-05-29 14:43:36 +02:00
parent 8334170184
commit d34482537d
9 changed files with 30 additions and 22 deletions

View File

@@ -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()
}
}

View File

@@ -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 {
@@ -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.

View File

@@ -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> {

View File

@@ -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")
}

View File

@@ -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();

View File

@@ -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);
}
@@ -632,7 +632,7 @@ pub enum WindowRequest {
AlwaysOnTop(bool),
WindowIcon(Option<Icon>),
UserAttention(Option<UserAttentionType>),
SkipTaskbar,
SetSkipTaskbar(bool),
CursorIcon(Option<CursorIcon>),
WireUpEvents,
Redraw,

View File

@@ -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 {

View File

@@ -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(
@@ -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();
}
}
@@ -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,

View File

@@ -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.