Skip to content

Commit

Permalink
fix(wm): normalize max hwnd before minimizing
Browse files Browse the repository at this point in the history
This commit ensures that if a window maximized using the 'komorebic
toggle-maximize' is minimized using the UI, on the receipt of the
Minimize WindowManagerEvent, the window will be normalized with
SW_NORMAL before being removed from the window manager state.

This ensures that if the window is later managed again, the user will be
able to toggle-maximize normally again as expected.
  • Loading branch information
LGUG2Z committed Jul 26, 2022
1 parent eec628f commit 89bd7d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ impl Window {
WindowsApi::maximize_window(self.hwnd());
}

pub fn unmaximize(self) {
let mut programmatically_hidden_hwnds = HIDDEN_HWNDS.lock();
if let Some(idx) = programmatically_hidden_hwnds
.iter()
.position(|&hwnd| hwnd == self.hwnd)
{
programmatically_hidden_hwnds.remove(idx);
}

WindowsApi::unmaximize_window(self.hwnd());
}

pub fn raise(self) -> Result<()> {
// Attach komorebi thread to Window thread
let (_, window_thread_id) = WindowsApi::window_thread_process_id(self.hwnd());
Expand Down
5 changes: 5 additions & 0 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ use windows::Win32::UI::WindowsAndMessaging::SPI_SETACTIVEWINDOWTRACKING;
use windows::Win32::UI::WindowsAndMessaging::SW_HIDE;
use windows::Win32::UI::WindowsAndMessaging::SW_MAXIMIZE;
use windows::Win32::UI::WindowsAndMessaging::SW_MINIMIZE;
use windows::Win32::UI::WindowsAndMessaging::SW_NORMAL;
use windows::Win32::UI::WindowsAndMessaging::SW_RESTORE;
use windows::Win32::UI::WindowsAndMessaging::SYSTEM_PARAMETERS_INFO_ACTION;
use windows::Win32::UI::WindowsAndMessaging::SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS;
Expand Down Expand Up @@ -294,6 +295,10 @@ impl WindowsApi {
Self::show_window(hwnd, SW_RESTORE);
}

pub fn unmaximize_window(hwnd: HWND) {
Self::show_window(hwnd, SW_NORMAL);
}

pub fn maximize_window(hwnd: HWND) {
Self::show_window(hwnd, SW_MAXIMIZE);
}
Expand Down
1 change: 1 addition & 0 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ impl Workspace {

if let Some(window) = self.maximized_window() {
if window.hwnd == hwnd {
window.unmaximize();
self.set_maximized_window(None);
self.set_maximized_window_restore_idx(None);
return Ok(());
Expand Down

0 comments on commit 89bd7d2

Please sign in to comment.