1
0
Fork 0
forked from wry/wry

autocommit 2022-01-06 19:08:32 CET

This commit is contained in:
Julian Orth 2022-01-06 19:08:32 +01:00
parent cbbc41a463
commit 4a939477a2
51 changed files with 3438 additions and 207 deletions

View file

@ -1,13 +1,15 @@
mod types;
use std::cell::RefCell;
use crate::client::{AddObj, Client};
use crate::clientmem::ClientMem;
use crate::client::{AddObj, Client, DynEventFormatter};
use crate::clientmem::{ClientMem, ClientMemOffset};
use crate::format::Format;
use crate::ifs::wl_surface::{WlSurface, WlSurfaceId};
use crate::object::{Interface, Object, ObjectId};
use crate::pixman;
use crate::utils::buffd::MsgParser;
use crate::utils::copyhashmap::CopyHashMap;
use std::rc::Rc;
pub use types::*;
use crate::utils::buffd::MsgParser;
const DESTROY: u32 = 0;
@ -19,11 +21,12 @@ pub struct WlBuffer {
id: WlBufferId,
client: Rc<Client>,
offset: usize,
width: u32,
height: u32,
pub width: u32,
pub height: u32,
stride: u32,
format: &'static Format,
mem: RefCell<Option<Rc<ClientMem>>>,
pub image: Rc<pixman::Image<ClientMemOffset>>,
pub(super) surfaces: CopyHashMap<WlSurfaceId, Rc<WlSurface>>,
}
impl WlBuffer {
@ -42,10 +45,12 @@ impl WlBuffer {
if required > mem.len() as u64 {
return Err(WlBufferError::OutOfBounds);
}
let mem = mem.offset(offset);
let min_row_size = width as u64 * format.bpp as u64;
if (stride as u64) < min_row_size {
return Err(WlBufferError::StrideTooSmall);
}
let image = pixman::Image::new(mem, format.pixman, width, height, stride)?;
Ok(Self {
id,
client: client.clone(),
@ -54,24 +59,38 @@ impl WlBuffer {
height,
stride,
format,
mem: RefCell::new(Some(mem.clone())),
image: Rc::new(image),
surfaces: Default::default(),
})
}
async fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
let _req: Destroy = self.client.parse(self, parser)?;
*self.mem.borrow_mut() = None;
{
let surfaces = self.surfaces.lock();
for surface in surfaces.values() {
*surface.buffer.borrow_mut() = None;
}
}
self.client.remove_obj(self).await?;
Ok(())
}
async fn handle_request_(&self, request: u32, parser: MsgParser<'_, '_>) -> Result<(), WlBufferError> {
async fn handle_request_(
&self,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), WlBufferError> {
match request {
DESTROY => self.destroy(parser).await?,
_ => unreachable!(),
}
Ok(())
}
pub fn release(self: &Rc<Self>) -> DynEventFormatter {
Box::new(Release { obj: self.clone() })
}
}
handle_request!(WlBuffer);
@ -88,4 +107,8 @@ impl Object for WlBuffer {
fn num_requests(&self) -> u32 {
DESTROY + 1
}
fn break_loops(&self) {
self.surfaces.clear();
}
}

View file

@ -1,10 +1,11 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_buffer::{WlBuffer, RELEASE};
use crate::object::Object;
use crate::pixman::PixmanError;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_buffer::{RELEASE, WlBuffer};
use crate::object::Object;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
#[derive(Debug, Error)]
pub enum WlBufferError {
@ -14,7 +15,10 @@ pub enum WlBufferError {
StrideTooSmall,
#[error("Could not handle a `destroy` request")]
DestroyError(#[from] DestroyError),
#[error("Pixman returned an error")]
PixmanError(#[source] Box<PixmanError>),
}
efrom!(WlBufferError, PixmanError, PixmanError);
#[derive(Debug, Error)]
pub enum DestroyError {

View file

@ -1 +1,223 @@
mod types;
use crate::backend::Output;
use crate::client::{AddObj, Client, ClientId, DynEventFormatter, WlEvent};
use crate::globals::{Global, GlobalName};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use crate::utils::copyhashmap::CopyHashMap;
use ahash::AHashMap;
use std::cell::Cell;
use std::iter;
use std::rc::Rc;
pub use types::*;
id!(WlOutputId);
const RELEASE: u32 = 0;
const GEOMETRY: u32 = 0;
const MODE: u32 = 1;
const DONE: u32 = 2;
const SCALE: u32 = 3;
const SP_UNKNOWN: i32 = 0;
const SP_NONE: i32 = 1;
const SP_HORIZONTAL_RGB: i32 = 2;
const SP_HORIZONTAL_BGR: i32 = 3;
const SP_VERTICAL_RGB: i32 = 4;
const SP_VERTICAL_BGR: i32 = 5;
const TF_NORMAL: i32 = 0;
const TF_90: i32 = 1;
const TF_180: i32 = 2;
const TF_270: i32 = 3;
const TF_FLIPPED: i32 = 4;
const TF_FLIPPED_90: i32 = 5;
const TF_FLIPPED_180: i32 = 6;
const TF_FLIPPED_270: i32 = 7;
const MODE_CURRENT: u32 = 1;
const MODE_PREFERRED: u32 = 2;
pub struct WlOutputGlobal {
name: GlobalName,
output: Rc<dyn Output>,
width: Cell<u32>,
height: Cell<u32>,
bindings: CopyHashMap<(ClientId, WlOutputId), Rc<WlOutputObj>>,
}
impl WlOutputGlobal {
pub fn new(name: GlobalName, output: &Rc<dyn Output>) -> Self {
Self {
name,
output: output.clone(),
width: Cell::new(output.width()),
height: Cell::new(output.height()),
bindings: Default::default(),
}
}
pub async fn update_properties(&self) {
let width = self.output.width();
let height = self.output.height();
let mut changed = false;
changed |= self.width.replace(width) != width;
changed |= self.height.replace(height) != height;
if changed {
let mut clients = AHashMap::new();
{
let bindings = self.bindings.lock();
for binding in bindings.values() {
let events = [
binding.geometry(),
binding.mode(),
binding.scale(),
binding.done(),
];
let events = events
.into_iter()
.map(|e| WlEvent::Event(e))
.chain(iter::once(WlEvent::Flush));
for event in events {
if binding.client.event2_locked(event) {
clients.insert(binding.client.id, binding.client.clone());
}
}
}
}
for client in clients.values() {
let _ = client.check_queue_size().await;
}
}
}
async fn bind_(
self: Rc<Self>,
id: WlOutputId,
client: &Rc<Client>,
version: u32,
) -> Result<(), WlOutputError> {
let obj = Rc::new(WlOutputObj {
global: self.clone(),
id,
client: client.clone(),
});
client.add_client_obj(&obj)?;
self.bindings.set((client.id, id), obj.clone());
client.event(obj.geometry()).await?;
client.event(obj.mode()).await?;
client.event(obj.scale()).await?;
client.event(obj.done()).await?;
Ok(())
}
}
bind!(WlOutputGlobal);
impl Global for WlOutputGlobal {
fn name(&self) -> GlobalName {
self.name
}
fn interface(&self) -> Interface {
Interface::WlOutput
}
fn version(&self) -> u32 {
3
}
fn pre_remove(&self) {
//
}
fn break_loops(&self) {
self.bindings.clear();
}
}
pub struct WlOutputObj {
global: Rc<WlOutputGlobal>,
id: WlOutputId,
client: Rc<Client>,
}
impl WlOutputObj {
fn geometry(self: &Rc<Self>) -> DynEventFormatter {
Box::new(Geometry {
obj: self.clone(),
x: 0,
y: 0,
physical_width: self.global.width.get() as _,
physical_height: self.global.height.get() as _,
subpixel: SP_UNKNOWN,
make: String::new(),
model: String::new(),
transform: TF_NORMAL,
})
}
fn mode(self: &Rc<Self>) -> DynEventFormatter {
Box::new(Mode {
obj: self.clone(),
flags: MODE_CURRENT,
width: self.global.width.get() as _,
height: self.global.height.get() as _,
refresh: 60_000_000,
})
}
fn scale(self: &Rc<Self>) -> DynEventFormatter {
Box::new(Scale {
obj: self.clone(),
factor: 1,
})
}
fn done(self: &Rc<Self>) -> DynEventFormatter {
Box::new(Done { obj: self.clone() })
}
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
let _req: Release = self.client.parse(self, parser)?;
self.global.bindings.remove(&(self.client.id, self.id));
self.client.remove_obj(self).await?;
Ok(())
}
async fn handle_request_(
&self,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), WlOutputError> {
match request {
RELEASE => self.release(parser).await?,
_ => unreachable!(),
}
Ok(())
}
}
handle_request!(WlOutputObj);
impl Object for WlOutputObj {
fn id(&self) -> ObjectId {
self.id.into()
}
fn interface(&self) -> Interface {
Interface::WlOutput
}
fn num_requests(&self) -> u32 {
RELEASE + 1
}
fn break_loops(&self) {
self.global.bindings.remove(&(self.client.id, self.id));
}
}

136
src/ifs/wl_output/types.rs Normal file
View file

@ -0,0 +1,136 @@
use crate::client::{ClientError, EventFormatter, RequestParser};
use crate::ifs::wl_output::{WlOutputObj, DONE, GEOMETRY, MODE, SCALE};
use crate::object::Object;
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum WlOutputError {
#[error("Could not handle `release` request")]
ReleaseError(#[from] ReleaseError),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(WlOutputError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum ReleaseError {
#[error("Parsing failed")]
ParseError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(ReleaseError, ClientError, ClientError);
efrom!(ReleaseError, ParseError, MsgParserError);
pub(super) struct Release;
impl RequestParser<'_> for Release {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self)
}
}
impl Debug for Release {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "release()")
}
}
pub(super) struct Geometry {
pub obj: Rc<WlOutputObj>,
pub x: i32,
pub y: i32,
pub physical_width: i32,
pub physical_height: i32,
pub subpixel: i32,
pub make: String,
pub model: String,
pub transform: i32,
}
impl EventFormatter for Geometry {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, GEOMETRY)
.int(self.x)
.int(self.y)
.int(self.physical_width)
.int(self.physical_height)
.int(self.subpixel)
.string(&self.make)
.string(&self.model)
.int(self.transform);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Geometry {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "geometry(x: {}, y: {}, physical_width: {}, physical_height: {}, subpixel: {}, make: {}, model: {}, transform: {})",
self.x, self.y, self.physical_width, self.physical_height, self.subpixel, self.make, self.model, self.transform)
}
}
pub(super) struct Mode {
pub obj: Rc<WlOutputObj>,
pub flags: u32,
pub width: i32,
pub height: i32,
pub refresh: i32,
}
impl EventFormatter for Mode {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, MODE)
.uint(self.flags)
.int(self.width)
.int(self.height)
.int(self.refresh);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Mode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"mode(flags: 0x{:x}, width: {}, height: {}, refresh: {})",
self.flags, self.width, self.height, self.refresh
)
}
}
pub(super) struct Done {
pub obj: Rc<WlOutputObj>,
}
impl EventFormatter for Done {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, DONE);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Done {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "done()")
}
}
pub(super) struct Scale {
pub obj: Rc<WlOutputObj>,
pub factor: i32,
}
impl EventFormatter for Scale {
fn format(self: Box<Self>, fmt: &mut MsgFormatter<'_>) {
fmt.header(self.obj.id, SCALE).int(self.factor);
}
fn obj(&self) -> &dyn Object {
&*self.obj
}
}
impl Debug for Scale {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "scale(factor: {})", self.factor)
}
}

