feat(wm): manage return bool of PostMessage + update ahk library

this commit makes a small refactor to the way PostMessageW is used so now be able to handle the
returned bool, as well as adding a custom error message to WindowsApi::close_window and updating the
ahk generated library

#259
This commit is contained in:
Yusuf007R
2022-10-12 12:44:23 -05:00
committed by جاد
parent 33965f92ad
commit 352c010021
4 changed files with 22 additions and 5 deletions

View File

@@ -177,7 +177,7 @@ impl WindowManager {
SocketMessage::CycleStack(direction) => { SocketMessage::CycleStack(direction) => {
self.cycle_container_window_in_direction(direction)?; self.cycle_container_window_in_direction(direction)?;
} }
SocketMessage::Close => self.focused_window()?.close(), SocketMessage::Close => self.focused_window()?.close()?,
SocketMessage::Minimize => self.focused_window()?.minimize(), SocketMessage::Minimize => self.focused_window()?.minimize(),
SocketMessage::ToggleFloat => self.toggle_float()?, SocketMessage::ToggleFloat => self.toggle_float()?,
SocketMessage::ToggleMonocle => self.toggle_monocle()?, SocketMessage::ToggleMonocle => self.toggle_monocle()?,

View File

@@ -155,8 +155,8 @@ impl Window {
WindowsApi::minimize_window(self.hwnd()); WindowsApi::minimize_window(self.hwnd());
} }
pub fn close(self) { pub fn close(self) -> Result<()> {
WindowsApi::close_window(self.hwnd()); WindowsApi::close_window(self.hwnd())
} }
pub fn restore(self) { pub fn restore(self) {

View File

@@ -339,8 +339,17 @@ impl WindowsApi {
Self::show_window(hwnd, SW_MINIMIZE); Self::show_window(hwnd, SW_MINIMIZE);
} }
pub fn close_window(hwnd: HWND) { fn post_message(hwnd: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> Result<()> {
unsafe { PostMessageW(hwnd, WM_CLOSE, WPARAM(0), LPARAM(0)) }; unsafe { PostMessageW(hwnd, message, wparam, lparam) }
.ok()
.process()
}
pub fn close_window(hwnd: HWND) -> Result<()> {
match Self::post_message(hwnd, WM_CLOSE, WPARAM(0), LPARAM(0)) {
Ok(_) => Ok(()),
Err(_) => Err(anyhow!("could not close window")),
}
} }
pub fn hide_window(hwnd: HWND) { pub fn hide_window(hwnd: HWND) {

View File

@@ -52,6 +52,14 @@ Move(operation_direction) {
Run, komorebic.exe move %operation_direction%, , Hide Run, komorebic.exe move %operation_direction%, , Hide
} }
Minimize() {
Run, komorebic.exe minimize, , Hide
}
Close() {
Run, komorebic.exe close, , Hide
}
CycleFocus(cycle_direction) { CycleFocus(cycle_direction) {
Run, komorebic.exe cycle-focus %cycle_direction%, , Hide Run, komorebic.exe cycle-focus %cycle_direction%, , Hide
} }