aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2019-11-28 09:47:50 +0000
committerAkshay <[email protected]>2019-11-28 09:47:50 +0000
commit4c068a1a1151a06dfe7689cf290a49b8a0335a7b (patch)
tree6e9c02c9325202b94cc829d1e0962859b9ba2c8a /src
parentb3305076ed2739b8d6ed7a65e77bca20f03321b4 (diff)
bugfix; circles no longer clips
Diffstat (limited to 'src')
-rw-r--r--src/main.rs92
1 files changed, 44 insertions, 48 deletions
diff --git a/src/main.rs b/src/main.rs
index 35e5035..04162b5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,12 +11,14 @@ struct Configuration {
11fn main() { 11fn main() {
12 let config = Configuration { 12 let config = Configuration {
13 max_size: 200u16, 13 max_size: 200u16,
14 duration: 600u16, 14 duration: 500u16,
15 thickness: 1, 15 thickness: 1,
16 no_of_circles: 6, 16 no_of_circles: 5,
17 }; 17 };
18 let win_width = config.max_size; 18
19 let win_height = config.max_size; 19 let padding = 10; // (???) largest circle gets clipped
20 let win_width = config.max_size + padding;
21 let win_height = config.max_size + padding;
20 22
21 let (conn, screen_num) = xcb::Connection::connect(None) 23 let (conn, screen_num) = xcb::Connection::connect(None)
22 .unwrap_or_else(|e| panic!("Unable to connect to X session: {}", e)); 24 .unwrap_or_else(|e| panic!("Unable to connect to X session: {}", e));
@@ -130,12 +132,12 @@ fn main() {
130 .rev() // TODO: add grow/shrink as option 132 .rev() // TODO: add grow/shrink as option
131 .map(|i| { 133 .map(|i| {
132 xcb::Arc::new( 134 xcb::Arc::new(
133 (config.max_size as i16) / (2 * config.no_of_circles as i16) * i as i16, 135 (config.max_size as i16) / (2 * config.no_of_circles as i16) * i as i16, // x
134 (config.max_size as i16) / (2 * config.no_of_circles as i16) * i as i16, 136 (config.max_size as i16) / (2 * config.no_of_circles as i16) * i as i16, // y
135 (config.max_size) - (config.max_size / config.no_of_circles) * i as u16, 137 (config.max_size) - (config.max_size / config.no_of_circles) * i as u16, // width
136 (config.max_size) - (config.max_size / config.no_of_circles) * i as u16, 138 (config.max_size) - (config.max_size / config.no_of_circles) * i as u16, // height
137 0, 139 0, // start angle
138 360 << 6, 140 360 << 6, // end angle
139 ) 141 )
140 }) 142 })
141 .collect::<Vec<xcb::Arc>>() 143 .collect::<Vec<xcb::Arc>>()
@@ -144,48 +146,42 @@ fn main() {
144 xcb::map_window(&conn, win); 146 xcb::map_window(&conn, win);
145 conn.flush(); 147 conn.flush();
146 148
147 loop { 149 // wait till window is mapped
148 let event = conn.wait_for_event(); 150 let event = conn.wait_for_event();
149 match event { 151 match event {
150 None => { 152 None => {}
151 break; 153 Some(e) => {
152 } 154 let r = e.response_type() & !0x80;
153 Some(e) => { 155 match r {
154 let r = e.response_type() & !0x80; 156 // the window is mapped to display
155 match r { 157 xcb::EXPOSE => {
156 // the window is mapped to display 158 let pointer = xcb::query_pointer(&conn, win).get_reply().unwrap();
157 xcb::EXPOSE => { 159 let p_x = pointer.root_x();
158 let pointer = xcb::query_pointer(&conn, win).get_reply().unwrap(); 160 let p_y = pointer.root_y();
159 let p_x = pointer.root_x(); 161
160 let p_y = pointer.root_y(); 162 move_win_to_cursor(&conn, win, win_width, win_height, p_x, p_y);
161 163
162 move_win_to_cursor(&conn, win, win_width, win_height, p_x, p_y); 164 let loop_start = Instant::now();
163 165 let anim_duration = Duration::from_millis(config.duration as u64);
164 let loop_start = Instant::now(); 166 let circle_duration =
165 let anim_duration = Duration::from_millis(config.duration as u64); 167 Duration::from_millis((config.duration / config.no_of_circles) as u64);
166 let circle_duration = 168 loop {
167 Duration::from_millis((config.duration / config.no_of_circles) as u64); 169 match circles.next() {
168 loop { 170 Some(c) => {
169 match circles.next() { 171 let _ = xcb::poly_arc(&conn, win, gfx_ctx, &[c]);
170 Some(c) => { 172 conn.flush();
171 let _ = xcb::poly_arc(&conn, win, gfx_ctx, &[c]);
172 conn.flush();
173 }
174 None => {}
175 };
176 thread::sleep(circle_duration);
177 let now = Instant::now();
178 if now.duration_since(loop_start) > anim_duration {
179 break;
180 } 173 }
174 None => {}
175 };
176 thread::sleep(circle_duration);
177 let now = Instant::now();
178 if now.duration_since(loop_start) > anim_duration {
179 break;
181 } 180 }
182 thread::sleep(Duration::from_millis(100));
183 break;
184 }
185 _ => {
186 break;
187 } 181 }
182 thread::sleep(Duration::from_millis(100));
188 } 183 }
184 _ => {}
189 } 185 }
190 } 186 }
191 } 187 }