View file

@ -3,6 +3,7 @@ use crate::globals::{Global, GlobalError, GlobalName};
use crate::ifs::wl_registry::{WlRegistry, GLOBAL, GLOBAL_REMOVE};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError};
use bstr::BStr;
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
@ -93,7 +94,7 @@ impl Debug for GlobalRemove {
pub(super) struct Bind<'a> {
pub name: GlobalName,
pub id: ObjectId,
pub interface: &'a str,
pub interface: &'a BStr,
pub version: u32,
}
impl<'a> RequestParser<'a> for Bind<'a> {

View file

@ -1 +1,121 @@
mod types;
use crate::backend::{Seat, SeatEvent};
use crate::client::{AddObj, Client, ClientId};
use crate::globals::{Global, GlobalName};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use crate::utils::copyhashmap::CopyHashMap;
use std::rc::Rc;
pub use types::*;
id!(WlSeatId);
const RELEASE: u32 = 0;
pub struct WlSeatGlobal {
name: GlobalName,
seat: Rc<dyn Seat>,
bindings: CopyHashMap<(ClientId, WlSeatId), Rc<WlSeatObj>>,
}
impl WlSeatGlobal {
pub fn new(name: GlobalName, seat: &Rc<dyn Seat>) -> Self {
Self {
name,
seat: seat.clone(),
bindings: Default::default(),
}
}
pub async fn event(&self, event: SeatEvent) {
log::debug!("se: {:?}", event);
}
async fn bind_(
self: Rc<Self>,
id: WlSeatId,
client: &Rc<Client>,
version: u32,
) -> Result<(), WlSeatError> {
let obj = Rc::new(WlSeatObj {
global: self.clone(),
id,
client: client.clone(),
});
client.add_client_obj(&obj)?;
self.bindings.set((client.id, id), obj.clone());
Ok(())
}
}
bind!(WlSeatGlobal);
impl Global for WlSeatGlobal {
fn name(&self) -> GlobalName {
self.name
}
fn interface(&self) -> Interface {
Interface::WlSeat
}
fn version(&self) -> u32 {
3
}
fn pre_remove(&self) {
//
}
fn break_loops(&self) {
self.bindings.clear();
}
}
pub struct WlSeatObj {
global: Rc<WlSeatGlobal>,
id: WlSeatId,
client: Rc<Client>,
}
impl WlSeatObj {
async fn release(&self, parser: MsgParser<'_, '_>) -> Result<(), ReleaseError> {
let _req: Release = self.client.parse(self, parser)?;
self.global.bindings.remove(&(self.client.id, self.id));
self.client.remove_obj(self).await?;
Ok(())
}
async fn handle_request_(
&self,
request: u32,
parser: MsgParser<'_, '_>,
) -> Result<(), WlSeatError> {
match request {
RELEASE => self.release(parser).await?,
_ => unreachable!(),
}
Ok(())
}
}
handle_request!(WlSeatObj);
impl Object for WlSeatObj {
fn id(&self) -> ObjectId {
self.id.into()
}
fn interface(&self) -> Interface {
Interface::WlSeat
}
fn num_requests(&self) -> u32 {
RELEASE + 1
}
fn break_loops(&self) {
self.global.bindings.remove(&(self.client.id, self.id));
}
}

