tony / oxwm

added sane defaults Browse files
tonybtw committed 2025-10-11 parent ac5ee9e commit 4001329983a7b31d87a0a8c950f56fcea65f5f05
Showing 2 changed files with 147 additions and 15 deletions. UnifiedSplit
+30 −12 src/bin/main.rs
@@ -32,10 +32,27 @@ fn main() -> Result<()> {
32 32 let err = Command::new(&cache_binary).args(&args[1..]).exec();
33 33 anyhow::bail!("Failed to exec user binary: {}", err);
34 34 } else {
35 - eprintln!("No configuration found.");
36 - eprintln!("Run: oxwm --init");
37 - eprintln!("Then add 'exec oxwm' to your ~/.xinitrc");
38 - std::process::exit(1);
35 + // No user config - use built-in defaults
36 + eprintln!("╔════════════════════════════════════════╗");
37 + eprintln!("║ OXWM: Running with default config ║");
38 + eprintln!("╚════════════════════════════════════════╝");
39 + eprintln!();
40 + eprintln!("ℹ️ Run 'oxwm --init' to create a custom config");
41 + eprintln!();
42 +
43 + let config = oxwm::Config::default();
44 + let mut wm = oxwm::window_manager::WindowManager::new(config)?;
45 + let should_restart = wm.run()?;
46 +
47 + drop(wm);
48 +
49 + if should_restart {
50 + use std::os::unix::process::CommandExt;
51 + let err = Command::new(&args[0]).args(&args[1..]).exec();
52 + eprintln!("Failed to restart: {}", err);
53 + }
54 +
55 + Ok(())
39 56 }
40 57 }
41 58
@@ -123,7 +140,7 @@ pkgs.mkShell {
123 140 recompile_config()?;
124 141
125 142 println!("\n✓ Setup complete!");
126 - println!(" Add 'exec oxwm' to your ~/.xinitrc");
143 + println!(" Your custom config is now active");
127 144 println!(" Reload config anytime with Mod+Shift+R");
128 145
129 146 Ok(())
@@ -253,14 +270,15 @@ fn print_help() {
253 270 println!(" --recompile Recompile user configuration");
254 271 println!(" --version Print version information");
255 272 println!(" --help Print this help message\n");
256 - println!("SETUP:");
257 - println!(" 1. Run 'oxwm --init' to create your config");
258 - println!(" 2. Edit ~/.config/oxwm/config.rs");
259 - println!(" 3. Add 'exec oxwm' to your ~/.xinitrc");
260 - println!(" 4. Start X with 'startx'\n");
261 273 println!("CONFIGURATION:");
262 - println!(" Config location: ~/.config/oxwm/config.rs");
263 - println!(" Reload hotkey: Mod+Shift+R (auto-recompiles if needed)\n");
274 + println!(" Without --init: Runs with built-in defaults");
275 + println!(" With --init: Uses custom config from ~/.config/oxwm/config.rs");
276 + println!(" Reload hotkey: Mod+Shift+R (auto-recompiles if needed)\n");
277 + println!("SETUP:");
278 + println!(" 1. Add 'exec oxwm' to your ~/.xinitrc (works immediately with defaults)");
279 + println!(" 2. Optionally run 'oxwm --init' to create custom config");
280 + println!(" 3. Edit ~/.config/oxwm/config.rs to customize");
281 + println!(" 4. Restart with Mod+Shift+R\n");
264 282 println!("ADVANCED:");
265 283 println!(" Create flake.nix or shell.nix in ~/.config/oxwm to use nix builds");
266 284 }
+117 −3 src/lib.rs
@@ -53,6 +53,16 @@ pub struct ColorScheme {
53 53
54 54 impl Default for Config {
55 55 fn default() -> Self {
56 + use crate::keyboard::handlers::Key;
57 + use crate::keyboard::{Arg, KeyAction, keycodes};
58 + use x11rb::protocol::xproto::KeyButMask;
59 +
60 + const MODKEY: KeyButMask = KeyButMask::MOD4;
61 + const SHIFT: KeyButMask = KeyButMask::SHIFT;
62 +
63 + // Detect terminal
64 + let terminal = detect_terminal();
65 +
56 66 Self {
57 67 border_width: 2,
58 68 border_focused: 0x6dade3,
@@ -63,13 +73,101 @@ impl Default for Config {
63 73 gap_inner_vertical: 0,
64 74 gap_outer_horizontal: 0,
65 75 gap_outer_vertical: 0,
66 - terminal: "xterm".to_string(),
67 - modkey: x11rb::protocol::xproto::KeyButMask::MOD4,
76 + terminal,
77 + modkey: MODKEY,
68 78 tags: vec!["1", "2", "3", "4", "5", "6", "7", "8", "9"]
69 79 .into_iter()
70 80 .map(String::from)
71 81 .collect(),
72 - keybindings: Vec::new(),
82 + keybindings: vec![
83 + // Launch terminal
84 + Key::new(
85 + &[MODKEY],
86 + keycodes::RETURN,
87 + KeyAction::Spawn,
88 + Arg::Str("xterm"),
89 + ),
90 + // Window management
91 + Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
92 + Key::new(
93 + &[MODKEY, SHIFT],
94 + keycodes::F,
95 + KeyAction::ToggleFullScreen,
96 + Arg::None,
97 + ),
98 + Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None),
99 + // WM controls
100 + Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None),
101 + Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None),
102 + // Focus
103 + Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)),
104 + Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)),
105 + // View tags
106 + Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)),
107 + Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)),
108 + Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)),
109 + Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)),
110 + Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)),
111 + Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)),
112 + Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)),
113 + Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)),
114 + Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)),
115 + // Move windows to tags
116 + Key::new(
117 + &[MODKEY, SHIFT],
118 + keycodes::KEY_1,
119 + KeyAction::MoveToTag,
120 + Arg::Int(0),
121 + ),
122 + Key::new(
123 + &[MODKEY, SHIFT],
124 + keycodes::KEY_2,
125 + KeyAction::MoveToTag,
126 + Arg::Int(1),
127 + ),
128 + Key::new(
129 + &[MODKEY, SHIFT],
130 + keycodes::KEY_3,
131 + KeyAction::MoveToTag,
132 + Arg::Int(2),
133 + ),
134 + Key::new(
135 + &[MODKEY, SHIFT],
136 + keycodes::KEY_4,
137 + KeyAction::MoveToTag,
138 + Arg::Int(3),
139 + ),
140 + Key::new(
141 + &[MODKEY, SHIFT],
142 + keycodes::KEY_5,
143 + KeyAction::MoveToTag,
144 + Arg::Int(4),
145 + ),
146 + Key::new(
147 + &[MODKEY, SHIFT],
148 + keycodes::KEY_6,
149 + KeyAction::MoveToTag,
150 + Arg::Int(5),
151 + ),
152 + Key::new(
153 + &[MODKEY, SHIFT],
154 + keycodes::KEY_7,
155 + KeyAction::MoveToTag,
156 + Arg::Int(6),
157 + ),
158 + Key::new(
159 + &[MODKEY, SHIFT],
160 + keycodes::KEY_8,
161 + KeyAction::MoveToTag,
162 + Arg::Int(7),
163 + ),
164 + Key::new(
165 + &[MODKEY, SHIFT],
166 + keycodes::KEY_9,
167 + KeyAction::MoveToTag,
168 + Arg::Int(8),
169 + ),
170 + ],
73 171 status_blocks: Vec::new(),
74 172 scheme_normal: ColorScheme {
75 173 foreground: 0xbbbbbb,
@@ -89,3 +187,19 @@ impl Default for Config {
89 187 }
90 188 }
91 189 }
190 +
191 +fn detect_terminal() -> String {
192 + let terminals = ["alacritty", "kitty", "st", "xterm", "urxvt", "termite"];
193 +
194 + for term in &terminals {
195 + if std::process::Command::new("which")
196 + .arg(term)
197 + .output()
198 + .map(|o| o.status.success())
199 + .unwrap_or(false)
200 + {
201 + return term.to_string();
202 + }
203 + }
204 + "xterm".to_string()
205 +}