diff options
author | Akshay <[email protected]> | 2019-11-27 18:40:23 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2019-11-27 18:40:23 +0000 |
commit | 1b41b089a12ced2ae93389d3732cb9339c3914f4 (patch) | |
tree | 70dee55d57915b520832d89c27eb595b1db1bfd0 | |
parent | 29c45aafe30e48af3fb7bc8ef5b944e1eb819973 (diff) |
do quicc maffs
-rw-r--r-- | src/main.rs | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/main.rs b/src/main.rs index d273e9f..f26d107 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -81,7 +81,7 @@ fn main() { | |||
81 | &[ | 81 | &[ |
82 | (xcb::GC_FOREGROUND, screen.white_pixel()), | 82 | (xcb::GC_FOREGROUND, screen.white_pixel()), |
83 | (xcb::GC_GRAPHICS_EXPOSURES, 0), | 83 | (xcb::GC_GRAPHICS_EXPOSURES, 0), |
84 | (xcb::GC_LINE_WIDTH, 1), | 84 | (xcb::GC_LINE_WIDTH, config.thickness), |
85 | ], | 85 | ], |
86 | ); | 86 | ); |
87 | 87 | ||
@@ -124,13 +124,13 @@ fn main() { | |||
124 | &[win_on_top_atom], | 124 | &[win_on_top_atom], |
125 | ); | 125 | ); |
126 | 126 | ||
127 | let mut circles = (1u16..10u16) | 127 | let mut circles = (0..config.no_of_circles) |
128 | .map(|i| { | 128 | .map(|i| { |
129 | xcb::Arc::new( | 129 | xcb::Arc::new( |
130 | win_start_x + 25 * i as i16, | 130 | (config.max_size as i16) / (2 * config.no_of_circles as i16) * i as i16, |
131 | win_start_y + 25 * i as i16, | 131 | (config.max_size as i16) / (2 * config.no_of_circles as i16) * i as i16, |
132 | win_width - 50 * i, | 132 | (config.max_size) - (config.max_size / config.no_of_circles) * i as u16, |
133 | win_height - 50 * i, | 133 | (config.max_size) - (config.max_size / config.no_of_circles) * i as u16, |
134 | 0, | 134 | 0, |
135 | 360 << 6, | 135 | 360 << 6, |
136 | ) | 136 | ) |
@@ -151,8 +151,31 @@ fn main() { | |||
151 | let r = e.response_type() & !0x80; | 151 | let r = e.response_type() & !0x80; |
152 | match r { | 152 | match r { |
153 | xcb::EXPOSE => { | 153 | xcb::EXPOSE => { |
154 | xcb::poly_arc(&conn, win, gfx_ctx, &[circles.next().unwrap()]); | 154 | let pointer = xcb::query_pointer(&conn, win).get_reply().unwrap(); |
155 | conn.flush(); | 155 | let p_x = pointer.root_x(); |
156 | let p_y = pointer.root_y(); | ||
157 | |||
158 | move_win_to_cursor(&conn, win, win_width, win_height, p_x, p_y); | ||
159 | |||
160 | let loop_start = Instant::now(); | ||
161 | let anim_duration = Duration::from_millis(config.duration as u64); | ||
162 | let circle_duration = | ||
163 | Duration::from_millis((config.duration / config.no_of_circles) as u64); | ||
164 | loop { | ||
165 | match circles.next() { | ||
166 | Some(c) => { | ||
167 | let _ = xcb::poly_arc(&conn, win, gfx_ctx, &[c]); | ||
168 | conn.flush(); | ||
169 | } | ||
170 | None => {} | ||
171 | }; | ||
172 | thread::sleep(circle_duration); | ||
173 | let now = Instant::now(); | ||
174 | if now.duration_since(loop_start) > anim_duration { | ||
175 | break; | ||
176 | } | ||
177 | } | ||
178 | thread::sleep(Duration::from_millis(100)); | ||
156 | break; | 179 | break; |
157 | } | 180 | } |
158 | _ => { | 181 | _ => { |
@@ -162,31 +185,6 @@ fn main() { | |||
162 | } | 185 | } |
163 | } | 186 | } |
164 | } | 187 | } |
165 | |||
166 | let pointer = xcb::query_pointer(&conn, win).get_reply().unwrap(); | ||
167 | let p_x = pointer.root_x(); | ||
168 | let p_y = pointer.root_y(); | ||
169 | |||
170 | move_win_to_cursor(&conn, win, win_width, win_height, p_x, p_y); | ||
171 | |||
172 | let loop_start = Instant::now(); | ||
173 | let anim_duration = Duration::from_millis(600); | ||
174 | let circle_duration = Duration::from_millis(60); | ||
175 | loop { | ||
176 | match circles.next() { | ||
177 | Some(c) => { | ||
178 | let _ = xcb::poly_arc(&conn, win, gfx_ctx, &[c]); | ||
179 | conn.flush(); | ||
180 | } | ||
181 | None => {} | ||
182 | }; | ||
183 | thread::sleep(circle_duration); | ||
184 | let now = Instant::now(); | ||
185 | if now.duration_since(loop_start) > anim_duration { | ||
186 | break; | ||
187 | } | ||
188 | } | ||
189 | thread::sleep(Duration::from_millis(100)); | ||
190 | } | 188 | } |
191 | 189 | ||
192 | fn move_win_to_cursor( | 190 | fn move_win_to_cursor( |