diff options
| author | dyknon dyknonr5fjp | 2025-03-02 03:24:49 +0900 |
|---|---|---|
| committer | dyknon dyknonr5fjp | 2025-03-02 03:24:49 +0900 |
| commit | 49fdc6dd7b1a166846df75f17f9902de5043b634 (patch) | |
| tree | fd5db0bedf98587c557ad7bc69fa3e51349267a0 /src/gtk.rs | |
| parent | 55cae3e208dcc5579470f90d16a49ad7331b6b23 (diff) | |
show delay.
Diffstat (limited to 'src/gtk.rs')
| -rw-r--r-- | src/gtk.rs | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -7,7 +7,7 @@ use glib::{clone, spawn_future_local}; use std::thread; use std::sync::{Arc, Mutex}; use std::rc::Rc; -use std::cell::RefCell; +use std::cell::Cell; use crate::sync::Signal; use std::future::poll_fn; use std::task::Poll; @@ -107,41 +107,54 @@ fn activate<Attr: Overlay>(app: >k::Application, apps: Arc<AppState<Attr>>){ let draw = gtk::DrawingArea::new(); let overlay = Attr::empty().unwrap(); - let frame_cache: Rc<RefCell<Option<cairo::ImageSurface>>> - = Rc::new(RefCell::new(None)); + let frame_cache: Rc<Cell<Option<cairo::ImageSurface>>> + = Rc::new(Cell::new(None)); + let attr_cache: Rc<Cell<Option<Attr>>> = Rc::new(Cell::new(None)); draw.set_draw_func(clone!{ #[strong] frame_cache, move |_draw, ctx, canvas_w, canvas_h|{ ctx.set_source_rgb(0., 0., 0.); ctx.paint().unwrap(); - if let Some(image) = frame_cache.borrow_mut().clone(){ + if let Some(image) = frame_cache.take(){ let ipat = cairo::SurfacePattern::create(&image); let scale = ((canvas_w as f64) / (image.width() as f64)).min( (canvas_h as f64) / (image.height() as f64)); ctx.scale(scale, scale); ctx.set_source(&ipat).unwrap(); ctx.paint().unwrap(); + frame_cache.replace(Some(image)); } } }); + overlay.add_tick_callback(clone!{ + #[strong] attr_cache, + move |overlay, _clock|{ + if let Some(attr) = attr_cache.take(){ + attr.update(overlay).unwrap(); + attr_cache.replace(Some(attr)); + } + glib::ControlFlow::Continue + } + }); spawn_future_local(poll_fn(clone!{ #[strong] apps, #[strong] draw, #[strong] frame_cache, + #[strong] attr_cache, #[strong] overlay, move |ctx|{ loop{ match apps.update.lock().unwrap().poll(ctx){ Poll::Ready(_) => { if let Some(newfb) = apps.next.lock().unwrap().take(){ - let mut frame_cache = frame_cache.borrow_mut(); if let Some(lastframe) = frame_cache.take(){ apps.fbpool.lock().unwrap() .put(lastframe.take_data().unwrap()); } - *frame_cache = Some(newfb.image.into_inner()); + frame_cache.replace(Some(newfb.image.into_inner())); newfb.attr.update(&overlay).unwrap(); + attr_cache.replace(Some(newfb.attr)); } draw.queue_draw(); }, |
