refactor: remove window system lifetime as it's not necessary

WIP/draft
drendog 2024-08-16 16:00:14 +02:00
parent a8c21ad2bc
commit 22cf1c8b70
Signed by: dwenya
GPG Key ID: 8DD77074645332D0
1 changed files with 7 additions and 6 deletions

View File

@ -10,7 +10,7 @@ use log::{debug, info};
use slint::{platform::femtovg_renderer::FemtoVGRenderer, ComponentHandle, LogicalPosition}; use slint::{platform::femtovg_renderer::FemtoVGRenderer, ComponentHandle, LogicalPosition};
use slint_interpreter::{ComponentDefinition, ComponentInstance}; use slint_interpreter::{ComponentDefinition, ComponentInstance};
use smithay_client_toolkit::reexports::{ use smithay_client_toolkit::reexports::{
calloop::{self, EventLoop}, calloop::{EventLoop, LoopHandle},
protocols_wlr::layer_shell::v1::client::{ protocols_wlr::layer_shell::v1::client::{
zwlr_layer_shell_v1::{self, ZwlrLayerShellV1}, zwlr_layer_shell_v1::{self, ZwlrLayerShellV1},
zwlr_layer_surface_v1::{Anchor, KeyboardInteractivity, ZwlrLayerSurfaceV1}, zwlr_layer_surface_v1::{Anchor, KeyboardInteractivity, ZwlrLayerSurfaceV1},
@ -137,7 +137,7 @@ impl WindowingSystemBuilder {
self self
} }
pub fn build(self) -> Result<WindowingSystem<'static>> { pub fn build(self) -> Result<WindowingSystem> {
if self.config.component_definition.is_none() { if self.config.component_definition.is_none() {
return Err(anyhow::anyhow!("Slint component not set")); return Err(anyhow::anyhow!("Slint component not set"));
} }
@ -146,24 +146,25 @@ impl WindowingSystemBuilder {
} }
} }
pub struct WindowingSystem<'a> { pub struct WindowingSystem {
state: Rc<RefCell<WindowState>>, state: Rc<RefCell<WindowState>>,
connection: Rc<Connection>, connection: Rc<Connection>,
event_queue: Rc<RefCell<EventQueue<WindowState>>>, event_queue: Rc<RefCell<EventQueue<WindowState>>>,
component_instance: Option<Rc<ComponentInstance>>, component_instance: Option<Rc<ComponentInstance>>,
display: WlDisplay, display: WlDisplay,
config: WindowConfig, config: WindowConfig,
event_loop: EventLoop<'a, ()>, event_loop: EventLoop<'static, ()>,
event_loop_handler: Option<EventLoopHandler>, event_loop_handler: Option<EventLoopHandler>,
} }
impl<'a> WindowingSystem<'a> { impl WindowingSystem {
fn new(config: WindowConfig) -> Result<Self> { fn new(config: WindowConfig) -> Result<Self> {
info!("Initializing WindowingSystem"); info!("Initializing WindowingSystem");
let connection = Rc::new(Connection::connect_to_env()?); let connection = Rc::new(Connection::connect_to_env()?);
let state = Rc::new(RefCell::new(WindowState::new(&config))); let state = Rc::new(RefCell::new(WindowState::new(&config)));
let display = connection.display(); let display = connection.display();
let event_queue = Rc::new(RefCell::new(connection.new_event_queue())); let event_queue = Rc::new(RefCell::new(connection.new_event_queue()));
let global_list = Self::initialize_registry(&connection)?; let global_list = Self::initialize_registry(&connection)?;
let (compositor, output, layer_shell, seat) = let (compositor, output, layer_shell, seat) =
Self::bind_globals(&global_list, &event_queue.borrow().handle())?; Self::bind_globals(&global_list, &event_queue.borrow().handle())?;
@ -366,7 +367,7 @@ impl<'a> WindowingSystem<'a> {
Ok(()) Ok(())
} }
pub fn event_loop_handle(&self) -> calloop::LoopHandle<'a, ()> { pub fn event_loop_handle(&self) -> LoopHandle<'static, ()> {
self.event_loop.handle() self.event_loop.handle()
} }