mirror of
				https://codeberg.org/waydeer/layer-shika.git
				synced 2025-11-04 03:04:23 +00:00 
			
		
		
		
	feat: dismiss anyhow by replacing with thiserror
This commit is contained in:
		
							parent
							
								
									721c8ca91d
								
							
						
					
					
						commit
						fc2e3944b4
					
				
					 13 changed files with 179 additions and 99 deletions
				
			
		
							
								
								
									
										8
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							| 
						 | 
					@ -189,12 +189,6 @@ dependencies = [
 | 
				
			||||||
 "libc",
 | 
					 "libc",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					 | 
				
			||||||
name = "anyhow"
 | 
					 | 
				
			||||||
version = "1.0.86"
 | 
					 | 
				
			||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
					 | 
				
			||||||
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "arrayref"
 | 
					name = "arrayref"
 | 
				
			||||||
version = "0.3.8"
 | 
					version = "0.3.8"
 | 
				
			||||||
| 
						 | 
					@ -2118,13 +2112,13 @@ dependencies = [
 | 
				
			||||||
name = "layer-shika"
 | 
					name = "layer-shika"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.1.0"
 | 
				
			||||||
dependencies = [
 | 
					dependencies = [
 | 
				
			||||||
 "anyhow",
 | 
					 | 
				
			||||||
 "glutin",
 | 
					 "glutin",
 | 
				
			||||||
 "log",
 | 
					 "log",
 | 
				
			||||||
 "raw-window-handle",
 | 
					 "raw-window-handle",
 | 
				
			||||||
 "slint",
 | 
					 "slint",
 | 
				
			||||||
 "slint-interpreter",
 | 
					 "slint-interpreter",
 | 
				
			||||||
 "smithay-client-toolkit",
 | 
					 "smithay-client-toolkit",
 | 
				
			||||||
 | 
					 "thiserror",
 | 
				
			||||||
 "wayland-client",
 | 
					 "wayland-client",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,7 +33,6 @@ module_name_repetitions = "allow"
 | 
				
			||||||
unwrap_used = "warn"
 | 
					unwrap_used = "warn"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
anyhow = "1.0.86"
 | 
					 | 
				
			||||||
glutin = { version = "0.32.0", default-features = false, features = [
 | 
					glutin = { version = "0.32.0", default-features = false, features = [
 | 
				
			||||||
    "wayland",
 | 
					    "wayland",
 | 
				
			||||||
] }
 | 
					] }
 | 
				
			||||||
| 
						 | 
					@ -45,4 +44,5 @@ slint = { version = "1.7.2", default-features = false, features = [
 | 
				
			||||||
] }
 | 
					] }
 | 
				
			||||||
slint-interpreter = "1.7.2"
 | 
					slint-interpreter = "1.7.2"
 | 
				
			||||||
smithay-client-toolkit = "0.19.2"
 | 
					smithay-client-toolkit = "0.19.2"
 | 
				
			||||||
 | 
					thiserror = "1.0.63"
 | 
				
			||||||
wayland-client = "0.31.5"
 | 
					wayland-client = "0.31.5"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										43
									
								
								src/errors.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/errors.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,43 @@
 | 
				
			||||||
 | 
					use thiserror::Error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Error, Debug)]
 | 
				
			||||||
 | 
					pub enum LayerShikaError {
 | 
				
			||||||
 | 
					    #[error("Failed to connect to Wayland: {0}")]
 | 
				
			||||||
 | 
					    WaylandConnection(#[from] wayland_client::ConnectError),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Failed to initialize Wayland globals: {0}")]
 | 
				
			||||||
 | 
					    GlobalInitialization(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Failed to dispatch Wayland event: {0}")]
 | 
				
			||||||
 | 
					    WaylandDispatch(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Failed to create EGL context: {0}")]
 | 
				
			||||||
 | 
					    EGLContextCreation(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Failed to create FemtoVG renderer: {0}")]
 | 
				
			||||||
 | 
					    FemtoVGRendererCreation(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Failed to create Slint component: {0}")]
 | 
				
			||||||
 | 
					    SlintComponentCreation(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Failed to run event loop: {0}")]
 | 
				
			||||||
 | 
					    EventLoop(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Window configuration error: {0}")]
 | 
				
			||||||
 | 
					    WindowConfiguration(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Rendering error: {0}")]
 | 
				
			||||||
 | 
					    Rendering(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Invalid input: {0}")]
 | 
				
			||||||
 | 
					    InvalidInput(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Wayland protocol error: {0}")]
 | 
				
			||||||
 | 
					    WaylandProtocol(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Failed to set platform: {0}")]
 | 
				
			||||||
 | 
					    PlatformSetup(String),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[error("Failed to flush connection: {0}")]
 | 
				
			||||||
 | 
					    ConnectionFlush(#[from] wayland_client::backend::WaylandError),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					mod errors;
 | 
				
			||||||
mod reexports;
 | 
					mod reexports;
 | 
				
			||||||
mod rendering;
 | 
					mod rendering;
 | 
				
			||||||
mod windowing;
 | 
					mod windowing;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,5 +8,3 @@ pub mod sctk {
 | 
				
			||||||
pub mod wayland_client {
 | 
					pub mod wayland_client {
 | 
				
			||||||
    pub use wayland_client::*;
 | 
					    pub use wayland_client::*;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
pub use anyhow;
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
use anyhow::{anyhow, Result};
 | 
					use crate::errors::LayerShikaError;
 | 
				
			||||||
use glutin::{
 | 
					use glutin::{
 | 
				
			||||||
    api::egl::{context::PossiblyCurrentContext, display::Display, surface::Surface},
 | 
					    api::egl::{context::PossiblyCurrentContext, display::Display, surface::Surface},
 | 
				
			||||||
    config::ConfigTemplateBuilder,
 | 
					    config::ConfigTemplateBuilder,
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,7 @@ pub struct EGLContext {
 | 
				
			||||||
    context: PossiblyCurrentContext,
 | 
					    context: PossiblyCurrentContext,
 | 
				
			||||||
    surface: Surface<WindowSurface>,
 | 
					    surface: Surface<WindowSurface>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Default)]
 | 
					#[derive(Default)]
 | 
				
			||||||
pub struct EGLContextBuilder {
 | 
					pub struct EGLContextBuilder {
 | 
				
			||||||
    display_id: Option<ObjectId>,
 | 
					    display_id: Option<ObjectId>,
 | 
				
			||||||
| 
						 | 
					@ -31,7 +32,6 @@ pub struct EGLContextBuilder {
 | 
				
			||||||
    context_attributes: Option<ContextAttributesBuilder>,
 | 
					    context_attributes: Option<ContextAttributesBuilder>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[allow(dead_code)]
 | 
					 | 
				
			||||||
impl EGLContextBuilder {
 | 
					impl EGLContextBuilder {
 | 
				
			||||||
    pub fn new() -> Self {
 | 
					    pub fn new() -> Self {
 | 
				
			||||||
        Self::default()
 | 
					        Self::default()
 | 
				
			||||||
| 
						 | 
					@ -52,11 +52,13 @@ impl EGLContextBuilder {
 | 
				
			||||||
        self
 | 
					        self
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[allow(dead_code)]
 | 
				
			||||||
    pub const fn with_config_template(mut self, config_template: ConfigTemplateBuilder) -> Self {
 | 
					    pub const fn with_config_template(mut self, config_template: ConfigTemplateBuilder) -> Self {
 | 
				
			||||||
        self.config_template = Some(config_template);
 | 
					        self.config_template = Some(config_template);
 | 
				
			||||||
        self
 | 
					        self
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[allow(dead_code)]
 | 
				
			||||||
    pub const fn with_context_attributes(
 | 
					    pub const fn with_context_attributes(
 | 
				
			||||||
        mut self,
 | 
					        mut self,
 | 
				
			||||||
        context_attributes: ContextAttributesBuilder,
 | 
					        context_attributes: ContextAttributesBuilder,
 | 
				
			||||||
| 
						 | 
					@ -65,17 +67,21 @@ impl EGLContextBuilder {
 | 
				
			||||||
        self
 | 
					        self
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn build(self) -> Result<EGLContext> {
 | 
					    pub fn build(self) -> Result<EGLContext, LayerShikaError> {
 | 
				
			||||||
        let display_id = self
 | 
					        let display_id = self
 | 
				
			||||||
            .display_id
 | 
					            .display_id
 | 
				
			||||||
            .ok_or_else(|| anyhow!("Display ID is required"))?;
 | 
					            .ok_or_else(|| LayerShikaError::InvalidInput("Display ID is required".into()))?;
 | 
				
			||||||
        let surface_id = self
 | 
					        let surface_id = self
 | 
				
			||||||
            .surface_id
 | 
					            .surface_id
 | 
				
			||||||
            .ok_or_else(|| anyhow!("Surface ID is required"))?;
 | 
					            .ok_or_else(|| LayerShikaError::InvalidInput("Surface ID is required".into()))?;
 | 
				
			||||||
        let size = self.size.ok_or_else(|| anyhow!("Size is required"))?;
 | 
					        let size = self
 | 
				
			||||||
 | 
					            .size
 | 
				
			||||||
 | 
					            .ok_or_else(|| LayerShikaError::InvalidInput("Size is required".into()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let display_handle = create_wayland_display_handle(&display_id)?;
 | 
					        let display_handle = create_wayland_display_handle(&display_id)?;
 | 
				
			||||||
        let glutin_display = unsafe { Display::new(display_handle) }?;
 | 
					        let glutin_display = unsafe { Display::new(display_handle) }.map_err(|e| {
 | 
				
			||||||
 | 
					            LayerShikaError::EGLContextCreation(format!("Failed to create display: {e}"))
 | 
				
			||||||
 | 
					        })?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let config_template = self.config_template.unwrap_or_default();
 | 
					        let config_template = self.config_template.unwrap_or_default();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -90,7 +96,7 @@ impl EGLContextBuilder {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let context = context
 | 
					        let context = context
 | 
				
			||||||
            .make_current(&surface)
 | 
					            .make_current(&surface)
 | 
				
			||||||
            .map_err(|e| anyhow!("Unable to activate EGL context: {}. This may indicate a problem with the graphics drivers.", e))?;
 | 
					            .map_err(|e| LayerShikaError::EGLContextCreation(format!("Unable to activate EGL context: {e}. This may indicate a problem with the graphics drivers.")))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Ok(EGLContext { context, surface })
 | 
					        Ok(EGLContext { context, surface })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -101,17 +107,22 @@ impl EGLContext {
 | 
				
			||||||
        EGLContextBuilder::new()
 | 
					        EGLContextBuilder::new()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn ensure_current(&self) -> Result<()> {
 | 
					    fn ensure_current(&self) -> Result<(), LayerShikaError> {
 | 
				
			||||||
        if !self.context.is_current() {
 | 
					        if !self.context.is_current() {
 | 
				
			||||||
            self.context.make_current(&self.surface)?;
 | 
					            self.context.make_current(&self.surface).map_err(|e| {
 | 
				
			||||||
 | 
					                LayerShikaError::EGLContextCreation(format!("Failed to make context current: {e}"))
 | 
				
			||||||
 | 
					            })?;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn create_wayland_display_handle(display_id: &ObjectId) -> Result<RawDisplayHandle> {
 | 
					fn create_wayland_display_handle(
 | 
				
			||||||
    let display = NonNull::new(display_id.as_ptr().cast::<c_void>())
 | 
					    display_id: &ObjectId,
 | 
				
			||||||
        .ok_or_else(|| anyhow!("Failed to create NonNull pointer for display"))?;
 | 
					) -> Result<RawDisplayHandle, LayerShikaError> {
 | 
				
			||||||
 | 
					    let display = NonNull::new(display_id.as_ptr().cast::<c_void>()).ok_or_else(|| {
 | 
				
			||||||
 | 
					        LayerShikaError::InvalidInput("Failed to create NonNull pointer for display".into())
 | 
				
			||||||
 | 
					    })?;
 | 
				
			||||||
    let handle = WaylandDisplayHandle::new(display);
 | 
					    let handle = WaylandDisplayHandle::new(display);
 | 
				
			||||||
    Ok(RawDisplayHandle::Wayland(handle))
 | 
					    Ok(RawDisplayHandle::Wayland(handle))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -119,24 +130,27 @@ fn create_wayland_display_handle(display_id: &ObjectId) -> Result<RawDisplayHand
 | 
				
			||||||
fn select_config(
 | 
					fn select_config(
 | 
				
			||||||
    glutin_display: &Display,
 | 
					    glutin_display: &Display,
 | 
				
			||||||
    config_template: ConfigTemplateBuilder,
 | 
					    config_template: ConfigTemplateBuilder,
 | 
				
			||||||
) -> Result<glutin::api::egl::config::Config> {
 | 
					) -> Result<glutin::api::egl::config::Config, LayerShikaError> {
 | 
				
			||||||
    let mut configs = unsafe { glutin_display.find_configs(config_template.build()) }?;
 | 
					    let mut configs = unsafe { glutin_display.find_configs(config_template.build()) }
 | 
				
			||||||
    configs
 | 
					        .map_err(|e| LayerShikaError::EGLContextCreation(format!("Failed to find configs: {e}")))?;
 | 
				
			||||||
        .next()
 | 
					    configs.next().ok_or_else(|| {
 | 
				
			||||||
        .ok_or_else(|| anyhow!("No compatible EGL configurations found."))
 | 
					        LayerShikaError::EGLContextCreation("No compatible EGL configurations found.".into())
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn create_context(
 | 
					fn create_context(
 | 
				
			||||||
    glutin_display: &Display,
 | 
					    glutin_display: &Display,
 | 
				
			||||||
    config: &glutin::api::egl::config::Config,
 | 
					    config: &glutin::api::egl::config::Config,
 | 
				
			||||||
    context_attributes: ContextAttributesBuilder,
 | 
					    context_attributes: ContextAttributesBuilder,
 | 
				
			||||||
) -> Result<glutin::api::egl::context::NotCurrentContext> {
 | 
					) -> Result<glutin::api::egl::context::NotCurrentContext, LayerShikaError> {
 | 
				
			||||||
    unsafe { glutin_display.create_context(config, &context_attributes.build(None)) }
 | 
					    unsafe { glutin_display.create_context(config, &context_attributes.build(None)) }
 | 
				
			||||||
        .map_err(|e| anyhow!("Failed to create context: {}", e))
 | 
					        .map_err(|e| LayerShikaError::EGLContextCreation(format!("Failed to create context: {e}")))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn create_surface_handle(surface_id: &ObjectId) -> Result<RawWindowHandle> {
 | 
					fn create_surface_handle(surface_id: &ObjectId) -> Result<RawWindowHandle, LayerShikaError> {
 | 
				
			||||||
    let surface = NonNull::new(surface_id.as_ptr().cast::<c_void>())
 | 
					    let surface = NonNull::new(surface_id.as_ptr().cast::<c_void>()).ok_or_else(|| {
 | 
				
			||||||
        .ok_or_else(|| anyhow!("Failed to create NonNull pointer for surface"))?;
 | 
					        LayerShikaError::InvalidInput("Failed to create NonNull pointer for surface".into())
 | 
				
			||||||
 | 
					    })?;
 | 
				
			||||||
    let handle = WaylandWindowHandle::new(surface);
 | 
					    let handle = WaylandWindowHandle::new(surface);
 | 
				
			||||||
    Ok(RawWindowHandle::Wayland(handle))
 | 
					    Ok(RawWindowHandle::Wayland(handle))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -146,32 +160,31 @@ fn create_surface(
 | 
				
			||||||
    config: &glutin::api::egl::config::Config,
 | 
					    config: &glutin::api::egl::config::Config,
 | 
				
			||||||
    surface_handle: RawWindowHandle,
 | 
					    surface_handle: RawWindowHandle,
 | 
				
			||||||
    size: PhysicalSize,
 | 
					    size: PhysicalSize,
 | 
				
			||||||
) -> Result<Surface<WindowSurface>> {
 | 
					) -> Result<Surface<WindowSurface>, LayerShikaError> {
 | 
				
			||||||
    let Some(width) = NonZeroU32::new(size.width) else {
 | 
					    let width = NonZeroU32::new(size.width)
 | 
				
			||||||
        return Err(anyhow!("Width cannot be zero"));
 | 
					        .ok_or_else(|| LayerShikaError::InvalidInput("Width cannot be zero".into()))?;
 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let Some(height) = NonZeroU32::new(size.height) else {
 | 
					    let height = NonZeroU32::new(size.height)
 | 
				
			||||||
        return Err(anyhow!("Height cannot be zero"));
 | 
					        .ok_or_else(|| LayerShikaError::InvalidInput("Height cannot be zero".into()))?;
 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let attrs =
 | 
					    let attrs =
 | 
				
			||||||
        SurfaceAttributesBuilder::<WindowSurface>::new().build(surface_handle, width, height);
 | 
					        SurfaceAttributesBuilder::<WindowSurface>::new().build(surface_handle, width, height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unsafe { glutin_display.create_window_surface(config, &attrs) }
 | 
					    unsafe { glutin_display.create_window_surface(config, &attrs) }.map_err(|e| {
 | 
				
			||||||
        .map_err(|e| anyhow!("Failed to create window surface: {}", e))
 | 
					        LayerShikaError::EGLContextCreation(format!("Failed to create window surface: {e}"))
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unsafe impl OpenGLInterface for EGLContext {
 | 
					unsafe impl OpenGLInterface for EGLContext {
 | 
				
			||||||
    fn ensure_current(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
 | 
					    fn ensure_current(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
 | 
				
			||||||
        Ok(self.ensure_current()?)
 | 
					        self.ensure_current()
 | 
				
			||||||
 | 
					            .map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn swap_buffers(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
 | 
					    fn swap_buffers(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
 | 
				
			||||||
        self.surface
 | 
					        self.surface.swap_buffers(&self.context).map_err(|e| {
 | 
				
			||||||
            .swap_buffers(&self.context)
 | 
					            LayerShikaError::EGLContextCreation(format!("Failed to swap buffers: {e}")).into()
 | 
				
			||||||
            .map_err(|e| anyhow!("Failed to swap buffers: {}", e))
 | 
					        })
 | 
				
			||||||
            .map_err(Into::into)
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn resize(
 | 
					    fn resize(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
use anyhow::{anyhow, Result};
 | 
					use crate::errors::LayerShikaError;
 | 
				
			||||||
use log::info;
 | 
					use log::info;
 | 
				
			||||||
use slint::{
 | 
					use slint::{
 | 
				
			||||||
    platform::{femtovg_renderer::FemtoVGRenderer, Renderer, WindowAdapter, WindowEvent},
 | 
					    platform::{femtovg_renderer::FemtoVGRenderer, Renderer, WindowAdapter, WindowEvent},
 | 
				
			||||||
| 
						 | 
					@ -34,14 +34,14 @@ impl FemtoVGWindow {
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn render_frame_if_dirty(&self) -> Result<()> {
 | 
					    pub fn render_frame_if_dirty(&self) -> Result<(), LayerShikaError> {
 | 
				
			||||||
        if matches!(
 | 
					        if matches!(
 | 
				
			||||||
            self.render_state.replace(RenderState::Clean),
 | 
					            self.render_state.replace(RenderState::Clean),
 | 
				
			||||||
            RenderState::Dirty
 | 
					            RenderState::Dirty
 | 
				
			||||||
        ) {
 | 
					        ) {
 | 
				
			||||||
            self.renderer
 | 
					            self.renderer
 | 
				
			||||||
                .render()
 | 
					                .render()
 | 
				
			||||||
                .map_err(|e| anyhow!("Error rendering frame: {}", e))?;
 | 
					                .map_err(|e| LayerShikaError::Rendering(format!("Error rendering frame: {e}")))?;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,3 @@
 | 
				
			||||||
use anyhow::Result;
 | 
					 | 
				
			||||||
use slint::{
 | 
					use slint::{
 | 
				
			||||||
    platform::{Platform, WindowAdapter},
 | 
					    platform::{Platform, WindowAdapter},
 | 
				
			||||||
    PlatformError,
 | 
					    PlatformError,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,10 +1,11 @@
 | 
				
			||||||
use anyhow::Result;
 | 
					 | 
				
			||||||
use slint_interpreter::ComponentDefinition;
 | 
					use slint_interpreter::ComponentDefinition;
 | 
				
			||||||
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::{
 | 
					use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::{
 | 
				
			||||||
    zwlr_layer_shell_v1::{self},
 | 
					    zwlr_layer_shell_v1::{self},
 | 
				
			||||||
    zwlr_layer_surface_v1::{Anchor, KeyboardInteractivity},
 | 
					    zwlr_layer_surface_v1::{Anchor, KeyboardInteractivity},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::errors::LayerShikaError;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::{config::WindowConfig, WindowingSystem};
 | 
					use super::{config::WindowConfig, WindowingSystem};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct WindowingSystemBuilder {
 | 
					pub struct WindowingSystemBuilder {
 | 
				
			||||||
| 
						 | 
					@ -84,10 +85,12 @@ impl WindowingSystemBuilder {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[allow(clippy::missing_errors_doc)]
 | 
					    #[allow(clippy::missing_errors_doc)]
 | 
				
			||||||
    pub fn build(&mut self) -> Result<WindowingSystem> {
 | 
					    pub fn build(&mut self) -> Result<WindowingSystem, LayerShikaError> {
 | 
				
			||||||
        match self.config.component_definition {
 | 
					        match self.config.component_definition {
 | 
				
			||||||
            Some(_) => WindowingSystem::new(&mut self.config),
 | 
					            Some(_) => WindowingSystem::new(&mut self.config),
 | 
				
			||||||
            None => Err(anyhow::anyhow!("Slint component not set")),
 | 
					            None => Err(LayerShikaError::InvalidInput(
 | 
				
			||||||
 | 
					                "Slint component not set".into(),
 | 
				
			||||||
 | 
					            )),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,9 +24,9 @@ macro_rules! bind_globals {
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            $(
 | 
					            $(
 | 
				
			||||||
                let $name: $interface = $global_list.bind($queue_handle, $version, ())
 | 
					                let $name: $interface = $global_list.bind($queue_handle, $version, ())
 | 
				
			||||||
                    .with_context(|| format!("Failed to bind {}", stringify!($name)))?;
 | 
					                    .map_err(|e| LayerShikaError::WaylandDispatch(e.to_string()))?;
 | 
				
			||||||
            )+
 | 
					            )+
 | 
				
			||||||
            Ok::<($($interface,)+), anyhow::Error>(($($name,)+))
 | 
					            Ok::<($($interface,)+), LayerShikaError>(($($name,)+))
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,9 @@
 | 
				
			||||||
use self::state::WindowState;
 | 
					use self::state::WindowState;
 | 
				
			||||||
use crate::{
 | 
					use crate::{
 | 
				
			||||||
    bind_globals,
 | 
					    bind_globals,
 | 
				
			||||||
 | 
					    errors::LayerShikaError,
 | 
				
			||||||
    rendering::{egl_context::EGLContext, femtovg_window::FemtoVGWindow},
 | 
					    rendering::{egl_context::EGLContext, femtovg_window::FemtoVGWindow},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use anyhow::{Context, Result};
 | 
					 | 
				
			||||||
use config::WindowConfig;
 | 
					use config::WindowConfig;
 | 
				
			||||||
use log::{debug, error, info};
 | 
					use log::{debug, error, info};
 | 
				
			||||||
use slint::{platform::femtovg_renderer::FemtoVGRenderer, LogicalPosition, PhysicalSize};
 | 
					use slint::{platform::femtovg_renderer::FemtoVGRenderer, LogicalPosition, PhysicalSize};
 | 
				
			||||||
| 
						 | 
					@ -38,13 +38,15 @@ pub struct WindowingSystem {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl WindowingSystem {
 | 
					impl WindowingSystem {
 | 
				
			||||||
    fn new(config: &mut WindowConfig) -> Result<Self> {
 | 
					    fn new(config: &mut WindowConfig) -> Result<Self, LayerShikaError> {
 | 
				
			||||||
        info!("Initializing WindowingSystem");
 | 
					        info!("Initializing WindowingSystem");
 | 
				
			||||||
        let connection = Rc::new(Connection::connect_to_env()?);
 | 
					        let connection =
 | 
				
			||||||
 | 
					            Rc::new(Connection::connect_to_env().map_err(LayerShikaError::WaylandConnection)?);
 | 
				
			||||||
        let event_queue = connection.new_event_queue();
 | 
					        let event_queue = connection.new_event_queue();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let (compositor, output, layer_shell, seat) =
 | 
					        let (compositor, output, layer_shell, seat) =
 | 
				
			||||||
            Self::initialize_globals(&connection, &event_queue.handle())?;
 | 
					            Self::initialize_globals(&connection, &event_queue.handle())
 | 
				
			||||||
 | 
					                .map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let (surface, layer_surface) = Self::setup_surface(
 | 
					        let (surface, layer_surface) = Self::setup_surface(
 | 
				
			||||||
            &compositor,
 | 
					            &compositor,
 | 
				
			||||||
| 
						 | 
					@ -55,11 +57,11 @@ impl WindowingSystem {
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let pointer = Rc::new(seat.get_pointer(&event_queue.handle(), ()));
 | 
					        let pointer = Rc::new(seat.get_pointer(&event_queue.handle(), ()));
 | 
				
			||||||
        let window = Self::initialize_renderer(&surface, &connection.display(), config)?;
 | 
					        let window = Self::initialize_renderer(&surface, &connection.display(), config)
 | 
				
			||||||
        let component_definition = config
 | 
					            .map_err(|e| LayerShikaError::EGLContextCreation(e.to_string()))?;
 | 
				
			||||||
            .component_definition
 | 
					        let component_definition = config.component_definition.take().ok_or_else(|| {
 | 
				
			||||||
            .take()
 | 
					            LayerShikaError::WindowConfiguration("Component definition is required".to_string())
 | 
				
			||||||
            .context("Component definition is required")?;
 | 
					        })?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let state = WindowStateBuilder::new()
 | 
					        let state = WindowStateBuilder::new()
 | 
				
			||||||
            .with_component_definition(component_definition)
 | 
					            .with_component_definition(component_definition)
 | 
				
			||||||
| 
						 | 
					@ -70,9 +72,11 @@ impl WindowingSystem {
 | 
				
			||||||
            .with_height(config.height)
 | 
					            .with_height(config.height)
 | 
				
			||||||
            .with_exclusive_zone(config.exclusive_zone)
 | 
					            .with_exclusive_zone(config.exclusive_zone)
 | 
				
			||||||
            .with_window(window)
 | 
					            .with_window(window)
 | 
				
			||||||
            .build()?;
 | 
					            .build()
 | 
				
			||||||
 | 
					            .map_err(|e| LayerShikaError::WindowConfiguration(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let event_loop = EventLoop::try_new().context("Failed to create event loop")?;
 | 
					        let event_loop =
 | 
				
			||||||
 | 
					            EventLoop::try_new().map_err(|e| LayerShikaError::EventLoop(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Ok(Self {
 | 
					        Ok(Self {
 | 
				
			||||||
            state,
 | 
					            state,
 | 
				
			||||||
| 
						 | 
					@ -85,10 +89,10 @@ impl WindowingSystem {
 | 
				
			||||||
    fn initialize_globals(
 | 
					    fn initialize_globals(
 | 
				
			||||||
        connection: &Connection,
 | 
					        connection: &Connection,
 | 
				
			||||||
        queue_handle: &QueueHandle<WindowState>,
 | 
					        queue_handle: &QueueHandle<WindowState>,
 | 
				
			||||||
    ) -> Result<(WlCompositor, WlOutput, ZwlrLayerShellV1, WlSeat)> {
 | 
					    ) -> Result<(WlCompositor, WlOutput, ZwlrLayerShellV1, WlSeat), LayerShikaError> {
 | 
				
			||||||
        let global_list = registry_queue_init::<WindowState>(connection)
 | 
					        let global_list = registry_queue_init::<WindowState>(connection)
 | 
				
			||||||
            .map(|(global_list, _)| global_list)
 | 
					            .map(|(global_list, _)| global_list)
 | 
				
			||||||
            .context("Failed to initialize registry")?;
 | 
					            .map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let (compositor, output, layer_shell, seat) = bind_globals!(
 | 
					        let (compositor, output, layer_shell, seat) = bind_globals!(
 | 
				
			||||||
            &global_list,
 | 
					            &global_list,
 | 
				
			||||||
| 
						 | 
					@ -147,16 +151,18 @@ impl WindowingSystem {
 | 
				
			||||||
        surface: &Rc<WlSurface>,
 | 
					        surface: &Rc<WlSurface>,
 | 
				
			||||||
        display: &WlDisplay,
 | 
					        display: &WlDisplay,
 | 
				
			||||||
        config: &WindowConfig,
 | 
					        config: &WindowConfig,
 | 
				
			||||||
    ) -> Result<Rc<FemtoVGWindow>> {
 | 
					    ) -> Result<Rc<FemtoVGWindow>, LayerShikaError> {
 | 
				
			||||||
        let init_size = PhysicalSize::new(1, 1);
 | 
					        let init_size = PhysicalSize::new(1, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let context = EGLContext::builder()
 | 
					        let context = EGLContext::builder()
 | 
				
			||||||
            .with_display_id(display.id())
 | 
					            .with_display_id(display.id())
 | 
				
			||||||
            .with_surface_id(surface.id())
 | 
					            .with_surface_id(surface.id())
 | 
				
			||||||
            .with_size(init_size)
 | 
					            .with_size(init_size)
 | 
				
			||||||
            .build()?;
 | 
					            .build()
 | 
				
			||||||
 | 
					            .map_err(|e| LayerShikaError::EGLContextCreation(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let renderer = FemtoVGRenderer::new(context).context("Failed to create FemtoVGRenderer")?;
 | 
					        let renderer = FemtoVGRenderer::new(context)
 | 
				
			||||||
 | 
					            .map_err(|e| LayerShikaError::FemtoVGRendererCreation(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let femtovg_window = FemtoVGWindow::new(renderer);
 | 
					        let femtovg_window = FemtoVGWindow::new(renderer);
 | 
				
			||||||
        femtovg_window.set_size(slint::WindowSize::Physical(init_size));
 | 
					        femtovg_window.set_size(slint::WindowSize::Physical(init_size));
 | 
				
			||||||
| 
						 | 
					@ -170,12 +176,22 @@ impl WindowingSystem {
 | 
				
			||||||
        self.event_loop.handle()
 | 
					        self.event_loop.handle()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn run(&mut self) -> Result<()> {
 | 
					    pub fn run(&mut self) -> Result<(), LayerShikaError> {
 | 
				
			||||||
        info!("Starting WindowingSystem main loop");
 | 
					        info!("Starting WindowingSystem main loop");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while self.event_queue.blocking_dispatch(&mut self.state)? > 0 {
 | 
					        while self
 | 
				
			||||||
            self.connection.flush()?;
 | 
					            .event_queue
 | 
				
			||||||
            self.state.window().render_frame_if_dirty()?;
 | 
					            .blocking_dispatch(&mut self.state)
 | 
				
			||||||
 | 
					            .map_err(|e| LayerShikaError::WaylandProtocol(e.to_string()))?
 | 
				
			||||||
 | 
					            > 0
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            self.connection
 | 
				
			||||||
 | 
					                .flush()
 | 
				
			||||||
 | 
					                .map_err(|e| LayerShikaError::WaylandProtocol(e.to_string()))?;
 | 
				
			||||||
 | 
					            self.state
 | 
				
			||||||
 | 
					                .window()
 | 
				
			||||||
 | 
					                .render_frame_if_dirty()
 | 
				
			||||||
 | 
					                .map_err(|e| LayerShikaError::Rendering(e.to_string()))?;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.setup_wayland_event_source()?;
 | 
					        self.setup_wayland_event_source()?;
 | 
				
			||||||
| 
						 | 
					@ -189,10 +205,10 @@ impl WindowingSystem {
 | 
				
			||||||
                    error!("Error processing events: {}", e);
 | 
					                    error!("Error processing events: {}", e);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            .map_err(|e| anyhow::anyhow!("Failed to run event loop: {}", e))
 | 
					            .map_err(|e| LayerShikaError::EventLoop(e.to_string()))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn setup_wayland_event_source(&self) -> Result<()> {
 | 
					    fn setup_wayland_event_source(&self) -> Result<(), LayerShikaError> {
 | 
				
			||||||
        debug!("Setting up Wayland event source");
 | 
					        debug!("Setting up Wayland event source");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let connection = Rc::clone(&self.connection);
 | 
					        let connection = Rc::clone(&self.connection);
 | 
				
			||||||
| 
						 | 
					@ -203,7 +219,7 @@ impl WindowingSystem {
 | 
				
			||||||
                calloop::generic::Generic::new(connection, Interest::READ, Mode::Level),
 | 
					                calloop::generic::Generic::new(connection, Interest::READ, Mode::Level),
 | 
				
			||||||
                move |_, _connection, _shared_data| Ok(PostAction::Continue),
 | 
					                move |_, _connection, _shared_data| Ok(PostAction::Continue),
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            .map_err(|e| anyhow::anyhow!("Failed to set up Wayland event source: {}", e))?;
 | 
					            .map_err(|e| LayerShikaError::EventLoop(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -212,19 +228,24 @@ impl WindowingSystem {
 | 
				
			||||||
        connection: &Connection,
 | 
					        connection: &Connection,
 | 
				
			||||||
        event_queue: &mut EventQueue<WindowState>,
 | 
					        event_queue: &mut EventQueue<WindowState>,
 | 
				
			||||||
        shared_data: &mut WindowState,
 | 
					        shared_data: &mut WindowState,
 | 
				
			||||||
    ) -> Result<()> {
 | 
					    ) -> Result<(), LayerShikaError> {
 | 
				
			||||||
        if let Some(guard) = event_queue.prepare_read() {
 | 
					        if let Some(guard) = event_queue.prepare_read() {
 | 
				
			||||||
            guard
 | 
					            guard
 | 
				
			||||||
                .read()
 | 
					                .read()
 | 
				
			||||||
                .map_err(|e| anyhow::anyhow!("Failed to read events: {}", e))?;
 | 
					                .map_err(|e| LayerShikaError::WaylandProtocol(e.to_string()))?;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        connection.flush()?;
 | 
					        connection.flush()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        event_queue.dispatch_pending(shared_data)?;
 | 
					        event_queue
 | 
				
			||||||
 | 
					            .dispatch_pending(shared_data)
 | 
				
			||||||
 | 
					            .map_err(|e| LayerShikaError::WaylandProtocol(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        slint::platform::update_timers_and_animations();
 | 
					        slint::platform::update_timers_and_animations();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        shared_data.window().render_frame_if_dirty()?;
 | 
					        shared_data
 | 
				
			||||||
 | 
					            .window()
 | 
				
			||||||
 | 
					            .render_frame_if_dirty()
 | 
				
			||||||
 | 
					            .map_err(|e| LayerShikaError::Rendering(e.to_string()))?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,8 +3,7 @@ use slint::PhysicalSize;
 | 
				
			||||||
use slint_interpreter::ComponentDefinition;
 | 
					use slint_interpreter::ComponentDefinition;
 | 
				
			||||||
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
 | 
					use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
 | 
				
			||||||
use wayland_client::protocol::{wl_pointer::WlPointer, wl_surface::WlSurface};
 | 
					use wayland_client::protocol::{wl_pointer::WlPointer, wl_surface::WlSurface};
 | 
				
			||||||
use crate::rendering::{femtovg_window::FemtoVGWindow, slint_platform::CustomSlintPlatform};
 | 
					use crate::{errors::LayerShikaError, rendering::{femtovg_window::FemtoVGWindow, slint_platform::CustomSlintPlatform}};
 | 
				
			||||||
use anyhow::{Context, Result};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
use super::WindowState;
 | 
					use super::WindowState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -76,12 +75,15 @@ impl WindowStateBuilder {
 | 
				
			||||||
        self
 | 
					        self
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn build(self) -> Result<WindowState> {
 | 
					    pub fn build(self) -> Result<WindowState, LayerShikaError> {
 | 
				
			||||||
        let platform = CustomSlintPlatform::new(Rc::clone(
 | 
					        let platform = CustomSlintPlatform::new(Rc::clone(
 | 
				
			||||||
            self.window.as_ref().context("Window is required")?,
 | 
					            self.window
 | 
				
			||||||
 | 
					                .as_ref()
 | 
				
			||||||
 | 
					                .ok_or_else(|| LayerShikaError::InvalidInput("Window is required".into()))?,
 | 
				
			||||||
        ));
 | 
					        ));
 | 
				
			||||||
        slint::platform::set_platform(Box::new(platform))
 | 
					        slint::platform::set_platform(Box::new(platform)).map_err(|e| {
 | 
				
			||||||
            .map_err(|e| anyhow::anyhow!("Failed to set platform: {:?}", e))?;
 | 
					            LayerShikaError::PlatformSetup(format!("Failed to set platform: {e:?}"))
 | 
				
			||||||
 | 
					        })?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        WindowState::new(self)
 | 
					        WindowState::new(self)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ use slint_interpreter::ComponentInstance;
 | 
				
			||||||
use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
 | 
					use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1;
 | 
				
			||||||
use wayland_client::protocol::wl_surface::WlSurface;
 | 
					use wayland_client::protocol::wl_surface::WlSurface;
 | 
				
			||||||
use crate::rendering::femtovg_window::FemtoVGWindow;
 | 
					use crate::rendering::femtovg_window::FemtoVGWindow;
 | 
				
			||||||
use anyhow::{Context, Result};
 | 
					use crate::errors::LayerShikaError;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub mod builder;
 | 
					pub mod builder;
 | 
				
			||||||
pub mod dispatches;
 | 
					pub mod dispatches;
 | 
				
			||||||
| 
						 | 
					@ -25,23 +25,29 @@ pub struct WindowState {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl WindowState {
 | 
					impl WindowState {
 | 
				
			||||||
    pub fn new(builder: WindowStateBuilder) -> Result<Self> {
 | 
					    pub fn new(builder: WindowStateBuilder) -> Result<Self, LayerShikaError> {
 | 
				
			||||||
        let component_definition = builder
 | 
					        let component_definition = builder.component_definition.ok_or_else(|| {
 | 
				
			||||||
            .component_definition
 | 
					            LayerShikaError::InvalidInput("Component definition is required".into())
 | 
				
			||||||
            .context("Component definition is required")?;
 | 
					        })?;
 | 
				
			||||||
        let component_instance = component_definition
 | 
					        let component_instance = component_definition
 | 
				
			||||||
            .create()
 | 
					            .create()
 | 
				
			||||||
            .context("Failed to create component instance")?;
 | 
					            .map_err(|e| LayerShikaError::SlintComponentCreation(e.to_string()))?;
 | 
				
			||||||
        component_instance
 | 
					        component_instance
 | 
				
			||||||
            .show()
 | 
					            .show()
 | 
				
			||||||
            .context("Failed to show component")?;
 | 
					            .map_err(|e| LayerShikaError::SlintComponentCreation(e.to_string()))?;
 | 
				
			||||||
        Ok(Self {
 | 
					        Ok(Self {
 | 
				
			||||||
            component_instance,
 | 
					            component_instance,
 | 
				
			||||||
            surface: builder.surface.context("Surface is required")?,
 | 
					            surface: builder
 | 
				
			||||||
            layer_surface: builder.layer_surface.context("Layer surface is required")?,
 | 
					                .surface
 | 
				
			||||||
 | 
					                .ok_or_else(|| LayerShikaError::InvalidInput("Surface is required".into()))?,
 | 
				
			||||||
 | 
					            layer_surface: builder
 | 
				
			||||||
 | 
					                .layer_surface
 | 
				
			||||||
 | 
					                .ok_or_else(|| LayerShikaError::InvalidInput("Layer surface is required".into()))?,
 | 
				
			||||||
            size: builder.size.unwrap_or_default(),
 | 
					            size: builder.size.unwrap_or_default(),
 | 
				
			||||||
            output_size: builder.output_size.unwrap_or_default(),
 | 
					            output_size: builder.output_size.unwrap_or_default(),
 | 
				
			||||||
            window: builder.window.context("Window is required")?,
 | 
					            window: builder
 | 
				
			||||||
 | 
					                .window
 | 
				
			||||||
 | 
					                .ok_or_else(|| LayerShikaError::InvalidInput("Window is required".into()))?,
 | 
				
			||||||
            current_pointer_position: LogicalPosition::default(),
 | 
					            current_pointer_position: LogicalPosition::default(),
 | 
				
			||||||
            scale_factor: builder.scale_factor,
 | 
					            scale_factor: builder.scale_factor,
 | 
				
			||||||
            height: builder.height,
 | 
					            height: builder.height,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue