diff options
author | Akshay <[email protected]> | 2019-11-28 10:50:57 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2019-11-28 10:50:57 +0000 |
commit | 3f1665f0a3b83b4010472f3a18d0dd6881c17f2b (patch) | |
tree | fd55d4c6641c33ae0e8127c3177f82a8a2006fd3 /src | |
parent | 17fb18ae4b8f34c41fa6ebd1bfa0973b4c7a441e (diff) |
feature; toml based config
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 04162b5..a32cec0 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,20 +1,32 @@ | |||
1 | use std::thread; | 1 | use std::thread; |
2 | use std::time::{Duration, Instant}; | 2 | use std::time::{Duration, Instant}; |
3 | 3 | ||
4 | struct Configuration { | 4 | use serde::{Deserialize, Serialize}; |
5 | |||
6 | #[derive(Serialize, Deserialize)] | ||
7 | struct IndicatorConfig { | ||
5 | max_size: u16, // display pixels | 8 | max_size: u16, // display pixels |
6 | duration: u16, // milliseconds | 9 | duration: u16, // milliseconds |
7 | thickness: u32, // display pixels | 10 | thickness: u32, // display pixels |
8 | no_of_circles: u16, | 11 | no_of_circles: u16, |
12 | color: u32, | ||
13 | } | ||
14 | |||
15 | // sane defaults | ||
16 | impl std::default::Default for IndicatorConfig { | ||
17 | fn default() -> IndicatorConfig { | ||
18 | IndicatorConfig { | ||
19 | max_size: 200u16, | ||
20 | duration: 500u16, | ||
21 | thickness: 1, | ||
22 | no_of_circles: 5, | ||
23 | color: 0xFFFFFF, | ||
24 | } | ||
25 | } | ||
9 | } | 26 | } |
10 | 27 | ||
11 | fn main() { | 28 | fn main() { |
12 | let config = Configuration { | 29 | let config: IndicatorConfig = confy::load("xcursorlocate").unwrap(); |
13 | max_size: 200u16, | ||
14 | duration: 500u16, | ||
15 | thickness: 1, | ||
16 | no_of_circles: 5, | ||
17 | }; | ||
18 | 30 | ||
19 | let padding = 10; // (???) largest circle gets clipped | 31 | let padding = 10; // (???) largest circle gets clipped |
20 | let win_width = config.max_size + padding; | 32 | let win_width = config.max_size + padding; |
@@ -83,7 +95,7 @@ fn main() { | |||
83 | gfx_ctx, | 95 | gfx_ctx, |
84 | win, | 96 | win, |
85 | &[ | 97 | &[ |
86 | (xcb::GC_FOREGROUND, screen.white_pixel()), // TODO: support different colors here | 98 | (xcb::GC_FOREGROUND, config.color), |
87 | (xcb::GC_GRAPHICS_EXPOSURES, 0), | 99 | (xcb::GC_GRAPHICS_EXPOSURES, 0), |
88 | (xcb::GC_LINE_WIDTH, config.thickness), | 100 | (xcb::GC_LINE_WIDTH, config.thickness), |
89 | ], | 101 | ], |