mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-24 18:31:22 +01:00
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:
@@ -177,7 +177,7 @@ impl WindowManager {
|
||||
SocketMessage::CycleStack(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::ToggleFloat => self.toggle_float()?,
|
||||
SocketMessage::ToggleMonocle => self.toggle_monocle()?,
|
||||
|
||||
@@ -155,8 +155,8 @@ impl Window {
|
||||
WindowsApi::minimize_window(self.hwnd());
|
||||
}
|
||||
|
||||
pub fn close(self) {
|
||||
WindowsApi::close_window(self.hwnd());
|
||||
pub fn close(self) -> Result<()> {
|
||||
WindowsApi::close_window(self.hwnd())
|
||||
}
|
||||
|
||||
pub fn restore(self) {
|
||||
|
||||
@@ -339,8 +339,17 @@ impl WindowsApi {
|
||||
Self::show_window(hwnd, SW_MINIMIZE);
|
||||
}
|
||||
|
||||
pub fn close_window(hwnd: HWND) {
|
||||
unsafe { PostMessageW(hwnd, WM_CLOSE, WPARAM(0), LPARAM(0)) };
|
||||
fn post_message(hwnd: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> Result<()> {
|
||||
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) {
|
||||
|
||||
@@ -52,6 +52,14 @@ Move(operation_direction) {
|
||||
Run, komorebic.exe move %operation_direction%, , Hide
|
||||
}
|
||||
|
||||
Minimize() {
|
||||
Run, komorebic.exe minimize, , Hide
|
||||
}
|
||||
|
||||
Close() {
|
||||
Run, komorebic.exe close, , Hide
|
||||
}
|
||||
|
||||
CycleFocus(cycle_direction) {
|
||||
Run, komorebic.exe cycle-focus %cycle_direction%, , Hide
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user