autocommit 2022-01-03 18:56:52 CET
This commit is contained in:
parent
fc887b339e
commit
30376c595c
39 changed files with 3157 additions and 309 deletions
|
|
@ -9,8 +9,12 @@ use crate::ifs::wl_shm::{WlShmError, WlShmObj};
|
|||
use crate::ifs::wl_shm_pool::{WlShmPool, WlShmPoolError};
|
||||
use crate::ifs::wl_subcompositor::{WlSubcompositorError, WlSubcompositorObj};
|
||||
use crate::ifs::wl_surface::wl_subsurface::{WlSubsurface, WlSubsurfaceError};
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopupError;
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevelError;
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError};
|
||||
use crate::ifs::wl_surface::{WlSurface, WlSurfaceError};
|
||||
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
|
||||
use crate::ifs::xdg_positioner::{XdgPositioner, XdgPositionerError};
|
||||
use crate::ifs::xdg_wm_base::{XdgWmBaseError, XdgWmBaseObj};
|
||||
use crate::object::{Object, ObjectId, WL_DISPLAY_ID};
|
||||
use crate::state::State;
|
||||
use crate::utils::buffd::{BufFdError, MsgFormatter, MsgParser, MsgParserError};
|
||||
|
|
@ -86,6 +90,16 @@ pub enum ClientError {
|
|||
WlSubsurfaceError(#[source] Box<WlSubsurfaceError>),
|
||||
#[error("An error occurred in a `wl_subcompositor`")]
|
||||
WlSubcompositorError(#[source] Box<WlSubcompositorError>),
|
||||
#[error("An error occurred in a `xdg_surface`")]
|
||||
XdgSurfaceError(#[source] Box<XdgSurfaceError>),
|
||||
#[error("An error occurred in a `xdg_positioner`")]
|
||||
XdgPositionerError(#[source] Box<XdgPositionerError>),
|
||||
#[error("An error occurred in a `xdg_popup`")]
|
||||
XdgPopupError(#[source] Box<XdgPopupError>),
|
||||
#[error("An error occurred in a `xdg_toplevel`")]
|
||||
XdgToplevelError(#[source] Box<XdgToplevelError>),
|
||||
#[error("An error occurred in a `xdg_wm_base`")]
|
||||
XdgWmBaseError(#[source] Box<XdgWmBaseError>),
|
||||
#[error("Object {0} is not a display")]
|
||||
NotADisplay(ObjectId),
|
||||
}
|
||||
|
|
@ -100,6 +114,11 @@ efrom!(ClientError, WlShmPoolError, WlShmPoolError);
|
|||
efrom!(ClientError, WlRegionError, WlRegionError);
|
||||
efrom!(ClientError, WlSubsurfaceError, WlSubsurfaceError);
|
||||
efrom!(ClientError, WlSubcompositorError, WlSubcompositorError);
|
||||
efrom!(ClientError, XdgSurfaceError, XdgSurfaceError);
|
||||
efrom!(ClientError, XdgPositionerError, XdgPositionerError);
|
||||
efrom!(ClientError, XdgWmBaseError, XdgWmBaseError);
|
||||
efrom!(ClientError, XdgToplevelError, XdgToplevelError);
|
||||
efrom!(ClientError, XdgPopupError, XdgPopupError);
|
||||
|
||||
impl ClientError {
|
||||
fn peer_closed(&self) -> bool {
|
||||
|
|
@ -162,9 +181,9 @@ impl Clients {
|
|||
shutdown: Cell::new(Some(send)),
|
||||
shutdown_sent: Cell::new(false),
|
||||
});
|
||||
data.objects
|
||||
.add_client_object(Rc::new(WlDisplay::new(&data)))
|
||||
.expect("");
|
||||
let display = Rc::new(WlDisplay::new(&data));
|
||||
*data.objects.display.borrow_mut() = Some(display.clone());
|
||||
data.objects.add_client_object(display).expect("");
|
||||
let client = ClientHolder {
|
||||
_handler: global.eng.spawn(tasks::client(data.clone(), recv)),
|
||||
data,
|
||||
|
|
@ -272,7 +291,10 @@ impl Client {
|
|||
}
|
||||
|
||||
pub fn display(&self) -> Result<Rc<WlDisplay>, ClientError> {
|
||||
Ok(self.objects.get_obj(WL_DISPLAY_ID)?.into_display()?)
|
||||
match self.objects.display.borrow_mut().clone() {
|
||||
Some(d) => Ok(d),
|
||||
_ => Err(ClientError::NotADisplay(WL_DISPLAY_ID)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse<'a, R: RequestParser<'a>>(
|
||||
|
|
@ -292,6 +314,14 @@ impl Client {
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn protocol_error(&self, obj: &dyn Object, code: u32, message: String) {
|
||||
if let Ok(d) = self.display() {
|
||||
self.fatal_event(d.error(obj.id(), code, message));
|
||||
} else {
|
||||
self.state.clients.shutdown(self.id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fatal_event(&self, event: Box<dyn EventFormatter>) {
|
||||
self.events.push(WlEvent::Event(event));
|
||||
self.state.clients.shutdown(self.id);
|
||||
|
|
@ -407,7 +437,8 @@ simple_add_obj!(WlShmObj);
|
|||
simple_add_obj!(WlShmPool);
|
||||
simple_add_obj!(WlSubcompositorObj);
|
||||
simple_add_obj!(WlSubsurface);
|
||||
simple_add_obj!(XdgWmBaseObj);
|
||||
simple_add_obj!(XdgPositioner);
|
||||
simple_add_obj!(XdgSurface);
|
||||
|
||||
macro_rules! dedicated_add_obj {
|
||||
($ty:ty, $field:ident) => {
|
||||
|
|
@ -429,3 +460,4 @@ macro_rules! dedicated_add_obj {
|
|||
|
||||
dedicated_add_obj!(WlRegion, regions);
|
||||
dedicated_add_obj!(WlSurface, surfaces);
|
||||
dedicated_add_obj!(XdgWmBaseObj, xdg_wm_bases);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::client::{Client, ClientError};
|
||||
use crate::ifs::wl_display::WlDisplay;
|
||||
use crate::ifs::wl_region::WlRegion;
|
||||
use crate::ifs::wl_registry::WlRegistry;
|
||||
use crate::ifs::wl_surface::WlSurface;
|
||||
|
|
@ -8,12 +9,15 @@ use ahash::AHashMap;
|
|||
use std::cell::{RefCell, RefMut};
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
|
||||
|
||||
pub struct Objects {
|
||||
pub display: RefCell<Option<Rc<WlDisplay>>>,
|
||||
registry: CopyHashMap<ObjectId, Rc<dyn Object>>,
|
||||
registries: CopyHashMap<ObjectId, Rc<WlRegistry>>,
|
||||
pub surfaces: CopyHashMap<ObjectId, Rc<WlSurface>>,
|
||||
pub regions: CopyHashMap<ObjectId, Rc<WlRegion>>,
|
||||
pub xdg_wm_bases: CopyHashMap<ObjectId, Rc<XdgWmBaseObj>>,
|
||||
ids: RefCell<Vec<usize>>,
|
||||
}
|
||||
|
||||
|
|
@ -23,10 +27,12 @@ const SEG_SIZE: usize = 8 * mem::size_of::<usize>();
|
|||
impl Objects {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
display: RefCell::new(None),
|
||||
registry: Default::default(),
|
||||
registries: Default::default(),
|
||||
surfaces: Default::default(),
|
||||
regions: Default::default(),
|
||||
xdg_wm_bases: Default::default(),
|
||||
ids: RefCell::new(vec![]),
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +44,13 @@ impl Objects {
|
|||
surface.break_loops();
|
||||
}
|
||||
}
|
||||
{
|
||||
let mut xdg_wm_bases = self.xdg_wm_bases.lock();
|
||||
for xdg_wm_base in xdg_wm_bases.values_mut() {
|
||||
xdg_wm_base.break_loops();
|
||||
}
|
||||
}
|
||||
*self.display.borrow_mut() = None;
|
||||
self.registry.clear();
|
||||
self.regions.clear();
|
||||
self.registries.clear();
|
||||
|
|
|
|||
|
|
@ -114,7 +114,10 @@ async fn send(data: Rc<Client>) {
|
|||
if log::log_enabled!(log::Level::Trace) {
|
||||
data.log_event(&*e);
|
||||
}
|
||||
e.format(&mut MsgFormatter::new(&mut buf));
|
||||
let mut fds = vec![];
|
||||
let mut fmt = MsgFormatter::new(&mut buf, &mut fds);
|
||||
e.format(&mut fmt);
|
||||
fmt.write_len();
|
||||
if buf.needs_flush() {
|
||||
buf.flush().await?;
|
||||
flush_requested = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue