From e6b26df15017362b5b3d44fccd4762e2d6260676 Mon Sep 17 00:00:00 2001 From: lars-berger Date: Tue, 5 Nov 2024 21:10:49 +0800 Subject: [PATCH] style: linting fixes (#831) --- packages/wm/src/app_command.rs | 8 ++--- .../common/events/handle_window_destroyed.rs | 15 ++++---- .../common/events/handle_window_focused.rs | 5 +-- packages/wm/src/common/platform/platform.rs | 36 +++++++++++-------- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs index a8f698ce..29a38890 100644 --- a/packages/wm/src/app_command.rs +++ b/packages/wm/src/app_command.rs @@ -533,12 +533,10 @@ impl InvokeCommand { _ => Ok(()), } } - InvokeCommand::ShellExec { + InvokeCommand::ShellExec { hide_window, - command - } => { - shell_exec(&command.join(" "), hide_window.clone()) - } + command, + } => shell_exec(&command.join(" "), hide_window.clone()), InvokeCommand::Size(args) => { match subject_container.as_window_container() { Ok(window) => set_window_size( diff --git a/packages/wm/src/common/events/handle_window_destroyed.rs b/packages/wm/src/common/events/handle_window_destroyed.rs index da211622..7ef3551e 100644 --- a/packages/wm/src/common/events/handle_window_destroyed.rs +++ b/packages/wm/src/common/events/handle_window_destroyed.rs @@ -2,10 +2,9 @@ use anyhow::Context; use tracing::info; use crate::{ - common::platform::NativeWindow, windows::commands::unmanage_window, - wm_state::WmState, - containers::traits::CommonGetters, - workspaces::commands::deactivate_workspace + common::platform::NativeWindow, containers::traits::CommonGetters, + windows::commands::unmanage_window, wm_state::WmState, + workspaces::commands::deactivate_workspace, }; pub fn handle_window_destroyed( @@ -22,8 +21,12 @@ pub fn handle_window_destroyed( info!("Window closed"); unmanage_window(window, state)?; - // Destroy parent workspace if window was killed while its workspace was not displayed (e.g. via task manager). - if !workspace.config().keep_alive && !workspace.has_children() && !workspace.is_displayed() { + // Destroy parent workspace if window was killed while its workspace + // was not displayed (e.g. via task manager). + if !workspace.config().keep_alive + && !workspace.has_children() + && !workspace.is_displayed() + { deactivate_workspace(workspace, state)?; } } diff --git a/packages/wm/src/common/events/handle_window_focused.rs b/packages/wm/src/common/events/handle_window_focused.rs index 360b1721..7c37f050 100644 --- a/packages/wm/src/common/events/handle_window_focused.rs +++ b/packages/wm/src/common/events/handle_window_focused.rs @@ -2,10 +2,7 @@ use anyhow::Context; use tracing::info; use crate::{ - common::{ - platform::{NativeWindow, Platform}, - DisplayState, - }, + common::{platform::NativeWindow, DisplayState}, containers::{commands::set_focused_descendant, traits::CommonGetters}, user_config::{UserConfig, WindowRuleEvent}, windows::{commands::run_window_rules, traits::WindowGetters}, diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rs index 62a15182..651addce 100644 --- a/packages/wm/src/common/platform/platform.rs +++ b/packages/wm/src/common/platform/platform.rs @@ -19,12 +19,13 @@ use windows::{ }, WindowsAndMessaging::{ CreateWindowExW, DispatchMessageW, GetAncestor, GetCursorPos, - GetDesktopWindow, GetForegroundWindow, GetMessageW, MessageBoxW, - PeekMessageW, PostThreadMessageW, RegisterClassW, SetCursorPos, - SystemParametersInfoW, TranslateMessage, WindowFromPoint, GetShellWindow, - ANIMATIONINFO, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, GA_ROOT, - MB_ICONERROR, MB_OK, MB_SYSTEMMODAL, MSG, PM_REMOVE, - SPI_GETANIMATION, SPI_SETANIMATION, SW_NORMAL, SW_HIDE, + GetDesktopWindow, GetForegroundWindow, GetMessageW, + GetShellWindow, MessageBoxW, PeekMessageW, PostThreadMessageW, + RegisterClassW, SetCursorPos, SystemParametersInfoW, + TranslateMessage, WindowFromPoint, ANIMATIONINFO, CS_HREDRAW, + CS_VREDRAW, CW_USEDEFAULT, GA_ROOT, MB_ICONERROR, MB_OK, + MB_SYSTEMMODAL, MSG, PM_REMOVE, SPI_GETANIMATION, + SPI_SETANIMATION, SW_HIDE, SW_NORMAL, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, WM_QUIT, WNDCLASSW, WNDPROC, WS_OVERLAPPEDWINDOW, }, @@ -49,14 +50,17 @@ impl Platform { NativeWindow::new(handle.0) } - // Get Explorer wallpaper window (i.e. "Progman"). Default to the - // desktop window on which the wallpaper window sits above for edge - // case where Explorer isn't running. + /// Gets the `NativeWindow` instance of the desktop window. + /// + /// This is the explorer.exe wallpaper window (i.e. "Progman"). If + /// explorer.exe isn't running, then default to the desktop window below + /// the wallpaper window. pub fn desktop_window() -> NativeWindow { - let mut handle = unsafe { GetShellWindow() }; - if handle == HWND(0) { - handle = unsafe { GetDesktopWindow() }; - } + let handle = match unsafe { GetShellWindow() } { + HWND(0) => unsafe { GetDesktopWindow() }, + handle => handle, + }; + NativeWindow::new(handle.0) } @@ -416,7 +420,11 @@ impl Platform { } /// Runs the specified program with the given arguments. - pub fn run_command(program: &str, args: &str, hide_window: bool) -> anyhow::Result<()> { + pub fn run_command( + program: &str, + args: &str, + hide_window: bool, + ) -> anyhow::Result<()> { let home_dir = home::home_dir() .context("Unable to get home directory.")? .to_str()