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

@ -4,15 +4,18 @@ pub mod xdg_surface;
use crate::client::{AddObj, Client, RequestParser};
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
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::xdg_surface::XdgSurface;
use crate::object::{Interface, Object, ObjectId};
use crate::pixman::Region;
use crate::utils::buffd::{MsgParser, MsgParserError};
use crate::utils::copyhashmap::CopyHashMap;
use crate::utils::linkedlist::{LinkedList, Node};
use ahash::AHashMap;
use std::cell::{Cell, RefCell};
use std::rc::Rc;
pub use types::*;
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
const DESTROY: u32 = 0;
const ATTACH: u32 = 1;
@ -32,6 +35,8 @@ const INVALID_SCALE: u32 = 0;
const INVALID_TRANSFORM: u32 = 1;
const INVALID_SIZE: u32 = 2;
id!(WlSurfaceId);
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum SurfaceRole {
None,
@ -50,7 +55,7 @@ impl SurfaceRole {
}
pub struct WlSurface {
id: ObjectId,
id: WlSurfaceId,
client: Rc<Client>,
role: Cell<SurfaceRole>,
pending: PendingState,
@ -78,21 +83,44 @@ struct PendingState {
struct XdgSurfaceData {
xdg_surface: Rc<XdgSurface>,
committed: bool,
role: XdgSurfaceRole,
role_data: XdgSurfaceRoleData,
popups: CopyHashMap<WlSurfaceId, Rc<XdgPopup>>,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum XdgSurfaceRole {
None,
Popup,
Toplevel,
}
impl XdgSurfaceRole {
fn is_compatible(self, role: XdgSurfaceRole) -> bool {
self == XdgSurfaceRole::None || self == role
}
}
enum XdgSurfaceRoleData {
None,
Popup(XdgPopupData),
Toplevel(XdgToplevelData),
}
struct XdgPopupData {
impl XdgSurfaceRoleData {
fn is_some(&self) -> bool {
!matches!(self, XdgSurfaceRoleData::None)
}
}
struct XdgPopupData {
popup: Rc<XdgPopup>,
parent: Option<Rc<XdgSurface>>,
}
struct XdgToplevelData {
toplevel: Rc<XdgToplevel>,
}
struct SubsurfaceData {
@ -114,7 +142,7 @@ struct PendingSubsurfaceData {
#[derive(Default)]
struct ParentData {
subsurfaces: AHashMap<ObjectId, Rc<WlSurface>>,
subsurfaces: AHashMap<WlSurfaceId, Rc<WlSurface>>,
below: LinkedList<StackElement>,
above: LinkedList<StackElement>,
}
@ -125,7 +153,7 @@ struct StackElement {
}
impl WlSurface {
pub fn new(id: ObjectId, client: &Rc<Client>) -> Self {
pub fn new(id: WlSurfaceId, client: &Rc<Client>) -> Self {
Self {
id,
client: client.clone(),
@ -136,11 +164,6 @@ impl WlSurface {
}
}
pub fn break_loops(&self) {
*self.children.borrow_mut() = None;
*self.role_data.borrow_mut() = RoleData::None;
}
pub fn get_root(self: &Rc<Self>) -> Rc<WlSurface> {
let mut root = self.clone();
loop {
@ -165,8 +188,47 @@ impl WlSurface {
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
let _req: Destroy = self.parse(parser)?;
*self.children.borrow_mut() = None;
*self.role_data.borrow_mut() = RoleData::None;
{
let mut children = self.children.borrow_mut();
if let Some(children) = &mut *children {
for surface in children.subsurfaces.values() {
*surface.role_data.borrow_mut() = RoleData::None;
}
}
*children = None;
}
{
let mut data = self.role_data.borrow_mut();
match &mut *data {
RoleData::None => {}
RoleData::Subsurface(ss) => {
let mut children = ss.subsurface.parent.children.borrow_mut();
if let Some(children) = &mut *children {
children.subsurfaces.remove(&self.id);
}
}
RoleData::XdgSurface(xdg) => {
let children = xdg.popups.lock();
for child in children.values() {
let mut rd = child.surface.surface.role_data.borrow_mut();
if let RoleData::XdgSurface(xdg) = &mut *rd {
if let XdgSurfaceRoleData::Popup(p) = &mut xdg.role_data {
p.parent = None;
}
}
}
if let XdgSurfaceRoleData::Popup(p) = &mut 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.id);
}
}
}
}
}
*data = RoleData::None;
}
self.client.remove_obj(self).await?;
Ok(())
}
@ -252,7 +314,7 @@ handle_request!(WlSurface);
impl Object for WlSurface {
fn id(&self) -> ObjectId {
self.id
self.id.into()
}
fn interface(&self) -> Interface {
@ -262,4 +324,9 @@ impl Object for WlSurface {
fn num_requests(&self) -> u32 {
DAMAGE_BUFFER + 1
}
fn break_loops(&self) {
*self.children.borrow_mut() = None;
*self.role_data.borrow_mut() = RoleData::None;
}
}

View file

@ -1,5 +1,6 @@
use crate::client::{ClientError, RequestParser};
use crate::object::ObjectId;
use crate::ifs::wl_callback::WlCallbackId;
use crate::ifs::wl_region::WlRegionId;
use crate::utils::buffd::{MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use thiserror::Error;
@ -134,7 +135,7 @@ impl Debug for Destroy {
}
pub(super) struct Attach {
pub buffer: ObjectId,
pub buffer: crate::ifs::wl_buffer::WlBufferId,
pub x: i32,
pub y: i32,
}
@ -184,7 +185,7 @@ impl Debug for Damage {
}
pub(super) struct Frame {
pub callback: ObjectId,
pub callback: WlCallbackId,
}
impl RequestParser<'_> for Frame {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
@ -200,7 +201,7 @@ impl Debug for Frame {
}
pub(super) struct SetOpaqueRegion {
pub region: ObjectId,
pub region: WlRegionId,
}
impl RequestParser<'_> for SetOpaqueRegion {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
@ -216,7 +217,7 @@ impl Debug for SetOpaqueRegion {
}
pub(super) struct SetInputRegion {
pub region: ObjectId,
pub region: WlRegionId,
}
impl RequestParser<'_> for SetInputRegion {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {

View file

@ -1,7 +1,9 @@
mod types;
use crate::client::AddObj;
use crate::ifs::wl_surface::{RoleData, StackElement, SubsurfaceData, SurfaceRole, WlSurface};
use crate::ifs::wl_surface::{
RoleData, StackElement, SubsurfaceData, SurfaceRole, WlSurface, WlSurfaceId,
};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::cell::Cell;
@ -19,8 +21,10 @@ const BAD_SURFACE: u32 = 0;
const MAX_SUBSURFACE_DEPTH: u32 = 100;
id!(WlSubsurfaceId);
pub struct WlSubsurface {
id: ObjectId,
id: WlSubsurfaceId,
surface: Rc<WlSurface>,
pub(super) parent: Rc<WlSurface>,
}
@ -67,7 +71,7 @@ fn update_children_attach(
}
impl WlSubsurface {
pub fn new(id: ObjectId, surface: &Rc<WlSurface>, parent: &Rc<WlSurface>) -> Self {
pub fn new(id: WlSubsurfaceId, surface: &Rc<WlSurface>, parent: &Rc<WlSurface>) -> Self {
Self {
id,
surface: surface.clone(),
@ -150,7 +154,7 @@ impl WlSubsurface {
Ok(())
}
fn place(&self, sibling: ObjectId, above: bool) -> Result<(), PlacementError> {
fn place(&self, sibling: WlSurfaceId, above: bool) -> Result<(), PlacementError> {
if sibling == self.surface.id {
return Err(PlacementError::AboveSelf(sibling));
}
@ -247,7 +251,7 @@ handle_request!(WlSubsurface);
impl Object for WlSubsurface {
fn id(&self) -> ObjectId {
self.id
self.id.into()
}
fn interface(&self) -> Interface {

View file

@ -1,6 +1,5 @@
use crate::client::{ClientError, RequestParser};
use crate::ifs::wl_surface::SurfaceRole;
use crate::object::ObjectId;
use crate::ifs::wl_surface::{SurfaceRole, WlSurfaceId};
use crate::utils::buffd::{MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use thiserror::Error;
@ -20,13 +19,13 @@ pub enum WlSubsurfaceError {
#[error("Could not process `set_desync` request")]
SetDesync(#[from] SetDesyncError),
#[error("Surface {0} cannot be assigned the role `Subsurface` because it already has the role `{1:?}`")]
IncompatibleType(ObjectId, SurfaceRole),
IncompatibleType(WlSurfaceId, SurfaceRole),
#[error("Surface {0} already has an attached `wl_subsurface`")]
AlreadyAttached(ObjectId),
AlreadyAttached(WlSurfaceId),
#[error("Surface {0} cannot be made its own parent")]
OwnParent(ObjectId),
OwnParent(WlSurfaceId),
#[error("Surface {0} cannot be made a subsurface of {1} because it's an ancestor of {1}")]
Ancestor(ObjectId, ObjectId),
Ancestor(WlSurfaceId, WlSurfaceId),
#[error("Subsurfaces cannot be nested deeper than 100 levels")]
MaxDepthExceeded,
}
@ -60,9 +59,9 @@ efrom!(PlaceAboveError, ParseFailed, MsgParserError);
#[derive(Debug, Error)]
pub enum PlacementError {
#[error("Cannot place {0} above/below itself")]
AboveSelf(ObjectId),
AboveSelf(WlSurfaceId),
#[error("{0} is not a sibling of {1}")]
NotASibling(ObjectId, ObjectId),
NotASibling(WlSurfaceId, WlSurfaceId),
}
#[derive(Debug, Error)]
@ -88,7 +87,7 @@ pub enum SetDesyncError {
}
efrom!(SetDesyncError, ParseFailed, MsgParserError);
pub(in crate::ifs) struct Destroy;
pub(super) struct Destroy;
impl RequestParser<'_> for Destroy {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self)
@ -100,7 +99,7 @@ impl Debug for Destroy {
}
}
pub(in crate::ifs) struct SetPosition {
pub(super) struct SetPosition {
pub x: i32,
pub y: i32,
}
@ -118,8 +117,8 @@ impl Debug for SetPosition {
}
}
pub(in crate::ifs) struct PlaceAbove {
pub sibling: ObjectId,
pub(super) struct PlaceAbove {
pub sibling: WlSurfaceId,
}
impl RequestParser<'_> for PlaceAbove {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
@ -134,8 +133,8 @@ impl Debug for PlaceAbove {
}
}
pub(in crate::ifs) struct PlaceBelow {
pub sibling: ObjectId,
pub(super) struct PlaceBelow {
pub sibling: WlSurfaceId,
}
impl RequestParser<'_> for PlaceBelow {
fn parse(parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
@ -150,7 +149,7 @@ impl Debug for PlaceBelow {
}
}
pub(in crate::ifs) struct SetSync;
pub(super) struct SetSync;
impl RequestParser<'_> for SetSync {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self)
@ -162,7 +161,7 @@ impl Debug for SetSync {
}
}
pub(in crate::ifs) struct SetDesync;
pub(super) struct SetDesync;
impl RequestParser<'_> for SetDesync {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self)

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 {