From 1c5bb977824cfe900238852336a143a6db36ba0e Mon Sep 17 00:00:00 2001 From: drendog Date: Sat, 25 Oct 2025 15:09:57 +0200 Subject: [PATCH] refactor: remove absolute paths --- Cargo.toml | 1 + src/errors.rs | 6 ++++-- src/rendering/egl_context.rs | 25 ++++++++++++++++--------- src/rendering/femtovg_window.rs | 3 ++- src/windowing/mod.rs | 11 +++++++---- src/windowing/state/builder.rs | 4 ++-- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a80843d..3e245c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ clone_on_ref_ptr = "warn" multiple-crate-versions = "allow" module_name_repetitions = "allow" unwrap_used = "warn" +absolute_paths = "deny" [dependencies] glutin = { version = "0.32.3", default-features = false, features = [ diff --git a/src/errors.rs b/src/errors.rs index c219215..3e2c1a7 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,8 @@ +use std::result::Result as StdResult; use thiserror::Error; +use wayland_client::backend::WaylandError; -pub type Result = std::result::Result; +pub type Result = StdResult; #[derive(Error, Debug)] pub enum LayerShikaError { @@ -41,5 +43,5 @@ pub enum LayerShikaError { PlatformSetup(String), #[error("Failed to flush connection: {0}")] - ConnectionFlush(#[from] wayland_client::backend::WaylandError), + ConnectionFlush(#[from] WaylandError), } diff --git a/src/rendering/egl_context.rs b/src/rendering/egl_context.rs index d0eb7a1..4334446 100644 --- a/src/rendering/egl_context.rs +++ b/src/rendering/egl_context.rs @@ -1,6 +1,11 @@ use crate::errors::{LayerShikaError, Result}; use glutin::{ - api::egl::{context::PossiblyCurrentContext, display::Display, surface::Surface}, + api::egl::{ + config::Config, + context::{NotCurrentContext, PossiblyCurrentContext}, + display::Display, + surface::Surface, + }, config::ConfigTemplateBuilder, context::ContextAttributesBuilder, display::GetGlDisplay, @@ -12,9 +17,11 @@ use raw_window_handle::{ }; use slint::{platform::femtovg_renderer::OpenGLInterface, PhysicalSize}; use std::{ + error::Error, ffi::{self, c_void, CStr}, num::NonZeroU32, ptr::NonNull, + result::Result as StdResult, }; use wayland_client::backend::ObjectId; @@ -128,7 +135,7 @@ fn create_wayland_display_handle(display_id: &ObjectId) -> Result 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(|| { @@ -138,9 +145,9 @@ fn select_config( fn create_context( glutin_display: &Display, - config: &glutin::api::egl::config::Config, + 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}"))) } @@ -155,7 +162,7 @@ fn create_surface_handle(surface_id: &ObjectId) -> Result { fn create_surface( glutin_display: &Display, - config: &glutin::api::egl::config::Config, + config: &Config, surface_handle: RawWindowHandle, size: PhysicalSize, ) -> Result> { @@ -174,12 +181,12 @@ fn create_surface( } unsafe impl OpenGLInterface for EGLContext { - fn ensure_current(&self) -> std::result::Result<(), Box> { + fn ensure_current(&self) -> StdResult<(), Box> { self.ensure_current() - .map_err(|e| Box::new(e) as Box) + .map_err(|e| Box::new(e) as Box) } - fn swap_buffers(&self) -> std::result::Result<(), Box> { + fn swap_buffers(&self) -> StdResult<(), Box> { self.surface.swap_buffers(&self.context).map_err(|e| { LayerShikaError::EGLContextCreation(format!("Failed to swap buffers: {e}")).into() }) @@ -189,7 +196,7 @@ unsafe impl OpenGLInterface for EGLContext { &self, width: NonZeroU32, height: NonZeroU32, - ) -> std::result::Result<(), Box> { + ) -> StdResult<(), 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 6903eeb..d39329a 100644 --- a/src/rendering/femtovg_window.rs +++ b/src/rendering/femtovg_window.rs @@ -1,4 +1,5 @@ use crate::errors::{LayerShikaError, Result}; +use core::ops::Deref; use log::info; use slint::{ platform::{femtovg_renderer::FemtoVGRenderer, Renderer, WindowAdapter, WindowEvent}, @@ -83,7 +84,7 @@ impl WindowAdapter for FemtoVGWindow { } } -impl core::ops::Deref for FemtoVGWindow { +impl Deref for FemtoVGWindow { type Target = Window; fn deref(&self) -> &Self::Target { &self.window diff --git a/src/windowing/mod.rs b/src/windowing/mod.rs index e1bf675..e841214 100644 --- a/src/windowing/mod.rs +++ b/src/windowing/mod.rs @@ -6,10 +6,13 @@ use crate::{ }; use config::WindowConfig; use log::{debug, error, info}; -use slint::{platform::femtovg_renderer::FemtoVGRenderer, LogicalPosition, PhysicalSize}; +use slint::{ + platform::{femtovg_renderer::FemtoVGRenderer, update_timers_and_animations}, + LogicalPosition, PhysicalSize, +}; use slint_interpreter::ComponentInstance; use smithay_client_toolkit::reexports::{ - calloop::{self, EventLoop, Interest, LoopHandle, Mode, PostAction}, + calloop::{generic::Generic, EventLoop, Interest, LoopHandle, Mode, PostAction}, protocols_wlr::layer_shell::v1::client::{ zwlr_layer_shell_v1::ZwlrLayerShellV1, zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, }, @@ -288,7 +291,7 @@ impl WindowingSystem { self.event_loop .handle() .insert_source( - calloop::generic::Generic::new(connection, Interest::READ, Mode::Level), + Generic::new(connection, Interest::READ, Mode::Level), move |_, _connection, _shared_data| Ok(PostAction::Continue), ) .map_err(|e| LayerShikaError::EventLoop(e.to_string()))?; @@ -312,7 +315,7 @@ impl WindowingSystem { .dispatch_pending(shared_data) .map_err(|e| LayerShikaError::WaylandProtocol(e.to_string()))?; - slint::platform::update_timers_and_animations(); + update_timers_and_animations(); shared_data .window() diff --git a/src/windowing/state/builder.rs b/src/windowing/state/builder.rs index 23b8ffb..a99f356 100644 --- a/src/windowing/state/builder.rs +++ b/src/windowing/state/builder.rs @@ -1,5 +1,5 @@ use std::rc::Rc; -use slint::PhysicalSize; +use slint::{platform::set_platform, PhysicalSize}; use slint_interpreter::ComponentDefinition; 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}; @@ -108,7 +108,7 @@ impl WindowStateBuilder { .as_ref() .ok_or_else(|| LayerShikaError::InvalidInput("Window is required".into()))?, )); - slint::platform::set_platform(Box::new(platform)).map_err(|e| { + set_platform(Box::new(platform)).map_err(|e| { LayerShikaError::PlatformSetup(format!("Failed to set platform: {e:?}")) })?;