1
0
Fork 0
forked from wry/wry

autocommit 2022-01-08 16:57:40 CET

This commit is contained in:
Julian Orth 2022-01-08 16:57:40 +01:00
parent f8e7557d1d
commit 33549184d4
42 changed files with 2072 additions and 190 deletions

View file

@ -60,13 +60,14 @@ impl SurfaceRole {
}
pub struct WlSurface {
id: WlSurfaceId,
pub id: WlSurfaceId,
pub client: Rc<Client>,
role: Cell<SurfaceRole>,
pending: PendingState,
input_region: Cell<Option<Region>>,
opaque_region: Cell<Option<Region>>,
pub extents: Cell<SurfaceExtents>,
pub effective_extents: Cell<SurfaceExtents>,
pub buffer: RefCell<Option<Rc<WlBuffer>>>,
pub children: RefCell<Option<Box<ParentData>>>,
role_data: RefCell<RoleData>,
@ -105,8 +106,15 @@ struct XdgSurfaceData {
requested_serial: u32,
acked_serial: Option<u32>,
role: XdgSurfaceRole,
extents: Option<SurfaceExtents>,
role_data: XdgSurfaceRoleData,
popups: CopyHashMap<WlSurfaceId, Rc<XdgPopup>>,
pending: PendingXdgSurfaceData,
}
#[derive(Default)]
struct PendingXdgSurfaceData {
extents: Cell<Option<SurfaceExtents>>,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -193,6 +201,7 @@ impl WlSurface {
input_region: Cell::new(None),
opaque_region: Cell::new(None),
extents: Default::default(),
effective_extents: Default::default(),
buffer: RefCell::new(None),
children: Default::default(),
role_data: RefCell::new(RoleData::None),
@ -350,7 +359,7 @@ impl WlSurface {
surface: td.toplevel.clone(),
});
td.node = Some(ToplevelNodeHolder { node: node.clone() });
let link = output.floating.append(node.clone());
let link = output.floating.add_last(node.clone());
node.common
.floating_outputs
.borrow_mut()
@ -402,6 +411,8 @@ impl WlSurface {
}
fn do_commit(&self) {
let mut xdg_extents = None;
let mut td_node = None;
{
let mut rd = self.role_data.borrow_mut();
match &mut *rd {
@ -416,7 +427,15 @@ impl WlSurface {
ss.y = y;
}
}
RoleData::XdgSurface(xdg) => {}
RoleData::XdgSurface(xdg) => {
if let Some(extents) = xdg.pending.extents.take() {
xdg.extents = Some(extents);
}
xdg_extents = xdg.extents;
if let XdgSurfaceRoleData::Toplevel(tl) = &xdg.role_data {
td_node = tl.node.as_ref().map(|n| n.node.clone());
}
}
}
}
{
@ -444,6 +463,28 @@ impl WlSurface {
if !committed_any_children {
self.calculate_extents();
}
let mut effective_extents = self.extents.get();
if let Some(extents) = xdg_extents {
effective_extents.x1 = effective_extents.x1.max(extents.x1);
effective_extents.y1 = effective_extents.y1.max(extents.y1);
effective_extents.x2 = effective_extents.x2.min(extents.x2);
effective_extents.y2 = effective_extents.y2.min(extents.y2);
if effective_extents.x1 > effective_extents.x2 {
effective_extents.x1 = 0;
effective_extents.x2 = 0;
}
if effective_extents.y1 > effective_extents.y2 {
effective_extents.y1 = 0;
effective_extents.y2 = 0;
}
}
if let Some(node) = td_node {
let mut td_extents = node.common.extents.get();
td_extents.width = (effective_extents.x2 - effective_extents.x1) as u32;
td_extents.height = (effective_extents.y2 - effective_extents.y1) as u32;
node.common.extents.set(td_extents);
}
self.effective_extents.set(effective_extents);
}
async fn commit(&self, parser: MsgParser<'_, '_>) -> Result<(), CommitError> {

View file

@ -112,7 +112,7 @@ impl WlSubsurface {
let data = data.get_or_insert_with(|| Default::default());
data.subsurfaces
.insert(self.surface.id, self.surface.clone());
data.above.prepend(StackElement {
data.above.add_first(StackElement {
pending: Cell::new(true),
surface: self.surface.clone(),
})
@ -168,8 +168,8 @@ impl WlSubsurface {
};
if sibling == self.parent.id {
let node = match above {
true => pdata.above.prepend(element),
_ => pdata.below.append(element),
true => pdata.above.add_first(element),
_ => pdata.below.add_last(element),
};
data.pending.node = Some(node);
} else {

View file

@ -6,7 +6,7 @@ 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::{
RoleData, SurfaceRole, WlSurface, XdgPopupData, XdgSurfaceData, XdgSurfaceRole,
RoleData, SurfaceExtents, SurfaceRole, WlSurface, XdgPopupData, XdgSurfaceData, XdgSurfaceRole,
XdgSurfaceRoleData, XdgToplevelData,
};
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
@ -73,8 +73,10 @@ impl XdgSurface {
requested_serial: 0,
acked_serial: None,
role: XdgSurfaceRole::None,
extents: None,
role_data: XdgSurfaceRoleData::None,
popups: Default::default(),
pending: Default::default(),
}));
Ok(())
}
@ -176,7 +178,20 @@ impl XdgSurface {
&self,
parser: MsgParser<'_, '_>,
) -> Result<(), SetWindowGeometryError> {
let _req: SetWindowGeometry = self.surface.client.parse(self, parser)?;
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));
}
Ok(())
}

View file

@ -74,6 +74,8 @@ pub enum SetWindowGeometryError {
ParseFailed(#[source] Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Tried no set a non-positive width/height")]
NonPositiveWidthHeight,
}
efrom!(SetWindowGeometryError, ParseFailed, MsgParserError);
efrom!(SetWindowGeometryError, ClientError, ClientError);

View file

@ -5,6 +5,7 @@ use crate::ifs::wl_surface::{RoleData, XdgSurfaceRoleData};
use crate::object::{Interface, Object, ObjectId};
use crate::utils::buffd::MsgParser;
use num_derive::FromPrimitive;
use std::ops::Deref;
use std::rc::Rc;
pub use types::*;
@ -97,7 +98,16 @@ impl XdgToplevel {
}
async fn move_(&self, parser: MsgParser<'_, '_>) -> Result<(), MoveError> {
let _req: Move = self.surface.surface.client.parse(self, parser)?;
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);
}
}
}
Ok(())
}