diff options
-rw-r--r-- | src/main.rs | 37 |
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 @@ | |||
1 | use std::thread; | 1 | use std::thread; |
2 | use std::time::{Duration, Instant}; | 2 | use std::time::Duration; |
3 | 3 | ||
4 | use serde::{Deserialize, Serialize}; | 4 | use 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 | } |