Compare commits

...

1 Commits

3 changed files with 20 additions and 33 deletions

1
Cargo.lock generated
View File

@ -844,6 +844,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
name = "wl-seasonal-hours-clock"
version = "0.1.0"
dependencies = [
"calloop",
"chrono",
"resvg",
"serde",

View File

@ -14,3 +14,4 @@ suncalc = "0.4"
toml = "0.5"
serde = { version = "1.0", features = ["derive"] }
xdg = "2.4"
calloop = "0.9"

View File

@ -2,8 +2,8 @@ extern crate smithay_client_toolkit as sctk;
use std::fmt;
use std::fs;
use std::time::SystemTime;
use calloop::{timer::{Timer, TimerHandle}, EventLoop};
use chrono::prelude::{Local, Utc};
use chrono::TimeZone;
use chrono::Timelike;
@ -633,7 +633,7 @@ fn main() {
None
};
let (env, display, mut queue) = sctk::new_default_environment!(SeasonalClock, desktop)
let (env, display, queue) = sctk::new_default_environment!(SeasonalClock, desktop)
.expect("Unable to connect to a Wayland compositor");
let surface = env
@ -679,25 +679,23 @@ fn main() {
window.refresh()
}
let now = SystemTime::now();
let mut last_elapsed = 0;
let mut event_loop = EventLoop::<Option<WEvent>>::try_new().unwrap();
let handle = event_loop.handle();
let source = Timer::new().expect("Failed to create timer event source!");
let timer_handle = source.handle();
timer_handle.add_timeout(std::time::Duration::from_secs(1), "");
handle.insert_source(source, |_, timer_handle, _| {
println!("Redraw!");
redraw(&mut pool, window.surface(), dimensions).expect("Failed to draw");
window.refresh();
timer_handle.add_timeout(std::time::Duration::from_secs(1), "");
});
sctk::WaylandSource::new(queue).quick_insert(handle).unwrap();
loop {
// Update every second
// TODO: Theres probably a better way to do this…
match now.elapsed() {
Ok(elapsed) => {
let new_elapsed = elapsed.as_secs();
if new_elapsed != last_elapsed {
need_redraw = true;
last_elapsed = new_elapsed;
}
}
Err(e) => {
println!("Error: {:?}", e);
}
}
match next_action.take() {
Some(WEvent::Close) => break,
Some(WEvent::Refresh) => {
@ -732,20 +730,7 @@ fn main() {
}
}
if let Some(guard) = queue.prepare_read() {
if let Err(e) = guard.read_events() {
if e.kind() != ::std::io::ErrorKind::WouldBlock {
eprintln!(
"Error while trying to read from the wayland socked: {:?}",
e
);
}
}
}
queue
.dispatch_pending(&mut next_action, |_, _, _| {})
.expect("Failed to dispatch all messages.");
event_loop.dispatch(None, &mut next_action).unwrap();
}
}