mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
anime: tweak gif animation time types
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use rog_anime::Action;
|
||||
use rog_anime::{Action, AnimTime};
|
||||
use rog_dbus::AuraDbusClient;
|
||||
use rog_user::user_config::*;
|
||||
|
||||
@@ -27,20 +27,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let start = Instant::now();
|
||||
|
||||
match action {
|
||||
Action::Animation(frames) => 'animation: loop {
|
||||
for frame in frames.frames() {
|
||||
client.proxies().anime().write(frame.frame().clone())?;
|
||||
if let Some(time) = frames.duration() {
|
||||
if Instant::now().duration_since(start) > time {
|
||||
Action::Animation(frames) => {
|
||||
let mut count = 0;
|
||||
'animation: loop {
|
||||
for frame in frames.frames() {
|
||||
client.proxies().anime().write(frame.frame().clone())?;
|
||||
if let AnimTime::Time(time) = frames.duration() {
|
||||
if Instant::now().duration_since(start) > time {
|
||||
break 'animation;
|
||||
}
|
||||
}
|
||||
sleep(frame.delay());
|
||||
}
|
||||
if let AnimTime::Cycles(times) = frames.duration() {
|
||||
count += 1;
|
||||
if count >= times {
|
||||
break 'animation;
|
||||
}
|
||||
}
|
||||
sleep(frame.delay());
|
||||
}
|
||||
if frames.duration().is_none() {
|
||||
break 'animation;
|
||||
}
|
||||
},
|
||||
}
|
||||
Action::Image(image) => {
|
||||
client.proxies().anime().write(image.as_ref().clone())?;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use rog_anime::{Sequences, Vec2};
|
||||
use rog_anime::{AnimTime, Sequences, Vec2};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::Error;
|
||||
@@ -20,7 +20,7 @@ pub enum AnimeAction {
|
||||
/// Full gif sequence. Immutable.
|
||||
AsusAnimation {
|
||||
file: PathBuf,
|
||||
duration: Option<Duration>,
|
||||
time: AnimTime,
|
||||
brightness: f32,
|
||||
},
|
||||
/// Basic image, can have properties changed
|
||||
@@ -29,7 +29,7 @@ pub enum AnimeAction {
|
||||
scale: f32,
|
||||
angle: f32,
|
||||
translation: Vec2,
|
||||
duration: Option<Duration>,
|
||||
time: AnimTime,
|
||||
brightness: f32,
|
||||
},
|
||||
Image {
|
||||
@@ -45,12 +45,12 @@ pub enum AnimeAction {
|
||||
|
||||
impl UserConfig {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
let x = Self {
|
||||
anime: vec![
|
||||
AnimeAction::AsusAnimation {
|
||||
file: "/usr/share/asusd/anime/asus/rog/Sunset.gif".into(),
|
||||
brightness: 0.5,
|
||||
duration: None,
|
||||
time: AnimTime::Cycles(1),
|
||||
},
|
||||
AnimeAction::ImageAnimation {
|
||||
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
||||
@@ -58,7 +58,7 @@ impl UserConfig {
|
||||
angle: 0.65,
|
||||
translation: Vec2::default(),
|
||||
brightness: 0.5,
|
||||
duration: Some(Duration::from_secs(5)),
|
||||
time: AnimTime::Time(Duration::from_secs(5)),
|
||||
},
|
||||
AnimeAction::Image {
|
||||
file: "/usr/share/asusd/anime/custom/rust.png".into(),
|
||||
@@ -74,10 +74,12 @@ impl UserConfig {
|
||||
angle: 0.0,
|
||||
translation: Vec2::new(3.0, 2.0),
|
||||
brightness: 0.5,
|
||||
duration: None,
|
||||
time: AnimTime::Cycles(2),
|
||||
},
|
||||
],
|
||||
}
|
||||
};
|
||||
println!("{}", serde_json::to_string_pretty(&x).unwrap());
|
||||
x
|
||||
}
|
||||
|
||||
pub fn load_config(&mut self) -> Result<(), Error> {
|
||||
@@ -122,7 +124,7 @@ impl UserConfig {
|
||||
match anime {
|
||||
AnimeAction::AsusAnimation {
|
||||
file,
|
||||
duration,
|
||||
time: duration,
|
||||
brightness,
|
||||
} => seq.add_asus_gif(&file, *duration, *brightness)?,
|
||||
AnimeAction::ImageAnimation {
|
||||
@@ -130,7 +132,7 @@ impl UserConfig {
|
||||
scale,
|
||||
angle,
|
||||
translation,
|
||||
duration,
|
||||
time: duration,
|
||||
brightness,
|
||||
} => {
|
||||
seq.add_image_gif(&file, *scale, *angle, *translation, *duration, *brightness)?
|
||||
|
||||
Reference in New Issue
Block a user