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
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue