diff --git a/src/errors.rs b/src/errors.rs index a26c107..c219215 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,5 +1,7 @@ use thiserror::Error; +pub type Result = std::result::Result; + #[derive(Error, Debug)] pub enum LayerShikaError { #[error("Failed to connect to Wayland: {0}")] diff --git a/src/lib.rs b/src/lib.rs index d88d561..cc14910 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,5 +3,6 @@ mod reexports; mod rendering; mod windowing; +pub use errors::{LayerShikaError, Result}; pub use reexports::*; pub use windowing::builder::WindowingSystemBuilder as LayerShika; diff --git a/src/rendering/egl_context.rs b/src/rendering/egl_context.rs index a34d252..d0eb7a1 100644 --- a/src/rendering/egl_context.rs +++ b/src/rendering/egl_context.rs @@ -1,4 +1,4 @@ -use crate::errors::LayerShikaError; +use crate::errors::{LayerShikaError, Result}; use glutin::{ api::egl::{context::PossiblyCurrentContext, display::Display, surface::Surface}, config::ConfigTemplateBuilder, @@ -67,7 +67,7 @@ impl EGLContextBuilder { self } - pub fn build(self) -> Result { + pub fn build(self) -> Result { let display_id = self .display_id .ok_or_else(|| LayerShikaError::InvalidInput("Display ID is required".into()))?; @@ -107,7 +107,7 @@ impl EGLContext { EGLContextBuilder::new() } - fn ensure_current(&self) -> Result<(), LayerShikaError> { + fn ensure_current(&self) -> Result<()> { if !self.context.is_current() { self.context.make_current(&self.surface).map_err(|e| { LayerShikaError::EGLContextCreation(format!("Failed to make context current: {e}")) @@ -117,9 +117,7 @@ impl EGLContext { } } -fn create_wayland_display_handle( - display_id: &ObjectId, -) -> Result { +fn create_wayland_display_handle(display_id: &ObjectId) -> Result { let display = NonNull::new(display_id.as_ptr().cast::()).ok_or_else(|| { LayerShikaError::InvalidInput("Failed to create NonNull pointer for display".into()) })?; @@ -130,7 +128,7 @@ fn create_wayland_display_handle( fn select_config( glutin_display: &Display, config_template: ConfigTemplateBuilder, -) -> Result { +) -> Result { let mut configs = unsafe { glutin_display.find_configs(config_template.build()) } .map_err(|e| LayerShikaError::EGLContextCreation(format!("Failed to find configs: {e}")))?; configs.next().ok_or_else(|| { @@ -142,12 +140,12 @@ fn create_context( glutin_display: &Display, config: &glutin::api::egl::config::Config, context_attributes: ContextAttributesBuilder, -) -> Result { +) -> Result { unsafe { glutin_display.create_context(config, &context_attributes.build(None)) } .map_err(|e| LayerShikaError::EGLContextCreation(format!("Failed to create context: {e}"))) } -fn create_surface_handle(surface_id: &ObjectId) -> Result { +fn create_surface_handle(surface_id: &ObjectId) -> Result { let surface = NonNull::new(surface_id.as_ptr().cast::()).ok_or_else(|| { LayerShikaError::InvalidInput("Failed to create NonNull pointer for surface".into()) })?; @@ -160,7 +158,7 @@ fn create_surface( config: &glutin::api::egl::config::Config, surface_handle: RawWindowHandle, size: PhysicalSize, -) -> Result, LayerShikaError> { +) -> Result> { let width = NonZeroU32::new(size.width) .ok_or_else(|| LayerShikaError::InvalidInput("Width cannot be zero".into()))?; @@ -176,12 +174,12 @@ fn create_surface( } unsafe impl OpenGLInterface for EGLContext { - fn ensure_current(&self) -> Result<(), Box> { + fn ensure_current(&self) -> std::result::Result<(), Box> { self.ensure_current() .map_err(|e| Box::new(e) as Box) } - fn swap_buffers(&self) -> Result<(), Box> { + fn swap_buffers(&self) -> std::result::Result<(), Box> { self.surface.swap_buffers(&self.context).map_err(|e| { LayerShikaError::EGLContextCreation(format!("Failed to swap buffers: {e}")).into() }) @@ -191,7 +189,7 @@ unsafe impl OpenGLInterface for EGLContext { &self, width: NonZeroU32, height: NonZeroU32, - ) -> Result<(), Box> { + ) -> std::result::Result<(), Box> { self.ensure_current()?; self.surface.resize(&self.context, width, height); Ok(()) diff --git a/src/rendering/femtovg_window.rs b/src/rendering/femtovg_window.rs index b9c0dc9..6903eeb 100644 --- a/src/rendering/femtovg_window.rs +++ b/src/rendering/femtovg_window.rs @@ -1,4 +1,4 @@ -use crate::errors::LayerShikaError; +use crate::errors::{LayerShikaError, Result}; use log::info; use slint::{ platform::{femtovg_renderer::FemtoVGRenderer, Renderer, WindowAdapter, WindowEvent}, @@ -34,7 +34,7 @@ impl FemtoVGWindow { }) } - pub fn render_frame_if_dirty(&self) -> Result<(), LayerShikaError> { + pub fn render_frame_if_dirty(&self) -> Result<()> { if matches!( self.render_state.replace(RenderState::Clean), RenderState::Dirty diff --git a/src/windowing/builder.rs b/src/windowing/builder.rs index b47ddf6..96d5c98 100644 --- a/src/windowing/builder.rs +++ b/src/windowing/builder.rs @@ -4,7 +4,7 @@ use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::{ zwlr_layer_surface_v1::{Anchor, KeyboardInteractivity}, }; -use crate::errors::LayerShikaError; +use crate::errors::{LayerShikaError, Result}; use super::{config::WindowConfig, WindowingSystem}; @@ -85,7 +85,7 @@ impl WindowingSystemBuilder { } #[allow(clippy::missing_errors_doc)] - pub fn build(&mut self) -> Result { + pub fn build(&mut self) -> Result { match self.config.component_definition { Some(_) => WindowingSystem::new(&mut self.config), None => Err(LayerShikaError::InvalidInput( diff --git a/src/windowing/mod.rs b/src/windowing/mod.rs index 15da7b9..e1bf675 100644 --- a/src/windowing/mod.rs +++ b/src/windowing/mod.rs @@ -1,7 +1,7 @@ use self::state::WindowState; use crate::{ bind_globals, - errors::LayerShikaError, + errors::{LayerShikaError, Result}, rendering::{egl_context::EGLContext, femtovg_window::FemtoVGWindow}, }; use config::WindowConfig; @@ -61,7 +61,7 @@ pub struct WindowingSystem { } impl WindowingSystem { - fn new(config: &mut WindowConfig) -> Result { + fn new(config: &mut WindowConfig) -> Result { info!("Initializing WindowingSystem"); let connection = Rc::new(Connection::connect_to_env().map_err(LayerShikaError::WaylandConnection)?); @@ -124,7 +124,7 @@ impl WindowingSystem { fn initialize_globals( connection: &Connection, queue_handle: &QueueHandle, - ) -> Result { + ) -> Result { let global_list = registry_queue_init::(connection) .map(|(global_list, _)| global_list) .map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?; @@ -223,7 +223,7 @@ impl WindowingSystem { surface: &Rc, display: &WlDisplay, config: &WindowConfig, - ) -> Result, LayerShikaError> { + ) -> Result> { let init_size = PhysicalSize::new(1, 1); let context = EGLContext::builder() @@ -248,7 +248,7 @@ impl WindowingSystem { self.event_loop.handle() } - pub fn run(&mut self) -> Result<(), LayerShikaError> { + pub fn run(&mut self) -> Result<()> { info!("Starting WindowingSystem main loop"); while self @@ -280,7 +280,7 @@ impl WindowingSystem { .map_err(|e| LayerShikaError::EventLoop(e.to_string())) } - fn setup_wayland_event_source(&self) -> Result<(), LayerShikaError> { + fn setup_wayland_event_source(&self) -> Result<()> { debug!("Setting up Wayland event source"); let connection = Rc::clone(&self.connection); @@ -300,7 +300,7 @@ impl WindowingSystem { connection: &Connection, event_queue: &mut EventQueue, shared_data: &mut WindowState, - ) -> Result<(), LayerShikaError> { + ) -> Result<()> { if let Some(guard) = event_queue.prepare_read() { guard .read() diff --git a/src/windowing/state/builder.rs b/src/windowing/state/builder.rs index ba04eb6..23b8ffb 100644 --- a/src/windowing/state/builder.rs +++ b/src/windowing/state/builder.rs @@ -5,7 +5,7 @@ use smithay_client_toolkit::reexports::protocols_wlr::layer_shell::v1::client::z use wayland_client::protocol::{wl_pointer::WlPointer, wl_surface::WlSurface}; use wayland_protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1; use wayland_protocols::wp::viewporter::client::wp_viewport::WpViewport; -use crate::{errors::LayerShikaError, rendering::{femtovg_window::FemtoVGWindow, slint_platform::CustomSlintPlatform}}; +use crate::{errors::{LayerShikaError, Result}, rendering::{femtovg_window::FemtoVGWindow, slint_platform::CustomSlintPlatform}}; use super::WindowState; @@ -102,7 +102,7 @@ impl WindowStateBuilder { self } - pub fn build(self) -> Result { + pub fn build(self) -> Result { let platform = CustomSlintPlatform::new(Rc::clone( self.window .as_ref() diff --git a/src/windowing/state/mod.rs b/src/windowing/state/mod.rs index d468567..fafb83c 100644 --- a/src/windowing/state/mod.rs +++ b/src/windowing/state/mod.rs @@ -8,7 +8,7 @@ use wayland_client::protocol::wl_surface::WlSurface; use wayland_protocols::wp::fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1; use wayland_protocols::wp::viewporter::client::wp_viewport::WpViewport; use crate::rendering::femtovg_window::FemtoVGWindow; -use crate::errors::LayerShikaError; +use crate::errors::{LayerShikaError, Result}; pub mod builder; pub mod dispatches; @@ -30,7 +30,7 @@ pub struct WindowState { } impl WindowState { - pub fn new(builder: WindowStateBuilder) -> Result { + pub fn new(builder: WindowStateBuilder) -> Result { let component_definition = builder.component_definition.ok_or_else(|| { LayerShikaError::InvalidInput("Component definition is required".into()) })?;