refactor: minor refactor

This commit is contained in:
drendog 2025-10-25 11:58:15 +02:00
parent 2cd5df6ee1
commit b232df23a9
Signed by: dwenya
GPG key ID: 8DD77074645332D0
5 changed files with 33 additions and 36 deletions

View file

@ -47,13 +47,13 @@ impl FemtoVGWindow {
}
pub fn set_scale_factor(&self, scale_factor: f32) {
info!("Setting scale factor to {}", scale_factor);
info!("Setting scale factor to {scale_factor}");
self.scale_factor.set(scale_factor);
self.window()
.dispatch_event(WindowEvent::ScaleFactorChanged { scale_factor });
}
pub fn scale_factor(&self) -> f32 {
pub const fn scale_factor(&self) -> f32 {
self.scale_factor.get()
}
}

View file

@ -11,13 +11,13 @@ pub struct CustomSlintPlatform {
}
impl CustomSlintPlatform {
pub fn new(window: Rc<FemtoVGWindow>) -> Self {
pub const fn new(window: Rc<FemtoVGWindow>) -> Self {
Self { window }
}
}
impl Platform for CustomSlintPlatform {
fn create_window_adapter(&self) -> Result<Rc<(dyn WindowAdapter + 'static)>, PlatformError> {
fn create_window_adapter(&self) -> Result<Rc<dyn WindowAdapter + 'static>, PlatformError> {
Result::Ok(Rc::clone(&self.window) as Rc<dyn WindowAdapter>)
}
}

View file

@ -37,6 +37,22 @@ mod config;
mod macros;
mod state;
type GlobalObjects = (
WlCompositor,
WlOutput,
ZwlrLayerShellV1,
WlSeat,
Option<WpFractionalScaleManagerV1>,
Option<WpViewporter>,
);
type SurfaceObjects = (
Rc<WlSurface>,
Rc<ZwlrLayerSurfaceV1>,
Option<Rc<WpFractionalScaleV1>>,
Option<Rc<WpViewport>>,
);
pub struct WindowingSystem {
state: WindowState,
connection: Rc<Connection>,
@ -108,17 +124,7 @@ impl WindowingSystem {
fn initialize_globals(
connection: &Connection,
queue_handle: &QueueHandle<WindowState>,
) -> Result<
(
WlCompositor,
WlOutput,
ZwlrLayerShellV1,
WlSeat,
Option<WpFractionalScaleManagerV1>,
Option<WpViewporter>,
),
LayerShikaError,
> {
) -> Result<GlobalObjects, LayerShikaError> {
let global_list = registry_queue_init::<WindowState>(connection)
.map(|(global_list, _)| global_list)
.map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?;
@ -166,12 +172,7 @@ impl WindowingSystem {
viewporter: Option<&WpViewporter>,
queue_handle: &QueueHandle<WindowState>,
config: &WindowConfig,
) -> (
Rc<WlSurface>,
Rc<ZwlrLayerSurfaceV1>,
Option<Rc<WpFractionalScaleV1>>,
Option<Rc<WpViewport>>,
) {
) -> SurfaceObjects {
let surface = Rc::new(compositor.create_surface(queue_handle, ()));
let layer_surface = Rc::new(layer_shell.get_layer_surface(
&surface,
@ -273,7 +274,7 @@ impl WindowingSystem {
self.event_loop
.run(None, &mut self.state, move |shared_data| {
if let Err(e) = Self::process_events(connection, event_queue, shared_data) {
error!("Error processing events: {}", e);
error!("Error processing events: {e}");
}
})
.map_err(|e| LayerShikaError::EventLoop(e.to_string()))

View file

@ -49,10 +49,7 @@ impl Dispatch<ZwlrLayerSurfaceV1, ()> for WindowState {
width,
height,
} => {
info!(
"Layer surface configured with compositor size: {}x{}",
width, height
);
info!("Layer surface configured with compositor size: {width}x{height}");
layer_surface.ack_configure(serial);
let output_width = state.output_size().width;
@ -112,19 +109,19 @@ impl Dispatch<WlOutput, ()> for WindowState {
) {
match event {
wl_output::Event::Mode { width, height, .. } => {
info!("WlOutput size changed to {}x{}", width, height);
info!("WlOutput size changed to {width}x{height}");
let width = width.try_into().unwrap_or_default();
let height = height.try_into().unwrap_or_default();
state.set_output_size(PhysicalSize::new(width, height));
}
wl_output::Event::Description { ref description } => {
info!("WlOutput description: {:?}", description);
info!("WlOutput description: {description:?}");
}
wl_output::Event::Scale { ref factor } => {
info!("WlOutput factor scale: {:?}", factor);
info!("WlOutput factor scale: {factor:?}");
}
wl_output::Event::Name { ref name } => {
info!("WlOutput name: {:?}", name);
info!("WlOutput name: {name:?}");
}
wl_output::Event::Geometry {
x,
@ -136,7 +133,7 @@ impl Dispatch<WlOutput, ()> for WindowState {
model,
transform,
} => {
info!("WlOutput geometry: x={}, y={}, physical_width={}, physical_height={}, subpixel={:?}, make={:?}, model={:?}, transform={:?}", x, y, physical_width, physical_height, subpixel, make, model, transform);
info!("WlOutput geometry: x={x}, y={y}, physical_width={physical_width}, physical_height={physical_height}, subpixel={subpixel:?}, make={make:?}, model={model:?}, transform={transform:?}");
}
wl_output::Event::Done => {
info!("WlOutput done");

View file

@ -67,12 +67,11 @@ impl WindowState {
})
}
#[allow(clippy::cast_precision_loss)]
#[allow(clippy::cast_possible_wrap)]
pub fn update_size(&mut self, width: u32, height: u32) {
if width == 0 || height == 0 {
info!(
"Skipping update_size with zero dimension: {}x{}",
width, height
);
info!("Skipping update_size with zero dimension: {width}x{height}");
return;
}
@ -181,7 +180,7 @@ impl WindowState {
self.height
}
pub fn set_output_size(&mut self, output_size: PhysicalSize) {
pub const fn set_output_size(&mut self, output_size: PhysicalSize) {
self.output_size = output_size;
}