refactor: decouple ui init from configure events

This commit is contained in:
drendog 2026-01-18 03:20:01 +01:00
parent f0b9660dd2
commit e6f425842b
Signed by: dwenya
GPG key ID: 8DD77074645332D0
4 changed files with 153 additions and 49 deletions

View file

@ -677,11 +677,13 @@ impl Dispatch<ExtSessionLockSurfaceV1, ()> for AppState {
}; };
if let Some(manager) = state.lock_manager_mut() { if let Some(manager) = state.lock_manager_mut() {
if let Err(err) = manager.handle_surface_configured(
manager.handle_configure(&lock_surface_id, serial, width, height, output_ctx) &lock_surface_id,
{ serial,
info!("Failed to configure session lock surface: {err}"); width,
} height,
output_ctx,
);
} }
} }
} }

View file

@ -253,6 +253,65 @@ impl SessionLockManager {
surface.handle_configure(serial, width, height, &context) surface.handle_configure(serial, width, height, &context)
} }
pub fn handle_surface_configured(
&mut self,
lock_surface_id: &ObjectId,
serial: u32,
width: u32,
height: u32,
output_ctx: LockSurfaceOutputContext,
) {
let component_name = self.component_definition.name().to_string();
let context = LockConfigureContext {
scale_factor: self.config.scale_factor.value(),
component_definition: self.component_definition.clone(),
compilation_result: self.compilation_result.clone(),
platform: Rc::clone(&self.platform),
callbacks: self.callbacks.clone(),
component_name,
output_handle: output_ctx.output_handle,
output_info: output_ctx.output_info,
primary_handle: output_ctx.primary_handle,
active_handle: output_ctx.active_handle,
};
let Some(surface) = self.find_surface_by_lock_surface_id_mut(lock_surface_id) else {
return;
};
surface.handle_surface_configured(serial, width, height, &context);
}
pub fn initialize_pending_components(&mut self) -> Result<()> {
let component_name = self.component_definition.name().to_string();
for (_, surface) in &mut self.lock_surfaces {
if surface.has_pending_initialization() {
let Some(output_handle) = surface.output_handle else {
continue;
};
let context = LockConfigureContext {
scale_factor: self.config.scale_factor.value(),
component_definition: self.component_definition.clone(),
compilation_result: self.compilation_result.clone(),
platform: Rc::clone(&self.platform),
callbacks: self.callbacks.clone(),
component_name: component_name.clone(),
output_handle,
output_info: surface.output_info.clone(),
primary_handle: surface.primary_handle,
active_handle: surface.active_handle,
};
surface.initialize_pending_component(&context)?;
}
}
Ok(())
}
pub fn render_frames(&self) -> Result<()> { pub fn render_frames(&self) -> Result<()> {
rendering::render_frames(&self.lock_surfaces) rendering::render_frames(&self.lock_surfaces)
} }

View file

@ -52,11 +52,12 @@ pub struct ActiveLockSurface {
component: Option<ComponentState>, component: Option<ComponentState>,
scale_factor: f32, scale_factor: f32,
has_fractional_scale: bool, has_fractional_scale: bool,
output_handle: Option<OutputHandle>,
component_name: Option<String>, component_name: Option<String>,
output_info: Option<OutputInfo>, pub(super) output_handle: Option<OutputHandle>,
primary_handle: Option<OutputHandle>, pub(super) output_info: Option<OutputInfo>,
active_handle: Option<OutputHandle>, pub(super) primary_handle: Option<OutputHandle>,
pub(super) active_handle: Option<OutputHandle>,
pending_component_initialization: bool,
} }
impl ActiveLockSurface { impl ActiveLockSurface {
@ -72,16 +73,17 @@ impl ActiveLockSurface {
output_info: None, output_info: None,
primary_handle: None, primary_handle: None,
active_handle: None, active_handle: None,
pending_component_initialization: false,
} }
} }
pub fn handle_configure( pub fn handle_surface_configured(
&mut self, &mut self,
serial: u32, serial: u32,
width: u32, width: u32,
height: u32, height: u32,
context: &LockConfigureContext, context: &LockConfigureContext,
) -> Result<()> { ) {
self.surface.handle_configure(serial, width, height); self.surface.handle_configure(serial, width, height);
self.scale_factor = context.scale_factor; self.scale_factor = context.scale_factor;
self.output_handle = Some(context.output_handle); self.output_handle = Some(context.output_handle);
@ -93,7 +95,7 @@ impl ActiveLockSurface {
Ok(dimensions) => dimensions, Ok(dimensions) => dimensions,
Err(err) => { Err(err) => {
info!("Failed to calculate lock surface dimensions: {err}"); info!("Failed to calculate lock surface dimensions: {err}");
return Ok(()); return;
} }
}; };
let scaling_mode = self.scaling_mode(); let scaling_mode = self.scaling_mode();
@ -110,6 +112,33 @@ impl ActiveLockSurface {
self.configure_surface(&dimensions, scaling_mode); self.configure_surface(&dimensions, scaling_mode);
if self.component.is_none() { if self.component.is_none() {
self.pending_component_initialization = true;
}
RenderableWindow::request_redraw(self.window.as_ref());
}
pub fn handle_configure(
&mut self,
serial: u32,
width: u32,
height: u32,
context: &LockConfigureContext,
) -> Result<()> {
self.handle_surface_configured(serial, width, height, context);
if self.pending_component_initialization {
self.initialize_component(context)?;
}
Ok(())
}
fn initialize_component(&mut self, context: &LockConfigureContext) -> Result<()> {
if self.component.is_some() {
return Ok(());
}
context.platform.add_window(Rc::clone(&self.window)); context.platform.add_window(Rc::clone(&self.window));
let component = ComponentState::new( let component = ComponentState::new(
context.component_definition.clone(), context.component_definition.clone(),
@ -147,9 +176,8 @@ impl ActiveLockSurface {
} }
} }
self.component = Some(component); self.component = Some(component);
} self.pending_component_initialization = false;
RenderableWindow::request_redraw(self.window.as_ref());
Ok(()) Ok(())
} }
@ -280,4 +308,15 @@ impl ActiveLockSurface {
pub const fn component(&self) -> Option<&ComponentState> { pub const fn component(&self) -> Option<&ComponentState> {
self.component.as_ref() self.component.as_ref()
} }
pub const fn has_pending_initialization(&self) -> bool {
self.pending_component_initialization
}
pub fn initialize_pending_component(&mut self, context: &LockConfigureContext) -> Result<()> {
if self.pending_component_initialization {
self.initialize_component(context)?;
}
Ok(())
}
} }

View file

@ -694,6 +694,10 @@ impl WaylandShellSystem {
update_timers_and_animations(); update_timers_and_animations();
if let Some(lock_manager) = shared_data.lock_manager_mut() {
lock_manager.initialize_pending_components()?;
}
for surface in shared_data.all_outputs() { for surface in shared_data.all_outputs() {
surface surface
.window() .window()