Bring down time to first draw

This commit is contained in:
Kenny Levinsen
2019-08-05 23:45:59 +02:00
parent 4e48df376b
commit 11fd9a79c3
2 changed files with 14 additions and 28 deletions
+4 -1
View File
@@ -9,6 +9,7 @@ use chrono::{DateTime, Datelike, Duration, Local, Timelike};
pub struct Clock { pub struct Clock {
cur_time: DateTime<Local>, cur_time: DateTime<Local>,
first_draw: bool,
} }
impl Clock { impl Clock {
@@ -29,6 +30,7 @@ impl Clock {
Clock { Clock {
cur_time: Local::now(), cur_time: Local::now(),
first_draw: true,
} }
} }
} }
@@ -74,9 +76,10 @@ impl ModuleImpl for Clock {
if time.date() != self.cur_time.date() if time.date() != self.cur_time.date()
|| time.hour() != self.cur_time.hour() || time.hour() != self.cur_time.hour()
|| time.minute() != self.cur_time.minute() || time.minute() != self.cur_time.minute()
|| force || force || self.first_draw
{ {
self.cur_time = time.clone(); self.cur_time = time.clone();
self.first_draw = false;
Ok(true) Ok(true)
} else { } else {
Ok(false) Ok(false)
+10 -27
View File
@@ -44,7 +44,6 @@ use crate::sound::PulseAudio;
enum Cmd { enum Cmd {
Exit, Exit,
Configure,
Draw, Draw,
MouseInput { pos: (u32, u32), input: Input }, MouseInput { pos: (u32, u32), input: Input },
KeyboardInput { input: Input }, KeyboardInput { input: Input },
@@ -272,7 +271,6 @@ impl App {
|_, _| {}, |_, _| {},
) )
.expect("Failed to map keyboard"); .expect("Failed to map keyboard");
event_queue.sync_roundtrip().unwrap();
// //
// Prepare shell so that we can create our shell surface // Prepare shell so that we can create our shell surface
@@ -292,7 +290,6 @@ impl App {
.create_surface(NewProxy::implement_dummy) .create_surface(NewProxy::implement_dummy)
.unwrap(); .unwrap();
let event_clone = cmd_queue.clone();
let shell_surface = shell let shell_surface = shell
.get_layer_surface( .get_layer_surface(
&surface, &surface,
@@ -302,14 +299,7 @@ impl App {
move |layer| { move |layer| {
layer.implement_closure( layer.implement_closure(
move |evt, layer| match evt { move |evt, layer| match evt {
zwlr_layer_surface_v1::Event::Configure { zwlr_layer_surface_v1::Event::Configure { serial, .. } => layer.ack_configure(serial),
serial,
width: _,
height: _,
} => {
layer.ack_configure(serial);
event_clone.lock().unwrap().push_back(Cmd::Configure);
}
_ => unreachable!(), _ => unreachable!(),
}, },
(), (),
@@ -350,40 +340,35 @@ impl App {
ptr.implement_closure( ptr.implement_closure(
move |evt, _| match evt { move |evt, _| match evt {
wl_pointer::Event::Enter { wl_pointer::Event::Enter {
serial: _,
surface: _,
surface_x, surface_x,
surface_y, surface_y,
..
} => { } => {
pos = (surface_x as u32, surface_y as u32); pos = (surface_x as u32, surface_y as u32);
} }
wl_pointer::Event::Leave { wl_pointer::Event::Leave { .. } => {
serial: _,
surface: _,
} => {
pos = (0, 0); pos = (0, 0);
} }
wl_pointer::Event::Motion { wl_pointer::Event::Motion {
time: _,
surface_x, surface_x,
surface_y, surface_y,
..
} => { } => {
pos = (surface_x as u32, surface_y as u32); pos = (surface_x as u32, surface_y as u32);
} }
wl_pointer::Event::Axis { wl_pointer::Event::Axis {
time: _,
axis, axis,
value, value,
..
} => { } => {
if axis == wl_pointer::Axis::VerticalScroll { if axis == wl_pointer::Axis::VerticalScroll {
vert_scroll += value; vert_scroll += value;
} }
} }
wl_pointer::Event::Button { wl_pointer::Event::Button {
serial: _,
time: _,
button, button,
state, state,
..
} => match state { } => match state {
wl_pointer::ButtonState::Released => { wl_pointer::ButtonState::Released => {
btn = button; btn = button;
@@ -427,7 +412,7 @@ impl App {
}) })
.unwrap(); .unwrap();
event_queue.sync_roundtrip().unwrap(); display.flush().unwrap();
App { App {
surface: surface, surface: surface,
@@ -446,6 +431,7 @@ fn main() {
let (tx_draw, rx_draw) = channel(); let (tx_draw, rx_draw) = channel();
let mut app = App::new(tx_draw); let mut app = App::new(tx_draw);
app.wipe();
let worker_queue = app.cmd_queue(); let worker_queue = app.cmd_queue();
std::thread::spawn(move || loop { std::thread::spawn(move || loop {
@@ -459,16 +445,13 @@ fn main() {
PollFd::new(rx_pipe.as_raw_fd(), PollFlags::POLLIN), PollFd::new(rx_pipe.as_raw_fd(), PollFlags::POLLIN),
]; ];
app.cmd_queue().lock().unwrap().push_back(Cmd::Draw);
let q = app.cmd_queue(); let q = app.cmd_queue();
loop { loop {
let cmd = q.lock().unwrap().pop_front(); let cmd = q.lock().unwrap().pop_front();
match cmd { match cmd {
Some(cmd) => match cmd { Some(cmd) => match cmd {
Cmd::Configure => {
app.wipe();
app.redraw(true).expect("Failed to draw");
app.flush_display();
}
Cmd::Draw => { Cmd::Draw => {
app.redraw(false).expect("Failed to draw"); app.redraw(false).expect("Failed to draw");
app.flush_display(); app.flush_display();