Wow a message loop, but it does nothing...

This commit is contained in:
Timmy Xiao authored and Wez Furlong committed 2024-02-03 14:54:43 -07:00
1 parent 618d7beede
commit a3eee407c7
1 file changed
+51 -3
+51 -3
View File
@@ -1,17 +1,54 @@
// TODO: change this
#![allow(dead_code, unused)]
use std::{borrow::BorrowMut, cell::RefCell};
use anyhow::Context;
use smithay_client_toolkit::{
delegate_registry,
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
};
use wayland_client::{globals::registry_queue_init, Connection, EventQueue};
use crate::ConnectionOps;
pub struct WaylandConnection {}
pub struct WaylandConnection {
event_queue: RefCell<EventQueue<WaylandState>>,
wayland_state: RefCell<WaylandState>,
}
struct WaylandState {
registry_state: RegistryState,
}
impl WaylandConnection {
pub(crate) fn create_new() -> anyhow::Result<Self> {
Ok( WaylandConnection{} )
let conn = Connection::connect_to_env()?;
let (globals, mut event_queue) = registry_queue_init::<WaylandState>(&conn)?;
let qh = event_queue.handle();
let wayland_state = WaylandState {
registry_state: RegistryState::new(&globals),
};
let wayland_connection = WaylandConnection {
event_queue: RefCell::new(event_queue),
wayland_state: RefCell::new(wayland_state),
};
Ok(wayland_connection)
}
pub(crate) fn advise_of_appearance_change(&self, appearance: crate::Appearance) {}
}
impl ProvidesRegistryState for WaylandState {
fn registry(&mut self) -> &mut RegistryState {
&mut self.registry_state
}
registry_handlers!();
}
impl ConnectionOps for WaylandConnection {
fn name(&self) -> String {
todo!()
@@ -22,6 +59,17 @@ impl ConnectionOps for WaylandConnection {
}
fn run_message_loop(&self) -> anyhow::Result<()> {
todo!()
loop {
let mut event_q = self.event_queue.borrow_mut();
let mut wayland_state = self.wayland_state.borrow_mut();
if let Err(err) = event_q.dispatch_pending(&mut wayland_state) {
// TODO: show the protocol error in the display
return Err(err)
.with_context(|| format!("error during event_q.dispatch protcol_error"));
}
}
Ok(())
}
}
delegate_registry!(WaylandState);