aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2019-11-29 10:58:22 +0000
committerAkshay <[email protected]>2019-11-29 10:58:22 +0000
commitd7420dd7378e27832961bbdca1bc581a73bdd598 (patch)
treee5047b939f56189057db37149557f66e0e3974d7 /src
parent8893a1acc2d4d78a4a1c3b9d1ee47bc1503a0376 (diff)
improve animations
Diffstat (limited to 'src')
-rw-r--r--src/main.rs37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs
index 7dd3450..484a6c0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,5 @@
1use std::thread; 1use std::thread;
2use std::time::{Duration, Instant}; 2use std::time::Duration;
3 3
4use serde::{Deserialize, Serialize}; 4use serde::{Deserialize, Serialize};
5 5
@@ -148,11 +148,11 @@ fn main() {
148 ); 148 );
149 149
150 let range: Box<dyn DoubleEndedIterator<Item = u16>> = match config.animation { 150 let range: Box<dyn DoubleEndedIterator<Item = u16>> = match config.animation {
151 Animation::Grow => Box::new(0..config.no_of_circles), 151 Animation::Shrink => Box::new(0..config.no_of_circles),
152 Animation::Shrink => Box::new((0..config.no_of_circles).rev()), 152 Animation::Grow => Box::new((0..config.no_of_circles).rev()),
153 }; 153 };
154 154
155 let mut circles = range 155 let circles = range
156 .map(|i| { 156 .map(|i| {
157 xcb::Arc::new( 157 xcb::Arc::new(
158 (config.max_size as i16) / (2 * config.no_of_circles as i16) * i as i16, // x 158 (config.max_size as i16) / (2 * config.no_of_circles as i16) * i as i16, // x
@@ -184,27 +184,26 @@ fn main() {
184 184
185 move_win_to_cursor(&conn, win, win_size, p_x, p_y); 185 move_win_to_cursor(&conn, win, win_size, p_x, p_y);
186 186
187 let loop_start = Instant::now();
188 let anim_duration = Duration::from_millis(config.duration as u64);
189 let circle_duration = 187 let circle_duration =
190 Duration::from_millis((config.duration / config.no_of_circles) as u64); 188 Duration::from_millis((config.duration / config.no_of_circles) as u64);
191 loop { 189 for c in circles {
192 match circles.next() { 190 let _ = xcb::poly_arc(&conn, win, gfx_ctx, &[c]);
193 Some(c) => { 191 conn.flush();
194 let _ = xcb::poly_arc(&conn, win, gfx_ctx, &[c]);
195 conn.flush();
196 }
197 None => {}
198 };
199 thread::sleep(circle_duration); 192 thread::sleep(circle_duration);
200 let now = Instant::now(); 193 xcb::clear_area(
201 if now.duration_since(loop_start) > anim_duration { 194 &conn,
202 break; 195 false,
203 } 196 win,
197 c.x(),
198 c.y(),
199 c.width() + padding + config.thickness as u16,
200 c.height() + padding + config.thickness as u16,
201 );
202 conn.flush();
204 } 203 }
205 thread::sleep(Duration::from_millis(100)); 204 thread::sleep(Duration::from_millis(100));
206 } 205 }
207 _ => {} 206 _ => eprintln!("how did you even get here: {}", r),
208 } 207 }
209 } 208 }
210 } 209 }