autocommit 2022-01-25 16:45:44 CET
This commit is contained in:
parent
0336bf3bde
commit
c340df0d08
59 changed files with 3085 additions and 1710 deletions
|
|
@ -2,17 +2,19 @@ mod types;
|
|||
pub mod xdg_popup;
|
||||
pub mod xdg_toplevel;
|
||||
|
||||
use crate::client::{AddObj, DynEventFormatter};
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup;
|
||||
use crate::client::DynEventFormatter;
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{XdgPopup, XdgPopupId};
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel;
|
||||
use crate::ifs::wl_surface::{
|
||||
RoleData, SurfaceExtents, SurfaceRole, WlSurface, XdgPopupData, XdgSurfaceData, XdgSurfaceRole,
|
||||
XdgSurfaceRoleData, XdgToplevelData,
|
||||
};
|
||||
use crate::ifs::wl_surface::{CommitAction, CommitContext, SurfaceExt, SurfaceRole, WlSurface};
|
||||
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::rect::Rect;
|
||||
use crate::tree::Node;
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use std::ops::DerefMut;
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
use crate::utils::copyhashmap::CopyHashMap;
|
||||
use crate::NumCell;
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
|
|
@ -36,6 +38,32 @@ pub struct XdgSurface {
|
|||
id: XdgSurfaceId,
|
||||
base: Rc<XdgWmBaseObj>,
|
||||
pub surface: Rc<WlSurface>,
|
||||
requested_serial: NumCell<u32>,
|
||||
acked_serial: Cell<Option<u32>>,
|
||||
geometry: Cell<Option<Rect>>,
|
||||
extents: Cell<Rect>,
|
||||
ext: CloneCell<Option<Rc<dyn XdgSurfaceExt>>>,
|
||||
popups: CopyHashMap<XdgPopupId, Rc<XdgPopup>>,
|
||||
pending: PendingXdgSurfaceData,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct PendingXdgSurfaceData {
|
||||
geometry: Cell<Option<Rect>>,
|
||||
}
|
||||
|
||||
trait XdgSurfaceExt {
|
||||
fn post_commit(self: Rc<Self>) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn extents_changed(&self) {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurface {
|
||||
|
|
@ -44,9 +72,25 @@ impl XdgSurface {
|
|||
id,
|
||||
base: wm_base.clone(),
|
||||
surface: surface.clone(),
|
||||
requested_serial: NumCell::new(0),
|
||||
acked_serial: Cell::new(None),
|
||||
geometry: Cell::new(None),
|
||||
extents: Cell::new(Default::default()),
|
||||
ext: Default::default(),
|
||||
popups: Default::default(),
|
||||
pending: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geometry(&self) -> Option<Rect> {
|
||||
self.geometry.get()
|
||||
}
|
||||
|
||||
pub fn send_configure(self: &Rc<Self>) {
|
||||
let serial = self.requested_serial.fetch_add(1) + 1;
|
||||
self.surface.client.event(self.configure(serial));
|
||||
}
|
||||
|
||||
pub fn configure(self: &Rc<Self>, serial: u32) -> DynEventFormatter {
|
||||
Box::new(Configure {
|
||||
obj: self.clone(),
|
||||
|
|
@ -55,171 +99,125 @@ impl XdgSurface {
|
|||
}
|
||||
|
||||
pub fn install(self: &Rc<Self>) -> Result<(), XdgSurfaceError> {
|
||||
let old_role = self.surface.role.get();
|
||||
if !matches!(old_role, SurfaceRole::None | SurfaceRole::XdgSurface) {
|
||||
return Err(XdgSurfaceError::IncompatibleRole(self.surface.id, old_role));
|
||||
}
|
||||
self.surface.role.set(SurfaceRole::XdgSurface);
|
||||
let mut data = self.surface.role_data.borrow_mut();
|
||||
if data.is_some() {
|
||||
self.surface.set_role(SurfaceRole::XdgSurface)?;
|
||||
if self.surface.ext.get().is_some() {
|
||||
return Err(XdgSurfaceError::AlreadyAttached(self.surface.id));
|
||||
}
|
||||
*data = RoleData::XdgSurface(Box::new(XdgSurfaceData {
|
||||
xdg_surface: self.clone(),
|
||||
requested_serial: 0,
|
||||
acked_serial: None,
|
||||
role: XdgSurfaceRole::None,
|
||||
extents: None,
|
||||
role_data: XdgSurfaceRoleData::None,
|
||||
popups: Default::default(),
|
||||
pending: Default::default(),
|
||||
}));
|
||||
self.surface.ext.set(self.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.surface.client.parse(self, parser)?;
|
||||
if self.ext.get().is_some() {
|
||||
return Err(DestroyError::RoleNotYetDestroyed(self.id));
|
||||
}
|
||||
{
|
||||
let mut data = self.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(rd) = &*data {
|
||||
if rd.role_data.is_some() {
|
||||
return Err(DestroyError::RoleNotYetDestroyed(self.id));
|
||||
}
|
||||
let children = rd.popups.lock();
|
||||
for child in children.values() {
|
||||
let mut data = child.surface.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(xdg) = &mut *data {
|
||||
if let XdgSurfaceRoleData::Popup(p) = &mut xdg.role_data {
|
||||
p.parent = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
let children = self.popups.lock();
|
||||
for child in children.values() {
|
||||
child.parent.set(None);
|
||||
}
|
||||
*data = RoleData::None;
|
||||
}
|
||||
self.surface.unset_ext();
|
||||
self.base.surfaces.remove(&self.id);
|
||||
self.surface.client.remove_obj(self).await?;
|
||||
self.surface.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_toplevel(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), GetToplevelError> {
|
||||
fn get_toplevel(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetToplevelError> {
|
||||
let req: GetToplevel = self.surface.client.parse(&**self, parser)?;
|
||||
let mut data = self.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(data) = &mut *data {
|
||||
if !data.role.is_compatible(XdgSurfaceRole::Toplevel) {
|
||||
return Err(GetToplevelError::IncompatibleRole);
|
||||
}
|
||||
if data.role_data.is_some() {
|
||||
self.surface.client.protocol_error(
|
||||
&**self,
|
||||
ALREADY_CONSTRUCTED,
|
||||
format!(
|
||||
"wl_surface {} already has an assigned xdg_toplevel",
|
||||
self.surface.id
|
||||
),
|
||||
);
|
||||
return Err(GetToplevelError::AlreadyConstructed);
|
||||
}
|
||||
data.role = XdgSurfaceRole::Toplevel;
|
||||
let toplevel = Rc::new(XdgToplevel::new(req.id, self));
|
||||
self.surface.client.add_client_obj(&toplevel)?;
|
||||
data.role_data = XdgSurfaceRoleData::Toplevel(XdgToplevelData {
|
||||
toplevel,
|
||||
node: None,
|
||||
});
|
||||
self.surface.set_role(SurfaceRole::XdgToplevel)?;
|
||||
if self.ext.get().is_some() {
|
||||
self.surface.client.protocol_error(
|
||||
&**self,
|
||||
ALREADY_CONSTRUCTED,
|
||||
format!(
|
||||
"wl_surface {} already has an assigned xdg_toplevel",
|
||||
self.surface.id
|
||||
),
|
||||
);
|
||||
return Err(GetToplevelError::AlreadyConstructed);
|
||||
}
|
||||
let toplevel = Rc::new(XdgToplevel::new(req.id, self));
|
||||
self.surface.client.add_client_obj(&toplevel)?;
|
||||
self.ext.set(Some(toplevel));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_popup(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetPopupError> {
|
||||
fn get_popup(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetPopupError> {
|
||||
let req: GetPopup = self.surface.client.parse(&**self, parser)?;
|
||||
let mut data = self.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(data) = &mut *data {
|
||||
let mut parent = None;
|
||||
if req.parent.is_some() {
|
||||
parent = Some(self.surface.client.get_xdg_surface(req.parent)?);
|
||||
}
|
||||
if !data.role.is_compatible(XdgSurfaceRole::Popup) {
|
||||
return Err(GetPopupError::IncompatibleRole);
|
||||
}
|
||||
if data.role_data.is_some() {
|
||||
self.surface.client.protocol_error(
|
||||
&**self,
|
||||
ALREADY_CONSTRUCTED,
|
||||
format!(
|
||||
"wl_surface {} already has an assigned xdg_popup",
|
||||
self.surface.id
|
||||
),
|
||||
);
|
||||
return Err(GetPopupError::AlreadyConstructed);
|
||||
}
|
||||
data.role = XdgSurfaceRole::Popup;
|
||||
let popup = Rc::new(XdgPopup::new(req.id, self));
|
||||
self.surface.client.add_client_obj(&popup)?;
|
||||
if let Some(parent) = &parent {
|
||||
let mut data = parent.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(xdg) = &mut *data {
|
||||
xdg.popups.set(self.surface.id, popup.clone());
|
||||
}
|
||||
}
|
||||
data.role_data = XdgSurfaceRoleData::Popup(XdgPopupData {
|
||||
_popup: popup,
|
||||
parent,
|
||||
});
|
||||
self.surface.set_role(SurfaceRole::XdgPopup)?;
|
||||
let mut parent = None;
|
||||
if req.parent.is_some() {
|
||||
parent = Some(self.surface.client.get_xdg_surface(req.parent)?);
|
||||
}
|
||||
if self.ext.get().is_some() {
|
||||
self.surface.client.protocol_error(
|
||||
&**self,
|
||||
ALREADY_CONSTRUCTED,
|
||||
format!(
|
||||
"wl_surface {} already has an assigned xdg_popup",
|
||||
self.surface.id
|
||||
),
|
||||
);
|
||||
return Err(GetPopupError::AlreadyConstructed);
|
||||
}
|
||||
let popup = Rc::new(XdgPopup::new(req.id, self, parent.as_ref()));
|
||||
self.surface.client.add_client_obj(&popup)?;
|
||||
if let Some(parent) = &parent {
|
||||
parent.popups.set(req.id, popup.clone());
|
||||
}
|
||||
self.ext.set(Some(popup));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_window_geometry(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), SetWindowGeometryError> {
|
||||
fn set_window_geometry(&self, parser: MsgParser<'_, '_>) -> Result<(), SetWindowGeometryError> {
|
||||
let req: SetWindowGeometry = self.surface.client.parse(self, parser)?;
|
||||
if req.height <= 0 || req.width <= 0 {
|
||||
return Err(SetWindowGeometryError::NonPositiveWidthHeight);
|
||||
}
|
||||
let mut rd = self.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(xdg) = rd.deref_mut() {
|
||||
let extents = SurfaceExtents {
|
||||
x1: req.x,
|
||||
y1: req.y,
|
||||
x2: req.x + req.width,
|
||||
y2: req.y + req.height,
|
||||
};
|
||||
xdg.pending.extents.set(Some(extents));
|
||||
}
|
||||
let extents = Rect::new_sized(req.x, req.y, req.width, req.height).unwrap();
|
||||
self.pending.geometry.set(Some(extents));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn ack_configure(&self, parser: MsgParser<'_, '_>) -> Result<(), AckConfigureError> {
|
||||
fn ack_configure(&self, parser: MsgParser<'_, '_>) -> Result<(), AckConfigureError> {
|
||||
let req: AckConfigure = self.surface.client.parse(self, parser)?;
|
||||
let mut rd = self.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(xdg) = rd.deref_mut() {
|
||||
if xdg.requested_serial == req.serial {
|
||||
xdg.acked_serial = Some(xdg.requested_serial);
|
||||
}
|
||||
if self.requested_serial.get() == req.serial {
|
||||
self.acked_serial.set(Some(req.serial));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
fn handle_request_(
|
||||
self: &Rc<Self>,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), XdgSurfaceError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
GET_TOPLEVEL => self.get_toplevel(parser).await?,
|
||||
GET_POPUP => self.get_popup(parser).await?,
|
||||
SET_WINDOW_GEOMETRY => self.set_window_geometry(parser).await?,
|
||||
ACK_CONFIGURE => self.ack_configure(parser).await?,
|
||||
DESTROY => self.destroy(parser)?,
|
||||
GET_TOPLEVEL => self.get_toplevel(parser)?,
|
||||
GET_POPUP => self.get_popup(parser)?,
|
||||
SET_WINDOW_GEOMETRY => self.set_window_geometry(parser)?,
|
||||
ACK_CONFIGURE => self.ack_configure(parser)?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_extents(&self) {
|
||||
let old_extents = self.extents.get();
|
||||
let mut new_extents = self.surface.extents.get();
|
||||
if let Some(geometry) = self.geometry.get() {
|
||||
new_extents = new_extents.intersect(geometry);
|
||||
}
|
||||
self.extents.set(new_extents);
|
||||
if old_extents != new_extents {
|
||||
if let Some(ext) = self.ext.get() {
|
||||
ext.extents_changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(XdgSurface);
|
||||
|
|
@ -237,3 +235,40 @@ impl Object for XdgSurface {
|
|||
ACK_CONFIGURE + 1
|
||||
}
|
||||
}
|
||||
|
||||
impl SurfaceExt for XdgSurface {
|
||||
fn pre_commit(self: Rc<Self>, _ctx: CommitContext) -> CommitAction {
|
||||
{
|
||||
let ase = self.acked_serial.get();
|
||||
let rse = self.requested_serial.get();
|
||||
if ase != Some(rse) {
|
||||
if ase.is_none() {
|
||||
self.surface.client.event(self.configure(rse));
|
||||
}
|
||||
// return CommitAction::AbortCommit;
|
||||
}
|
||||
}
|
||||
if let Some(geometry) = self.pending.geometry.take() {
|
||||
self.geometry.set(Some(geometry));
|
||||
self.update_extents();
|
||||
}
|
||||
CommitAction::ContinueCommit
|
||||
}
|
||||
|
||||
fn post_commit(&self) {
|
||||
if let Some(ext) = self.ext.get() {
|
||||
ext.post_commit();
|
||||
}
|
||||
}
|
||||
|
||||
fn extents_changed(&self) {
|
||||
self.update_extents();
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
match self.ext.get() {
|
||||
Some(e) => e.into_node(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::client::{ClientError, EventFormatter, RequestParser};
|
|||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopupId;
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevelId;
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId, CONFIGURE};
|
||||
use crate::ifs::wl_surface::{SurfaceRole, WlSurfaceId};
|
||||
use crate::ifs::wl_surface::{WlSurfaceError, WlSurfaceId};
|
||||
use crate::ifs::xdg_positioner::XdgPositionerId;
|
||||
use crate::object::Object;
|
||||
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
|
||||
|
|
@ -22,11 +22,12 @@ pub enum XdgSurfaceError {
|
|||
SetWindowGeometryError(#[from] SetWindowGeometryError),
|
||||
#[error("Could not process `ack_configure` request")]
|
||||
AckConfigureError(#[from] AckConfigureError),
|
||||
#[error("Surface {0} cannot be turned into a xdg_surface because it already has the role {}", .1.name())]
|
||||
IncompatibleRole(WlSurfaceId, SurfaceRole),
|
||||
#[error("Surface {0} cannot be turned into a xdg_surface because it already has an attached xdg_surface")]
|
||||
AlreadyAttached(WlSurfaceId),
|
||||
#[error(transparent)]
|
||||
WlSurfaceError(Box<WlSurfaceError>),
|
||||
}
|
||||
efrom!(XdgSurfaceError, WlSurfaceError, WlSurfaceError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DestroyError {
|
||||
|
|
@ -46,13 +47,14 @@ pub enum GetToplevelError {
|
|||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("The surface already has a different role")]
|
||||
IncompatibleRole,
|
||||
#[error("The surface already has an assigned xdg_toplevel")]
|
||||
AlreadyConstructed,
|
||||
#[error(transparent)]
|
||||
WlSurfaceError(Box<WlSurfaceError>),
|
||||
}
|
||||
efrom!(GetToplevelError, ParseFailed, MsgParserError);
|
||||
efrom!(GetToplevelError, ClientError, ClientError);
|
||||
efrom!(GetToplevelError, WlSurfaceError, WlSurfaceError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GetPopupError {
|
||||
|
|
@ -60,13 +62,14 @@ pub enum GetPopupError {
|
|||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("The surface already has a different role")]
|
||||
IncompatibleRole,
|
||||
#[error("The surface already has an assigned xdg_popup")]
|
||||
AlreadyConstructed,
|
||||
#[error(transparent)]
|
||||
WlSurfaceError(Box<WlSurfaceError>),
|
||||
}
|
||||
efrom!(GetPopupError, ParseFailed, MsgParserError);
|
||||
efrom!(GetPopupError, ClientError, ClientError);
|
||||
efrom!(GetPopupError, WlSurfaceError, WlSurfaceError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetWindowGeometryError {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
mod types;
|
||||
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||
use crate::ifs::wl_surface::{RoleData, XdgSurfaceRoleData};
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceExt};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::tree::{Node, NodeId};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
|
|
@ -18,59 +19,55 @@ const REPOSITIONED: u32 = 2;
|
|||
#[allow(dead_code)]
|
||||
const INVALID_GRAB: u32 = 1;
|
||||
|
||||
tree_id!(PopupId);
|
||||
id!(XdgPopupId);
|
||||
|
||||
pub struct XdgPopup {
|
||||
id: XdgPopupId,
|
||||
node_id: PopupId,
|
||||
pub(in super::super) surface: Rc<XdgSurface>,
|
||||
pub(super) parent: CloneCell<Option<Rc<XdgSurface>>>,
|
||||
}
|
||||
|
||||
impl XdgPopup {
|
||||
pub fn new(id: XdgPopupId, surface: &Rc<XdgSurface>) -> Self {
|
||||
pub fn new(id: XdgPopupId, surface: &Rc<XdgSurface>, parent: Option<&Rc<XdgSurface>>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
node_id: surface.surface.client.state.node_ids.next(),
|
||||
surface: surface.clone(),
|
||||
parent: CloneCell::new(parent.cloned()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.surface.surface.client.parse(self, parser)?;
|
||||
{
|
||||
let mut rd = self.surface.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(xdg) = &mut *rd {
|
||||
if let XdgSurfaceRoleData::Popup(p) = &xdg.role_data {
|
||||
if let Some(p) = &p.parent {
|
||||
let mut rd = p.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(xdg) = &mut *rd {
|
||||
xdg.popups.remove(&self.surface.surface.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
xdg.role_data = XdgSurfaceRoleData::None;
|
||||
if let Some(parent) = self.parent.take() {
|
||||
parent.popups.remove(&self.id);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn grab(&self, parser: MsgParser<'_, '_>) -> Result<(), GrabError> {
|
||||
fn grab(&self, parser: MsgParser<'_, '_>) -> Result<(), GrabError> {
|
||||
let _req: Grab = self.surface.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn reposition(&self, parser: MsgParser<'_, '_>) -> Result<(), RepositionError> {
|
||||
fn reposition(&self, parser: MsgParser<'_, '_>) -> Result<(), RepositionError> {
|
||||
let _req: Reposition = self.surface.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), XdgPopupError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
GRAB => self.grab(parser).await?,
|
||||
REPOSITION => self.reposition(parser).await?,
|
||||
DESTROY => self.destroy(parser)?,
|
||||
GRAB => self.grab(parser)?,
|
||||
REPOSITION => self.reposition(parser)?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -92,3 +89,11 @@ impl Object for XdgPopup {
|
|||
REPOSITION + 1
|
||||
}
|
||||
}
|
||||
|
||||
impl Node for XdgPopup {
|
||||
fn id(&self) -> NodeId {
|
||||
self.node_id.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurfaceExt for XdgPopup {}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,21 @@
|
|||
mod types;
|
||||
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||
use crate::ifs::wl_surface::{RoleData, XdgSurfaceRoleData};
|
||||
use crate::client::DynEventFormatter;
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::WlSeatGlobal;
|
||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceExt};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::rect::Rect;
|
||||
use crate::render::Renderer;
|
||||
use crate::tree::ContainerNode;
|
||||
use crate::tree::{FloatNode, FoundNode, Node, NodeId, ToplevelNodeId, WorkspaceNode};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
use ahash::{AHashMap, AHashSet};
|
||||
use num_derive::FromPrimitive;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
|
@ -60,130 +71,245 @@ const STATE_TILED_BOTTOM: u32 = 8;
|
|||
id!(XdgToplevelId);
|
||||
|
||||
pub struct XdgToplevel {
|
||||
id: XdgToplevelId,
|
||||
pub surface: Rc<XdgSurface>,
|
||||
pub id: XdgToplevelId,
|
||||
pub xdg: Rc<XdgSurface>,
|
||||
pub node_id: ToplevelNodeId,
|
||||
pub parent_node: CloneCell<Option<Rc<dyn Node>>>,
|
||||
pub parent: CloneCell<Option<Rc<XdgToplevel>>>,
|
||||
pub children: RefCell<AHashMap<XdgToplevelId, Rc<XdgToplevel>>>,
|
||||
pub focus_subsurface: CloneCell<Option<Rc<WlSubsurface>>>,
|
||||
states: RefCell<AHashSet<u32>>,
|
||||
}
|
||||
|
||||
impl XdgToplevel {
|
||||
pub fn new(id: XdgToplevelId, surface: &Rc<XdgSurface>) -> Self {
|
||||
let mut states = AHashSet::new();
|
||||
states.insert(STATE_TILED_LEFT);
|
||||
states.insert(STATE_TILED_RIGHT);
|
||||
states.insert(STATE_TILED_TOP);
|
||||
states.insert(STATE_TILED_BOTTOM);
|
||||
Self {
|
||||
id,
|
||||
surface: surface.clone(),
|
||||
xdg: surface.clone(),
|
||||
node_id: surface.surface.client.state.node_ids.next(),
|
||||
parent_node: Default::default(),
|
||||
parent: Default::default(),
|
||||
children: RefCell::new(Default::default()),
|
||||
focus_subsurface: Default::default(),
|
||||
states: RefCell::new(states),
|
||||
}
|
||||
}
|
||||
|
||||
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.surface.surface.client.parse(self, parser)?;
|
||||
pub fn parent_is_float(&self) -> bool {
|
||||
if let Some(parent) = self.parent_node.get() {
|
||||
return parent.is_float();
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub fn configure(self: &Rc<Self>, width: i32, height: i32) -> DynEventFormatter {
|
||||
Box::new(Configure {
|
||||
obj: self.clone(),
|
||||
width,
|
||||
height,
|
||||
states: self.states.borrow().iter().copied().collect(),
|
||||
})
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.xdg.surface.client.parse(self, parser)?;
|
||||
self.xdg.ext.set(None);
|
||||
if let Some(parent) = self.parent_node.take() {
|
||||
parent.remove_child(self);
|
||||
}
|
||||
{
|
||||
let mut rd = self.surface.surface.role_data.borrow_mut();
|
||||
if let RoleData::XdgSurface(rd) = &mut *rd {
|
||||
rd.role_data = XdgSurfaceRoleData::None;
|
||||
let mut children = self.children.borrow_mut();
|
||||
for (_, child) in children.drain() {
|
||||
child.parent.set(self.parent.get());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_parent(&self, parser: MsgParser<'_, '_>) -> Result<(), SetParentError> {
|
||||
let _req: SetParent = self.surface.surface.client.parse(self, parser)?;
|
||||
fn set_parent(&self, parser: MsgParser<'_, '_>) -> Result<(), SetParentError> {
|
||||
let _req: SetParent = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_title(&self, parser: MsgParser<'_, '_>) -> Result<(), SetTitleError> {
|
||||
let _req: SetTitle = self.surface.surface.client.parse(self, parser)?;
|
||||
fn set_title(&self, parser: MsgParser<'_, '_>) -> Result<(), SetTitleError> {
|
||||
let _req: SetTitle = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_app_id(&self, parser: MsgParser<'_, '_>) -> Result<(), SetAppIdError> {
|
||||
let _req: SetAppId = self.surface.surface.client.parse(self, parser)?;
|
||||
fn set_app_id(&self, parser: MsgParser<'_, '_>) -> Result<(), SetAppIdError> {
|
||||
let _req: SetAppId = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn show_window_menu(&self, parser: MsgParser<'_, '_>) -> Result<(), ShowWindowMenuError> {
|
||||
let _req: ShowWindowMenu = self.surface.surface.client.parse(self, parser)?;
|
||||
fn show_window_menu(&self, parser: MsgParser<'_, '_>) -> Result<(), ShowWindowMenuError> {
|
||||
let _req: ShowWindowMenu = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn move_(&self, parser: MsgParser<'_, '_>) -> Result<(), MoveError> {
|
||||
let req: Move = self.surface.surface.client.parse(self, parser)?;
|
||||
let rd = self.surface.surface.role_data.borrow();
|
||||
if let RoleData::XdgSurface(xdg) = rd.deref() {
|
||||
if let XdgSurfaceRoleData::Toplevel(tl) = &xdg.role_data {
|
||||
if let Some(node) = tl.node.as_ref() {
|
||||
let seat = self.surface.surface.client.get_wl_seat(req.seat)?;
|
||||
seat.move_(&node.node);
|
||||
}
|
||||
fn move_(&self, parser: MsgParser<'_, '_>) -> Result<(), MoveError> {
|
||||
let req: Move = self.xdg.surface.client.parse(self, parser)?;
|
||||
let seat = self.xdg.surface.client.get_wl_seat(req.seat)?;
|
||||
if let Some(parent) = self.parent_node.get() {
|
||||
if let Some(float) = parent.into_float() {
|
||||
seat.move_(&float);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn resize(&self, parser: MsgParser<'_, '_>) -> Result<(), ResizeError> {
|
||||
let _req: Resize = self.surface.surface.client.parse(self, parser)?;
|
||||
fn resize(&self, parser: MsgParser<'_, '_>) -> Result<(), ResizeError> {
|
||||
let _req: Resize = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_max_size(&self, parser: MsgParser<'_, '_>) -> Result<(), SetMaxSizeError> {
|
||||
let _req: SetMaxSize = self.surface.surface.client.parse(self, parser)?;
|
||||
fn set_max_size(&self, parser: MsgParser<'_, '_>) -> Result<(), SetMaxSizeError> {
|
||||
let _req: SetMaxSize = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_min_size(&self, parser: MsgParser<'_, '_>) -> Result<(), SetMinSizeError> {
|
||||
let _req: SetMinSize = self.surface.surface.client.parse(self, parser)?;
|
||||
fn set_min_size(&self, parser: MsgParser<'_, '_>) -> Result<(), SetMinSizeError> {
|
||||
let _req: SetMinSize = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_maximized(&self, parser: MsgParser<'_, '_>) -> Result<(), SetMaximizedError> {
|
||||
let _req: SetMaximized = self.surface.surface.client.parse(self, parser)?;
|
||||
fn set_maximized(&self, parser: MsgParser<'_, '_>) -> Result<(), SetMaximizedError> {
|
||||
let _req: SetMaximized = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn unset_maximized(&self, parser: MsgParser<'_, '_>) -> Result<(), UnsetMaximizedError> {
|
||||
let _req: UnsetMaximized = self.surface.surface.client.parse(self, parser)?;
|
||||
fn unset_maximized(&self, parser: MsgParser<'_, '_>) -> Result<(), UnsetMaximizedError> {
|
||||
let _req: UnsetMaximized = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_fullscreen(&self, parser: MsgParser<'_, '_>) -> Result<(), SetFullscreenError> {
|
||||
let _req: SetFullscreen = self.surface.surface.client.parse(self, parser)?;
|
||||
fn set_fullscreen(&self, parser: MsgParser<'_, '_>) -> Result<(), SetFullscreenError> {
|
||||
let _req: SetFullscreen = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn unset_fullscreen(
|
||||
&self,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), UnsetFullscreenError> {
|
||||
let _req: UnsetFullscreen = self.surface.surface.client.parse(self, parser)?;
|
||||
fn unset_fullscreen(&self, parser: MsgParser<'_, '_>) -> Result<(), UnsetFullscreenError> {
|
||||
let _req: UnsetFullscreen = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_minimized(&self, parser: MsgParser<'_, '_>) -> Result<(), SetMinimizedError> {
|
||||
let _req: SetMinimized = self.surface.surface.client.parse(self, parser)?;
|
||||
fn set_minimized(&self, parser: MsgParser<'_, '_>) -> Result<(), SetMinimizedError> {
|
||||
let _req: SetMinimized = self.xdg.surface.client.parse(self, parser)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), XdgToplevelError> {
|
||||
match request {
|
||||
DESTROY => self.destroy(parser).await?,
|
||||
SET_PARENT => self.set_parent(parser).await?,
|
||||
SET_TITLE => self.set_title(parser).await?,
|
||||
SET_APP_ID => self.set_app_id(parser).await?,
|
||||
SHOW_WINDOW_MENU => self.show_window_menu(parser).await?,
|
||||
MOVE => self.move_(parser).await?,
|
||||
RESIZE => self.resize(parser).await?,
|
||||
SET_MAX_SIZE => self.set_max_size(parser).await?,
|
||||
SET_MIN_SIZE => self.set_min_size(parser).await?,
|
||||
SET_MAXIMIZED => self.set_maximized(parser).await?,
|
||||
UNSET_MAXIMIZED => self.unset_maximized(parser).await?,
|
||||
SET_FULLSCREEN => self.set_fullscreen(parser).await?,
|
||||
UNSET_FULLSCREEN => self.unset_fullscreen(parser).await?,
|
||||
SET_MINIMIZED => self.set_minimized(parser).await?,
|
||||
DESTROY => self.destroy(parser)?,
|
||||
SET_PARENT => self.set_parent(parser)?,
|
||||
SET_TITLE => self.set_title(parser)?,
|
||||
SET_APP_ID => self.set_app_id(parser)?,
|
||||
SHOW_WINDOW_MENU => self.show_window_menu(parser)?,
|
||||
MOVE => self.move_(parser)?,
|
||||
RESIZE => self.resize(parser)?,
|
||||
SET_MAX_SIZE => self.set_max_size(parser)?,
|
||||
SET_MIN_SIZE => self.set_min_size(parser)?,
|
||||
SET_MAXIMIZED => self.set_maximized(parser)?,
|
||||
UNSET_MAXIMIZED => self.unset_maximized(parser)?,
|
||||
SET_FULLSCREEN => self.set_fullscreen(parser)?,
|
||||
UNSET_FULLSCREEN => self.unset_fullscreen(parser)?,
|
||||
SET_MINIMIZED => self.set_minimized(parser)?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn map_child(self: &Rc<Self>, parent: &XdgToplevel) {
|
||||
let workspace = match parent.get_workspace() {
|
||||
Some(w) => w,
|
||||
_ => return self.map_tiled(),
|
||||
};
|
||||
let output = workspace.output.get();
|
||||
let output_rect = output.position.get();
|
||||
let position = {
|
||||
let extents = self.xdg.extents.get().to_origin();
|
||||
let width = extents.width();
|
||||
let height = extents.height();
|
||||
let mut x1 = output_rect.x1();
|
||||
let mut y1 = output_rect.y1();
|
||||
if width < output_rect.width() {
|
||||
x1 += (output_rect.width() - width) as i32 / 2;
|
||||
}
|
||||
if height < output_rect.height() {
|
||||
y1 += (output_rect.height() - height) as i32 / 2;
|
||||
}
|
||||
Rect::new_sized(x1, y1, width, height).unwrap()
|
||||
};
|
||||
let state = &self.xdg.surface.client.state;
|
||||
let floater = Rc::new(FloatNode {
|
||||
id: state.node_ids.next(),
|
||||
visible: Cell::new(true),
|
||||
position: Cell::new(position),
|
||||
display: output.display.clone(),
|
||||
display_link: Cell::new(None),
|
||||
workspace_link: Cell::new(None),
|
||||
workspace: CloneCell::new(workspace.clone()),
|
||||
child: CloneCell::new(Some(self.clone())),
|
||||
});
|
||||
self.parent_node.set(Some(floater.clone()));
|
||||
floater
|
||||
.display_link
|
||||
.set(Some(state.root.floaters.add_last(floater.clone())));
|
||||
floater
|
||||
.workspace_link
|
||||
.set(Some(workspace.floaters.add_last(floater.clone())));
|
||||
}
|
||||
|
||||
fn map_tiled(self: &Rc<Self>) {
|
||||
log::info!("mapping tiled");
|
||||
let state = &self.xdg.surface.client.state;
|
||||
let seat = state.seat_queue.last();
|
||||
if let Some(seat) = seat {
|
||||
if let Some(prev) = seat.last_tiled_keyboard_toplevel() {
|
||||
if let Some(container) = prev.parent_node.get() {
|
||||
if let Some(container) = container.into_container() {
|
||||
container.add_child_after(&*prev, self.clone());
|
||||
self.parent_node.set(Some(container));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let output = {
|
||||
let outputs = state.root.outputs.lock();
|
||||
outputs.values().next().cloned()
|
||||
};
|
||||
if let Some(output) = output {
|
||||
if let Some(workspace) = output.workspace.get() {
|
||||
if let Some(container) = workspace.container.get() {
|
||||
container.append_child(self.clone());
|
||||
self.parent_node.set(Some(container));
|
||||
} else {
|
||||
let container =
|
||||
Rc::new(ContainerNode::new(state, workspace.clone(), self.clone()));
|
||||
workspace.set_container(&container);
|
||||
self.parent_node.set(Some(container));
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
todo!("map_tiled");
|
||||
}
|
||||
|
||||
fn get_workspace(&self) -> Option<Rc<WorkspaceNode>> {
|
||||
match self.parent_node.get() {
|
||||
Some(node) => node.get_workspace(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(XdgToplevel);
|
||||
|
|
@ -200,4 +326,101 @@ impl Object for XdgToplevel {
|
|||
fn num_requests(&self) -> u32 {
|
||||
SET_MINIMIZED + 1
|
||||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
if let Some(parent) = self.parent_node.take() {
|
||||
parent.remove_child(self);
|
||||
}
|
||||
self.parent.set(None);
|
||||
let _children = mem::take(&mut *self.children.borrow_mut());
|
||||
self.focus_subsurface.set(None);
|
||||
}
|
||||
}
|
||||
|
||||
impl Node for XdgToplevel {
|
||||
fn id(&self) -> NodeId {
|
||||
self.node_id.into()
|
||||
}
|
||||
|
||||
fn clear(&self) {
|
||||
self.parent_node.set(None);
|
||||
}
|
||||
|
||||
fn find_child_at(&self, mut x: i32, mut y: i32) -> Option<FoundNode> {
|
||||
if let Some(geo) = self.xdg.geometry.get() {
|
||||
let (xt, yt) = geo.translate_inv(x, y);
|
||||
x = xt;
|
||||
y = yt;
|
||||
}
|
||||
match self.xdg.surface.find_surface_at(x, y) {
|
||||
Some((node, x, y)) => Some(FoundNode {
|
||||
node: if std::ptr::eq(node.deref(), self.xdg.surface.deref()) {
|
||||
node
|
||||
} else {
|
||||
node.ext.get().into_node().unwrap()
|
||||
},
|
||||
x,
|
||||
y,
|
||||
contained: true,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn render(&self, renderer: &mut dyn Renderer, x: i32, y: i32) {
|
||||
renderer.render_toplevel(self, x, y)
|
||||
}
|
||||
|
||||
fn get_workspace(self: Rc<Self>) -> Option<Rc<WorkspaceNode>> {
|
||||
self.deref().get_workspace()
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &WlSeatGlobal, _x: Fixed, _y: Fixed) {
|
||||
seat.enter_toplevel(&self);
|
||||
}
|
||||
|
||||
fn change_size(self: Rc<Self>, width: i32, height: i32) {
|
||||
self.xdg.surface.client.event(self.configure(width, height));
|
||||
self.xdg.send_configure();
|
||||
self.xdg.surface.client.flush();
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurfaceExt for XdgToplevel {
|
||||
fn post_commit(self: Rc<Self>) {
|
||||
let surface = &self.xdg.surface;
|
||||
if let Some(parent) = self.parent_node.get() {
|
||||
if surface.buffer.get().is_none() {
|
||||
parent.remove_child(&*self);
|
||||
{
|
||||
let new_parent = self.parent.get();
|
||||
let mut children = self.children.borrow_mut();
|
||||
for (_, child) in children.drain() {
|
||||
child.parent.set(new_parent.clone());
|
||||
}
|
||||
}
|
||||
surface.client.state.tree_changed();
|
||||
}
|
||||
} else if surface.buffer.get().is_some() {
|
||||
if let Some(parent) = self.parent.get() {
|
||||
self.map_child(&parent);
|
||||
} else {
|
||||
self.map_tiled();
|
||||
}
|
||||
self.extents_changed();
|
||||
surface.client.state.tree_changed();
|
||||
}
|
||||
}
|
||||
|
||||
fn extents_changed(&self) {
|
||||
if let Some(parent) = self.parent_node.get() {
|
||||
let extents = self.xdg.extents.get();
|
||||
parent.child_size_changed(self, extents.width(), extents.height());
|
||||
self.xdg.surface.client.state.tree_changed();
|
||||
}
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue