|
|
@@ -1,5 +1,6 @@ |
| 1 |
1 |
use crate::Config; |
| 2 |
2 |
use crate::bar::Bar; |
|
3 |
+use crate::client::{Client, TagMask}; |
| 3 |
4 |
use crate::errors::WmError; |
| 4 |
5 |
use crate::keyboard::{self, Arg, KeyAction, handlers}; |
| 5 |
6 |
use crate::layout::GapConfig; |
|
|
@@ -7,7 +8,7 @@ use crate::layout::tiling::TilingLayout; |
| 7 |
8 |
use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout}; |
| 8 |
9 |
use crate::monitor::{Monitor, detect_monitors}; |
| 9 |
10 |
use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay}; |
| 10 |
|
-use std::collections::HashSet; |
|
11 |
+use std::collections::{HashMap, HashSet}; |
| 11 |
12 |
use std::process::Command; |
| 12 |
13 |
use x11rb::cursor::Handle as CursorHandle; |
| 13 |
14 |
|
|
|
@@ -18,8 +19,6 @@ use x11rb::rust_connection::RustConnection; |
| 18 |
19 |
|
| 19 |
20 |
const DEFAULT_FLOAT_WIDTH_RATIO: f32 = 0.5; |
| 20 |
21 |
const DEFAULT_FLOAT_HEIGHT_RATIO: f32 = 0.5; |
| 21 |
|
-const SMART_MOVE_STEP_RATIO_VERTICAL: i32 = 4; |
| 22 |
|
-const SMART_MOVE_STEP_RATIO_HORIZONTAL: i32 = 6; |
| 23 |
22 |
|
| 24 |
23 |
#[derive(Debug, Clone, Copy)] |
| 25 |
24 |
pub struct CachedGeometry { |
|
|
@@ -30,7 +29,6 @@ pub struct CachedGeometry { |
| 30 |
29 |
pub border_width: u16, |
| 31 |
30 |
} |
| 32 |
31 |
|
| 33 |
|
-pub type TagMask = u32; |
| 34 |
32 |
pub fn tag_mask(tag: usize) -> TagMask { |
| 35 |
33 |
1 << tag |
| 36 |
34 |
} |
|
|
@@ -112,14 +110,15 @@ pub struct WindowManager { |
| 112 |
110 |
root: Window, |
| 113 |
111 |
screen: Screen, |
| 114 |
112 |
windows: Vec<Window>, |
|
113 |
+ clients: HashMap<Window, Client>, |
| 115 |
114 |
layout: LayoutBox, |
| 116 |
|
- window_tags: std::collections::HashMap<Window, TagMask>, |
| 117 |
|
- window_monitor: std::collections::HashMap<Window, usize>, |
| 118 |
|
- window_geometry_cache: std::collections::HashMap<Window, CachedGeometry>, |
|
115 |
+ window_tags: HashMap<Window, TagMask>, |
|
116 |
+ window_monitor: HashMap<Window, usize>, |
|
117 |
+ window_geometry_cache: HashMap<Window, CachedGeometry>, |
| 119 |
118 |
gaps_enabled: bool, |
| 120 |
119 |
floating_windows: HashSet<Window>, |
| 121 |
120 |
fullscreen_windows: HashSet<Window>, |
| 122 |
|
- floating_geometry_before_fullscreen: std::collections::HashMap<Window, (i16, i16, u16, u16, u16)>, |
|
121 |
+ floating_geometry_before_fullscreen: HashMap<Window, (i16, i16, u16, u16, u16)>, |
| 123 |
122 |
bars: Vec<Bar>, |
| 124 |
123 |
tab_bars: Vec<crate::tab_bar::TabBar>, |
| 125 |
124 |
show_bar: bool, |
|
|
@@ -221,9 +220,9 @@ impl WindowManager { |
| 221 |
220 |
&config, |
| 222 |
221 |
display, |
| 223 |
222 |
&font, |
| 224 |
|
- monitor.x as i16, |
| 225 |
|
- monitor.y as i16, |
| 226 |
|
- monitor.width as u16, |
|
223 |
+ monitor.screen_x as i16, |
|
224 |
+ monitor.screen_y as i16, |
|
225 |
+ monitor.screen_width as u16, |
| 227 |
226 |
)?; |
| 228 |
227 |
bars.push(bar); |
| 229 |
228 |
} |
|
|
@@ -237,9 +236,9 @@ impl WindowManager { |
| 237 |
236 |
screen_number, |
| 238 |
237 |
display, |
| 239 |
238 |
&font, |
| 240 |
|
- (monitor.x + config.gap_outer_horizontal as i32) as i16, |
| 241 |
|
- (monitor.y as f32 + bar_height + config.gap_outer_vertical as f32) as i16, |
| 242 |
|
- monitor.width.saturating_sub(2 * config.gap_outer_horizontal) as u16, |
|
239 |
+ (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, |
|
241 |
+ monitor.screen_width.saturating_sub(2 * config.gap_outer_horizontal as i32) as u16, |
| 243 |
242 |
config.scheme_occupied, |
| 244 |
243 |
config.scheme_selected, |
| 245 |
244 |
)?; |
|
|
@@ -269,14 +268,15 @@ impl WindowManager { |
| 269 |
268 |
root, |
| 270 |
269 |
screen, |
| 271 |
270 |
windows: Vec::new(), |
|
271 |
+ clients: HashMap::new(), |
| 272 |
272 |
layout: Box::new(TilingLayout), |
| 273 |
|
- window_tags: std::collections::HashMap::new(), |
| 274 |
|
- window_monitor: std::collections::HashMap::new(), |
| 275 |
|
- window_geometry_cache: std::collections::HashMap::new(), |
|
273 |
+ window_tags: HashMap::new(), |
|
274 |
+ window_monitor: HashMap::new(), |
|
275 |
+ window_geometry_cache: HashMap::new(), |
| 276 |
276 |
gaps_enabled, |
| 277 |
277 |
floating_windows: HashSet::new(), |
| 278 |
278 |
fullscreen_windows: HashSet::new(), |
| 279 |
|
- floating_geometry_before_fullscreen: std::collections::HashMap::new(), |
|
279 |
+ floating_geometry_before_fullscreen: HashMap::new(), |
| 280 |
280 |
bars, |
| 281 |
281 |
tab_bars, |
| 282 |
282 |
show_bar: true, |
|
|
@@ -443,7 +443,7 @@ impl WindowManager { |
| 443 |
443 |
Ok(self |
| 444 |
444 |
.monitors |
| 445 |
445 |
.get(self.selected_monitor) |
| 446 |
|
- .map(|m| m.selected_tags) |
|
446 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
| 447 |
447 |
.unwrap_or(tag_mask(0))) |
| 448 |
448 |
} |
| 449 |
449 |
|
|
|
@@ -524,15 +524,18 @@ impl WindowManager { |
| 524 |
524 |
if let Some(focused) = self |
| 525 |
525 |
.monitors |
| 526 |
526 |
.get(self.selected_monitor) |
| 527 |
|
- .and_then(|m| m.focused_window) |
|
527 |
+ .and_then(|m| m.selected_client) |
| 528 |
528 |
{ |
| 529 |
529 |
if self.floating_windows.contains(&focused) { |
| 530 |
530 |
self.floating_windows.remove(&focused); |
|
531 |
+ if let Some(client) = self.clients.get_mut(&focused) { |
|
532 |
+ client.is_floating = false; |
|
533 |
+ } |
| 531 |
534 |
|
| 532 |
535 |
let selected_tags = self |
| 533 |
536 |
.monitors |
| 534 |
537 |
.get(self.selected_monitor) |
| 535 |
|
- .map(|m| m.selected_tags) |
|
538 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
| 536 |
539 |
.unwrap_or(tag_mask(0)); |
| 537 |
540 |
|
| 538 |
541 |
self.window_tags.insert(focused, selected_tags); |
|
|
@@ -564,6 +567,9 @@ impl WindowManager { |
| 564 |
567 |
)?; |
| 565 |
568 |
|
| 566 |
569 |
self.floating_windows.insert(focused); |
|
570 |
+ if let Some(client) = self.clients.get_mut(&focused) { |
|
571 |
+ client.is_floating = true; |
|
572 |
+ } |
| 567 |
573 |
self.apply_layout()?; |
| 568 |
574 |
self.connection.flush()?; |
| 569 |
575 |
} |
|
|
@@ -571,239 +577,11 @@ impl WindowManager { |
| 571 |
577 |
Ok(()) |
| 572 |
578 |
} |
| 573 |
579 |
|
| 574 |
|
- fn collect_visible_floating_geometries(&mut self) -> Vec<(Window, CachedGeometry)> { |
| 575 |
|
- let focused_window = self.monitors.get(self.selected_monitor) |
| 576 |
|
- .and_then(|monitor| monitor.focused_window) |
| 577 |
|
- .unwrap_or(0); |
| 578 |
|
- let selected_monitor_index = self.selected_monitor; |
| 579 |
|
- |
| 580 |
|
- let candidate_windows: Vec<Window> = self.windows.iter() |
| 581 |
|
- .filter(|&&window| { |
| 582 |
|
- window != focused_window |
| 583 |
|
- && self.floating_windows.contains(&window) |
| 584 |
|
- && self.is_window_visible(window) |
| 585 |
|
- && self.window_monitor.get(&window).copied().unwrap_or(0) == selected_monitor_index |
| 586 |
|
- }) |
| 587 |
|
- .copied() |
| 588 |
|
- .collect(); |
| 589 |
|
- |
| 590 |
|
- candidate_windows.into_iter() |
| 591 |
|
- .filter_map(|window| { |
| 592 |
|
- self.get_or_query_geometry(window).ok().map(|geometry| (window, geometry)) |
| 593 |
|
- }) |
| 594 |
|
- .collect() |
| 595 |
|
- } |
| 596 |
|
- |
| 597 |
|
- fn calculate_smart_move_position( |
| 598 |
|
- &self, |
| 599 |
|
- current_x: i32, |
| 600 |
|
- current_y: i32, |
| 601 |
|
- current_width: i32, |
| 602 |
|
- current_height: i32, |
| 603 |
|
- direction: i32, |
| 604 |
|
- monitor: &Monitor, |
| 605 |
|
- other_geometries: &[(Window, CachedGeometry)], |
| 606 |
|
- ) -> (i32, i32) { |
| 607 |
|
- let (gap_inner_horizontal, gap_inner_vertical, gap_outer_horizontal, gap_outer_vertical) = if self.gaps_enabled { |
| 608 |
|
- ( |
| 609 |
|
- self.config.gap_inner_horizontal as i32, |
| 610 |
|
- self.config.gap_inner_vertical as i32, |
| 611 |
|
- self.config.gap_outer_horizontal as i32, |
| 612 |
|
- self.config.gap_outer_vertical as i32, |
| 613 |
|
- ) |
| 614 |
|
- } else { |
| 615 |
|
- (0, 0, 0, 0) |
| 616 |
|
- }; |
| 617 |
|
- |
| 618 |
|
- match direction { |
| 619 |
|
- 0 => { |
| 620 |
|
- let mut target_position = i32::MIN; |
| 621 |
|
- let current_top = current_y; |
| 622 |
|
- let mut new_y_position = current_y - (monitor.height as i32 / SMART_MOVE_STEP_RATIO_VERTICAL); |
| 623 |
|
- |
| 624 |
|
- for (_other_window, other_geometry) in other_geometries { |
| 625 |
|
- let other_x = other_geometry.x_position as i32; |
| 626 |
|
- let other_y = other_geometry.y_position as i32; |
| 627 |
|
- let other_width = other_geometry.width as i32; |
| 628 |
|
- let other_height = other_geometry.height as i32; |
| 629 |
|
- |
| 630 |
|
- if current_x + current_width < other_x || current_x > other_x + other_width { |
| 631 |
|
- continue; |
| 632 |
|
- } |
| 633 |
|
- |
| 634 |
|
- let other_bottom = other_y + other_height + gap_inner_vertical; |
| 635 |
|
- if current_top > other_bottom && new_y_position < other_bottom { |
| 636 |
|
- target_position = target_position.max(other_bottom); |
| 637 |
|
- } |
| 638 |
|
- } |
| 639 |
|
- |
| 640 |
|
- if target_position != i32::MIN { |
| 641 |
|
- new_y_position = target_position; |
| 642 |
|
- } |
| 643 |
|
- new_y_position = new_y_position.max(monitor.y as i32 + gap_outer_vertical); |
| 644 |
|
- (current_x, new_y_position) |
| 645 |
|
- } |
| 646 |
|
- 1 => { |
| 647 |
|
- let mut target_position = i32::MAX; |
| 648 |
|
- let current_bottom = current_y + current_height; |
| 649 |
|
- let mut new_y_position = current_y + (monitor.height as i32 / SMART_MOVE_STEP_RATIO_VERTICAL); |
| 650 |
|
- |
| 651 |
|
- for (_other_window, other_geometry) in other_geometries { |
| 652 |
|
- let other_x = other_geometry.x_position as i32; |
| 653 |
|
- let other_y = other_geometry.y_position as i32; |
| 654 |
|
- let other_width = other_geometry.width as i32; |
| 655 |
|
- |
| 656 |
|
- if current_x + current_width < other_x || current_x > other_x + other_width { |
| 657 |
|
- continue; |
| 658 |
|
- } |
| 659 |
|
- |
| 660 |
|
- let other_top = other_y - gap_inner_vertical; |
| 661 |
|
- if current_bottom < other_top && (new_y_position + current_height) > other_top { |
| 662 |
|
- target_position = target_position.min(other_top - current_height); |
| 663 |
|
- } |
| 664 |
|
- } |
| 665 |
|
- |
| 666 |
|
- if target_position != i32::MAX { |
| 667 |
|
- new_y_position = target_position; |
| 668 |
|
- } |
| 669 |
|
- new_y_position = new_y_position.min(monitor.y as i32 + monitor.height as i32 - current_height - gap_outer_vertical); |
| 670 |
|
- (current_x, new_y_position) |
| 671 |
|
- } |
| 672 |
|
- 2 => { |
| 673 |
|
- let mut target_position = i32::MIN; |
| 674 |
|
- let current_left = current_x; |
| 675 |
|
- let mut new_x_position = current_x - (monitor.width as i32 / SMART_MOVE_STEP_RATIO_HORIZONTAL); |
| 676 |
|
- |
| 677 |
|
- for (_other_window, other_geometry) in other_geometries { |
| 678 |
|
- let other_x = other_geometry.x_position as i32; |
| 679 |
|
- let other_y = other_geometry.y_position as i32; |
| 680 |
|
- let other_width = other_geometry.width as i32; |
| 681 |
|
- let other_height = other_geometry.height as i32; |
| 682 |
|
- |
| 683 |
|
- if current_y + current_height < other_y || current_y > other_y + other_height { |
| 684 |
|
- continue; |
| 685 |
|
- } |
| 686 |
|
- |
| 687 |
|
- let other_right = other_x + other_width + gap_inner_horizontal; |
| 688 |
|
- if current_left > other_right && new_x_position < other_right { |
| 689 |
|
- target_position = target_position.max(other_right); |
| 690 |
|
- } |
| 691 |
|
- } |
| 692 |
|
- |
| 693 |
|
- if target_position != i32::MIN { |
| 694 |
|
- new_x_position = target_position; |
| 695 |
|
- } |
| 696 |
|
- new_x_position = new_x_position.max(monitor.x as i32 + gap_outer_horizontal); |
| 697 |
|
- (new_x_position, current_y) |
| 698 |
|
- } |
| 699 |
|
- 3 => { |
| 700 |
|
- let mut target_position = i32::MAX; |
| 701 |
|
- let current_right = current_x + current_width; |
| 702 |
|
- let mut new_x_position = current_x + (monitor.width as i32 / SMART_MOVE_STEP_RATIO_HORIZONTAL); |
| 703 |
|
- |
| 704 |
|
- for (_other_window, other_geometry) in other_geometries { |
| 705 |
|
- let other_x = other_geometry.x_position as i32; |
| 706 |
|
- let other_y = other_geometry.y_position as i32; |
| 707 |
|
- let other_height = other_geometry.height as i32; |
| 708 |
|
- |
| 709 |
|
- if current_y + current_height < other_y || current_y > other_y + other_height { |
| 710 |
|
- continue; |
| 711 |
|
- } |
| 712 |
|
- |
| 713 |
|
- let other_left = other_x - gap_inner_horizontal; |
| 714 |
|
- if current_right < other_left && (new_x_position + current_width) > other_left { |
| 715 |
|
- target_position = target_position.min(other_left - current_width); |
| 716 |
|
- } |
| 717 |
|
- } |
| 718 |
|
- |
| 719 |
|
- if target_position != i32::MAX { |
| 720 |
|
- new_x_position = target_position; |
| 721 |
|
- } |
| 722 |
|
- new_x_position = new_x_position.min(monitor.x as i32 + monitor.width as i32 - current_width - gap_outer_horizontal); |
| 723 |
|
- (new_x_position, current_y) |
| 724 |
|
- } |
| 725 |
|
- _ => (current_x, current_y), |
| 726 |
|
- } |
| 727 |
|
- } |
| 728 |
|
- |
| 729 |
|
- fn smart_move_window(&mut self, direction: i32) -> WmResult<()> { |
| 730 |
|
- let focused = match self |
| 731 |
|
- .monitors |
| 732 |
|
- .get(self.selected_monitor) |
| 733 |
|
- .and_then(|monitor| monitor.focused_window) |
| 734 |
|
- { |
| 735 |
|
- Some(window) => window, |
| 736 |
|
- None => return Ok(()), |
| 737 |
|
- }; |
| 738 |
|
- |
| 739 |
|
- if !self.floating_windows.contains(&focused) { |
| 740 |
|
- let float_width = (self.screen.width_in_pixels as f32 * DEFAULT_FLOAT_WIDTH_RATIO) as u32; |
| 741 |
|
- let float_height = (self.screen.height_in_pixels as f32 * DEFAULT_FLOAT_HEIGHT_RATIO) as u32; |
| 742 |
|
- let border_width = self.config.border_width; |
| 743 |
|
- let center_x_position = ((self.screen.width_in_pixels - float_width as u16) / 2) as i32; |
| 744 |
|
- let center_y_position = ((self.screen.height_in_pixels - float_height as u16) / 2) as i32; |
| 745 |
|
- |
| 746 |
|
- self.connection.configure_window( |
| 747 |
|
- focused, |
| 748 |
|
- &ConfigureWindowAux::new() |
| 749 |
|
- .x(center_x_position) |
| 750 |
|
- .y(center_y_position) |
| 751 |
|
- .width(float_width) |
| 752 |
|
- .height(float_height) |
| 753 |
|
- .border_width(border_width) |
| 754 |
|
- .stack_mode(StackMode::ABOVE), |
| 755 |
|
- )?; |
| 756 |
|
- self.floating_windows.insert(focused); |
| 757 |
|
- } |
| 758 |
|
- |
| 759 |
|
- let current_geometry = self.get_or_query_geometry(focused)?; |
| 760 |
|
- let current_x = current_geometry.x_position as i32; |
| 761 |
|
- let current_y = current_geometry.y_position as i32; |
| 762 |
|
- let current_width = current_geometry.width as i32; |
| 763 |
|
- let current_height = current_geometry.height as i32; |
| 764 |
|
- |
| 765 |
|
- let other_geometries = self.collect_visible_floating_geometries(); |
| 766 |
|
- |
| 767 |
|
- let monitor = match self.monitors.get(self.selected_monitor) { |
| 768 |
|
- Some(monitor) => monitor, |
| 769 |
|
- None => return Ok(()), |
| 770 |
|
- }; |
| 771 |
|
- |
| 772 |
|
- let (new_x_position, new_y_position) = self.calculate_smart_move_position( |
| 773 |
|
- current_x, |
| 774 |
|
- current_y, |
| 775 |
|
- current_width, |
| 776 |
|
- current_height, |
| 777 |
|
- direction, |
| 778 |
|
- monitor, |
| 779 |
|
- &other_geometries, |
| 780 |
|
- ); |
| 781 |
|
- |
| 782 |
|
- self.connection.configure_window( |
| 783 |
|
- focused, |
| 784 |
|
- &ConfigureWindowAux::new() |
| 785 |
|
- .x(new_x_position) |
| 786 |
|
- .y(new_y_position) |
| 787 |
|
- .stack_mode(StackMode::ABOVE), |
| 788 |
|
- )?; |
| 789 |
|
- |
| 790 |
|
- self.update_geometry_cache(focused, CachedGeometry { |
| 791 |
|
- x_position: new_x_position as i16, |
| 792 |
|
- y_position: new_y_position as i16, |
| 793 |
|
- width: current_width as u16, |
| 794 |
|
- height: current_height as u16, |
| 795 |
|
- border_width: current_geometry.border_width, |
| 796 |
|
- }); |
| 797 |
|
- |
| 798 |
|
- self.connection.flush()?; |
| 799 |
|
- Ok(()) |
| 800 |
|
- } |
| 801 |
|
- |
| 802 |
580 |
fn exchange_client(&mut self, direction: i32) -> WmResult<()> { |
| 803 |
581 |
let focused = match self |
| 804 |
582 |
.monitors |
| 805 |
583 |
.get(self.selected_monitor) |
| 806 |
|
- .and_then(|m| m.focused_window) |
|
584 |
+ .and_then(|m| m.selected_client) |
| 807 |
585 |
{ |
| 808 |
586 |
Some(win) => win, |
| 809 |
587 |
None => return Ok(()), |
|
|
@@ -942,7 +720,7 @@ impl WindowManager { |
| 942 |
720 |
&self.connection, |
| 943 |
721 |
&self.font, |
| 944 |
722 |
self.display, |
| 945 |
|
- monitor.selected_tags, |
|
723 |
+ monitor.tagset[monitor.selected_tags_index], |
| 946 |
724 |
occupied_tags, |
| 947 |
725 |
draw_blocks, |
| 948 |
726 |
&layout_symbol, |
|
|
@@ -968,7 +746,7 @@ impl WindowManager { |
| 968 |
746 |
return false; |
| 969 |
747 |
} |
| 970 |
748 |
if let Some(&tags) = self.window_tags.get(&window) { |
| 971 |
|
- (tags & monitor.selected_tags) != 0 |
|
749 |
+ (tags & monitor.tagset[monitor.selected_tags_index]) != 0 |
| 972 |
750 |
} else { |
| 973 |
751 |
false |
| 974 |
752 |
} |
|
|
@@ -976,7 +754,7 @@ impl WindowManager { |
| 976 |
754 |
.copied() |
| 977 |
755 |
.collect(); |
| 978 |
756 |
|
| 979 |
|
- let focused_window = monitor.focused_window; |
|
757 |
+ let focused_window = monitor.selected_client; |
| 980 |
758 |
|
| 981 |
759 |
tab_bar.draw( |
| 982 |
760 |
&self.connection, |
|
|
@@ -1003,7 +781,7 @@ impl WindowManager { |
| 1003 |
781 |
if let Some(focused) = self |
| 1004 |
782 |
.monitors |
| 1005 |
783 |
.get(self.selected_monitor) |
| 1006 |
|
- .and_then(|m| m.focused_window) |
|
784 |
+ .and_then(|m| m.selected_client) |
| 1007 |
785 |
{ |
| 1008 |
786 |
self.kill_client(focused)?; |
| 1009 |
787 |
} |
|
|
@@ -1045,12 +823,6 @@ impl WindowManager { |
| 1045 |
823 |
self.toggle_floating()?; |
| 1046 |
824 |
} |
| 1047 |
825 |
|
| 1048 |
|
- KeyAction::SmartMoveWin => { |
| 1049 |
|
- if let Arg::Int(direction) = arg { |
| 1050 |
|
- self.smart_move_window(*direction)?; |
| 1051 |
|
- } |
| 1052 |
|
- } |
| 1053 |
|
- |
| 1054 |
826 |
KeyAction::ExchangeClient => { |
| 1055 |
827 |
if let Arg::Int(direction) = arg { |
| 1056 |
828 |
self.exchange_client(*direction)?; |
|
|
@@ -1109,8 +881,8 @@ impl WindowManager { |
| 1109 |
881 |
&self.connection, |
| 1110 |
882 |
&self.font, |
| 1111 |
883 |
&self.config.keybindings, |
| 1112 |
|
- monitor.width as u16, |
| 1113 |
|
- monitor.height as u16, |
|
884 |
+ monitor.screen_width as u16, |
|
885 |
+ monitor.screen_height as u16, |
| 1114 |
886 |
)?; |
| 1115 |
887 |
} |
| 1116 |
888 |
KeyAction::None => {} |
|
|
@@ -1150,7 +922,7 @@ impl WindowManager { |
| 1150 |
922 |
|
| 1151 |
923 |
if let Some(&tags) = self.window_tags.get(&window) { |
| 1152 |
924 |
let monitor = self.monitors.get(window_mon); |
| 1153 |
|
- let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0); |
|
925 |
+ let selected_tags = monitor.map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0); |
| 1154 |
926 |
(tags & selected_tags) != 0 |
| 1155 |
927 |
} else { |
| 1156 |
928 |
false |
|
|
@@ -1158,31 +930,41 @@ impl WindowManager { |
| 1158 |
930 |
} |
| 1159 |
931 |
|
| 1160 |
932 |
fn visible_windows(&self) -> Vec<Window> { |
| 1161 |
|
- self.windows |
| 1162 |
|
- .iter() |
| 1163 |
|
- .filter(|&&w| self.is_window_visible(w)) |
| 1164 |
|
- .copied() |
| 1165 |
|
- .collect() |
|
933 |
+ let mut result = Vec::new(); |
|
934 |
+ for monitor in &self.monitors { |
|
935 |
+ let mut current = monitor.clients_head; |
|
936 |
+ while let Some(window) = current { |
|
937 |
+ if let Some(client) = self.clients.get(&window) { |
|
938 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
939 |
+ if visible_tags != 0 { |
|
940 |
+ result.push(window); |
|
941 |
+ } |
|
942 |
+ current = client.next; |
|
943 |
+ } else { |
|
944 |
+ break; |
|
945 |
+ } |
|
946 |
+ } |
|
947 |
+ } |
|
948 |
+ result |
| 1166 |
949 |
} |
| 1167 |
950 |
|
| 1168 |
951 |
fn visible_windows_on_monitor(&self, monitor_index: usize) -> Vec<Window> { |
| 1169 |
|
- self.windows |
| 1170 |
|
- .iter() |
| 1171 |
|
- .filter(|&&w| { |
| 1172 |
|
- let window_mon = self.window_monitor.get(&w).copied().unwrap_or(0); |
| 1173 |
|
- if window_mon != monitor_index { |
| 1174 |
|
- return false; |
| 1175 |
|
- } |
| 1176 |
|
- if let Some(&tags) = self.window_tags.get(&w) { |
| 1177 |
|
- let monitor = self.monitors.get(monitor_index); |
| 1178 |
|
- let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0); |
| 1179 |
|
- (tags & selected_tags) != 0 |
|
952 |
+ let mut result = Vec::new(); |
|
953 |
+ if let Some(monitor) = self.monitors.get(monitor_index) { |
|
954 |
+ let mut current = monitor.clients_head; |
|
955 |
+ while let Some(window) = current { |
|
956 |
+ if let Some(client) = self.clients.get(&window) { |
|
957 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
958 |
+ if visible_tags != 0 { |
|
959 |
+ result.push(window); |
|
960 |
+ } |
|
961 |
+ current = client.next; |
| 1180 |
962 |
} else { |
| 1181 |
|
- false |
|
963 |
+ break; |
| 1182 |
964 |
} |
| 1183 |
|
- }) |
| 1184 |
|
- .copied() |
| 1185 |
|
- .collect() |
|
965 |
+ } |
|
966 |
+ } |
|
967 |
+ result |
| 1186 |
968 |
} |
| 1187 |
969 |
|
| 1188 |
970 |
fn get_monitor_at_point(&self, x: i32, y: i32) -> Option<usize> { |
|
|
@@ -1215,7 +997,7 @@ impl WindowManager { |
| 1215 |
997 |
} |
| 1216 |
998 |
|
| 1217 |
999 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 1218 |
|
- monitor.selected_tags = tag_mask(tag_index); |
|
1000 |
+ monitor.tagset[monitor.selected_tags_index] = tag_mask(tag_index); |
| 1219 |
1001 |
} |
| 1220 |
1002 |
|
| 1221 |
1003 |
self.save_selected_tags()?; |
|
|
@@ -1237,7 +1019,7 @@ impl WindowManager { |
| 1237 |
1019 |
let selected_tags = self |
| 1238 |
1020 |
.monitors |
| 1239 |
1021 |
.get(self.selected_monitor) |
| 1240 |
|
- .map(|m| m.selected_tags) |
|
1022 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
| 1241 |
1023 |
.unwrap_or(tag_mask(0)); |
| 1242 |
1024 |
let desktop = selected_tags.trailing_zeros(); |
| 1243 |
1025 |
|
|
|
@@ -1264,7 +1046,7 @@ impl WindowManager { |
| 1264 |
1046 |
if let Some(focused) = self |
| 1265 |
1047 |
.monitors |
| 1266 |
1048 |
.get(self.selected_monitor) |
| 1267 |
|
- .and_then(|m| m.focused_window) |
|
1049 |
+ .and_then(|m| m.selected_client) |
| 1268 |
1050 |
{ |
| 1269 |
1051 |
let mask = tag_mask(tag_index); |
| 1270 |
1052 |
self.window_tags.insert(focused, mask); |
|
|
@@ -1291,7 +1073,7 @@ impl WindowManager { |
| 1291 |
1073 |
let current = self |
| 1292 |
1074 |
.monitors |
| 1293 |
1075 |
.get(self.selected_monitor) |
| 1294 |
|
- .and_then(|m| m.focused_window); |
|
1076 |
+ .and_then(|m| m.selected_client); |
| 1295 |
1077 |
|
| 1296 |
1078 |
let next_window = if let Some(current) = current { |
| 1297 |
1079 |
if let Some(current_index) = visible.iter().position(|&w| w == current) { |
|
|
@@ -1373,7 +1155,7 @@ impl WindowManager { |
| 1373 |
1155 |
let focused_window = match self |
| 1374 |
1156 |
.monitors |
| 1375 |
1157 |
.get(self.selected_monitor) |
| 1376 |
|
- .and_then(|monitor| monitor.focused_window) |
|
1158 |
+ .and_then(|monitor| monitor.selected_client) |
| 1377 |
1159 |
{ |
| 1378 |
1160 |
Some(window) => window, |
| 1379 |
1161 |
None => return Ok(()), |
|
|
@@ -1390,7 +1172,7 @@ impl WindowManager { |
| 1390 |
1172 |
let focused_window = match self |
| 1391 |
1173 |
.monitors |
| 1392 |
1174 |
.get(self.selected_monitor) |
| 1393 |
|
- .and_then(|monitor| monitor.focused_window) |
|
1175 |
+ .and_then(|monitor| monitor.selected_client) |
| 1394 |
1176 |
{ |
| 1395 |
1177 |
Some(window) => window, |
| 1396 |
1178 |
None => return Ok(()), |
|
|
@@ -1615,18 +1397,18 @@ impl WindowManager { |
| 1615 |
1397 |
(0, 0) |
| 1616 |
1398 |
}; |
| 1617 |
1399 |
|
| 1618 |
|
- let window_x = monitor.x + outer_gap_h as i32; |
| 1619 |
|
- let window_y = monitor.y + outer_gap_v as i32; |
| 1620 |
|
- let window_width = monitor.width.saturating_sub(2 * outer_gap_h).saturating_sub(2 * border_width); |
| 1621 |
|
- let window_height = monitor.height.saturating_sub(2 * outer_gap_v).saturating_sub(2 * border_width); |
|
1400 |
+ let window_x = monitor.screen_x + outer_gap_h as i32; |
|
1401 |
+ let window_y = monitor.screen_y + outer_gap_v as i32; |
|
1402 |
+ let window_width = monitor.screen_width.saturating_sub(2 * outer_gap_h as i32).saturating_sub(2 * border_width as i32); |
|
1403 |
+ let window_height = monitor.screen_height.saturating_sub(2 * outer_gap_v as i32).saturating_sub(2 * border_width as i32); |
| 1622 |
1404 |
|
| 1623 |
1405 |
self.connection.configure_window( |
| 1624 |
1406 |
window, |
| 1625 |
1407 |
&x11rb::protocol::xproto::ConfigureWindowAux::new() |
| 1626 |
1408 |
.x(window_x) |
| 1627 |
1409 |
.y(window_y) |
| 1628 |
|
- .width(window_width) |
| 1629 |
|
- .height(window_height), |
|
1410 |
+ .width(window_width as u32) |
|
1411 |
+ .height(window_height as u32), |
| 1630 |
1412 |
)?; |
| 1631 |
1413 |
} |
| 1632 |
1414 |
self.connection.flush()?; |
|
|
@@ -1699,6 +1481,9 @@ impl WindowManager { |
| 1699 |
1481 |
)?; |
| 1700 |
1482 |
|
| 1701 |
1483 |
self.fullscreen_windows.insert(window); |
|
1484 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
1485 |
+ client.is_fullscreen = true; |
|
1486 |
+ } |
| 1702 |
1487 |
|
| 1703 |
1488 |
let monitor_idx = *self.window_monitor.get(&window).unwrap_or(&self.selected_monitor); |
| 1704 |
1489 |
let monitor = &self.monitors[monitor_idx]; |
|
|
@@ -1713,10 +1498,10 @@ impl WindowManager { |
| 1713 |
1498 |
window, |
| 1714 |
1499 |
&x11rb::protocol::xproto::ConfigureWindowAux::new() |
| 1715 |
1500 |
.border_width(0) |
| 1716 |
|
- .x(monitor.x) |
| 1717 |
|
- .y(monitor.y) |
| 1718 |
|
- .width(monitor.width as u32) |
| 1719 |
|
- .height(monitor.height as u32) |
|
1501 |
+ .x(monitor.screen_x) |
|
1502 |
+ .y(monitor.screen_y) |
|
1503 |
+ .width(monitor.screen_width as u32) |
|
1504 |
+ .height(monitor.screen_height as u32) |
| 1720 |
1505 |
.stack_mode(x11rb::protocol::xproto::StackMode::ABOVE), |
| 1721 |
1506 |
)?; |
| 1722 |
1507 |
|
|
|
@@ -1734,6 +1519,9 @@ impl WindowManager { |
| 1734 |
1519 |
)?; |
| 1735 |
1520 |
|
| 1736 |
1521 |
self.fullscreen_windows.remove(&window); |
|
1522 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
1523 |
+ client.is_fullscreen = false; |
|
1524 |
+ } |
| 1737 |
1525 |
|
| 1738 |
1526 |
self.connection.configure_window( |
| 1739 |
1527 |
window, |
|
|
@@ -1854,7 +1642,7 @@ impl WindowManager { |
| 1854 |
1642 |
let parent_tags = self.window_tags.get(&parent).copied().unwrap_or_else(|| { |
| 1855 |
1643 |
self.monitors |
| 1856 |
1644 |
.get(self.selected_monitor) |
| 1857 |
|
- .map(|m| m.selected_tags) |
|
1645 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
| 1858 |
1646 |
.unwrap_or(tag_mask(0)) |
| 1859 |
1647 |
}); |
| 1860 |
1648 |
let parent_monitor = self.window_monitor.get(&parent).copied().unwrap_or(self.selected_monitor); |
|
|
@@ -1862,7 +1650,7 @@ impl WindowManager { |
| 1862 |
1650 |
} else { |
| 1863 |
1651 |
let selected_tags = self.monitors |
| 1864 |
1652 |
.get(self.selected_monitor) |
| 1865 |
|
- .map(|m| m.selected_tags) |
|
1653 |
+ .map(|m| m.tagset[m.selected_tags_index]) |
| 1866 |
1654 |
.unwrap_or(tag_mask(0)); |
| 1867 |
1655 |
(selected_tags, self.selected_monitor) |
| 1868 |
1656 |
}; |
|
|
@@ -1870,14 +1658,29 @@ impl WindowManager { |
| 1870 |
1658 |
let monitor = self.monitors[monitor_index].clone(); |
| 1871 |
1659 |
let border_width = self.config.border_width; |
| 1872 |
1660 |
|
| 1873 |
|
- if window_x + (window_width as i32) + (2 * border_width as i32) > monitor.x + monitor.width as i32 { |
| 1874 |
|
- window_x = monitor.x + monitor.width as i32 - (window_width as i32) - (2 * border_width as i32); |
|
1661 |
+ let mut client = Client::new(window, monitor_index, window_tags); |
|
1662 |
+ client.x_position = window_x as i16; |
|
1663 |
+ client.y_position = window_y as i16; |
|
1664 |
+ client.width = window_width as u16; |
|
1665 |
+ client.height = window_height as u16; |
|
1666 |
+ client.old_x_position = window_x as i16; |
|
1667 |
+ client.old_y_position = window_y as i16; |
|
1668 |
+ client.old_width = window_width as u16; |
|
1669 |
+ client.old_height = window_height as u16; |
|
1670 |
+ client.border_width = border_width as u16; |
|
1671 |
+ client.old_border_width = border_width as u16; |
|
1672 |
+ |
|
1673 |
+ self.update_size_hints(&mut client)?; |
|
1674 |
+ self.update_window_title(&mut client)?; |
|
1675 |
+ |
|
1676 |
+ if window_x + (window_width as i32) + (2 * border_width as i32) > monitor.screen_x + monitor.screen_width as i32 { |
|
1677 |
+ window_x = monitor.screen_x + monitor.screen_width as i32 - (window_width as i32) - (2 * border_width as i32); |
| 1875 |
1678 |
} |
| 1876 |
|
- if window_y + (window_height as i32) + (2 * border_width as i32) > monitor.y + monitor.height as i32 { |
| 1877 |
|
- window_y = monitor.y + monitor.height as i32 - (window_height as i32) - (2 * border_width as i32); |
|
1679 |
+ if window_y + (window_height as i32) + (2 * border_width as i32) > monitor.screen_y + monitor.screen_height as i32 { |
|
1680 |
+ window_y = monitor.screen_y + monitor.screen_height as i32 - (window_height as i32) - (2 * border_width as i32); |
| 1878 |
1681 |
} |
| 1879 |
|
- window_x = window_x.max(monitor.x); |
| 1880 |
|
- window_y = window_y.max(monitor.y); |
|
1682 |
+ window_x = window_x.max(monitor.screen_x); |
|
1683 |
+ window_y = window_y.max(monitor.screen_y); |
| 1881 |
1684 |
|
| 1882 |
1685 |
let is_transient = transient_parent.is_some(); |
| 1883 |
1686 |
let is_dialog = self.is_dialog_window(window); |
|
|
@@ -1905,6 +1708,12 @@ impl WindowManager { |
| 1905 |
1708 |
), |
| 1906 |
1709 |
)?; |
| 1907 |
1710 |
|
|
1711 |
+ client.is_floating = is_transient || is_dialog; |
|
1712 |
+ |
|
1713 |
+ self.clients.insert(window, client); |
|
1714 |
+ self.attach(window, monitor_index); |
|
1715 |
+ self.attach_stack(window, monitor_index); |
|
1716 |
+ |
| 1908 |
1717 |
self.windows.push(window); |
| 1909 |
1718 |
self.window_tags.insert(window, window_tags); |
| 1910 |
1719 |
self.window_monitor.insert(window, monitor_index); |
|
|
@@ -1918,13 +1727,13 @@ impl WindowManager { |
| 1918 |
1727 |
let parent_center_y = parent_geom.y as i32 + (parent_geom.height as i32 / 2); |
| 1919 |
1728 |
(parent_center_x, parent_center_y) |
| 1920 |
1729 |
} else { |
| 1921 |
|
- let monitor_center_x = monitor.x + (monitor.width as i32 / 2); |
| 1922 |
|
- let monitor_center_y = monitor.y + (monitor.height as i32 / 2); |
|
1730 |
+ let monitor_center_x = monitor.screen_x + (monitor.screen_width as i32 / 2); |
|
1731 |
+ let monitor_center_y = monitor.screen_y + (monitor.screen_height as i32 / 2); |
| 1923 |
1732 |
(monitor_center_x, monitor_center_y) |
| 1924 |
1733 |
} |
| 1925 |
1734 |
} else { |
| 1926 |
|
- let monitor_center_x = monitor.x + (monitor.width as i32 / 2); |
| 1927 |
|
- let monitor_center_y = monitor.y + (monitor.height as i32 / 2); |
|
1735 |
+ let monitor_center_x = monitor.screen_x + (monitor.screen_width as i32 / 2); |
|
1736 |
+ let monitor_center_y = monitor.screen_y + (monitor.screen_height as i32 / 2); |
| 1928 |
1737 |
(monitor_center_x, monitor_center_y) |
| 1929 |
1738 |
}; |
| 1930 |
1739 |
|
|
|
@@ -1932,11 +1741,11 @@ impl WindowManager { |
| 1932 |
1741 |
let positioned_y = center_y - (window_height as i32 / 2); |
| 1933 |
1742 |
|
| 1934 |
1743 |
let clamped_x = positioned_x |
| 1935 |
|
- .max(monitor.x) |
| 1936 |
|
- .min(monitor.x + monitor.width as i32 - window_width as i32); |
|
1744 |
+ .max(monitor.screen_x) |
|
1745 |
+ .min(monitor.screen_x + monitor.screen_width as i32 - window_width as i32); |
| 1937 |
1746 |
let clamped_y = positioned_y |
| 1938 |
|
- .max(monitor.y) |
| 1939 |
|
- .min(monitor.y + monitor.height as i32 - window_height as i32); |
|
1747 |
+ .max(monitor.screen_y) |
|
1748 |
+ .min(monitor.screen_y + monitor.screen_height as i32 - window_height as i32); |
| 1940 |
1749 |
|
| 1941 |
1750 |
self.update_geometry_cache(window, CachedGeometry { |
| 1942 |
1751 |
x_position: clamped_x as i16, |
|
|
@@ -1965,17 +1774,17 @@ impl WindowManager { |
| 1965 |
1774 |
.and_then(|idx| self.monitors.get(idx)) |
| 1966 |
1775 |
.unwrap_or(&monitor); |
| 1967 |
1776 |
|
| 1968 |
|
- let float_width = (cursor_monitor.width as f32 * 0.6) as u32; |
| 1969 |
|
- let float_height = (cursor_monitor.height as f32 * 0.6) as u32; |
|
1777 |
+ let float_width = (cursor_monitor.screen_width as f32 * 0.6) as u32; |
|
1778 |
+ let float_height = (cursor_monitor.screen_height as f32 * 0.6) as u32; |
| 1970 |
1779 |
let spawn_x = pointer.root_x as i32 - (float_width as i32 / 2); |
| 1971 |
1780 |
let spawn_y = pointer.root_y as i32 - (float_height as i32 / 2); |
| 1972 |
1781 |
|
| 1973 |
1782 |
let clamped_x = spawn_x |
| 1974 |
|
- .max(cursor_monitor.x) |
| 1975 |
|
- .min(cursor_monitor.x + cursor_monitor.width as i32 - float_width as i32); |
|
1783 |
+ .max(cursor_monitor.screen_x) |
|
1784 |
+ .min(cursor_monitor.screen_x + cursor_monitor.screen_width as i32 - float_width as i32); |
| 1976 |
1785 |
let clamped_y = spawn_y |
| 1977 |
|
- .max(cursor_monitor.y) |
| 1978 |
|
- .min(cursor_monitor.y + cursor_monitor.height as i32 - float_height as i32); |
|
1786 |
+ .max(cursor_monitor.screen_y) |
|
1787 |
+ .min(cursor_monitor.screen_y + cursor_monitor.screen_height as i32 - float_height as i32); |
| 1979 |
1788 |
|
| 1980 |
1789 |
self.connection.configure_window( |
| 1981 |
1790 |
window, |
|
|
@@ -1988,6 +1797,9 @@ impl WindowManager { |
| 1988 |
1797 |
.stack_mode(StackMode::ABOVE), |
| 1989 |
1798 |
)?; |
| 1990 |
1799 |
|
|
1800 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
1801 |
+ client.is_floating = true; |
|
1802 |
+ } |
| 1991 |
1803 |
self.floating_windows.insert(window); |
| 1992 |
1804 |
} |
| 1993 |
1805 |
} |
|
|
@@ -2013,7 +1825,7 @@ impl WindowManager { |
| 2013 |
1825 |
let old_focused = self.previous_focused; |
| 2014 |
1826 |
|
| 2015 |
1827 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 2016 |
|
- monitor.focused_window = Some(window); |
|
1828 |
+ monitor.selected_client = Some(window); |
| 2017 |
1829 |
} |
| 2018 |
1830 |
|
| 2019 |
1831 |
self.connection |
|
|
@@ -2410,7 +2222,7 @@ impl WindowManager { |
| 2410 |
2222 |
{ |
| 2411 |
2223 |
return false; |
| 2412 |
2224 |
} |
| 2413 |
|
- let monitor_tags = self.monitors.get(monitor_index).map(|m| m.selected_tags).unwrap_or(0); |
|
2225 |
+ let monitor_tags = self.monitors.get(monitor_index).map(|m| m.tagset[m.selected_tags_index]).unwrap_or(0); |
| 2414 |
2226 |
if let Some(&tags) = self.window_tags.get(&window) { |
| 2415 |
2227 |
(tags & monitor_tags) != 0 |
| 2416 |
2228 |
} else { |
|
|
@@ -2474,18 +2286,18 @@ impl WindowManager { |
| 2474 |
2286 |
|
| 2475 |
2287 |
if value_mask.contains(ConfigWindow::X) { |
| 2476 |
2288 |
let mut x = event.x as i32; |
| 2477 |
|
- x = x.max(monitor.x); |
| 2478 |
|
- if x + event.width as i32 + 2 * border_width as i32 > monitor.x + monitor.width as i32 { |
| 2479 |
|
- x = monitor.x + monitor.width as i32 - event.width as i32 - 2 * border_width as i32; |
|
2289 |
+ x = x.max(monitor.screen_x); |
|
2290 |
+ if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 { |
|
2291 |
+ x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32; |
| 2480 |
2292 |
} |
| 2481 |
2293 |
config = config.x(x); |
| 2482 |
2294 |
} |
| 2483 |
2295 |
|
| 2484 |
2296 |
if value_mask.contains(ConfigWindow::Y) { |
| 2485 |
2297 |
let mut y = event.y as i32; |
| 2486 |
|
- y = y.max(monitor.y); |
| 2487 |
|
- if y + event.height as i32 + 2 * border_width as i32 > monitor.y + monitor.height as i32 { |
| 2488 |
|
- y = monitor.y + monitor.height as i32 - event.height as i32 - 2 * border_width as i32; |
|
2298 |
+ y = y.max(monitor.screen_y); |
|
2299 |
+ if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 { |
|
2300 |
+ y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32; |
| 2489 |
2301 |
} |
| 2490 |
2302 |
config = config.y(y); |
| 2491 |
2303 |
} |
|
|
@@ -2510,9 +2322,9 @@ impl WindowManager { |
| 2510 |
2322 |
|
| 2511 |
2323 |
let final_x = if value_mask.contains(ConfigWindow::X) { |
| 2512 |
2324 |
let mut x = event.x as i32; |
| 2513 |
|
- x = x.max(monitor.x); |
| 2514 |
|
- if x + event.width as i32 + 2 * border_width as i32 > monitor.x + monitor.width as i32 { |
| 2515 |
|
- x = monitor.x + monitor.width as i32 - event.width as i32 - 2 * border_width as i32; |
|
2325 |
+ x = x.max(monitor.screen_x); |
|
2326 |
+ if x + event.width as i32 + 2 * border_width as i32 > monitor.screen_x + monitor.screen_width as i32 { |
|
2327 |
+ x = monitor.screen_x + monitor.screen_width as i32 - event.width as i32 - 2 * border_width as i32; |
| 2516 |
2328 |
} |
| 2517 |
2329 |
x as i16 |
| 2518 |
2330 |
} else { |
|
|
@@ -2521,9 +2333,9 @@ impl WindowManager { |
| 2521 |
2333 |
|
| 2522 |
2334 |
let final_y = if value_mask.contains(ConfigWindow::Y) { |
| 2523 |
2335 |
let mut y = event.y as i32; |
| 2524 |
|
- y = y.max(monitor.y); |
| 2525 |
|
- if y + event.height as i32 + 2 * border_width as i32 > monitor.y + monitor.height as i32 { |
| 2526 |
|
- y = monitor.y + monitor.height as i32 - event.height as i32 - 2 * border_width as i32; |
|
2336 |
+ y = y.max(monitor.screen_y); |
|
2337 |
+ if y + event.height as i32 + 2 * border_width as i32 > monitor.screen_y + monitor.screen_height as i32 { |
|
2338 |
+ y = monitor.screen_y + monitor.screen_height as i32 - event.height as i32 - 2 * border_width as i32; |
| 2527 |
2339 |
} |
| 2528 |
2340 |
y as i16 |
| 2529 |
2341 |
} else { |
|
|
@@ -2606,31 +2418,21 @@ impl WindowManager { |
| 2606 |
2418 |
} |
| 2607 |
2419 |
}; |
| 2608 |
2420 |
|
| 2609 |
|
- let monitor_selected_tags = monitor.selected_tags; |
| 2610 |
|
- let monitor_x = monitor.x; |
| 2611 |
|
- let monitor_y = monitor.y; |
| 2612 |
|
- let monitor_width = monitor.width; |
| 2613 |
|
- let monitor_height = monitor.height; |
| 2614 |
|
- |
| 2615 |
|
- let visible: Vec<Window> = self |
| 2616 |
|
- .windows |
| 2617 |
|
- .iter() |
| 2618 |
|
- .filter(|&&window| { |
| 2619 |
|
- let window_monitor_index = self.window_monitor.get(&window).copied().unwrap_or(0); |
| 2620 |
|
- if window_monitor_index != monitor_index |
| 2621 |
|
- || self.floating_windows.contains(&window) |
| 2622 |
|
- || self.fullscreen_windows.contains(&window) |
| 2623 |
|
- { |
| 2624 |
|
- return false; |
| 2625 |
|
- } |
| 2626 |
|
- if let Some(&tags) = self.window_tags.get(&window) { |
| 2627 |
|
- (tags & monitor_selected_tags) != 0 |
| 2628 |
|
- } else { |
| 2629 |
|
- false |
| 2630 |
|
- } |
| 2631 |
|
- }) |
| 2632 |
|
- .copied() |
| 2633 |
|
- .collect(); |
|
2421 |
+ let monitor_x = monitor.screen_x; |
|
2422 |
+ let monitor_y = monitor.screen_y; |
|
2423 |
+ let monitor_width = monitor.screen_width; |
|
2424 |
+ let monitor_height = monitor.screen_height; |
|
2425 |
+ |
|
2426 |
+ let mut visible: Vec<Window> = Vec::new(); |
|
2427 |
+ let mut current = self.next_tiled(monitor.clients_head, monitor); |
|
2428 |
+ while let Some(window) = current { |
|
2429 |
+ visible.push(window); |
|
2430 |
+ if let Some(client) = self.clients.get(&window) { |
|
2431 |
+ current = self.next_tiled(client.next, monitor); |
|
2432 |
+ } else { |
|
2433 |
+ break; |
|
2434 |
+ } |
|
2435 |
+ } |
| 2634 |
2436 |
|
| 2635 |
2437 |
let bar_height = if self.show_bar { |
| 2636 |
2438 |
self.bars |
|
|
@@ -2640,11 +2442,11 @@ impl WindowManager { |
| 2640 |
2442 |
} else { |
| 2641 |
2443 |
0 |
| 2642 |
2444 |
}; |
| 2643 |
|
- let usable_height = monitor_height.saturating_sub(bar_height); |
|
2445 |
+ let usable_height = monitor_height.saturating_sub(bar_height as i32); |
| 2644 |
2446 |
|
| 2645 |
2447 |
let geometries = self |
| 2646 |
2448 |
.layout |
| 2647 |
|
- .arrange(&visible, monitor_width, usable_height, &gaps); |
|
2449 |
+ .arrange(&visible, monitor_width as u32, usable_height as u32, &gaps); |
| 2648 |
2450 |
|
| 2649 |
2451 |
for (window, geometry) in visible.iter().zip(geometries.iter()) { |
| 2650 |
2452 |
let adjusted_width = geometry.width.saturating_sub(2 * border_width); |
|
|
@@ -2700,9 +2502,9 @@ impl WindowManager { |
| 2700 |
2502 |
0.0 |
| 2701 |
2503 |
}; |
| 2702 |
2504 |
|
| 2703 |
|
- let tab_bar_x = (monitor.x + outer_horizontal as i32) as i16; |
| 2704 |
|
- let tab_bar_y = (monitor.y as f32 + bar_height + outer_vertical as f32) as i16; |
| 2705 |
|
- let tab_bar_width = monitor.width.saturating_sub(2 * outer_horizontal) as u16; |
|
2505 |
+ let tab_bar_x = (monitor.screen_x + outer_horizontal as i32) as i16; |
|
2506 |
+ let tab_bar_y = (monitor.screen_y as f32 + bar_height + outer_vertical as f32) as i16; |
|
2507 |
+ let tab_bar_width = monitor.screen_width.saturating_sub(2 * outer_horizontal as i32) as u16; |
| 2706 |
2508 |
|
| 2707 |
2509 |
if let Err(e) = self.tab_bars[monitor_index].reposition( |
| 2708 |
2510 |
&self.connection, |
|
|
@@ -2730,7 +2532,7 @@ impl WindowManager { |
| 2730 |
2532 |
} |
| 2731 |
2533 |
if let Some(monitor) = self.monitors.get(monitor_index) { |
| 2732 |
2534 |
if let Some(&tags) = self.window_tags.get(&window) { |
| 2733 |
|
- return (tags & monitor.selected_tags) != 0; |
|
2535 |
+ return (tags & monitor.tagset[monitor.selected_tags_index]) != 0; |
| 2734 |
2536 |
} |
| 2735 |
2537 |
} |
| 2736 |
2538 |
false |
|
|
@@ -2812,9 +2614,300 @@ impl WindowManager { |
| 2812 |
2614 |
Ok(()) |
| 2813 |
2615 |
} |
| 2814 |
2616 |
|
|
2617 |
+ fn update_size_hints(&mut self, client: &mut Client) -> WmResult<()> { |
|
2618 |
+ let size_hints = self.connection |
|
2619 |
+ .get_property( |
|
2620 |
+ false, |
|
2621 |
+ client.window, |
|
2622 |
+ x11rb::protocol::xproto::AtomEnum::WM_NORMAL_HINTS, |
|
2623 |
+ x11rb::protocol::xproto::AtomEnum::WM_SIZE_HINTS, |
|
2624 |
+ 0, |
|
2625 |
+ 18, |
|
2626 |
+ )? |
|
2627 |
+ .reply()?; |
|
2628 |
+ |
|
2629 |
+ if size_hints.value.is_empty() { |
|
2630 |
+ client.hints_valid = false; |
|
2631 |
+ return Ok(()); |
|
2632 |
+ } |
|
2633 |
+ |
|
2634 |
+ if size_hints.value.len() < 18 * 4 { |
|
2635 |
+ client.hints_valid = false; |
|
2636 |
+ return Ok(()); |
|
2637 |
+ } |
|
2638 |
+ |
|
2639 |
+ let read_u32 = |offset: usize| -> u32 { |
|
2640 |
+ let bytes = &size_hints.value[offset * 4..(offset + 1) * 4]; |
|
2641 |
+ u32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]) |
|
2642 |
+ }; |
|
2643 |
+ |
|
2644 |
+ let flags = read_u32(0); |
|
2645 |
+ |
|
2646 |
+ const P_SIZE: u32 = 1 << 3; |
|
2647 |
+ const P_MIN_SIZE: u32 = 1 << 4; |
|
2648 |
+ const P_MAX_SIZE: u32 = 1 << 5; |
|
2649 |
+ const P_RESIZE_INC: u32 = 1 << 6; |
|
2650 |
+ const P_ASPECT: u32 = 1 << 7; |
|
2651 |
+ const P_BASE_SIZE: u32 = 1 << 8; |
|
2652 |
+ |
|
2653 |
+ if flags & P_BASE_SIZE != 0 { |
|
2654 |
+ client.base_width = read_u32(8) as i32; |
|
2655 |
+ client.base_height = read_u32(9) as i32; |
|
2656 |
+ } else if flags & P_MIN_SIZE != 0 { |
|
2657 |
+ client.base_width = read_u32(5) as i32; |
|
2658 |
+ client.base_height = read_u32(6) as i32; |
|
2659 |
+ } else { |
|
2660 |
+ client.base_width = 0; |
|
2661 |
+ client.base_height = 0; |
|
2662 |
+ } |
|
2663 |
+ |
|
2664 |
+ if flags & P_RESIZE_INC != 0 { |
|
2665 |
+ client.increment_width = read_u32(10) as i32; |
|
2666 |
+ client.increment_height = read_u32(11) as i32; |
|
2667 |
+ } else { |
|
2668 |
+ client.increment_width = 0; |
|
2669 |
+ client.increment_height = 0; |
|
2670 |
+ } |
|
2671 |
+ |
|
2672 |
+ if flags & P_MAX_SIZE != 0 { |
|
2673 |
+ client.max_width = read_u32(7) as i32; |
|
2674 |
+ client.max_height = read_u32(8) as i32; |
|
2675 |
+ } else { |
|
2676 |
+ client.max_width = 0; |
|
2677 |
+ client.max_height = 0; |
|
2678 |
+ } |
|
2679 |
+ |
|
2680 |
+ if flags & P_MIN_SIZE != 0 { |
|
2681 |
+ client.min_width = read_u32(5) as i32; |
|
2682 |
+ client.min_height = read_u32(6) as i32; |
|
2683 |
+ } else if flags & P_SIZE != 0 { |
|
2684 |
+ client.min_width = read_u32(3) as i32; |
|
2685 |
+ client.min_height = read_u32(4) as i32; |
|
2686 |
+ } else { |
|
2687 |
+ client.min_width = 0; |
|
2688 |
+ client.min_height = 0; |
|
2689 |
+ } |
|
2690 |
+ |
|
2691 |
+ if flags & P_ASPECT != 0 { |
|
2692 |
+ client.min_aspect = (read_u32(12) as f32) / (read_u32(13) as f32).max(1.0); |
|
2693 |
+ client.max_aspect = (read_u32(14) as f32) / (read_u32(15) as f32).max(1.0); |
|
2694 |
+ } else { |
|
2695 |
+ client.min_aspect = 0.0; |
|
2696 |
+ client.max_aspect = 0.0; |
|
2697 |
+ } |
|
2698 |
+ |
|
2699 |
+ client.is_fixed = client.max_width > 0 |
|
2700 |
+ && client.max_height > 0 |
|
2701 |
+ && client.max_width == client.min_width |
|
2702 |
+ && client.max_height == client.min_height; |
|
2703 |
+ |
|
2704 |
+ client.hints_valid = true; |
|
2705 |
+ Ok(()) |
|
2706 |
+ } |
|
2707 |
+ |
|
2708 |
+ fn update_window_title(&mut self, client: &mut Client) -> WmResult<()> { |
|
2709 |
+ let name = self.connection |
|
2710 |
+ .get_property( |
|
2711 |
+ false, |
|
2712 |
+ client.window, |
|
2713 |
+ x11rb::protocol::xproto::AtomEnum::WM_NAME, |
|
2714 |
+ x11rb::protocol::xproto::AtomEnum::STRING, |
|
2715 |
+ 0, |
|
2716 |
+ 256, |
|
2717 |
+ )? |
|
2718 |
+ .reply()?; |
|
2719 |
+ |
|
2720 |
+ if !name.value.is_empty() { |
|
2721 |
+ if let Ok(title) = String::from_utf8(name.value.clone()) { |
|
2722 |
+ client.name = title; |
|
2723 |
+ } |
|
2724 |
+ } |
|
2725 |
+ |
|
2726 |
+ Ok(()) |
|
2727 |
+ } |
|
2728 |
+ |
|
2729 |
+ fn apply_size_hints(&self, client: &Client, mut width: i32, mut height: i32) -> (i32, i32) { |
|
2730 |
+ if !client.hints_valid { |
|
2731 |
+ return (width.max(1), height.max(1)); |
|
2732 |
+ } |
|
2733 |
+ |
|
2734 |
+ if client.min_width > 0 { |
|
2735 |
+ width = width.max(client.min_width); |
|
2736 |
+ } |
|
2737 |
+ if client.min_height > 0 { |
|
2738 |
+ height = height.max(client.min_height); |
|
2739 |
+ } |
|
2740 |
+ |
|
2741 |
+ if client.max_width > 0 { |
|
2742 |
+ width = width.min(client.max_width); |
|
2743 |
+ } |
|
2744 |
+ if client.max_height > 0 { |
|
2745 |
+ height = height.min(client.max_height); |
|
2746 |
+ } |
|
2747 |
+ |
|
2748 |
+ if client.increment_width > 0 { |
|
2749 |
+ width -= client.base_width; |
|
2750 |
+ width -= width % client.increment_width; |
|
2751 |
+ width += client.base_width; |
|
2752 |
+ } |
|
2753 |
+ if client.increment_height > 0 { |
|
2754 |
+ height -= client.base_height; |
|
2755 |
+ height -= height % client.increment_height; |
|
2756 |
+ height += client.base_height; |
|
2757 |
+ } |
|
2758 |
+ |
|
2759 |
+ if client.min_aspect > 0.0 || client.max_aspect > 0.0 { |
|
2760 |
+ let actual_aspect = width as f32 / height as f32; |
|
2761 |
+ |
|
2762 |
+ if client.max_aspect > 0.0 && actual_aspect > client.max_aspect { |
|
2763 |
+ width = (height as f32 * client.max_aspect) as i32; |
|
2764 |
+ } else if client.min_aspect > 0.0 && actual_aspect < client.min_aspect { |
|
2765 |
+ height = (width as f32 / client.min_aspect) as i32; |
|
2766 |
+ } |
|
2767 |
+ } |
|
2768 |
+ |
|
2769 |
+ (width.max(1), height.max(1)) |
|
2770 |
+ } |
|
2771 |
+ |
|
2772 |
+ fn next_tiled(&self, start: Option<Window>, monitor: &Monitor) -> Option<Window> { |
|
2773 |
+ let mut current = start; |
|
2774 |
+ while let Some(window) = current { |
|
2775 |
+ if let Some(client) = self.clients.get(&window) { |
|
2776 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
2777 |
+ if visible_tags != 0 && !client.is_floating { |
|
2778 |
+ return Some(window); |
|
2779 |
+ } |
|
2780 |
+ current = client.next; |
|
2781 |
+ } else { |
|
2782 |
+ break; |
|
2783 |
+ } |
|
2784 |
+ } |
|
2785 |
+ None |
|
2786 |
+ } |
|
2787 |
+ |
|
2788 |
+ fn count_tiled(&self, monitor: &Monitor) -> usize { |
|
2789 |
+ let mut count = 0; |
|
2790 |
+ let mut current = monitor.clients_head; |
|
2791 |
+ while let Some(window) = current { |
|
2792 |
+ if let Some(client) = self.clients.get(&window) { |
|
2793 |
+ let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index]; |
|
2794 |
+ if visible_tags != 0 && !client.is_floating { |
|
2795 |
+ count += 1; |
|
2796 |
+ } |
|
2797 |
+ current = client.next; |
|
2798 |
+ } else { |
|
2799 |
+ break; |
|
2800 |
+ } |
|
2801 |
+ } |
|
2802 |
+ count |
|
2803 |
+ } |
|
2804 |
+ |
|
2805 |
+ fn attach(&mut self, window: Window, monitor_index: usize) { |
|
2806 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
2807 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
2808 |
+ client.next = monitor.clients_head; |
|
2809 |
+ monitor.clients_head = Some(window); |
|
2810 |
+ } |
|
2811 |
+ } |
|
2812 |
+ } |
|
2813 |
+ |
|
2814 |
+ fn detach(&mut self, window: Window) { |
|
2815 |
+ let monitor_index = self.clients.get(&window).map(|c| c.monitor_index); |
|
2816 |
+ if let Some(monitor_index) = monitor_index { |
|
2817 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
2818 |
+ if monitor.clients_head == Some(window) { |
|
2819 |
+ if let Some(client) = self.clients.get(&window) { |
|
2820 |
+ monitor.clients_head = client.next; |
|
2821 |
+ } |
|
2822 |
+ } else { |
|
2823 |
+ let mut current = monitor.clients_head; |
|
2824 |
+ while let Some(current_window) = current { |
|
2825 |
+ if let Some(current_client) = self.clients.get(¤t_window) { |
|
2826 |
+ if current_client.next == Some(window) { |
|
2827 |
+ let new_next = self.clients.get(&window).and_then(|c| c.next); |
|
2828 |
+ if let Some(current_client_mut) = self.clients.get_mut(¤t_window) { |
|
2829 |
+ current_client_mut.next = new_next; |
|
2830 |
+ } |
|
2831 |
+ break; |
|
2832 |
+ } |
|
2833 |
+ current = current_client.next; |
|
2834 |
+ } else { |
|
2835 |
+ break; |
|
2836 |
+ } |
|
2837 |
+ } |
|
2838 |
+ } |
|
2839 |
+ } |
|
2840 |
+ } |
|
2841 |
+ } |
|
2842 |
+ |
|
2843 |
+ fn attach_stack(&mut self, window: Window, monitor_index: usize) { |
|
2844 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
2845 |
+ if let Some(client) = self.clients.get_mut(&window) { |
|
2846 |
+ client.stack_next = monitor.stack_head; |
|
2847 |
+ monitor.stack_head = Some(window); |
|
2848 |
+ } |
|
2849 |
+ } |
|
2850 |
+ } |
|
2851 |
+ |
|
2852 |
+ fn detach_stack(&mut self, window: Window) { |
|
2853 |
+ let monitor_index = self.clients.get(&window).map(|c| c.monitor_index); |
|
2854 |
+ if let Some(monitor_index) = monitor_index { |
|
2855 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
2856 |
+ if monitor.stack_head == Some(window) { |
|
2857 |
+ if let Some(client) = self.clients.get(&window) { |
|
2858 |
+ monitor.stack_head = client.stack_next; |
|
2859 |
+ } |
|
2860 |
+ let should_update_selected = monitor.selected_client == Some(window); |
|
2861 |
+ let mut new_selected: Option<Window> = None; |
|
2862 |
+ if should_update_selected { |
|
2863 |
+ let mut stack_current = monitor.stack_head; |
|
2864 |
+ while let Some(stack_window) = stack_current { |
|
2865 |
+ if let Some(stack_client) = self.clients.get(&stack_window) { |
|
2866 |
+ if self.is_window_visible(stack_window) { |
|
2867 |
+ new_selected = Some(stack_window); |
|
2868 |
+ break; |
|
2869 |
+ } |
|
2870 |
+ stack_current = stack_client.stack_next; |
|
2871 |
+ } else { |
|
2872 |
+ break; |
|
2873 |
+ } |
|
2874 |
+ } |
|
2875 |
+ } |
|
2876 |
+ if should_update_selected { |
|
2877 |
+ if let Some(monitor) = self.monitors.get_mut(monitor_index) { |
|
2878 |
+ monitor.selected_client = new_selected; |
|
2879 |
+ } |
|
2880 |
+ } |
|
2881 |
+ } else { |
|
2882 |
+ let mut current = monitor.stack_head; |
|
2883 |
+ while let Some(current_window) = current { |
|
2884 |
+ if let Some(current_client) = self.clients.get(¤t_window) { |
|
2885 |
+ if current_client.stack_next == Some(window) { |
|
2886 |
+ let new_stack_next = self.clients.get(&window).and_then(|c| c.stack_next); |
|
2887 |
+ if let Some(current_client_mut) = self.clients.get_mut(¤t_window) { |
|
2888 |
+ current_client_mut.stack_next = new_stack_next; |
|
2889 |
+ } |
|
2890 |
+ break; |
|
2891 |
+ } |
|
2892 |
+ current = current_client.stack_next; |
|
2893 |
+ } else { |
|
2894 |
+ break; |
|
2895 |
+ } |
|
2896 |
+ } |
|
2897 |
+ } |
|
2898 |
+ } |
|
2899 |
+ } |
|
2900 |
+ } |
|
2901 |
+ |
| 2815 |
2902 |
fn remove_window(&mut self, window: Window) -> WmResult<()> { |
| 2816 |
2903 |
let initial_count = self.windows.len(); |
| 2817 |
2904 |
|
|
2905 |
+ if self.clients.contains_key(&window) { |
|
2906 |
+ self.detach(window); |
|
2907 |
+ self.detach_stack(window); |
|
2908 |
+ self.clients.remove(&window); |
|
2909 |
+ } |
|
2910 |
+ |
| 2818 |
2911 |
self.windows.retain(|&w| w != window); |
| 2819 |
2912 |
self.window_tags.remove(&window); |
| 2820 |
2913 |
self.window_monitor.remove(&window); |
|
|
@@ -2825,13 +2918,13 @@ impl WindowManager { |
| 2825 |
2918 |
let focused = self |
| 2826 |
2919 |
.monitors |
| 2827 |
2920 |
.get(self.selected_monitor) |
| 2828 |
|
- .and_then(|m| m.focused_window); |
|
2921 |
+ .and_then(|m| m.selected_client); |
| 2829 |
2922 |
if focused == Some(window) { |
| 2830 |
2923 |
let visible = self.visible_windows_on_monitor(self.selected_monitor); |
| 2831 |
2924 |
if let Some(&new_win) = visible.last() { |
| 2832 |
2925 |
self.set_focus(new_win)?; |
| 2833 |
2926 |
} else if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 2834 |
|
- monitor.focused_window = None; |
|
2927 |
+ monitor.selected_client = None; |
| 2835 |
2928 |
} |
| 2836 |
2929 |
} |
| 2837 |
2930 |
|