floating: Implement center_window()
Browse files at this commit56e249aee68cd03687dd87dc47e2d13d599e5b87Parent: 6a7c8fc2 changed files +18 -3
- src/layout/floating.rs +15 -0
- src/layout/workspace.rs +3 -3
src/layout/floating.rsmodified+15 -0
| @@ -691,6 +691,21 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 691 | } | 691 | } |
| 692 | } | 692 | } |
| 693 | 693 | ||
| 694 | + pub fn center_window(&mut self) { | ||
| 695 | + let Some(active_id) = &self.active_window_id else { | ||
| 696 | + return; | ||
| 697 | + }; | ||
| 698 | + let active_idx = self.idx_of(active_id).unwrap(); | ||
| 699 | + | ||
| 700 | + let tile = &mut self.tiles[active_idx]; | ||
| 701 | + let data = &mut self.data[active_idx]; | ||
| 702 | + | ||
| 703 | + let prev_pos = data.logical_pos; | ||
| 704 | + let new_pos = center_preferring_top_left_in_area(self.working_area, data.size); | ||
| 705 | + data.set_logical_pos(new_pos); | ||
| 706 | + tile.animate_move_from(prev_pos - new_pos); | ||
| 707 | + } | ||
| 708 | + | ||
| 694 | pub fn descendants_added(&mut self, id: &W::Id) -> bool { | 709 | pub fn descendants_added(&mut self, id: &W::Id) -> bool { |
| 695 | let Some(idx) = self.idx_of(id) else { | 710 | let Some(idx) = self.idx_of(id) else { |
| 696 | return false; | 711 | return false; |
src/layout/workspace.rsmodified+3 -3
| @@ -909,11 +909,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 909 | } | 909 | } |
| 910 | 910 | ||
| 911 | pub fn center_column(&mut self) { | 911 | pub fn center_column(&mut self) { |
| 912 | - // TODO | ||
| 913 | if self.floating_is_active { | 912 | if self.floating_is_active { |
| 914 | - return; | 913 | + self.floating.center_window(); |
| 914 | + } else { | ||
| 915 | + self.scrolling.center_column(); | ||
| 915 | } | 916 | } |
| 916 | - self.scrolling.center_column(); | ||
| 917 | } | 917 | } |
| 918 | 918 | ||
| 919 | pub fn toggle_width(&mut self) { | 919 | pub fn toggle_width(&mut self) { |