Skip to content

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

feat: tray menu item for auto-launching on system startup (#1116)

Antoine Gaudreau Simard003b9b988b37
diff --git a/Cargo.lock b/Cargo.lock
index 412022e8..12333bcd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -120,6 +120,17 @@ dependencies = [
"system-deps",
]
+[[package]]
+name = "auto-launch"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471"
+dependencies = [
+ "dirs 4.0.0",
+ "thiserror 1.0.69",
+ "winreg 0.10.1",
+]
+
[[package]]
name = "autocfg"
version = "1.4.0"
@@ -350,13 +361,33 @@ dependencies = [
"crypto-common",
]
+[[package]]
+name = "dirs"
+version = "4.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
+dependencies = [
+ "dirs-sys 0.3.7",
+]
+
[[package]]
name = "dirs"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
dependencies = [
- "dirs-sys",
+ "dirs-sys 0.5.0",
+]
+
+[[package]]
+name = "dirs-sys"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
+dependencies = [
+ "libc",
+ "redox_users 0.4.6",
+ "winapi",
]
[[package]]
@@ -367,7 +398,7 @@ checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
dependencies = [
"libc",
"option-ext",
- "redox_users",
+ "redox_users 0.5.0",
"windows-sys 0.59.0",
]
@@ -404,7 +435,7 @@ dependencies = [
"rustc_version",
"toml 0.8.2",
"vswhom",
- "winreg",
+ "winreg 0.52.0",
]
[[package]]
@@ -1331,6 +1362,17 @@ dependencies = [
"bitflags 2.9.1",
]
+[[package]]
+name = "redox_users"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
+dependencies = [
+ "getrandom 0.2.16",
+ "libredox",
+ "thiserror 1.0.69",
+]
+
[[package]]
name = "redox_users"
version = "0.5.0"
@@ -1862,7 +1904,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7eee98ec5c90daf179d55c20a49d8c0d043054ce7c26336c09a24d31f14fa0"
dependencies = [
"crossbeam-channel",
- "dirs",
+ "dirs 6.0.0",
"libappindicator",
"muda",
"objc2",
@@ -2274,6 +2316,15 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "winreg"
+version = "0.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
+dependencies = [
+ "winapi",
+]
+
[[package]]
name = "winreg"
version = "0.52.0"
@@ -2375,6 +2426,7 @@ name = "wm-platform"
version = "0.0.0"
dependencies = [
"anyhow",
+ "auto-launch",
"home",
"tokio",
"tracing",
diff --git a/README.md b/README.md
index 1d20cea4..24bff172 100644
--- a/README.md
+++ b/README.md
@@ -356,7 +356,7 @@ binding_modes:
**Q: How do I run GlazeWM on startup?**
-Create a shortcut for the executable by right-clicking on the GlazeWM executable -> `Create shortcut`. Put the shortcut in your startup folder, which you can get to by entering `shell:startup` in the top bar in File Explorer.
+Right-click the GlazeWM icon in the system tray and select "Start with Windows".
**Q: How can I create `<insert layout>`?**
diff --git a/packages/wm-platform/Cargo.toml b/packages/wm-platform/Cargo.toml
index d0c244ca..f4079810 100644
--- a/packages/wm-platform/Cargo.toml
+++ b/packages/wm-platform/Cargo.toml
@@ -8,6 +8,7 @@ path = "src/lib.rs"
[dependencies]
anyhow = { workspace = true }
+auto-launch = "0.5.0"
home = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
diff --git a/packages/wm-platform/src/platform.rs b/packages/wm-platform/src/platform.rs
index 153aef20..ebe3e2d1 100644
--- a/packages/wm-platform/src/platform.rs
+++ b/packages/wm-platform/src/platform.rs
@@ -5,6 +5,7 @@ use std::{
};
use anyhow::{bail, Context};
+use auto_launch::AutoLaunch;
use windows::{
core::{w, PCWSTR},
Win32::{
@@ -319,6 +320,38 @@ impl Platform {
Ok(())
}
+ /// Gets the `AutoLaunch` instance for the GlazeWM application.
+ fn get_auto_launch() -> anyhow::Result<AutoLaunch> {
+ let exe_path = std::env::current_exe()?;
+ let quoted_exe_str = format!("\"{}\"", exe_path.to_str().unwrap());
+ Ok(AutoLaunch::new("GlazeWM", &quoted_exe_str, &[] as &[&str]))
+ }
+
+ /// Checks if auto-launch at system startup is enabled.
+ pub fn is_auto_launch_enabled() -> anyhow::Result<bool> {
+ let auto_launch = Self::get_auto_launch()?;
+
+ match auto_launch.is_enabled() {
+ Ok(enabled) => Ok(enabled),
+ Err(e) => {
+ Err(e.into())
+ }
+ }
+ }
+
+ /// Enables or disables auto-launch at system startup.
+ pub fn set_auto_launch_enabled(enable: bool) -> anyhow::Result<()> {
+ let auto_launch = Self::get_auto_launch()?;
+
+ if enable {
+ auto_launch.enable()?;
+ } else {
+ auto_launch.disable()?;
+ }
+
+ Ok(())
+ }
+
/// Opens File Explorer at the specified path.
pub fn open_file_explorer(path: &PathBuf) -> anyhow::Result<()> {
let normalized_path = std::fs::canonicalize(path)?;
diff --git a/packages/wm/src/sys_tray.rs b/packages/wm/src/sys_tray.rs
index 32c8ba34..bc61f6c9 100644
--- a/packages/wm/src/sys_tray.rs
+++ b/packages/wm/src/sys_tray.rs
@@ -42,7 +42,17 @@ impl SystemTray {
animations_enabled,
None,
);
+
+ let mut start_with_windows_enabled =
+ Platform::is_auto_launch_enabled().unwrap_or(false);
+ let start_with_windows_item = CheckMenuItem::new(
+ "Start with Windows",
+ true,
+ start_with_windows_enabled,
+ None,
+ );
+
let exit_item = MenuItem::new("Exit", true, None);
let tray_menu = Menu::new();
@@ -50,6 +60,7 @@ impl SystemTray {
&reload_config_item,
&config_dir_item,
&animations_item,
+ &start_with_windows_item,
&PredefinedMenuItem::separator(),
&exit_item,
])?;
@@ -76,6 +87,12 @@ impl SystemTray {
Platform::set_window_animations_enabled(!animations_enabled);
animations_enabled = !animations_enabled;
+ } else if event.id == start_with_windows_item.id() {
+ // Toggle auto-launch on Windows startup.
+ let _ =
+ Platform::set_auto_launch_enabled(!start_with_windows_enabled);
+
+ start_with_windows_enabled = !start_with_windows_enabled;
} else if event.id == exit_item.id() {
exit_tx.send(())?;
}
diff --git a/resources/wix/standalone.wxs b/resources/wix/standalone.wxs
index c0a29800..b8175318 100644
--- a/resources/wix/standalone.wxs
+++ b/resources/wix/standalone.wxs
@@ -122,5 +122,21 @@
System="yes"
/>
</Component>
+
+ <!-- Remove auto-launch registry values on uninstall. -->
+ <Component Id="Custom_RemoveAutoLaunchRegistry" Guid="B1A2C3D4-E5F6-47A8-9B0C-1234567890AB">
+ <RemoveRegistryValue
+ Root="HKCU"
+ Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
+ Name="GlazeWM"
+ Action="remove"
+ On="uninstall" />
+ <RemoveRegistryValue
+ Root="HKCU"
+ Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run"
+ Name="GlazeWM"
+ Action="remove"
+ On="uninstall" />
+ </Component>
</Package>
</Wix>