Skip to content

Commit

Permalink
refactor(windows): only skip taskbar if needed when set_visible is …
Browse files Browse the repository at this point in the history
…called (#196)
  • Loading branch information
amrbashir authored Sep 1, 2021
1 parent bb0a597 commit c24593d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl WindowExtWindows for Window {

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

Expand Down
40 changes: 15 additions & 25 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,19 @@ impl Window {

#[inline]
pub fn set_visible(&self, visible: bool) {
let prev = self.is_visible();
let skip_taskbar = self.window_state.lock().skip_taskbar;
// Hidden window also skips taskbar, we need to check if it conflicts with skip_taskbar state
// If it's moving from visible to hidden, we need to unset skip_taskbar
if prev && !visible && skip_taskbar {
self.set_skip_taskbar(false, false);
}
let already_skipped = self.window_state.lock().already_skipped;

// If it's still the same, there's no need to set it again
if prev != visible {
let window = self.window.clone();
let window_state = Arc::clone(&self.window_state);
self.thread_executor.execute_in_thread(move || {
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
f.set(WindowFlags::VISIBLE, visible)
});
let window = self.window.clone();
let window_state = Arc::clone(&self.window_state);
self.thread_executor.execute_in_thread(move || {
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
f.set(WindowFlags::VISIBLE, visible)
});
}
});

// If it's moving from hidden to visible, we set skip_taskbar back
if !prev && visible && skip_taskbar {
self.set_skip_taskbar(true, false);
if visible && skip_taskbar != already_skipped {
self.set_skip_taskbar(skip_taskbar);
}
}

Expand Down Expand Up @@ -770,12 +761,9 @@ impl Window {
}

#[inline]
pub(crate) fn set_skip_taskbar(&self, skip: bool, state: bool) {
// Update self skip_taskbar state if true
if state {
let mut window_state = self.window_state.lock();
window_state.skip_taskbar = skip;
}
pub(crate) fn set_skip_taskbar(&self, skip: bool) {
let mut window_state = self.window_state.lock();
window_state.skip_taskbar = skip;

if self.is_visible() {
unsafe {
Expand All @@ -794,6 +782,8 @@ impl Window {
}
(*taskbar_list).Release();
}

window_state.already_skipped = skip
}
}
}
Expand Down Expand Up @@ -938,7 +928,7 @@ unsafe fn init<T: 'static>(
menu: None,
};

win.set_skip_taskbar(pl_attribs.skip_taskbar, false);
win.set_skip_taskbar(pl_attribs.skip_taskbar);

let dimensions = attributes
.inner_size
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/windows/window_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct WindowState {
pub window_flags: WindowFlags,

pub skip_taskbar: bool,
pub already_skipped: bool,
}

#[derive(Clone)]
Expand Down Expand Up @@ -135,6 +136,7 @@ impl WindowState {
window_flags: WindowFlags::empty(),

skip_taskbar,
already_skipped: false,
}
}

Expand Down

0 comments on commit c24593d

Please sign in to comment.