Focus requests reach widgets clipped by a scroll viewport, and stop retrying after a few frames
A scroll viewport keeps in `widget_rects` only the widgets at least partly inside its visible area (`draw/layout.rs`, the translation of the sub-canvas rects to surface space). A focus request whose target sits below the fold therefore never finds it: `App::take_focus_request` was honoured only for widgets already laid out on screen. The Wi-Fi page of settings is one such case by construction: tapping a secured network inserts the password form under the row and asks for focus on the field, so for a row in the lower part of the list the field is born outside the viewport and the request misses. Worse, the miss branch parked the id in `focus_retry`, marked the view dirty and requested a redraw on every iteration, so the application rebuilt and repainted at the compositor's frame rate for as long as the widget stayed hidden. The layout pass now records the widgets it drops for carrying a `WidgetId`: `DrawCtx::scroll_clipped` holds `(id, scroll flat_idx, rect)` with the rect in the scroll's content coordinates, the same frame the navigable-item list uses, and `draw_frame` hands it to `FrameState`. When a focus request misses, `AppData::reveal_clipped_widget` looks the id up in that list on the main surface and the overlays, finds the viewport in `scroll_rects`, and moves its offset on the axes the scroll allows so the rect lands inside; the next frame lays the widget out and the retry focuses it. Nested scrolls resolve one viewport per frame. The rule that computes the new offset is `scroll::offset_into_view`, extracted from the keyboard navigation in `input/keyboard/nav.rs`, which now calls it instead of carrying its own copy; unit tests cover the three cases. `focus_retry` carries a budget of drawn frames (`FOCUS_RETRY_FRAMES`, four), decremented only on iterations that actually drew, so a request made while a frame callback is pending does not lose its chance. A fresh request from the application replaces a pending retry with a full budget. When the budget runs out the request is dropped, which ends the redraw loop for a widget that never appears. Documented in the `take_focus_request` doc comment, the cookbook and the changelog; Debian revision 0.3.0-3.
This commit is contained in:
+17
-5
@@ -35,6 +35,10 @@ use super::frame::draw_frame;
|
||||
use super::invalidation::apply_invalidation;
|
||||
use super::overlays_reconcile::reconcile_overlays;
|
||||
|
||||
/// Drawn frames a focus request waits for its target to appear: one for
|
||||
/// the rebuilt view, one per scroll viewport moved to reveal the widget.
|
||||
const FOCUS_RETRY_FRAMES: u8 = 4;
|
||||
|
||||
/// Run the application, panicking on init failure. Thin wrapper over
|
||||
/// [`try_run`] kept for backwards-compatibility — embedders that need
|
||||
/// to recover from a missing compositor or a stripped-down driver
|
||||
@@ -903,8 +907,11 @@ pub( crate ) fn try_run<A: App>( mut app: A ) -> Result<(), RunError>
|
||||
// Walks main + every overlay because the targeted widget can live
|
||||
// on any of them (a search field on a launcher overlay, a text
|
||||
// edit on a dialog modal, …).
|
||||
let focus_id = data.app.take_focus_request().or_else( || data.focus_retry.take() );
|
||||
if let Some( id ) = focus_id
|
||||
let retry = data.focus_retry.take();
|
||||
let focus_request = data.app.take_focus_request()
|
||||
.map( |id| ( id, FOCUS_RETRY_FRAMES ) )
|
||||
.or( retry );
|
||||
if let Some( ( id, frames_left ) ) = focus_request
|
||||
{
|
||||
let mut hit: Option<( SurfaceFocus, usize )> = data.main.frame.widget_rects.iter()
|
||||
.find( |w| w.id == Some( id ) )
|
||||
@@ -936,9 +943,14 @@ pub( crate ) fn try_run<A: App>( mut app: A ) -> Result<(), RunError>
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data.focus_retry = Some( id );
|
||||
data.view_dirty = true;
|
||||
data.main.request_redraw();
|
||||
let frames_left = if any_drawable { frames_left.saturating_sub( 1 ) } else { frames_left };
|
||||
if frames_left > 0
|
||||
{
|
||||
data.reveal_clipped_widget( id );
|
||||
data.focus_retry = Some( ( id, frames_left ) );
|
||||
data.view_dirty = true;
|
||||
data.main.request_redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user