From 6df91d7d403595fc7a09599f0f5d7c01da7dbd54 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 12 Jun 2023 16:46:24 -0700 Subject: [PATCH] fix(wm): manually close process handles ZiN on Discord noted that handles returned by OpenProcess must be closed manually (this is not implemented in the Drop trait for handle, it seems) https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess#remarks --- komorebi.generated.ahk | 10 ++++++++++ komorebi.generated.ps1 | 10 ++++++++++ komorebi/src/window.rs | 5 ++++- komorebi/src/windows_api.rs | 5 +++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/komorebi.generated.ahk b/komorebi.generated.ahk index f0e89921..79ca7717 100644 --- a/komorebi.generated.ahk +++ b/komorebi.generated.ahk @@ -16,6 +16,10 @@ RunWait('komorebic.exe identify-tray-application class "CreativeCloudDesktopWind ; Adobe Photoshop RunWait('komorebic.exe identify-border-overflow-application class "Photoshop"', , "Hide") +; Affinity Photo 2 +RunWait('komorebic.exe manage-rule title "Affinity Photo 2"', , "Hide") +RunWait('komorebic.exe float-rule exe "Photo.exe"', , "Hide") + ; Akiflow ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line RunWait('komorebic.exe identify-tray-application exe "Akiflow.exe"', , "Hide") @@ -57,6 +61,10 @@ RunWait('komorebic.exe identify-border-overflow-application exe "Cron.exe"', , " ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line RunWait('komorebic.exe identify-tray-application exe "Cron.exe"', , "Hide") +; DS4Windows +; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line +RunWait('komorebic.exe identify-tray-application exe "DS4Windows.exe"', , "Hide") + ; Delphi applications ; Target hidden window spawned by Delphi applications RunWait('komorebic.exe float-rule class "TApplication"', , "Hide") @@ -388,6 +396,8 @@ RunWait('komorebic.exe identify-border-overflow-application class "vguiPopupWind RunWait('komorebic.exe identify-border-overflow-application class "SDL_app"', , "Hide") ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line RunWait('komorebic.exe identify-tray-application class "SDL_app"', , "Hide") +; Target notification toast popups +RunWait('komorebic.exe float-rule title "notificationtoasts_"', , "Hide") ; Stremio ; If you have disabled minimize/close to tray for this application, you can delete/comment out the next line diff --git a/komorebi.generated.ps1 b/komorebi.generated.ps1 index f22360c3..b3046c46 100644 --- a/komorebi.generated.ps1 +++ b/komorebi.generated.ps1 @@ -16,6 +16,10 @@ komorebic.exe identify-tray-application class "CreativeCloudDesktopWindowClass" # Adobe Photoshop komorebic.exe identify-border-overflow-application class "Photoshop" +# Affinity Photo 2 +komorebic.exe manage-rule title "Affinity Photo 2" +komorebic.exe float-rule exe "Photo.exe" + # Akiflow # If you have disabled minimize/close to tray for this application, you can delete/comment out the next line komorebic.exe identify-tray-application exe "Akiflow.exe" @@ -57,6 +61,10 @@ komorebic.exe identify-border-overflow-application exe "Cron.exe" # If you have disabled minimize/close to tray for this application, you can delete/comment out the next line komorebic.exe identify-tray-application exe "Cron.exe" +# DS4Windows +# If you have disabled minimize/close to tray for this application, you can delete/comment out the next line +komorebic.exe identify-tray-application exe "DS4Windows.exe" + # Delphi applications # Target hidden window spawned by Delphi applications komorebic.exe float-rule class "TApplication" @@ -388,6 +396,8 @@ komorebic.exe identify-border-overflow-application class "vguiPopupWindow" komorebic.exe identify-border-overflow-application class "SDL_app" # If you have disabled minimize/close to tray for this application, you can delete/comment out the next line komorebic.exe identify-tray-application class "SDL_app" +# Target notification toast popups +komorebic.exe float-rule title "notificationtoasts_" # Stremio # If you have disabled minimize/close to tray for this application, you can delete/comment out the next line diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 03583d6e..57a5ba9a 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -383,7 +383,10 @@ impl Window { pub fn exe(self) -> Result { let (process_id, _) = WindowsApi::window_thread_process_id(self.hwnd()); - WindowsApi::exe(WindowsApi::process_handle(process_id)?) + let handle = WindowsApi::process_handle(process_id)?; + let exe = WindowsApi::exe(handle); + WindowsApi::close_process(handle)?; + exe } pub fn class(self) -> Result { diff --git a/komorebi/src/windows_api.rs b/komorebi/src/windows_api.rs index be3f66fd..2575f030 100644 --- a/komorebi/src/windows_api.rs +++ b/komorebi/src/windows_api.rs @@ -11,6 +11,7 @@ use color_eyre::Result; use windows::core::Result as WindowsCrateResult; use windows::core::PCSTR; use windows::core::PWSTR; +use windows::Win32::Foundation::CloseHandle; use windows::Win32::Foundation::BOOL; use windows::Win32::Foundation::COLORREF; use windows::Win32::Foundation::HANDLE; @@ -560,6 +561,10 @@ impl WindowsApi { unsafe { OpenProcess(access_rights, inherit_handle, process_id) }.process() } + pub fn close_process(handle: HANDLE) -> Result<()> { + unsafe { CloseHandle(handle) }.ok().process() + } + pub fn process_handle(process_id: u32) -> Result { Self::open_process(PROCESS_QUERY_INFORMATION, false, process_id) }