wayland: implement xwayland_shell_v1
This commit is contained in:
parent
1f64fefc86
commit
335677bbcd
11 changed files with 332 additions and 7 deletions
|
|
@ -1,6 +1,9 @@
|
|||
use {
|
||||
crate::{
|
||||
ifs::wl_surface::{x_surface::xwindow::Xwindow, SurfaceExt, WlSurface, WlSurfaceError},
|
||||
ifs::wl_surface::{
|
||||
x_surface::{xwayland_surface_v1::XwaylandSurfaceV1, xwindow::Xwindow},
|
||||
SurfaceExt, WlSurface, WlSurfaceError,
|
||||
},
|
||||
leaks::Tracker,
|
||||
tree::ToplevelNode,
|
||||
utils::clonecell::CloneCell,
|
||||
|
|
@ -9,11 +12,13 @@ use {
|
|||
std::rc::Rc,
|
||||
};
|
||||
|
||||
pub mod xwayland_surface_v1;
|
||||
pub mod xwindow;
|
||||
|
||||
pub struct XSurface {
|
||||
pub surface: Rc<WlSurface>,
|
||||
pub xwindow: CloneCell<Option<Rc<Xwindow>>>,
|
||||
pub xwayland_surface: CloneCell<Option<Rc<XwaylandSurfaceV1>>>,
|
||||
pub tracker: Tracker<Self>,
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +30,9 @@ impl SurfaceExt for XSurface {
|
|||
}
|
||||
|
||||
fn on_surface_destroy(&self) -> Result<(), WlSurfaceError> {
|
||||
if self.xwayland_surface.get().is_some() {
|
||||
return Err(WlSurfaceError::ReloObjectStillExists);
|
||||
}
|
||||
self.surface.unset_ext();
|
||||
if let Some(xwindow) = self.xwindow.take() {
|
||||
xwindow.tl_destroy();
|
||||
|
|
@ -35,7 +43,10 @@ impl SurfaceExt for XSurface {
|
|||
.state
|
||||
.xwayland
|
||||
.queue
|
||||
.push(XWaylandEvent::SurfaceDestroyed(self.surface.id));
|
||||
.push(XWaylandEvent::SurfaceDestroyed(
|
||||
self.surface.id,
|
||||
self.surface.xwayland_serial.get(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
77
src/ifs/wl_surface/x_surface/xwayland_surface_v1.rs
Normal file
77
src/ifs/wl_surface/x_surface/xwayland_surface_v1.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
ifs::wl_surface::{x_surface::XSurface, WlSurfaceError},
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
wire::{xwayland_surface_v1::*, XwaylandSurfaceV1Id},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct XwaylandSurfaceV1 {
|
||||
pub id: XwaylandSurfaceV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub x: Rc<XSurface>,
|
||||
pub tracker: Tracker<Self>,
|
||||
}
|
||||
|
||||
impl XwaylandSurfaceV1 {
|
||||
fn set_serial(&self, parser: MsgParser<'_, '_>) -> Result<(), XwaylandSurfaceV1Error> {
|
||||
let req: SetSerial = self.client.parse(self, parser)?;
|
||||
if self.x.surface.xwayland_serial.get().is_some() {
|
||||
return Err(XwaylandSurfaceV1Error::SerialAlreadySet);
|
||||
}
|
||||
let serial = req.serial_lo as u64 | ((req.serial_hi as u64) << 32);
|
||||
if self.client.last_xwayland_serial.get() >= serial {
|
||||
return Err(XwaylandSurfaceV1Error::NonMonotonicSerial);
|
||||
}
|
||||
self.client.last_xwayland_serial.set(serial);
|
||||
self.x.surface.pending.xwayland_serial.set(Some(serial));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), XwaylandSurfaceV1Error> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
self.x.xwayland_surface.set(None);
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
XwaylandSurfaceV1;
|
||||
|
||||
SET_SERIAL => set_serial,
|
||||
DESTROY => destroy,
|
||||
}
|
||||
|
||||
impl Object for XwaylandSurfaceV1 {
|
||||
fn num_requests(&self) -> u32 {
|
||||
DESTROY + 1
|
||||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.x.xwayland_surface.set(None);
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(XwaylandSurfaceV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum XwaylandSurfaceV1Error {
|
||||
#[error("The serial for this surface is already set")]
|
||||
SerialAlreadySet,
|
||||
#[error("The serial is not larger than the previously used serial")]
|
||||
NonMonotonicSerial,
|
||||
#[error(transparent)]
|
||||
WlSurfaceError(#[from] WlSurfaceError),
|
||||
#[error("Parsing failed")]
|
||||
MsgParserError(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(XwaylandSurfaceV1Error, MsgParserError);
|
||||
efrom!(XwaylandSurfaceV1Error, ClientError);
|
||||
|
|
@ -117,6 +117,7 @@ pub struct XwindowData {
|
|||
pub window_id: u32,
|
||||
pub client: Rc<Client>,
|
||||
pub surface_id: Cell<Option<WlSurfaceId>>,
|
||||
pub surface_serial: Cell<Option<u64>>,
|
||||
pub window: CloneCell<Option<Rc<Xwindow>>>,
|
||||
pub info: XwindowInfo,
|
||||
pub children: CopyHashMap<u32, Rc<XwindowData>>,
|
||||
|
|
@ -152,6 +153,7 @@ impl XwindowData {
|
|||
window_id: event.window,
|
||||
client: client.clone(),
|
||||
surface_id: Cell::new(None),
|
||||
surface_serial: Cell::new(None),
|
||||
window: Default::default(),
|
||||
info: XwindowInfo {
|
||||
override_redirect: Cell::new(event.override_redirect != 0),
|
||||
|
|
|
|||
120
src/ifs/wl_surface/xwayland_shell_v1.rs
Normal file
120
src/ifs/wl_surface/xwayland_shell_v1.rs
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::wl_surface::{x_surface::xwayland_surface_v1::XwaylandSurfaceV1, WlSurfaceError},
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
wire::{xwayland_shell_v1::*, WlSurfaceId, XwaylandShellV1Id},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct XwaylandShellV1Global {
|
||||
name: GlobalName,
|
||||
}
|
||||
|
||||
pub struct XwaylandShellV1 {
|
||||
id: XwaylandShellV1Id,
|
||||
client: Rc<Client>,
|
||||
pub version: u32,
|
||||
pub tracker: Tracker<Self>,
|
||||
}
|
||||
|
||||
impl XwaylandShellV1Global {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: XwaylandShellV1Id,
|
||||
client: &Rc<Client>,
|
||||
version: u32,
|
||||
) -> Result<(), XwaylandShellV1Error> {
|
||||
let obj = Rc::new(XwaylandShellV1 {
|
||||
id,
|
||||
client: client.clone(),
|
||||
version,
|
||||
tracker: Default::default(),
|
||||
});
|
||||
track!(client, obj);
|
||||
client.add_client_obj(&obj)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl XwaylandShellV1 {
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), XwaylandShellV1Error> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_xwayland_surface(&self, parser: MsgParser<'_, '_>) -> Result<(), XwaylandShellV1Error> {
|
||||
let req: GetXwaylandSurface = self.client.parse(self, parser)?;
|
||||
let surface = self.client.lookup(req.surface)?;
|
||||
let xsurface = surface.get_xsurface()?;
|
||||
if xsurface.xwayland_surface.get().is_some() {
|
||||
return Err(XwaylandShellV1Error::AlreadyAttached(surface.id));
|
||||
}
|
||||
let xws = Rc::new(XwaylandSurfaceV1 {
|
||||
id: req.id,
|
||||
client: self.client.clone(),
|
||||
x: xsurface,
|
||||
tracker: Default::default(),
|
||||
});
|
||||
track!(self.client, xws);
|
||||
xws.x.xwayland_surface.set(Some(xws.clone()));
|
||||
self.client.add_client_obj(&xws)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
global_base!(XwaylandShellV1Global, XwaylandShellV1, XwaylandShellV1Error);
|
||||
|
||||
impl Global for XwaylandShellV1Global {
|
||||
fn singleton(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
fn xwayland_only(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_global!(XwaylandShellV1Global);
|
||||
|
||||
object_base! {
|
||||
XwaylandShellV1;
|
||||
|
||||
DESTROY => destroy,
|
||||
GET_XWAYLAND_SURFACE => get_xwayland_surface,
|
||||
}
|
||||
|
||||
impl Object for XwaylandShellV1 {
|
||||
fn num_requests(&self) -> u32 {
|
||||
GET_XWAYLAND_SURFACE + 1
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(XwaylandShellV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum XwaylandShellV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Parsing failed")]
|
||||
MsgParserError(#[source] Box<MsgParserError>),
|
||||
#[error("The `wl_surface` {0} already has an extension object")]
|
||||
AlreadyAttached(WlSurfaceId),
|
||||
#[error(transparent)]
|
||||
WlSurfaceError(#[from] WlSurfaceError),
|
||||
}
|
||||
efrom!(XwaylandShellV1Error, ClientError);
|
||||
efrom!(XwaylandShellV1Error, MsgParserError);
|
||||
Loading…
Add table
Add a link
Reference in a new issue