1
0
Fork 0
forked from wry/wry

autocommit 2022-01-29 23:08:25 CET

This commit is contained in:
Julian Orth 2022-01-29 23:08:25 +01:00
parent 11d3604de4
commit f577f5feef
18 changed files with 484 additions and 173 deletions

View file

@ -28,6 +28,8 @@ use std::ops::Deref;
use std::rc::Rc;
pub use types::*;
use uapi::{c, OwnedFd};
use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup;
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
id!(WlSeatId);
@ -167,13 +169,17 @@ impl WlSeatGlobal {
self.toplevel_focus_stash
.borrow_mut()
.insert(toplevel.id, node);
self.focus_xdg_surface(&toplevel.xdg);
}
fn focus_xdg_surface(&self, xdg: &Rc<XdgSurface>) {
self.keyboard_node.get().unfocus(self);
let focus_surface;
if let Some(ss) = toplevel.focus_subsurface.get() {
if let Some(ss) = xdg.focus_subsurface.get() {
focus_surface = ss.surface.clone();
self.keyboard_node.set(ss);
} else {
focus_surface = toplevel.xdg.surface.clone();
focus_surface = xdg.surface.clone();
self.keyboard_node.set(focus_surface.clone());
}
self.focus_surface(&focus_surface);
@ -328,6 +334,10 @@ impl WlSeatGlobal {
self.focus_toplevel(n);
}
pub fn enter_popup(&self, n: &Rc<XdgPopup>) {
self.focus_xdg_surface(&n.xdg);
}
pub fn enter_surface(&self, n: &WlSurface, x: Fixed, y: Fixed) {
self.surface_pointer_event(0, n, |p| p.enter(0, n.id, x, y));
}

View file

@ -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(())
}

View file

@ -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);

View file

@ -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) {

View file

@ -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) {

View file

@ -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)]

View file

@ -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();
}
}

View file

