tony / oxwm

format files Browse files
emzywastaken committed 2025-12-12 parent d90e50d commit bb500f41ff598a5d95cd754bde34609eb7bef79e
Showing 12 changed files with 836 additions and 472 deletions. UnifiedSplit
+8 −2 src/bar/bar.rs
@@ -326,7 +326,8 @@ impl Bar {
326 let underline_x = x_position - (underline_padding / 2) as i16; 326 let underline_x = x_position - (underline_padding / 2) as i16;
327 327
328 unsafe { 328 unsafe {
329 - let gc = x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut()); 329 + let gc =
330 + x11::xlib::XCreateGC(display, self.pixmap, 0, std::ptr::null_mut());
330 x11::xlib::XSetForeground(display, gc, block.color() as u64); 331 x11::xlib::XSetForeground(display, gc, block.color() as u64);
331 x11::xlib::XFillRectangle( 332 x11::xlib::XFillRectangle(
332 display, 333 display,
@@ -345,7 +346,12 @@ impl Bar {
345 } 346 }
346 347
347 unsafe { 348 unsafe {
348 - let gc = x11::xlib::XCreateGC(display, self.window as x11::xlib::Drawable, 0, std::ptr::null_mut()); 349 + let gc = x11::xlib::XCreateGC(
350 + display,
351 + self.window as x11::xlib::Drawable,
352 + 0,
353 + std::ptr::null_mut(),
354 + );
349 x11::xlib::XCopyArea( 355 x11::xlib::XCopyArea(
350 display, 356 display,
351 self.pixmap, 357 self.pixmap,
+6 −2 src/bin/main.rs
@@ -43,14 +43,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
43 43
44 if should_restart { 44 if should_restart {
45 use std::os::unix::process::CommandExt; 45 use std::os::unix::process::CommandExt;
46 - let error = std::process::Command::new(&arguments[0]).args(&arguments[1..]).exec(); 46 + let error = std::process::Command::new(&arguments[0])
47 + .args(&arguments[1..])
48 + .exec();
47 eprintln!("Failed to restart: {}", error); 49 eprintln!("Failed to restart: {}", error);
48 } 50 }
49 51
50 Ok(()) 52 Ok(())
51 } 53 }
52 54
53 -fn load_config(custom_path: Option<PathBuf>) -> Result<(oxwm::Config, bool), Box<dyn std::error::Error>> { 55 +fn load_config(
56 + custom_path: Option<PathBuf>,
57 +) -> Result<(oxwm::Config, bool), Box<dyn std::error::Error>> {
54 let config_path = if let Some(path) = custom_path { 58 let config_path = if let Some(path) = custom_path {
55 path 59 path
56 } else { 60 } else {
+1 −1 src/config/lua.rs
@@ -48,5 +48,5 @@ pub fn parse_lua_config(
48 scheme_occupied: builder_data.scheme_occupied, 48 scheme_occupied: builder_data.scheme_occupied,
49 scheme_selected: builder_data.scheme_selected, 49 scheme_selected: builder_data.scheme_selected,
50 autostart: builder_data.autostart, 50 autostart: builder_data.autostart,
51 - }) 51 + });
52 } 52 }
+213 −134 src/config/lua_api.rs Large diff collapsed, click to expand
@@ -2,11 +2,11 @@ use mlua::{Lua, Table, Value};
2 use std::cell::RefCell; 2 use std::cell::RefCell;
3 use std::rc::Rc; 3 use std::rc::Rc;
4 4
5 +use crate::ColorScheme;
5 use crate::bar::BlockConfig; 6 use crate::bar::BlockConfig;
6 use crate::errors::ConfigError; 7 use crate::errors::ConfigError;
7 use crate::keyboard::handlers::{Arg, KeyAction, KeyBinding, KeyPress}; 8 use crate::keyboard::handlers::{Arg, KeyAction, KeyBinding, KeyPress};
8 use crate::keyboard::keysyms::{self, Keysym}; 9 use crate::keyboard::keysyms::{self, Keysym};
9 -use crate::ColorScheme;
10 use x11rb::protocol::xproto::KeyButMask; 10 use x11rb::protocol::xproto::KeyButMask;
11 11
12 #[derive(Clone)] 12 #[derive(Clone)]
@@ -99,18 +99,19 @@ pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
99 } 99 }
100 100
101 fn register_spawn(lua: &Lua, parent: &Table, _builder: SharedBuilder) -> Result<(), ConfigError> { 101 fn register_spawn(lua: &Lua, parent: &Table, _builder: SharedBuilder) -> Result<(), ConfigError> {
102 - let spawn = lua.create_function(|lua, cmd: Value| { 102 + let spawn = lua.create_function(|lua, cmd: Value| create_action_table(lua, "Spawn", cmd))?;
103 - create_action_table(lua, "Spawn", cmd) 103 + let spawn_terminal =
104 - })?; 104 + lua.create_function(|lua, ()| create_action_table(lua, "SpawnTerminal", Value::Nil))?;
105 - let spawn_terminal = lua.create_function(|lua, ()| {
106 - create_action_table(lua, "SpawnTerminal", Value::Nil)
107 - })?;
108 parent.set("spawn", spawn)?; 105 parent.set("spawn", spawn)?;
109 parent.set("spawn_terminal", spawn_terminal)?; 106 parent.set("spawn_terminal", spawn_terminal)?;
110 Ok(()) 107 Ok(())
111 } 108 }
112 109
113 -fn register_key_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 110 +fn register_key_module(
111 + lua: &Lua,
112 + parent: &Table,
113 + builder: SharedBuilder,
114 +) -> Result<(), ConfigError> {
114 let key_table = lua.create_table()?; 115 let key_table = lua.create_table()?;
115 116
116 let builder_clone = builder.clone(); 117 let builder_clone = builder.clone();
@@ -153,7 +154,11 @@ fn register_key_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
153 Ok(()) 154 Ok(())
154 } 155 }
155 156
156 -fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 157 +fn register_gaps_module(
158 + lua: &Lua,
159 + parent: &Table,
160 + builder: SharedBuilder,
161 +) -> Result<(), ConfigError> {
157 let gaps_table = lua.create_table()?; 162 let gaps_table = lua.create_table()?;
158 163
159 let builder_clone = builder.clone(); 164 let builder_clone = builder.clone();
@@ -206,7 +211,11 @@ fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Re
206 Ok(()) 211 Ok(())
207 } 212 }
208 213
209 -fn register_border_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 214 +fn register_border_module(
215 + lua: &Lua,
216 + parent: &Table,
217 + builder: SharedBuilder,
218 +) -> Result<(), ConfigError> {
210 let border_table = lua.create_table()?; 219 let border_table = lua.create_table()?;
211 220
212 let builder_clone = builder.clone(); 221 let builder_clone = builder.clone();
@@ -239,17 +248,13 @@ fn register_border_module(lua: &Lua, parent: &Table, builder: SharedBuilder) ->
239 fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> { 248 fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
240 let client_table = lua.create_table()?; 249 let client_table = lua.create_table()?;
241 250
242 - let kill = lua.create_function(|lua, ()| { 251 + let kill = lua.create_function(|lua, ()| create_action_table(lua, "KillClient", Value::Nil))?;
243 - create_action_table(lua, "KillClient", Value::Nil)
244 - })?;
245 252
246 - let toggle_fullscreen = lua.create_function(|lua, ()| { 253 + let toggle_fullscreen =
247 - create_action_table(lua, "ToggleFullScreen", Value::Nil) 254 + lua.create_function(|lua, ()| create_action_table(lua, "ToggleFullScreen", Value::Nil))?;
248 - })?;
249 255
250 - let toggle_floating = lua.create_function(|lua, ()| { 256 + let toggle_floating =
251 - create_action_table(lua, "ToggleFloating", Value::Nil) 257 + lua.create_function(|lua, ()| create_action_table(lua, "ToggleFloating", Value::Nil))?;
252 - })?;
253 258
254 let focus_stack = lua.create_function(|lua, dir: i32| { 259 let focus_stack = lua.create_function(|lua, dir: i32| {
255 create_action_table(lua, "FocusStack", Value::Integer(dir as i64)) 260 create_action_table(lua, "FocusStack", Value::Integer(dir as i64))
@@ -272,12 +277,15 @@ fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError>
272 fn register_layout_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> { 277 fn register_layout_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
273 let layout_table = lua.create_table()?; 278 let layout_table = lua.create_table()?;
274 279
275 - let cycle = lua.create_function(|lua, ()| { 280 + let cycle =
276 - create_action_table(lua, "CycleLayout", Value::Nil) 281 + lua.create_function(|lua, ()| create_action_table(lua, "CycleLayout", Value::Nil))?;
277 - })?;
278 282
279 let set = lua.create_function(|lua, name: String| { 283 let set = lua.create_function(|lua, name: String| {
280 - create_action_table(lua, "ChangeLayout", Value::String(lua.create_string(&name)?)) 284 + create_action_table(
285 + lua,
286 + "ChangeLayout",
287 + Value::String(lua.create_string(&name)?),
288 + )
281 })?; 289 })?;
282 290
283 layout_table.set("cycle", cycle)?; 291 layout_table.set("cycle", cycle)?;
@@ -330,7 +338,11 @@ fn register_monitor_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError>
330 Ok(()) 338 Ok(())
331 } 339 }
332 340
333 -fn register_rule_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 341 +fn register_rule_module(
342 + lua: &Lua,
343 + parent: &Table,
344 + builder: SharedBuilder,
345 +) -> Result<(), ConfigError> {
334 let rule_table = lua.create_table()?; 346 let rule_table = lua.create_table()?;
335 347
336 let builder_clone = builder.clone(); 348 let builder_clone = builder.clone();
@@ -369,7 +381,11 @@ fn register_rule_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Re
369 Ok(()) 381 Ok(())
370 } 382 }
371 383
372 -fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<(), ConfigError> { 384 +fn register_bar_module(
385 + lua: &Lua,
386 + parent: &Table,
387 + builder: SharedBuilder,
388 +) -> Result<(), ConfigError> {
373 let bar_table = lua.create_table()?; 389 let bar_table = lua.create_table()?;
374 390
375 let builder_clone = builder.clone(); 391 let builder_clone = builder.clone();
@@ -380,35 +396,59 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
380 396
381 let block_table = lua.create_table()?; 397 let block_table = lua.create_table()?;
382 398
383 - let ram = lua.create_function(|lua, config: Table| { 399 + let ram =
384 - create_block_config(lua, config, "Ram", None) 400 + lua.create_function(|lua, config: Table| create_block_config(lua, config, "Ram", None))?;
385 - })?;
386 401
387 let datetime = lua.create_function(|lua, config: Table| { 402 let datetime = lua.create_function(|lua, config: Table| {
388 - let date_format: String = config.get("date_format") 403 + let date_format: String = config.get("date_format").map_err(|_| {
389 - .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.datetime: 'date_format' field is required (e.g., '%H:%M')".into()))?; 404 + mlua::Error::RuntimeError(
390 - create_block_config(lua, config, "DateTime", Some(Value::String(lua.create_string(&date_format)?))) 405 + "oxwm.bar.block.datetime: 'date_format' field is required (e.g., '%H:%M')".into(),
406 + )
407 + })?;
408 + create_block_config(
409 + lua,
410 + config,
411 + "DateTime",
412 + Some(Value::String(lua.create_string(&date_format)?)),
413 + )
391 })?; 414 })?;
392 415
393 let shell = lua.create_function(|lua, config: Table| { 416 let shell = lua.create_function(|lua, config: Table| {
394 - let command: String = config.get("command") 417 + let command: String = config.get("command").map_err(|_| {
395 - .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.shell: 'command' field is required".into()))?; 418 + mlua::Error::RuntimeError("oxwm.bar.block.shell: 'command' field is required".into())
396 - create_block_config(lua, config, "Shell", Some(Value::String(lua.create_string(&command)?))) 419 + })?;
420 + create_block_config(
421 + lua,
422 + config,
423 + "Shell",
424 + Some(Value::String(lua.create_string(&command)?)),
425 + )
397 })?; 426 })?;
398 427
399 let static_block = lua.create_function(|lua, config: Table| { 428 let static_block = lua.create_function(|lua, config: Table| {
400 - let text: String = config.get("text") 429 + let text: String = config.get("text").map_err(|_| {
401 - .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.static: 'text' field is required".into()))?; 430 + mlua::Error::RuntimeError("oxwm.bar.block.static: 'text' field is required".into())
402 - create_block_config(lua, config, "Static", Some(Value::String(lua.create_string(&text)?))) 431 + })?;
432 + create_block_config(
433 + lua,
434 + config,
435 + "Static",
436 + Some(Value::String(lua.create_string(&text)?)),
437 + )
403 })?; 438 })?;
404 439
405 let battery = lua.create_function(|lua, config: Table| { 440 let battery = lua.create_function(|lua, config: Table| {
406 - let charging: String = config.get("charging") 441 + let charging: String = config.get("charging").map_err(|_| {
407 - .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.battery: 'charging' field is required".into()))?; 442 + mlua::Error::RuntimeError("oxwm.bar.block.battery: 'charging' field is required".into())
408 - let discharging: String = config.get("discharging") 443 + })?;
409 - .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.battery: 'discharging' field is required".into()))?; 444 + let discharging: String = config.get("discharging").map_err(|_| {
410 - let full: String = config.get("full") 445 + mlua::Error::RuntimeError(
411 - .map_err(|_| mlua::Error::RuntimeError("oxwm.bar.block.battery: 'full' field is required".into()))?; 446 + "oxwm.bar.block.battery: 'discharging' field is required".into(),
447 + )
448 + })?;
449 + let full: String = config.get("full").map_err(|_| {
450 + mlua::Error::RuntimeError("oxwm.bar.block.battery: 'full' field is required".into())
451 + })?;
412 452
413 let formats_table = lua.create_table()?; 453 let formats_table = lua.create_table()?;
414 formats_table.set("charging", charging)?; 454 formats_table.set("charging", charging)?;
@@ -496,44 +536,58 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
496 536
497 let cmd = match block_type.as_str() { 537 let cmd = match block_type.as_str() {
498 "DateTime" => { 538 "DateTime" => {
499 - let fmt = arg.and_then(|v| { 539 + let fmt = arg
500 - if let Value::String(s) = v { 540 + .and_then(|v| {
501 - s.to_str().ok().map(|s| s.to_string()) 541 + if let Value::String(s) = v {
502 - } else { 542 + s.to_str().ok().map(|s| s.to_string())
503 - None 543 + } else {
504 - } 544 + None
505 - }).ok_or_else(|| mlua::Error::RuntimeError("DateTime block missing format".into()))?; 545 + }
546 + })
547 + .ok_or_else(|| {
548 + mlua::Error::RuntimeError("DateTime block missing format".into())
549 + })?;
506 BlockCommand::DateTime(fmt) 550 BlockCommand::DateTime(fmt)
507 } 551 }
508 "Shell" => { 552 "Shell" => {
509 - let cmd_str = arg.and_then(|v| { 553 + let cmd_str = arg
510 - if let Value::String(s) = v { 554 + .and_then(|v| {
511 - s.to_str().ok().map(|s| s.to_string()) 555 + if let Value::String(s) = v {
512 - } else { 556 + s.to_str().ok().map(|s| s.to_string())
513 - None 557 + } else {
514 - } 558 + None
515 - }).ok_or_else(|| mlua::Error::RuntimeError("Shell block missing command".into()))?; 559 + }
560 + })
561 + .ok_or_else(|| {
562 + mlua::Error::RuntimeError("Shell block missing command".into())
563 + })?;
516 BlockCommand::Shell(cmd_str) 564 BlockCommand::Shell(cmd_str)
517 } 565 }
518 "Ram" => BlockCommand::Ram, 566 "Ram" => BlockCommand::Ram,
519 "Static" => { 567 "Static" => {
520 - let text = arg.and_then(|v| { 568 + let text = arg
521 - if let Value::String(s) = v { 569 + .and_then(|v| {
522 - s.to_str().ok().map(|s| s.to_string()) 570 + if let Value::String(s) = v {
523 - } else { 571 + s.to_str().ok().map(|s| s.to_string())
524 - None 572 + } else {
525 - } 573 + None
526 - }).unwrap_or_default(); 574 + }
575 + })
576 + .unwrap_or_default();
527 BlockCommand::Static(text) 577 BlockCommand::Static(text)
528 } 578 }
529 "Battery" => { 579 "Battery" => {
530 - let formats = arg.and_then(|v| { 580 + let formats = arg
531 - if let Value::Table(t) = v { 581 + .and_then(|v| {
532 - Some(t) 582 + if let Value::Table(t) = v {
533 - } else { 583 + Some(t)
534 - None 584 + } else {
535 - } 585 + None
536 - }).ok_or_else(|| mlua::Error::RuntimeError("Battery block missing formats".into()))?; 586 + }
587 + })
588 + .ok_or_else(|| {
589 + mlua::Error::RuntimeError("Battery block missing formats".into())
590 + })?;
537 591
538 let charging: String = formats.get("charging")?; 592 let charging: String = formats.get("charging")?;
539 let discharging: String = formats.get("discharging")?; 593 let discharging: String = formats.get("discharging")?;
@@ -545,7 +599,12 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
545 format_full: full, 599 format_full: full,
546 } 600 }
547 } 601 }
548 - _ => return Err(mlua::Error::RuntimeError(format!("Unknown block type '{}'", block_type))), 602 + _ => {
603 + return Err(mlua::Error::RuntimeError(format!(
604 + "Unknown block type '{}'",
605 + block_type
606 + )));
607 + }
549 }; 608 };
550 609
551 let color_u32 = parse_color_value(color_val)?; 610 let color_u32 = parse_color_value(color_val)?;
@@ -566,50 +625,53 @@ fn register_bar_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Res
566 })?; 625 })?;
567 626
568 let builder_clone = builder.clone(); 627 let builder_clone = builder.clone();
569 - let set_scheme_normal = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| { 628 + let set_scheme_normal =
570 - let foreground = parse_color_value(fg)?; 629 + lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| {
571 - let background = parse_color_value(bg)?; 630 + let foreground = parse_color_value(fg)?;
572 - let underline = parse_color_value(ul)?; 631 + let background = parse_color_value(bg)?;
573 - 632 + let underline = parse_color_value(ul)?;
574 - builder_clone.borrow_mut().scheme_normal = ColorScheme { 633 +
575 - foreground, 634 + builder_clone.borrow_mut().scheme_normal = ColorScheme {
576 - background, 635 + foreground,
577 - underline, 636 + background,
578 - }; 637 + underline,
579 - Ok(()) 638 + };
580 - })?; 639 + Ok(())
640 + })?;
581 641
582 let builder_clone = builder.clone(); 642 let builder_clone = builder.clone();
583 - let set_scheme_occupied = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| { 643 + let set_scheme_occupied =
584 - let foreground = parse_color_value(fg)?; 644 + lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| {
585 - let background = parse_color_value(bg)?; 645 + let foreground = parse_color_value(fg)?;
586 - let underline = parse_color_value(ul)?; 646 + let background = parse_color_value(bg)?;
587 - 647 + let underline = parse_color_value(ul)?;
588 - builder_clone.borrow_mut().scheme_occupied = ColorScheme { 648 +
589 - foreground, 649 + builder_clone.borrow_mut().scheme_occupied = ColorScheme {
590 - background, 650 + foreground,
591 - underline, 651 + background,
592 - }; 652 + underline,
593 - Ok(()) 653 + };
594 - })?; 654 + Ok(())
655 + })?;
595 656
596 let builder_clone = builder.clone(); 657 let builder_clone = builder.clone();
597 - let set_scheme_selected = lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| { 658 + let set_scheme_selected =
598 - let foreground = parse_color_value(fg)?; 659 + lua.create_function(move |_, (fg, bg, ul): (Value, Value, Value)| {
599 - let background = parse_color_value(bg)?; 660 + let foreground = parse_color_value(fg)?;
600 - let underline = parse_color_value(ul)?; 661 + let background = parse_color_value(bg)?;
601 - 662 + let underline = parse_color_value(ul)?;
602 - builder_clone.borrow_mut().scheme_selected = ColorScheme { 663 +
603 - foreground, 664 + builder_clone.borrow_mut().scheme_selected = ColorScheme {
604 - background, 665 + foreground,
605 - underline, 666 + background,
606 - }; 667 + underline,
607 - Ok(()) 668 + };
608 - })?; 669 + Ok(())
670 + })?;
609 671
610 bar_table.set("set_font", set_font)?; 672 bar_table.set("set_font", set_font)?;
611 bar_table.set("block", block_table)?; 673 bar_table.set("block", block_table)?;
612 - bar_table.set("add_block", add_block)?; // Deprecated, for backwards compatibility 674 + bar_table.set("add_block", add_block)?; // Deprecated, for backwards compatibility
613 bar_table.set("set_blocks", set_blocks)?; 675 bar_table.set("set_blocks", set_blocks)?;
614 bar_table.set("set_scheme_normal", set_scheme_normal)?; 676 bar_table.set("set_scheme_normal", set_scheme_normal)?;
615 bar_table.set("set_scheme_occupied", set_scheme_occupied)?; 677 bar_table.set("set_scheme_occupied", set_scheme_occupied)?;
@@ -639,17 +701,12 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
639 Ok(()) 701 Ok(())
640 })?; 702 })?;
641 703
642 - let quit = lua.create_function(|lua, ()| { 704 + let quit = lua.create_function(|lua, ()| create_action_table(lua, "Quit", Value::Nil))?;
643 - create_action_table(lua, "Quit", Value::Nil)
644 - })?;
645 705
646 - let restart = lua.create_function(|lua, ()| { 706 + let restart = lua.create_function(|lua, ()| create_action_table(lua, "Restart", Value::Nil))?;
647 - create_action_table(lua, "Restart", Value::Nil)
648 - })?;
649 707
650 - let toggle_gaps = lua.create_function(|lua, ()| { 708 + let toggle_gaps =
651 - create_action_table(lua, "ToggleGaps", Value::Nil) 709 + lua.create_function(|lua, ()| create_action_table(lua, "ToggleGaps", Value::Nil))?;
652 - })?;
653 710
654 let set_master_factor = lua.create_function(|lua, delta: i32| { 711 let set_master_factor = lua.create_function(|lua, delta: i32| {
655 create_action_table(lua, "SetMasterFactor", Value::Integer(delta as i64)) 712 create_action_table(lua, "SetMasterFactor", Value::Integer(delta as i64))
@@ -659,9 +716,8 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
659 create_action_table(lua, "IncNumMaster", Value::Integer(delta as i64)) 716 create_action_table(lua, "IncNumMaster", Value::Integer(delta as i64))
660 })?; 717 })?;
661 718
662 - let show_keybinds = lua.create_function(|lua, ()| { 719 + let show_keybinds =
663 - create_action_table(lua, "ShowKeybindOverlay", Value::Nil) 720 + lua.create_function(|lua, ()| create_action_table(lua, "ShowKeybindOverlay", Value::Nil))?;
664 - })?;
665 721
666 let focus_monitor = lua.create_function(|lua, idx: i32| { 722 let focus_monitor = lua.create_function(|lua, idx: i32| {
667 create_action_table(lua, "FocusMonitor", Value::Integer(idx as i64)) 723 create_action_table(lua, "FocusMonitor", Value::Integer(idx as i64))
@@ -669,10 +725,10 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
669 725
670 let builder_clone = builder.clone(); 726 let builder_clone = builder.clone();
671 let set_layout_symbol = lua.create_function(move |_, (name, symbol): (String, String)| { 727 let set_layout_symbol = lua.create_function(move |_, (name, symbol): (String, String)| {
672 - builder_clone.borrow_mut().layout_symbols.push(crate::LayoutSymbolOverride { 728 + builder_clone
673 - name, 729 + .borrow_mut()
674 - symbol, 730 + .layout_symbols
675 - }); 731 + .push(crate::LayoutSymbolOverride { name, symbol });
676 Ok(()) 732 Ok(())
677 })?; 733 })?;
678 734
@@ -730,7 +786,10 @@ fn parse_modkey_string(s: &str) -> Result<KeyButMask, ConfigError> {
730 "Mod5" => Ok(KeyButMask::MOD5), 786 "Mod5" => Ok(KeyButMask::MOD5),
731 "Shift" => Ok(KeyButMask::SHIFT), 787 "Shift" => Ok(KeyButMask::SHIFT),
732 "Control" => Ok(KeyButMask::CONTROL), 788 "Control" => Ok(KeyButMask::CONTROL),
733 - _ => Err(ConfigError::InvalidModkey(format!("'{}' is not a valid modifier. Use one of: Mod1, Mod4, Shift, Control", s))), 789 + _ => Err(ConfigError::InvalidModkey(format!(
790 + "'{}' is not a valid modifier. Use one of: Mod1, Mod4, Shift, Control",
791 + s
792 + ))),
734 } 793 }
735 } 794 }
736 795
@@ -790,7 +849,10 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
790 "FocusMonitor" => Ok(KeyAction::FocusMonitor), 849 "FocusMonitor" => Ok(KeyAction::FocusMonitor),
791 "TagMonitor" => Ok(KeyAction::TagMonitor), 850 "TagMonitor" => Ok(KeyAction::TagMonitor),
792 "ShowKeybindOverlay" => Ok(KeyAction::ShowKeybindOverlay), 851 "ShowKeybindOverlay" => Ok(KeyAction::ShowKeybindOverlay),
793 - _ => Err(mlua::Error::RuntimeError(format!("unknown action '{}'. this is an internal error, please report it", s))), 852 + _ => Err(mlua::Error::RuntimeError(format!(
853 + "unknown action '{}'. this is an internal error, please report it",
854 + s
855 + ))),
794 } 856 }
795 } 857 }
796 858
@@ -826,14 +888,26 @@ fn parse_color_value(value: Value) -> mlua::Result<u32> {
826 Value::String(s) => { 888 Value::String(s) => {
827 let s = s.to_str()?; 889 let s = s.to_str()?;
828 if s.starts_with('#') { 890 if s.starts_with('#') {
829 - u32::from_str_radix(&s[1..], 16) 891 + u32::from_str_radix(&s[1..], 16).map_err(|e| {
830 - .map_err(|e| mlua::Error::RuntimeError(format!("invalid hex color '{}': {}. use format like #ff0000 or 0xff0000", s, e))) 892 + mlua::Error::RuntimeError(format!(
893 + "invalid hex color '{}': {}. use format like #ff0000 or 0xff0000",
894 + s, e
895 + ))
896 + })
831 } else if s.starts_with("0x") { 897 } else if s.starts_with("0x") {
832 - u32::from_str_radix(&s[2..], 16) 898 + u32::from_str_radix(&s[2..], 16).map_err(|e| {
833 - .map_err(|e| mlua::Error::RuntimeError(format!("invalid hex color '{}': {}. use format like 0xff0000 or #ff0000", s, e))) 899 + mlua::Error::RuntimeError(format!(
900 + "invalid hex color '{}': {}. use format like 0xff0000 or #ff0000",
901 + s, e
902 + ))
903 + })
834 } else { 904 } else {
835 - s.parse::<u32>() 905 + s.parse::<u32>().map_err(|e| {
836 - .map_err(|e| mlua::Error::RuntimeError(format!("invalid color '{}': {}. use hex format like 0xff0000 or #ff0000", s, e))) 906 + mlua::Error::RuntimeError(format!(
907 + "invalid color '{}': {}. use hex format like 0xff0000 or #ff0000",
908 + s, e
909 + ))
910 + })
837 } 911 }
838 } 912 }
839 _ => Err(mlua::Error::RuntimeError( 913 _ => Err(mlua::Error::RuntimeError(
@@ -842,7 +916,12 @@ fn parse_color_value(value: Value) -> mlua::Result<u32> {
842 } 916 }
843 } 917 }
844 918
845 -fn create_block_config(lua: &Lua, config: Table, block_type: &str, arg: Option<Value>) -> mlua::Result<Table> { 919 +fn create_block_config(
920 + lua: &Lua,
921 + config: Table,
922 + block_type: &str,
923 + arg: Option<Value>,
924 +) -> mlua::Result<Table> {
846 let table = lua.create_table()?; 925 let table = lua.create_table()?;
847 table.set("__block_type", block_type)?; 926 table.set("__block_type", block_type)?;
848 927
+0 −1 src/config/mod.rs
@@ -2,4 +2,3 @@ mod lua;
2 mod lua_api; 2 mod lua_api;
3 3
4 pub use lua::parse_lua_config; 4 pub use lua::parse_lua_config;
5 -
+5 −1 src/errors.rs
@@ -47,7 +47,11 @@ impl std::fmt::Display for WmError {
47 Self::Io(error) => write!(f, "{}", error), 47 Self::Io(error) => write!(f, "{}", error),
48 Self::Config(error) => write!(f, "{}", error), 48 Self::Config(error) => write!(f, "{}", error),
49 Self::Block(error) => write!(f, "{}", error), 49 Self::Block(error) => write!(f, "{}", error),
50 - Self::Autostart(command, error) => write!(f, "Failed to spawn autostart command '{}': {}", command, error), 50 + Self::Autostart(command, error) => write!(
51 + f,
52 + "Failed to spawn autostart command '{}': {}",
53 + command, error
54 + ),
51 } 55 }
52 } 56 }
53 } 57 }
+9 −2 src/keyboard/handlers.rs
@@ -118,7 +118,12 @@ impl KeyboardMapping {
118 self.syms.get(index).copied().unwrap_or(0) 118 self.syms.get(index).copied().unwrap_or(0)
119 } 119 }
120 120
121 - pub fn find_keycode(&self, keysym: Keysym, min_keycode: Keycode, max_keycode: Keycode) -> Option<Keycode> { 121 + pub fn find_keycode(
122 + &self,
123 + keysym: Keysym,
124 + min_keycode: Keycode,
125 + max_keycode: Keycode,
126 + ) -> Option<Keycode> {
122 for keycode in min_keycode..=max_keycode { 127 for keycode in min_keycode..=max_keycode {
123 let index = (keycode - self.min_keycode) as usize * self.keysyms_per_keycode as usize; 128 let index = (keycode - self.min_keycode) as usize * self.keysyms_per_keycode as usize;
124 if let Some(&sym) = self.syms.get(index) { 129 if let Some(&sym) = self.syms.get(index) {
@@ -194,7 +199,9 @@ pub fn grab_keys(
194 } 199 }
195 200
196 if current_key > 0 { 201 if current_key > 0 {
197 - if let Some(escape_keycode) = mapping.find_keycode(keysyms::XK_ESCAPE, min_keycode, max_keycode) { 202 + if let Some(escape_keycode) =
203 + mapping.find_keycode(keysyms::XK_ESCAPE, min_keycode, max_keycode)
204 + {
198 connection.grab_key( 205 connection.grab_key(
199 true, 206 true,
200 root, 207 root,
+2 −1 src/layout/tiling.rs
@@ -124,7 +124,8 @@ impl Layout for TilingLayout {
124 let mut master_width = stack_width; 124 let mut master_width = stack_width;
125 125
126 if num_master > 0 && window_count > num_master_usize { 126 if num_master > 0 && window_count > num_master_usize {
127 - stack_width = ((master_width as f32 - inner_gap_vertical as f32) * (1.0 - master_factor)) as i32; 127 + stack_width =
128 + ((master_width as f32 - inner_gap_vertical as f32) * (1.0 - master_factor)) as i32;
128 master_width = master_width - inner_gap_vertical as i32 - stack_width; 129 master_width = master_width - inner_gap_vertical as i32 - stack_width;
129 stack_x = master_x + master_width + inner_gap_vertical as i32; 130 stack_x = master_x + master_width + inner_gap_vertical as i32;
130 } 131 }
+36 −7 src/lib.rs
@@ -38,9 +38,18 @@ pub struct WindowRule {
38 38
39 impl WindowRule { 39 impl WindowRule {
40 pub fn matches(&self, class: &str, instance: &str, title: &str) -> bool { 40 pub fn matches(&self, class: &str, instance: &str, title: &str) -> bool {
41 - let class_matches = self.class.as_ref().map_or(true, |c| class.contains(c.as_str())); 41 + let class_matches = self
42 - let instance_matches = self.instance.as_ref().map_or(true, |i| instance.contains(i.as_str())); 42 + .class
43 - let title_matches = self.title.as_ref().map_or(true, |t| title.contains(t.as_str())); 43 + .as_ref()
44 + .map_or(true, |c| class.contains(c.as_str()));
45 + let instance_matches = self
46 + .instance
47 + .as_ref()
48 + .map_or(true, |i| instance.contains(i.as_str()));
49 + let title_matches = self
50 + .title
51 + .as_ref()
52 + .map_or(true, |t| title.contains(t.as_str()));
44 class_matches && instance_matches && title_matches 53 class_matches && instance_matches && title_matches
45 } 54 }
46 } 55 }
@@ -142,16 +151,36 @@ impl Default for Config {
142 "dmenu_run -l 10".to_string(), 151 "dmenu_run -l 10".to_string(),
143 ]), 152 ]),
144 ), 153 ),
145 - KeyBinding::single_key(vec![MODKEY], keysyms::XK_Q, KeyAction::KillClient, Arg::None), 154 + KeyBinding::single_key(
146 - KeyBinding::single_key(vec![MODKEY], keysyms::XK_N, KeyAction::CycleLayout, Arg::None), 155 + vec![MODKEY],
156 + keysyms::XK_Q,
157 + KeyAction::KillClient,
158 + Arg::None,
159 + ),
160 + KeyBinding::single_key(
161 + vec![MODKEY],
162 + keysyms::XK_N,
163 + KeyAction::CycleLayout,
164 + Arg::None,
165 + ),
147 KeyBinding::single_key( 166 KeyBinding::single_key(
148 vec![MODKEY, SHIFT], 167 vec![MODKEY, SHIFT],
149 keysyms::XK_F, 168 keysyms::XK_F,
150 KeyAction::ToggleFullScreen, 169 KeyAction::ToggleFullScreen,
151 Arg::None, 170 Arg::None,
152 ), 171 ),
153 - KeyBinding::single_key(vec![MODKEY], keysyms::XK_A, KeyAction::ToggleGaps, Arg::None), 172 + KeyBinding::single_key(
154 - KeyBinding::single_key(vec![MODKEY, SHIFT], keysyms::XK_Q, KeyAction::Quit, Arg::None), 173 + vec![MODKEY],
174 + keysyms::XK_A,
175 + KeyAction::ToggleGaps,
176 + Arg::None,
177 + ),
178 + KeyBinding::single_key(
179 + vec![MODKEY, SHIFT],
180 + keysyms::XK_Q,
181 + KeyAction::Quit,
182 + Arg::None,
183 + ),
155 KeyBinding::single_key( 184 KeyBinding::single_key(
156 vec![MODKEY, SHIFT], 185 vec![MODKEY, SHIFT],
157 keysyms::XK_R, 186 keysyms::XK_R,
+9 −1 src/overlay/keybind.rs
@@ -123,7 +123,15 @@ impl KeybindOverlay {
123 if self.base.is_visible { 123 if self.base.is_visible {
124 self.hide(connection)?; 124 self.hide(connection)?;
125 } else { 125 } else {
126 - self.show(connection, font, keybindings, monitor_x, monitor_y, screen_width, screen_height)?; 126 + self.show(
127 + connection,
128 + font,
129 + keybindings,
130 + monitor_x,
131 + monitor_y,
132 + screen_width,
133 + screen_height,
134 + )?;
127 } 135 }
128 Ok(()) 136 Ok(())
129 } 137 }
+6 −13 src/tab_bar.rs
@@ -1,11 +1,11 @@
1 +use crate::ColorScheme;
1 use crate::bar::font::{Font, FontDraw}; 2 use crate::bar::font::{Font, FontDraw};
2 use crate::errors::X11Error; 3 use crate::errors::X11Error;
3 use crate::layout::tabbed::TAB_BAR_HEIGHT; 4 use crate::layout::tabbed::TAB_BAR_HEIGHT;
4 -use crate::ColorScheme; 5 +use x11rb::COPY_DEPTH_FROM_PARENT;
5 use x11rb::connection::Connection; 6 use x11rb::connection::Connection;
6 use x11rb::protocol::xproto::*; 7 use x11rb::protocol::xproto::*;
7 use x11rb::rust_connection::RustConnection; 8 use x11rb::rust_connection::RustConnection;
8 -use x11rb::COPY_DEPTH_FROM_PARENT;
9 9
10 pub struct TabBar { 10 pub struct TabBar {
11 window: Window, 11 window: Window,
@@ -117,11 +117,7 @@ impl TabBar {
117 117
118 unsafe { 118 unsafe {
119 let gc = x11::xlib::XCreateGC(self.display, self.pixmap, 0, std::ptr::null_mut()); 119 let gc = x11::xlib::XCreateGC(self.display, self.pixmap, 0, std::ptr::null_mut());
120 - x11::xlib::XSetForeground( 120 + x11::xlib::XSetForeground(self.display, gc, self.scheme_normal.background as u64);
121 - self.display,
122 - gc,
123 - self.scheme_normal.background as u64,
124 - );
125 x11::xlib::XFillRectangle( 121 x11::xlib::XFillRectangle(
126 self.display, 122 self.display,
127 self.pixmap, 123 self.pixmap,
@@ -195,7 +191,8 @@ impl TabBar {
195 191
196 fn copy_pixmap_to_window(&self) { 192 fn copy_pixmap_to_window(&self) {
197 unsafe { 193 unsafe {
198 - let gc = x11::xlib::XCreateGC(self.display, self.window as u64, 0, std::ptr::null_mut()); 194 + let gc =
195 + x11::xlib::XCreateGC(self.display, self.window as u64, 0, std::ptr::null_mut());
199 x11::xlib::XCopyArea( 196 x11::xlib::XCopyArea(
200 self.display, 197 self.display,
201 self.pixmap, 198 self.pixmap,
@@ -212,11 +209,7 @@ impl TabBar {
212 } 209 }
213 } 210 }
214 211
215 - pub fn get_clicked_window( 212 + pub fn get_clicked_window(&self, windows: &[(Window, String)], click_x: i16) -> Option<Window> {
216 - &self,
217 - windows: &[(Window, String)],
218 - click_x: i16,
219 - ) -> Option<Window> {
220 if windows.is_empty() { 213 if windows.is_empty() {
221 return None; 214 return None;
222 } 215 }
+541 −307 src/window_manager.rs Large diff collapsed, click to expand
@@ -16,7 +16,6 @@ use x11rb::protocol::Event;
16 use x11rb::protocol::xproto::*; 16 use x11rb::protocol::xproto::*;
17 use x11rb::rust_connection::RustConnection; 17 use x11rb::rust_connection::RustConnection;
18 18
19 -
20 pub fn tag_mask(tag: usize) -> TagMask { 19 pub fn tag_mask(tag: usize) -> TagMask {
21 1 << tag 20 1 << tag
22 } 21 }
@@ -82,9 +81,15 @@ impl AtomCache {
82 .atom; 81 .atom;
83 82
84 let wm_name = AtomEnum::WM_NAME.into(); 83 let wm_name = AtomEnum::WM_NAME.into();
85 - let net_wm_name = connection.intern_atom(false, b"_NET_WM_NAME")?.reply()?.atom; 84 + let net_wm_name = connection
85 + .intern_atom(false, b"_NET_WM_NAME")?
86 + .reply()?
87 + .atom;
86 let utf8_string = connection.intern_atom(false, b"UTF8_STRING")?.reply()?.atom; 88 let utf8_string = connection.intern_atom(false, b"UTF8_STRING")?.reply()?.atom;
87 - let net_active_window = connection.intern_atom(false, b"_NET_ACTIVE_WINDOW")?.reply()?.atom; 89 + let net_active_window = connection
90 + .intern_atom(false, b"_NET_ACTIVE_WINDOW")?
91 + .reply()?
92 + .atom;
88 93
89 Ok(Self { 94 Ok(Self {
90 net_current_desktop, 95 net_current_desktop,
@@ -238,7 +243,9 @@ impl WindowManager {
238 &font, 243 &font,
239 (monitor.screen_x + config.gap_outer_horizontal as i32) as i16, 244 (monitor.screen_x + config.gap_outer_horizontal as i32) as i16,
240 (monitor.screen_y as f32 + bar_height + config.gap_outer_vertical as f32) as i16, 245 (monitor.screen_y as f32 + bar_height + config.gap_outer_vertical as f32) as i16,
241 - monitor.screen_width.saturating_sub(2 * config.gap_outer_horizontal as i32) as u16, 246 + monitor
247 + .screen_width
248 + .saturating_sub(2 * config.gap_outer_horizontal as i32) as u16,
242 config.scheme_occupied, 249 config.scheme_occupied,
243 config.scheme_selected, 250 config.scheme_selected,
244 )?; 251 )?;
@@ -542,7 +549,13 @@ impl WindowManager {
542 } 549 }
543 550
544 let (is_fixed, x, y, w, h) = if let Some(client) = self.clients.get(&focused) { 551 let (is_fixed, x, y, w, h) = if let Some(client) = self.clients.get(&focused) {
545 - (client.is_fixed, client.x_position as i32, client.y_position as i32, client.width as u32, client.height as u32) 552 + (
553 + client.is_fixed,
554 + client.x_position as i32,
555 + client.y_position as i32,
556 + client.width as u32,
557 + client.height as u32,
558 + )
546 } else { 559 } else {
547 return Ok(()); 560 return Ok(());
548 }; 561 };
@@ -593,7 +606,6 @@ impl WindowManager {
593 Ok(()) 606 Ok(())
594 } 607 }
595 608
596 -
597 fn get_layout_symbol(&self) -> String { 609 fn get_layout_symbol(&self) -> String {
598 let layout_name = self.layout.name(); 610 let layout_name = self.layout.name();
599 self.config 611 self.config
@@ -647,7 +659,6 @@ impl WindowManager {
647 } 659 }
648 } 660 }
649 661
650 -
651 fn update_bar(&mut self) -> WmResult<()> { 662 fn update_bar(&mut self) -> WmResult<()> {
652 let layout_symbol = self.get_layout_symbol(); 663 let layout_symbol = self.get_layout_symbol();
653 let keychord_indicator = self.get_keychord_indicator(); 664 let keychord_indicator = self.get_keychord_indicator();
@@ -844,11 +855,12 @@ impl WindowManager {
844 Ok(()) 855 Ok(())
845 } 856 }
846 857
847 -
848 fn is_window_visible(&self, window: Window) -> bool { 858 fn is_window_visible(&self, window: Window) -> bool {
849 if let Some(client) = self.clients.get(&window) { 859 if let Some(client) = self.clients.get(&window) {
850 let monitor = self.monitors.get(client.monitor_index); 860 let monitor = self.monitors.get(client.monitor_index);
851 - let selected_tags = monitor.map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0); 861 + let selected_tags = monitor
862 + .map(|m| m.tagset[m.selected_tags_index])
863 + .unwrap_or(0);
852 (client.tags & selected_tags) != 0 864 (client.tags & selected_tags) != 0
853 } else { 865 } else {
854 false 866 false
@@ -904,8 +916,14 @@ impl WindowManager {
904 let mut max_area = 0; 916 let mut max_area = 0;
905 917
906 for (idx, monitor) in self.monitors.iter().enumerate() { 918 for (idx, monitor) in self.monitors.iter().enumerate() {
907 - let intersect_width = 0.max((x + w).min(monitor.window_area_x + monitor.window_area_width) - x.max(monitor.window_area_x)); 919 + let intersect_width = 0.max(
908 - let intersect_height = 0.max((y + h).min(monitor.window_area_y + monitor.window_area_height) - y.max(monitor.window_area_y)); 920 + (x + w).min(monitor.window_area_x + monitor.window_area_width)
921 + - x.max(monitor.window_area_x),
922 + );
923 + let intersect_height = 0.max(
924 + (y + h).min(monitor.window_area_y + monitor.window_area_height)
925 + - y.max(monitor.window_area_y),
926 + );
909 let area = intersect_width * intersect_height; 927 let area = intersect_width * intersect_height;
910 928
911 if area > max_area { 929 if area > max_area {
@@ -917,10 +935,12 @@ impl WindowManager {
917 best_monitor 935 best_monitor
918 } 936 }
919 937
920 - fn move_window_to_monitor(&mut self, window: Window, target_monitor_index: usize) -> WmResult<()> { 938 + fn move_window_to_monitor(
921 - let current_monitor_index = self.clients 939 + &mut self,
922 - .get(&window) 940 + window: Window,
923 - .map(|c| c.monitor_index); 941 + target_monitor_index: usize,
942 + ) -> WmResult<()> {
943 + let current_monitor_index = self.clients.get(&window).map(|c| c.monitor_index);
924 944
925 if let Some(current_idx) = current_monitor_index { 945 if let Some(current_idx) = current_monitor_index {
926 if current_idx == target_monitor_index { 946 if current_idx == target_monitor_index {
@@ -1078,7 +1098,7 @@ impl WindowManager {
1078 1098
1079 self.save_selected_tags()?; 1099 self.save_selected_tags()?;
1080 self.focus(None)?; 1100 self.focus(None)?;
1081 - self.apply_layout()?; 1101 + self.apply_layout()?;
1082 self.update_bar()?; 1102 self.update_bar()?;
1083 1103
1084 Ok(()) 1104 Ok(())
@@ -1262,7 +1282,10 @@ impl WindowManager {
1262 if self.send_event(window, self.atoms.wm_delete_window)? { 1282 if self.send_event(window, self.atoms.wm_delete_window)? {
1263 self.connection.flush()?; 1283 self.connection.flush()?;
1264 } else { 1284 } else {
1265 - eprintln!("Window {} doesn't support WM_DELETE_WINDOW, killing forcefully", window); 1285 + eprintln!(
1286 + "Window {} doesn't support WM_DELETE_WINDOW, killing forcefully",
1287 + window
1288 + );
1266 self.connection.kill_client(window)?; 1289 self.connection.kill_client(window)?;
1267 self.connection.flush()?; 1290 self.connection.flush()?;
1268 } 1291 }
@@ -1270,14 +1293,17 @@ impl WindowManager {
1270 } 1293 }
1271 1294
1272 fn send_event(&self, window: Window, protocol: Atom) -> WmResult<bool> { 1295 fn send_event(&self, window: Window, protocol: Atom) -> WmResult<bool> {
1273 - let protocols_reply = self.connection.get_property( 1296 + let protocols_reply = self
1274 - false, 1297 + .connection
1275 - window, 1298 + .get_property(
1276 - self.atoms.wm_protocols, 1299 + false,
1277 - AtomEnum::ATOM, 1300 + window,
1278 - 0, 1301 + self.atoms.wm_protocols,
1279 - 100, 1302 + AtomEnum::ATOM,
1280 - )?.reply(); 1303 + 0,
1304 + 100,
1305 + )?
1306 + .reply();
1281 1307
1282 let protocols_reply = match protocols_reply { 1308 let protocols_reply = match protocols_reply {
1283 Ok(reply) => reply, 1309 Ok(reply) => reply,
@@ -1300,15 +1326,17 @@ impl WindowManager {
1300 sequence: 0, 1326 sequence: 0,
1301 window, 1327 window,
1302 type_: self.atoms.wm_protocols, 1328 type_: self.atoms.wm_protocols,
1303 - data: x11rb::protocol::xproto::ClientMessageData::from([protocol, x11rb::CURRENT_TIME, 0, 0, 0]), 1329 + data: x11rb::protocol::xproto::ClientMessageData::from([
1330 + protocol,
1331 + x11rb::CURRENT_TIME,
1332 + 0,
1333 + 0,
1334 + 0,
1335 + ]),
1304 }; 1336 };
1305 1337
1306 - self.connection.send_event( 1338 + self.connection
1307 - false, 1339 + .send_event(false, window, EventMask::NO_EVENT, event)?;
1308 - window,
1309 - EventMask::NO_EVENT,
1310 - event,
1311 - )?;
1312 self.connection.flush()?; 1340 self.connection.flush()?;
1313 Ok(true) 1341 Ok(true)
1314 } 1342 }
@@ -1318,14 +1346,10 @@ impl WindowManager {
1318 client.is_urgent = urgent; 1346 client.is_urgent = urgent;
1319 } 1347 }
1320 1348
1321 - let hints_reply = self.connection.get_property( 1349 + let hints_reply = self
1322 - false, 1350 + .connection
1323 - window, 1351 + .get_property(false, window, AtomEnum::WM_HINTS, AtomEnum::WM_HINTS, 0, 9)?
1324 - AtomEnum::WM_HINTS, 1352 + .reply();
1325 - AtomEnum::WM_HINTS,
1326 - 0,
1327 - 9,
1328 - )?.reply();
1329 1353
1330 if let Ok(hints) = hints_reply { 1354 if let Ok(hints) = hints_reply {
1331 if hints.value.len() >= 4 { 1355 if hints.value.len() >= 4 {
@@ -1361,14 +1385,10 @@ impl WindowManager {
1361 } 1385 }
1362 1386
1363 fn get_window_atom_property(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> { 1387 fn get_window_atom_property(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> {
1364 - let reply = self.connection.get_property( 1388 + let reply = self
1365 - false, 1389 + .connection
1366 - window, 1390 + .get_property(false, window, property, AtomEnum::ATOM, 0, 1)?
1367 - property, 1391 + .reply();
1368 - AtomEnum::ATOM,
1369 - 0,
1370 - 1,
1371 - )?.reply();
1372 1392
1373 match reply { 1393 match reply {
1374 Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => { 1394 Ok(prop) if !prop.value.is_empty() && prop.value.len() >= 4 => {
@@ -1386,18 +1406,26 @@ impl WindowManager {
1386 1406
1387 fn fullscreen(&mut self) -> WmResult<()> { 1407 fn fullscreen(&mut self) -> WmResult<()> {
1388 if self.show_bar { 1408 if self.show_bar {
1389 - let windows: Vec<Window> = self.windows.iter() 1409 + let windows: Vec<Window> = self
1410 + .windows
1411 + .iter()
1390 .filter(|&&w| self.is_window_visible(w)) 1412 .filter(|&&w| self.is_window_visible(w))
1391 .copied() 1413 .copied()
1392 .collect(); 1414 .collect();
1393 1415
1394 for window in &windows { 1416 for window in &windows {
1395 if let Ok(geom) = self.connection.get_geometry(*window)?.reply() { 1417 if let Ok(geom) = self.connection.get_geometry(*window)?.reply() {
1396 - self.floating_geometry_before_fullscreen.insert( 1418 + self.floating_geometry_before_fullscreen.insert(
1397 - *window, 1419 + *window,
1398 - (geom.x, geom.y, geom.width, geom.height, geom.border_width as u16), 1420 + (
1399 - ); 1421 + geom.x,
1400 - } 1422 + geom.y,
1423 + geom.width,
1424 + geom.height,
1425 + geom.border_width as u16,
1426 + ),
1427 + );
1428 + }
1401 } 1429 }
1402 1430
1403 self.last_layout = Some(self.layout.name()); 1431 self.last_layout = Some(self.layout.name());
@@ -1408,13 +1436,16 @@ impl WindowManager {
1408 self.apply_layout()?; 1436 self.apply_layout()?;
1409 1437
1410 let border_width = self.config.border_width; 1438 let border_width = self.config.border_width;
1411 - let floating_windows: Vec<Window> = windows.iter() 1439 + let floating_windows: Vec<Window> = windows
1440 + .iter()
1412 .filter(|&&w| self.floating_windows.contains(&w)) 1441 .filter(|&&w| self.floating_windows.contains(&w))
1413 .copied() 1442 .copied()
1414 .collect(); 1443 .collect();
1415 1444
1416 for window in floating_windows { 1445 for window in floating_windows {
1417 - let monitor_idx = self.clients.get(&window) 1446 + let monitor_idx = self
1447 + .clients
1448 + .get(&window)
1418 .map(|c| c.monitor_index) 1449 .map(|c| c.monitor_index)
1419 .unwrap_or(self.selected_monitor); 1450 .unwrap_or(self.selected_monitor);
1420 let monitor = &self.monitors[monitor_idx]; 1451 let monitor = &self.monitors[monitor_idx];
@@ -1430,8 +1461,14 @@ impl WindowManager {
1430 1461
1431 let window_x = monitor.screen_x + outer_gap_h as i32; 1462 let window_x = monitor.screen_x + outer_gap_h as i32;
1432 let window_y = monitor.screen_y + outer_gap_v as i32; 1463 let window_y = monitor.screen_y + outer_gap_v as i32;
1433 - let window_width = monitor.screen_width.saturating_sub(2 * outer_gap_h as i32).saturating_sub(2 * border_width as i32); 1464 + let window_width = monitor
1434 - let window_height = monitor.screen_height.saturating_sub(2 * outer_gap_v as i32).saturating_sub(2 * border_width as i32); 1465 + .screen_width
1466 + .saturating_sub(2 * outer_gap_h as i32)
1467 + .saturating_sub(2 * border_width as i32);
1468 + let window_height = monitor
1469 + .screen_height
1470 + .saturating_sub(2 * outer_gap_v as i32)
1471 + .saturating_sub(2 * border_width as i32);
1435 1472
1436 self.connection.configure_window( 1473 self.connection.configure_window(
1437 window, 1474 window,
@@ -1450,13 +1487,16 @@ impl WindowManager {
1450 } 1487 }
1451 } 1488 }
1452 1489
1453 - let windows_to_restore: Vec<Window> = self.floating_geometry_before_fullscreen 1490 + let windows_to_restore: Vec<Window> = self
1491 + .floating_geometry_before_fullscreen
1454 .keys() 1492 .keys()
1455 .copied() 1493 .copied()
1456 .collect(); 1494 .collect();
1457 1495
1458 for window in windows_to_restore { 1496 for window in windows_to_restore {
1459 - if let Some(&(x, y, width, height, border_width)) = self.floating_geometry_before_fullscreen.get(&window) { 1497 + if let Some(&(x, y, width, height, border_width)) =
1498 + self.floating_geometry_before_fullscreen.get(&window)
1499 + {
1460 self.connection.configure_window( 1500 self.connection.configure_window(
1461 window, 1501 window,
1462 &ConfigureWindowAux::new() 1502 &ConfigureWindowAux::new()
@@ -1499,7 +1539,9 @@ impl WindowManager {
1499 } 1539 }
1500 1540
1501 fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> { 1541 fn set_window_fullscreen(&mut self, window: Window, fullscreen: bool) -> WmResult<()> {
1502 - let monitor_idx = self.clients.get(&window) 1542 + let monitor_idx = self
1543 + .clients
1544 + .get(&window)
1503 .map(|c| c.monitor_index) 1545 .map(|c| c.monitor_index)
1504 .unwrap_or(self.selected_monitor); 1546 .unwrap_or(self.selected_monitor);
1505 let monitor = &self.monitors[monitor_idx]; 1547 let monitor = &self.monitors[monitor_idx];
@@ -1622,7 +1664,8 @@ impl WindowManager {
1622 } 1664 }
1623 1665
1624 fn get_window_class_instance(&self, window: Window) -> (String, String) { 1666 fn get_window_class_instance(&self, window: Window) -> (String, String) {
1625 - let reply = self.connection 1667 + let reply = self
1668 + .connection
1626 .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024) 1669 .get_property(false, window, AtomEnum::WM_CLASS, AtomEnum::STRING, 0, 1024)
1627 .ok() 1670 .ok()
1628 .and_then(|cookie| cookie.reply().ok()); 1671 .and_then(|cookie| cookie.reply().ok());
@@ -1643,7 +1686,11 @@ impl WindowManager {
1643 1686
1644 fn apply_rules(&mut self, window: Window) -> WmResult<()> { 1687 fn apply_rules(&mut self, window: Window) -> WmResult<()> {
1645 let (instance, class) = self.get_window_class_instance(window); 1688 let (instance, class) = self.get_window_class_instance(window);
1646 - let title = self.clients.get(&window).map(|c| c.name.clone()).unwrap_or_default(); 1689 + let title = self
1690 + .clients
1691 + .get(&window)
1692 + .map(|c| c.name.clone())
1693 + .unwrap_or_default();
1647 1694
1648 let mut rule_tags: Option<u32> = None; 1695 let mut rule_tags: Option<u32> = None;
1649 let mut rule_floating: Option<bool> = None; 1696 let mut rule_floating: Option<bool> = None;
@@ -1703,13 +1750,17 @@ impl WindowManager {
1703 if let Some(parent_client) = self.clients.get(&parent) { 1750 if let Some(parent_client) = self.clients.get(&parent) {
1704 (parent_client.monitor_index, parent_client.tags) 1751 (parent_client.monitor_index, parent_client.tags)
1705 } else { 1752 } else {
1706 - let tags = self.monitors.get(self.selected_monitor) 1753 + let tags = self
1754 + .monitors
1755 + .get(self.selected_monitor)
1707 .map(|m| m.tagset[m.selected_tags_index]) 1756 .map(|m| m.tagset[m.selected_tags_index])
1708 .unwrap_or(tag_mask(0)); 1757 .unwrap_or(tag_mask(0));
1709 (self.selected_monitor, tags) 1758 (self.selected_monitor, tags)
1710 } 1759 }
1711 } else { 1760 } else {
1712 - let tags = self.monitors.get(self.selected_monitor) 1761 + let tags = self
1762 + .monitors
1763 + .get(self.selected_monitor)
1713 .map(|m| m.tagset[m.selected_tags_index]) 1764 .map(|m| m.tagset[m.selected_tags_index])
1714 .unwrap_or(tag_mask(0)); 1765 .unwrap_or(tag_mask(0));
1715 (self.selected_monitor, tags) 1766 (self.selected_monitor, tags)
@@ -1734,13 +1785,33 @@ impl WindowManager {
1734 self.apply_rules(window)?; 1785 self.apply_rules(window)?;
1735 } 1786 }
1736 1787
1737 - let client_monitor = self.clients.get(&window).map(|c| c.monitor_index).unwrap_or(monitor_index); 1788 + let client_monitor = self
1789 + .clients
1790 + .get(&window)
1791 + .map(|c| c.monitor_index)
1792 + .unwrap_or(monitor_index);
1738 let monitor = &self.monitors[client_monitor]; 1793 let monitor = &self.monitors[client_monitor];
1739 1794
1740 - let mut x = self.clients.get(&window).map(|c| c.x_position as i32).unwrap_or(0); 1795 + let mut x = self
1741 - let mut y = self.clients.get(&window).map(|c| c.y_position as i32).unwrap_or(0); 1796 + .clients
1742 - let w = self.clients.get(&window).map(|c| c.width as i32).unwrap_or(1); 1797 + .get(&window)
1743 - let h = self.clients.get(&window).map(|c| c.height as i32).unwrap_or(1); 1798 + .map(|c| c.x_position as i32)
1799 + .unwrap_or(0);
1800 + let mut y = self
1801 + .clients
1802 + .get(&window)
1803 + .map(|c| c.y_position as i32)
1804 + .unwrap_or(0);
1805 + let w = self
1806 + .clients
1807 + .get(&window)
1808 + .map(|c| c.width as i32)
1809 + .unwrap_or(1);
1810 + let h = self
1811 + .clients
1812 + .get(&window)
1813 + .map(|c| c.height as i32)
1814 + .unwrap_or(1);
1744 let bw = border_width as i32; 1815 let bw = border_width as i32;
1745 1816
1746 if x + w + 2 * bw > monitor.window_area_x + monitor.window_area_width { 1817 if x + w + 2 * bw > monitor.window_area_x + monitor.window_area_width {
@@ -1773,11 +1844,18 @@ impl WindowManager {
1773 self.connection.change_window_attributes( 1844 self.connection.change_window_attributes(
1774 window, 1845 window,
1775 &ChangeWindowAttributesAux::new().event_mask( 1846 &ChangeWindowAttributesAux::new().event_mask(
1776 - EventMask::ENTER_WINDOW | EventMask::FOCUS_CHANGE | EventMask::PROPERTY_CHANGE | EventMask::STRUCTURE_NOTIFY 1847 + EventMask::ENTER_WINDOW
1848 + | EventMask::FOCUS_CHANGE
1849 + | EventMask::PROPERTY_CHANGE
1850 + | EventMask::STRUCTURE_NOTIFY,
1777 ), 1851 ),
1778 )?; 1852 )?;
1779 1853
1780 - let is_fixed = self.clients.get(&window).map(|c| c.is_fixed).unwrap_or(false); 1854 + let is_fixed = self
1855 + .clients
1856 + .get(&window)
1857 + .map(|c| c.is_fixed)
1858 + .unwrap_or(false);
1781 if let Some(c) = self.clients.get_mut(&window) { 1859 if let Some(c) = self.clients.get_mut(&window) {
1782 if !c.is_floating { 1860 if !c.is_floating {
1783 c.is_floating = is_transient || is_fixed; 1861 c.is_floating = is_transient || is_fixed;
@@ -1785,7 +1863,12 @@ impl WindowManager {
1785 } 1863 }
1786 } 1864 }
1787 1865
1788 - if self.clients.get(&window).map(|c| c.is_floating).unwrap_or(false) { 1866 + if self
1867 + .clients
1868 + .get(&window)
1869 + .map(|c| c.is_floating)
1870 + .unwrap_or(false)
1871 + {
1789 self.floating_windows.insert(window); 1872 self.floating_windows.insert(window);
1790 self.connection.configure_window( 1873 self.connection.configure_window(
1791 window, 1874 window,
@@ -1813,7 +1896,11 @@ impl WindowManager {
1813 let _ = self.save_client_tag(window, final_tags); 1896 let _ = self.save_client_tag(window, final_tags);
1814 1897
1815 if client_monitor == self.selected_monitor { 1898 if client_monitor == self.selected_monitor {
1816 - if let Some(old_sel) = self.monitors.get(self.selected_monitor).and_then(|m| m.selected_client) { 1899 + if let Some(old_sel) = self
1900 + .monitors
1901 + .get(self.selected_monitor)
1902 + .and_then(|m| m.selected_client)
1903 + {
1817 self.unfocus(old_sel)?; 1904 self.unfocus(old_sel)?;
1818 } 1905 }
1819 } 1906 }
@@ -1892,7 +1979,9 @@ impl WindowManager {
1892 1979
1893 let mut win = window; 1980 let mut win = window;
1894 if win.is_none() || !self.is_visible(win.unwrap()) { 1981 if win.is_none() || !self.is_visible(win.unwrap()) {
1895 - let mut current = self.monitors.get(self.selected_monitor) 1982 + let mut current = self
1983 + .monitors
1984 + .get(self.selected_monitor)
1896 .and_then(|m| m.stack_head); 1985 .and_then(|m| m.stack_head);
1897 1986
1898 while let Some(w) = current { 1987 while let Some(w) = current {
@@ -1909,7 +1998,9 @@ impl WindowManager {
1909 return Ok(()); 1998 return Ok(());
1910 } 1999 }
1911 2000
1912 - let monitor_idx = self.clients.get(&win) 2001 + let monitor_idx = self
2002 + .clients
2003 + .get(&win)
1913 .map(|c| c.monitor_index) 2004 .map(|c| c.monitor_index)
1914 .unwrap_or(self.selected_monitor); 2005 .unwrap_or(self.selected_monitor);
1915 if monitor_idx != self.selected_monitor { 2006 if monitor_idx != self.selected_monitor {
@@ -1924,13 +2015,11 @@ impl WindowManager {
1924 &ChangeWindowAttributesAux::new().border_pixel(self.config.border_focused), 2015 &ChangeWindowAttributesAux::new().border_pixel(self.config.border_focused),
1925 )?; 2016 )?;
1926 2017
1927 - self.connection.ungrab_button(ButtonIndex::ANY, win, ModMask::ANY)?; 2018 + self.connection
2019 + .ungrab_button(ButtonIndex::ANY, win, ModMask::ANY)?;
1928 2020
1929 - self.connection.set_input_focus( 2021 + self.connection
1930 - InputFocus::POINTER_ROOT, 2022 + .set_input_focus(InputFocus::POINTER_ROOT, win, x11rb::CURRENT_TIME)?;
1931 - win,
1932 - x11rb::CURRENT_TIME,
1933 - )?;
1934 2023
1935 if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { 2024 if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
1936 monitor.selected_client = Some(win); 2025 monitor.selected_client = Some(win);
@@ -2108,7 +2197,8 @@ impl WindowManager {
2108 let mut current = monitor.clients_head; 2197 let mut current = monitor.clients_head;
2109 while let Some(window) = current { 2198 while let Some(window) = current {
2110 if let Some(client) = self.clients.get(&window) { 2199 if let Some(client) = self.clients.get(&window) {
2111 - let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; 2200 + let visible_tags =
2201 + client.tags & monitor.tagset[monitor.selected_tags_index];
2112 if visible_tags != 0 && !client.is_floating { 2202 if visible_tags != 0 && !client.is_floating {
2113 last = Some(window); 2203 last = Some(window);
2114 } 2204 }
@@ -2205,7 +2295,8 @@ impl WindowManager {
2205 _ => return Ok(()), 2295 _ => return Ok(()),
2206 }; 2296 };
2207 2297
2208 - let old_selected = self.monitors 2298 + let old_selected = self
2299 + .monitors
2209 .get(self.selected_monitor) 2300 .get(self.selected_monitor)
2210 .and_then(|m| m.selected_client); 2301 .and_then(|m| m.selected_client);
2211 2302
@@ -2224,7 +2315,8 @@ impl WindowManager {
2224 return Ok(()); 2315 return Ok(());
2225 } 2316 }
2226 2317
2227 - let selected_window = self.monitors 2318 + let selected_window = self
2319 + .monitors
2228 .get(self.selected_monitor) 2320 .get(self.selected_monitor)
2229 .and_then(|m| m.selected_client); 2321 .and_then(|m| m.selected_client);
2230 2322
@@ -2277,7 +2369,8 @@ impl WindowManager {
2277 } 2369 }
2278 2370
2279 fn drag_window(&mut self, window: Window) -> WmResult<()> { 2371 fn drag_window(&mut self, window: Window) -> WmResult<()> {
2280 - let is_fullscreen = self.clients 2372 + let is_fullscreen = self
2373 + .clients
2281 .get(&window) 2374 .get(&window)
2282 .map(|c| c.is_fullscreen) 2375 .map(|c| c.is_fullscreen)
2283 .unwrap_or(false); 2376 .unwrap_or(false);
@@ -2287,7 +2380,14 @@ impl WindowManager {
2287 } 2380 }
2288 2381
2289 let client_info = self.clients.get(&window).map(|c| { 2382 let client_info = self.clients.get(&window).map(|c| {
2290 - (c.x_position, c.y_position, c.width, c.height, c.is_floating, c.monitor_index) 2383 + (
2384 + c.x_position,
2385 + c.y_position,
2386 + c.width,
2387 + c.height,
2388 + c.is_floating,
2389 + c.monitor_index,
2390 + )
2291 }); 2391 });
2292 2392
2293 let Some((orig_x, orig_y, width, height, was_floating, monitor_idx)) = client_info else { 2393 let Some((orig_x, orig_y, width, height, was_floating, monitor_idx)) = client_info else {
@@ -2306,17 +2406,19 @@ impl WindowManager {
2306 self.toggle_floating()?; 2406 self.toggle_floating()?;
2307 } 2407 }
2308 2408
2309 - self.connection.grab_pointer( 2409 + self.connection
2310 - false, 2410 + .grab_pointer(
2311 - self.root, 2411 + false,
2312 - (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | 2412 + self.root,
2313 - EventMask::BUTTON_PRESS).into(), 2413 + (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS)
2314 - GrabMode::ASYNC, 2414 + .into(),
2315 - GrabMode::ASYNC, 2415 + GrabMode::ASYNC,
2316 - x11rb::NONE, 2416 + GrabMode::ASYNC,
2317 - x11rb::NONE, 2417 + x11rb::NONE,
2318 - x11rb::CURRENT_TIME, 2418 + x11rb::NONE,
2319 - )?.reply()?; 2419 + x11rb::CURRENT_TIME,
2420 + )?
2421 + .reply()?;
2320 2422
2321 let pointer = self.connection.query_pointer(self.root)?.reply()?; 2423 let pointer = self.connection.query_pointer(self.root)?.reply()?;
2322 let (start_x, start_y) = (pointer.root_x as i32, pointer.root_y as i32); 2424 let (start_x, start_y) = (pointer.root_x as i32, pointer.root_y as i32);
@@ -2338,20 +2440,30 @@ impl WindowManager {
2338 2440
2339 if (monitor.window_area_x - new_x).abs() < snap { 2441 if (monitor.window_area_x - new_x).abs() < snap {
2340 new_x = monitor.window_area_x; 2442 new_x = monitor.window_area_x;
2341 - } else if ((monitor.window_area_x + monitor.window_area_width) - (new_x + width as i32)).abs() < snap { 2443 + } else if ((monitor.window_area_x + monitor.window_area_width)
2444 + - (new_x + width as i32))
2445 + .abs()
2446 + < snap
2447 + {
2342 new_x = monitor.window_area_x + monitor.window_area_width - width as i32; 2448 new_x = monitor.window_area_x + monitor.window_area_width - width as i32;
2343 } 2449 }
2344 2450
2345 if (monitor.window_area_y - new_y).abs() < snap { 2451 if (monitor.window_area_y - new_y).abs() < snap {
2346 new_y = monitor.window_area_y; 2452 new_y = monitor.window_area_y;
2347 - } else if ((monitor.window_area_y + monitor.window_area_height) - (new_y + height as i32)).abs() < snap { 2453 + } else if ((monitor.window_area_y + monitor.window_area_height)
2454 + - (new_y + height as i32))
2455 + .abs()
2456 + < snap
2457 + {
2348 new_y = monitor.window_area_y + monitor.window_area_height - height as i32; 2458 new_y = monitor.window_area_y + monitor.window_area_height - height as i32;
2349 } 2459 }
2350 2460
2351 - let should_resize = is_normie || self.clients 2461 + let should_resize = is_normie
2352 - .get(&window) 2462 + || self
2353 - .map(|c| c.is_floating) 2463 + .clients
2354 - .unwrap_or(false); 2464 + .get(&window)
2465 + .map(|c| c.is_floating)
2466 + .unwrap_or(false);
2355 2467
2356 if should_resize { 2468 if should_resize {
2357 if let Some(client) = self.clients.get_mut(&window) { 2469 if let Some(client) = self.clients.get_mut(&window) {
@@ -2361,9 +2473,7 @@ impl WindowManager {
2361 2473
2362 self.connection.configure_window( 2474 self.connection.configure_window(
2363 window, 2475 window,
2364 - &ConfigureWindowAux::new() 2476 + &ConfigureWindowAux::new().x(new_x).y(new_y),
2365 - .x(new_x)
2366 - .y(new_y),
2367 )?; 2477 )?;
2368 self.connection.flush()?; 2478 self.connection.flush()?;
2369 } 2479 }
@@ -2373,11 +2483,14 @@ impl WindowManager {
2373 } 2483 }
2374 } 2484 }
2375 2485
2376 - self.connection.ungrab_pointer(x11rb::CURRENT_TIME)?.check()?; 2486 + self.connection
2487 + .ungrab_pointer(x11rb::CURRENT_TIME)?
2488 + .check()?;
2377 2489
2378 - let final_client = self.clients.get(&window).map(|c| { 2490 + let final_client = self
2379 - (c.x_position, c.y_position, c.width, c.height) 2491 + .clients
2380 - }); 2492 + .get(&window)
2493 + .map(|c| (c.x_position, c.y_position, c.width, c.height));
2381 2494
2382 if let Some((x, y, w, h)) = final_client { 2495 if let Some((x, y, w, h)) = final_client {
2383 let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32); 2496 let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32);
@@ -2392,7 +2505,8 @@ impl WindowManager {
2392 } 2505 }
2393 2506
2394 fn resize_window_with_mouse(&mut self, window: Window) -> WmResult<()> { 2507 fn resize_window_with_mouse(&mut self, window: Window) -> WmResult<()> {
2395 - let is_fullscreen = self.clients 2508 + let is_fullscreen = self
2509 + .clients
2396 .get(&window) 2510 .get(&window)
2397 .map(|c| c.is_fullscreen) 2511 .map(|c| c.is_fullscreen)
2398 .unwrap_or(false); 2512 .unwrap_or(false);
@@ -2402,10 +2516,27 @@ impl WindowManager {
2402 } 2516 }
2403 2517
2404 let client_info = self.clients.get(&window).map(|c| { 2518 let client_info = self.clients.get(&window).map(|c| {
2405 - (c.x_position, c.y_position, c.width, c.height, c.border_width, c.is_floating, c.monitor_index) 2519 + (
2520 + c.x_position,
2521 + c.y_position,
2522 + c.width,
2523 + c.height,
2524 + c.border_width,
2525 + c.is_floating,
2526 + c.monitor_index,
2527 + )
2406 }); 2528 });
2407 2529
2408 - let Some((orig_x, orig_y, orig_width, orig_height, border_width, was_floating, monitor_idx)) = client_info else { 2530 + let Some((
2531 + orig_x,
2532 + orig_y,
2533 + orig_width,
2534 + orig_height,
2535 + border_width,
2536 + was_floating,
2537 + monitor_idx,
2538 + )) = client_info
2539 + else {
2409 return Ok(()); 2540 return Ok(());
2410 }; 2541 };
2411 2542
@@ -2430,17 +2561,19 @@ impl WindowManager {
2430 (orig_height + border_width - 1) as i16, 2561 (orig_height + border_width - 1) as i16,
2431 )?; 2562 )?;
2432 2563
2433 - self.connection.grab_pointer( 2564 + self.connection
2434 - false, 2565 + .grab_pointer(
2435 - self.root, 2566 + false,
2436 - (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | 2567 + self.root,
2437 - EventMask::BUTTON_PRESS).into(), 2568 + (EventMask::POINTER_MOTION | EventMask::BUTTON_RELEASE | EventMask::BUTTON_PRESS)
2438 - GrabMode::ASYNC, 2569 + .into(),
2439 - GrabMode::ASYNC, 2570 + GrabMode::ASYNC,
2440 - x11rb::NONE, 2571 + GrabMode::ASYNC,
2441 - x11rb::NONE, 2572 + x11rb::NONE,
2442 - x11rb::CURRENT_TIME, 2573 + x11rb::NONE,
2443 - )?.reply()?; 2574 + x11rb::CURRENT_TIME,
2575 + )?
2576 + .reply()?;
2444 2577
2445 let mut last_time = 0u32; 2578 let mut last_time = 0u32;
2446 2579
@@ -2454,13 +2587,19 @@ impl WindowManager {
2454 } 2587 }
2455 last_time = e.time; 2588 last_time = e.time;
2456 2589
2457 - let new_width = ((e.root_x as i32 - orig_x as i32 - 2 * border_width as i32 + 1).max(1)) as u32; 2590 + let new_width = ((e.root_x as i32 - orig_x as i32 - 2 * border_width as i32
2458 - let new_height = ((e.root_y as i32 - orig_y as i32 - 2 * border_width as i32 + 1).max(1)) as u32; 2591 + + 1)
2592 + .max(1)) as u32;
2593 + let new_height = ((e.root_y as i32 - orig_y as i32 - 2 * border_width as i32
2594 + + 1)
2595 + .max(1)) as u32;
2459 2596
2460 - let should_resize = is_normie || self.clients 2597 + let should_resize = is_normie
2461 - .get(&window) 2598 + || self
2462 - .map(|c| c.is_floating) 2599 + .clients
2463 - .unwrap_or(false); 2600 + .get(&window)
2601 + .map(|c| c.is_floating)
2602 + .unwrap_or(false);
2464 2603
2465 if should_resize { 2604 if should_resize {
2466 if let Some(client) = self.clients.get(&window).cloned() { 2605 if let Some(client) = self.clients.get(&window).cloned() {
@@ -2492,9 +2631,7 @@ impl WindowManager {
2492 } 2631 }
2493 } 2632 }
2494 2633
2495 - let final_client = self.clients.get(&window).map(|c| { 2634 + let final_client = self.clients.get(&window).map(|c| (c.width, c.border_width));
2496 - (c.width, c.border_width)
2497 - });
2498 2635
2499 if let Some((w, bw)) = final_client { 2636 if let Some((w, bw)) = final_client {
2500 self.connection.warp_pointer( 2637 self.connection.warp_pointer(
@@ -2509,11 +2646,14 @@ impl WindowManager {
2509 )?; 2646 )?;
2510 } 2647 }
2511 2648
2512 - self.connection.ungrab_pointer(x11rb::CURRENT_TIME)?.check()?; 2649 + self.connection
2650 + .ungrab_pointer(x11rb::CURRENT_TIME)?
2651 + .check()?;
2513 2652
2514 - let final_client_pos = self.clients.get(&window).map(|c| { 2653 + let final_client_pos = self
2515 - (c.x_position, c.y_position, c.width, c.height) 2654 + .clients
2516 - }); 2655 + .get(&window)
2656 + .map(|c| (c.x_position, c.y_position, c.width, c.height));
2517 2657
2518 if let Some((x, y, w, h)) = final_client_pos { 2658 if let Some((x, y, w, h)) = final_client_pos {
2519 let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32); 2659 let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32);
@@ -2572,10 +2712,13 @@ impl WindowManager {
2572 return Ok(None); 2712 return Ok(None);
2573 } 2713 }
2574 Event::ButtonPress(ref e) if e.event == self.keybind_overlay.window() => { 2714 Event::ButtonPress(ref e) if e.event == self.keybind_overlay.window() => {
2575 - self.connection.allow_events(Allow::REPLAY_POINTER, e.time)?; 2715 + self.connection
2716 + .allow_events(Allow::REPLAY_POINTER, e.time)?;
2576 return Ok(None); 2717 return Ok(None);
2577 } 2718 }
2578 - Event::Expose(ref expose_event) if expose_event.window == self.keybind_overlay.window() => { 2719 + Event::Expose(ref expose_event)
2720 + if expose_event.window == self.keybind_overlay.window() =>
2721 + {
2579 if self.keybind_overlay.is_visible() { 2722 if self.keybind_overlay.is_visible() {
2580 if let Err(error) = self.keybind_overlay.draw(&self.connection, &self.font) { 2723 if let Err(error) = self.keybind_overlay.draw(&self.connection, &self.font) {
2581 eprintln!("Failed to draw keybind overlay: {:?}", error); 2724 eprintln!("Failed to draw keybind overlay: {:?}", error);
@@ -2617,7 +2760,11 @@ impl WindowManager {
2617 } 2760 }
2618 2761
2619 if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() { 2762 if event.atom == AtomEnum::WM_TRANSIENT_FOR.into() {
2620 - let is_floating = self.clients.get(&event.window).map(|c| c.is_floating).unwrap_or(false); 2763 + let is_floating = self
2764 + .clients
2765 + .get(&event.window)
2766 + .map(|c| c.is_floating)
2767 + .unwrap_or(false);
2621 if !is_floating { 2768 if !is_floating {
2622 if let Some(parent) = self.get_transient_parent(event.window) { 2769 if let Some(parent) = self.get_transient_parent(event.window) {
2623 if self.clients.contains_key(&parent) { 2770 if self.clients.contains_key(&parent) {
@@ -2710,7 +2857,10 @@ impl WindowManager {
2710 self.gaps_enabled = self.config.gaps_enabled; 2857 self.gaps_enabled = self.config.gaps_enabled;
2711 self.error_message = None; 2858 self.error_message = None;
2712 if let Err(error) = self.overlay.hide(&self.connection) { 2859 if let Err(error) = self.overlay.hide(&self.connection) {
2713 - eprintln!("Failed to hide overlay after config reload: {:?}", error); 2860 + eprintln!(
2861 + "Failed to hide overlay after config reload: {:?}",
2862 + error
2863 + );
2714 } 2864 }
2715 self.apply_layout()?; 2865 self.apply_layout()?;
2716 self.update_bar()?; 2866 self.update_bar()?;
@@ -2759,7 +2909,8 @@ impl WindowManager {
2759 } 2909 }
2760 } 2910 }
2761 Event::ButtonPress(event) => { 2911 Event::ButtonPress(event) => {
2762 - if self.keybind_overlay.is_visible() && event.event != self.keybind_overlay.window() { 2912 + if self.keybind_overlay.is_visible() && event.event != self.keybind_overlay.window()
2913 + {
2763 if let Err(error) = self.keybind_overlay.hide(&self.connection) { 2914 if let Err(error) = self.keybind_overlay.hide(&self.connection) {
2764 eprintln!("Failed to hide keybind overlay: {:?}", error); 2915 eprintln!("Failed to hide keybind overlay: {:?}", error);
2765 } 2916 }
@@ -2801,7 +2952,11 @@ impl WindowManager {
2801 { 2952 {
2802 return None; 2953 return None;
2803 } 2954 }
2804 - let monitor_tags = self.monitors.get(monitor_index).map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0); 2955 + let monitor_tags = self
2956 + .monitors
2957 + .get(monitor_index)
2958 + .map(|m| m.tagset[m.selected_tags_index])
2959 + .unwrap_or(0);
2805 if (client.tags & monitor_tags) != 0 { 2960 if (client.tags & monitor_tags) != 0 {
2806 return Some((window, client.name.clone())); 2961 return Some((window, client.name.clone()));
2807 } 2962 }
@@ -2810,7 +2965,9 @@ impl WindowManager {
2810 }) 2965 })
2811 .collect(); 2966 .collect();
2812 2967
2813 - if let Some(clicked_window) = tab_bar.get_clicked_window(&visible_windows, event.event_x) { 2968 + if let Some(clicked_window) =
2969 + tab_bar.get_clicked_window(&visible_windows, event.event_x)
2970 + {
2814 self.connection.configure_window( 2971 self.connection.configure_window(
2815 clicked_window, 2972 clicked_window,
2816 &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE), 2973 &ConfigureWindowAux::new().stack_mode(StackMode::ABOVE),
@@ -2822,40 +2979,49 @@ impl WindowManager {
2822 self.focus(Some(event.child))?; 2979 self.focus(Some(event.child))?;
2823 self.update_tab_bars()?; 2980 self.update_tab_bars()?;
2824 2981
2825 - let state_clean = u16::from(event.state) & !(u16::from(ModMask::LOCK) | u16::from(ModMask::M2)); 2982 + let state_clean = u16::from(event.state)
2983 + & !(u16::from(ModMask::LOCK) | u16::from(ModMask::M2));
2826 let modkey_held = state_clean & u16::from(self.config.modkey) != 0; 2984 let modkey_held = state_clean & u16::from(self.config.modkey) != 0;
2827 2985
2828 if modkey_held && event.detail == ButtonIndex::M1.into() { 2986 if modkey_held && event.detail == ButtonIndex::M1.into() {
2829 if self.clients.contains_key(&event.child) { 2987 if self.clients.contains_key(&event.child) {
2830 self.drag_window(event.child)?; 2988 self.drag_window(event.child)?;
2831 } 2989 }
2832 - self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; 2990 + self.connection
2991 + .allow_events(Allow::REPLAY_POINTER, event.time)?;
2833 } else if modkey_held && event.detail == ButtonIndex::M3.into() { 2992 } else if modkey_held && event.detail == ButtonIndex::M3.into() {
2834 if self.clients.contains_key(&event.child) { 2993 if self.clients.contains_key(&event.child) {
2835 self.resize_window_with_mouse(event.child)?; 2994 self.resize_window_with_mouse(event.child)?;
2836 } 2995 }
2837 - self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; 2996 + self.connection
2997 + .allow_events(Allow::REPLAY_POINTER, event.time)?;
2838 } else { 2998 } else {
2839 - self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; 2999 + self.connection
3000 + .allow_events(Allow::REPLAY_POINTER, event.time)?;
2840 } 3001 }
2841 } else if self.windows.contains(&event.event) { 3002 } else if self.windows.contains(&event.event) {
2842 self.focus(Some(event.event))?; 3003 self.focus(Some(event.event))?;
2843 self.update_tab_bars()?; 3004 self.update_tab_bars()?;
2844 3005
2845 - let state_clean = u16::from(event.state) & !(u16::from(ModMask::LOCK) | u16::from(ModMask::M2)); 3006 + let state_clean = u16::from(event.state)
3007 + & !(u16::from(ModMask::LOCK) | u16::from(ModMask::M2));
2846 let modkey_held = state_clean & u16::from(self.config.modkey) != 0; 3008 let modkey_held = state_clean & u16::from(self.config.modkey) != 0;
2847 3009
2848 if modkey_held && event.detail == ButtonIndex::M1.into() { 3010 if modkey_held && event.detail == ButtonIndex::M1.into() {
2849 self.drag_window(event.event)?; 3011 self.drag_window(event.event)?;
2850 - self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; 3012 + self.connection
3013 + .allow_events(Allow::REPLAY_POINTER, event.time)?;
2851 } else if modkey_held && event.detail == ButtonIndex::M3.into() { 3014 } else if modkey_held && event.detail == ButtonIndex::M3.into() {
2852 self.resize_window_with_mouse(event.event)?; 3015 self.resize_window_with_mouse(event.event)?;
2853 - self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; 3016 + self.connection
3017 + .allow_events(Allow::REPLAY_POINTER, event.time)?;
2854 } else { 3018 } else {
2855 - self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; 3019 + self.connection
3020 + .allow_events(Allow::REPLAY_POINTER, event.time)?;
2856 } 3021 }
2857 } else { 3022 } else {
2858 - self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; 3023 + self.connection
3024 + .allow_events(Allow::REPLAY_POINTER, event.time)?;
2859 } 3025 }
2860 } 3026 }
2861 } 3027 }
@@ -2920,10 +3086,13 @@ impl WindowManager {
2920 let height_with_border = h + 2 * bw; 3086 let height_with_border = h + 2 * bw;
2921 3087
2922 if (x + w) > monitor.screen_x + monitor.screen_width as i32 && is_floating { 3088 if (x + w) > monitor.screen_x + monitor.screen_width as i32 && is_floating {
2923 - x = monitor.screen_x + (monitor.screen_width as i32 / 2 - width_with_border / 2); 3089 + x = monitor.screen_x
3090 + + (monitor.screen_width as i32 / 2 - width_with_border / 2);
2924 } 3091 }
2925 - if (y + h) > monitor.screen_y + monitor.screen_height as i32 && is_floating { 3092 + if (y + h) > monitor.screen_y + monitor.screen_height as i32 && is_floating
2926 - y = monitor.screen_y + (monitor.screen_height as i32 / 2 - height_with_border / 2); 3093 + {
3094 + y = monitor.screen_y
3095 + + (monitor.screen_height as i32 / 2 - height_with_border / 2);
2927 } 3096 }
2928 3097
2929 if let Some(c) = self.clients.get_mut(&event.window) { 3098 if let Some(c) = self.clients.get_mut(&event.window) {
@@ -2933,8 +3102,10 @@ impl WindowManager {
2933 c.height = h as u16; 3102 c.height = h as u16;
2934 } 3103 }
2935 3104
2936 - let only_position_change = event.value_mask.contains(ConfigWindow::X) || event.value_mask.contains(ConfigWindow::Y); 3105 + let only_position_change = event.value_mask.contains(ConfigWindow::X)
2937 - let no_size_change = !event.value_mask.contains(ConfigWindow::WIDTH) && !event.value_mask.contains(ConfigWindow::HEIGHT); 3106 + || event.value_mask.contains(ConfigWindow::Y);
3107 + let no_size_change = !event.value_mask.contains(ConfigWindow::WIDTH)
3108 + && !event.value_mask.contains(ConfigWindow::HEIGHT);
2938 if only_position_change && no_size_change { 3109 if only_position_change && no_size_change {
2939 self.send_configure_notify(event.window)?; 3110 self.send_configure_notify(event.window)?;
2940 } 3111 }
@@ -2998,11 +3169,13 @@ impl WindowManager {
2998 } 3169 }
2999 } 3170 }
3000 } else if event.type_ == self.atoms.net_active_window { 3171 } else if event.type_ == self.atoms.net_active_window {
3001 - let selected_window = self.monitors 3172 + let selected_window = self
3173 + .monitors
3002 .get(self.selected_monitor) 3174 .get(self.selected_monitor)
3003 .and_then(|m| m.selected_client); 3175 .and_then(|m| m.selected_client);
3004 3176
3005 - let is_urgent = self.clients 3177 + let is_urgent = self
3178 + .clients
3006 .get(&event.window) 3179 .get(&event.window)
3007 .map(|c| c.is_urgent) 3180 .map(|c| c.is_urgent)
3008 .unwrap_or(false); 3181 .unwrap_or(false);
@@ -3013,7 +3186,8 @@ impl WindowManager {
3013 } 3186 }
3014 } 3187 }
3015 Event::FocusIn(event) => { 3188 Event::FocusIn(event) => {
3016 - let selected_window = self.monitors 3189 + let selected_window = self
3190 + .monitors
3017 .get(self.selected_monitor) 3191 .get(self.selected_monitor)
3018 .and_then(|m| m.selected_client); 3192 .and_then(|m| m.selected_client);
3019 3193
@@ -3055,111 +3229,111 @@ impl WindowManager {
3055 if !is_normie { 3229 if !is_normie {
3056 let monitor_count = self.monitors.len(); 3230 let monitor_count = self.monitors.len();
3057 for monitor_index in 0..monitor_count { 3231 for monitor_index in 0..monitor_count {
3058 - let monitor = &self.monitors[monitor_index]; 3232 + let monitor = &self.monitors[monitor_index];
3059 - let border_width = self.config.border_width; 3233 + let border_width = self.config.border_width;
3060 3234
3061 - let gaps = if self.gaps_enabled { 3235 + let gaps = if self.gaps_enabled {
3062 - GapConfig { 3236 + GapConfig {
3063 - inner_horizontal: self.config.gap_inner_horizontal, 3237 + inner_horizontal: self.config.gap_inner_horizontal,
3064 - inner_vertical: self.config.gap_inner_vertical, 3238 + inner_vertical: self.config.gap_inner_vertical,
3065 - outer_horizontal: self.config.gap_outer_horizontal, 3239 + outer_horizontal: self.config.gap_outer_horizontal,
3066 - outer_vertical: self.config.gap_outer_vertical, 3240 + outer_vertical: self.config.gap_outer_vertical,
3067 - } 3241 + }
3068 - } else { 3242 + } else {
3069 - GapConfig { 3243 + GapConfig {
3070 - inner_horizontal: 0, 3244 + inner_horizontal: 0,
3071 - inner_vertical: 0, 3245 + inner_vertical: 0,
3072 - outer_horizontal: 0, 3246 + outer_horizontal: 0,
3073 - outer_vertical: 0, 3247 + outer_vertical: 0,
3074 - } 3248 + }
3075 - }; 3249 + };
3076 3250
3077 - let monitor_x = monitor.screen_x; 3251 + let monitor_x = monitor.screen_x;
3078 - let monitor_y = monitor.screen_y; 3252 + let monitor_y = monitor.screen_y;
3079 - let monitor_width = monitor.screen_width; 3253 + let monitor_width = monitor.screen_width;
3080 - let monitor_height = monitor.screen_height; 3254 + let monitor_height = monitor.screen_height;
3081 3255
3082 - let mut visible: Vec<Window> = Vec::new(); 3256 + let mut visible: Vec<Window> = Vec::new();
3083 - let mut current = self.next_tiled(monitor.clients_head, monitor); 3257 + let mut current = self.next_tiled(monitor.clients_head, monitor);
3084 - while let Some(window) = current { 3258 + while let Some(window) = current {
3085 - visible.push(window); 3259 + visible.push(window);
3086 - if let Some(client) = self.clients.get(&window) { 3260 + if let Some(client) = self.clients.get(&window) {
3087 - current = self.next_tiled(client.next, monitor); 3261 + current = self.next_tiled(client.next, monitor);
3088 - } else { 3262 + } else {
3089 - break; 3263 + break;
3264 + }
3090 } 3265 }
3091 - }
3092 3266
3093 - let bar_height = if self.show_bar { 3267 + let bar_height = if self.show_bar {
3094 - self.bars 3268 + self.bars
3095 - .get(monitor_index) 3269 + .get(monitor_index)
3096 - .map(|bar| bar.height() as u32) 3270 + .map(|bar| bar.height() as u32)
3097 - .unwrap_or(0) 3271 + .unwrap_or(0)
3098 - } else { 3272 + } else {
3099 - 0 3273 + 0
3100 - }; 3274 + };
3101 - let usable_height = monitor_height.saturating_sub(bar_height as i32); 3275 + let usable_height = monitor_height.saturating_sub(bar_height as i32);
3102 - let master_factor = monitor.master_factor; 3276 + let master_factor = monitor.master_factor;
3103 - let num_master = monitor.num_master; 3277 + let num_master = monitor.num_master;
3104 - let smartgaps_enabled = self.config.smartgaps_enabled; 3278 + let smartgaps_enabled = self.config.smartgaps_enabled;
3105 - 3279 +
3106 - let geometries = self.layout.arrange( 3280 + let geometries = self.layout.arrange(
3107 - &visible, 3281 + &visible,
3108 - monitor_width as u32, 3282 + monitor_width as u32,
3109 - usable_height as u32, 3283 + usable_height as u32,
3110 - &gaps, 3284 + &gaps,
3111 - master_factor, 3285 + master_factor,
3112 - num_master, 3286 + num_master,
3113 - smartgaps_enabled, 3287 + smartgaps_enabled,
3114 - ); 3288 + );
3115 3289
3116 - for (window, geometry) in visible.iter().zip(geometries.iter()) { 3290 + for (window, geometry) in visible.iter().zip(geometries.iter()) {
3117 - let mut adjusted_width = geometry.width.saturating_sub(2 * border_width); 3291 + let mut adjusted_width = geometry.width.saturating_sub(2 * border_width);
3118 - let mut adjusted_height = geometry.height.saturating_sub(2 * border_width); 3292 + let mut adjusted_height = geometry.height.saturating_sub(2 * border_width);
3119 3293
3120 - if let Some(client) = self.clients.get(window).cloned() { 3294 + if let Some(client) = self.clients.get(window).cloned() {
3121 - if !client.is_floating { 3295 + if !client.is_floating {
3122 - let (_, _, hint_width, hint_height, _) = self.apply_size_hints( 3296 + let (_, _, hint_width, hint_height, _) = self.apply_size_hints(
3123 - *window, 3297 + *window,
3124 - geometry.x_coordinate as i32, 3298 + geometry.x_coordinate as i32,
3125 - geometry.y_coordinate as i32, 3299 + geometry.y_coordinate as i32,
3126 - adjusted_width as i32, 3300 + adjusted_width as i32,
3127 - adjusted_height as i32, 3301 + adjusted_height as i32,
3128 - ); 3302 + );
3129 - adjusted_width = hint_width as u32; 3303 + adjusted_width = hint_width as u32;
3130 - adjusted_height = hint_height as u32; 3304 + adjusted_height = hint_height as u32;
3305 + }
3131 } 3306 }
3132 - }
3133 3307
3134 - let adjusted_x = geometry.x_coordinate + monitor_x; 3308 + let adjusted_x = geometry.x_coordinate + monitor_x;
3135 - let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32; 3309 + let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32;
3136 3310
3137 - if let Some(client) = self.clients.get_mut(window) { 3311 + if let Some(client) = self.clients.get_mut(window) {
3138 - client.x_position = adjusted_x as i16; 3312 + client.x_position = adjusted_x as i16;
3139 - client.y_position = adjusted_y as i16; 3313 + client.y_position = adjusted_y as i16;
3140 - client.width = adjusted_width as u16; 3314 + client.width = adjusted_width as u16;
3141 - client.height = adjusted_height as u16; 3315 + client.height = adjusted_height as u16;
3142 - } 3316 + }
3143 3317
3144 - self.connection.configure_window( 3318 + self.connection.configure_window(
3145 - *window, 3319 + *window,
3146 - &ConfigureWindowAux::new() 3320 + &ConfigureWindowAux::new()
3147 - .x(adjusted_x) 3321 + .x(adjusted_x)
3148 - .y(adjusted_y) 3322 + .y(adjusted_y)
3149 - .width(adjusted_width) 3323 + .width(adjusted_width)
3150 - .height(adjusted_height) 3324 + .height(adjusted_height)
3151 - .border_width(border_width), 3325 + .border_width(border_width),
3152 - )?; 3326 + )?;
3153 3327
3154 - if let Some(c) = self.clients.get_mut(window) { 3328 + if let Some(c) = self.clients.get_mut(window) {
3155 - c.x_position = adjusted_x as i16; 3329 + c.x_position = adjusted_x as i16;
3156 - c.y_position = adjusted_y as i16; 3330 + c.y_position = adjusted_y as i16;
3157 - c.width = adjusted_width as u16; 3331 + c.width = adjusted_width as u16;
3158 - c.height = adjusted_height as u16; 3332 + c.height = adjusted_height as u16;
3159 - c.border_width = border_width as u16; 3333 + c.border_width = border_width as u16;
3334 + }
3160 } 3335 }
3161 } 3336 }
3162 - }
3163 } 3337 }
3164 3338
3165 for monitor_index in 0..self.monitors.len() { 3339 for monitor_index in 0..self.monitors.len() {
@@ -3195,8 +3369,12 @@ impl WindowManager {
3195 }; 3369 };
3196 3370
3197 let tab_bar_x = (monitor.screen_x + outer_horizontal as i32) as i16; 3371 let tab_bar_x = (monitor.screen_x + outer_horizontal as i32) as i16;
3198 - let tab_bar_y = (monitor.screen_y as f32 + bar_height + outer_vertical as f32) as i16; 3372 + let tab_bar_y =
3199 - let tab_bar_width = monitor.screen_width.saturating_sub(2 * outer_horizontal as i32) as u16; 3373 + (monitor.screen_y as f32 + bar_height + outer_vertical as f32) as i16;
3374 + let tab_bar_width = monitor
3375 + .screen_width
3376 + .saturating_sub(2 * outer_horizontal as i32)
3377 + as u16;
3200 3378
3201 if let Err(e) = self.tab_bars[monitor_index].reposition( 3379 if let Err(e) = self.tab_bars[monitor_index].reposition(
3202 &self.connection, 3380 &self.connection,
@@ -3211,23 +3389,20 @@ impl WindowManager {
3211 } 3389 }
3212 3390
3213 for monitor_index in 0..self.tab_bars.len() { 3391 for monitor_index in 0..self.tab_bars.len() {
3214 - let has_visible_windows = self 3392 + let has_visible_windows = self.windows.iter().any(|&window| {
3215 - .windows 3393 + if let Some(client) = self.clients.get(&window) {
3216 - .iter() 3394 + if client.monitor_index != monitor_index
3217 - .any(|&window| { 3395 + || self.floating_windows.contains(&window)
3218 - if let Some(client) = self.clients.get(&window) { 3396 + || self.fullscreen_windows.contains(&window)
3219 - if client.monitor_index != monitor_index 3397 + {
3220 - || self.floating_windows.contains(&window) 3398 + return false;
3221 - || self.fullscreen_windows.contains(&window) 3399 + }
3222 - { 3400 + if let Some(monitor) = self.monitors.get(monitor_index) {
3223 - return false; 3401 + return (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0;
3224 - }
3225 - if let Some(monitor) = self.monitors.get(monitor_index) {
3226 - return (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0;
3227 - }
3228 } 3402 }
3229 - false 3403 + }
3230 - }); 3404 + false
3405 + });
3231 3406
3232 if is_tabbed && has_visible_windows { 3407 if is_tabbed && has_visible_windows {
3233 if let Err(e) = self.tab_bars[monitor_index].show(&self.connection) { 3408 if let Err(e) = self.tab_bars[monitor_index].show(&self.connection) {
@@ -3256,7 +3431,13 @@ impl WindowManager {
3256 fn send_configure_notify(&self, window: Window) -> WmResult<()> { 3431 fn send_configure_notify(&self, window: Window) -> WmResult<()> {
3257 let client = self.clients.get(&window); 3432 let client = self.clients.get(&window);
3258 let (x, y, w, h, bw) = if let Some(c) = client { 3433 let (x, y, w, h, bw) = if let Some(c) = client {
3259 - (c.x_position, c.y_position, c.width, c.height, c.border_width) 3434 + (
3435 + c.x_position,
3436 + c.y_position,
3437 + c.width,
3438 + c.height,
3439 + c.border_width,
3440 + )
3260 } else { 3441 } else {
3261 let geom = self.connection.get_geometry(window)?.reply()?; 3442 let geom = self.connection.get_geometry(window)?.reply()?;
3262 (geom.x, geom.y, geom.width, geom.height, geom.border_width) 3443 (geom.x, geom.y, geom.width, geom.height, geom.border_width)
@@ -3276,18 +3457,15 @@ impl WindowManager {
3276 override_redirect: false, 3457 override_redirect: false,
3277 }; 3458 };
3278 3459
3279 - self.connection.send_event( 3460 + self.connection
3280 - false, 3461 + .send_event(false, window, EventMask::STRUCTURE_NOTIFY, event)?;
3281 - window,
3282 - EventMask::STRUCTURE_NOTIFY,
3283 - event,
3284 - )?;
3285 3462
3286 Ok(()) 3463 Ok(())
3287 } 3464 }
3288 3465
3289 fn update_size_hints(&mut self, window: Window) -> WmResult<()> { 3466 fn update_size_hints(&mut self, window: Window) -> WmResult<()> {
3290 - let size_hints = self.connection 3467 + let size_hints = self
3468 + .connection
3291 .get_property( 3469 .get_property(
3292 false, 3470 false,
3293 window, 3471 window,
@@ -3361,8 +3539,10 @@ impl WindowManager {
3361 } 3539 }
3362 3540
3363 if flags & P_ASPECT != 0 { 3541 if flags & P_ASPECT != 0 {
3364 - client.min_aspect = (read_u32(MIN_ASPECT_Y) as f32) / (read_u32(MIN_ASPECT_X) as f32).max(1.0); 3542 + client.min_aspect =
3365 - client.max_aspect = (read_u32(MAX_ASPECT_X) as f32) / (read_u32(MAX_ASPECT_Y) as f32).max(1.0); 3543 + (read_u32(MIN_ASPECT_Y) as f32) / (read_u32(MIN_ASPECT_X) as f32).max(1.0);
3544 + client.max_aspect =
3545 + (read_u32(MAX_ASPECT_X) as f32) / (read_u32(MAX_ASPECT_Y) as f32).max(1.0);
3366 } else { 3546 } else {
3367 client.min_aspect = 0.0; 3547 client.min_aspect = 0.0;
3368 client.max_aspect = 0.0; 3548 client.max_aspect = 0.0;
@@ -3379,7 +3559,8 @@ impl WindowManager {
3379 } 3559 }
3380 3560
3381 fn update_window_title(&mut self, window: Window) -> WmResult<()> { 3561 fn update_window_title(&mut self, window: Window) -> WmResult<()> {
3382 - let net_name = self.connection 3562 + let net_name = self
3563 + .connection
3383 .get_property( 3564 .get_property(
3384 false, 3565 false,
3385 window, 3566 window,
@@ -3402,7 +3583,8 @@ impl WindowManager {
3402 } 3583 }
3403 } 3584 }
3404 3585
3405 - let wm_name = self.connection 3586 + let wm_name = self
3587 + .connection
3406 .get_property( 3588 .get_property(
3407 false, 3589 false,
3408 window, 3590 window,
@@ -3425,14 +3607,10 @@ impl WindowManager {
3425 } 3607 }
3426 3608
3427 fn update_window_hints(&mut self, window: Window) -> WmResult<()> { 3609 fn update_window_hints(&mut self, window: Window) -> WmResult<()> {
3428 - let hints_reply = self.connection.get_property( 3610 + let hints_reply = self
3429 - false, 3611 + .connection
3430 - window, 3612 + .get_property(false, window, AtomEnum::WM_HINTS, AtomEnum::WM_HINTS, 0, 9)?
3431 - AtomEnum::WM_HINTS, 3613 + .reply();
3432 - AtomEnum::WM_HINTS,
3433 - 0,
3434 - 9,
3435 - )?.reply();
3436 3614
3437 if let Ok(hints) = hints_reply { 3615 if let Ok(hints) = hints_reply {
3438 if hints.value.len() >= 4 { 3616 if hints.value.len() >= 4 {
@@ -3443,7 +3621,8 @@ impl WindowManager {
3443 hints.value[3], 3621 hints.value[3],
3444 ]); 3622 ]);
3445 3623
3446 - let selected_window = self.monitors 3624 + let selected_window = self
3625 + .monitors
3447 .get(self.selected_monitor) 3626 .get(self.selected_monitor)
3448 .and_then(|m| m.selected_client); 3627 .and_then(|m| m.selected_client);
3449 3628
@@ -3490,13 +3669,16 @@ impl WindowManager {
3490 } 3669 }
3491 3670
3492 fn update_window_type(&mut self, window: Window) -> WmResult<()> { 3671 fn update_window_type(&mut self, window: Window) -> WmResult<()> {
3493 - if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state) { 3672 + if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state)
3673 + {
3494 if state_atom == self.atoms.net_wm_state_fullscreen { 3674 if state_atom == self.atoms.net_wm_state_fullscreen {
3495 self.set_window_fullscreen(window, true)?; 3675 self.set_window_fullscreen(window, true)?;
3496 } 3676 }
3497 } 3677 }
3498 3678
3499 - if let Ok(Some(type_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_window_type) { 3679 + if let Ok(Some(type_atom)) =
3680 + self.get_window_atom_property(window, self.atoms.net_wm_window_type)
3681 + {
3500 if type_atom == self.atoms.net_wm_window_type_dialog { 3682 if type_atom == self.atoms.net_wm_window_type_dialog {
3501 if let Some(client) = self.clients.get_mut(&window) { 3683 if let Some(client) = self.clients.get_mut(&window) {
3502 client.is_floating = true; 3684 client.is_floating = true;
@@ -3508,16 +3690,40 @@ impl WindowManager {
3508 Ok(()) 3690 Ok(())
3509 } 3691 }
3510 3692
3511 - fn apply_size_hints(&mut self, window: Window, mut x: i32, mut y: i32, mut w: i32, mut h: i32) -> (i32, i32, i32, i32, bool) { 3693 + fn apply_size_hints(
3694 + &mut self,
3695 + window: Window,
3696 + mut x: i32,
3697 + mut y: i32,
3698 + mut w: i32,
3699 + mut h: i32,
3700 + ) -> (i32, i32, i32, i32, bool) {
3512 let bh = 20; 3701 let bh = 20;
3513 3702
3514 - let (client_x, client_y, client_w, client_h, bw, monitor_index, is_floating, mut hints_valid) = { 3703 + let (
3704 + client_x,
3705 + client_y,
3706 + client_w,
3707 + client_h,
3708 + bw,
3709 + monitor_index,
3710 + is_floating,
3711 + mut hints_valid,
3712 + ) = {
3515 let client = match self.clients.get(&window) { 3713 let client = match self.clients.get(&window) {
3516 Some(c) => c, 3714 Some(c) => c,
3517 None => return (x, y, w, h, false), 3715 None => return (x, y, w, h, false),
3518 }; 3716 };
3519 - (client.x_position as i32, client.y_position as i32, client.width as i32, client.height as i32, 3717 + (
3520 - client.border_width as i32, client.monitor_index, client.is_floating, client.hints_valid) 3718 + client.x_position as i32,
3719 + client.y_position as i32,
3720 + client.width as i32,
3721 + client.height as i32,
3722 + client.border_width as i32,
3723 + client.monitor_index,
3724 + client.is_floating,
3725 + client.hints_valid,
3726 + )
3521 }; 3727 };
3522 3728
3523 let monitor = &self.monitors[monitor_index]; 3729 let monitor = &self.monitors[monitor_index];
@@ -3550,16 +3756,39 @@ impl WindowManager {
3550 if is_floating || self.layout.name() == "normie" { 3756 if is_floating || self.layout.name() == "normie" {
3551 if !hints_valid { 3757 if !hints_valid {
3552 let _ = self.update_size_hints(window); 3758 let _ = self.update_size_hints(window);
3553 - hints_valid = self.clients.get(&window).map(|c| c.hints_valid).unwrap_or(false); 3759 + hints_valid = self
3760 + .clients
3761 + .get(&window)
3762 + .map(|c| c.hints_valid)
3763 + .unwrap_or(false);
3554 } 3764 }
3555 3765
3556 if hints_valid { 3766 if hints_valid {
3557 - let (base_width, base_height, min_width, min_height, max_width, max_height, 3767 + let (
3558 - inc_width, inc_height, min_aspect, max_aspect) = { 3768 + base_width,
3769 + base_height,
3770 + min_width,
3771 + min_height,
3772 + max_width,
3773 + max_height,
3774 + inc_width,
3775 + inc_height,
3776 + min_aspect,
3777 + max_aspect,
3778 + ) = {
3559 let client = self.clients.get(&window).unwrap(); 3779 let client = self.clients.get(&window).unwrap();
3560 - (client.base_width, client.base_height, client.min_width, client.min_height, 3780 + (
3561 - client.max_width, client.max_height, client.increment_width, client.increment_height, 3781 + client.base_width,
3562 - client.min_aspect, client.max_aspect) 3782 + client.base_height,
3783 + client.min_width,
3784 + client.min_height,
3785 + client.max_width,
3786 + client.max_height,
3787 + client.increment_width,
3788 + client.increment_height,
3789 + client.min_aspect,
3790 + client.max_aspect,
3791 + )
3563 }; 3792 };
3564 3793
3565 let base_is_min = base_width == min_width && base_height == min_height; 3794 let base_is_min = base_width == min_width && base_height == min_height;
@@ -3687,7 +3916,9 @@ impl WindowManager {
3687 if let Some(current_client) = self.clients.get(&current_window) { 3916 if let Some(current_client) = self.clients.get(&current_window) {
3688 if current_client.next == Some(window) { 3917 if current_client.next == Some(window) {
3689 let new_next = self.clients.get(&window).and_then(|c| c.next); 3918 let new_next = self.clients.get(&window).and_then(|c| c.next);
3690 - if let Some(current_client_mut) = self.clients.get_mut(&current_window) { 3919 + if let Some(current_client_mut) =
3920 + self.clients.get_mut(&current_window)
3921 + {
3691 current_client_mut.next = new_next; 3922 current_client_mut.next = new_next;
3692 } 3923 }
3693 break; 3924 break;
@@ -3745,8 +3976,11 @@ impl WindowManager {
3745 while let Some(current_window) = current { 3976 while let Some(current_window) = current {
3746 if let Some(current_client) = self.clients.get(&current_window) { 3977 if let Some(current_client) = self.clients.get(&current_window) {
3747 if current_client.stack_next == Some(window) { 3978 if current_client.stack_next == Some(window) {
3748 - let new_stack_next = self.clients.get(&window).and_then(|c| c.stack_next); 3979 + let new_stack_next =
3749 - if let Some(current_client_mut) = self.clients.get_mut(&current_window) { 3980 + self.clients.get(&window).and_then(|c| c.stack_next);
3981 + if let Some(current_client_mut) =
3982 + self.clients.get_mut(&current_window)
3983 + {
3750 current_client_mut.stack_next = new_stack_next; 3984 current_client_mut.stack_next = new_stack_next;
3751 } 3985 }
3752 break; 3986 break;