diff --git a/src/event_loop/mod.rs b/src/event_loop/mod.rs index e086efd..2ccea1c 100644 --- a/src/event_loop/mod.rs +++ b/src/event_loop/mod.rs @@ -497,17 +497,41 @@ pub( crate ) fn try_run( app: A ) -> Result<(), RunError> draw_frame( &mut data ); } - // Focus the widget with the requested WidgetId if the app requests it + // Focus the widget with the requested WidgetId if the app requests it. + // 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, …). if let Some( id ) = data.app.take_focus_request() { - let found = data.main.widget_rects.iter() + let mut hit: Option<( SurfaceFocus, usize )> = data.main.widget_rects.iter() .find( |w| w.id == Some( id ) ) - .map( |w| w.flat_idx ); - if let Some( flat_idx ) = found + .map( |w| ( SurfaceFocus::Main, w.flat_idx ) ); + if hit.is_none() + { + for ( ov_id, surf ) in &data.overlays + { + if let Some( w ) = surf.widget_rects.iter().find( |w| w.id == Some( id ) ) + { + hit = Some( ( SurfaceFocus::Overlay( *ov_id ), w.flat_idx ) ); + break; + } + } + } + if let Some( ( focus, flat_idx ) ) = hit { let qh = data.qh.clone(); - data.set_focus( SurfaceFocus::Main, Some( flat_idx ), &qh ); - data.main.request_redraw(); + data.set_focus( focus, Some( flat_idx ), &qh ); + match focus + { + SurfaceFocus::Main => data.main.request_redraw(), + SurfaceFocus::Overlay( id ) => + { + if let Some( s ) = data.overlays.get_mut( &id ) + { + s.request_redraw(); + } + } + } } } }