| 1 |
extern crate cairo;
|
| 2 |
|
| 3 |
use std::io::Write;
|
| 4 |
use std::{time,thread};
|
| 5 |
|
| 6 |
const XSIZE: i32 = 1024;
|
| 7 |
const YSIZE: i32 = 768;
|
| 8 |
const XCENTER: f64 = XSIZE as f64 / 2.0;
|
| 9 |
const YCENTER: f64 = YSIZE as f64 / 2.0;
|
| 10 |
const TAU: f64 = 2.0 * std::f64::consts::PI;
|
| 11 |
|
| 12 |
/// Return `true` if slim has started, `false` otherwise
|
| 13 |
fn check_slim() -> bool {
|
| 14 |
use std::process::{Command};
|
| 15 |
|
| 16 |
let o = Command::new("sv")
|
| 17 |
.args(&["status", "slim"])
|
| 18 |
.output()
|
| 19 |
.unwrap();
|
| 20 |
String::from_utf8_lossy(&o.stdout).contains("run")
|
| 21 |
}
|
| 22 |
|
| 23 |
/// draw a clock on the surface
|
| 24 |
fn draw(surf: &cairo::ImageSurface, t: usize) {
|
| 25 |
let ctx = cairo::Context::new(&surf);
|
| 26 |
ctx.set_source_rgb(0.6, 0.6, 0.6);
|
| 27 |
ctx.paint();
|
| 28 |
|
| 29 |
ctx.set_source_rgb(0.0, 0.0, 0.0);
|
| 30 |
ctx.set_line_width(12.0);
|
| 31 |
ctx.arc(XCENTER, YCENTER, 200.0, 0.0, TAU);
|
| 32 |
ctx.stroke();
|
| 33 |
|
| 34 |
let theta = (t as f64 / 24.0) * TAU;
|
| 35 |
ctx.move_to(XCENTER, YCENTER);
|
| 36 |
ctx.line_to(
|
| 37 |
XCENTER + theta.sin() * 200.0,
|
| 38 |
YCENTER + theta.cos() * 200.0,
|
| 39 |
);
|
| 40 |
ctx.stroke();
|
| 41 |
}
|
| 42 |
|
| 43 |
fn main() {
|
| 44 |
let mut surf = cairo::ImageSurface::create(
|
| 45 |
cairo::Format::Rgb24,
|
| 46 |
XSIZE,
|
| 47 |
YSIZE,
|
| 48 |
).unwrap();
|
| 49 |
let mut t: usize = 0;
|
| 50 |
|
| 51 |
while !check_slim() {
|
| 52 |
t = (t + 1) % 24;
|
| 53 |
draw(&surf, t);
|
| 54 |
|
| 55 |
let mut f = std::fs::File::create("/dev/fb0").unwrap();
|
| 56 |
f.write(&surf.get_data().unwrap()).unwrap();
|
| 57 |
|
| 58 |
thread::sleep(time::Duration::from_millis(50));
|
| 59 |
}
|
| 60 |
}
|