|
|
@@ -1,4 +1,5 @@ |
| 1 |
1 |
use crate::Config; |
|
2 |
+use crate::animations::{AnimationConfig, ScrollAnimation}; |
| 2 |
3 |
use crate::bar::Bar; |
| 3 |
4 |
use crate::client::{Client, TagMask}; |
| 4 |
5 |
use crate::errors::WmError; |
|
|
@@ -144,6 +145,8 @@ pub struct WindowManager { |
| 144 |
145 |
error_message: Option<String>, |
| 145 |
146 |
overlay: ErrorOverlay, |
| 146 |
147 |
keybind_overlay: KeybindOverlay, |
|
148 |
+ scroll_animation: ScrollAnimation, |
|
149 |
+ animation_config: AnimationConfig, |
| 147 |
150 |
} |
| 148 |
151 |
|
| 149 |
152 |
type WmResult<T> = Result<T, WmError>; |
|
|
@@ -303,6 +306,8 @@ impl WindowManager { |
| 303 |
306 |
error_message: None, |
| 304 |
307 |
overlay, |
| 305 |
308 |
keybind_overlay, |
|
309 |
+ scroll_animation: ScrollAnimation::new(), |
|
310 |
+ animation_config: AnimationConfig::default(), |
| 306 |
311 |
}; |
| 307 |
312 |
|
| 308 |
313 |
for tab_bar in &window_manager.tab_bars { |
|
|
@@ -528,6 +533,8 @@ impl WindowManager { |
| 528 |
533 |
last_bar_update = std::time::Instant::now(); |
| 529 |
534 |
} |
| 530 |
535 |
|
|
536 |
+ self.tick_animations()?; |
|
537 |
+ |
| 531 |
538 |
self.connection.flush()?; |
| 532 |
539 |
std::thread::sleep(std::time::Duration::from_millis(16)); |
| 533 |
540 |
} |
|
|
@@ -610,8 +617,219 @@ impl WindowManager { |
| 610 |
617 |
Ok(()) |
| 611 |
618 |
} |
| 612 |
619 |
|
|
620 |
+ fn tick_animations(&mut self) -> WmResult<()> { |
|
621 |
+ if self.scroll_animation.is_active() { |
|
622 |
+ if let Some(new_offset) = self.scroll_animation.update() { |
|
623 |
+ if let Some(m) = self.monitors.get_mut(self.selected_monitor) { |
|
624 |
+ m.scroll_offset = new_offset; |
|
625 |
+ } |
|
626 |
+ self.apply_layout()?; |
|
627 |
+ self.update_bar()?; |
|
628 |
+ } |
|
629 |
+ } |
|
630 |
+ Ok(()) |
|
631 |
+ } |
|
632 |
+ |
|
633 |
+ fn scroll_layout(&mut self, direction: i32) -> WmResult<()> { |
|
634 |
+ if self.layout.name() != "scrolling" { |
|
635 |
+ return Ok(()); |
|
636 |
+ } |
|
637 |
+ |
|
638 |
+ let monitor_index = self.selected_monitor; |
|
639 |
+ let monitor = match self.monitors.get(monitor_index) { |
|
640 |
+ Some(m) => m.clone(), |
|
641 |
+ None => return Ok(()), |
|
642 |
+ }; |
|
643 |
+ |
|
644 |
+ let visible_count = if monitor.num_master > 0 { |
|
645 |
+ monitor.num_master as usize |
|
646 |
+ } else { |
|
647 |
+ 2 |
|
648 |
+ }; |
|
649 |
+ |
|
650 |
+ let mut tiled_count = 0; |
|
651 |
+ let mut current = self.next_tiled(monitor.clients_head, &monitor); |
|
652 |
+ while let Some(window) = current { |
|
653 |
+ tiled_count += 1; |
|
654 |
+ if let Some(client) = self.clients.get(&window) { |
|
655 |
+ current = self.next_tiled(client.next, &monitor); |
|
656 |
+ } else { |
|
657 |
+ break; |
|
658 |
+ } |
|
659 |
+ } |
|
660 |
+ |
|
661 |
+ if tiled_count <= visible_count { |
|
662 |
+ if let Some(m) = self.monitors.get_mut(monitor_index) { |
|
663 |
+ m.scroll_offset = 0; |
|
664 |
+ } |
|
665 |
+ return Ok(()); |
|
666 |
+ } |
|
667 |
+ |
|
668 |
+ let outer_gap = if self.gaps_enabled { |
|
669 |
+ self.config.gap_outer_vertical |
|
670 |
+ } else { |
|
671 |
+ 0 |
|
672 |
+ }; |
|
673 |
+ let inner_gap = if self.gaps_enabled { |
|
674 |
+ self.config.gap_inner_vertical |
|
675 |
+ } else { |
|
676 |
+ 0 |
|
677 |
+ }; |
|
678 |
+ |
|
679 |
+ let available_width = monitor.screen_width - 2 * outer_gap as i32; |
|
680 |
+ let total_inner_gaps = inner_gap as i32 * (visible_count - 1) as i32; |
|
681 |
+ let window_width = (available_width - total_inner_gaps) / visible_count as i32; |
|
682 |
+ let scroll_amount = window_width + inner_gap as i32; |
|
683 |
+ |
|
684 |
+ let total_width = tiled_count as i32 * window_width + (tiled_count - 1) as i32 * inner_gap as i32; |
|
685 |
+ let max_scroll = (total_width - available_width).max(0); |
|
686 |
+ |
|
687 |
+ let current_offset = monitor.scroll_offset; |
|
688 |
+ let target_offset = if self.scroll_animation.is_active() { |
|
689 |
+ self.scroll_animation.target() + direction * scroll_amount |
|
690 |
+ } else { |
|
691 |
+ current_offset + direction * scroll_amount |
|
692 |
+ }; |
|
693 |
+ let target_offset = target_offset.clamp(0, max_scroll); |
|
694 |
+ |
|
695 |
+ self.scroll_animation.start(current_offset, target_offset, &self.animation_config); |
|
696 |
+ |
|
697 |
+ Ok(()) |
|
698 |
+ } |
|
699 |
+ |
|
700 |
+ fn scroll_to_window(&mut self, target_window: Window, animate: bool) -> WmResult<()> { |
|
701 |
+ if self.layout.name() != "scrolling" { |
|
702 |
+ return Ok(()); |
|
703 |
+ } |
|
704 |
+ |
|
705 |
+ let monitor_index = self.selected_monitor; |
|
706 |
+ let monitor = match self.monitors.get(monitor_index) { |
|
707 |
+ Some(m) => m.clone(), |
|
708 |
+ None => return Ok(()), |
|
709 |
+ }; |
|
710 |
+ |
|
711 |
+ let visible_count = if monitor.num_master > 0 { |
|
712 |
+ monitor.num_master as usize |
|
713 |
+ } else { |
|
714 |
+ 2 |
|
715 |
+ }; |
|
716 |
+ |
|
717 |
+ let outer_gap = if self.gaps_enabled { |
|
718 |
+ self.config.gap_outer_vertical |
|
719 |
+ } else { |
|
720 |
+ 0 |
|
721 |
+ }; |
|
722 |
+ let inner_gap = if self.gaps_enabled { |
|
723 |
+ self.config.gap_inner_vertical |
|
724 |
+ } else { |
|
725 |
+ 0 |
|
726 |
+ }; |
|
727 |
+ |
|
728 |
+ let mut tiled_windows = Vec::new(); |
|
729 |
+ let mut current = self.next_tiled(monitor.clients_head, &monitor); |
|
730 |
+ while let Some(window) = current { |
|
731 |
+ tiled_windows.push(window); |
|
732 |
+ if let Some(client) = self.clients.get(&window) { |
|
733 |
+ current = self.next_tiled(client.next, &monitor); |
|
734 |
+ } else { |
|
735 |
+ break; |
|
736 |
+ } |
|
737 |
+ } |
|
738 |
+ |
|
739 |
+ let target_idx = tiled_windows.iter().position(|&w| w == target_window); |
|
740 |
+ let target_idx = match target_idx { |
|
741 |
+ Some(idx) => idx, |
|
742 |
+ None => return Ok(()), |
|
743 |
+ }; |
|
744 |
+ |
|
745 |
+ let tiled_count = tiled_windows.len(); |
|
746 |
+ if tiled_count <= visible_count { |
|
747 |
+ if let Some(m) = self.monitors.get_mut(monitor_index) { |
|
748 |
+ m.scroll_offset = 0; |
|
749 |
+ } |
|
750 |
+ return Ok(()); |
|
751 |
+ } |
|
752 |
+ |
|
753 |
+ let available_width = monitor.screen_width - 2 * outer_gap as i32; |
|
754 |
+ let total_inner_gaps = inner_gap as i32 * (visible_count - 1) as i32; |
|
755 |
+ let window_width = (available_width - total_inner_gaps) / visible_count as i32; |
|
756 |
+ let scroll_step = window_width + inner_gap as i32; |
|
757 |
+ |
|
758 |
+ let total_width = tiled_count as i32 * window_width + (tiled_count - 1) as i32 * inner_gap as i32; |
|
759 |
+ let max_scroll = (total_width - available_width).max(0); |
|
760 |
+ |
|
761 |
+ let target_scroll = (target_idx as i32) * scroll_step; |
|
762 |
+ let new_offset = target_scroll.clamp(0, max_scroll); |
|
763 |
+ |
|
764 |
+ let current_offset = monitor.scroll_offset; |
|
765 |
+ if current_offset != new_offset { |
|
766 |
+ if animate { |
|
767 |
+ self.scroll_animation.start(current_offset, new_offset, &self.animation_config); |
|
768 |
+ } else { |
|
769 |
+ if let Some(m) = self.monitors.get_mut(monitor_index) { |
|
770 |
+ m.scroll_offset = new_offset; |
|
771 |
+ } |
|
772 |
+ } |
|
773 |
+ } |
|
774 |
+ |
|
775 |
+ Ok(()) |
|
776 |
+ } |
|
777 |
+ |
| 613 |
778 |
fn get_layout_symbol(&self) -> String { |
| 614 |
779 |
let layout_name = self.layout.name(); |
|
780 |
+ |
|
781 |
+ if layout_name == "scrolling" { |
|
782 |
+ if let Some(monitor) = self.monitors.get(self.selected_monitor) { |
|
783 |
+ let visible_count = if monitor.num_master > 0 { |
|
784 |
+ monitor.num_master as usize |
|
785 |
+ } else { |
|
786 |
+ 2 |
|
787 |
+ }; |
|
788 |
+ |
|
789 |
+ let mut tiled_count = 0; |
|
790 |
+ let mut current = self.next_tiled(monitor.clients_head, monitor); |
|
791 |
+ while let Some(window) = current { |
|
792 |
+ tiled_count += 1; |
|
793 |
+ if let Some(client) = self.clients.get(&window) { |
|
794 |
+ current = self.next_tiled(client.next, monitor); |
|
795 |
+ } else { |
|
796 |
+ break; |
|
797 |
+ } |
|
798 |
+ } |
|
799 |
+ |
|
800 |
+ if tiled_count > 0 { |
|
801 |
+ let outer_gap = if self.gaps_enabled { |
|
802 |
+ self.config.gap_outer_vertical |
|
803 |
+ } else { |
|
804 |
+ 0 |
|
805 |
+ }; |
|
806 |
+ let inner_gap = if self.gaps_enabled { |
|
807 |
+ self.config.gap_inner_vertical |
|
808 |
+ } else { |
|
809 |
+ 0 |
|
810 |
+ }; |
|
811 |
+ |
|
812 |
+ let available_width = monitor.screen_width - 2 * outer_gap as i32; |
|
813 |
+ let total_inner_gaps = inner_gap as i32 * (visible_count.min(tiled_count) - 1) as i32; |
|
814 |
+ let window_width = if tiled_count <= visible_count { |
|
815 |
+ (available_width - total_inner_gaps) / tiled_count as i32 |
|
816 |
+ } else { |
|
817 |
+ (available_width - inner_gap as i32 * (visible_count - 1) as i32) / visible_count as i32 |
|
818 |
+ }; |
|
819 |
+ |
|
820 |
+ let scroll_step = window_width + inner_gap as i32; |
|
821 |
+ let first_visible = if scroll_step > 0 { |
|
822 |
+ (monitor.scroll_offset / scroll_step) + 1 |
|
823 |
+ } else { |
|
824 |
+ 1 |
|
825 |
+ }; |
|
826 |
+ let last_visible = (first_visible + visible_count as i32 - 1).min(tiled_count as i32); |
|
827 |
+ |
|
828 |
+ return format!("[{}-{}/{}]", first_visible, last_visible, tiled_count); |
|
829 |
+ } |
|
830 |
+ } |
|
831 |
+ } |
|
832 |
+ |
| 615 |
833 |
self.config |
| 616 |
834 |
.layout_symbols |
| 617 |
835 |
.iter() |
|
|
@@ -908,6 +1126,12 @@ impl WindowManager { |
| 908 |
1126 |
self.inc_num_master(*delta)?; |
| 909 |
1127 |
} |
| 910 |
1128 |
} |
|
1129 |
+ KeyAction::ScrollLeft => { |
|
1130 |
+ self.scroll_layout(-1)?; |
|
1131 |
+ } |
|
1132 |
+ KeyAction::ScrollRight => { |
|
1133 |
+ self.scroll_layout(1)?; |
|
1134 |
+ } |
| 911 |
1135 |
KeyAction::None => {} |
| 912 |
1136 |
} |
| 913 |
1137 |
Ok(()) |
|
|
@@ -1953,7 +2177,15 @@ impl WindowManager { |
| 1953 |
2177 |
)?; |
| 1954 |
2178 |
} |
| 1955 |
2179 |
|
| 1956 |
|
- self.attach_aside(window, client_monitor); |
|
2180 |
+ if self.layout.name() == "scrolling" { |
|
2181 |
+ if let Some(selected) = self.monitors.get(client_monitor).and_then(|m| m.selected_client) { |
|
2182 |
+ self.attach_after(window, selected, client_monitor); |
|
2183 |
+ } else { |
|
2184 |
+ self.attach_aside(window, client_monitor); |
|
2185 |
+ } |
|
2186 |
+ } else { |
|
2187 |
+ self.attach_aside(window, client_monitor); |
|
2188 |
+ } |
| 1957 |
2189 |
self.attach_stack(window, client_monitor); |
| 1958 |
2190 |
self.windows.push(window); |
| 1959 |
2191 |
|
|
|
@@ -1985,6 +2217,10 @@ impl WindowManager { |
| 1985 |
2217 |
m.selected_client = Some(window); |
| 1986 |
2218 |
} |
| 1987 |
2219 |
|
|
2220 |
+ if self.layout.name() == "scrolling" { |
|
2221 |
+ self.scroll_to_window(window, false)?; |
|
2222 |
+ } |
|
2223 |
+ |
| 1988 |
2224 |
self.apply_layout()?; |
| 1989 |
2225 |
self.connection.map_window(window)?; |
| 1990 |
2226 |
self.focus(Some(window))?; |
|
|
@@ -2224,6 +2460,11 @@ impl WindowManager { |
| 2224 |
2460 |
}; |
| 2225 |
2461 |
|
| 2226 |
2462 |
self.focus(Some(next_window))?; |
|
2463 |
+ |
|
2464 |
+ if self.layout.name() == "scrolling" { |
|
2465 |
+ self.scroll_to_window(next_window, true)?; |
|
2466 |
+ } |
|
2467 |
+ |
| 2227 |
2468 |
self.update_tab_bars()?; |
| 2228 |
2469 |
|
| 2229 |
2470 |
Ok(()) |
|
|
@@ -3434,6 +3675,7 @@ impl WindowManager { |
| 3434 |
3675 |
let monitor_y = monitor.screen_y; |
| 3435 |
3676 |
let monitor_width = monitor.screen_width; |
| 3436 |
3677 |
let monitor_height = monitor.screen_height; |
|
3678 |
+ let scroll_offset = monitor.scroll_offset; |
| 3437 |
3679 |
|
| 3438 |
3680 |
let mut visible: Vec<Window> = Vec::new(); |
| 3439 |
3681 |
let mut current = self.next_tiled(monitor.clients_head, monitor); |
|
|
@@ -3487,7 +3729,12 @@ impl WindowManager { |
| 3487 |
3729 |
adjusted_height = hint_height as u32; |
| 3488 |
3730 |
} |
| 3489 |
3731 |
|
| 3490 |
|
- let adjusted_x = geometry.x_coordinate + monitor_x; |
|
3732 |
+ let is_scrolling = self.layout.name() == "scrolling"; |
|
3733 |
+ let adjusted_x = if is_scrolling { |
|
3734 |
+ geometry.x_coordinate + monitor_x - scroll_offset |
|
3735 |
+ } else { |
|
3736 |
+ geometry.x_coordinate + monitor_x |
|
3737 |
+ }; |
| 3491 |
3738 |
let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32; |
| 3492 |
3739 |
|
| 3493 |
3740 |
if let Some(client) = self.clients.get_mut(window) { |
|
|
@@ -4046,6 +4293,20 @@ impl WindowManager { |
| 4046 |
4293 |
} |
| 4047 |
4294 |
} |
| 4048 |
4295 |
|
|
4296 |
+ fn attach_after(&mut self, window: Window, after_window: Window, monitor_index: usize) { |
|
4297 |
+ if let Some(after_client) = self.clients.get(&after_window) { |
|
4298 |
+ let old_next = after_client.next; |
|
4299 |
+ if let Some(new_client) = self.clients.get_mut(&window) { |
|
4300 |
+ new_client.next = old_next; |
|
4301 |
+ } |
|
4302 |
+ if let Some(after_client_mut) = self.clients.get_mut(&after_window) { |
|
4303 |
+ after_client_mut.next = Some(window); |
|
4304 |
+ } |
|
4305 |
+ } else { |
|
4306 |
+ self.attach(window, monitor_index); |
|
4307 |
+ } |
|
4308 |
+ } |
|
4309 |
+ |
| 4049 |
4310 |
fn attach_aside(&mut self, window: Window, monitor_index: usize) { |
| 4050 |
4311 |
let monitor = match self.monitors.get(monitor_index) { |
| 4051 |
4312 |
Some(m) => m, |