1
0
Fork 0
forked from wry/wry

autocommit 2022-01-04 15:30:21 CET

This commit is contained in:
Julian Orth 2022-01-04 15:30:21 +01:00
parent 30376c595c
commit cbbc41a463
40 changed files with 725 additions and 189 deletions

View file

@ -2,13 +2,18 @@ mod types;
pub mod xdg_popup;
pub mod xdg_toplevel;
use crate::ifs::wl_surface::{RoleData, SurfaceRole, WlSurface, XdgSurfaceData};
use crate::client::AddObj;
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup;
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel;
use crate::ifs::wl_surface::{
RoleData, SurfaceRole, WlSurface, XdgPopupData, XdgSurfaceData, XdgSurfaceRole,
XdgSurfaceRoleData, XdgToplevelData,
};
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::rc::Rc;
pub use types::*;
use crate::client::AddObj;
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
const DESTROY: u32 = 0;
const GET_TOPLEVEL: u32 = 1;
@ -22,15 +27,22 @@ const NOT_CONSTRUCTED: u32 = 1;
const ALREADY_CONSTRUCTED: u32 = 2;
const UNCONFIGURED_BUFFER: u32 = 3;
id!(XdgSurfaceId);
pub struct XdgSurface {
id: ObjectId,
id: XdgSurfaceId,
wm_base: Rc<XdgWmBaseObj>,
surface: Rc<WlSurface>,
pub(super) surface: Rc<WlSurface>,
version: u32,
}
impl XdgSurface {
pub fn new(wm_base: &Rc<XdgWmBaseObj>, id: ObjectId, surface: &Rc<WlSurface>, version: u32) -> Self {
pub fn new(
wm_base: &Rc<XdgWmBaseObj>,
id: XdgSurfaceId,
surface: &Rc<WlSurface>,
version: u32,
) -> Self {
Self {
id,
wm_base: wm_base.clone(),
@ -50,25 +62,101 @@ impl XdgSurface {
}
*data = RoleData::XdgSurface(Box::new(XdgSurfaceData {
xdg_surface: self.clone(),
committed: false,
role: XdgSurfaceRole::None,
role_data: XdgSurfaceRoleData::None,
popups: Default::default(),
}));
Ok(())
}
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
let _req: Destroy = self.surface.client.parse(self, parser)?;
*self.surface.role_data.borrow_mut() = RoleData::None;
{
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;
}
}
}
}
*data = RoleData::None;
}
self.wm_base.surfaces.remove(&self.id);
self.surface.client.remove_obj(self).await?;
Ok(())
}
async fn get_toplevel(&self, parser: MsgParser<'_, '_>) -> Result<(), GetToplevelError> {
let _req: GetToplevel = self.surface.client.parse(self, parser)?;
async 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.version));
self.surface.client.add_client_obj(&toplevel)?;
data.role_data = XdgSurfaceRoleData::Toplevel(XdgToplevelData { toplevel });
}
Ok(())
}
async fn get_popup(&self, parser: MsgParser<'_, '_>) -> Result<(), GetPopupError> {
let _req: GetPopup = self.surface.client.parse(self, parser)?;
async 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.version));
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, parent });
}
Ok(())
}
@ -86,7 +174,7 @@ impl XdgSurface {
}
async fn handle_request_(
&self,
self: &Rc<Self>,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), XdgSurfaceError> {
@ -106,7 +194,7 @@ handle_request!(XdgSurface);
impl Object for XdgSurface {
fn id(&self) -> ObjectId {
self.id
self.id.into()
}
fn interface(&self) -> Interface {

View file

@ -1,11 +1,14 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, CONFIGURE};
use crate::object::{Object, ObjectId};
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::xdg_positioner::XdgPositionerId;
use crate::object::Object;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
use crate::ifs::wl_surface::SurfaceRole;
#[derive(Debug, Error)]
pub enum XdgSurfaceError {
@ -20,9 +23,9 @@ pub enum XdgSurfaceError {
#[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(ObjectId, SurfaceRole),
IncompatibleRole(WlSurfaceId, SurfaceRole),
#[error("Surface {0} cannot be turned into a xdg_surface because it already has an attached xdg_surface")]
AlreadyAttached(ObjectId),
AlreadyAttached(WlSurfaceId),
}
#[derive(Debug, Error)]
@ -31,6 +34,8 @@ pub enum DestroyError {
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Cannot destroy xdg_surface {0} because it's associated xdg_toplevel/popup is not yet destroyed")]
RoleNotYetDestroyed(XdgSurfaceId),
}
efrom!(DestroyError, ParseFailed, MsgParserError);
efrom!(DestroyError, ClientError, ClientError);
@ -41,6 +46,10 @@ 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,
}
efrom!(GetToplevelError, ParseFailed, MsgParserError);
efrom!(GetToplevelError, ClientError, ClientError);
@ -51,6 +60,10 @@ 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,
}
efrom!(GetPopupError, ParseFailed, MsgParserError);
efrom!(GetPopupError, ClientError, ClientError);
@ -88,7 +101,7 @@ impl Debug for Destroy {
}
pub(super) struct GetToplevel {
pub id: ObjectId,
pub id: XdgToplevelId,
}
impl RequestParser<'_> for GetToplevel {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
@ -104,9 +117,9 @@ impl Debug for GetToplevel {
}
pub(super) struct GetPopup {
pub id: ObjectId,
pub parent: ObjectId,
pub positioner: ObjectId,
pub id: XdgPopupId,
pub parent: XdgSurfaceId,
pub positioner: XdgPositionerId,
}
impl RequestParser<'_> for GetPopup {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {

View file

@ -1,6 +1,7 @@
mod types;
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
use crate::ifs::wl_surface::{RoleData, XdgSurfaceRoleData};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::rc::Rc;
@ -16,14 +17,16 @@ const REPOSITIONED: u32 = 2;
const INVALID_GRAB: u32 = 1;
id!(XdgPopupId);
pub struct XdgPopup {
id: ObjectId,
surface: Rc<XdgSurface>,
id: XdgPopupId,
pub(in super::super) surface: Rc<XdgSurface>,
version: u32,
}
impl XdgPopup {
pub fn new(id: ObjectId, surface: &Rc<XdgSurface>, version: u32) -> Self {
pub fn new(id: XdgPopupId, surface: &Rc<XdgSurface>, version: u32) -> Self {
Self {
id,
surface: surface.clone(),
@ -33,6 +36,20 @@ impl XdgPopup {
async 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;
}
}
Ok(())
}
@ -65,7 +82,7 @@ handle_request!(XdgPopup);
impl Object for XdgPopup {
fn id(&self) -> ObjectId {
self.id
self.id.into()
}
fn interface(&self) -> Interface {

View file

@ -1,8 +1,10 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_seat::WlSeatId;
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{
XdgPopup, CONFIGURE, POPUP_DONE, REPOSITIONED,
};
use crate::object::{Object, ObjectId};
use crate::ifs::xdg_positioner::XdgPositionerId;
use crate::object::Object;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
@ -61,7 +63,7 @@ impl Debug for Destroy {
}
pub(super) struct Grab {
pub seat: ObjectId,
pub seat: WlSeatId,
pub serial: u32,
}
impl RequestParser<'_> for Grab {
@ -79,7 +81,7 @@ impl Debug for Grab {
}
pub(super) struct Reposition {
pub positioner: ObjectId,
pub positioner: XdgPositionerId,
pub token: u32,
}
impl RequestParser<'_> for Reposition {

View file

@ -1,6 +1,7 @@
mod types;
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
use crate::ifs::wl_surface::{RoleData, XdgSurfaceRoleData};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use num_derive::FromPrimitive;
@ -47,14 +48,16 @@ const STATE_TILED_RIGHT: u32 = 6;
const STATE_TILED_TOP: u32 = 7;
const STATE_TILED_BOTTOM: u32 = 8;
id!(XdgToplevelId);
pub struct XdgToplevel {
id: ObjectId,
id: XdgToplevelId,
surface: Rc<XdgSurface>,
version: u32,
}
impl XdgToplevel {
pub fn new(id: ObjectId, surface: &Rc<XdgSurface>, version: u32) -> Self {
pub fn new(id: XdgToplevelId, surface: &Rc<XdgSurface>, version: u32) -> Self {
Self {
id,
surface: surface.clone(),
@ -64,6 +67,12 @@ impl XdgToplevel {
async 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(rd) = &mut *rd {
rd.role_data = XdgSurfaceRoleData::None;
}
}
Ok(())
}
@ -165,7 +174,7 @@ handle_request!(XdgToplevel);
impl Object for XdgToplevel {
fn id(&self) -> ObjectId {
self.id
self.id.into()
}
fn interface(&self) -> Interface {

View file

@ -1,7 +1,8 @@
use super::CONFIGURE;
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, CLOSE};
use crate::object::{Object, ObjectId};
use crate::ifs::wl_seat::WlSeatId;
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::{XdgToplevel, XdgToplevelId, CLOSE};
use crate::object::Object;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
@ -192,11 +193,13 @@ impl Debug for Destroy {
}
pub(super) struct SetParent {
pub parent: ObjectId,
pub parent: XdgToplevelId,
}
impl RequestParser<'_> for SetParent {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self { parent: parser.object()? })
Ok(Self {
parent: parser.object()?,
})
}
}
impl Debug for SetParent {
@ -210,7 +213,9 @@ pub(super) struct SetTitle<'a> {
}
impl<'a> RequestParser<'a> for SetTitle<'a> {
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
Ok(Self { title: parser.string()? })
Ok(Self {
title: parser.string()?,
})
}
}
impl<'a> Debug for SetTitle<'a> {
@ -224,7 +229,9 @@ pub(super) struct SetAppId<'a> {
}
impl<'a> RequestParser<'a> for SetAppId<'a> {
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
Ok(Self { app_id: parser.string()? })
Ok(Self {
app_id: parser.string()?,
})
}
}
impl<'a> Debug for SetAppId<'a> {
@ -234,7 +241,7 @@ impl<'a> Debug for SetAppId<'a> {
}
pub(super) struct ShowWindowMenu {
pub seat: ObjectId,
pub seat: WlSeatId,
pub serial: u32,
pub x: i32,
pub y: i32,
@ -251,17 +258,24 @@ impl RequestParser<'_> for ShowWindowMenu {
}
impl Debug for ShowWindowMenu {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "show_window_menu(seat: {}, serial: {}, x: {}, y: {})", self.seat, self.serial, self.x, self.y)
write!(
f,
"show_window_menu(seat: {}, serial: {}, x: {}, y: {})",
self.seat, self.serial, self.x, self.y
)
}
}
pub(super) struct Move {
pub seat: ObjectId,
pub seat: WlSeatId,
pub serial: u32,
}
impl RequestParser<'_> for Move {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self { seat: parser.object()?, serial: parser.uint()? })
Ok(Self {
seat: parser.object()?,
serial: parser.uint()?,
})
}
}
impl Debug for Move {
@ -271,7 +285,7 @@ impl Debug for Move {
}
pub(super) struct Resize {
pub seat: ObjectId,
pub seat: WlSeatId,
pub serial: u32,
pub edges: u32,
}
@ -286,7 +300,11 @@ impl RequestParser<'_> for Resize {
}
impl Debug for Resize {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "resize(seat: {}, serial: {}, edges: {})", self.seat, self.serial, self.edges)
write!(
f,
"resize(seat: {}, serial: {}, edges: {})",
self.seat, self.serial, self.edges
)
}
}
@ -296,12 +314,19 @@ pub(super) struct SetMaxSize {
}
impl RequestParser<'_> for SetMaxSize {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self { width: parser.int()?, height: parser.int()? })
Ok(Self {
width: parser.int()?,
height: parser.int()?,
})
}
}
impl Debug for SetMaxSize {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "set_max_size(width: {}, height: {})", self.width, self.height)
write!(
f,
"set_max_size(width: {}, height: {})",
self.width, self.height
)
}
}
@ -311,12 +336,19 @@ pub(super) struct SetMinSize {
}
impl RequestParser<'_> for SetMinSize {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self { width: parser.int()?, height: parser.int()? })
Ok(Self {
width: parser.int()?,
height: parser.int()?,
})
}
}
impl Debug for SetMinSize {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "set_min_size(width: {}, height: {})", self.width, self.height)
write!(
f,
"set_min_size(width: {}, height: {})",
self.width, self.height
)
}
}
@ -345,11 +377,13 @@ impl Debug for UnsetMaximized {
}
pub(super) struct SetFullscreen {
pub output: ObjectId,
pub output: crate::ifs::wl_output::WlOutputId,
}
impl RequestParser<'_> for SetFullscreen {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self { output: parser.object()? })
Ok(Self {
output: parser.object()?,
})
}
}
impl Debug for SetFullscreen {