Skip to content

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

feat: implement option on system tray icon for opening config dir

Lars Berger21dbab81014c
diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rs
index 2ca19c20..584202d3 100644
--- a/packages/wm/src/common/platform/platform.rs
+++ b/packages/wm/src/common/platform/platform.rs
@@ -1,4 +1,8 @@
-use std::{os::windows::io::AsRawHandle, path::Path, thread::JoinHandle};
+use std::{
+ os::windows::io::AsRawHandle,
+ path::{Path, PathBuf},
+ thread::JoinHandle,
+};
use anyhow::{bail, Context};
use windows::{
@@ -288,6 +292,17 @@ impl Platform {
Ok(())
}
+ /// Opens File Explorer at the specified path.
+ pub fn open_file_explorer(path: &PathBuf) -> anyhow::Result<()> {
+ let normalized_path = std::fs::canonicalize(path)?;
+
+ std::process::Command::new("explorer")
+ .arg(normalized_path)
+ .spawn()?;
+
+ Ok(())
+ }
+
/// Parses a command string into a program name/path and arguments. This
/// also expands any environment variables found in the command string if
/// they are wrapped in `%` characters. If the command string is a path, a
diff --git a/packages/wm/src/main.rs b/packages/wm/src/main.rs
index 2490dbad..69477956 100644
--- a/packages/wm/src/main.rs
+++ b/packages/wm/src/main.rs
@@ -82,7 +82,7 @@ async fn start_wm(
start_watcher_process()?;
// Add application icon to system tray.
- let mut tray = SystemTray::new()?;
+ let mut tray = SystemTray::new(&config.config_path)?;
let mut wm = WindowManager::new(&config)?;
diff --git a/packages/wm/src/sys_tray.rs b/packages/wm/src/sys_tray.rs
index 5377c131..907bcd68 100644
--- a/packages/wm/src/sys_tray.rs
+++ b/packages/wm/src/sys_tray.rs
@@ -1,5 +1,6 @@
-use std::{thread::JoinHandle, time::Duration};
+use std::{path::PathBuf, thread::JoinHandle, time::Duration};
+use anyhow::Context;
use tokio::sync::mpsc;
use tracing::{error, info};
use tray_icon::{
@@ -19,9 +20,13 @@ pub struct SystemTray {
}
impl SystemTray {
- pub fn new() -> anyhow::Result<Self> {
+ pub fn new(config_path: &PathBuf) -> anyhow::Result<Self> {
let (exit_tx, exit_rx) = mpsc::unbounded_channel();
let (config_reload_tx, config_reload_rx) = mpsc::unbounded_channel();
+ let config_dir = config_path
+ .parent()
+ .context("Invalid config path.")?
+ .to_owned();
let icon_thread = std::thread::spawn(move || {
let reload_config_item = MenuItem::new("Reload config", true, None);
@@ -64,8 +69,8 @@ impl SystemTray {
if event.id == reload_config_item.id() {
config_reload_tx.send(())?;
} else if event.id == config_dir_item.id() {
- // TODO: Open config directory.
- todo!()
+ // Open config directory in File Explorer.
+ let _ = Platform::open_file_explorer(&config_dir);
} else if event.id == animations_item.id() {
// Toggle window animations globally.
let _ =
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index fe525da9..8202e325 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -16,9 +16,10 @@ const SAMPLE_CONFIG: &str =
#[derive(Debug)]
pub struct UserConfig {
- pub value: ParsedConfig,
pub changes_rx: mpsc::UnboundedReceiver<()>,
pub changes_tx: mpsc::UnboundedSender<()>,
+ pub config_path: PathBuf,
+ pub value: ParsedConfig,
}
impl UserConfig {
@@ -46,9 +47,10 @@ impl UserConfig {
let (changes_tx, changes_rx) = mpsc::unbounded_channel::<()>();
Ok(Self {
- value: parsed_config,
changes_rx,
changes_tx,
+ config_path,
+ value: parsed_config,
})
}