mirror of
https://codeberg.org/waydeer/layer-shika.git
synced 2025-10-28 14:14:23 +00:00
refactor: result alias
This commit is contained in:
parent
8094a5cecb
commit
9f6cd31322
8 changed files with 29 additions and 28 deletions
|
|
@ -1,5 +1,7 @@
|
|||
use thiserror::Error;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, LayerShikaError>;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum LayerShikaError {
|
||||
#[error("Failed to connect to Wayland: {0}")]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<EGLContext, LayerShikaError> {
|
||||
pub fn build(self) -> Result<EGLContext> {
|
||||
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<RawDisplayHandle, LayerShikaError> {
|
||||
fn create_wayland_display_handle(display_id: &ObjectId) -> Result<RawDisplayHandle> {
|
||||
let display = NonNull::new(display_id.as_ptr().cast::<c_void>()).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<glutin::api::egl::config::Config, LayerShikaError> {
|
||||
) -> Result<glutin::api::egl::config::Config> {
|
||||
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<glutin::api::egl::context::NotCurrentContext, LayerShikaError> {
|
||||
) -> Result<glutin::api::egl::context::NotCurrentContext> {
|
||||
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<RawWindowHandle, LayerShikaError> {
|
||||
fn create_surface_handle(surface_id: &ObjectId) -> Result<RawWindowHandle> {
|
||||
let surface = NonNull::new(surface_id.as_ptr().cast::<c_void>()).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<Surface<WindowSurface>, LayerShikaError> {
|
||||
) -> Result<Surface<WindowSurface>> {
|
||||
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<dyn std::error::Error + Send + Sync>> {
|
||||
fn ensure_current(&self) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
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) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
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<dyn std::error::Error + Send + Sync>> {
|
||||
) -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
self.ensure_current()?;
|
||||
self.surface.resize(&self.context, width, height);
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<WindowingSystem, LayerShikaError> {
|
||||
pub fn build(&mut self) -> Result<WindowingSystem> {
|
||||
match self.config.component_definition {
|
||||
Some(_) => WindowingSystem::new(&mut self.config),
|
||||
None => Err(LayerShikaError::InvalidInput(
|
||||
|
|
|
|||
|
|
@ -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<Self, LayerShikaError> {
|
||||
fn new(config: &mut WindowConfig) -> Result<Self> {
|
||||
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<WindowState>,
|
||||
) -> Result<GlobalObjects, LayerShikaError> {
|
||||
) -> Result<GlobalObjects> {
|
||||
let global_list = registry_queue_init::<WindowState>(connection)
|
||||
.map(|(global_list, _)| global_list)
|
||||
.map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?;
|
||||
|
|
@ -223,7 +223,7 @@ impl WindowingSystem {
|
|||
surface: &Rc<WlSurface>,
|
||||
display: &WlDisplay,
|
||||
config: &WindowConfig,
|
||||
) -> Result<Rc<FemtoVGWindow>, LayerShikaError> {
|
||||
) -> Result<Rc<FemtoVGWindow>> {
|
||||
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<WindowState>,
|
||||
shared_data: &mut WindowState,
|
||||
) -> Result<(), LayerShikaError> {
|
||||
) -> Result<()> {
|
||||
if let Some(guard) = event_queue.prepare_read() {
|
||||
guard
|
||||
.read()
|
||||
|
|
|
|||
|
|
@ -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<WindowState, LayerShikaError> {
|
||||
pub fn build(self) -> Result<WindowState> {
|
||||
let platform = CustomSlintPlatform::new(Rc::clone(
|
||||
self.window
|
||||
.as_ref()
|
||||
|
|
|
|||
|
|
@ -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<Self, LayerShikaError> {
|
||||
pub fn new(builder: WindowStateBuilder) -> Result<Self> {
|
||||
let component_definition = builder.component_definition.ok_or_else(|| {
|
||||
LayerShikaError::InvalidInput("Component definition is required".into())
|
||||
})?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue