Skip to content

Commit

Permalink
fix: shutdown and config reload commands get run from tray menu (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger authored Sep 28, 2024
1 parent 0e23b06 commit ac370d7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 39 deletions.
23 changes: 2 additions & 21 deletions packages/wm/src/app_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
common::{
commands::{
cycle_focus, disable_binding_mode, enable_binding_mode,
platform_sync, reload_config, shell_exec,
reload_config, shell_exec,
},
Direction, LengthValue, RectDelta, TilingDirection,
},
Expand Down Expand Up @@ -604,14 +604,6 @@ impl InvokeCommand {
enable_binding_mode(name, state, config)
}
InvokeCommand::WmExit => {
Self::run_multiple(
config.value.general.shutdown_commands.clone(),
subject_container,
state,
config,
)?;
platform_sync(state, config)?;

state.emit_exit();
Ok(())
}
Expand All @@ -624,18 +616,7 @@ impl InvokeCommand {

Ok(())
}
InvokeCommand::WmReloadConfig => {
reload_config(state, config)?;

Self::run_multiple(
config.value.general.config_reload_commands.clone(),
subject_container,
state,
config,
)?;
platform_sync(state, config)?;
Ok(())
}
InvokeCommand::WmReloadConfig => reload_config(state, config),
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/wm/src/common/commands/reload_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Context;
use tracing::{info, warn};

use crate::{
app_command::InvokeCommand,
containers::traits::{CommonGetters, TilingSizeGetters},
user_config::{ParsedConfig, UserConfig, WindowRuleEvent},
windows::{commands::run_window_rules, traits::WindowGetters},
Expand Down Expand Up @@ -55,6 +56,14 @@ pub fn reload_config(
parsed_config: config.value.clone(),
});

// Run config reload commands.
InvokeCommand::run_multiple(
config.value.general.config_reload_commands.clone(),
state.focused_container().context("No focused container.")?,
state,
config,
)?;

Ok(())
}

Expand Down
19 changes: 13 additions & 6 deletions packages/wm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,19 @@ async fn start_wm(
}
}

// Broadcast `WmEvent::ApplicationExiting` on shutdown.
if let Err(err) = ipc_server.process_event(WmEvent::ApplicationExiting) {
warn!(
"Failed to emit `WmEvent::ApplicationExiting` event over IPC: {:?}",
err
);
// Run shutdown commands.
let shutdown_commands = config.value.general.shutdown_commands.clone();
wm.process_commands(shutdown_commands, None, &mut config)?;

wm.state.emit_event(WmEvent::ApplicationExiting);

// Emit remaining WM events before exiting.
while let Ok(wm_event) = wm.event_rx.try_recv() {
info!("Emitting WM event before shutting down: {:?}", wm_event);

if let Err(err) = ipc_server.process_event(wm_event) {
warn!("{:?}", err);
}
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions packages/wm/src/wm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl WindowManager {
state,
config,
)?;

platform_sync(state, config)?;

Ok(new_subject_container_id)
Expand Down
22 changes: 10 additions & 12 deletions resources/assets/sample-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
general:
# Commands to run when the WM has started (e.g. to run a script or launch
# another application). Here we are running a batch script to start Zebar.
startup_commands: ['shell-exec %userprofile%/.glzr/zebar/start.bat']
# Similarly commands can be executed just before the WM is shutdown
# and after the config has reloaded.
# Here we shutdown Zebar when the WM is shutdown.
# Commands to run when the WM has started. This is useful for running a
# script or launching another application.
# Example: The below command launches Zebar.
startup_commands: ['shell-exec zebar']

# Commands to run just before the WM is shutdown.
# Example: The below command kills Zebar.
shutdown_commands: ['shell-exec taskkill /IM zebar.exe /F']
# Here we restart Zebar to reload the Zebar config when reloading the
# WM config.
config_reload_commands: [
'shell-exec taskkill /IM zebar.exe /F',
'shell-exec %userprofile%/.glzr/zebar/start.bat'
]

# Commands to run after the WM config is reloaded.
config_reload_commands: []

# Whether to automatically focus windows underneath the cursor.
focus_follows_cursor: false
Expand Down

0 comments on commit ac370d7

Please sign in to comment.