Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat: add `--hide-window` flag to allow `shell-exec` to run commands in background (#819)

DreamMaoMao4fd4e17e780a
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs
index f124c920..a8f698ce 100644
--- a/packages/wm/src/app_command.rs
+++ b/packages/wm/src/app_command.rs
@@ -210,6 +210,9 @@ pub enum InvokeCommand {
visibility: TitleBarVisibility,
},
ShellExec {
+ #[clap(long, action)]
+ hide_window: bool,
+
#[clap(required = true, trailing_var_arg = true)]
command: Vec<String>,
},
@@ -530,8 +533,11 @@ impl InvokeCommand {
_ => Ok(()),
}
}
- InvokeCommand::ShellExec { command } => {
- shell_exec(&command.join(" "))
+ InvokeCommand::ShellExec {
+ hide_window,
+ command
+ } => {
+ shell_exec(&command.join(" "), hide_window.clone())
}
InvokeCommand::Size(args) => {
match subject_container.as_window_container() {
diff --git a/packages/wm/src/common/commands/shell_exec.rs b/packages/wm/src/common/commands/shell_exec.rs
index 677955ab..3d625080 100644
--- a/packages/wm/src/common/commands/shell_exec.rs
+++ b/packages/wm/src/common/commands/shell_exec.rs
@@ -2,12 +2,12 @@ use tracing::{error, info};
use crate::common::platform::Platform;
-pub fn shell_exec(command: &str) -> anyhow::Result<()> {
+pub fn shell_exec(command: &str, hide_window: bool) -> anyhow::Result<()> {
let res =
Platform::parse_command(command).and_then(|(program, args)| {
info!("Parsed command program: '{}', args: '{}'.", program, args);
- Platform::run_command(&program, &args)
+ Platform::run_command(&program, &args, hide_window)
});
match res {
diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rs
index 985f8558..5a3afc9e 100644
--- a/packages/wm/src/common/platform/platform.rs
+++ b/packages/wm/src/common/platform/platform.rs
@@ -24,7 +24,7 @@ use windows::{
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_NORMAL,
+ SPI_GETANIMATION, SPI_SETANIMATION, SW_NORMAL, SW_HIDE,
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, WM_QUIT, WNDCLASSW, WNDPROC,
WS_OVERLAPPEDWINDOW,
},
@@ -411,7 +411,7 @@ impl Platform {
}
/// Runs the specified program with the given arguments.
- pub fn run_command(program: &str, args: &str) -> 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()
@@ -435,7 +435,7 @@ impl Platform {
lpFile: PCWSTR(program_wide.as_ptr()),
lpParameters: PCWSTR(args_wide.as_ptr()),
lpDirectory: PCWSTR(home_dir_wide.as_ptr()),
- nShow: SW_NORMAL.0 as _,
+ nShow: if hide_window { SW_HIDE } else { SW_NORMAL }.0 as _,
fMask: SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC,
..Default::default()
};