Compare commits
1 Commits
main
...
timer-refa
Author | SHA1 | Date | |
---|---|---|---|
6198a4a31f |
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -844,6 +844,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|||||||
name = "wl-seasonal-hours-clock"
|
name = "wl-seasonal-hours-clock"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"calloop",
|
||||||
"chrono",
|
"chrono",
|
||||||
"resvg",
|
"resvg",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -14,3 +14,4 @@ suncalc = "0.4"
|
|||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
xdg = "2.4"
|
xdg = "2.4"
|
||||||
|
calloop = "0.9"
|
||||||
|
49
src/main.rs
49
src/main.rs
@ -2,8 +2,8 @@ extern crate smithay_client_toolkit as sctk;
|
|||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::time::SystemTime;
|
|
||||||
|
|
||||||
|
use calloop::{timer::{Timer, TimerHandle}, EventLoop};
|
||||||
use chrono::prelude::{Local, Utc};
|
use chrono::prelude::{Local, Utc};
|
||||||
use chrono::TimeZone;
|
use chrono::TimeZone;
|
||||||
use chrono::Timelike;
|
use chrono::Timelike;
|
||||||
@ -633,7 +633,7 @@ fn main() {
|
|||||||
None
|
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");
|
.expect("Unable to connect to a Wayland compositor");
|
||||||
|
|
||||||
let surface = env
|
let surface = env
|
||||||
@ -679,25 +679,23 @@ fn main() {
|
|||||||
window.refresh()
|
window.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
let now = SystemTime::now();
|
let mut event_loop = EventLoop::<Option<WEvent>>::try_new().unwrap();
|
||||||
let mut last_elapsed = 0;
|
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 {
|
loop {
|
||||||
// Update every second
|
// Update every second
|
||||||
// TODO: There’s 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() {
|
match next_action.take() {
|
||||||
Some(WEvent::Close) => break,
|
Some(WEvent::Close) => break,
|
||||||
Some(WEvent::Refresh) => {
|
Some(WEvent::Refresh) => {
|
||||||
@ -732,20 +730,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(guard) = queue.prepare_read() {
|
event_loop.dispatch(None, &mut next_action).unwrap();
|
||||||
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.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user