mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2026-01-22 07:05:56 +00:00
refactor: decouple ui init from configure events
This commit is contained in:
parent
f0b9660dd2
commit
e6f425842b
4 changed files with 153 additions and 49 deletions
|
|
@ -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,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,46 +112,72 @@ impl ActiveLockSurface {
|
||||||
self.configure_surface(&dimensions, scaling_mode);
|
self.configure_surface(&dimensions, scaling_mode);
|
||||||
|
|
||||||
if self.component.is_none() {
|
if self.component.is_none() {
|
||||||
context.platform.add_window(Rc::clone(&self.window));
|
self.pending_component_initialization = true;
|
||||||
let component = ComponentState::new(
|
|
||||||
context.component_definition.clone(),
|
|
||||||
context.compilation_result.clone(),
|
|
||||||
&self.window,
|
|
||||||
)?;
|
|
||||||
self.window
|
|
||||||
.window()
|
|
||||||
.dispatch_event(WindowEvent::WindowActiveChanged(true));
|
|
||||||
|
|
||||||
let callback_context = LockCallbackContext::new(
|
|
||||||
context.component_name.clone(),
|
|
||||||
context.output_handle,
|
|
||||||
context.output_info.clone(),
|
|
||||||
context.primary_handle,
|
|
||||||
context.active_handle,
|
|
||||||
);
|
|
||||||
|
|
||||||
for callback in &context.callbacks {
|
|
||||||
if let Err(err) =
|
|
||||||
callback.apply_with_context(component.component_instance(), &callback_context)
|
|
||||||
{
|
|
||||||
info!(
|
|
||||||
"Failed to register lock callback '{}': {err}",
|
|
||||||
callback.name()
|
|
||||||
);
|
|
||||||
} else if callback.should_apply(&callback_context) {
|
|
||||||
info!("Registered lock callback '{}'", callback.name());
|
|
||||||
} else {
|
|
||||||
info!(
|
|
||||||
"Skipping callback '{}' due to selector filter (output {:?})",
|
|
||||||
callback.name(),
|
|
||||||
context.output_handle
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.component = Some(component);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderableWindow::request_redraw(self.window.as_ref());
|
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));
|
||||||
|
let component = ComponentState::new(
|
||||||
|
context.component_definition.clone(),
|
||||||
|
context.compilation_result.clone(),
|
||||||
|
&self.window,
|
||||||
|
)?;
|
||||||
|
self.window
|
||||||
|
.window()
|
||||||
|
.dispatch_event(WindowEvent::WindowActiveChanged(true));
|
||||||
|
|
||||||
|
let callback_context = LockCallbackContext::new(
|
||||||
|
context.component_name.clone(),
|
||||||
|
context.output_handle,
|
||||||
|
context.output_info.clone(),
|
||||||
|
context.primary_handle,
|
||||||
|
context.active_handle,
|
||||||
|
);
|
||||||
|
|
||||||
|
for callback in &context.callbacks {
|
||||||
|
if let Err(err) =
|
||||||
|
callback.apply_with_context(component.component_instance(), &callback_context)
|
||||||
|
{
|
||||||
|
info!(
|
||||||
|
"Failed to register lock callback '{}': {err}",
|
||||||
|
callback.name()
|
||||||
|
);
|
||||||
|
} else if callback.should_apply(&callback_context) {
|
||||||
|
info!("Registered lock callback '{}'", callback.name());
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"Skipping callback '{}' due to selector filter (output {:?})",
|
||||||
|
callback.name(),
|
||||||
|
context.output_handle
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.component = Some(component);
|
||||||
|
self.pending_component_initialization = false;
|
||||||
|
|
||||||
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue