refactor: decompose ws constructor

This commit is contained in:
drendog 2025-10-25 21:33:16 +02:00
parent db46d7ce8a
commit f5338750e6
Signed by: dwenya
GPG key ID: 8DD77074645332D0

View file

@ -33,11 +33,32 @@ pub struct WindowingSystem {
impl WindowingSystem { impl WindowingSystem {
pub(super) fn new(config: WindowConfig) -> Result<Self> { pub(super) fn new(config: WindowConfig) -> Result<Self> {
info!("Initializing WindowingSystem"); info!("Initializing WindowingSystem");
let (connection, event_queue) = Self::init_wayland_connection()?;
let state = Self::init_state(config, &connection, &event_queue)?;
let event_loop =
EventLoop::try_new().map_err(|e| LayerShikaError::EventLoop(e.to_string()))?;
Ok(Self {
state,
connection,
event_queue,
event_loop,
})
}
fn init_wayland_connection() -> Result<(Rc<Connection>, EventQueue<WindowState>)> {
let connection = let connection =
Rc::new(Connection::connect_to_env().map_err(LayerShikaError::WaylandConnection)?); Rc::new(Connection::connect_to_env().map_err(LayerShikaError::WaylandConnection)?);
let event_queue = connection.new_event_queue(); let event_queue = connection.new_event_queue();
Ok((connection, event_queue))
}
let global_ctx = GlobalCtx::initialize(&connection, &event_queue.handle()) fn init_state(
config: WindowConfig,
connection: &Connection,
event_queue: &EventQueue<WindowState>,
) -> Result<WindowState> {
let global_ctx = GlobalCtx::initialize(connection, &event_queue.handle())
.map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?; .map_err(|e| LayerShikaError::GlobalInitialization(e.to_string()))?;
let layer_surface_params = LayerSurfaceParams { let layer_surface_params = LayerSurfaceParams {
@ -86,19 +107,9 @@ impl WindowingSystem {
builder = builder.with_viewport(Rc::clone(vp)); builder = builder.with_viewport(Rc::clone(vp));
} }
let state = builder builder
.build() .build()
.map_err(|e| LayerShikaError::WindowConfiguration(e.to_string()))?; .map_err(|e| LayerShikaError::WindowConfiguration(e.to_string()))
let event_loop =
EventLoop::try_new().map_err(|e| LayerShikaError::EventLoop(e.to_string()))?;
Ok(Self {
state,
connection,
event_queue,
event_loop,
})
} }
fn initialize_renderer( fn initialize_renderer(