35
src/ifs/wl_seat/types.rs Normal file
View file

@ -0,0 +1,35 @@
use crate::client::{ClientError, RequestParser};
use crate::utils::buffd::{MsgParser, MsgParserError};
use std::fmt::{Debug, Formatter};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum WlSeatError {
#[error("Could not handle `release` request")]
ReleaseError(#[from] ReleaseError),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(WlSeatError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum ReleaseError {
#[error("Parsing failed")]
ParseError(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(ReleaseError, ClientError, ClientError);
efrom!(ReleaseError, ParseError, MsgParserError);
pub(super) struct Release;
impl RequestParser<'_> for Release {
fn parse(_parser: &mut MsgParser<'_, '_>) -> Result<Self, MsgParserError> {
Ok(Self)
}
}
impl Debug for Release {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "release()")
}
}

View file

@ -3,17 +3,22 @@ pub mod wl_subsurface;
pub mod xdg_surface;
use crate::client::{AddObj, Client, RequestParser};
use crate::ifs::wl_buffer::WlBuffer;
use crate::ifs::wl_callback::WlCallback;
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::tree::{NodeBase, NodeCommon, ToplevelNode};
use crate::utils::buffd::{MsgParser, MsgParserError};
use crate::utils::copyhashmap::CopyHashMap;
use crate::utils::linkedlist::{LinkedList, Node};
use crate::utils::linkedlist::{LinkedList, Node as LinkNode};
use ahash::AHashMap;
use std::cell::{Cell, RefCell};
use std::mem;
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
pub use types::*;
@ -56,11 +61,24 @@ impl SurfaceRole {
pub struct WlSurface {
id: WlSurfaceId,
client: Rc<Client>,
pub client: Rc<Client>,
role: Cell<SurfaceRole>,
pending: PendingState,
children: RefCell<Option<Box<ParentData>>>,
input_region: Cell<Option<Region>>,
opaque_region: Cell<Option<Region>>,
pub extents: Cell<SurfaceExtents>,
pub buffer: RefCell<Option<Rc<WlBuffer>>>,
pub children: RefCell<Option<Box<ParentData>>>,
role_data: RefCell<RoleData>,
pub frame_requests: RefCell<Vec<Rc<WlCallback>>>,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub struct SurfaceExtents {
pub x1: i32,
pub y1: i32,
pub x2: i32,
pub y2: i32,
}
enum RoleData {
@ -79,11 +97,13 @@ impl RoleData {
struct PendingState {
opaque_region: Cell<Option<Region>>,
input_region: Cell<Option<Region>>,
frame_request: RefCell<Vec<Rc<WlCallback>>>,
}
struct XdgSurfaceData {
xdg_surface: Rc<XdgSurface>,
committed: bool,
requested_serial: u32,
acked_serial: Option<u32>,
role: XdgSurfaceRole,
role_data: XdgSurfaceRoleData,
popups: CopyHashMap<WlSurfaceId, Rc<XdgPopup>>,
@ -121,6 +141,17 @@ struct XdgPopupData {
struct XdgToplevelData {
toplevel: Rc<XdgToplevel>,
node: Option<ToplevelNodeHolder>,
}
struct ToplevelNodeHolder {
node: Rc<ToplevelNode>,
}
impl Drop for ToplevelNodeHolder {
fn drop(&mut self) {
mem::take(&mut *self.node.common.floating_outputs.borrow_mut());
}
}
struct SubsurfaceData {
@ -129,27 +160,27 @@ struct SubsurfaceData {
y: i32,
sync_requested: bool,
sync_ancestor: bool,
node: Node<StackElement>,
node: LinkNode<StackElement>,
depth: u32,
pending: PendingSubsurfaceData,
}
#[derive(Default)]
struct PendingSubsurfaceData {
node: Option<Node<StackElement>>,
node: Option<LinkNode<StackElement>>,
position: Option<(i32, i32)>,
}
#[derive(Default)]
struct ParentData {
pub struct ParentData {
subsurfaces: AHashMap<WlSurfaceId, Rc<WlSurface>>,
below: LinkedList<StackElement>,
above: LinkedList<StackElement>,
pub below: LinkedList<StackElement>,
pub above: LinkedList<StackElement>,
}
struct StackElement {
pub struct StackElement {
pending: Cell<bool>,
surface: Rc<WlSurface>,
pub surface: Rc<WlSurface>,
}
impl WlSurface {
@ -159,11 +190,60 @@ impl WlSurface {
client: client.clone(),
role: Cell::new(SurfaceRole::None),
pending: Default::default(),
input_region: Cell::new(None),
opaque_region: Cell::new(None),
extents: Default::default(),
buffer: RefCell::new(None),
children: Default::default(),
role_data: RefCell::new(RoleData::None),
frame_requests: RefCell::new(vec![]),
}
}
pub fn subsurface_position(&self) -> Option<(i32, i32)> {
let rd = self.role_data.borrow();
match rd.deref() {
RoleData::Subsurface(ss) => Some((ss.x, ss.y)),
_ => None,
}
}
fn calculate_extents(&self) {
{
let mut extents = SurfaceExtents::default();
if let Some(b) = self.buffer.borrow().deref() {
extents.x2 = b.width as i32;
extents.y2 = b.height as i32;
}
let children = self.children.borrow();
if let Some(children) = &*children {
for surface in children.subsurfaces.values() {
let rd = surface.role_data.borrow();
if let RoleData::Subsurface(ss) = &*rd {
let mut ss_extents = surface.extents.get();
extents.x1 = extents.x1.min(ss_extents.x1 + ss.x);
extents.y1 = extents.y1.min(ss_extents.y1 + ss.y);
extents.x2 = extents.x2.max(ss_extents.x2 + ss.x);
extents.y2 = extents.y2.max(ss_extents.y2 + ss.y);
}
}
}
self.extents.set(extents);
}
let parent = {
let rd = self.role_data.borrow();
match &*rd {
RoleData::Subsurface(ss) => ss.subsurface.parent.clone(),
_ => return,
}
};
parent.calculate_extents();
}
pub fn is_subsurface(&self) -> bool {
self.role.get() == SurfaceRole::Subsurface
}
pub fn get_root(self: &Rc<Self>) -> Rc<WlSurface> {
let mut root = self.clone();
loop {
@ -197,11 +277,13 @@ impl WlSurface {
}
*children = None;
}
let mut ss_parent = None;
{
let mut data = self.role_data.borrow_mut();
match &mut *data {
RoleData::None => {}
RoleData::Subsurface(ss) => {
ss_parent = Some(ss.subsurface.parent.clone());
let mut children = ss.subsurface.parent.children.borrow_mut();
if let Some(children) = &mut *children {
children.subsurfaces.remove(&self.id);
@ -229,12 +311,63 @@ impl WlSurface {
}
*data = RoleData::None;
}
{
let buffer = self.buffer.borrow();
if let Some(buffer) = &*buffer {
buffer.surfaces.remove(&self.id);
}
}
if let Some(parent) = ss_parent {
parent.calculate_extents();
}
self.client.remove_obj(self).await?;
Ok(())
}
async fn attach(&self, parser: MsgParser<'_, '_>) -> Result<(), AttachError> {
let req: Attach = self.parse(parser)?;
{
let mut buffer = self.buffer.borrow_mut();
if let Some(buffer) = buffer.take() {
self.client.event(buffer.release()).await?;
buffer.surfaces.remove(&self.id);
}
let mut rd = self.role_data.borrow_mut();
if req.buffer.is_some() {
*buffer = Some(self.client.get_buffer(req.buffer)?);
if let RoleData::XdgSurface(xdg) = &mut *rd {
if let XdgSurfaceRoleData::Toplevel(td) = &mut xdg.role_data {
if td.node.is_none() {
let outputs = self.client.state.root.outputs.lock();
if let Some(output) = outputs.values().next() {
let node = Rc::new(ToplevelNode {
common: NodeCommon {
extents: Cell::new(Default::default()),
id: self.client.state.node_ids.next(),
parent: Some(output.clone()),
floating_outputs: RefCell::new(Default::default()),
},
surface: td.toplevel.clone(),
});
td.node = Some(ToplevelNodeHolder { node: node.clone() });
let link = output.floating.append(node.clone());
node.common
.floating_outputs
.borrow_mut()
.insert(output.id(), link);
}
}
}
}
} else {
*buffer = None;
if let RoleData::XdgSurface(xdg) = &mut *rd {
if let XdgSurfaceRoleData::Toplevel(td) = &mut xdg.role_data {
td.node = None;
}
}
}
}
Ok(())
}
@ -245,6 +378,9 @@ impl WlSurface {
async fn frame(&self, parser: MsgParser<'_, '_>) -> Result<(), FrameError> {
let req: Frame = self.parse(parser)?;
let cb = Rc::new(WlCallback::new(req.callback));
self.client.add_client_obj(&cb)?;
self.pending.frame_request.borrow_mut().push(cb);
Ok(())
}
@ -265,8 +401,75 @@ impl WlSurface {
Ok(())
}
fn do_commit(&self) {
{
let mut rd = self.role_data.borrow_mut();
match &mut *rd {
RoleData::None => {}
RoleData::Subsurface(ss) => {
if let Some(v) = ss.pending.node.take() {
v.pending.set(false);
ss.node = v;
}
if let Some((x, y)) = ss.pending.position.take() {
ss.x = x;
ss.y = y;
}
}
RoleData::XdgSurface(xdg) => {}
}
}
{
let mut pfr = self.pending.frame_request.borrow_mut();
self.frame_requests.borrow_mut().extend(pfr.drain(..));
}
{
if let Some(region) = self.pending.input_region.take() {
self.input_region.set(Some(region));
}
if let Some(region) = self.pending.opaque_region.take() {
self.opaque_region.set(Some(region));
}
}
let mut committed_any_children = false;
{
let children = self.children.borrow();
if let Some(children) = children.deref() {
for child in children.subsurfaces.values() {
child.do_commit();
committed_any_children = true;
}
}
}
if !committed_any_children {
self.calculate_extents();
}
}
async fn commit(&self, parser: MsgParser<'_, '_>) -> Result<(), CommitError> {
let req: Commit = self.parse(parser)?;
let _req: Commit = self.parse(parser)?;
{
let rd = self.role_data.borrow();
match rd.deref() {
RoleData::Subsurface(ss) => {
if ss.sync_ancestor || ss.sync_requested {
return Ok(());
}
}
RoleData::XdgSurface(xdg) => {
if xdg.acked_serial != Some(xdg.requested_serial) {
if xdg.acked_serial.is_none() {
self.client
.event(xdg.xdg_surface.configure(xdg.requested_serial))
.await?;
}
return Ok(());
}
}
_ => {}
}
}
self.do_commit();
Ok(())
}
@ -328,5 +531,7 @@ impl Object for WlSurface {
fn break_loops(&self) {
*self.children.borrow_mut() = None;
*self.role_data.borrow_mut() = RoleData::None;
mem::take(self.frame_requests.borrow_mut().deref_mut());
*self.buffer.borrow_mut() = None;
}
}

View file

@ -57,8 +57,11 @@ efrom!(DestroyError, ClientError, ClientError);
pub enum AttachError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(AttachError, ParseFailed, MsgParserError);
efrom!(AttachError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum DamageError {
@ -71,8 +74,11 @@ efrom!(DamageError, ParseFailed, MsgParserError);
pub enum FrameError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(FrameError, ParseFailed, MsgParserError);
efrom!(FrameError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum SetOpaqueRegionError {
@ -98,8 +104,11 @@ efrom!(SetInputRegionError, ClientError, ClientError);
pub enum CommitError {
#[error("Parsing failed")]
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(CommitError, ParseFailed, MsgParserError);
efrom!(CommitError, ClientError, ClientError);
#[derive(Debug, Error)]
pub enum SetBufferTransformError {

View file

@ -142,6 +142,7 @@ impl WlSubsurface {
}
}
self.surface.client.remove_obj(self).await?;
self.parent.calculate_extents();
Ok(())
}

View file

@ -2,7 +2,7 @@ mod types;
pub mod xdg_popup;
pub mod xdg_toplevel;
use crate::client::AddObj;
use crate::client::{AddObj, DynEventFormatter};
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::{
@ -12,6 +12,7 @@ use crate::ifs::wl_surface::{
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use std::ops::DerefMut;
use std::rc::Rc;
pub use types::*;
@ -32,7 +33,7 @@ id!(XdgSurfaceId);
pub struct XdgSurface {
id: XdgSurfaceId,
wm_base: Rc<XdgWmBaseObj>,
pub(super) surface: Rc<WlSurface>,
pub surface: Rc<WlSurface>,
version: u32,
}
@ -51,6 +52,13 @@ impl XdgSurface {
}
}
pub fn configure(self: &Rc<Self>, serial: u32) -> DynEventFormatter {
Box::new(Configure {
obj: self.clone(),
serial,
})
}
pub fn install(self: &Rc<Self>) -> Result<(), XdgSurfaceError> {
let old_role = self.surface.role.get();
if !matches!(old_role, SurfaceRole::None | SurfaceRole::XdgSurface) {
@ -62,7 +70,8 @@ impl XdgSurface {
}
*data = RoleData::XdgSurface(Box::new(XdgSurfaceData {
xdg_surface: self.clone(),
committed: false,
requested_serial: 0,
acked_serial: None,
role: XdgSurfaceRole::None,
role_data: XdgSurfaceRoleData::None,
popups: Default::default(),
@ -119,7 +128,10 @@ impl XdgSurface {
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 });
data.role_data = XdgSurfaceRoleData::Toplevel(XdgToplevelData {
toplevel,
node: None,
});
}
Ok(())
}
@ -169,7 +181,13 @@ impl XdgSurface {
}
async fn ack_configure(&self, parser: MsgParser<'_, '_>) -> Result<(), AckConfigureError> {
let _req: AckConfigure = self.surface.client.parse(self, parser)?;
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);
}
}
Ok(())
}

View file

@ -52,7 +52,7 @@ id!(XdgToplevelId);
pub struct XdgToplevel {
id: XdgToplevelId,
surface: Rc<XdgSurface>,
pub surface: Rc<XdgSurface>,
version: u32,
}

View file

@ -4,6 +4,7 @@ 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 bstr::BStr;
use std::fmt::{Debug, Formatter};
use std::rc::Rc;
use thiserror::Error;
@ -209,7 +210,7 @@ impl Debug for SetParent {
}
pub(super) struct SetTitle<'a> {
pub title: &'a str,
pub title: &'a BStr,
}
impl<'a> RequestParser<'a> for SetTitle<'a> {
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {
@ -225,7 +226,7 @@ impl<'a> Debug for SetTitle<'a> {
}
pub(super) struct SetAppId<'a> {
pub app_id: &'a str,
pub app_id: &'a BStr,
}
impl<'a> RequestParser<'a> for SetAppId<'a> {
fn parse(parser: &mut MsgParser<'_, 'a>) -> Result<Self, MsgParserError> {