Skip to content

Commit

Permalink
Fix Window::set_minimized(false) on Windows
Browse files Browse the repository at this point in the history
When other application minimized the winit window the
minimize state was going out of sync. This commit fixes
it by polling the state in `set_minimized`.
  • Loading branch information
amrbashir authored Jan 17, 2023
1 parent 7d626d9 commit 067535e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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 Windows, fix `Window::set_minimized(false)` not working for windows minimized by `Win + D` hotkey.
- **Breaking:** On Web, touch input no longer fires `WindowEvent::Cursor*`, `WindowEvent::MouseInput`, or `DeviceEvent::MouseMotion` like other platforms, but instead it fires `WindowEvent::Touch`.
- **Breaking:** Removed platform specific `WindowBuilder::with_parent` API in favor of `WindowBuilder::with_parent_window`.
- On Windows, retain `WS_MAXIMIZE` window style when un-minimizing a maximized window.
Expand Down
12 changes: 11 additions & 1 deletion src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use windows_sys::Win32::{
},
WindowsAndMessaging::{
CreateWindowExW, FlashWindowEx, GetClientRect, GetCursorPos, GetForegroundWindow,
GetSystemMetrics, GetWindowPlacement, GetWindowTextLengthW, GetWindowTextW,
GetSystemMetrics, GetWindowPlacement, GetWindowTextLengthW, GetWindowTextW, IsIconic,
IsWindowVisible, LoadCursorW, PeekMessageW, PostMessageW, RegisterClassExW, SetCursor,
SetCursorPos, SetForegroundWindow, SetWindowDisplayAffinity, SetWindowPlacement,
SetWindowPos, SetWindowTextW, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, FLASHWINFO,
Expand Down Expand Up @@ -462,8 +462,13 @@ impl Window {
let window = self.window.clone();
let window_state = Arc::clone(&self.window_state);

let is_minimized = self.is_minimized();

self.thread_executor.execute_in_thread(move || {
let _ = &window;
WindowState::set_window_flags_in_place(&mut window_state.lock().unwrap(), |f| {
f.set(WindowFlags::MINIMIZED, is_minimized)
});
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
f.set(WindowFlags::MINIMIZED, minimized)
});
Expand All @@ -489,6 +494,11 @@ impl Window {
window_state.window_flags.contains(WindowFlags::MAXIMIZED)
}

#[inline]
pub fn is_minimized(&self) -> bool {
unsafe { IsIconic(self.hwnd()) == 1 }
}

#[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> {
let window_state = self.window_state_lock();
Expand Down

0 comments on commit 067535e

Please sign in to comment.