|
|
@@ -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::{ConfigError, WmError}; |
|
|
@@ -174,6 +175,8 @@ pub struct WindowManager { |
| 174 |
175 |
error_message: Option<String>, |
| 175 |
176 |
overlay: ErrorOverlay, |
| 176 |
177 |
keybind_overlay: KeybindOverlay, |
|
178 |
+ scroll_animation: ScrollAnimation, |
|
179 |
+ animation_config: AnimationConfig, |
| 177 |
180 |
} |
| 178 |
181 |
|
| 179 |
182 |
type WmResult<T> = Result<T, WmError>; |
|
|
@@ -407,6 +410,8 @@ impl WindowManager { |
| 407 |
410 |
error_message: None, |
| 408 |
411 |
overlay, |
| 409 |
412 |
keybind_overlay, |
|
413 |
+ scroll_animation: ScrollAnimation::new(), |
|
414 |
+ animation_config: AnimationConfig::default(), |
| 410 |
415 |
}; |
| 411 |
416 |
|
| 412 |
417 |
for tab_bar in &window_manager.tab_bars { |
|
|
@@ -645,6 +650,8 @@ impl WindowManager { |
| 645 |
650 |
last_bar_update = std::time::Instant::now(); |
| 646 |
651 |
} |
| 647 |
652 |
|
|
653 |
+ self.tick_animations()?; |
|
654 |
+ |
| 648 |
655 |
self.connection.flush()?; |
| 649 |
656 |
std::thread::sleep(std::time::Duration::from_millis(16)); |
| 650 |
657 |
} |
|
|
@@ -733,6 +740,166 @@ impl WindowManager { |
| 733 |
740 |
Ok(()) |
| 734 |
741 |
} |
| 735 |
742 |
|
|
743 |
+ fn tick_animations(&mut self) -> WmResult<()> { |
|
744 |
+ if self.scroll_animation.is_active() { |
|
745 |
+ if let Some(new_offset) = self.scroll_animation.update() { |
|
746 |
+ if let Some(m) = self.monitors.get_mut(self.selected_monitor) { |
|
747 |
+ m.scroll_offset = new_offset; |
|
748 |
+ } |
|
749 |
+ self.apply_layout()?; |
|
750 |
+ self.update_bar()?; |
|
751 |
+ } |
|
752 |
+ } |
|
753 |
+ Ok(()) |
|
754 |
+ } |
|
755 |
+ |
|
756 |
+ fn scroll_layout(&mut self, direction: i32) -> WmResult<()> { |
|
757 |
+ if self.layout.name() != "scrolling" { |
|
758 |
+ return Ok(()); |
|
759 |
+ } |
|
760 |
+ |
|
761 |
+ let monitor_index = self.selected_monitor; |
|
762 |
+ let monitor = match self.monitors.get(monitor_index) { |
|
763 |
+ Some(m) => m.clone(), |
|
764 |
+ None => return Ok(()), |
|
765 |
+ }; |
|
766 |
+ |
|
767 |
+ let visible_count = if monitor.num_master > 0 { |
|
768 |
+ monitor.num_master as usize |
|
769 |
+ } else { |
|
770 |
+ 2 |
|
771 |
+ }; |
|
772 |
+ |
|
773 |
+ let mut tiled_count = 0; |
|
774 |
+ let mut current = self.next_tiled(monitor.clients_head, &monitor); |
|
775 |
+ while let Some(window) = current { |
|
776 |
+ tiled_count += 1; |
|
777 |
+ if let Some(client) = self.clients.get(&window) { |
|
778 |
+ current = self.next_tiled(client.next, &monitor); |
|
779 |
+ } else { |
|
780 |
+ break; |
|
781 |
+ } |
|
782 |
+ } |
|
783 |
+ |
|
784 |
+ if tiled_count <= visible_count { |
|
785 |
+ if let Some(m) = self.monitors.get_mut(monitor_index) { |
|
786 |
+ m.scroll_offset = 0; |
|
787 |
+ } |
|
788 |
+ return Ok(()); |
|
789 |
+ } |
|
790 |
+ |
|
791 |
+ let outer_gap = if self.gaps_enabled { |
|
792 |
+ self.config.gap_outer_vertical |
|
793 |
+ } else { |
|
794 |
+ 0 |
|
795 |
+ }; |
|
796 |
+ let inner_gap = if self.gaps_enabled { |
|
797 |
+ self.config.gap_inner_vertical |
|
798 |
+ } else { |
|
799 |
+ 0 |
|
800 |
+ }; |
|
801 |
+ |
|
802 |
+ let available_width = monitor.screen_width - 2 * outer_gap as i32; |
|
803 |
+ let total_inner_gaps = inner_gap as i32 * (visible_count - 1) as i32; |
|
804 |
+ let window_width = (available_width - total_inner_gaps) / visible_count as i32; |
|
805 |
+ let scroll_amount = window_width + inner_gap as i32; |
|
806 |
+ |
|
807 |
+ let total_width = tiled_count as i32 * window_width + (tiled_count - 1) as i32 * inner_gap as i32; |
|
808 |
+ let max_scroll = (total_width - available_width).max(0); |
|
809 |
+ |
|
810 |
+ let current_offset = monitor.scroll_offset; |
|
811 |
+ let target_offset = if self.scroll_animation.is_active() { |
|
812 |
+ self.scroll_animation.target() + direction * scroll_amount |
|
813 |
+ } else { |
|
814 |
+ current_offset + direction * scroll_amount |
|
815 |
+ }; |
|
816 |
+ let target_offset = target_offset.clamp(0, max_scroll); |
|
817 |
+ |
|
818 |
+ self.scroll_animation.start(current_offset, target_offset, &self.animation_config); |
|
819 |
+ |
|
820 |
+ Ok(()) |
|
821 |
+ } |
|
822 |
+ |
|
823 |
+ fn scroll_to_window(&mut self, target_window: Window, animate: bool) -> WmResult<()> { |
|
824 |
+ if self.layout.name() != "scrolling" { |
|
825 |
+ return Ok(()); |
|
826 |
+ } |
|
827 |
+ |
|
828 |
+ let monitor_index = self.selected_monitor; |
|
829 |
+ let monitor = match self.monitors.get(monitor_index) { |
|
830 |
+ Some(m) => m.clone(), |
|
831 |
+ None => return Ok(()), |
|
832 |
+ }; |
|
833 |
+ |
|
834 |
+ let visible_count = if monitor.num_master > 0 { |
|
835 |
+ monitor.num_master as usize |
|
836 |
+ } else { |
|
837 |
+ 2 |
|
838 |
+ }; |
|
839 |
+ |
|
840 |
+ let outer_gap = if self.gaps_enabled { |
|
841 |
+ self.config.gap_outer_vertical |
|
842 |
+ } else { |
|
843 |
+ 0 |
|
844 |
+ }; |
|
845 |
+ let inner_gap = if self.gaps_enabled { |
|
846 |
+ self.config.gap_inner_vertical |
|
847 |
+ } else { |
|
848 |
+ 0 |
|
849 |
+ }; |
|
850 |
+ |
|
851 |
+ let mut tiled_windows = Vec::new(); |
|
852 |
+ let mut current = self.next_tiled(monitor.clients_head, &monitor); |
|
853 |
+ while let Some(window) = current { |
|
854 |
+ tiled_windows.push(window); |
|
855 |
+ if let Some(client) = self.clients.get(&window) { |
|
856 |
+ current = self.next_tiled(client.next, &monitor); |
|
857 |
+ } else { |
|
858 |
+ break; |
|
859 |
+ } |
|
860 |
+ } |
|
861 |
+ |
|
862 |
+ let target_idx = tiled_windows.iter().position(|&w| w == target_window); |
|
863 |
+ let target_idx = match target_idx { |
|
864 |
+ Some(idx) => idx, |
|
865 |
+ None => return Ok(()), |
|
866 |
+ }; |
|
867 |
+ |
|
868 |
+ let tiled_count = tiled_windows.len(); |
|
869 |
+ if tiled_count <= visible_count { |
|
870 |
+ if animate && monitor.scroll_offset != 0 { |
|
871 |
+ self.scroll_animation.start(monitor.scroll_offset, 0, &self.animation_config); |
|
872 |
+ } else if let Some(m) = self.monitors.get_mut(monitor_index) { |
|
873 |
+ m.scroll_offset = 0; |
|
874 |
+ } |
|
875 |
+ return Ok(()); |
|
876 |
+ } |
|
877 |
+ |
|
878 |
+ let available_width = monitor.screen_width - 2 * outer_gap as i32; |
|
879 |
+ let total_inner_gaps = inner_gap as i32 * (visible_count - 1) as i32; |
|
880 |
+ let window_width = (available_width - total_inner_gaps) / visible_count as i32; |
|
881 |
+ let scroll_step = window_width + inner_gap as i32; |
|
882 |
+ |
|
883 |
+ let total_width = tiled_count as i32 * window_width + (tiled_count - 1) as i32 * inner_gap as i32; |
|
884 |
+ let max_scroll = (total_width - available_width).max(0); |
|
885 |
+ |
|
886 |
+ let target_scroll = (target_idx as i32) * scroll_step; |
|
887 |
+ let new_offset = target_scroll.clamp(0, max_scroll); |
|
888 |
+ |
|
889 |
+ let current_offset = monitor.scroll_offset; |
|
890 |
+ if current_offset != new_offset { |
|
891 |
+ if animate { |
|
892 |
+ self.scroll_animation.start(current_offset, new_offset, &self.animation_config); |
|
893 |
+ } else { |
|
894 |
+ if let Some(m) = self.monitors.get_mut(monitor_index) { |
|
895 |
+ m.scroll_offset = new_offset; |
|
896 |
+ } |
|
897 |
+ } |
|
898 |
+ } |
|
899 |
+ |
|
900 |
+ Ok(()) |
|
901 |
+ } |
|
902 |
+ |
| 736 |
903 |
fn toggle_bar(&mut self) -> WmResult<()> { |
| 737 |
904 |
if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 738 |
905 |
monitor.show_bar = !monitor.show_bar; |
|
|
@@ -748,6 +915,59 @@ impl WindowManager { |
| 748 |
915 |
|
| 749 |
916 |
fn get_layout_symbol(&self) -> String { |
| 750 |
917 |
let layout_name = self.layout.name(); |
|
918 |
+ |
|
919 |
+ if layout_name == "scrolling" { |
|
920 |
+ if let Some(monitor) = self.monitors.get(self.selected_monitor) { |
|
921 |
+ let visible_count = if monitor.num_master > 0 { |
|
922 |
+ monitor.num_master as usize |
|
923 |
+ } else { |
|
924 |
+ 2 |
|
925 |
+ }; |
|
926 |
+ |
|
927 |
+ let mut tiled_count = 0; |
|
928 |
+ let mut current = self.next_tiled(monitor.clients_head, monitor); |
|
929 |
+ while let Some(window) = current { |
|
930 |
+ tiled_count += 1; |
|
931 |
+ if let Some(client) = self.clients.get(&window) { |
|
932 |
+ current = self.next_tiled(client.next, monitor); |
|
933 |
+ } else { |
|
934 |
+ break; |
|
935 |
+ } |
|
936 |
+ } |
|
937 |
+ |
|
938 |
+ if tiled_count > 0 { |
|
939 |
+ let outer_gap = if self.gaps_enabled { |
|
940 |
+ self.config.gap_outer_vertical |
|
941 |
+ } else { |
|
942 |
+ 0 |
|
943 |
+ }; |
|
944 |
+ let inner_gap = if self.gaps_enabled { |
|
945 |
+ self.config.gap_inner_vertical |
|
946 |
+ } else { |
|
947 |
+ 0 |
|
948 |
+ }; |
|
949 |
+ |
|
950 |
+ let available_width = monitor.screen_width - 2 * outer_gap as i32; |
|
951 |
+ let total_inner_gaps = inner_gap as i32 * (visible_count.min(tiled_count) - 1) as i32; |
|
952 |
+ let window_width = if tiled_count <= visible_count { |
|
953 |
+ (available_width - total_inner_gaps) / tiled_count as i32 |
|
954 |
+ } else { |
|
955 |
+ (available_width - inner_gap as i32 * (visible_count - 1) as i32) / visible_count as i32 |
|
956 |
+ }; |
|
957 |
+ |
|
958 |
+ let scroll_step = window_width + inner_gap as i32; |
|
959 |
+ let first_visible = if scroll_step > 0 { |
|
960 |
+ (monitor.scroll_offset / scroll_step) + 1 |
|
961 |
+ } else { |
|
962 |
+ 1 |
|
963 |
+ }; |
|
964 |
+ let last_visible = (first_visible + visible_count as i32 - 1).min(tiled_count as i32); |
|
965 |
+ |
|
966 |
+ return format!("[{}-{}/{}]", first_visible, last_visible, tiled_count); |
|
967 |
+ } |
|
968 |
+ } |
|
969 |
+ } |
|
970 |
+ |
| 751 |
971 |
self.config |
| 752 |
972 |
.layout_symbols |
| 753 |
973 |
.iter() |
|
|
@@ -1045,6 +1265,12 @@ impl WindowManager { |
| 1045 |
1265 |
self.inc_num_master(*delta)?; |
| 1046 |
1266 |
} |
| 1047 |
1267 |
} |
|
1268 |
+ KeyAction::ScrollLeft => { |
|
1269 |
+ self.scroll_layout(-1)?; |
|
1270 |
+ } |
|
1271 |
+ KeyAction::ScrollRight => { |
|
1272 |
+ self.scroll_layout(1)?; |
|
1273 |
+ } |
| 1048 |
1274 |
KeyAction::None => {} |
| 1049 |
1275 |
} |
| 1050 |
1276 |
Ok(()) |
|
|
@@ -2047,7 +2273,15 @@ impl WindowManager { |
| 2047 |
2273 |
)?; |
| 2048 |
2274 |
} |
| 2049 |
2275 |
|
| 2050 |
|
- self.attach_aside(window, client_monitor); |
|
2276 |
+ if self.layout.name() == "scrolling" { |
|
2277 |
+ if let Some(selected) = self.monitors.get(client_monitor).and_then(|m| m.selected_client) { |
|
2278 |
+ self.attach_after(window, selected, client_monitor); |
|
2279 |
+ } else { |
|
2280 |
+ self.attach_aside(window, client_monitor); |
|
2281 |
+ } |
|
2282 |
+ } else { |
|
2283 |
+ self.attach_aside(window, client_monitor); |
|
2284 |
+ } |
| 2051 |
2285 |
self.attach_stack(window, client_monitor); |
| 2052 |
2286 |
self.windows.push(window); |
| 2053 |
2287 |
|
|
|
@@ -2067,6 +2301,23 @@ impl WindowManager { |
| 2067 |
2301 |
let final_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(tags); |
| 2068 |
2302 |
let _ = self.save_client_tag(window, final_tags); |
| 2069 |
2303 |
|
|
2304 |
+ if client_monitor == self.selected_monitor |
|
2305 |
+ && let Some(old_sel) = self |
|
2306 |
+ .monitors |
|
2307 |
+ .get(self.selected_monitor) |
|
2308 |
+ .and_then(|m| m.selected_client) |
|
2309 |
+ { |
|
2310 |
+ self.unfocus(old_sel, false)?; |
|
2311 |
+ } |
|
2312 |
+ |
|
2313 |
+ if let Some(m) = self.monitors.get_mut(client_monitor) { |
|
2314 |
+ m.selected_client = Some(window); |
|
2315 |
+ } |
|
2316 |
+ |
|
2317 |
+ if self.layout.name() == "scrolling" { |
|
2318 |
+ self.scroll_to_window(window, true)?; |
|
2319 |
+ } |
|
2320 |
+ |
| 2070 |
2321 |
self.apply_layout()?; |
| 2071 |
2322 |
self.connection.map_window(window)?; |
| 2072 |
2323 |
self.focus(None)?; |
|
|
@@ -2403,6 +2654,11 @@ impl WindowManager { |
| 2403 |
2654 |
}; |
| 2404 |
2655 |
|
| 2405 |
2656 |
self.focus(Some(next_window))?; |
|
2657 |
+ |
|
2658 |
+ if self.layout.name() == "scrolling" { |
|
2659 |
+ self.scroll_to_window(next_window, true)?; |
|
2660 |
+ } |
|
2661 |
+ |
| 2406 |
2662 |
self.restack()?; |
| 2407 |
2663 |
self.update_tab_bars()?; |
| 2408 |
2664 |
|
|
|
@@ -3644,6 +3900,7 @@ impl WindowManager { |
| 3644 |
3900 |
let monitor_y = monitor.screen_y; |
| 3645 |
3901 |
let monitor_width = monitor.screen_width; |
| 3646 |
3902 |
let monitor_height = monitor.screen_height; |
|
3903 |
+ let scroll_offset = monitor.scroll_offset; |
| 3647 |
3904 |
|
| 3648 |
3905 |
let mut visible: Vec<Window> = Vec::new(); |
| 3649 |
3906 |
let mut current = self.next_tiled(monitor.clients_head, monitor); |
|
|
@@ -3697,7 +3954,12 @@ impl WindowManager { |
| 3697 |
3954 |
adjusted_height = hint_height as u32; |
| 3698 |
3955 |
} |
| 3699 |
3956 |
|
| 3700 |
|
- let adjusted_x = geometry.x_coordinate + monitor_x; |
|
3957 |
+ let is_scrolling = self.layout.name() == "scrolling"; |
|
3958 |
+ let adjusted_x = if is_scrolling { |
|
3959 |
+ geometry.x_coordinate + monitor_x - scroll_offset |
|
3960 |
+ } else { |
|
3961 |
+ geometry.x_coordinate + monitor_x |
|
3962 |
+ }; |
| 3701 |
3963 |
let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32; |
| 3702 |
3964 |
|
| 3703 |
3965 |
if let Some(client) = self.clients.get_mut(window) { |
|
|
@@ -4295,6 +4557,20 @@ impl WindowManager { |
| 4295 |
4557 |
} |
| 4296 |
4558 |
} |
| 4297 |
4559 |
|
|
4560 |
+ fn attach_after(&mut self, window: Window, after_window: Window, monitor_index: usize) { |
|
4561 |
+ if let Some(after_client) = self.clients.get(&after_window) { |
|
4562 |
+ let old_next = after_client.next; |
|
4563 |
+ if let Some(new_client) = self.clients.get_mut(&window) { |
|
4564 |
+ new_client.next = old_next; |
|
4565 |
+ } |
|
4566 |
+ if let Some(after_client_mut) = self.clients.get_mut(&after_window) { |
|
4567 |
+ after_client_mut.next = Some(window); |
|
4568 |
+ } |
|
4569 |
+ } else { |
|
4570 |
+ self.attach(window, monitor_index); |
|
4571 |
+ } |
|
4572 |
+ } |
|
4573 |
+ |
| 4298 |
4574 |
fn attach_aside(&mut self, window: Window, monitor_index: usize) { |
| 4299 |
4575 |
let monitor = match self.monitors.get(monitor_index) { |
| 4300 |
4576 |
Some(m) => m, |
|
|
@@ -4447,6 +4723,9 @@ impl WindowManager { |
| 4447 |
4723 |
let visible = self.visible_windows_on_monitor(self.selected_monitor); |
| 4448 |
4724 |
if let Some(&new_win) = visible.last() { |
| 4449 |
4725 |
self.focus(Some(new_win))?; |
|
4726 |
+ if self.layout.name() == "scrolling" { |
|
4727 |
+ self.scroll_to_window(new_win, true)?; |
|
4728 |
+ } |
| 4450 |
4729 |
} else if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) { |
| 4451 |
4730 |
monitor.selected_client = None; |
| 4452 |
4731 |
} |