|
|
@@ -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 |
|
-} |