Skip to main content

PumpRunner

Struct PumpRunner 

Source
pub struct PumpRunner<A: App> { /* private fields */ }
Expand description

A windowed runner driven from outside: same [Shell] as Launcher::run (input mapping, IME, clipboard, chrome, caret blink), but the host calls pump on its own cadence instead of parking in run_app.

Typed by its app for app_mut and route_events alone: every method hands the shell on unsized, so the work is compiled once in kui rather than in every crate that opens one (backlog C49).

Implementations§

Source§

impl<A: App> PumpRunner<A>

Source

pub fn pump(&mut self) -> bool

Processes all pending OS events without blocking. Returns false once the main window has closed — and from that pump on the windows are gone and the loop is parked for the next runner; further pumps are no-ops.

Source

pub fn pumps(&self) -> u64

How many turns this runner has taken, the one that opened the window included — every pump and pump_until that ran, not the no-ops after it retired. Monotonic, so two readings a second apart are the pump rate over that second, which is what a driver’s backoff promises and what frame_stats cannot say (backlog F62). Which of them something outside the app caused is woken_pumps.

Source

pub fn woken_pumps(&self) -> u64

How many of those pumps found an OS event or a wake in their batch: any window event but a redraw — a key, the pointer crossing the window, a focus change, a resize, the window moved or occluded — or anything that came through the loop’s proxy: a Waker::wake, assistive technology asking, a file dialog’s answer. It is what makes next_deadline answer “now” after a pump, counted (backlog F94). Monotonic, and never more than pumps.

Two readings a second apart with this one unmoved are a second the desktop left the window alone: whatever it drew was the app’s own doing — a tick, a caret blink, a transition, the audio poll. A moved one is the desktop or a person reaching in, which resets a driver’s backoff exactly as a regression would, so an idle-window test that sees it move re-measures instead of failing.

Source

pub fn pump_until(&mut self, deadline: Instant) -> bool

pump, but parked until an OS event, a Waker::wake or deadline — whichever comes first — so a host that owns the loop blocks on all three instead of polling on a timer (backlog C21). Returns false once the main window has closed.

Source

pub fn next_deadline(&self) -> Option<Instant>

When the shell next needs pumping, as the last pump left it — None when nothing it knows about is due, which is ControlFlow::Wait for a loop that owns itself.

A host driving from a foreign loop has to guess how long to leave between pumps, and the guess is what pays: a caret blink, a tick, a transition’s next frame, the audio poll and a window’s first-frame retry are all deadlines the shell has already worked out, and a driver on a fixed interval hits them a whole interval late. Ask after each pump and sleep to the answer instead.

What it does not say is whether an OS event is waiting — nothing short of pumping can — so a driver still needs a ceiling of its own. This only ever tells it to come back sooner.

Source

pub fn waker(&self) -> Waker

A Waker for this loop, to clone into the threads the host’s data arrives on.

Source

pub fn app_mut(&mut self) -> &mut A

Source

pub fn route_events( &mut self, events: impl IntoIterator<Item = UiEvent>, to_app: impl FnMut(&mut A, UiEvent, &mut Core), )

Delivers events the way this runner’s own loop does (Shell::route_events, ADR 0014 decision 6): an extension’s event to the extension, and what it replies to to_app carrying its origin. A host that drives the core directly — core_mut().press, an access action, a drained take_pending_events — produces events the loop never saw, and pushing those at the app would hand it a plugin’s clicks and leave the plugin deaf to them.

to_app is lent the core of the window each event came from, as the runner’s own loop lends it to App::on_event_with (ADR 0036).

Source

pub fn core_mut(&mut self) -> &mut Core

The main window’s core. Every window of the app shares its session, so resources registered through it draw in all of them, and Core::windows on it lists them.

Source

pub fn core_mut_of(&mut self, id: WindowId) -> Option<&mut Core>

The core of the window id names, if that window is open — the main window’s for WindowId::MAIN. Everything that is one window’s rather than the session’s — its focus, its editors’ text, its scroll offsets, its tokens — is answered by this core and no other (backlog AR12).

Source

pub fn window_id(&mut self, name: &str) -> Option<WindowId>

The id of the open window named name ("main" for the launcher’s), or None while no window of that name is open — before its first frame’s diff, or after the user closed it.

Source

pub fn window_size(&self) -> (Size, f32)

The main window’s inner size (logical px) and its scale factor. Unlike core_mut().viewport() this is known before the first frame, so a host can size its model at setup — through core_mut().host_area(size), which is what the next frame lays out against: the window less the devtools’ dock while the panel is docked (docs/adr/0024), and the window itself otherwise.

Source

pub fn request_redraw(&self)

Schedules a redraw of every window (call after changing what view will produce). Under Launcher::deferred_events it is also what ends a frame’s wait: the host calling this is the host saying its view is current, so the frame that was waiting can be painted now — with the answer in it.

Source

pub fn request_exit(&mut self)

Asks the app to close; the next pump observes it and returns false.

Source

pub fn flush_audio(&mut self)

Hands the core’s queued audio commands to the device now, rather than at the next pump — for hosts that call Core::play between pumps and want the sound to start at once.

Trait Implementations§

Source§

impl<A: App> Drop for PumpRunner<A>

Source§

fn drop(&mut self)

A runner dropped while alive — a host that let go of it without pumping to the end — parks the loop too, so the next open on the thread is not refused for its sake.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<A> !Freeze for PumpRunner<A>

§

impl<A> !RefUnwindSafe for PumpRunner<A>

§

impl<A> !Send for PumpRunner<A>

§

impl<A> !Sync for PumpRunner<A>

§

impl<A> !UnwindSafe for PumpRunner<A>

§

impl<A> Unpin for PumpRunner<A>
where ManuallyDrop<Box<Shell<A>>>: Unpin,

§

impl<A> UnsafeUnpin for PumpRunner<A>
where ManuallyDrop<Box<Shell<A>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more