|
|
@@ -5,6 +5,7 @@ use crate::keyboard::{self, Arg, KeyAction, handlers}; |
| 5 |
5 |
use crate::layout::GapConfig; |
| 6 |
6 |
use crate::layout::Layout; |
| 7 |
7 |
use crate::layout::tiling::TilingLayout; |
|
8 |
+use crate::monitor::{Monitor, detect_monitors}; |
| 8 |
9 |
use std::collections::HashSet; |
| 9 |
10 |
use x11rb::cursor::Handle as CursorHandle; |
| 10 |
11 |
|
|
|
@@ -25,14 +26,15 @@ pub struct WindowManager { |
| 25 |
26 |
root: Window, |
| 26 |
27 |
screen: Screen, |
| 27 |
28 |
windows: Vec<Window>, |
| 28 |
|
- focused_window: Option<Window>, |
| 29 |
29 |
layout: Box<dyn Layout>, |
| 30 |
30 |
window_tags: std::collections::HashMap<Window, TagMask>, |
| 31 |
|
- selected_tags: TagMask, |
|
31 |
+ window_monitor: std::collections::HashMap<Window, usize>, |
| 32 |
32 |
gaps_enabled: bool, |
| 33 |
33 |
fullscreen_window: Option<Window>, |
| 34 |
34 |
floating_windows: HashSet<Window>, |
| 35 |
|
- bar: Bar, |
|
35 |
+ bars: Vec<Bar>, |
|
36 |
+ monitors: Vec<Monitor>, |
|
37 |
+ selected_monitor: usize, |
| 36 |
38 |
} |
| 37 |
39 |
|
| 38 |
40 |
type WmResult<T> = Result<T, WmError>; |
|
|
@@ -90,9 +92,27 @@ impl WindowManager { |
| 90 |
92 |
u16::from(config.modkey).into(), |
| 91 |
93 |
)?; |
| 92 |
94 |
|
| 93 |
|
- let bar = Bar::new(&connection, &screen, screen_number, &config)?; |
|
95 |
+ let mut monitors = detect_monitors(&connection, &screen, root)?; |
| 94 |
96 |
|
| 95 |
97 |
let selected_tags = Self::get_saved_selected_tags(&connection, root, config.tags.len())?; |
|
98 |
+ if !monitors.is_empty() { |
|
99 |
+ monitors[0].selected_tags = selected_tags; |
|
100 |
+ } |
|
101 |
+ |
|
102 |
+ let mut bars = Vec::new(); |
|
103 |
+ for monitor in &monitors { |
|
104 |
+ let bar = Bar::new( |
|
105 |
+ &connection, |
|
106 |
+ &screen, |
|
107 |
+ screen_number, |
|
108 |
+ &config, |
|
109 |
+ monitor.x as i16, |
|
110 |
+ monitor.y as i16, |
|
111 |
+ monitor.width as u16, |
|
112 |
+ )?; |
|
113 |
+ bars.push(bar); |
|
114 |
+ } |
|
115 |
+ |
| 96 |
116 |
let gaps_enabled = config.gaps_enabled; |
| 97 |
117 |
|
| 98 |
118 |
let mut window_manager = Self { |
|
|
@@ -102,14 +122,15 @@ impl WindowManager { |
| 102 |
122 |
root, |
| 103 |
123 |
screen, |
| 104 |
124 |
windows: Vec::new(), |
| 105 |
|
- focused_window: None, |
| 106 |
125 |
layout: Box::new(TilingLayout), |
| 107 |
126 |
window_tags: std::collections::HashMap::new(), |
| 108 |
|
- selected_tags, |
|
127 |
+ window_monitor: std::collections::HashMap::new(), |
| 109 |
128 |
gaps_enabled, |
| 110 |
129 |
fullscreen_window: None, |
| 111 |
130 |
floating_windows: HashSet::new(), |
| 112 |
|
- bar, |
|
131 |
+ bars, |
|
132 |
+ monitors, |
|
133 |
+ selected_monitor: 0, |
| 113 |
134 |
}; |
| 114 |
135 |
|
| 115 |
136 |
window_manager.scan_existing_windows()?; |
|
|
@@ -167,7 +188,7 @@ impl WindowManager { |
| 167 |
188 |
.atom; |
| 168 |
189 |
|
| 169 |
190 |
for &window in &tree.children { |
| 170 |
|
- if window == self.bar.window() { |
|
191 |
+ if self.bars.iter().any(|bar| bar.window() == window) { |
| 171 |
192 |
continue; |
| 172 |
193 |
} |
| 173 |
194 |
|
|
|
@@ -183,6 +204,7 @@ impl WindowManager { |
| 183 |
204 |
let tag = self.get_saved_tag(window, net_client_info)?; |
| 184 |
205 |
self.windows.push(window); |
| 185 |
206 |
self.window_tags.insert(window, tag); |
|
207 |
+ self.window_monitor.insert(window, self.selected_monitor); |
| 186 |
208 |
continue; |
| 187 |
209 |
} |
| 188 |
210 |
|
|
|
@@ -207,12 +229,13 @@ impl WindowManager { |
| 207 |
229 |
let tag = self.get_saved_tag(window, net_client_info)?; |
| 208 |
230 |
self.windows.push(window); |
| 209 |
231 |
self.window_tags.insert(window, tag); |
|
232 |
+ self.window_monitor.insert(window, self.selected_monitor); |
| 210 |
233 |
} |
| 211 |
234 |
} |
| 212 |
235 |
} |
| 213 |
236 |
|
| 214 |
237 |
if let Some(&first) = self.windows.first() { |
| 215 |
|
- self.set_focus(Some(first))?; |
|
238 |
+ self.set_focus(first)?; |
| 216 |
239 |
} |
| 217 |
240 |
|
| 218 |
241 |
self.apply_layout()?; |
|
|
@@ -243,7 +266,7 @@ impl WindowManager { |
| 243 |
266 |
} |
| 244 |
267 |
} |
| 245 |
268 |
|
| 246 |
|
- Ok(self.selected_tags) |
|
269 |
+ Ok(self.monitors.get(self.selected_monitor).map(|m| m.selected_tags).unwrap_or(tag_mask(0))) |
| 247 |
270 |
} |
| 248 |
271 |
|
| 249 |
272 |
fn save_client_tag(&self, window: Window, tag: TagMask) -> WmResult<()> { |
|
|
@@ -300,7 +323,9 @@ impl WindowManager { |
| 300 |
323 |
self.update_bar()?; |
| 301 |
324 |
|
| 302 |
325 |
loop { |
| 303 |
|
- self.bar.update_blocks(); |
|
326 |
+ for bar in &mut self.bars { |
|
327 |
+ bar.update_blocks(); |
|
328 |
+ } |
| 304 |
329 |
|
| 305 |
330 |
if let Ok(Some(event)) = self.connection.poll_for_event() { |
| 306 |
331 |
if let Some(should_restart) = self.handle_event(event)? { |
|
|
@@ -308,7 +333,7 @@ impl WindowManager { |
| 308 |
333 |
} |
| 309 |
334 |
} |
| 310 |
335 |
|
| 311 |
|
- if self.bar.needs_redraw() { |
|
336 |
+ if self.bars.iter().any(|bar| bar.needs_redraw()) { |
| 312 |
337 |
self.update_bar()?; |
| 313 |
338 |
} |
| 314 |
339 |
|
|
|
@@ -317,7 +342,7 @@ impl WindowManager { |
| 317 |
342 |
} |
| 318 |
343 |
|
| 319 |
344 |
fn toggle_floating(&mut self) -> WmResult<()> { |
| 320 |
|
- if let Some(focused) = self.focused_window { |
|
345 |
+ if let Some(focused) = self.monitors.get(self.selected_monitor).and_then(|m| m.focused_window) { |
| 321 |
346 |
if self.floating_windows.contains(&focused) { |
| 322 |
347 |
self.floating_windows.remove(&focused); |
| 323 |
348 |
self.apply_layout()?; |
|
|
@@ -335,27 +360,32 @@ impl WindowManager { |
| 335 |
360 |
} |
| 336 |
361 |
|
| 337 |
362 |
fn toggle_fullscreen(&mut self) -> WmResult<()> { |
| 338 |
|
- if let Some(focused) = self.focused_window { |
|
363 |
+ if let Some(focused) = self.monitors.get(self.selected_monitor).and_then(|m| m.focused_window) { |
| 339 |
364 |
if self.fullscreen_window == Some(focused) { |
| 340 |
365 |
self.fullscreen_window = None; |
| 341 |
366 |
|
| 342 |
|
- self.connection.map_window(self.bar.window())?; |
|
367 |
+ for bar in &self.bars { |
|
368 |
+ self.connection.map_window(bar.window())?; |
|
369 |
+ } |
| 343 |
370 |
|
| 344 |
371 |
self.apply_layout()?; |
| 345 |
372 |
self.update_focus_visuals()?; |
| 346 |
373 |
} else { |
| 347 |
374 |
self.fullscreen_window = Some(focused); |
| 348 |
375 |
|
| 349 |
|
- self.connection.unmap_window(self.bar.window())?; |
|
376 |
+ if let Some(bar) = self.bars.get(self.selected_monitor) { |
|
377 |
+ self.connection.unmap_window(bar.window())?; |
|
378 |
+ } |
| 350 |
379 |
|
| 351 |
|
- let screen_width = self.screen.width_in_pixels as u32; |
| 352 |
|
- let screen_height = self.screen.height_in_pixels as u32; |
|
380 |
+ let monitor = &self.monitors[self.selected_monitor]; |
|
381 |
+ let screen_width = monitor.width; |
|
382 |
+ let screen_height = monitor.height; |
| 353 |
383 |
|
| 354 |
384 |
self.connection.configure_window( |
| 355 |
385 |
focused, |
| 356 |
386 |
&ConfigureWindowAux::new() |
| 357 |
|
- .x(0) |
| 358 |
|
- .y(0) |
|
387 |
+ .x(monitor.x) |
|
388 |
+ .y(monitor.y) |
| 359 |
389 |
.width(screen_width) |
| 360 |
390 |
.height(screen_height) |
| 361 |
391 |
.border_width(0) |
|
|
@@ -369,14 +399,19 @@ impl WindowManager { |
| 369 |
399 |
} |
| 370 |
400 |
|
| 371 |
401 |
fn update_bar(&mut self) -> WmResult<()> { |
| 372 |
|
- let mut occupied_tags: TagMask = 0; |
| 373 |
|
- for &tags in self.window_tags.values() { |
| 374 |
|
- occupied_tags |= tags; |
| 375 |
|
- } |
|
402 |
+ for (mon_idx, monitor) in self.monitors.iter().enumerate() { |
|
403 |
+ if let Some(bar) = self.bars.get_mut(mon_idx) { |
|
404 |
+ let mut occupied_tags: TagMask = 0; |
|
405 |
+ for (&window, &tags) in &self.window_tags { |
|
406 |
+ if self.window_monitor.get(&window).copied().unwrap_or(0) == mon_idx { |
|
407 |
+ occupied_tags |= tags; |
|
408 |
+ } |
|
409 |
+ } |
| 376 |
410 |
|
| 377 |
|
- self.bar.invalidate(); |
| 378 |
|
- self.bar |
| 379 |
|
- .draw(&self.connection, self.selected_tags, occupied_tags)?; |
|
411 |
+ bar.invalidate(); |
|
412 |
+ bar.draw(&self.connection, monitor.selected_tags, occupied_tags)?; |
|
413 |
+ } |
|
414 |
+ } |
| 380 |
415 |
Ok(()) |
| 381 |
416 |
} |
| 382 |
417 |
|
|
|
@@ -384,7 +419,7 @@ impl WindowManager { |
| 384 |
419 |
match action { |
| 385 |
420 |
KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, |
| 386 |
421 |
KeyAction::KillClient => { |
| 387 |
|
- if let Some(focused) = self.focused_window { |
|
422 |
+ if let Some(focused) = self.monitors.get(self.selected_monitor).and_then(|m| m.focused_window) { |
| 388 |
423 |
match self.connection.kill_client(focused) { |
| 389 |
424 |
Ok(_) => { |
| 390 |
425 |
self.connection.flush()?; |
|
|
@@ -433,14 +468,54 @@ impl WindowManager { |
| 433 |
468 |
self.gaps_enabled = !self.gaps_enabled; |
| 434 |
469 |
self.apply_layout()?; |
| 435 |
470 |
} |
|
471 |
+ KeyAction::FocusMonitor => { |
|
472 |
+ if let Arg::Int(direction) = arg { |
|
473 |
+ self.focus_monitor(*direction)?; |
|
474 |
+ } |
|
475 |
+ } |
| 436 |
476 |
KeyAction::None => {} |
| 437 |
477 |
} |
| 438 |
478 |
Ok(()) |
| 439 |
479 |
} |
| 440 |
480 |
|
|
481 |
+ fn focus_monitor(&mut self, direction: i32) -> WmResult<()> { |
|
482 |
+ if self.monitors.is_empty() { |
|
483 |
+ return Ok(()); |
|
484 |
+ } |
|
485 |
+ |
|
486 |
+ let new_monitor = if direction > 0 { |
|
487 |
+ (self.selected_monitor + 1) % self.monitors.len() |
|
488 |
+ } else { |
|
489 |
+ (self.selected_monitor + self.monitors.len() - 1) % self.monitors.len() |
|
490 |
+ }; |
|
491 |
+ |
|
492 |
+ if new_monitor == self.selected_monitor { |
|
493 |
+ return Ok(()); |
|
494 |
+ } |
|
495 |
+ |
|
496 |
+ self.selected_monitor = new_monitor; |
|
497 |
+ |
|
498 |
+ self.update_window_visibility()?; |
|
499 |
+ self.apply_layout()?; |
|
500 |
+ self.update_bar()?; |
|
501 |
+ |
|
502 |
+ let visible = self.visible_windows(); |
|
503 |
+ if let Some(&win) = visible.first() { |
|
504 |
+ self.set_focus(win)?; |
|
505 |
+ } |
|
506 |
+ |
|
507 |
+ Ok(()) |
|
508 |
+ } |
|
509 |
+ |
| 441 |
510 |
fn is_window_visible(&self, window: Window) -> bool { |
|
511 |
+ let window_mon = self.window_monitor.get(&window).copied().unwrap_or(0); |
|
512 |
+ if window_mon != self.selected_monitor { |
|
513 |
+ return false; |
|
514 |
+ } |
|
515 |
+ |
| 442 |
516 |
if let Some(&tags) = self.window_tags.get(&window) { |
| 443 |
|
- (tags & self.selected_tags) != 0 |
|
517 |
+ let selected_tags = self.monitors.get(self.selected_monitor).map(|m| m.selected_tags).unwrap_or(0); |
|
518 |
+ (tags & selected_tags) != 0 |
| 444 |
519 |
} else { |
| 445 |
520 |
false |
| 446 |
521 |
} |
|
|
@@ -473,10 +548,14 @@ impl WindowManager { |
| 473 |
548 |
|
| 474 |
549 |
if self.fullscreen_window.is_some() { |
| 475 |
550 |
self.fullscreen_window = None; |
| 476 |
|
- self.connection.map_window(self.bar.window())?; |
|
551 |
+ for bar in &self.bars { |
|
552 |
+ self.connection.map_window(bar.window())?; |
|
553 |
+ } |
| 477 |
554 |
} |
| 478 |
555 |
|
| 479 |
|
- self.selected_tags = tag_mask(tag_index); |
|
556 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
557 |
+ monitor.selected_tags = tag_mask(tag_index); |
|
558 |
+ } |
| 480 |
559 |
|
| 481 |
560 |
self.save_selected_tags()?; |
| 482 |
561 |
|
|
|
@@ -485,7 +564,9 @@ impl WindowManager { |
| 485 |
564 |
self.update_bar()?; |
| 486 |
565 |
|
| 487 |
566 |
let visible = self.visible_windows(); |
| 488 |
|
- self.set_focus(visible.first().copied())?; |
|
567 |
+ if let Some(&win) = visible.first() { |
|
568 |
+ self.set_focus(win)?; |
|
569 |
+ } |
| 489 |
570 |
|
| 490 |
571 |
Ok(()) |
| 491 |
572 |
} |
|
|
@@ -497,7 +578,8 @@ impl WindowManager { |
| 497 |
578 |
.reply()? |
| 498 |
579 |
.atom; |
| 499 |
580 |
|
| 500 |
|
- let desktop = self.selected_tags.trailing_zeros(); |
|
581 |
+ let selected_tags = self.monitors.get(self.selected_monitor).map(|m| m.selected_tags).unwrap_or(tag_mask(0)); |
|
582 |
+ let desktop = selected_tags.trailing_zeros(); |
| 501 |
583 |
|
| 502 |
584 |
let bytes = (desktop as u32).to_ne_bytes(); |
| 503 |
585 |
self.connection.change_property( |
|
|
@@ -519,7 +601,7 @@ impl WindowManager { |
| 519 |
601 |
return Ok(()); |
| 520 |
602 |
} |
| 521 |
603 |
|
| 522 |
|
- if let Some(focused) = self.focused_window { |
|
604 |
+ if let Some(focused) = self.monitors.get(self.selected_monitor).and_then(|m| m.focused_window) { |
| 523 |
605 |
let mask = tag_mask(tag_index); |
| 524 |
606 |
self.window_tags.insert(focused, mask); |
| 525 |
607 |
|
|
|
@@ -540,7 +622,9 @@ impl WindowManager { |
| 540 |
622 |
return Ok(()); |
| 541 |
623 |
} |
| 542 |
624 |
|
| 543 |
|
- let next_window = if let Some(current) = self.focused_window { |
|
625 |
+ let current = self.monitors.get(self.selected_monitor).and_then(|m| m.focused_window); |
|
626 |
+ |
|
627 |
+ let next_window = if let Some(current) = current { |
| 544 |
628 |
if let Some(current_index) = visible.iter().position(|&w| w == current) { |
| 545 |
629 |
let next_index = if direction > 0 { |
| 546 |
630 |
(current_index + 1) % visible.len() |
|
|
@@ -555,26 +639,28 @@ impl WindowManager { |
| 555 |
639 |
visible[0] |
| 556 |
640 |
}; |
| 557 |
641 |
|
| 558 |
|
- self.set_focus(Some(next_window))?; |
|
642 |
+ self.set_focus(next_window)?; |
| 559 |
643 |
Ok(()) |
| 560 |
644 |
} |
| 561 |
645 |
|
| 562 |
|
- pub fn set_focus(&mut self, window: Option<Window>) -> WmResult<()> { |
| 563 |
|
- self.focused_window = window; |
| 564 |
|
- |
| 565 |
|
- if let Some(win) = window { |
| 566 |
|
- self.connection |
| 567 |
|
- .set_input_focus(InputFocus::POINTER_ROOT, win, x11rb::CURRENT_TIME)?; |
| 568 |
|
- self.connection.flush()?; |
|
646 |
+ pub fn set_focus(&mut self, window: Window) -> WmResult<()> { |
|
647 |
+ if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
648 |
+ monitor.focused_window = Some(window); |
| 569 |
649 |
} |
| 570 |
650 |
|
|
651 |
+ self.connection |
|
652 |
+ .set_input_focus(InputFocus::POINTER_ROOT, window, x11rb::CURRENT_TIME)?; |
|
653 |
+ self.connection.flush()?; |
|
654 |
+ |
| 571 |
655 |
self.update_focus_visuals()?; |
| 572 |
656 |
Ok(()) |
| 573 |
657 |
} |
| 574 |
658 |
|
| 575 |
659 |
fn update_focus_visuals(&self) -> WmResult<()> { |
|
660 |
+ let focused = self.monitors.get(self.selected_monitor).and_then(|m| m.focused_window); |
|
661 |
+ |
| 576 |
662 |
for &window in &self.windows { |
| 577 |
|
- let (border_color, border_width) = if self.focused_window == Some(window) { |
|
663 |
+ let (border_color, border_width) = if focused == Some(window) { |
| 578 |
664 |
(self.config.border_focused, self.config.border_width) |
| 579 |
665 |
} else { |
| 580 |
666 |
(self.config.border_unfocused, self.config.border_width) |
|
|
@@ -733,14 +819,17 @@ impl WindowManager { |
| 733 |
819 |
&ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW), |
| 734 |
820 |
)?; |
| 735 |
821 |
|
|
822 |
+ let selected_tags = self.monitors.get(self.selected_monitor).map(|m| m.selected_tags).unwrap_or(tag_mask(0)); |
|
823 |
+ |
| 736 |
824 |
self.windows.push(event.window); |
| 737 |
|
- self.window_tags.insert(event.window, self.selected_tags); |
|
825 |
+ self.window_tags.insert(event.window, selected_tags); |
|
826 |
+ self.window_monitor.insert(event.window, self.selected_monitor); |
| 738 |
827 |
self.set_wm_state(event.window, 1)?; |
| 739 |
|
- let _ = self.save_client_tag(event.window, self.selected_tags); |
|
828 |
+ let _ = self.save_client_tag(event.window, selected_tags); |
| 740 |
829 |
|
| 741 |
830 |
self.apply_layout()?; |
| 742 |
831 |
self.update_bar()?; |
| 743 |
|
- self.set_focus(Some(event.window))?; |
|
832 |
+ self.set_focus(event.window)?; |
| 744 |
833 |
} |
| 745 |
834 |
Event::UnmapNotify(event) => { |
| 746 |
835 |
if self.windows.contains(&event.window) && self.is_window_visible(event.window) { |
|
|
@@ -757,7 +846,7 @@ impl WindowManager { |
| 757 |
846 |
return Ok(None); |
| 758 |
847 |
} |
| 759 |
848 |
if self.windows.contains(&event.event) { |
| 760 |
|
- self.set_focus(Some(event.event))?; |
|
849 |
+ self.set_focus(event.event)?; |
| 761 |
850 |
} |
| 762 |
851 |
} |
| 763 |
852 |
Event::KeyPress(event) => { |
|
|
@@ -769,12 +858,19 @@ impl WindowManager { |
| 769 |
858 |
} |
| 770 |
859 |
} |
| 771 |
860 |
Event::ButtonPress(event) => { |
| 772 |
|
- if event.event == self.bar.window() { |
| 773 |
|
- if let Some(tag_index) = self.bar.handle_click(event.event_x) { |
|
861 |
+ let is_bar_click = self.bars.iter() |
|
862 |
+ .enumerate() |
|
863 |
+ .find(|(_, bar)| bar.window() == event.event); |
|
864 |
+ |
|
865 |
+ if let Some((mon_idx, bar)) = is_bar_click { |
|
866 |
+ if let Some(tag_index) = bar.handle_click(event.event_x) { |
|
867 |
+ if mon_idx != self.selected_monitor { |
|
868 |
+ self.selected_monitor = mon_idx; |
|
869 |
+ } |
| 774 |
870 |
self.view_tag(tag_index)?; |
| 775 |
871 |
} |
| 776 |
872 |
} else if event.child != x11rb::NONE { |
| 777 |
|
- self.set_focus(Some(event.child))?; |
|
873 |
+ self.set_focus(event.child)?; |
| 778 |
874 |
|
| 779 |
875 |
if event.detail == ButtonIndex::M1.into() { |
| 780 |
876 |
self.move_mouse(event.child)?; |
|
|
@@ -784,9 +880,12 @@ impl WindowManager { |
| 784 |
880 |
} |
| 785 |
881 |
} |
| 786 |
882 |
Event::Expose(event) => { |
| 787 |
|
- if event.window == self.bar.window() { |
| 788 |
|
- self.bar.invalidate(); |
| 789 |
|
- self.update_bar()?; |
|
883 |
+ for bar in &mut self.bars { |
|
884 |
+ if event.window == bar.window() { |
|
885 |
+ bar.invalidate(); |
|
886 |
+ self.update_bar()?; |
|
887 |
+ break; |
|
888 |
+ } |
| 790 |
889 |
} |
| 791 |
890 |
} |
| 792 |
891 |
_ => {} |
|
|
@@ -798,12 +897,8 @@ impl WindowManager { |
| 798 |
897 |
if self.fullscreen_window.is_some() { |
| 799 |
898 |
return Ok(()); |
| 800 |
899 |
} |
| 801 |
|
- let screen_width = self.screen.width_in_pixels as u32; |
| 802 |
|
- let screen_height = self.screen.height_in_pixels as u32; |
| 803 |
|
- let border_width = self.config.border_width; |
| 804 |
900 |
|
| 805 |
|
- let bar_height = self.bar.height() as u32; |
| 806 |
|
- let usable_height = screen_height.saturating_sub(bar_height); |
|
901 |
+ let border_width = self.config.border_width; |
| 807 |
902 |
|
| 808 |
903 |
let gaps = if self.gaps_enabled { |
| 809 |
904 |
GapConfig { |
|
|
@@ -821,31 +916,52 @@ impl WindowManager { |
| 821 |
916 |
} |
| 822 |
917 |
}; |
| 823 |
918 |
|
| 824 |
|
- let visible: Vec<Window> = self |
| 825 |
|
- .visible_windows() |
| 826 |
|
- .into_iter() |
| 827 |
|
- .filter(|w| !self.floating_windows.contains(w)) |
| 828 |
|
- .collect(); |
|
919 |
+ for (mon_idx, monitor) in self.monitors.iter().enumerate() { |
|
920 |
+ let visible: Vec<Window> = self |
|
921 |
+ .windows |
|
922 |
+ .iter() |
|
923 |
+ .filter(|&&w| { |
|
924 |
+ let window_mon = self.window_monitor.get(&w).copied().unwrap_or(0); |
|
925 |
+ if window_mon != mon_idx { |
|
926 |
+ return false; |
|
927 |
+ } |
|
928 |
+ if self.floating_windows.contains(&w) { |
|
929 |
+ return false; |
|
930 |
+ } |
|
931 |
+ if let Some(&tags) = self.window_tags.get(&w) { |
|
932 |
+ (tags & monitor.selected_tags) != 0 |
|
933 |
+ } else { |
|
934 |
+ false |
|
935 |
+ } |
|
936 |
+ }) |
|
937 |
+ .copied() |
|
938 |
+ .collect(); |
|
939 |
+ |
|
940 |
+ let bar_height = self.bars.get(mon_idx).map(|b| b.height() as u32).unwrap_or(0); |
|
941 |
+ let usable_height = monitor.height.saturating_sub(bar_height); |
| 829 |
942 |
|
| 830 |
|
- let geometries = self |
| 831 |
|
- .layout |
| 832 |
|
- .arrange(&visible, screen_width, usable_height, &gaps); |
|
943 |
+ let geometries = self |
|
944 |
+ .layout |
|
945 |
+ .arrange(&visible, monitor.width, usable_height, &gaps); |
| 833 |
946 |
|
| 834 |
|
- for (window, geometry) in visible.iter().zip(geometries.iter()) { |
| 835 |
|
- let adjusted_width = geometry.width.saturating_sub(2 * border_width); |
| 836 |
|
- let adjusted_height = geometry.height.saturating_sub(2 * border_width); |
|
947 |
+ for (window, geometry) in visible.iter().zip(geometries.iter()) { |
|
948 |
+ let adjusted_width = geometry.width.saturating_sub(2 * border_width); |
|
949 |
+ let adjusted_height = geometry.height.saturating_sub(2 * border_width); |
| 837 |
950 |
|
| 838 |
|
- let adjusted_y = geometry.y_coordinate + bar_height as i32; |
|
951 |
+ let adjusted_x = geometry.x_coordinate + monitor.x; |
|
952 |
+ let adjusted_y = geometry.y_coordinate + monitor.y + bar_height as i32; |
| 839 |
953 |
|
| 840 |
|
- self.connection.configure_window( |
| 841 |
|
- *window, |
| 842 |
|
- &ConfigureWindowAux::new() |
| 843 |
|
- .x(geometry.x_coordinate) |
| 844 |
|
- .y(adjusted_y) |
| 845 |
|
- .width(adjusted_width) |
| 846 |
|
- .height(adjusted_height), |
| 847 |
|
- )?; |
|
954 |
+ self.connection.configure_window( |
|
955 |
+ *window, |
|
956 |
+ &ConfigureWindowAux::new() |
|
957 |
+ .x(adjusted_x) |
|
958 |
+ .y(adjusted_y) |
|
959 |
+ .width(adjusted_width) |
|
960 |
+ .height(adjusted_height), |
|
961 |
+ )?; |
|
962 |
+ } |
| 848 |
963 |
} |
|
964 |
+ |
| 849 |
965 |
self.connection.flush()?; |
| 850 |
966 |
Ok(()) |
| 851 |
967 |
} |
|
|
@@ -854,21 +970,25 @@ impl WindowManager { |
| 854 |
970 |
let initial_count = self.windows.len(); |
| 855 |
971 |
self.windows.retain(|&w| w != window); |
| 856 |
972 |
self.window_tags.remove(&window); |
|
973 |
+ self.window_monitor.remove(&window); |
| 857 |
974 |
self.floating_windows.remove(&window); |
| 858 |
975 |
|
| 859 |
976 |
if self.fullscreen_window == Some(window) { |
| 860 |
977 |
self.fullscreen_window = None; |
| 861 |
|
- self.connection.map_window(self.bar.window())?; |
|
978 |
+ for bar in &self.bars { |
|
979 |
+ self.connection.map_window(bar.window())?; |
|
980 |
+ } |
| 862 |
981 |
} |
| 863 |
982 |
|
| 864 |
983 |
if self.windows.len() < initial_count { |
| 865 |
|
- if self.focused_window == Some(window) { |
| 866 |
|
- let new_focus = if self.windows.is_empty() { |
| 867 |
|
- None |
| 868 |
|
- } else { |
| 869 |
|
- Some(self.windows[self.windows.len() - 1]) |
| 870 |
|
- }; |
| 871 |
|
- self.set_focus(new_focus)?; |
|
984 |
+ let focused = self.monitors.get(self.selected_monitor).and_then(|m| m.focused_window); |
|
985 |
+ if focused == Some(window) { |
|
986 |
+ let visible = self.visible_windows(); |
|
987 |
+ if let Some(&new_win) = visible.last() { |
|
988 |
+ self.set_focus(new_win)?; |
|
989 |
+ } else if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
|
990 |
+ monitor.focused_window = None; |
|
991 |
+ } |
| 872 |
992 |
} |
| 873 |
993 |
|
| 874 |
994 |
self.apply_layout()?; |