autocommit 2022-01-29 23:08:25 CET
This commit is contained in:
parent
11d3604de4
commit
f577f5feef
18 changed files with 484 additions and 173 deletions
|
|
@ -102,9 +102,9 @@ enum CommitAction {
|
|||
}
|
||||
|
||||
trait SurfaceExt {
|
||||
fn pre_commit(self: Rc<Self>, ctx: CommitContext) -> CommitAction {
|
||||
fn pre_commit(self: Rc<Self>, ctx: CommitContext) -> Result<CommitAction, WlSurfaceError> {
|
||||
let _ = ctx;
|
||||
CommitAction::ContinueCommit
|
||||
Ok(CommitAction::ContinueCommit)
|
||||
}
|
||||
|
||||
fn post_commit(&self) {
|
||||
|
|
@ -147,8 +147,8 @@ impl SurfaceExt for NoneSurfaceExt {
|
|||
#[derive(Default)]
|
||||
struct PendingState {
|
||||
buffer: Cell<Option<Option<(i32, i32, Rc<WlBuffer>)>>>,
|
||||
opaque_region: Cell<Option<Region>>,
|
||||
input_region: Cell<Option<Region>>,
|
||||
opaque_region: Cell<Option<Option<Region>>>,
|
||||
input_region: Cell<Option<Option<Region>>>,
|
||||
frame_request: RefCell<Vec<Rc<WlCallback>>>,
|
||||
}
|
||||
|
||||
|
|
@ -306,28 +306,36 @@ impl WlSurface {
|
|||
|
||||
fn set_opaque_region(&self, parser: MsgParser<'_, '_>) -> Result<(), SetOpaqueRegionError> {
|
||||
let region: SetOpaqueRegion = self.parse(parser)?;
|
||||
let region = self.client.get_region(region.region)?;
|
||||
self.pending.opaque_region.set(Some(region.region()));
|
||||
let region = if region.region.is_some() {
|
||||
Some(self.client.get_region(region.region)?.region())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.pending.opaque_region.set(Some(region));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_input_region(&self, parser: MsgParser<'_, '_>) -> Result<(), SetInputRegionError> {
|
||||
let req: SetInputRegion = self.parse(parser)?;
|
||||
let region = self.client.get_region(req.region)?;
|
||||
self.pending.input_region.set(Some(region.region()));
|
||||
let region = if req.region.is_some() {
|
||||
Some(self.client.get_region(req.region)?.region())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.pending.input_region.set(Some(region));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn do_commit(&self, ctx: CommitContext) {
|
||||
fn do_commit(&self, ctx: CommitContext) -> Result<(), WlSurfaceError> {
|
||||
let ext = self.ext.get();
|
||||
if ext.clone().pre_commit(ctx) == CommitAction::AbortCommit {
|
||||
return;
|
||||
if ext.clone().pre_commit(ctx)? == CommitAction::AbortCommit {
|
||||
return Ok(());
|
||||
}
|
||||
{
|
||||
let children = self.children.borrow();
|
||||
if let Some(children) = children.deref() {
|
||||
for child in children.subsurfaces.values() {
|
||||
child.surface.do_commit(CommitContext::ChildCommit);
|
||||
child.surface.do_commit(CommitContext::ChildCommit)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -362,21 +370,22 @@ impl WlSurface {
|
|||
}
|
||||
{
|
||||
if let Some(region) = self.pending.input_region.take() {
|
||||
self.input_region.set(Some(region));
|
||||
self.input_region.set(region);
|
||||
}
|
||||
if let Some(region) = self.pending.opaque_region.take() {
|
||||
self.opaque_region.set(Some(region));
|
||||
self.opaque_region.set(region);
|
||||
}
|
||||
}
|
||||
if self.need_extents_update.get() {
|
||||
self.calculate_extents();
|
||||
}
|
||||
ext.post_commit();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn commit(&self, parser: MsgParser<'_, '_>) -> Result<(), CommitError> {
|
||||
let _req: Commit = self.parse(parser)?;
|
||||
self.do_commit(CommitContext::RootCommit);
|
||||
self.do_commit(CommitContext::RootCommit)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@ use crate::ifs::wl_surface::{SurfaceRole, WlSurfaceId};
|
|||
use crate::utils::buffd::{MsgParser, MsgParserError};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use thiserror::Error;
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurfaceError;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlSurfaceError {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error(transparent)]
|
||||
XdgSurfaceError(Box<XdgSurfaceError>),
|
||||
#[error("Could not process `destroy` request")]
|
||||
DestroyError(#[source] Box<DestroyError>),
|
||||
#[error("Could not process `attach` request")]
|
||||
|
|
@ -38,6 +41,7 @@ pub enum WlSurfaceError {
|
|||
},
|
||||
}
|
||||
efrom!(WlSurfaceError, ClientError);
|
||||
efrom!(WlSurfaceError, XdgSurfaceError);
|
||||
efrom!(WlSurfaceError, DestroyError);
|
||||
efrom!(WlSurfaceError, AttachError);
|
||||
efrom!(WlSurfaceError, DamageError);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ mod types;
|
|||
use crate::backend::{KeyState, ScrollAxis};
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::WlSeatGlobal;
|
||||
use crate::ifs::wl_surface::{
|
||||
CommitAction, CommitContext, StackElement, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceId,
|
||||
};
|
||||
use crate::ifs::wl_surface::{CommitAction, CommitContext, StackElement, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError, WlSurfaceId};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::rect::Rect;
|
||||
use crate::tree::{Node, NodeId};
|
||||
|
|
@ -279,12 +277,12 @@ impl Object for WlSubsurface {
|
|||
}
|
||||
|
||||
impl SurfaceExt for WlSubsurface {
|
||||
fn pre_commit(self: Rc<Self>, ctx: CommitContext) -> CommitAction {
|
||||
fn pre_commit(self: Rc<Self>, ctx: CommitContext) -> Result<CommitAction, WlSurfaceError> {
|
||||
if ctx == CommitContext::RootCommit && self.sync() {
|
||||
log::info!("Aborting commit due to sync");
|
||||
return CommitAction::AbortCommit;
|
||||
return Ok(CommitAction::AbortCommit);
|
||||
}
|
||||
CommitAction::ContinueCommit
|
||||
Ok(CommitAction::ContinueCommit)
|
||||
}
|
||||
|
||||
fn post_commit(&self) {
|
||||
|
|
|
|||
|
|
@ -5,18 +5,20 @@ pub mod xdg_toplevel;
|
|||
use crate::client::DynEventFormatter;
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{XdgPopup, XdgPopupId};
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel;
|
||||
use crate::ifs::wl_surface::{CommitAction, CommitContext, SurfaceExt, SurfaceRole, WlSurface};
|
||||
use crate::ifs::wl_surface::{CommitAction, CommitContext, SurfaceExt, SurfaceRole, WlSurface, WlSurfaceError};
|
||||
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::rect::Rect;
|
||||
use crate::tree::Node;
|
||||
use crate::tree::{FoundNode, Node};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
use crate::utils::copyhashmap::CopyHashMap;
|
||||
use crate::NumCell;
|
||||
use std::cell::Cell;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const GET_TOPLEVEL: u32 = 1;
|
||||
|
|
@ -42,9 +44,11 @@ pub struct XdgSurface {
|
|||
acked_serial: Cell<Option<u32>>,
|
||||
geometry: Cell<Option<Rect>>,
|
||||
extents: Cell<Rect>,
|
||||
pub absolute_desired_extents: Cell<Rect>,
|
||||
ext: CloneCell<Option<Rc<dyn XdgSurfaceExt>>>,
|
||||
popups: CopyHashMap<XdgPopupId, Rc<XdgPopup>>,
|
||||
pending: PendingXdgSurfaceData,
|
||||
pub focus_subsurface: CloneCell<Option<Rc<WlSubsurface>>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -53,12 +57,8 @@ struct PendingXdgSurfaceData {
|
|||
}
|
||||
|
||||
trait XdgSurfaceExt {
|
||||
fn initial_configure(self: Rc<Self>) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
fn pre_commit(self: Rc<Self>) {
|
||||
// nothing
|
||||
fn initial_configure(self: Rc<Self>) -> Result<(), XdgSurfaceError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn post_commit(self: Rc<Self>) {
|
||||
|
|
@ -84,9 +84,11 @@ impl XdgSurface {
|
|||
acked_serial: Cell::new(None),
|
||||
geometry: Cell::new(None),
|
||||
extents: Cell::new(Default::default()),
|
||||
absolute_desired_extents: Cell::new(Default::default()),
|
||||
ext: Default::default(),
|
||||
popups: Default::default(),
|
||||
pending: Default::default(),
|
||||
focus_subsurface: Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,8 +124,8 @@ impl XdgSurface {
|
|||
}
|
||||
{
|
||||
let children = self.popups.lock();
|
||||
for child in children.values() {
|
||||
child.parent.set(None);
|
||||
if !children.is_empty() {
|
||||
return Err(DestroyError::PopupsNotYetDestroyed);
|
||||
}
|
||||
}
|
||||
self.surface.unset_ext();
|
||||
|
|
@ -159,6 +161,7 @@ impl XdgSurface {
|
|||
if req.parent.is_some() {
|
||||
parent = Some(self.surface.client.get_xdg_surface(req.parent)?);
|
||||
}
|
||||
let positioner = self.surface.client.get_xdg_positioner(req.positioner)?;
|
||||
if self.ext.get().is_some() {
|
||||
self.surface.client.protocol_error(
|
||||
&**self,
|
||||
|
|
@ -170,7 +173,7 @@ impl XdgSurface {
|
|||
);
|
||||
return Err(GetPopupError::AlreadyConstructed);
|
||||
}
|
||||
let popup = Rc::new(XdgPopup::new(req.id, self, parent.as_ref()));
|
||||
let popup = Rc::new(XdgPopup::new(req.id, self, parent.as_ref(), &positioner)?);
|
||||
self.surface.client.add_client_obj(&popup)?;
|
||||
if let Some(parent) = &parent {
|
||||
parent.popups.set(req.id, popup.clone());
|
||||
|
|
@ -226,6 +229,35 @@ impl XdgSurface {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn find_child_at(&self, mut x: i32, mut y: i32) -> Option<FoundNode> {
|
||||
if let Some(geo) = self.geometry.get() {
|
||||
let (xt, yt) = geo.translate_inv(x, y);
|
||||
x = xt;
|
||||
y = yt;
|
||||
}
|
||||
match self.surface.find_surface_at(x, y) {
|
||||
Some((node, x, y)) => Some(FoundNode {
|
||||
node: if std::ptr::eq(node.deref(), self.surface.deref()) {
|
||||
node
|
||||
} else {
|
||||
node.ext.get().into_node().unwrap()
|
||||
},
|
||||
x,
|
||||
y,
|
||||
contained: true,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn update_popup_positions(&self) {
|
||||
let popups = self.popups.lock();
|
||||
for popup in popups.values() {
|
||||
popup.update_absolute_position();
|
||||
popup.xdg.update_popup_positions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(XdgSurface);
|
||||
|
|
@ -242,17 +274,21 @@ impl Object for XdgSurface {
|
|||
fn num_requests(&self) -> u32 {
|
||||
ACK_CONFIGURE + 1
|
||||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.focus_subsurface.set(None);
|
||||
}
|
||||
}
|
||||
|
||||
impl SurfaceExt for XdgSurface {
|
||||
fn pre_commit(self: Rc<Self>, _ctx: CommitContext) -> CommitAction {
|
||||
fn pre_commit(self: Rc<Self>, _ctx: CommitContext) -> Result<CommitAction, WlSurfaceError> {
|
||||
{
|
||||
let ase = self.acked_serial.get();
|
||||
let rse = self.requested_serial.get();
|
||||
if ase != Some(rse) {
|
||||
if ase.is_none() {
|
||||
if let Some(ext) = self.ext.get() {
|
||||
ext.initial_configure();
|
||||
ext.initial_configure()?;
|
||||
}
|
||||
self.surface.client.event(self.configure(rse));
|
||||
}
|
||||
|
|
@ -263,7 +299,7 @@ impl SurfaceExt for XdgSurface {
|
|||
self.geometry.set(Some(geometry));
|
||||
self.update_extents();
|
||||
}
|
||||
CommitAction::ContinueCommit
|
||||
Ok(CommitAction::ContinueCommit)
|
||||
}
|
||||
|
||||
fn post_commit(&self) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopupId;
|
||||
use crate::ifs::wl_surface::xdg_surface::xdg_popup::{XdgPopupError, 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::{WlSurfaceError, WlSurfaceId};
|
||||
|
|
@ -26,6 +26,8 @@ pub enum XdgSurfaceError {
|
|||
AlreadyAttached(WlSurfaceId),
|
||||
#[error(transparent)]
|
||||
WlSurfaceError(Box<WlSurfaceError>),
|
||||
#[error(transparent)]
|
||||
XdgPopupError(#[from] XdgPopupError),
|
||||
}
|
||||
efrom!(XdgSurfaceError, WlSurfaceError);
|
||||
|
||||
|
|
@ -37,6 +39,8 @@ pub enum DestroyError {
|
|||
ClientError(Box<ClientError>),
|
||||
#[error("Cannot destroy xdg_surface {0} because it's associated xdg_toplevel/popup is not yet destroyed")]
|
||||
RoleNotYetDestroyed(XdgSurfaceId),
|
||||
#[error("The surface still has popups attached")]
|
||||
PopupsNotYetDestroyed,
|
||||
}
|
||||
efrom!(DestroyError, ParseFailed, MsgParserError);
|
||||
efrom!(DestroyError, ClientError);
|
||||
|
|
@ -66,9 +70,12 @@ pub enum GetPopupError {
|
|||
AlreadyConstructed,
|
||||
#[error(transparent)]
|
||||
WlSurfaceError(Box<WlSurfaceError>),
|
||||
#[error(transparent)]
|
||||
XdgPopupError(Box<XdgPopupError>),
|
||||
}
|
||||
efrom!(GetPopupError, ParseFailed, MsgParserError);
|
||||
efrom!(GetPopupError, ClientError);
|
||||
efrom!(GetPopupError, XdgPopupError);
|
||||
efrom!(GetPopupError, WlSurfaceError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
|
|||
|
|
@ -1,12 +1,21 @@
|
|||
mod types;
|
||||
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceExt};
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt};
|
||||
use crate::ifs::xdg_positioner::{XdgPositioned, XdgPositioner};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::tree::{Node, NodeId};
|
||||
use crate::rect::Rect;
|
||||
use crate::tree::{FoundNode, Node, NodeId, StackedNode, WorkspaceNode};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::client::DynEventFormatter;
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::WlSeatGlobal;
|
||||
use crate::ifs::wl_surface::SurfaceExt;
|
||||
use crate::render::Renderer;
|
||||
use crate::utils::linkedlist::LinkedNode;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const GRAB: u32 = 1;
|
||||
|
|
@ -25,17 +34,75 @@ id!(XdgPopupId);
|
|||
pub struct XdgPopup {
|
||||
id: XdgPopupId,
|
||||
node_id: PopupId,
|
||||
pub(in super::super) xdg: Rc<XdgSurface>,
|
||||
pub xdg: Rc<XdgSurface>,
|
||||
pub(super) parent: CloneCell<Option<Rc<XdgSurface>>>,
|
||||
relative_position: Cell<Rect>,
|
||||
display_link: RefCell<Option<LinkedNode<StackedNode>>>,
|
||||
workspace_link: RefCell<Option<LinkedNode<StackedNode>>>,
|
||||
pos: RefCell<XdgPositioned>,
|
||||
}
|
||||
|
||||
impl XdgPopup {
|
||||
pub fn new(id: XdgPopupId, xdg: &Rc<XdgSurface>, parent: Option<&Rc<XdgSurface>>) -> Self {
|
||||
Self {
|
||||
pub fn new(
|
||||
id: XdgPopupId,
|
||||
xdg: &Rc<XdgSurface>,
|
||||
parent: Option<&Rc<XdgSurface>>,
|
||||
pos: &Rc<XdgPositioner>,
|
||||
) -> Result<Self, XdgPopupError> {
|
||||
let pos = pos.value();
|
||||
if !pos.is_complete() {
|
||||
return Err(XdgPopupError::Incomplete);
|
||||
}
|
||||
Ok(Self {
|
||||
id,
|
||||
node_id: xdg.surface.client.state.node_ids.next(),
|
||||
xdg: xdg.clone(),
|
||||
parent: CloneCell::new(parent.cloned()),
|
||||
relative_position: Cell::new(Default::default()),
|
||||
display_link: RefCell::new(None),
|
||||
workspace_link: RefCell::new(None),
|
||||
pos: RefCell::new(pos),
|
||||
})
|
||||
}
|
||||
|
||||
fn configure(self: &Rc<Self>, x: i32, y: i32, width: i32, height: i32) -> DynEventFormatter {
|
||||
Box::new(Configure {
|
||||
obj: self.clone(),
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
})
|
||||
}
|
||||
|
||||
fn repositioned(self: &Rc<Self>, token: u32) -> DynEventFormatter {
|
||||
Box::new(Repositioned {
|
||||
obj: self.clone(),
|
||||
token,
|
||||
})
|
||||
}
|
||||
|
||||
fn popup_done(self: &Rc<Self>) -> DynEventFormatter {
|
||||
Box::new(PopupDone {
|
||||
obj: self.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
fn update_relative_position(&self, parent: &XdgSurface) -> Result<(), XdgPopupError> {
|
||||
let parent = parent.extents.get();
|
||||
let positioner = self.pos.borrow();
|
||||
if !parent.contains_rect(&positioner.ar) {
|
||||
// return Err(XdgPopupError::AnchorRectOutside);
|
||||
}
|
||||
self.relative_position.set(positioner.get_position());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_absolute_position(&self) {
|
||||
if let Some(parent) = self.parent.get() {
|
||||
let rel = self.relative_position.get();
|
||||
let parent = parent.absolute_desired_extents.get();
|
||||
self.xdg.absolute_desired_extents.set(rel.move_(parent.x1(), parent.y1()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +115,9 @@ impl XdgPopup {
|
|||
}
|
||||
self.xdg.ext.set(None);
|
||||
self.xdg.surface.client.remove_obj(self)?;
|
||||
self.clear();
|
||||
*self.display_link.borrow_mut() = None;
|
||||
*self.workspace_link.borrow_mut() = None;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -56,13 +126,23 @@ impl XdgPopup {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn reposition(&self, parser: MsgParser<'_, '_>) -> Result<(), RepositionError> {
|
||||
let _req: Reposition = self.xdg.surface.client.parse(self, parser)?;
|
||||
fn reposition(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), RepositionError> {
|
||||
let req: Reposition = self.xdg.surface.client.parse(&**self, parser)?;
|
||||
*self.pos.borrow_mut() = self.xdg.surface.client.get_xdg_positioner(req.positioner)?.value();
|
||||
if let Some(parent) = self.parent.get() {
|
||||
self.update_relative_position(&parent)?;
|
||||
let rel = self.relative_position.get();
|
||||
self.xdg.surface.client.event(self.repositioned(req.token));
|
||||
self.xdg.surface.client.event(self.configure(rel.x1(), rel.y1(), rel.width(), rel.height()));
|
||||
self.xdg.send_configure();
|
||||
let parent = parent.absolute_desired_extents.get();
|
||||
self.xdg.absolute_desired_extents.set(rel.move_(parent.x1(), parent.y1()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_request_(
|
||||
&self,
|
||||
self: &Rc<Self>,
|
||||
request: u32,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), XdgPopupError> {
|
||||
|
|
@ -90,12 +170,83 @@ impl Object for XdgPopup {
|
|||
fn num_requests(&self) -> u32 {
|
||||
REPOSITION + 1
|
||||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.parent.set(None);
|
||||
self.clear();
|
||||
*self.display_link.borrow_mut() = None;
|
||||
*self.workspace_link.borrow_mut() = None;
|
||||
}
|
||||
}
|
||||
|
||||
impl Node for XdgPopup {
|
||||
fn id(&self) -> NodeId {
|
||||
self.node_id.into()
|
||||
}
|
||||
|
||||
fn clear(&self) {
|
||||
let _v = self.display_link.borrow_mut().take();
|
||||
let _v = self.workspace_link.borrow_mut().take();
|
||||
}
|
||||
|
||||
fn find_child_at(&self, x: i32, y: i32) -> Option<FoundNode> {
|
||||
self.xdg.find_child_at(x, y)
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &WlSeatGlobal, _x: Fixed, _y: Fixed) {
|
||||
seat.enter_popup(&self);
|
||||
}
|
||||
|
||||
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
|
||||
renderer.render_xdg_surface(&self.xdg, x, y)
|
||||
}
|
||||
|
||||
fn get_workspace(self: Rc<Self>) -> Option<Rc<WorkspaceNode>> {
|
||||
self.parent.get()?.into_node()?.get_workspace()
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurfaceExt for XdgPopup {}
|
||||
impl XdgSurfaceExt for XdgPopup {
|
||||
fn initial_configure(self: Rc<Self>) -> Result<(), XdgSurfaceError> {
|
||||
if let Some(parent) = self.parent.get() {
|
||||
self.update_relative_position(&parent)?;
|
||||
let rel = self.relative_position.get();
|
||||
self.xdg.surface.client.event(self.configure(rel.x1(), rel.y1(), rel.width(), rel.height()));
|
||||
let parent = parent.absolute_desired_extents.get();
|
||||
self.xdg.absolute_desired_extents.set(rel.move_(parent.x1(), parent.y1()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn post_commit(self: Rc<Self>) {
|
||||
let mut wl = self.workspace_link.borrow_mut();
|
||||
let mut dl = self.display_link.borrow_mut();
|
||||
let ws = match self.clone().get_workspace() {
|
||||
Some(ws) => ws,
|
||||
_ => return,
|
||||
};
|
||||
let surface = &self.xdg.surface;
|
||||
let state = &surface.client.state;
|
||||
if surface.buffer.get().is_some() {
|
||||
if wl.is_none() {
|
||||
*wl = Some(ws.stacked.add_last(StackedNode::Popup(self.clone())));
|
||||
*dl = Some(state.root.stacked.add_last(StackedNode::Popup(self.clone())));
|
||||
state.tree_changed();
|
||||
}
|
||||
} else {
|
||||
if wl.take().is_some() {
|
||||
*dl = None;
|
||||
state.tree_changed();
|
||||
surface.client.event(self.popup_done());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn extents_changed(&self) {
|
||||
self.xdg.surface.client.state.tree_changed();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ pub enum XdgPopupError {
|
|||
GrabError(#[from] GrabError),
|
||||
#[error("Could not process `reposition` request")]
|
||||
RepositionError(#[from] RepositionError),
|
||||
#[error("The `xdg_positioner` is incomplete")]
|
||||
Incomplete,
|
||||
#[error("The anchor rectangle of the `xdg_positioner` extends outside the parent")]
|
||||
AnchorRectOutside,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
@ -46,9 +50,12 @@ pub enum RepositionError {
|
|||
ParseFailed(#[source] Box<MsgParserError>),
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error(transparent)]
|
||||
XdgPopupError(Box<XdgPopupError>),
|
||||
}
|
||||
efrom!(RepositionError, ParseFailed, MsgParserError);
|
||||
efrom!(RepositionError, ClientError);
|
||||
efrom!(RepositionError, XdgPopupError);
|
||||
|
||||
pub(super) struct Destroy;
|
||||
impl RequestParser<'_> for Destroy {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ mod types;
|
|||
use crate::client::DynEventFormatter;
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::WlSeatGlobal;
|
||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceExt};
|
||||
use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt};
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::rect::Rect;
|
||||
use crate::render::Renderer;
|
||||
use crate::tree::ContainerNode;
|
||||
use crate::tree::{ContainerNode, StackedNode};
|
||||
use crate::tree::{FloatNode, FoundNode, Node, NodeId, ToplevelNodeId, WorkspaceNode};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
|
|
@ -77,7 +76,6 @@ pub struct XdgToplevel {
|
|||
pub parent_node: CloneCell<Option<Rc<dyn Node>>>,
|
||||
pub parent: CloneCell<Option<Rc<XdgToplevel>>>,
|
||||
pub children: RefCell<AHashMap<XdgToplevelId, Rc<XdgToplevel>>>,
|
||||
pub focus_subsurface: CloneCell<Option<Rc<WlSubsurface>>>,
|
||||
states: RefCell<AHashSet<u32>>,
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +93,6 @@ impl XdgToplevel {
|
|||
parent_node: Default::default(),
|
||||
parent: Default::default(),
|
||||
children: RefCell::new(Default::default()),
|
||||
focus_subsurface: Default::default(),
|
||||
states: RefCell::new(states),
|
||||
}
|
||||
}
|
||||
|
|
@ -262,10 +259,10 @@ impl XdgToplevel {
|
|||
self.parent_node.set(Some(floater.clone()));
|
||||
floater
|
||||
.display_link
|
||||
.set(Some(state.root.floaters.add_last(floater.clone())));
|
||||
.set(Some(state.root.stacked.add_last(StackedNode::Float(floater.clone()))));
|
||||
floater
|
||||
.workspace_link
|
||||
.set(Some(workspace.floaters.add_last(floater.clone())));
|
||||
.set(Some(workspace.stacked.add_last(StackedNode::Float(floater.clone()))));
|
||||
}
|
||||
|
||||
fn map_tiled(self: &Rc<Self>) {
|
||||
|
|
@ -333,7 +330,6 @@ impl Object for XdgToplevel {
|
|||
}
|
||||
self.parent.set(None);
|
||||
let _children = mem::take(&mut *self.children.borrow_mut());
|
||||
self.focus_subsurface.set(None);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -346,29 +342,12 @@ impl Node for XdgToplevel {
|
|||
self.parent_node.set(None);
|
||||
}
|
||||
|
||||
fn find_child_at(&self, mut x: i32, mut y: i32) -> Option<FoundNode> {
|
||||
if let Some(geo) = self.xdg.geometry.get() {
|
||||
let (xt, yt) = geo.translate_inv(x, y);
|
||||
x = xt;
|
||||
y = yt;
|
||||
}
|
||||
match self.xdg.surface.find_surface_at(x, y) {
|
||||
Some((node, x, y)) => Some(FoundNode {
|
||||
node: if std::ptr::eq(node.deref(), self.xdg.surface.deref()) {
|
||||
node
|
||||
} else {
|
||||
node.ext.get().into_node().unwrap()
|
||||
},
|
||||
x,
|
||||
y,
|
||||
contained: true,
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
fn find_child_at(&self, x: i32, y: i32) -> Option<FoundNode> {
|
||||
self.xdg.find_child_at(x, y)
|
||||
}
|
||||
|
||||
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
|
||||
renderer.render_toplevel(self, x, y)
|
||||
renderer.render_xdg_surface(&self.xdg, x, y)
|
||||
}
|
||||
|
||||
fn get_workspace(self: Rc<Self>) -> Option<Rc<WorkspaceNode>> {
|
||||
|
|
@ -379,16 +358,23 @@ impl Node for XdgToplevel {
|
|||
seat.enter_toplevel(&self);
|
||||
}
|
||||
|
||||
fn change_size(self: Rc<Self>, width: i32, height: i32) {
|
||||
self.xdg.surface.client.event(self.configure(width, height));
|
||||
self.xdg.send_configure();
|
||||
self.xdg.surface.client.flush();
|
||||
fn change_extents(self: Rc<Self>, rect: &Rect) {
|
||||
let de = self.xdg.absolute_desired_extents.replace(*rect);
|
||||
if de.width() != rect.width() || de.height() != rect.height() {
|
||||
self.xdg.surface.client.event(self.configure(rect.width(), rect.height()));
|
||||
self.xdg.send_configure();
|
||||
self.xdg.surface.client.flush();
|
||||
}
|
||||
if de.x1() != rect.x1() || de.y1() != rect.y1() {
|
||||
self.xdg.update_popup_positions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurfaceExt for XdgToplevel {
|
||||
fn initial_configure(self: Rc<Self>) {
|
||||
fn initial_configure(self: Rc<Self>) -> Result<(), XdgSurfaceError> {
|
||||
self.xdg.surface.client.event(self.configure(0, 0));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn post_commit(self: Rc<Self>) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue