Skip to content

Commit 4bc6ff9

Browse files
committed
sctk: Fire RedrawRequests
1 parent 07a1135 commit 4bc6ff9

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

core/src/event/wayland/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod popup;
55
mod seat;
66
mod window;
77

8-
use crate::window::Id;
8+
use crate::{time::Instant, window::Id};
99
use sctk::reexports::client::protocol::{
1010
wl_output::WlOutput, wl_seat::WlSeat, wl_surface::WlSurface,
1111
};
@@ -36,4 +36,6 @@ pub enum Event {
3636
DndOffer(DndOfferEvent),
3737
/// Selection Offer events
3838
SelectionOffer(SelectionOfferEvent),
39+
/// Frame events
40+
Frame(Instant, WlSurface, Id),
3941
}

runtime/src/window.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ use crate::futures::subscription::{self, Subscription};
1717
///
1818
/// In any case, this [`Subscription`] is useful to smoothly draw application-driven
1919
/// animations without missing any frames.
20-
pub fn frames() -> Subscription<Instant> {
20+
pub fn frames() -> Subscription<(Id, Instant)> {
2121
subscription::raw_events(|event, _status| match event {
22-
iced_core::Event::Window(_, Event::RedrawRequested(at)) => Some(at),
22+
iced_core::Event::Window(id, Event::RedrawRequested(at))
23+
| iced_core::Event::PlatformSpecific(
24+
iced_core::event::PlatformSpecific::Wayland(
25+
iced_core::event::wayland::Event::Frame(at, _, id),
26+
),
27+
) => Some((id, at)),
2328
_ => None,
2429
})
2530
}

sctk/src/application.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ use iced_accessibility::{
2121
};
2222
use iced_futures::{
2323
core::{
24-
event::Status,
24+
event::{
25+
wayland::Event as WaylandEvent, Event as CoreEvent,
26+
PlatformSpecific, Status,
27+
},
2528
layout::Limits,
2629
mouse,
2730
renderer::Style,
31+
time::Instant,
2832
widget::{
2933
operation::{self, OperationWrapper},
3034
tree, Operation, Tree,
@@ -673,8 +677,12 @@ where
673677
}
674678
SctkEvent::RemovedOutput( ..) => {
675679
}
676-
SctkEvent::Frame(_) => {
677-
// TODO if animations are running, request redraw here?
680+
SctkEvent::Frame(surface) => {
681+
if let Some(id) = surface_ids.get(&surface.id()) {
682+
runtime.broadcast(CoreEvent::PlatformSpecific(
683+
PlatformSpecific::Wayland(WaylandEvent::Frame(Instant::now(), surface, id.inner()))
684+
), Status::Ignored);
685+
}
678686
},
679687
SctkEvent::ScaleFactorChanged { .. } => {}
680688
SctkEvent::DataSource(DataSourceEvent::DndFinished) | SctkEvent::DataSource(DataSourceEvent::DndCancelled)=> {

0 commit comments

Comments
 (0)