Implement window close transaction
Browse files at this commitc8839f7658588bfd7f0f41bf2c2726e526366abfParent: dfe35807 changed files +172 -39
- src/handlers/compositor.rs +5 -2
- src/handlers/xdg_shell.rs +6 -2
- src/layout/closing_window.rs +72 -7
- src/layout/mod.rs +18 -14
- src/layout/monitor.rs +19 -3
- src/layout/workspace.rs +46 -11
- src/utils/transaction.rs +6 -0
src/handlers/compositor.rsmodified+5 -2
| @@ -20,6 +20,7 @@ use smithay::{delegate_compositor, delegate_shm}; | |||
| 20 | use super::xdg_shell::add_mapped_toplevel_pre_commit_hook; | 20 | use super::xdg_shell::add_mapped_toplevel_pre_commit_hook; |
| 21 | use crate::niri::{ClientState, State}; | 21 | use crate::niri::{ClientState, State}; |
| 22 | use crate::utils::send_scale_transform; | 22 | use crate::utils::send_scale_transform; |
| 23 | +use crate::utils::transaction::Transaction; | ||
| 23 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped}; | 24 | use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped}; |
| 24 | 25 | ||
| 25 | impl CompositorHandler for State { | 26 | impl CompositorHandler for State { |
| @@ -193,11 +194,13 @@ impl CompositorHandler for State { | |||
| 193 | }); | 194 | }); |
| 194 | 195 | ||
| 195 | // Must start the close animation before window.on_commit(). | 196 | // Must start the close animation before window.on_commit(). |
| 197 | + let transaction = Transaction::new(); | ||
| 196 | if !is_mapped { | 198 | if !is_mapped { |
| 199 | + let blocker = transaction.blocker(); | ||
| 197 | self.backend.with_primary_renderer(|renderer| { | 200 | self.backend.with_primary_renderer(|renderer| { |
| 198 | self.niri | 201 | self.niri |
| 199 | .layout | 202 | .layout |
| 200 | - .start_close_animation_for_window(renderer, &window); | 203 | + .start_close_animation_for_window(renderer, &window, blocker); |
| 201 | }); | 204 | }); |
| 202 | } | 205 | } |
| 203 | 206 | ||
| @@ -216,7 +219,7 @@ impl CompositorHandler for State { | |||
| 216 | id: u64::from(id.get()), | 219 | id: u64::from(id.get()), |
| 217 | }); | 220 | }); |
| 218 | 221 | ||
| 219 | - self.niri.layout.remove_window(&window); | 222 | + self.niri.layout.remove_window(&window, transaction); |
| 220 | self.add_default_dmabuf_pre_commit_hook(surface); | 223 | self.add_default_dmabuf_pre_commit_hook(surface); |
| 221 | 224 | ||
| 222 | if was_active { | 225 | if was_active { |
src/handlers/xdg_shell.rsmodified+6 -2
| @@ -40,6 +40,7 @@ use crate::input::resize_grab::ResizeGrab; | |||
| 40 | use crate::input::DOUBLE_CLICK_TIME; | 40 | use crate::input::DOUBLE_CLICK_TIME; |
| 41 | use crate::layout::workspace::ColumnWidth; | 41 | use crate::layout::workspace::ColumnWidth; |
| 42 | use crate::niri::{PopupGrabState, State}; | 42 | use crate::niri::{PopupGrabState, State}; |
| 43 | +use crate::utils::transaction::Transaction; | ||
| 43 | use crate::utils::{get_monotonic_time, send_scale_transform, ResizeEdge}; | 44 | use crate::utils::{get_monotonic_time, send_scale_transform, ResizeEdge}; |
| 44 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; | 45 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; |
| 45 | 46 | ||
| @@ -485,16 +486,19 @@ impl XdgShellHandler for State { | |||
| 485 | self.backend.with_primary_renderer(|renderer| { | 486 | self.backend.with_primary_renderer(|renderer| { |
| 486 | self.niri.layout.store_unmap_snapshot(renderer, &window); | 487 | self.niri.layout.store_unmap_snapshot(renderer, &window); |
| 487 | }); | 488 | }); |
| 489 | + | ||
| 490 | + let transaction = Transaction::new(); | ||
| 491 | + let blocker = transaction.blocker(); | ||
| 488 | self.backend.with_primary_renderer(|renderer| { | 492 | self.backend.with_primary_renderer(|renderer| { |
| 489 | self.niri | 493 | self.niri |
| 490 | .layout | 494 | .layout |
| 491 | - .start_close_animation_for_window(renderer, &window); | 495 | + .start_close_animation_for_window(renderer, &window, blocker); |
| 492 | }); | 496 | }); |
| 493 | 497 | ||
| 494 | let active_window = self.niri.layout.active_window().map(|(m, _)| &m.window); | 498 | let active_window = self.niri.layout.active_window().map(|(m, _)| &m.window); |
| 495 | let was_active = active_window == Some(&window); | 499 | let was_active = active_window == Some(&window); |
| 496 | 500 | ||
| 497 | - self.niri.layout.remove_window(&window); | 501 | + self.niri.layout.remove_window(&window, transaction); |
| 498 | self.add_default_dmabuf_pre_commit_hook(surface.wl_surface()); | 502 | self.add_default_dmabuf_pre_commit_hook(surface.wl_surface()); |
| 499 | 503 | ||
| 500 | if was_active { | 504 | if was_active { |
src/layout/closing_window.rsmodified+72 -7
| @@ -12,6 +12,7 @@ use smithay::backend::renderer::element::{Kind, RenderElement}; | |||
| 12 | use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture, Uniform}; | 12 | use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture, Uniform}; |
| 13 | use smithay::backend::renderer::Texture; | 13 | use smithay::backend::renderer::Texture; |
| 14 | use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform}; | 14 | use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform}; |
| 15 | +use smithay::wayland::compositor::{Blocker, BlockerState}; | ||
| 15 | 16 | ||
| 16 | use crate::animation::Animation; | 17 | use crate::animation::Animation; |
| 17 | use crate::niri_render_elements; | 18 | use crate::niri_render_elements; |
| @@ -21,6 +22,7 @@ use crate::render_helpers::shaders::{mat3_uniform, ProgramType, Shaders}; | |||
| 21 | use crate::render_helpers::snapshot::RenderSnapshot; | 22 | use crate::render_helpers::snapshot::RenderSnapshot; |
| 22 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; | 23 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; |
| 23 | use crate::render_helpers::{render_to_encompassing_texture, RenderTarget}; | 24 | use crate::render_helpers::{render_to_encompassing_texture, RenderTarget}; |
| 25 | +use crate::utils::transaction::TransactionBlocker; | ||
| 24 | 26 | ||
| 25 | #[derive(Debug)] | 27 | #[derive(Debug)] |
| 26 | pub struct ClosingWindow { | 28 | pub struct ClosingWindow { |
| @@ -46,7 +48,7 @@ pub struct ClosingWindow { | |||
| 46 | blocked_out_buffer_offset: Point<f64, Logical>, | 48 | blocked_out_buffer_offset: Point<f64, Logical>, |
| 47 | 49 | ||
| 48 | /// The closing animation. | 50 | /// The closing animation. |
| 49 | - anim: Animation, | 51 | + anim_state: AnimationState, |
| 50 | 52 | ||
| 51 | /// Random seed for the shader. | 53 | /// Random seed for the shader. |
| 52 | random_seed: f32, | 54 | random_seed: f32, |
| @@ -59,6 +61,29 @@ niri_render_elements! { | |||
| 59 | } | 61 | } |
| 60 | } | 62 | } |
| 61 | 63 | ||
| 64 | +#[derive(Debug)] | ||
| 65 | +enum AnimationState { | ||
| 66 | + Waiting { | ||
| 67 | + /// Blocker for a transaction before starting the animation. | ||
| 68 | + blocker: TransactionBlocker, | ||
| 69 | + anim: Animation, | ||
| 70 | + }, | ||
| 71 | + Animating(Animation), | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +impl AnimationState { | ||
| 75 | + pub fn new(blocker: TransactionBlocker, anim: Animation) -> Self { | ||
| 76 | + if blocker.state() == BlockerState::Pending { | ||
| 77 | + Self::Waiting { blocker, anim } | ||
| 78 | + } else { | ||
| 79 | + // This actually doesn't normally happen because the window is removed only after the | ||
| 80 | + // closing animation is created. Though, it does happen with disable-transactions debug | ||
| 81 | + // flag. | ||
| 82 | + Self::Animating(anim) | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | +} | ||
| 86 | + | ||
| 62 | impl ClosingWindow { | 87 | impl ClosingWindow { |
| 63 | pub fn new<E: RenderElement<GlesRenderer>>( | 88 | pub fn new<E: RenderElement<GlesRenderer>>( |
| 64 | renderer: &mut GlesRenderer, | 89 | renderer: &mut GlesRenderer, |
| @@ -66,6 +91,7 @@ impl ClosingWindow { | |||
| 66 | scale: Scale<f64>, | 91 | scale: Scale<f64>, |
| 67 | geo_size: Size<f64, Logical>, | 92 | geo_size: Size<f64, Logical>, |
| 68 | pos: Point<f64, Logical>, | 93 | pos: Point<f64, Logical>, |
| 94 | + blocker: TransactionBlocker, | ||
| 69 | anim: Animation, | 95 | anim: Animation, |
| 70 | ) -> anyhow::Result<Self> { | 96 | ) -> anyhow::Result<Self> { |
| 71 | let _span = tracy_client::span!("ClosingWindow::new"); | 97 | let _span = tracy_client::span!("ClosingWindow::new"); |
| @@ -107,17 +133,29 @@ impl ClosingWindow { | |||
| 107 | pos, | 133 | pos, |
| 108 | buffer_offset, | 134 | buffer_offset, |
| 109 | blocked_out_buffer_offset, | 135 | blocked_out_buffer_offset, |
| 110 | - anim, | 136 | + anim_state: AnimationState::new(blocker, anim), |
| 111 | random_seed: fastrand::f32(), | 137 | random_seed: fastrand::f32(), |
| 112 | }) | 138 | }) |
| 113 | } | 139 | } |
| 114 | 140 | ||
| 115 | pub fn advance_animations(&mut self, current_time: Duration) { | 141 | pub fn advance_animations(&mut self, current_time: Duration) { |
| 116 | - self.anim.set_current_time(current_time); | 142 | + match &mut self.anim_state { |
| 143 | + AnimationState::Waiting { blocker, anim } => { | ||
| 144 | + if blocker.state() != BlockerState::Pending { | ||
| 145 | + let mut anim = anim.restarted(0., 1., 0.); | ||
| 146 | + anim.set_current_time(current_time); | ||
| 147 | + self.anim_state = AnimationState::Animating(anim); | ||
| 148 | + } | ||
| 149 | + } | ||
| 150 | + AnimationState::Animating(anim) => anim.set_current_time(current_time), | ||
| 151 | + } | ||
| 117 | } | 152 | } |
| 118 | 153 | ||
| 119 | pub fn are_animations_ongoing(&self) -> bool { | 154 | pub fn are_animations_ongoing(&self) -> bool { |
| 120 | - !self.anim.is_done() | 155 | + match &self.anim_state { |
| 156 | + AnimationState::Waiting { .. } => true, | ||
| 157 | + AnimationState::Animating(anim) => !anim.is_done(), | ||
| 158 | + } | ||
| 121 | } | 159 | } |
| 122 | 160 | ||
| 123 | pub fn render( | 161 | pub fn render( |
| @@ -127,15 +165,42 @@ impl ClosingWindow { | |||
| 127 | scale: Scale<f64>, | 165 | scale: Scale<f64>, |
| 128 | target: RenderTarget, | 166 | target: RenderTarget, |
| 129 | ) -> ClosingWindowRenderElement { | 167 | ) -> ClosingWindowRenderElement { |
| 130 | - let progress = self.anim.value(); | ||
| 131 | - let clamped_progress = self.anim.clamped_value().clamp(0., 1.); | ||
| 132 | - | ||
| 133 | let (buffer, offset) = if target.should_block_out(self.block_out_from) { | 168 | let (buffer, offset) = if target.should_block_out(self.block_out_from) { |
| 134 | (&self.blocked_out_buffer, self.blocked_out_buffer_offset) | 169 | (&self.blocked_out_buffer, self.blocked_out_buffer_offset) |
| 135 | } else { | 170 | } else { |
| 136 | (&self.buffer, self.buffer_offset) | 171 | (&self.buffer, self.buffer_offset) |
| 137 | }; | 172 | }; |
| 138 | 173 | ||
| 174 | + let anim = match &self.anim_state { | ||
| 175 | + AnimationState::Waiting { .. } => { | ||
| 176 | + let elem = TextureRenderElement::from_texture_buffer( | ||
| 177 | + buffer.clone(), | ||
| 178 | + Point::from((0., 0.)), | ||
| 179 | + 1., | ||
| 180 | + None, | ||
| 181 | + None, | ||
| 182 | + Kind::Unspecified, | ||
| 183 | + ); | ||
| 184 | + | ||
| 185 | + let elem = PrimaryGpuTextureRenderElement(elem); | ||
| 186 | + let elem = RescaleRenderElement::from_element(elem, Point::from((0, 0)), 1.); | ||
| 187 | + | ||
| 188 | + let mut location = self.pos + offset; | ||
| 189 | + location.x -= view_rect.loc.x; | ||
| 190 | + let elem = RelocateRenderElement::from_element( | ||
| 191 | + elem, | ||
| 192 | + location.to_physical_precise_round(scale), | ||
| 193 | + Relocate::Relative, | ||
| 194 | + ); | ||
| 195 | + | ||
| 196 | + return elem.into(); | ||
| 197 | + } | ||
| 198 | + AnimationState::Animating(anim) => anim, | ||
| 199 | + }; | ||
| 200 | + | ||
| 201 | + let progress = anim.value(); | ||
| 202 | + let clamped_progress = anim.clamped_value().clamp(0., 1.); | ||
| 203 | + | ||
| 139 | if Shaders::get(renderer).program(ProgramType::Close).is_some() { | 204 | if Shaders::get(renderer).program(ProgramType::Close).is_some() { |
| 140 | let area_loc = Vec2::new(view_rect.loc.x as f32, view_rect.loc.y as f32); | 205 | let area_loc = Vec2::new(view_rect.loc.x as f32, view_rect.loc.y as f32); |
| 141 | let area_size = Vec2::new(view_rect.size.w as f32, view_rect.size.h as f32); | 206 | let area_size = Vec2::new(view_rect.size.w as f32, view_rect.size.h as f32); |
src/layout/mod.rsmodified+18 -14
| @@ -52,7 +52,7 @@ use crate::render_helpers::snapshot::RenderSnapshot; | |||
| 52 | use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement}; | 52 | use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement}; |
| 53 | use crate::render_helpers::texture::TextureBuffer; | 53 | use crate::render_helpers::texture::TextureBuffer; |
| 54 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; | 54 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; |
| 55 | -use crate::utils::transaction::Transaction; | 55 | +use crate::utils::transaction::{Transaction, TransactionBlocker}; |
| 56 | use crate::utils::{output_size, round_logical_in_physical_max1, ResizeEdge}; | 56 | use crate::utils::{output_size, round_logical_in_physical_max1, ResizeEdge}; |
| 57 | use crate::window::ResolvedWindowRules; | 57 | use crate::window::ResolvedWindowRules; |
| 58 | 58 | ||
| @@ -752,15 +752,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 752 | ); | 752 | ); |
| 753 | } | 753 | } |
| 754 | 754 | ||
| 755 | - pub fn remove_window(&mut self, window: &W::Id) -> Option<W> { | 755 | + pub fn remove_window(&mut self, window: &W::Id, transaction: Transaction) -> Option<W> { |
| 756 | - let mut rv = None; | ||
| 757 | - | ||
| 758 | match &mut self.monitor_set { | 756 | match &mut self.monitor_set { |
| 759 | MonitorSet::Normal { monitors, .. } => { | 757 | MonitorSet::Normal { monitors, .. } => { |
| 760 | for mon in monitors { | 758 | for mon in monitors { |
| 761 | for (idx, ws) in mon.workspaces.iter_mut().enumerate() { | 759 | for (idx, ws) in mon.workspaces.iter_mut().enumerate() { |
| 762 | if ws.has_window(window) { | 760 | if ws.has_window(window) { |
| 763 | - rv = Some(ws.remove_window(window)); | 761 | + let win = ws.remove_window(window, transaction); |
| 764 | 762 | ||
| 765 | // Clean up empty workspaces that are not active and not last. | 763 | // Clean up empty workspaces that are not active and not last. |
| 766 | if !ws.has_windows() | 764 | if !ws.has_windows() |
| @@ -776,7 +774,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 776 | } | 774 | } |
| 777 | } | 775 | } |
| 778 | 776 | ||
| 779 | - break; | 777 | + return Some(win); |
| 780 | } | 778 | } |
| 781 | } | 779 | } |
| 782 | } | 780 | } |
| @@ -784,20 +782,20 @@ impl<W: LayoutElement> Layout<W> { | |||
| 784 | MonitorSet::NoOutputs { workspaces, .. } => { | 782 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 785 | for (idx, ws) in workspaces.iter_mut().enumerate() { | 783 | for (idx, ws) in workspaces.iter_mut().enumerate() { |
| 786 | if ws.has_window(window) { | 784 | if ws.has_window(window) { |
| 787 | - rv = Some(ws.remove_window(window)); | 785 | + let win = ws.remove_window(window, transaction); |
| 788 | 786 | ||
| 789 | // Clean up empty workspaces. | 787 | // Clean up empty workspaces. |
| 790 | if !ws.has_windows() && workspaces[idx].name.is_none() { | 788 | if !ws.has_windows() && workspaces[idx].name.is_none() { |
| 791 | workspaces.remove(idx); | 789 | workspaces.remove(idx); |
| 792 | } | 790 | } |
| 793 | 791 | ||
| 794 | - break; | 792 | + return Some(win); |
| 795 | } | 793 | } |
| 796 | } | 794 | } |
| 797 | } | 795 | } |
| 798 | } | 796 | } |
| 799 | 797 | ||
| 800 | - rv | 798 | + None |
| 801 | } | 799 | } |
| 802 | 800 | ||
| 803 | pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) { | 801 | pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) { |
| @@ -1970,7 +1968,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1970 | let width = column.width; | 1968 | let width = column.width; |
| 1971 | let is_full_width = column.is_full_width; | 1969 | let is_full_width = column.is_full_width; |
| 1972 | let window = ws | 1970 | let window = ws |
| 1973 | - .remove_tile_by_idx(ws.active_column_idx, column.active_tile_idx, None) | 1971 | + .remove_tile_by_idx( |
| 1972 | + ws.active_column_idx, | ||
| 1973 | + column.active_tile_idx, | ||
| 1974 | + Transaction::new(), | ||
| 1975 | + None, | ||
| 1976 | + ) | ||
| 1974 | .into_window(); | 1977 | .into_window(); |
| 1975 | 1978 | ||
| 1976 | let workspace_idx = monitors[new_idx].active_workspace_idx; | 1979 | let workspace_idx = monitors[new_idx].active_workspace_idx; |
| @@ -2022,7 +2025,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2022 | 2025 | ||
| 2023 | let Some(width) = width else { return }; | 2026 | let Some(width) = width else { return }; |
| 2024 | 2027 | ||
| 2025 | - let window = self.remove_window(window).unwrap(); | 2028 | + let window = self.remove_window(window, Transaction::new()).unwrap(); |
| 2026 | 2029 | ||
| 2027 | if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | 2030 | if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { |
| 2028 | let new_idx = monitors | 2031 | let new_idx = monitors |
| @@ -2425,6 +2428,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2425 | &mut self, | 2428 | &mut self, |
| 2426 | renderer: &mut GlesRenderer, | 2429 | renderer: &mut GlesRenderer, |
| 2427 | window: &W::Id, | 2430 | window: &W::Id, |
| 2431 | + blocker: TransactionBlocker, | ||
| 2428 | ) { | 2432 | ) { |
| 2429 | let _span = tracy_client::span!("Layout::start_close_animation_for_window"); | 2433 | let _span = tracy_client::span!("Layout::start_close_animation_for_window"); |
| 2430 | 2434 | ||
| @@ -2433,7 +2437,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2433 | for mon in monitors { | 2437 | for mon in monitors { |
| 2434 | for ws in &mut mon.workspaces { | 2438 | for ws in &mut mon.workspaces { |
| 2435 | if ws.has_window(window) { | 2439 | if ws.has_window(window) { |
| 2436 | - ws.start_close_animation_for_window(renderer, window); | 2440 | + ws.start_close_animation_for_window(renderer, window, blocker); |
| 2437 | return; | 2441 | return; |
| 2438 | } | 2442 | } |
| 2439 | } | 2443 | } |
| @@ -2442,7 +2446,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2442 | MonitorSet::NoOutputs { workspaces, .. } => { | 2446 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 2443 | for ws in workspaces { | 2447 | for ws in workspaces { |
| 2444 | if ws.has_window(window) { | 2448 | if ws.has_window(window) { |
| 2445 | - ws.start_close_animation_for_window(renderer, window); | 2449 | + ws.start_close_animation_for_window(renderer, window, blocker); |
| 2446 | return; | 2450 | return; |
| 2447 | } | 2451 | } |
| 2448 | } | 2452 | } |
| @@ -3143,7 +3147,7 @@ mod tests { | |||
| 3143 | layout.add_window_to_named_workspace(&ws_name, win, None, false); | 3147 | layout.add_window_to_named_workspace(&ws_name, win, None, false); |
| 3144 | } | 3148 | } |
| 3145 | Op::CloseWindow(id) => { | 3149 | Op::CloseWindow(id) => { |
| 3146 | - layout.remove_window(&id); | 3150 | + layout.remove_window(&id, Transaction::new()); |
| 3147 | } | 3151 | } |
| 3148 | Op::FullscreenWindow(id) => { | 3152 | Op::FullscreenWindow(id) => { |
| 3149 | layout.toggle_fullscreen(&id); | 3153 | layout.toggle_fullscreen(&id); |
src/layout/monitor.rsmodified+19 -3
| @@ -19,6 +19,7 @@ use crate::input::swipe_tracker::SwipeTracker; | |||
| 19 | use crate::render_helpers::renderer::NiriRenderer; | 19 | use crate::render_helpers::renderer::NiriRenderer; |
| 20 | use crate::render_helpers::RenderTarget; | 20 | use crate::render_helpers::RenderTarget; |
| 21 | use crate::rubber_band::RubberBand; | 21 | use crate::rubber_band::RubberBand; |
| 22 | +use crate::utils::transaction::Transaction; | ||
| 22 | use crate::utils::{output_size, to_physical_precise_round, ResizeEdge}; | 23 | use crate::utils::{output_size, to_physical_precise_round, ResizeEdge}; |
| 23 | 24 | ||
| 24 | /// Amount of touchpad movement to scroll the height of one workspace. | 25 | /// Amount of touchpad movement to scroll the height of one workspace. |
| @@ -442,7 +443,12 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 442 | let width = column.width; | 443 | let width = column.width; |
| 443 | let is_full_width = column.is_full_width; | 444 | let is_full_width = column.is_full_width; |
| 444 | let window = workspace | 445 | let window = workspace |
| 445 | - .remove_tile_by_idx(workspace.active_column_idx, column.active_tile_idx, None) | 446 | + .remove_tile_by_idx( |
| 447 | + workspace.active_column_idx, | ||
| 448 | + column.active_tile_idx, | ||
| 449 | + Transaction::new(), | ||
| 450 | + None, | ||
| 451 | + ) | ||
| 446 | .into_window(); | 452 | .into_window(); |
| 447 | 453 | ||
| 448 | self.add_window(new_idx, window, true, width, is_full_width); | 454 | self.add_window(new_idx, window, true, width, is_full_width); |
| @@ -465,7 +471,12 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 465 | let width = column.width; | 471 | let width = column.width; |
| 466 | let is_full_width = column.is_full_width; | 472 | let is_full_width = column.is_full_width; |
| 467 | let window = workspace | 473 | let window = workspace |
| 468 | - .remove_tile_by_idx(workspace.active_column_idx, column.active_tile_idx, None) | 474 | + .remove_tile_by_idx( |
| 475 | + workspace.active_column_idx, | ||
| 476 | + column.active_tile_idx, | ||
| 477 | + Transaction::new(), | ||
| 478 | + None, | ||
| 479 | + ) | ||
| 469 | .into_window(); | 480 | .into_window(); |
| 470 | 481 | ||
| 471 | self.add_window(new_idx, window, true, width, is_full_width); | 482 | self.add_window(new_idx, window, true, width, is_full_width); |
| @@ -488,7 +499,12 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 488 | let width = column.width; | 499 | let width = column.width; |
| 489 | let is_full_width = column.is_full_width; | 500 | let is_full_width = column.is_full_width; |
| 490 | let window = workspace | 501 | let window = workspace |
| 491 | - .remove_tile_by_idx(workspace.active_column_idx, column.active_tile_idx, None) | 502 | + .remove_tile_by_idx( |
| 503 | + workspace.active_column_idx, | ||
| 504 | + column.active_tile_idx, | ||
| 505 | + Transaction::new(), | ||
| 506 | + None, | ||
| 507 | + ) | ||
| 492 | .into_window(); | 508 | .into_window(); |
| 493 | 509 | ||
| 494 | self.add_window(new_idx, window, true, width, is_full_width); | 510 | self.add_window(new_idx, window, true, width, is_full_width); |
src/layout/workspace.rsmodified+46 -11
| @@ -22,7 +22,7 @@ use crate::niri_render_elements; | |||
| 22 | use crate::render_helpers::renderer::NiriRenderer; | 22 | use crate::render_helpers::renderer::NiriRenderer; |
| 23 | use crate::render_helpers::RenderTarget; | 23 | use crate::render_helpers::RenderTarget; |
| 24 | use crate::utils::id::IdCounter; | 24 | use crate::utils::id::IdCounter; |
| 25 | -use crate::utils::transaction::Transaction; | 25 | +use crate::utils::transaction::{Transaction, TransactionBlocker}; |
| 26 | use crate::utils::{output_size, send_scale_transform, ResizeEdge}; | 26 | use crate::utils::{output_size, send_scale_transform, ResizeEdge}; |
| 27 | use crate::window::ResolvedWindowRules; | 27 | use crate::window::ResolvedWindowRules; |
| 28 | 28 | ||
| @@ -1098,6 +1098,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1098 | &mut self, | 1098 | &mut self, |
| 1099 | column_idx: usize, | 1099 | column_idx: usize, |
| 1100 | window_idx: usize, | 1100 | window_idx: usize, |
| 1101 | + transaction: Transaction, | ||
| 1101 | anim_config: Option<niri_config::Animation>, | 1102 | anim_config: Option<niri_config::Animation>, |
| 1102 | ) -> Tile<W> { | 1103 | ) -> Tile<W> { |
| 1103 | let offset = self.column_x(column_idx + 1) - self.column_x(column_idx); | 1104 | let offset = self.column_x(column_idx + 1) - self.column_x(column_idx); |
| @@ -1139,7 +1140,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1139 | offset | 1140 | offset |
| 1140 | } else { | 1141 | } else { |
| 1141 | column.active_tile_idx = min(column.active_tile_idx, column.tiles.len() - 1); | 1142 | column.active_tile_idx = min(column.active_tile_idx, column.tiles.len() - 1); |
| 1142 | - column.update_tile_sizes(true); | 1143 | + column.update_tile_sizes_with_transaction(true, transaction); |
| 1143 | self.data[column_idx].update(column); | 1144 | self.data[column_idx].update(column); |
| 1144 | 1145 | ||
| 1145 | prev_width - column.width() | 1146 | prev_width - column.width() |
| @@ -1294,7 +1295,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1294 | column | 1295 | column |
| 1295 | } | 1296 | } |
| 1296 | 1297 | ||
| 1297 | - pub fn remove_window(&mut self, window: &W::Id) -> W { | 1298 | + pub fn remove_window(&mut self, window: &W::Id, transaction: Transaction) -> W { |
| 1298 | let column_idx = self | 1299 | let column_idx = self |
| 1299 | .columns | 1300 | .columns |
| 1300 | .iter() | 1301 | .iter() |
| @@ -1303,7 +1304,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1303 | let column = &self.columns[column_idx]; | 1304 | let column = &self.columns[column_idx]; |
| 1304 | 1305 | ||
| 1305 | let window_idx = column.position(window).unwrap(); | 1306 | let window_idx = column.position(window).unwrap(); |
| 1306 | - self.remove_tile_by_idx(column_idx, window_idx, None) | 1307 | + self.remove_tile_by_idx(column_idx, window_idx, transaction, None) |
| 1307 | .into_window() | 1308 | .into_window() |
| 1308 | } | 1309 | } |
| 1309 | 1310 | ||
| @@ -1490,6 +1491,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1490 | &mut self, | 1491 | &mut self, |
| 1491 | renderer: &mut GlesRenderer, | 1492 | renderer: &mut GlesRenderer, |
| 1492 | window: &W::Id, | 1493 | window: &W::Id, |
| 1494 | + blocker: TransactionBlocker, | ||
| 1493 | ) { | 1495 | ) { |
| 1494 | let output_scale = Scale::from(self.scale.fractional_scale()); | 1496 | let output_scale = Scale::from(self.scale.fractional_scale()); |
| 1495 | 1497 | ||
| @@ -1542,7 +1544,21 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1542 | 1544 | ||
| 1543 | let anim = Animation::new(0., 1., 0., self.options.animations.window_close.anim); | 1545 | let anim = Animation::new(0., 1., 0., self.options.animations.window_close.anim); |
| 1544 | 1546 | ||
| 1545 | - let res = ClosingWindow::new(renderer, snapshot, output_scale, tile_size, tile_pos, anim); | 1547 | + let blocker = if self.options.disable_transactions { |
| 1548 | + TransactionBlocker::completed() | ||
| 1549 | + } else { | ||
| 1550 | + blocker | ||
| 1551 | + }; | ||
| 1552 | + | ||
| 1553 | + let res = ClosingWindow::new( | ||
| 1554 | + renderer, | ||
| 1555 | + snapshot, | ||
| 1556 | + output_scale, | ||
| 1557 | + tile_size, | ||
| 1558 | + tile_pos, | ||
| 1559 | + blocker, | ||
| 1560 | + anim, | ||
| 1561 | + ); | ||
| 1546 | match res { | 1562 | match res { |
| 1547 | Ok(closing) => { | 1563 | Ok(closing) => { |
| 1548 | self.closing_windows.push(closing); | 1564 | self.closing_windows.push(closing); |
| @@ -1781,6 +1797,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1781 | let tile = self.remove_tile_by_idx( | 1797 | let tile = self.remove_tile_by_idx( |
| 1782 | source_col_idx, | 1798 | source_col_idx, |
| 1783 | 0, | 1799 | 0, |
| 1800 | + Transaction::new(), | ||
| 1784 | Some(self.options.animations.window_movement.0), | 1801 | Some(self.options.animations.window_movement.0), |
| 1785 | ); | 1802 | ); |
| 1786 | self.enter_output_for_window(tile.window()); | 1803 | self.enter_output_for_window(tile.window()); |
| @@ -1813,7 +1830,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1813 | 1830 | ||
| 1814 | let mut offset = Point::from((source_column.render_offset().x, 0.)); | 1831 | let mut offset = Point::from((source_column.render_offset().x, 0.)); |
| 1815 | 1832 | ||
| 1816 | - let tile = self.remove_tile_by_idx(source_col_idx, source_column.active_tile_idx, None); | 1833 | + let tile = self.remove_tile_by_idx( |
| 1834 | + source_col_idx, | ||
| 1835 | + source_column.active_tile_idx, | ||
| 1836 | + Transaction::new(), | ||
| 1837 | + None, | ||
| 1838 | + ); | ||
| 1817 | 1839 | ||
| 1818 | self.add_tile_at( | 1840 | self.add_tile_at( |
| 1819 | self.active_column_idx, | 1841 | self.active_column_idx, |
| @@ -1861,6 +1883,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1861 | let tile = self.remove_tile_by_idx( | 1883 | let tile = self.remove_tile_by_idx( |
| 1862 | source_col_idx, | 1884 | source_col_idx, |
| 1863 | 0, | 1885 | 0, |
| 1886 | + Transaction::new(), | ||
| 1864 | Some(self.options.animations.window_movement.0), | 1887 | Some(self.options.animations.window_movement.0), |
| 1865 | ); | 1888 | ); |
| 1866 | self.enter_output_for_window(tile.window()); | 1889 | self.enter_output_for_window(tile.window()); |
| @@ -1888,7 +1911,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1888 | let width = source_column.width; | 1911 | let width = source_column.width; |
| 1889 | let is_full_width = source_column.is_full_width; | 1912 | let is_full_width = source_column.is_full_width; |
| 1890 | 1913 | ||
| 1891 | - let tile = self.remove_tile_by_idx(source_col_idx, source_column.active_tile_idx, None); | 1914 | + let tile = self.remove_tile_by_idx( |
| 1915 | + source_col_idx, | ||
| 1916 | + source_column.active_tile_idx, | ||
| 1917 | + Transaction::new(), | ||
| 1918 | + None, | ||
| 1919 | + ); | ||
| 1892 | 1920 | ||
| 1893 | self.add_tile( | 1921 | self.add_tile( |
| 1894 | tile, | 1922 | tile, |
| @@ -1921,7 +1949,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1921 | let mut offset = Point::from((offset, 0.)); | 1949 | let mut offset = Point::from((offset, 0.)); |
| 1922 | let prev_off = self.columns[source_column_idx].tile_offset(0); | 1950 | let prev_off = self.columns[source_column_idx].tile_offset(0); |
| 1923 | 1951 | ||
| 1924 | - let tile = self.remove_tile_by_idx(source_column_idx, 0, None); | 1952 | + let tile = self.remove_tile_by_idx(source_column_idx, 0, Transaction::new(), None); |
| 1925 | self.enter_output_for_window(tile.window()); | 1953 | self.enter_output_for_window(tile.window()); |
| 1926 | 1954 | ||
| 1927 | let prev_next_x = self.column_x(self.active_column_idx + 1); | 1955 | let prev_next_x = self.column_x(self.active_column_idx + 1); |
| @@ -1970,8 +1998,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1970 | 1998 | ||
| 1971 | let width = source_column.width; | 1999 | let width = source_column.width; |
| 1972 | let is_full_width = source_column.is_full_width; | 2000 | let is_full_width = source_column.is_full_width; |
| 1973 | - let tile = | 2001 | + let tile = self.remove_tile_by_idx( |
| 1974 | - self.remove_tile_by_idx(self.active_column_idx, source_column.active_tile_idx, None); | 2002 | + self.active_column_idx, |
| 2003 | + source_column.active_tile_idx, | ||
| 2004 | + Transaction::new(), | ||
| 2005 | + None, | ||
| 2006 | + ); | ||
| 1975 | 2007 | ||
| 1976 | self.add_tile( | 2008 | self.add_tile( |
| 1977 | tile, | 2009 | tile, |
| @@ -3031,6 +3063,10 @@ impl<W: LayoutElement> Column<W> { | |||
| 3031 | } | 3063 | } |
| 3032 | 3064 | ||
| 3033 | fn update_tile_sizes(&mut self, animate: bool) { | 3065 | fn update_tile_sizes(&mut self, animate: bool) { |
| 3066 | + self.update_tile_sizes_with_transaction(animate, Transaction::new()); | ||
| 3067 | + } | ||
| 3068 | + | ||
| 3069 | + fn update_tile_sizes_with_transaction(&mut self, animate: bool, transaction: Transaction) { | ||
| 3034 | if self.is_fullscreen { | 3070 | if self.is_fullscreen { |
| 3035 | self.tiles[0].request_fullscreen(self.view_size); | 3071 | self.tiles[0].request_fullscreen(self.view_size); |
| 3036 | return; | 3072 | return; |
| @@ -3195,7 +3231,6 @@ impl<W: LayoutElement> Column<W> { | |||
| 3195 | assert_eq!(auto_tiles_left, 0); | 3231 | assert_eq!(auto_tiles_left, 0); |
| 3196 | } | 3232 | } |
| 3197 | 3233 | ||
| 3198 | - let transaction = Transaction::new(); | ||
| 3199 | for (tile, h) in zip(&mut self.tiles, heights) { | 3234 | for (tile, h) in zip(&mut self.tiles, heights) { |
| 3200 | let WindowHeight::Fixed(height) = h else { | 3235 | let WindowHeight::Fixed(height) = h else { |
| 3201 | unreachable!() | 3236 | unreachable!() |
src/utils/transaction.rsmodified+6 -0
| @@ -148,6 +148,12 @@ impl Drop for Transaction { | |||
| 148 | } | 148 | } |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | +impl TransactionBlocker { | ||
| 152 | + pub fn completed() -> Self { | ||
| 153 | + Self(Weak::new()) | ||
| 154 | + } | ||
| 155 | +} | ||
| 156 | + | ||
| 151 | impl Blocker for TransactionBlocker { | 157 | impl Blocker for TransactionBlocker { |
| 152 | fn state(&self) -> BlockerState { | 158 | fn state(&self) -> BlockerState { |
| 153 | if self.0.upgrade().map_or(true, |x| x.is_completed()) { | 159 | if self.0.upgrade().map_or(true, |x| x.is_completed()) { |