aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-07-08 11:24:08 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-07-08 11:24:08 +0400
commit451366308446aeb8ae4ee1cd55559381e93b9b39 (patch)
tree6d2b3954fe20691e899fcc74addf3d3ced7c97b6 /src
parent092cf6cfaf9c03303bd04e44df4374b79f550f21 (diff)
downloadniri-451366308446aeb8ae4ee1cd55559381e93b9b39.tar.gz
niri-451366308446aeb8ae4ee1cd55559381e93b9b39.tar.bz2
niri-451366308446aeb8ae4ee1cd55559381e93b9b39.zip
screenshot-ui: Animate opening
Diffstat (limited to 'src')
-rw-r--r--src/input/mod.rs2
-rw-r--r--src/niri.rs6
-rw-r--r--src/ui/screenshot_ui.rs72
3 files changed, 58 insertions, 22 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs
index d1ce4114..d96de0cb 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -2569,7 +2569,7 @@ mod tests {
let comp_mod = CompositorMod::Super;
let mut suppressed_keys = HashSet::new();
- let screenshot_ui = ScreenshotUi::new();
+ let screenshot_ui = ScreenshotUi::new(Default::default());
let disable_power_key_handling = false;
// The key_code we pick is arbitrary, the only thing
diff --git a/src/niri.rs b/src/niri.rs
index ce7a1c2f..664aea67 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -1589,7 +1589,7 @@ impl Niri {
let mods_with_finger_scroll_binds =
mods_with_finger_scroll_binds(backend.mod_key(), &config_.binds);
- let screenshot_ui = ScreenshotUi::new();
+ let screenshot_ui = ScreenshotUi::new(config.clone());
let config_error_notification = ConfigErrorNotification::new(config.clone());
let mut hotkey_overlay = HotkeyOverlay::new(config.clone(), backend.mod_key());
@@ -2973,6 +2973,10 @@ impl Niri {
state.unfinished_animations_remain |=
self.config_error_notification.are_animations_ongoing();
+ self.screenshot_ui
+ .advance_animations(target_presentation_time);
+ state.unfinished_animations_remain |= self.screenshot_ui.are_animations_ongoing();
+
// Also keep redrawing if the current cursor is animated.
state.unfinished_animations_remain |= self
.cursor_manager
diff --git a/src/ui/screenshot_ui.rs b/src/ui/screenshot_ui.rs
index d55073f8..0e2006a1 100644
--- a/src/ui/screenshot_ui.rs
+++ b/src/ui/screenshot_ui.rs
@@ -1,11 +1,13 @@
+use std::cell::RefCell;
use std::cmp::{max, min};
use std::collections::HashMap;
use std::iter::zip;
-use std::mem;
+use std::rc::Rc;
+use std::time::Duration;
use anyhow::Context;
use arrayvec::ArrayVec;
-use niri_config::Action;
+use niri_config::{Action, Config};
use pango::{Alignment, FontDescription};
use pangocairo::cairo::{self, ImageSurface};
use smithay::backend::allocator::Fourcc;
@@ -18,6 +20,7 @@ use smithay::input::keyboard::{Keysym, ModifiersState};
use smithay::output::{Output, WeakOutput};
use smithay::utils::{Physical, Point, Rectangle, Scale, Size, Transform};
+use crate::animation::Animation;
use crate::niri_render_elements;
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
@@ -42,15 +45,19 @@ const TEXT_SHOW_P: &str =
// allows only single-output selections for now.
//
// As a consequence of this, selection coordinates are in output-local coordinate space.
+#[allow(clippy::large_enum_variant)]
pub enum ScreenshotUi {
Closed {
last_selection: Option<(WeakOutput, Rectangle<i32, Physical>)>,
+ config: Rc<RefCell<Config>>,
},
Open {
selection: (Output, Point<i32, Physical>, Point<i32, Physical>),
output_data: HashMap<Output, OutputData>,
mouse_down: bool,
show_pointer: bool,
+ open_anim: Animation,
+ config: Rc<RefCell<Config>>,
},
}
@@ -79,9 +86,10 @@ niri_render_elements! {
}
impl ScreenshotUi {
- pub fn new() -> Self {
+ pub fn new(config: Rc<RefCell<Config>>) -> Self {
Self::Closed {
last_selection: None,
+ config,
}
}
@@ -96,7 +104,11 @@ impl ScreenshotUi {
return false;
}
- let Self::Closed { last_selection } = self else {
+ let Self::Closed {
+ last_selection,
+ config,
+ } = self
+ else {
return false;
};
@@ -167,11 +179,18 @@ impl ScreenshotUi {
})
.collect();
+ let open_anim = {
+ let c = config.borrow();
+ Animation::new(0., 1., 0., c.animations.screenshot_ui_open.0)
+ };
+
*self = Self::Open {
selection,
output_data,
mouse_down: false,
show_pointer: true,
+ open_anim,
+ config: config.clone(),
};
self.update_buffers();
@@ -180,13 +199,11 @@ impl ScreenshotUi {
}
pub fn close(&mut self) -> bool {
- let selection = match mem::take(self) {
- Self::Open { selection, .. } => selection,
- closed @ Self::Closed { .. } => {
- // Put it back.
- *self = closed;
- return false;
- }
+ let Self::Open {
+ selection, config, ..
+ } = self
+ else {
+ return false;
};
let last_selection = Some((
@@ -194,7 +211,10 @@ impl ScreenshotUi {
rect_from_corner_points(selection.1, selection.2),
));
- *self = Self::Closed { last_selection };
+ *self = Self::Closed {
+ last_selection,
+ config: config.clone(),
+ };
true
}
@@ -209,6 +229,22 @@ impl ScreenshotUi {
matches!(self, ScreenshotUi::Open { .. })
}
+ pub fn advance_animations(&mut self, current_time: Duration) {
+ let Self::Open { open_anim, .. } = self else {
+ return;
+ };
+
+ open_anim.set_current_time(current_time);
+ }
+
+ pub fn are_animations_ongoing(&self) -> bool {
+ let Self::Open { open_anim, .. } = self else {
+ return false;
+ };
+
+ !open_anim.is_done()
+ }
+
fn update_buffers(&mut self) {
let Self::Open {
selection,
@@ -293,6 +329,7 @@ impl ScreenshotUi {
output_data,
show_pointer,
mouse_down,
+ open_anim,
..
} = self
else {
@@ -306,6 +343,7 @@ impl ScreenshotUi {
};
let scale = output_data.scale;
+ let progress = open_anim.clamped_value().clamp(0., 1.) as f32;
// The help panel goes on top.
if let Some((show, hide)) = &output_data.panel {
@@ -324,7 +362,7 @@ impl ScreenshotUi {
let elem = PrimaryGpuTextureRenderElement(TextureRenderElement::from_texture_buffer(
buffer.clone(),
location,
- alpha,
+ alpha * progress,
None,
None,
Kind::Unspecified,
@@ -337,7 +375,7 @@ impl ScreenshotUi {
SolidColorRenderElement::from_buffer(
buffer,
loc.to_f64().to_logical(scale),
- 1.,
+ progress,
Kind::Unspecified,
)
.into()
@@ -530,12 +568,6 @@ impl ScreenshotUi {
}
}
-impl Default for ScreenshotUi {
- fn default() -> Self {
- Self::new()
- }
-}
-
impl OutputScreenshot {
pub fn from_textures(
renderer: &mut GlesRenderer,