Autostart.
Browse files
+4 −4 justfile
| @@ -2,13 +2,13 @@ build: | |||
| 2 | cargo build --release | 2 | cargo build --release |
| 3 | 3 | ||
| 4 | install: build | 4 | install: build |
| 5 | - cp target/release/oxwm ~/.local/bin/oxwm | 5 | + cp target/release/oxwm /usr/bin/oxwm |
| 6 | - chmod +x ~/.local/bin/oxwm | 6 | + chmod +x /usr/bin/oxwm |
| 7 | - @echo "✓ oxwm installed to ~/.local/bin/oxwm" | 7 | + @echo "✓ oxwm installed to /usr/bin/oxwm" |
| 8 | @echo " Run 'oxwm --init' to create your config" | 8 | @echo " Run 'oxwm --init' to create your config" |
| 9 | 9 | ||
| 10 | uninstall: | 10 | uninstall: |
| 11 | - rm -f ~/.local/bin/oxwm | 11 | + rm -f /usr/bin/oxwm |
| 12 | @echo "✓ oxwm uninstalled" | 12 | @echo "✓ oxwm uninstalled" |
| 13 | @echo " Your config at ~/.config/oxwm/config.ron is preserved" | 13 | @echo " Your config at ~/.config/oxwm/config.ron is preserved" |
| 14 | 14 | ||
+4 −0 src/config/mod.rs
| @@ -256,6 +256,9 @@ struct ConfigData { | |||
| 256 | scheme_normal: ColorSchemeData, | 256 | scheme_normal: ColorSchemeData, |
| 257 | scheme_occupied: ColorSchemeData, | 257 | scheme_occupied: ColorSchemeData, |
| 258 | scheme_selected: ColorSchemeData, | 258 | scheme_selected: ColorSchemeData, |
| 259 | + | ||
| 260 | + #[serde(default)] | ||
| 261 | + autostart: Vec<String>, | ||
| 259 | } | 262 | } |
| 260 | 263 | ||
| 261 | #[derive(Debug, Deserialize)] | 264 | #[derive(Debug, Deserialize)] |
| @@ -458,6 +461,7 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError> | |||
| 458 | background: data.scheme_selected.background, | 461 | background: data.scheme_selected.background, |
| 459 | underline: data.scheme_selected.underline, | 462 | underline: data.scheme_selected.underline, |
| 460 | }, | 463 | }, |
| 464 | + autostart: data.autostart, | ||
| 461 | }) | 465 | }) |
| 462 | } | 466 | } |
| 463 | 467 | ||
+7 −3 src/errors.rs
| @@ -1,9 +1,12 @@ | |||
| 1 | +use std::io; | ||
| 2 | + | ||
| 1 | #[derive(Debug)] | 3 | #[derive(Debug)] |
| 2 | pub enum WmError { | 4 | pub enum WmError { |
| 3 | X11(X11Error), | 5 | X11(X11Error), |
| 4 | - Io(std::io::Error), | 6 | + Io(io::Error), |
| 5 | Anyhow(anyhow::Error), | 7 | Anyhow(anyhow::Error), |
| 6 | Config(ConfigError), | 8 | Config(ConfigError), |
| 9 | + Autostart(String, io::Error), | ||
| 7 | } | 10 | } |
| 8 | 11 | ||
| 9 | #[derive(Debug)] | 12 | #[derive(Debug)] |
| @@ -38,6 +41,7 @@ impl std::fmt::Display for WmError { | |||
| 38 | Self::Io(error) => write!(f, "{}", error), | 41 | Self::Io(error) => write!(f, "{}", error), |
| 39 | Self::Anyhow(error) => write!(f, "{}", error), | 42 | Self::Anyhow(error) => write!(f, "{}", error), |
| 40 | Self::Config(error) => write!(f, "{}", error), | 43 | Self::Config(error) => write!(f, "{}", error), |
| 44 | + Self::Autostart(command, error) => write!(f, "Failed to spawn autostart command '{}': {}", command, error), | ||
| 41 | } | 45 | } |
| 42 | } | 46 | } |
| 43 | } | 47 | } |
| @@ -101,8 +105,8 @@ impl<T: Into<X11Error>> From<T> for WmError { | |||
| 101 | } | 105 | } |
| 102 | } | 106 | } |
| 103 | 107 | ||
| 104 | -impl From<std::io::Error> for WmError { | 108 | +impl From<io::Error> for WmError { |
| 105 | - fn from(value: std::io::Error) -> Self { | 109 | + fn from(value: io::Error) -> Self { |
| 106 | Self::Io(value) | 110 | Self::Io(value) |
| 107 | } | 111 | } |
| 108 | } | 112 | } |
+4 −0 src/lib.rs
| @@ -55,6 +55,9 @@ pub struct Config { | |||
| 55 | pub scheme_normal: ColorScheme, | 55 | pub scheme_normal: ColorScheme, |
| 56 | pub scheme_occupied: ColorScheme, | 56 | pub scheme_occupied: ColorScheme, |
| 57 | pub scheme_selected: ColorScheme, | 57 | pub scheme_selected: ColorScheme, |
| 58 | + | ||
| 59 | + // Autostart commands | ||
| 60 | + pub autostart: Vec<String>, | ||
| 58 | } | 61 | } |
| 59 | 62 | ||
| 60 | #[derive(Clone, Copy)] | 63 | #[derive(Clone, Copy)] |
| @@ -298,6 +301,7 @@ impl Default for Config { | |||
| 298 | background: 0x1a1b26, | 301 | background: 0x1a1b26, |
| 299 | underline: 0xad8ee6, | 302 | underline: 0xad8ee6, |
| 300 | }, | 303 | }, |
| 304 | + autostart: vec![], | ||
| 301 | } | 305 | } |
| 302 | } | 306 | } |
| 303 | } | 307 | } |
+14 −0 src/window_manager.rs
| @@ -7,6 +7,7 @@ use crate::layout::tiling::TilingLayout; | |||
| 7 | use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout}; | 7 | use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout}; |
| 8 | use crate::monitor::{Monitor, detect_monitors}; | 8 | use crate::monitor::{Monitor, detect_monitors}; |
| 9 | use std::collections::HashSet; | 9 | use std::collections::HashSet; |
| 10 | +use std::process::Command; | ||
| 10 | use x11rb::cursor::Handle as CursorHandle; | 11 | use x11rb::cursor::Handle as CursorHandle; |
| 11 | 12 | ||
| 12 | use x11rb::connection::Connection; | 13 | use x11rb::connection::Connection; |
| @@ -180,6 +181,7 @@ impl WindowManager { | |||
| 180 | 181 | ||
| 181 | window_manager.scan_existing_windows()?; | 182 | window_manager.scan_existing_windows()?; |
| 182 | window_manager.update_bar()?; | 183 | window_manager.update_bar()?; |
| 184 | + window_manager.run_autostart_commands()?; | ||
| 183 | 185 | ||
| 184 | Ok(window_manager) | 186 | Ok(window_manager) |
| 185 | } | 187 | } |
| @@ -1886,4 +1888,16 @@ impl WindowManager { | |||
| 1886 | } | 1888 | } |
| 1887 | Ok(()) | 1889 | Ok(()) |
| 1888 | } | 1890 | } |
| 1891 | + | ||
| 1892 | + fn run_autostart_commands(&self) -> Result<(), WmError> { | ||
| 1893 | + for command in &self.config.autostart { | ||
| 1894 | + Command::new("sh") | ||
| 1895 | + .arg("-c") | ||
| 1896 | + .arg(command) | ||
| 1897 | + .spawn() | ||
| 1898 | + .map_err(|e| WmError::Autostart(command.clone(), e))?; | ||
| 1899 | + eprintln!("[autostart] Spawned: {}", command); | ||
| 1900 | + } | ||
| 1901 | + Ok(()) | ||
| 1902 | + } | ||
| 1889 | } | 1903 | } |
+10 −0 templates/config.ron
| @@ -113,5 +113,15 @@ | |||
| 113 | scheme_normal: (foreground: $color_fg, background: $color_bg, underline: 0x444444), | 113 | scheme_normal: (foreground: $color_fg, background: $color_bg, underline: 0x444444), |
| 114 | scheme_occupied: (foreground: $color_cyan, background: $color_bg, underline: $color_cyan), | 114 | scheme_occupied: (foreground: $color_cyan, background: $color_bg, underline: $color_cyan), |
| 115 | scheme_selected: (foreground: $color_cyan, background: $color_bg, underline: $color_purple), | 115 | scheme_selected: (foreground: $color_cyan, background: $color_bg, underline: $color_purple), |
| 116 | + | ||
| 117 | + // Autostart commands - these are executed when the window manager starts | ||
| 118 | + // Commands are run in a shell, so you can use shell syntax (pipes, &&, etc.) | ||
| 119 | + // Example: ["picom", "nitrogen --restore", "~/.config/polybar/launch.sh"] | ||
| 120 | + autostart: [ | ||
| 121 | + // Uncomment and add your autostart commands here: | ||
| 122 | + // "picom -b", | ||
| 123 | + // "nitrogen --restore &", | ||
| 124 | + // "dunst &", | ||
| 125 | + ], | ||
| 116 | ) | 126 | ) |
| 117 | 127 | ||