Skip to content

Commit 1de8188

Browse files
committed
fix(windows): let fullscreen and maximized work in harmony. (tauri-apps#1087)
1 parent c97080c commit 1de8188

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/platform_impl/windows/window.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,10 @@ impl Window {
767767
let placement = unsafe {
768768
let mut placement = WINDOWPLACEMENT::default();
769769
let _ = GetWindowPlacement(hwnd, &mut placement);
770+
// set the `showCmd` to your needs when you use this placement below.
771+
placement.showCmd = SW_NORMAL.0 as u32;
770772
placement
771773
};
772-
773774
window_state.lock().saved_window = Some(SavedWindow { placement });
774775

775776
let monitor = match &fullscreen {
@@ -798,7 +799,13 @@ impl Window {
798799
}
799800
None => {
800801
let mut window_state_lock = window_state.lock();
801-
if let Some(SavedWindow { placement }) = window_state_lock.saved_window.take() {
802+
if let Some(SavedWindow { mut placement }) = window_state_lock.saved_window.take() {
803+
if window_state_lock
804+
.window_flags
805+
.contains(WindowFlags::MAXIMIZED)
806+
{
807+
placement.showCmd = SW_MAXIMIZE.0 as u32;
808+
}
802809
drop(window_state_lock);
803810
unsafe {
804811
let _ = SetWindowPlacement(hwnd, &placement);

src/platform_impl/windows/window_state.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,18 @@ impl WindowFlags {
369369
}
370370
}
371371

372-
if diff.contains(WindowFlags::MAXIMIZED) || new.contains(WindowFlags::MAXIMIZED) {
373-
unsafe {
374-
let _ = ShowWindow(
375-
window,
376-
match new.contains(WindowFlags::MAXIMIZED) {
377-
true => SW_MAXIMIZE,
378-
false => SW_RESTORE,
379-
},
380-
);
372+
if diff.contains(WindowFlags::MAXIMIZED) {
373+
if new.contains(WindowFlags::MAXIMIZED) {
374+
let _ = unsafe { ShowWindow(window, SW_MAXIMIZE) };
375+
} else {
376+
if self.contains(WindowFlags::MARKER_BORDERLESS_FULLSCREEN) {
377+
let (style, _) = self.to_window_styles();
378+
// not to set SW_RESTORE to restore the size, we keep it for borderless fullscreen
379+
let unmaximized_style = style & !WS_MAXIMIZE;
380+
unsafe { SetWindowLongW(window, GWL_STYLE, unmaximized_style.0 as i32) };
381+
} else {
382+
let _ = unsafe { ShowWindow(window, SW_RESTORE) };
383+
}
381384
}
382385
}
383386

0 commit comments

Comments
 (0)