autocommit 2022-01-30 22:41:40 CET
This commit is contained in:
parent
f577f5feef
commit
865d5f295d
26 changed files with 1085 additions and 676 deletions
|
|
@ -7,7 +7,7 @@ use crate::client::{Client, RequestParser};
|
|||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_buffer::WlBuffer;
|
||||
use crate::ifs::wl_callback::WlCallback;
|
||||
use crate::ifs::wl_seat::WlSeatGlobal;
|
||||
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
|
||||
use crate::ifs::wl_surface::wl_subsurface::WlSubsurface;
|
||||
use crate::object::{Interface, Object, ObjectId};
|
||||
use crate::pixman::Region;
|
||||
|
|
@ -23,6 +23,7 @@ use std::mem;
|
|||
use std::ops::{Deref, DerefMut};
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurface;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const ATTACH: u32 = 1;
|
||||
|
|
@ -54,8 +55,6 @@ pub enum SurfaceRole {
|
|||
None,
|
||||
Subsurface,
|
||||
XdgSurface,
|
||||
XdgPopup,
|
||||
XdgToplevel,
|
||||
}
|
||||
|
||||
impl SurfaceRole {
|
||||
|
|
@ -64,8 +63,6 @@ impl SurfaceRole {
|
|||
SurfaceRole::None => "none",
|
||||
SurfaceRole::Subsurface => "subsurface",
|
||||
SurfaceRole::XdgSurface => "xdg_surface",
|
||||
SurfaceRole::XdgPopup => "xdg_popup",
|
||||
SurfaceRole::XdgToplevel => "xdg_toplevel",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -87,6 +84,8 @@ pub struct WlSurface {
|
|||
pub children: RefCell<Option<Box<ParentData>>>,
|
||||
ext: CloneCell<Rc<dyn SurfaceExt>>,
|
||||
pub frame_requests: RefCell<Vec<Rc<WlCallback>>>,
|
||||
seat_state: NodeSeatState,
|
||||
xdg: CloneCell<Option<Rc<XdgSurface>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
|
|
@ -130,10 +129,6 @@ trait SurfaceExt {
|
|||
fn into_subsurface(self: Rc<Self>) -> Option<Rc<WlSubsurface>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NoneSurfaceExt;
|
||||
|
|
@ -183,16 +178,26 @@ impl WlSurface {
|
|||
children: Default::default(),
|
||||
ext: CloneCell::new(client.state.none_surface_ext.clone()),
|
||||
frame_requests: RefCell::new(vec![]),
|
||||
seat_state: Default::default(),
|
||||
xdg: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_xdg_surface(&self, xdg: Option<Rc<XdgSurface>>) {
|
||||
let ch = self.children.borrow();
|
||||
if let Some(ch) = &*ch {
|
||||
for ss in ch.subsurfaces.values() {
|
||||
ss.surface.set_xdg_surface(xdg.clone());
|
||||
}
|
||||
}
|
||||
self.xdg.set(xdg);
|
||||
}
|
||||
|
||||
fn set_role(&self, role: SurfaceRole) -> Result<(), WlSurfaceError> {
|
||||
use SurfaceRole::*;
|
||||
match (self.role.get(), role) {
|
||||
(None, _) => {}
|
||||
(old, new) if old == new => {}
|
||||
(XdgSurface, XdgPopup) => {}
|
||||
(XdgSurface, XdgToplevel) => {}
|
||||
(old, new) => {
|
||||
return Err(WlSurfaceError::IncompatibleRole {
|
||||
id: self.id,
|
||||
|
|
@ -258,6 +263,7 @@ impl WlSurface {
|
|||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.parse(parser)?;
|
||||
self.destroy_node(true);
|
||||
if self.ext.get().is_some() {
|
||||
return Err(DestroyError::ReloObjectStillExists);
|
||||
}
|
||||
|
|
@ -488,10 +494,12 @@ impl Object for WlSurface {
|
|||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.destroy_node(true);
|
||||
*self.children.borrow_mut() = None;
|
||||
self.unset_ext();
|
||||
mem::take(self.frame_requests.borrow_mut().deref_mut());
|
||||
self.buffer.set(None);
|
||||
self.xdg.set(None);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -501,31 +509,58 @@ impl Node for WlSurface {
|
|||
self.node_id.into()
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &WlSeatGlobal, x: Fixed, y: Fixed) {
|
||||
seat.enter_surface(&self, x, y)
|
||||
fn seat_state(&self) -> &NodeSeatState {
|
||||
&self.seat_state
|
||||
}
|
||||
|
||||
fn leave(&self, seat: &WlSeatGlobal) {
|
||||
seat.leave_surface(self);
|
||||
fn destroy_node(&self, _detach: bool) {
|
||||
let children = self.children.borrow();
|
||||
if let Some(ch) = children.deref() {
|
||||
for ss in ch.subsurfaces.values() {
|
||||
ss.surface.destroy_node(false);
|
||||
}
|
||||
}
|
||||
if let Some(xdg) = self.xdg.get() {
|
||||
let mut remove = vec![];
|
||||
for (seat, s) in &xdg.focus_surface {
|
||||
if s.id == self.id {
|
||||
remove.push(seat);
|
||||
}
|
||||
}
|
||||
for seat in remove {
|
||||
xdg.focus_surface.remove(&seat);
|
||||
}
|
||||
}
|
||||
self.seat_state.destroy_node(self);
|
||||
}
|
||||
|
||||
fn motion(&self, seat: &WlSeatGlobal, x: Fixed, y: Fixed) {
|
||||
seat.motion_surface(self, x, y)
|
||||
fn button(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
|
||||
seat.button_surface(&self, button, state);
|
||||
}
|
||||
|
||||
fn scroll(&self, seat: &WlSeatGlobal, delta: i32, axis: ScrollAxis) {
|
||||
seat.scroll_surface(self, delta, axis);
|
||||
}
|
||||
|
||||
fn button(self: Rc<Self>, seat: &WlSeatGlobal, button: u32, state: KeyState) {
|
||||
seat.button_surface(&self, button, state);
|
||||
fn focus(self: Rc<Self>, seat: &Rc<WlSeatGlobal>) {
|
||||
if let Some(xdg) = self.xdg.get() {
|
||||
xdg.focus_surface.insert(seat.id(), self);
|
||||
}
|
||||
}
|
||||
|
||||
fn focus(self: Rc<Self>, seat: &WlSeatGlobal) {
|
||||
seat.focus_surface(&self);
|
||||
fn unfocus(&self, seat: &WlSeatGlobal) {
|
||||
seat.unfocus_surface(self);
|
||||
}
|
||||
|
||||
fn unfocus(self: Rc<Self>, seat: &WlSeatGlobal) {
|
||||
seat.unfocus_surface(&self);
|
||||
fn leave(&self, seat: &WlSeatGlobal) {
|
||||
seat.leave_surface(self);
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
|
||||
seat.enter_surface(&self, x, y)
|
||||
}
|
||||
|
||||
fn motion(&self, seat: &WlSeatGlobal, x: Fixed, y: Fixed) {
|
||||
seat.motion_surface(self, x, y)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use crate::client::{ClientError, RequestParser};
|
||||
use crate::ifs::wl_callback::WlCallbackId;
|
||||
use crate::ifs::wl_region::WlRegionId;
|
||||
use crate::ifs::wl_surface::xdg_surface::XdgSurfaceError;
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
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, WlSurfaceError, 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};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::linkedlist::LinkedNode;
|
||||
use crate::NumCell;
|
||||
|
|
@ -27,12 +26,10 @@ const BAD_SURFACE: u32 = 0;
|
|||
|
||||
const MAX_SUBSURFACE_DEPTH: u32 = 100;
|
||||
|
||||
tree_id!(SubsurfaceNodeId);
|
||||
id!(WlSubsurfaceId);
|
||||
|
||||
pub struct WlSubsurface {
|
||||
id: WlSubsurfaceId,
|
||||
node_id: SubsurfaceNodeId,
|
||||
pub surface: Rc<WlSurface>,
|
||||
pub(super) parent: Rc<WlSurface>,
|
||||
pub position: Cell<Rect>,
|
||||
|
|
@ -87,7 +84,6 @@ impl WlSubsurface {
|
|||
pub fn new(id: WlSubsurfaceId, surface: &Rc<WlSurface>, parent: &Rc<WlSurface>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
node_id: surface.client.state.node_ids.next(),
|
||||
surface: surface.clone(),
|
||||
parent: parent.clone(),
|
||||
position: Cell::new(Default::default()),
|
||||
|
|
@ -312,42 +308,4 @@ impl SurfaceExt for WlSubsurface {
|
|||
fn into_subsurface(self: Rc<Self>) -> Option<Rc<WlSubsurface>> {
|
||||
Some(self)
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Node for WlSubsurface {
|
||||
fn id(&self) -> NodeId {
|
||||
self.node_id.into()
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &WlSeatGlobal, x: Fixed, y: Fixed) {
|
||||
seat.enter_surface(&self.surface, x, y)
|
||||
}
|
||||
|
||||
fn leave(&self, seat: &WlSeatGlobal) {
|
||||
seat.leave_surface(&self.surface);
|
||||
}
|
||||
|
||||
fn motion(&self, seat: &WlSeatGlobal, x: Fixed, y: Fixed) {
|
||||
seat.motion_surface(&self.surface, x, y)
|
||||
}
|
||||
|
||||
fn button(self: Rc<Self>, seat: &WlSeatGlobal, button: u32, state: KeyState) {
|
||||
seat.button_surface(&self.surface, button, state);
|
||||
}
|
||||
|
||||
fn scroll(&self, seat: &WlSeatGlobal, delta: i32, axis: ScrollAxis) {
|
||||
seat.scroll_surface(&self.surface, delta, axis);
|
||||
}
|
||||
|
||||
fn focus(self: Rc<Self>, seat: &WlSeatGlobal) {
|
||||
seat.focus_surface(&self.surface);
|
||||
}
|
||||
|
||||
fn unfocus(self: Rc<Self>, seat: &WlSeatGlobal) {
|
||||
seat.unfocus_surface(&self.surface)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,20 +5,23 @@ 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, WlSurfaceError};
|
||||
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::{FoundNode, Node};
|
||||
use crate::tree::{FindTreeResult, FoundNode, Node, WorkspaceNode};
|
||||
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;
|
||||
use crate::backend::SeatId;
|
||||
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
|
||||
use crate::utils::smallmap::SmallMap;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const GET_TOPLEVEL: u32 = 1;
|
||||
|
|
@ -34,11 +37,29 @@ const ALREADY_CONSTRUCTED: u32 = 2;
|
|||
#[allow(dead_code)]
|
||||
const UNCONFIGURED_BUFFER: u32 = 3;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum XdgSurfaceRole {
|
||||
None,
|
||||
XdgPopup,
|
||||
XdgToplevel,
|
||||
}
|
||||
|
||||
impl XdgSurfaceRole {
|
||||
fn name(self) -> &'static str {
|
||||
match self {
|
||||
XdgSurfaceRole::None => "none",
|
||||
XdgSurfaceRole::XdgPopup => "xdg_popup",
|
||||
XdgSurfaceRole::XdgToplevel => "xdg_toplevel",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
id!(XdgSurfaceId);
|
||||
|
||||
pub struct XdgSurface {
|
||||
id: XdgSurfaceId,
|
||||
base: Rc<XdgWmBaseObj>,
|
||||
role: Cell<XdgSurfaceRole>,
|
||||
pub surface: Rc<WlSurface>,
|
||||
requested_serial: NumCell<u32>,
|
||||
acked_serial: Cell<Option<u32>>,
|
||||
|
|
@ -48,7 +69,9 @@ pub struct XdgSurface {
|
|||
ext: CloneCell<Option<Rc<dyn XdgSurfaceExt>>>,
|
||||
popups: CopyHashMap<XdgPopupId, Rc<XdgPopup>>,
|
||||
pending: PendingXdgSurfaceData,
|
||||
pub focus_subsurface: CloneCell<Option<Rc<WlSubsurface>>>,
|
||||
pub(super) focus_surface: SmallMap<SeatId, Rc<WlSurface>, 1>,
|
||||
seat_state: NodeSeatState,
|
||||
pub workspace: CloneCell<Option<Rc<WorkspaceNode>>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -79,6 +102,7 @@ impl XdgSurface {
|
|||
Self {
|
||||
id,
|
||||
base: wm_base.clone(),
|
||||
role: Cell::new(XdgSurfaceRole::None),
|
||||
surface: surface.clone(),
|
||||
requested_serial: NumCell::new(0),
|
||||
acked_serial: Cell::new(None),
|
||||
|
|
@ -88,7 +112,47 @@ impl XdgSurface {
|
|||
ext: Default::default(),
|
||||
popups: Default::default(),
|
||||
pending: Default::default(),
|
||||
focus_subsurface: Default::default()
|
||||
focus_surface: Default::default(),
|
||||
seat_state: Default::default(),
|
||||
workspace: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_workspace(&self, ws: &Rc<WorkspaceNode>) {
|
||||
self.workspace.set(Some(ws.clone()));
|
||||
let pu = self.popups.lock();
|
||||
for pu in pu.values() {
|
||||
pu.xdg.set_workspace(ws);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_role(&self, role: XdgSurfaceRole) -> Result<(), XdgSurfaceError> {
|
||||
use XdgSurfaceRole::*;
|
||||
match (self.role.get(), role) {
|
||||
(None, _) => {}
|
||||
(old, new) if old == new => {}
|
||||
(old, new) => {
|
||||
return Err(XdgSurfaceError::IncompatibleRole {
|
||||
id: self.id,
|
||||
old,
|
||||
new,
|
||||
})
|
||||
}
|
||||
}
|
||||
self.role.set(role);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn focus_surface(&self, seat: &WlSeatGlobal) -> Rc<WlSurface> {
|
||||
self.focus_surface.get(&seat.id()).unwrap_or_else(|| self.surface.clone())
|
||||
}
|
||||
|
||||
fn destroy_node(&self) {
|
||||
self.workspace.set(None);
|
||||
self.surface.destroy_node(false);
|
||||
let popups = self.popups.lock();
|
||||
for popup in popups.values() {
|
||||
popup.destroy_node(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,6 +178,7 @@ impl XdgSurface {
|
|||
return Err(XdgSurfaceError::AlreadyAttached(self.surface.id));
|
||||
}
|
||||
self.surface.ext.set(self.clone());
|
||||
self.surface.set_xdg_surface(Some(self.clone()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -128,6 +193,7 @@ impl XdgSurface {
|
|||
return Err(DestroyError::PopupsNotYetDestroyed);
|
||||
}
|
||||
}
|
||||
self.surface.set_xdg_surface(None);
|
||||
self.surface.unset_ext();
|
||||
self.base.surfaces.remove(&self.id);
|
||||
self.surface.client.remove_obj(self)?;
|
||||
|
|
@ -136,7 +202,7 @@ impl XdgSurface {
|
|||
|
||||
fn get_toplevel(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetToplevelError> {
|
||||
let req: GetToplevel = self.surface.client.parse(&**self, parser)?;
|
||||
self.surface.set_role(SurfaceRole::XdgToplevel)?;
|
||||
self.set_role(XdgSurfaceRole::XdgToplevel)?;
|
||||
if self.ext.get().is_some() {
|
||||
self.surface.client.protocol_error(
|
||||
&**self,
|
||||
|
|
@ -156,7 +222,7 @@ impl XdgSurface {
|
|||
|
||||
fn get_popup(self: &Rc<Self>, parser: MsgParser<'_, '_>) -> Result<(), GetPopupError> {
|
||||
let req: GetPopup = self.surface.client.parse(&**self, parser)?;
|
||||
self.surface.set_role(SurfaceRole::XdgPopup)?;
|
||||
self.set_role(XdgSurfaceRole::XdgPopup)?;
|
||||
let mut parent = None;
|
||||
if req.parent.is_some() {
|
||||
parent = Some(self.surface.client.get_xdg_surface(req.parent)?);
|
||||
|
|
@ -230,24 +296,22 @@ impl XdgSurface {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_child_at(&self, mut x: i32, mut y: i32) -> Option<FoundNode> {
|
||||
fn find_tree_at(&self, mut x: i32, mut y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
|
||||
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,
|
||||
Some((node, x, y)) => {
|
||||
tree.push(FoundNode {
|
||||
node,
|
||||
x,
|
||||
y,
|
||||
});
|
||||
FindTreeResult::AcceptsInput
|
||||
},
|
||||
_ => FindTreeResult::Other
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +340,7 @@ impl Object for XdgSurface {
|
|||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.focus_subsurface.set(None);
|
||||
self.focus_surface.take();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -311,11 +375,4 @@ impl SurfaceExt for XdgSurface {
|
|||
fn extents_changed(&self) {
|
||||
self.update_extents();
|
||||
}
|
||||
|
||||
fn into_node(self: Rc<Self>) -> Option<Rc<dyn Node>> {
|
||||
match self.ext.get() {
|
||||
Some(e) => e.into_node(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::client::{ClientError, EventFormatter, RequestParser};
|
||||
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::xdg_surface::{XdgSurface, XdgSurfaceId, CONFIGURE, XdgSurfaceRole};
|
||||
use crate::ifs::wl_surface::{WlSurfaceError, WlSurfaceId};
|
||||
use crate::ifs::xdg_positioner::XdgPositionerId;
|
||||
use crate::object::Object;
|
||||
|
|
@ -28,6 +28,12 @@ pub enum XdgSurfaceError {
|
|||
WlSurfaceError(Box<WlSurfaceError>),
|
||||
#[error(transparent)]
|
||||
XdgPopupError(#[from] XdgPopupError),
|
||||
#[error("Surface {} cannot be assigned the role {} because it already has the role {}", .id, .new.name(), .old.name())]
|
||||
IncompatibleRole {
|
||||
id: XdgSurfaceId,
|
||||
old: XdgSurfaceRole,
|
||||
new: XdgSurfaceRole,
|
||||
},
|
||||
}
|
||||
efrom!(XdgSurfaceError, WlSurfaceError);
|
||||
|
||||
|
|
@ -55,10 +61,13 @@ pub enum GetToplevelError {
|
|||
AlreadyConstructed,
|
||||
#[error(transparent)]
|
||||
WlSurfaceError(Box<WlSurfaceError>),
|
||||
#[error(transparent)]
|
||||
XdgSurfaceError(Box<XdgSurfaceError>),
|
||||
}
|
||||
efrom!(GetToplevelError, ParseFailed, MsgParserError);
|
||||
efrom!(GetToplevelError, ClientError);
|
||||
efrom!(GetToplevelError, WlSurfaceError);
|
||||
efrom!(GetToplevelError, XdgSurfaceError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GetPopupError {
|
||||
|
|
@ -72,11 +81,14 @@ pub enum GetPopupError {
|
|||
WlSurfaceError(Box<WlSurfaceError>),
|
||||
#[error(transparent)]
|
||||
XdgPopupError(Box<XdgPopupError>),
|
||||
#[error(transparent)]
|
||||
XdgSurfaceError(Box<XdgSurfaceError>),
|
||||
}
|
||||
efrom!(GetPopupError, ParseFailed, MsgParserError);
|
||||
efrom!(GetPopupError, ClientError);
|
||||
efrom!(GetPopupError, XdgPopupError);
|
||||
efrom!(GetPopupError, WlSurfaceError);
|
||||
efrom!(GetPopupError, XdgSurfaceError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SetWindowGeometryError {
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
mod types;
|
||||
|
||||
use crate::client::DynEventFormatter;
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
|
||||
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::rect::Rect;
|
||||
use crate::tree::{FoundNode, Node, NodeId, StackedNode, WorkspaceNode};
|
||||
use crate::render::Renderer;
|
||||
use crate::tree::{AbsoluteNode, FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
use crate::utils::linkedlist::LinkedNode;
|
||||
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;
|
||||
|
|
@ -37,8 +36,8 @@ pub struct XdgPopup {
|
|||
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>>>,
|
||||
display_link: RefCell<Option<LinkedNode<Rc<dyn AbsoluteNode>>>>,
|
||||
workspace_link: RefCell<Option<LinkedNode<Rc<dyn AbsoluteNode>>>>,
|
||||
pos: RefCell<XdgPositioned>,
|
||||
}
|
||||
|
||||
|
|
@ -83,9 +82,7 @@ impl XdgPopup {
|
|||
}
|
||||
|
||||
fn popup_done(self: &Rc<Self>) -> DynEventFormatter {
|
||||
Box::new(PopupDone {
|
||||
obj: self.clone(),
|
||||
})
|
||||
Box::new(PopupDone { obj: self.clone() })
|
||||
}
|
||||
|
||||
fn update_relative_position(&self, parent: &XdgSurface) -> Result<(), XdgPopupError> {
|
||||
|
|
@ -102,12 +99,15 @@ impl XdgPopup {
|
|||
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()));
|
||||
self.xdg
|
||||
.absolute_desired_extents
|
||||
.set(rel.move_(parent.x1(), parent.y1()));
|
||||
}
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.xdg.surface.client.parse(self, parser)?;
|
||||
self.destroy_node(true);
|
||||
{
|
||||
if let Some(parent) = self.parent.take() {
|
||||
parent.popups.remove(&self.id);
|
||||
|
|
@ -115,7 +115,6 @@ 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(())
|
||||
|
|
@ -128,15 +127,27 @@ impl XdgPopup {
|
|||
|
||||
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();
|
||||
*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.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()));
|
||||
self.xdg
|
||||
.absolute_desired_extents
|
||||
.set(rel.move_(parent.x1(), parent.y1()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -154,6 +165,10 @@ impl XdgPopup {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_parent_workspace(&self) -> Option<Rc<WorkspaceNode>> {
|
||||
self.parent.get()?.workspace.get()
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(XdgPopup);
|
||||
|
|
@ -172,28 +187,44 @@ impl Object for XdgPopup {
|
|||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.destroy_node(true);
|
||||
self.parent.set(None);
|
||||
self.clear();
|
||||
*self.display_link.borrow_mut() = None;
|
||||
*self.workspace_link.borrow_mut() = None;
|
||||
}
|
||||
}
|
||||
|
||||
impl AbsoluteNode for XdgPopup {
|
||||
fn into_node(self: Rc<Self>) -> Rc<dyn Node> {
|
||||
self
|
||||
}
|
||||
|
||||
fn absolute_position(&self) -> Rect {
|
||||
self.xdg.absolute_desired_extents.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl Node for XdgPopup {
|
||||
fn id(&self) -> NodeId {
|
||||
self.node_id.into()
|
||||
}
|
||||
|
||||
fn clear(&self) {
|
||||
fn seat_state(&self) -> &NodeSeatState {
|
||||
&self.xdg.seat_state
|
||||
}
|
||||
|
||||
fn destroy_node(&self, _detach: bool) {
|
||||
let _v = self.display_link.borrow_mut().take();
|
||||
let _v = self.workspace_link.borrow_mut().take();
|
||||
self.xdg.destroy_node();
|
||||
self.xdg.seat_state.destroy_node(self);
|
||||
}
|
||||
|
||||
fn find_child_at(&self, x: i32, y: i32) -> Option<FoundNode> {
|
||||
self.xdg.find_child_at(x, y)
|
||||
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
|
||||
self.xdg.find_tree_at(x, y, tree)
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &WlSeatGlobal, _x: Fixed, _y: Fixed) {
|
||||
fn enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, _x: Fixed, _y: Fixed) {
|
||||
seat.enter_popup(&self);
|
||||
}
|
||||
|
||||
|
|
@ -201,8 +232,8 @@ impl Node for XdgPopup {
|
|||
renderer.render_xdg_surface(&self.xdg, x, y)
|
||||
}
|
||||
|
||||
fn get_workspace(self: Rc<Self>) -> Option<Rc<WorkspaceNode>> {
|
||||
self.parent.get()?.into_node()?.get_workspace()
|
||||
fn set_workspace(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.xdg.set_workspace(ws);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,9 +242,16 @@ impl XdgSurfaceExt for XdgPopup {
|
|||
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()));
|
||||
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()));
|
||||
self.xdg
|
||||
.absolute_desired_extents
|
||||
.set(rel.move_(parent.x1(), parent.y1()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -221,22 +259,30 @@ impl XdgSurfaceExt for XdgPopup {
|
|||
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() {
|
||||
let ws = match self.get_parent_workspace() {
|
||||
Some(ws) => ws,
|
||||
_ => return,
|
||||
_ => {
|
||||
log::info!("no 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())));
|
||||
self.xdg.set_workspace(&ws);
|
||||
*wl = Some(ws.stacked.add_last(self.clone()));
|
||||
*dl = Some(
|
||||
state
|
||||
.root
|
||||
.stacked
|
||||
.add_last(self.clone()),
|
||||
);
|
||||
state.tree_changed();
|
||||
}
|
||||
} else {
|
||||
if wl.take().is_some() {
|
||||
*dl = None;
|
||||
state.tree_changed();
|
||||
self.destroy_node(true);
|
||||
surface.client.event(self.popup_done());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ pub enum XdgPopupError {
|
|||
#[error("The `xdg_positioner` is incomplete")]
|
||||
Incomplete,
|
||||
#[error("The anchor rectangle of the `xdg_positioner` extends outside the parent")]
|
||||
#[allow(dead_code)]
|
||||
AnchorRectOutside,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ mod types;
|
|||
|
||||
use crate::client::DynEventFormatter;
|
||||
use crate::fixed::Fixed;
|
||||
use crate::ifs::wl_seat::WlSeatGlobal;
|
||||
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
|
||||
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, StackedNode};
|
||||
use crate::tree::{ContainerNode, FindTreeResult};
|
||||
use crate::tree::{FloatNode, FoundNode, Node, NodeId, ToplevelNodeId, WorkspaceNode};
|
||||
use crate::utils::buffd::MsgParser;
|
||||
use crate::utils::clonecell::CloneCell;
|
||||
|
|
@ -15,9 +15,11 @@ use ahash::{AHashMap, AHashSet};
|
|||
use num_derive::FromPrimitive;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
use crate::backend::SeatId;
|
||||
use crate::utils::linkedlist::LinkedNode;
|
||||
use crate::utils::smallmap::SmallMap;
|
||||
|
||||
const DESTROY: u32 = 0;
|
||||
const SET_PARENT: u32 = 1;
|
||||
|
|
@ -77,6 +79,7 @@ pub struct XdgToplevel {
|
|||
pub parent: CloneCell<Option<Rc<XdgToplevel>>>,
|
||||
pub children: RefCell<AHashMap<XdgToplevelId, Rc<XdgToplevel>>>,
|
||||
states: RefCell<AHashSet<u32>>,
|
||||
pub toplevel_history: SmallMap<SeatId, LinkedNode<Rc<XdgToplevel>>, 1>,
|
||||
}
|
||||
|
||||
impl XdgToplevel {
|
||||
|
|
@ -94,6 +97,7 @@ impl XdgToplevel {
|
|||
parent: Default::default(),
|
||||
children: RefCell::new(Default::default()),
|
||||
states: RefCell::new(states),
|
||||
toplevel_history: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -115,6 +119,7 @@ impl XdgToplevel {
|
|||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> {
|
||||
let _req: Destroy = self.xdg.surface.client.parse(self, parser)?;
|
||||
self.destroy_node(true);
|
||||
self.xdg.ext.set(None);
|
||||
if let Some(parent) = self.parent_node.take() {
|
||||
parent.remove_child(self);
|
||||
|
|
@ -225,10 +230,11 @@ impl XdgToplevel {
|
|||
}
|
||||
|
||||
fn map_child(self: &Rc<Self>, parent: &XdgToplevel) {
|
||||
let workspace = match parent.get_workspace() {
|
||||
let workspace = match parent.xdg.workspace.get() {
|
||||
Some(w) => w,
|
||||
_ => return self.map_tiled(),
|
||||
};
|
||||
self.xdg.set_workspace(&workspace);
|
||||
let output = workspace.output.get();
|
||||
let output_rect = output.position.get();
|
||||
let position = {
|
||||
|
|
@ -255,14 +261,20 @@ impl XdgToplevel {
|
|||
workspace_link: Cell::new(None),
|
||||
workspace: CloneCell::new(workspace.clone()),
|
||||
child: CloneCell::new(Some(self.clone())),
|
||||
seat_state: Default::default(),
|
||||
});
|
||||
self.parent_node.set(Some(floater.clone()));
|
||||
floater
|
||||
.display_link
|
||||
.set(Some(state.root.stacked.add_last(StackedNode::Float(floater.clone()))));
|
||||
floater
|
||||
.workspace_link
|
||||
.set(Some(workspace.stacked.add_last(StackedNode::Float(floater.clone()))));
|
||||
floater.display_link.set(Some(
|
||||
state
|
||||
.root
|
||||
.stacked
|
||||
.add_last(floater.clone()),
|
||||
));
|
||||
floater.workspace_link.set(Some(
|
||||
workspace
|
||||
.stacked
|
||||
.add_last(floater.clone()),
|
||||
));
|
||||
}
|
||||
|
||||
fn map_tiled(self: &Rc<Self>) {
|
||||
|
|
@ -291,7 +303,7 @@ impl XdgToplevel {
|
|||
self.parent_node.set(Some(container));
|
||||
} else {
|
||||
let container =
|
||||
Rc::new(ContainerNode::new(state, workspace.clone(), self.clone()));
|
||||
Rc::new(ContainerNode::new(state, &workspace, workspace.clone(), self.clone()));
|
||||
workspace.set_container(&container);
|
||||
self.parent_node.set(Some(container));
|
||||
};
|
||||
|
|
@ -300,13 +312,6 @@ impl XdgToplevel {
|
|||
}
|
||||
todo!("map_tiled");
|
||||
}
|
||||
|
||||
fn get_workspace(&self) -> Option<Rc<WorkspaceNode>> {
|
||||
match self.parent_node.get() {
|
||||
Some(node) => node.get_workspace(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(XdgToplevel);
|
||||
|
|
@ -325,6 +330,7 @@ impl Object for XdgToplevel {
|
|||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.destroy_node(true);
|
||||
if let Some(parent) = self.parent_node.take() {
|
||||
parent.remove_child(self);
|
||||
}
|
||||
|
|
@ -338,30 +344,40 @@ impl Node for XdgToplevel {
|
|||
self.node_id.into()
|
||||
}
|
||||
|
||||
fn clear(&self) {
|
||||
self.parent_node.set(None);
|
||||
fn seat_state(&self) -> &NodeSeatState {
|
||||
&self.xdg.seat_state
|
||||
}
|
||||
|
||||
fn find_child_at(&self, x: i32, y: i32) -> Option<FoundNode> {
|
||||
self.xdg.find_child_at(x, y)
|
||||
fn destroy_node(&self, detach: bool) {
|
||||
if let Some(parent) = self.parent_node.take() {
|
||||
if detach {
|
||||
parent.remove_child(self);
|
||||
}
|
||||
}
|
||||
self.toplevel_history.take();
|
||||
self.xdg.destroy_node();
|
||||
self.xdg.seat_state.destroy_node(self)
|
||||
}
|
||||
|
||||
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
|
||||
self.xdg.find_tree_at(x, y, tree)
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, _x: Fixed, _y: Fixed) {
|
||||
seat.enter_toplevel(&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.deref().get_workspace()
|
||||
}
|
||||
|
||||
fn enter(self: Rc<Self>, seat: &WlSeatGlobal, _x: Fixed, _y: Fixed) {
|
||||
seat.enter_toplevel(&self);
|
||||
}
|
||||
|
||||
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
|
||||
.surface
|
||||
.client
|
||||
.event(self.configure(rect.width(), rect.height()));
|
||||
self.xdg.send_configure();
|
||||
self.xdg.surface.client.flush();
|
||||
}
|
||||
|
|
@ -369,6 +385,10 @@ impl Node for XdgToplevel {
|
|||
self.xdg.update_popup_positions();
|
||||
}
|
||||
}
|
||||
|
||||
fn set_workspace(self: Rc<Self>, ws: &Rc<WorkspaceNode>) {
|
||||
self.xdg.set_workspace(ws);
|
||||
}
|
||||
}
|
||||
|
||||
impl XdgSurfaceExt for XdgToplevel {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue