tony / oxwm

Updated monitor logic Browse files
tonybtw committed 2025-10-18 parent 84c9fb0 commit e4b558653dff24dc1bd91976e443bf892adaa1de
Showing 2 changed files with 58 additions and 20 deletions. UnifiedSplit
+2 −1 src/bar/bar.rs
@@ -177,6 +177,7 @@ impl Bar {
177 177 connection: &RustConnection,
178 178 current_tags: u32,
179 179 occupied_tags: u32,
180 + draw_blocks: bool,
180 181 ) -> Result<(), X11Error> {
181 182 if !self.needs_redraw {
182 183 return Ok(());
@@ -252,7 +253,7 @@ impl Bar {
252 253 x_position += tag_width as i16;
253 254 }
254 255
255 - if !self.status_text.is_empty() {
256 + if draw_blocks && !self.status_text.is_empty() {
256 257 let padding = 10;
257 258 let mut x_position = self.width as i16 - padding;
258 259
+56 −19 src/window_manager.rs
@@ -63,7 +63,8 @@ impl WindowManager {
63 63 | EventMask::SUBSTRUCTURE_NOTIFY
64 64 | EventMask::PROPERTY_CHANGE
65 65 | EventMask::KEY_PRESS
66 - | EventMask::BUTTON_PRESS,
66 + | EventMask::BUTTON_PRESS
67 + | EventMask::POINTER_MOTION,
67 68 ),
68 69 )?
69 70 .check()?;
@@ -323,7 +324,7 @@ impl WindowManager {
323 324 self.update_bar()?;
324 325
325 326 loop {
326 - for bar in &mut self.bars {
327 + if let Some(bar) = self.bars.get_mut(self.selected_monitor) {
327 328 bar.update_blocks();
328 329 }
329 330
@@ -399,17 +400,18 @@ impl WindowManager {
399 400 }
400 401
401 402 fn update_bar(&mut self) -> WmResult<()> {
402 - for (mon_idx, monitor) in self.monitors.iter().enumerate() {
403 - if let Some(bar) = self.bars.get_mut(mon_idx) {
403 + for (monitor_index, monitor) in self.monitors.iter().enumerate() {
404 + if let Some(bar) = self.bars.get_mut(monitor_index) {
404 405 let mut occupied_tags: TagMask = 0;
405 406 for (&window, &tags) in &self.window_tags {
406 - if self.window_monitor.get(&window).copied().unwrap_or(0) == mon_idx {
407 + if self.window_monitor.get(&window).copied().unwrap_or(0) == monitor_index {
407 408 occupied_tags |= tags;
408 409 }
409 410 }
410 411
412 + let draw_blocks = monitor_index == self.selected_monitor;
411 413 bar.invalidate();
412 - bar.draw(&self.connection, monitor.selected_tags, occupied_tags)?;
414 + bar.draw(&self.connection, monitor.selected_tags, occupied_tags, draw_blocks)?;
413 415 }
414 416 }
415 417 Ok(())
@@ -495,11 +497,9 @@ impl WindowManager {
495 497
496 498 self.selected_monitor = new_monitor;
497 499
498 - self.update_window_visibility()?;
499 - self.apply_layout()?;
500 500 self.update_bar()?;
501 501
502 - let visible = self.visible_windows();
502 + let visible = self.visible_windows_on_monitor(new_monitor);
503 503 if let Some(&win) = visible.first() {
504 504 self.set_focus(win)?;
505 505 }
@@ -509,12 +509,10 @@ impl WindowManager {
509 509
510 510 fn is_window_visible(&self, window: Window) -> bool {
511 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 512
516 513 if let Some(&tags) = self.window_tags.get(&window) {
517 - let selected_tags = self.monitors.get(self.selected_monitor).map(|m| m.selected_tags).unwrap_or(0);
514 + let monitor = self.monitors.get(window_mon);
515 + let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0);
518 516 (tags & selected_tags) != 0
519 517 } else {
520 518 false
@@ -529,6 +527,32 @@ impl WindowManager {
529 527 .collect()
530 528 }
531 529
530 + fn visible_windows_on_monitor(&self, monitor_index: usize) -> Vec<Window> {
531 + self.windows
532 + .iter()
533 + .filter(|&&w| {
534 + let window_mon = self.window_monitor.get(&w).copied().unwrap_or(0);
535 + if window_mon != monitor_index {
536 + return false;
537 + }
538 + if let Some(&tags) = self.window_tags.get(&w) {
539 + let monitor = self.monitors.get(monitor_index);
540 + let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0);
541 + (tags & selected_tags) != 0
542 + } else {
543 + false
544 + }
545 + })
546 + .copied()
547 + .collect()
548 + }
549 +
550 + fn get_monitor_at_point(&self, x: i32, y: i32) -> Option<usize> {
551 + self.monitors
552 + .iter()
553 + .position(|mon| mon.contains_point(x, y))
554 + }
555 +
532 556 fn update_window_visibility(&self) -> WmResult<()> {
533 557 for &window in &self.windows {
534 558 if self.is_window_visible(window) {
@@ -849,6 +873,19 @@ impl WindowManager {
849 873 self.set_focus(event.event)?;
850 874 }
851 875 }
876 + Event::MotionNotify(event) => {
877 + if let Some(monitor_index) = self.get_monitor_at_point(event.root_x as i32, event.root_y as i32) {
878 + if monitor_index != self.selected_monitor {
879 + self.selected_monitor = monitor_index;
880 + self.update_bar()?;
881 +
882 + let visible = self.visible_windows_on_monitor(monitor_index);
883 + if let Some(&win) = visible.first() {
884 + self.set_focus(win)?;
885 + }
886 + }
887 + }
888 + }
852 889 Event::KeyPress(event) => {
853 890 let (action, arg) = keyboard::handle_key_press(event, &self.config.keybindings);
854 891 match action {
@@ -862,10 +899,10 @@ impl WindowManager {
862 899 .enumerate()
863 900 .find(|(_, bar)| bar.window() == event.event);
864 901
865 - if let Some((mon_idx, bar)) = is_bar_click {
902 + if let Some((monitor_index, bar)) = is_bar_click {
866 903 if let Some(tag_index) = bar.handle_click(event.event_x) {
867 - if mon_idx != self.selected_monitor {
868 - self.selected_monitor = mon_idx;
904 + if monitor_index != self.selected_monitor {
905 + self.selected_monitor = monitor_index;
869 906 }
870 907 self.view_tag(tag_index)?;
871 908 }
@@ -916,13 +953,13 @@ impl WindowManager {
916 953 }
917 954 };
918 955
919 - for (mon_idx, monitor) in self.monitors.iter().enumerate() {
956 + for (monitor_index, monitor) in self.monitors.iter().enumerate() {
920 957 let visible: Vec<Window> = self
921 958 .windows
922 959 .iter()
923 960 .filter(|&&w| {
924 961 let window_mon = self.window_monitor.get(&w).copied().unwrap_or(0);
925 - if window_mon != mon_idx {
962 + if window_mon != monitor_index {
926 963 return false;
927 964 }
928 965 if self.floating_windows.contains(&w) {
@@ -937,7 +974,7 @@ impl WindowManager {
937 974 .copied()
938 975 .collect();
939 976
940 - let bar_height = self.bars.get(mon_idx).map(|b| b.height() as u32).unwrap_or(0);
977 + let bar_height = self.bars.get(monitor_index).map(|b| b.height() as u32).unwrap_or(0);
941 978 let usable_height = monitor.height.saturating_sub(bar_height);
942 979
943 980 let geometries = self