Skip to main content

arc_motion/
reduced_motion.rs

1//! Ported from Arc (MIT) © 2026 Elia Kuratli
2//! Reduced-motion wrappers over `gpui_kit::App::reduce_motion()` and
3//! `gpui_kit::base::set_reduce_motion_preference`.
4
5use gpui_kit::{
6    App,
7    base::{ReduceMotionPreference, set_reduce_motion_preference},
8};
9
10/// Returns whether reduced motion is currently active in GPUI.
11#[inline]
12pub fn is_reduced_motion(cx: &App) -> bool {
13    cx.reduce_motion()
14}
15
16/// Application-level reduced motion override (used by `arc-gallery` toggle and tests).
17#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
18pub enum ReducedMotionChoice {
19    #[default]
20    System,
21    Reduce,
22    Allow,
23}
24
25pub fn set_reduced_motion(choice: ReducedMotionChoice, cx: &mut App) {
26    let pref = match choice {
27        ReducedMotionChoice::System => ReduceMotionPreference::System,
28        ReducedMotionChoice::Reduce => ReduceMotionPreference::Reduce,
29        ReducedMotionChoice::Allow => ReduceMotionPreference::Allow,
30    };
31    set_reduce_motion_preference(pref, cx);
32}
33
34#[cfg(test)]
35mod tests {
36    use gpui_kit::TestAppContext;
37
38    use super::*;
39
40    #[gpui_kit::test]
41    fn reduced_motion_toggle_updates_app_flag(cx: &mut TestAppContext) {
42        cx.update(|cx| {
43            gpui_kit::init(cx);
44            set_reduced_motion(ReducedMotionChoice::Reduce, cx);
45            assert!(is_reduced_motion(cx));
46            set_reduced_motion(ReducedMotionChoice::Allow, cx);
47            assert!(!is_reduced_motion(cx));
48        });
49    }
50}