Make interactively moved window semitransparent
Browse files at this commit88614c08fe0a7833cbb749a6ecf3e703eb373c6eParent: 4f5c8e73 changed files +87 -3
- src/layout/mod.rs +64 -1
- src/layout/tile.rs +18 -2
- src/layout/workspace.rs +5 -0
src/layout/mod.rsmodified+64 -1
| @@ -93,6 +93,9 @@ pub const RESIZE_ANIMATION_THRESHOLD: f64 = 10.; | |||
| 93 | /// Pointer needs to move this far to pull a window from the layout. | 93 | /// Pointer needs to move this far to pull a window from the layout. |
| 94 | const INTERACTIVE_MOVE_START_THRESHOLD: f64 = 256. * 256.; | 94 | const INTERACTIVE_MOVE_START_THRESHOLD: f64 = 256. * 256.; |
| 95 | 95 | ||
| 96 | +/// Opacity of interactively moved tiles targeting the scrolling layout. | ||
| 97 | +const INTERACTIVE_MOVE_ALPHA: f64 = 0.75; | ||
| 98 | + | ||
| 96 | /// Size-relative units. | 99 | /// Size-relative units. |
| 97 | pub struct SizeFrac; | 100 | pub struct SizeFrac; |
| 98 | 101 | ||
| @@ -2334,6 +2337,34 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2334 | // Tile position must be rounded to physical pixels. | 2337 | // Tile position must be rounded to physical pixels. |
| 2335 | assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5); | 2338 | assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5); |
| 2336 | assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5); | 2339 | assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5); |
| 2340 | + | ||
| 2341 | + if let Some(alpha) = &move_.tile.alpha_animation { | ||
| 2342 | + if move_.is_floating { | ||
| 2343 | + assert_eq!( | ||
| 2344 | + alpha.anim.to(), | ||
| 2345 | + 1., | ||
| 2346 | + "interactively moved floating tile can animate alpha only to 1" | ||
| 2347 | + ); | ||
| 2348 | + | ||
| 2349 | + assert!( | ||
| 2350 | + !alpha.hold_after_done, | ||
| 2351 | + "interactively moved floating tile \ | ||
| 2352 | + cannot have held alpha animation" | ||
| 2353 | + ); | ||
| 2354 | + } else { | ||
| 2355 | + assert_ne!( | ||
| 2356 | + alpha.anim.to(), | ||
| 2357 | + 1., | ||
| 2358 | + "interactively moved scrolling tile must animate alpha to not 1" | ||
| 2359 | + ); | ||
| 2360 | + | ||
| 2361 | + assert!( | ||
| 2362 | + alpha.hold_after_done, | ||
| 2363 | + "interactively moved scrolling tile \ | ||
| 2364 | + must have held alpha animation" | ||
| 2365 | + ); | ||
| 2366 | + } | ||
| 2367 | + } | ||
| 2337 | } | 2368 | } |
| 2338 | } | 2369 | } |
| 2339 | } | 2370 | } |
| @@ -3005,6 +3036,21 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3005 | size.h = ensure_min_max_size_maybe_zero(size.h, min_size.h, max_size.h); | 3036 | size.h = ensure_min_max_size_maybe_zero(size.h, min_size.h, max_size.h); |
| 3006 | 3037 | ||
| 3007 | win.request_size_once(size, true); | 3038 | win.request_size_once(size, true); |
| 3039 | + | ||
| 3040 | + // Animate the tile back to opaque. | ||
| 3041 | + move_.tile.animate_alpha( | ||
| 3042 | + INTERACTIVE_MOVE_ALPHA, | ||
| 3043 | + 1., | ||
| 3044 | + self.options.animations.window_movement.0, | ||
| 3045 | + ); | ||
| 3046 | + } else { | ||
| 3047 | + // Animate the tile back to semitransparent. | ||
| 3048 | + move_.tile.animate_alpha( | ||
| 3049 | + 1., | ||
| 3050 | + INTERACTIVE_MOVE_ALPHA, | ||
| 3051 | + self.options.animations.window_movement.0, | ||
| 3052 | + ); | ||
| 3053 | + move_.tile.hold_alpha_animation_after_done(); | ||
| 3008 | } | 3054 | } |
| 3009 | 3055 | ||
| 3010 | return; | 3056 | return; |
| @@ -3773,6 +3819,16 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3773 | is_floating = unfullscreen_to_floating; | 3819 | is_floating = unfullscreen_to_floating; |
| 3774 | } | 3820 | } |
| 3775 | 3821 | ||
| 3822 | + // Animate to semitransparent. | ||
| 3823 | + if !is_floating { | ||
| 3824 | + tile.animate_alpha( | ||
| 3825 | + 1., | ||
| 3826 | + INTERACTIVE_MOVE_ALPHA, | ||
| 3827 | + self.options.animations.window_movement.0, | ||
| 3828 | + ); | ||
| 3829 | + tile.hold_alpha_animation_after_done(); | ||
| 3830 | + } | ||
| 3831 | + | ||
| 3776 | let mut data = InteractiveMoveData { | 3832 | let mut data = InteractiveMoveData { |
| 3777 | tile, | 3833 | tile, |
| 3778 | output, | 3834 | output, |
| @@ -3869,7 +3925,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3869 | return; | 3925 | return; |
| 3870 | } | 3926 | } |
| 3871 | 3927 | ||
| 3872 | - let Some(InteractiveMoveState::Moving(move_)) = self.interactive_move.take() else { | 3928 | + let Some(InteractiveMoveState::Moving(mut move_)) = self.interactive_move.take() else { |
| 3873 | unreachable!() | 3929 | unreachable!() |
| 3874 | }; | 3930 | }; |
| 3875 | 3931 | ||
| @@ -3878,6 +3934,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3878 | for ws in self.workspaces_mut() { | 3934 | for ws in self.workspaces_mut() { |
| 3879 | ws.dnd_scroll_gesture_end(); | 3935 | ws.dnd_scroll_gesture_end(); |
| 3880 | } | 3936 | } |
| 3937 | + | ||
| 3938 | + // Also animate the tile back to opaque. | ||
| 3939 | + move_.tile.animate_alpha( | ||
| 3940 | + INTERACTIVE_MOVE_ALPHA, | ||
| 3941 | + 1., | ||
| 3942 | + self.options.animations.window_movement.0, | ||
| 3943 | + ); | ||
| 3881 | } | 3944 | } |
| 3882 | 3945 | ||
| 3883 | match &mut self.monitor_set { | 3946 | match &mut self.monitor_set { |
src/layout/tile.rsmodified+18 -2
| @@ -148,6 +148,12 @@ struct MoveAnimation { | |||
| 148 | #[derive(Debug)] | 148 | #[derive(Debug)] |
| 149 | pub(super) struct AlphaAnimation { | 149 | pub(super) struct AlphaAnimation { |
| 150 | pub(super) anim: Animation, | 150 | pub(super) anim: Animation, |
| 151 | + /// Whether the animation should persist after it's done. | ||
| 152 | + /// | ||
| 153 | + /// This is used by things like interactive move which need to animate alpha to | ||
| 154 | + /// semitransparent, then hold it at semitransparent for a while, until the operation | ||
| 155 | + /// completes. | ||
| 156 | + pub(super) hold_after_done: bool, | ||
| 151 | offscreen: OffscreenBuffer, | 157 | offscreen: OffscreenBuffer, |
| 152 | } | 158 | } |
| 153 | 159 | ||
| @@ -319,7 +325,7 @@ impl<W: LayoutElement> Tile<W> { | |||
| 319 | } | 325 | } |
| 320 | 326 | ||
| 321 | if let Some(alpha) = &mut self.alpha_animation { | 327 | if let Some(alpha) = &mut self.alpha_animation { |
| 322 | - if alpha.anim.is_done() { | 328 | + if !alpha.hold_after_done && alpha.anim.is_done() { |
| 323 | self.alpha_animation = None; | 329 | self.alpha_animation = None; |
| 324 | } | 330 | } |
| 325 | } | 331 | } |
| @@ -334,7 +340,10 @@ impl<W: LayoutElement> Tile<W> { | |||
| 334 | || self.resize_animation.is_some() | 340 | || self.resize_animation.is_some() |
| 335 | || self.move_x_animation.is_some() | 341 | || self.move_x_animation.is_some() |
| 336 | || self.move_y_animation.is_some() | 342 | || self.move_y_animation.is_some() |
| 337 | - || self.alpha_animation.is_some() | 343 | + || self |
| 344 | + .alpha_animation | ||
| 345 | + .as_ref() | ||
| 346 | + .is_some_and(|alpha| !alpha.anim.is_done()) | ||
| 338 | } | 347 | } |
| 339 | 348 | ||
| 340 | pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) { | 349 | pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) { |
| @@ -491,6 +500,7 @@ impl<W: LayoutElement> Tile<W> { | |||
| 491 | 500 | ||
| 492 | self.alpha_animation = Some(AlphaAnimation { | 501 | self.alpha_animation = Some(AlphaAnimation { |
| 493 | anim: Animation::new(self.clock.clone(), current, to, 0., config), | 502 | anim: Animation::new(self.clock.clone(), current, to, 0., config), |
| 503 | + hold_after_done: false, | ||
| 494 | offscreen, | 504 | offscreen, |
| 495 | }); | 505 | }); |
| 496 | } | 506 | } |
| @@ -505,6 +515,12 @@ impl<W: LayoutElement> Tile<W> { | |||
| 505 | } | 515 | } |
| 506 | } | 516 | } |
| 507 | 517 | ||
| 518 | + pub fn hold_alpha_animation_after_done(&mut self) { | ||
| 519 | + if let Some(alpha) = &mut self.alpha_animation { | ||
| 520 | + alpha.hold_after_done = true; | ||
| 521 | + } | ||
| 522 | + } | ||
| 523 | + | ||
| 508 | pub fn window(&self) -> &W { | 524 | pub fn window(&self) -> &W { |
| 509 | &self.window | 525 | &self.window |
| 510 | } | 526 | } |
src/layout/workspace.rsmodified+5 -0
| @@ -1757,6 +1757,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1757 | if visible { | 1757 | if visible { |
| 1758 | assert_eq!(anim.to(), 1., "visible tiles can animate alpha only to 1"); | 1758 | assert_eq!(anim.to(), 1., "visible tiles can animate alpha only to 1"); |
| 1759 | } | 1759 | } |
| 1760 | + | ||
| 1761 | + assert!( | ||
| 1762 | + !alpha.hold_after_done, | ||
| 1763 | + "tiles in the layout cannot have held alpha animation" | ||
| 1764 | + ); | ||
| 1760 | } | 1765 | } |
| 1761 | } | 1766 | } |
| 1762 | } | 1767 | } |