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 | |
parent | 17fb18ae4b8f34c41fa6ebd1bfa0973b4c7a441e (diff) |
feature; toml based config
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Cargo.lock | 149 | ||||
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | src/main.rs | 28 |
4 files changed, 176 insertions, 13 deletions
@@ -2,9 +2,5 @@ | |||
2 | # will have compiled files and executables | 2 | # will have compiled files and executables |
3 | /target/ | 3 | /target/ |
4 | 4 | ||
5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
7 | Cargo.lock | ||
8 | |||
9 | # These are backup files generated by rustfmt | 5 | # These are backup files generated by rustfmt |
10 | **/*.rs.bk | 6 | **/*.rs.bk |
diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..38e044c --- /dev/null +++ b/Cargo.lock | |||
@@ -0,0 +1,149 @@ | |||
1 | # This file is automatically @generated by Cargo. | ||
2 | # It is not intended for manual editing. | ||
3 | [[package]] | ||
4 | name = "cfg-if" | ||
5 | version = "0.1.10" | ||
6 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
7 | |||
8 | [[package]] | ||
9 | name = "confy" | ||
10 | version = "0.3.1" | ||
11 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
12 | dependencies = [ | ||
13 | "directories 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
14 | "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", | ||
15 | "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", | ||
16 | ] | ||
17 | |||
18 | [[package]] | ||
19 | name = "directories" | ||
20 | version = "0.10.0" | ||
21 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
22 | dependencies = [ | ||
23 | "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||
24 | ] | ||
25 | |||
26 | [[package]] | ||
27 | name = "libc" | ||
28 | version = "0.2.65" | ||
29 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
30 | |||
31 | [[package]] | ||
32 | name = "log" | ||
33 | version = "0.4.8" | ||
34 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
35 | dependencies = [ | ||
36 | "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", | ||
37 | ] | ||
38 | |||
39 | [[package]] | ||
40 | name = "proc-macro2" | ||
41 | version = "1.0.6" | ||
42 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
43 | dependencies = [ | ||
44 | "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
45 | ] | ||
46 | |||
47 | [[package]] | ||
48 | name = "quote" | ||
49 | version = "1.0.2" | ||
50 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
51 | dependencies = [ | ||
52 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
53 | ] | ||
54 | |||
55 | [[package]] | ||
56 | name = "serde" | ||
57 | version = "1.0.103" | ||
58 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
59 | dependencies = [ | ||
60 | "serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", | ||
61 | ] | ||
62 | |||
63 | [[package]] | ||
64 | name = "serde_derive" | ||
65 | version = "1.0.103" | ||
66 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
67 | dependencies = [ | ||
68 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
69 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", | ||
70 | "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||
71 | ] | ||
72 | |||
73 | [[package]] | ||
74 | name = "syn" | ||
75 | version = "1.0.8" | ||
76 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
77 | dependencies = [ | ||
78 | "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
79 | "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", | ||
80 | "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
81 | ] | ||
82 | |||
83 | [[package]] | ||
84 | name = "toml" | ||
85 | version = "0.4.10" | ||
86 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
87 | dependencies = [ | ||
88 | "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", | ||
89 | ] | ||
90 | |||
91 | [[package]] | ||
92 | name = "unicode-xid" | ||
93 | version = "0.2.0" | ||
94 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
95 | |||
96 | [[package]] | ||
97 | name = "winapi" | ||
98 | version = "0.3.8" | ||
99 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
100 | dependencies = [ | ||
101 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
102 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
103 | ] | ||
104 | |||
105 | [[package]] | ||
106 | name = "winapi-i686-pc-windows-gnu" | ||
107 | version = "0.4.0" | ||
108 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
109 | |||
110 | [[package]] | ||
111 | name = "winapi-x86_64-pc-windows-gnu" | ||
112 | version = "0.4.0" | ||
113 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
114 | |||
115 | [[package]] | ||
116 | name = "xcb" | ||
117 | version = "0.9.0" | ||
118 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
119 | dependencies = [ | ||
120 | "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", | ||
121 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||
122 | ] | ||
123 | |||
124 | [[package]] | ||
125 | name = "xcursorlocate" | ||
126 | version = "0.1.1" | ||
127 | dependencies = [ | ||
128 | "confy 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
129 | "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", | ||
130 | "xcb 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
131 | ] | ||
132 | |||
133 | [metadata] | ||
134 | "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" | ||
135 | "checksum confy 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4b1400cd0dae7f27d2c7ced9492e1398d2e2df614570092a4936c73b416dedea" | ||
136 | "checksum directories 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc2561db021b6f1321d0f16b67ed28ce843ef4610dfaa432e3ffa2e8a3050ebf" | ||
137 | "checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" | ||
138 | "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" | ||
139 | "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" | ||
140 | "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" | ||
141 | "checksum serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "1217f97ab8e8904b57dd22eb61cde455fa7446a9c1cf43966066da047c1f3702" | ||
142 | "checksum serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "a8c6faef9a2e64b0064f48570289b4bf8823b7581f1d6157c1b52152306651d0" | ||
143 | "checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" | ||
144 | "checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" | ||
145 | "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" | ||
146 | "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" | ||
147 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | ||
148 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" | ||
149 | "checksum xcb 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62056f63138b39116f82a540c983cc11f1c90cd70b3d492a70c25eaa50bd22a6" | ||
@@ -1,11 +1,17 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "xcursorlocate" | 2 | name = "xcursorlocate" |
3 | version = "0.1.0" | 3 | version = "0.1.1" |
4 | authors = ["Akshay <[email protected]>"] | 4 | authors = ["Akshay <[email protected]>"] |
5 | edition = "2018" | 5 | edition = "2018" |
6 | 6 | ||
7 | [dependencies] | ||
8 | confy = "0.3.1" | ||
7 | 9 | ||
8 | [dependencies.xcb] | 10 | [dependencies.xcb] |
9 | version = "0.9" | 11 | version = "0.9" |
10 | features = ["shape"] # NOTE: mapping and unmapping circular windows might be faster | 12 | features = ["shape"] # NOTE: mapping and unmapping circular windows might be faster |
11 | 13 | ||
14 | [dependencies.serde] | ||
15 | version = "1.0.103" | ||
16 | features = ["derive"] | ||
17 | |||
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 | ], |