tony / oxwm

Merge remote-tracking branch 'origin/master' into floating Browse files
xsoder committed 2025-10-14 parents 5875fad 6c3b329 commit 7efd8c0251749ae8dc55b649cae4b70168c850c3
Showing 6 changed files with 27 additions and 139 deletions. UnifiedSplit
+1 −1 Cargo.lock
@@ -213,7 +213,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
213 213
214 214 [[package]]
215 215 name = "oxwm"
216 -version = "0.1.1"
216 +version = "0.1.11"
217 217 dependencies = [
218 218 "anyhow",
219 219 "chrono",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 1 [package]
2 2 name = "oxwm"
3 -version = "0.1.1"
3 +version = "0.1.11"
4 4 edition = "2024"
5 5
6 6 [lib]
+0 −0 images/oxwm1.png new file mode 100644, Binary files /dev/null and b/images/oxwm1.png differ
+2 −0 readme.org
@@ -1,6 +1,8 @@
1 1 #+AUTHOR: Tony
2 2 #+STARTUP: overview
3 3
4 +[[file:./images/oxwm1.png]]
5 +
4 6 * Table of Contents :toc:
5 7 - [[#oxwm--dwm-but-better-and-oxidized][OXWM — DWM but Better (and oxidized)]]
6 8 - [[#installation][Installation]]
+10 −24 src/bin/main.rs
@@ -26,24 +26,16 @@ fn main() -> Result<()> {
26 26 _ => {}
27 27 }
28 28
29 - let user_binary = get_user_binary_path();
30 - let config_path = get_config_path().join("config.rs");
31 -
32 - if config_path.exists() && user_binary.exists() {
33 - if !should_recompile(&config_path, &user_binary)? {
34 - use std::os::unix::process::CommandExt;
35 - let err = std::process::Command::new(&user_binary)
36 - .args(&args[1..])
37 - .exec();
38 - eprintln!("Failed to exec user binary: {}", err);
39 - std::process::exit(1);
40 - }
41 - }
29 + let config_dir = get_config_path();
30 + let user_bin = config_dir.join("target/release/oxwm-user");
42 31
43 - if !config_path.exists() {
44 - eprintln!("No config found, creating default at ~/.config/oxwm/config.rs");
45 - init_config()?;
46 - eprintln!("✓ Edit ~/.config/oxwm/config.rs and run 'oxwm --recompile'");
32 + if user_bin.exists() {
33 + use std::os::unix::process::CommandExt;
34 + let err = std::process::Command::new(&user_bin)
35 + .args(&args[1..])
36 + .exec();
37 + eprintln!("Failed to exec user binary: {}", err);
38 + std::process::exit(1);
47 39 }
48 40
49 41 let config = oxwm::Config::default();
@@ -175,13 +167,7 @@ fn recompile_config() -> Result<()> {
175 167 anyhow::bail!("Failed to compile configuration");
176 168 }
177 169
178 - let source = config_dir.join("target/release/oxwm-user");
179 - let dest = get_user_binary_path();
180 -
181 - std::fs::create_dir_all(dest.parent().unwrap())?;
182 - std::fs::copy(&source, &dest)?;
183 -
184 - println!("✓ Compiled successfully to {}", dest.display());
170 + println!("✓ Compiled successfully.");
185 171 println!(" Restart oxwm to use new config");
186 172
187 173 Ok(())
+13 −113 src/window_manager.rs
@@ -170,9 +170,8 @@ impl WindowManager {
170 170 continue;
171 171 }
172 172
173 - let attrs = match self.connection.get_window_attributes(window)?.reply() {
174 - Ok(attrs) => attrs,
175 - Err(_) => continue,
173 + let Ok(attrs) = self.connection.get_window_attributes(window)?.reply() else {
174 + continue;
176 175 };
177 176
178 177 if attrs.override_redirect {
@@ -187,27 +186,21 @@ impl WindowManager {
187 186 }
188 187
189 188 if attrs.map_state == MapState::UNMAPPED {
190 - let has_wm_state = match self
189 + let has_wm_state = self
191 190 .connection
192 191 .get_property(false, window, wm_state_atom, AtomEnum::ANY, 0, 2)?
193 192 .reply()
194 - {
195 - Ok(prop) => !prop.value.is_empty(),
196 - Err(_) => false,
197 - };
193 + .is_ok_and(|prop| !prop.value.is_empty());
198 194
199 195 if !has_wm_state {
200 196 continue;
201 197 }
202 198
203 - let has_wm_class = match self
199 + let has_wm_class = self
204 200 .connection
205 201 .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)?
206 202 .reply()
207 - {
208 - Ok(prop) => !prop.value.is_empty(),
209 - Err(_) => false,
210 - };
203 + .is_ok_and(|prop| !prop.value.is_empty());
211 204
212 205 if has_wm_class {
213 206 let tag = self.get_saved_tag(window, net_client_info)?;
@@ -299,73 +292,6 @@ impl WindowManager {
299 292 Ok(())
300 293 }
301 294
302 - fn handle_restart(&self) -> Result<bool> {
303 - let user_binary = get_config_path().join("oxwm-user");
304 -
305 - if user_binary.exists() && self.needs_recompile()? {
306 - println!("Config changed, recompiling...");
307 - self.recompile()?;
308 - }
309 -
310 - Ok(true)
311 - }
312 -
313 - fn needs_recompile(&self) -> Result<bool> {
314 - let config_dir = get_config_path();
315 - let binary_path = get_user_binary_path();
316 -
317 - if !binary_path.exists() {
318 - return Ok(true);
319 - }
320 -
321 - let binary_time = std::fs::metadata(&binary_path)?.modified()?;
322 -
323 - let watch_files = ["config.rs", "main.rs", "Cargo.toml"];
324 -
325 - for filename in &watch_files {
326 - let path = config_dir.join(filename);
327 - if !path.exists() {
328 - continue;
329 - }
330 -
331 - let file_time = std::fs::metadata(&path)?.modified()?;
332 - if file_time > binary_time {
333 - println!("✓ Change detected: {}", filename);
334 - return Ok(true);
335 - }
336 - }
337 -
338 - Ok(false)
339 - }
340 -
341 - fn recompile(&self) -> Result<()> {
342 - let config_dir = get_config_path();
343 -
344 - notify("OXWM", "Recompiling configuration...");
345 -
346 - let output = std::process::Command::new("cargo")
347 - .args(&["build", "--release"])
348 - .current_dir(&config_dir)
349 - .output()?;
350 -
351 - if !output.status.success() {
352 - let stderr = String::from_utf8_lossy(&output.stderr);
353 - notify_error("OXWM Compile Error", &stderr);
354 - eprintln!("Compilation failed:\n{}", stderr);
355 - anyhow::bail!("Failed to compile configuration");
356 - }
357 -
358 - let source = config_dir.join("target/release/oxwm-user");
359 - let dest = get_user_binary_path();
360 -
361 - std::fs::create_dir_all(dest.parent().unwrap())?;
362 - std::fs::copy(&source, &dest)?;
363 -
364 - notify("OXWM", "Recompiled successfully! Restarting...");
365 -
366 - Ok(())
367 - }
368 -
369 295 pub fn run(&mut self) -> Result<bool> {
370 296 println!("oxwm started on display {}", self.screen_number);
371 297
@@ -484,8 +410,12 @@ impl WindowManager {
484 410 // Handled in handle_event
485 411 }
486 412 KeyAction::Recompile => {
487 - if let Err(e) = self.recompile() {
488 - eprintln!("Recompile failed: {}", e);
413 + match std::process::Command::new("oxwm")
414 + .arg("--recompile")
415 + .spawn()
416 + {
417 + Ok(_) => eprintln!("Recompiling in background"),
418 + Err(e) => eprintln!("Failed to spawn recompile: {}", e),
489 419 }
490 420 }
491 421 KeyAction::ViewTag => {
@@ -833,7 +763,7 @@ impl WindowManager {
833 763 let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings)?;
834 764 match action {
835 765 KeyAction::Quit => return Ok(Some(false)),
836 - KeyAction::Restart => return Ok(Some(self.handle_restart()?)),
766 + KeyAction::Restart => return Ok(Some(true)),
837 767 _ => self.handle_key_action(action, &arg)?,
838 768 }
839 769 }
@@ -946,33 +876,3 @@ impl WindowManager {
946 876 Ok(())
947 877 }
948 878 }
949 -
950 -fn get_config_path() -> PathBuf {
951 - dirs::config_dir()
952 - .expect("Could not find config directory")
953 - .join("oxwm")
954 -}
955 -
956 -fn get_user_binary_path() -> PathBuf {
957 - get_config_path().join("oxwm-user")
958 -}
959 -
960 -fn can_recompile() -> bool {
961 - std::process::Command::new("cargo")
962 - .arg("--version")
963 - .output()
964 - .map(|o| o.status.success())
965 - .unwrap_or(false)
966 -}
967 -
968 -fn notify(title: &str, body: &str) {
969 - let _ = std::process::Command::new("notify-send")
970 - .args(&[title, body])
971 - .spawn();
972 -}
973 -
974 -fn notify_error(title: &str, body: &str) {
975 - let _ = std::process::Command::new("notify-send")
976 - .args(&["-u", "critical", title, body])
977 - .spawn();
978 -}