@ -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 {

View file

@ -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>) {

View file

@ -3,10 +3,9 @@ mod types;
use crate::client::Client;
use crate::ifs::xdg_wm_base::XdgWmBaseObj;
use crate::object::{Interface, Object, ObjectId};
use crate::rect::Rect;
use crate::utils::buffd::MsgParser;
use bitflags::bitflags;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use std::cell::RefCell;
use std::rc::Rc;
pub use types::*;
@ -24,41 +23,41 @@ const SET_PARENT_CONFIGURE: u32 = 9;
const INVALID_INPUT: u32 = 0;
#[derive(Debug, Eq, PartialEq, Copy, Clone, FromPrimitive)]
pub enum Anchor {
None = 0,
Top = 1,
Bottom = 2,
Left = 3,
Right = 4,
TopLeft = 5,
BottomLeft = 6,
TopRight = 7,
BottomRight = 8,
}
const NONE: u32 = 0;
const TOP: u32 = 1;
const BOTTOM: u32 = 2;
const LEFT: u32 = 3;
const RIGHT: u32 = 4;
const TOP_LEFT: u32 = 5;
const BOTTOM_LEFT: u32 = 6;
const TOP_RIGHT: u32 = 7;
const BOTTOM_RIGHT: u32 = 8;
impl Default for Anchor {
fn default() -> Self {
Self::None
bitflags::bitflags! {
#[derive(Default)]
pub struct Square: u32 {
const TOP = 1 << 0;
const BOTTOM = 1 << 1;
const LEFT = 1 << 2;
const RIGHT = 1 << 3;
}
}
#[derive(Debug, Eq, PartialEq, Copy, Clone, FromPrimitive)]
pub enum Gravity {
None = 0,
Top = 1,
Bottom = 2,
Left = 3,
Right = 4,
TopLeft = 5,
BottomLeft = 6,
TopRight = 7,
BottomRight = 8,
}
impl Default for Gravity {
fn default() -> Self {
Self::None
impl Square {
fn from_enum(e: u32) -> Option<Self> {
let s = match e {
NONE => Square::empty(),
TOP => Square::TOP,
BOTTOM => Square::BOTTOM,
LEFT => Square::LEFT,
RIGHT => Square::RIGHT,
TOP_LEFT => Square::TOP | Square::LEFT,
BOTTOM_LEFT => Square::BOTTOM | Square::LEFT,
TOP_RIGHT => Square::TOP | Square::RIGHT,
BOTTOM_RIGHT => Square::BOTTOM | Square::RIGHT,
_ => return None,
};
Some(s)
}
}
@ -86,23 +85,61 @@ pub struct XdgPositioner {
#[derive(Copy, Clone, Debug, Default)]
pub struct XdgPositioned {
pub size_width: u32,
pub size_height: u32,
pub ar_x: i32,
pub ar_y: i32,
pub ar_width: u32,
pub ar_height: u32,
pub anchor: Anchor,
pub gravity: Gravity,
pub size_width: i32,
pub size_height: i32,
pub ar: Rect,
pub anchor: Square,
pub gravity: Square,
pub ca: CA,
pub off_x: i32,
pub off_y: i32,
pub reactive: bool,
pub parent_width: u32,
pub parent_height: u32,
pub parent_width: i32,
pub parent_height: i32,
pub parent_serial: u32,
}
impl XdgPositioned {
pub fn is_complete(&self) -> bool {
self.size_height != 0 && self.size_width != 0
}
pub fn get_position(&self) -> Rect {
let mut x1 = self.off_x;
let mut y1 = self.off_x;
if self.anchor.contains(Square::LEFT) {
x1 += self.ar.x1();
} else if self.anchor.contains(Square::RIGHT) {
x1 += self.ar.x2();
} else {
x1 += self.ar.x1() + self.ar.width() / 2;
}
if self.anchor.contains(Square::TOP) {
y1 += self.ar.y1();
} else if self.anchor.contains(Square::BOTTOM) {
y1 += self.ar.y2();
} else {
y1 += self.ar.y1() + self.ar.height() / 2;
}
if self.gravity.contains(Square::LEFT) {
x1 -= self.size_width;
} else if !self.gravity.contains(Square::RIGHT) {
x1 -= self.size_width / 2;
}
if self.gravity.contains(Square::TOP) {
y1 -= self.size_height;
} else if !self.gravity.contains(Square::BOTTOM) {
y1 -= self.size_height / 2;
}
Rect::new_sized(x1, y1, self.size_width, self.size_height).unwrap()
}
}
impl XdgPositioner {
pub fn new(base: &Rc<XdgWmBaseObj>, id: XdgPositionerId, client: &Rc<Client>) -> Self {
Self {
@ -113,9 +150,8 @@ impl XdgPositioner {
}
}
#[allow(dead_code)]
pub fn clone(&self) -> Box<XdgPositioned> {
Box::new(*self.position.borrow())
pub fn value(&self) -> XdgPositioned {
*self.position.borrow()
}
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
@ -135,8 +171,8 @@ impl XdgPositioner {
return Err(SetSizeError::NonPositiveSize);
}
let mut position = self.position.borrow_mut();
position.size_width = req.width as u32;
position.size_height = req.height as u32;
position.size_width = req.width;
position.size_height = req.height;
Ok(())
}
@ -151,16 +187,13 @@ impl XdgPositioner {
return Err(SetAnchorRectError::NegativeAnchorRect);
}
let mut position = self.position.borrow_mut();
position.ar_x = req.x;
position.ar_y = req.y;
position.ar_width = req.width as u32;
position.ar_height = req.height as u32;
position.ar = Rect::new_sized(req.x, req.y, req.width, req.height).unwrap();
Ok(())
}
fn set_anchor(&self, parser: MsgParser<'_, '_>) -> Result<(), SetAnchorError> {
let req: SetAnchor = self.client.parse(self, parser)?;
let anchor = match Anchor::from_u32(req.anchor) {
let anchor = match Square::from_enum(req.anchor) {
Some(a) => a,
_ => return Err(SetAnchorError::UnknownAnchor(req.anchor)),
};
@ -170,7 +203,7 @@ impl XdgPositioner {
fn set_gravity(&self, parser: MsgParser<'_, '_>) -> Result<(), SetGravityError> {
let req: SetGravity = self.client.parse(self, parser)?;
let gravity = match Gravity::from_u32(req.gravity) {
let gravity = match Square::from_enum(req.gravity) {
Some(a) => a,
_ => return Err(SetGravityError::UnknownGravity(req.gravity)),
};
@ -220,8 +253,8 @@ impl XdgPositioner {
return Err(SetParentSizeError::NegativeParentSize);
}
let mut position = self.position.borrow_mut();
position.parent_width = req.parent_width as u32;
position.parent_height = req.parent_height as u32;
position.parent_width = req.parent_width;
position.parent_height = req.parent_height;
Ok(())
}