autocommit 2022-01-06 19:08:32 CET
This commit is contained in:
parent
cbbc41a463
commit
4a939477a2
51 changed files with 3438 additions and 207 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ impl WlSubsurface {
|
|||
}
|
||||
}
|
||||
self.surface.client.remove_obj(self).await?;
|
||||
self.parent.calculate_extents();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ id!(XdgToplevelId);
|
|||
|
||||
pub struct XdgToplevel {
|
||||
id: XdgToplevelId,
|
||||
surface: Rc<XdgSurface>,
|
||||
pub surface: Rc<XdgSurface>,
|
||||
version: u32,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue