diff options
author | Akshay <[email protected]> | 2019-11-28 16:45:47 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2019-11-28 16:45:47 +0000 |
commit | 6d660c2f72c0651b78fbe8763f526c8cc48fb52f (patch) | |
tree | c93f68cf78f27acd7085cca4e0c36cd0c4ba09a6 /src | |
parent | 96ad746788aafd50fb0be069f515095c7a88f278 (diff) |
feature; add animations
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs index a32cec0..7dd3450 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -4,12 +4,19 @@ use std::time::{Duration, Instant}; | |||
4 | use serde::{Deserialize, Serialize}; | 4 | use serde::{Deserialize, Serialize}; |
5 | 5 | ||
6 | #[derive(Serialize, Deserialize)] | 6 | #[derive(Serialize, Deserialize)] |
7 | enum Animation { | ||
8 | Grow, | ||
9 | Shrink, | ||
10 | } | ||
11 | |||
12 | #[derive(Serialize, Deserialize)] | ||
7 | struct IndicatorConfig { | 13 | struct IndicatorConfig { |
8 | max_size: u16, // display pixels | 14 | max_size: u16, // display pixels |
9 | duration: u16, // milliseconds | 15 | duration: u16, // milliseconds |
10 | thickness: u32, // display pixels | 16 | thickness: u32, // display pixels |
11 | no_of_circles: u16, | 17 | no_of_circles: u16, // number of circles to display |
12 | color: u32, | 18 | color: u32, // color in hex, eg.: 0x00FECA |
19 | animation: Animation, // 'Grow' | 'Shrink' | ||
13 | } | 20 | } |
14 | 21 | ||
15 | // sane defaults | 22 | // sane defaults |
@@ -21,6 +28,7 @@ impl std::default::Default for IndicatorConfig { | |||
21 | thickness: 1, | 28 | thickness: 1, |
22 | no_of_circles: 5, | 29 | no_of_circles: 5, |
23 | color: 0xFFFFFF, | 30 | color: 0xFFFFFF, |
31 | animation: Animation::Grow, | ||
24 | } | 32 | } |
25 | } | 33 | } |
26 | } | 34 | } |
@@ -29,8 +37,7 @@ fn main() { | |||
29 | let config: IndicatorConfig = confy::load("xcursorlocate").unwrap(); | 37 | let config: IndicatorConfig = confy::load("xcursorlocate").unwrap(); |
30 | 38 | ||
31 | let padding = 10; // (???) largest circle gets clipped | 39 | let padding = 10; // (???) largest circle gets clipped |
32 | let win_width = config.max_size + padding; | 40 | let win_size = config.max_size + padding; |
33 | let win_height = config.max_size + padding; | ||
34 | 41 | ||
35 | let (conn, screen_num) = xcb::Connection::connect(None) | 42 | let (conn, screen_num) = xcb::Connection::connect(None) |
36 | .unwrap_or_else(|e| panic!("Unable to connect to X session: {}", e)); | 43 | .unwrap_or_else(|e| panic!("Unable to connect to X session: {}", e)); |
@@ -75,8 +82,8 @@ fn main() { | |||
75 | screen.root(), | 82 | screen.root(), |
76 | win_start_x, | 83 | win_start_x, |
77 | win_start_y, | 84 | win_start_y, |
78 | win_width, | 85 | win_size, |
79 | win_height, | 86 | win_size, |
80 | 0, | 87 | 0, |
81 | xcb::WINDOW_CLASS_INPUT_OUTPUT as u16, | 88 | xcb::WINDOW_CLASS_INPUT_OUTPUT as u16, |
82 | visual.visual_id(), | 89 | visual.visual_id(), |
@@ -140,8 +147,12 @@ fn main() { | |||
140 | &[win_on_top_atom], | 147 | &[win_on_top_atom], |
141 | ); | 148 | ); |
142 | 149 | ||
143 | let mut circles = (0..config.no_of_circles) | 150 | let range: Box<dyn DoubleEndedIterator<Item = u16>> = match config.animation { |
144 | .rev() // TODO: add grow/shrink as option | 151 | Animation::Grow => Box::new(0..config.no_of_circles), |
152 | Animation::Shrink => Box::new((0..config.no_of_circles).rev()), | ||
153 | }; | ||
154 | |||
155 | let mut circles = range | ||
145 | .map(|i| { | 156 | .map(|i| { |
146 | xcb::Arc::new( | 157 | xcb::Arc::new( |
147 | (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 |
@@ -171,7 +182,7 @@ fn main() { | |||
171 | let p_x = pointer.root_x(); | 182 | let p_x = pointer.root_x(); |
172 | let p_y = pointer.root_y(); | 183 | let p_y = pointer.root_y(); |
173 | 184 | ||
174 | move_win_to_cursor(&conn, win, win_width, win_height, p_x, p_y); | 185 | move_win_to_cursor(&conn, win, win_size, p_x, p_y); |
175 | 186 | ||
176 | let loop_start = Instant::now(); | 187 | let loop_start = Instant::now(); |
177 | let anim_duration = Duration::from_millis(config.duration as u64); | 188 | let anim_duration = Duration::from_millis(config.duration as u64); |
@@ -199,16 +210,9 @@ fn main() { | |||
199 | } | 210 | } |
200 | } | 211 | } |
201 | 212 | ||
202 | fn move_win_to_cursor( | 213 | fn move_win_to_cursor(conn: &xcb::Connection, win: u32, win_size: u16, p_x: i16, p_y: i16) { |
203 | conn: &xcb::Connection, | 214 | let win_x = p_x - (win_size as i16) / 2; |
204 | win: u32, | 215 | let win_y = p_y - (win_size as i16) / 2; |
205 | win_width: u16, | ||
206 | win_height: u16, | ||
207 | p_x: i16, | ||
208 | p_y: i16, | ||
209 | ) { | ||
210 | let win_x = p_x - (win_width as i16) / 2; | ||
211 | let win_y = p_y - (win_height as i16) / 2; | ||
212 | xcb::configure_window( | 216 | xcb::configure_window( |
213 | &conn, | 217 | &conn, |
214 | win, | 218 | win, |