feat: add per-output callbacks

This commit is contained in:
drendog 2025-12-03 17:37:34 +01:00
parent 408355e980
commit 5f3f4e1072
Signed by: dwenya
GPG key ID: 8DD77074645332D0
2 changed files with 57 additions and 2 deletions

View file

@ -6,7 +6,7 @@ mod shell;
mod shell_composition;
mod shell_runtime;
mod system;
mod value_conversion;
pub mod value_conversion;
use layer_shika_adapters::errors::LayerShikaError;
use layer_shika_domain::errors::DomainError;
@ -30,6 +30,7 @@ pub use layer_shika_domain::value_objects::popup_request::{
pub use popup_builder::PopupBuilder;
pub use shell_runtime::{DEFAULT_WINDOW_NAME, ShellRuntime};
pub use system::{EventContext, EventLoopHandle, ShellControl, SingleWindowShell};
pub use value_conversion::IntoValue;
pub use shell::{
LayerSurfaceHandle, Shell, ShellEventContext, ShellEventLoopHandle, ShellWindowConfigHandler,
@ -59,7 +60,7 @@ pub enum Error {
pub mod prelude {
pub use crate::{
AnchorEdges, AnchorStrategy, DEFAULT_WINDOW_NAME, EventContext, EventLoopHandle,
AnchorEdges, AnchorStrategy, DEFAULT_WINDOW_NAME, EventContext, EventLoopHandle, IntoValue,
KeyboardInteractivity, Layer, LayerShika, OutputGeometry, OutputHandle, OutputInfo,
OutputPolicy, OutputRegistry, PopupBuilder, PopupHandle, PopupPlacement,
PopupPositioningMode, PopupRequest, PopupSize, PopupWindow, Result, ShellControl,

View file

@ -795,6 +795,60 @@ impl SingleWindowShell {
Ok(())
}
pub fn on_for_output<F, R>(
&self,
output: OutputHandle,
callback_name: &str,
handler: F,
) -> Result<()>
where
F: Fn(ShellControl) -> R + 'static,
R: IntoValue,
{
let control = self.control();
self.with_output(output, |instance| {
let control_clone = control.clone();
if let Err(e) = instance.set_callback(callback_name, move |_args| {
handler(control_clone.clone()).into_value()
}) {
log::error!(
"Failed to register callback '{}' on output {:?}: {}",
callback_name,
output,
e
);
}
})?;
Ok(())
}
pub fn on_for_output_with_args<F, R>(
&self,
output: OutputHandle,
callback_name: &str,
handler: F,
) -> Result<()>
where
F: Fn(&[Value], ShellControl) -> R + 'static,
R: IntoValue,
{
let control = self.control();
self.with_output(output, |instance| {
let control_clone = control.clone();
if let Err(e) = instance.set_callback(callback_name, move |args| {
handler(args, control_clone.clone()).into_value()
}) {
log::error!(
"Failed to register callback '{}' on output {:?}: {}",
callback_name,
output,
e
);
}
})?;
Ok(())
}
#[must_use]
pub fn popup(&self, component_name: impl Into<String>) -> PopupBuilder<'_> {
PopupBuilder::new(self, component_name.into())