xdg-popup: implement jay-popup-ext-v1
This commit is contained in:
parent
15e6ab2b8a
commit
1d3dfa8b3a
12 changed files with 473 additions and 8 deletions
|
|
@ -1,3 +1,5 @@
|
|||
pub mod jay_popup_ext_v1;
|
||||
|
||||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
|
|
@ -7,7 +9,9 @@ use {
|
|||
wl_seat::{NodeSeatState, SeatId, WlSeatGlobal, tablet::TabletTool},
|
||||
wl_surface::{
|
||||
tray::TrayItemId,
|
||||
xdg_surface::{XdgSurface, XdgSurfaceExt},
|
||||
xdg_surface::{
|
||||
XdgSurface, XdgSurfaceExt, xdg_popup::jay_popup_ext_v1::JayPopupExtV1,
|
||||
},
|
||||
},
|
||||
xdg_positioner::{
|
||||
CA_FLIP_X, CA_FLIP_Y, CA_RESIZE_X, CA_RESIZE_Y, CA_SLIDE_X, CA_SLIDE_Y,
|
||||
|
|
@ -65,6 +69,7 @@ pub struct XdgPopup {
|
|||
pub tracker: Tracker<Self>,
|
||||
seat_state: NodeSeatState,
|
||||
set_visible_prepared: Cell<bool>,
|
||||
jay_popup_ext: CloneCell<Option<Rc<JayPopupExtV1>>>,
|
||||
interactive_moves: SmallMap<SeatId, Rc<WlSeatGlobal>, 1>,
|
||||
}
|
||||
|
||||
|
|
@ -94,6 +99,7 @@ impl XdgPopup {
|
|||
tracker: Default::default(),
|
||||
seat_state: Default::default(),
|
||||
set_visible_prepared: Cell::new(false),
|
||||
jay_popup_ext: Default::default(),
|
||||
interactive_moves: Default::default(),
|
||||
})
|
||||
}
|
||||
|
|
@ -267,6 +273,9 @@ impl XdgPopupRequestHandler for XdgPopup {
|
|||
type Error = XdgPopupError;
|
||||
|
||||
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if self.jay_popup_ext.is_some() {
|
||||
return Err(XdgPopupError::HasJayPopupExt);
|
||||
}
|
||||
self.destroy_node();
|
||||
self.xdg.unset_ext();
|
||||
self.xdg.surface.client.remove_obj(self)?;
|
||||
|
|
@ -328,6 +337,7 @@ object_base! {
|
|||
|
||||
impl Object for XdgPopup {
|
||||
fn break_loops(&self) {
|
||||
self.jay_popup_ext.take();
|
||||
self.destroy_node();
|
||||
}
|
||||
}
|
||||
|
|
@ -518,5 +528,7 @@ pub enum XdgPopupError {
|
|||
Incomplete,
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("The popup still has a jay_popup_ext_v1 extension object")]
|
||||
HasJayPopupExt,
|
||||
}
|
||||
efrom!(XdgPopupError, ClientError);
|
||||
|
|
|
|||
101
src/ifs/wl_surface/xdg_surface/xdg_popup/jay_popup_ext_v1.rs
Normal file
101
src/ifs/wl_surface/xdg_surface/xdg_popup/jay_popup_ext_v1.rs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
ifs::wl_surface::xdg_surface::{xdg_popup::XdgPopup, xdg_toplevel::map_resize_edges},
|
||||
leaks::Tracker,
|
||||
object::{Object, Version},
|
||||
wire::{JayPopupExtV1Id, jay_popup_ext_v1::*},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct JayPopupExtV1 {
|
||||
id: JayPopupExtV1Id,
|
||||
client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
version: Version,
|
||||
popup: Rc<XdgPopup>,
|
||||
}
|
||||
|
||||
impl JayPopupExtV1 {
|
||||
pub fn new(
|
||||
id: JayPopupExtV1Id,
|
||||
client: &Rc<Client>,
|
||||
version: Version,
|
||||
popup: &Rc<XdgPopup>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id,
|
||||
tracker: Default::default(),
|
||||
version,
|
||||
client: client.clone(),
|
||||
popup: popup.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn install(self: &Rc<Self>) -> Result<(), JayPopupExtV1Error> {
|
||||
if self.popup.jay_popup_ext.is_some() {
|
||||
return Err(JayPopupExtV1Error::HasExt);
|
||||
}
|
||||
self.popup.jay_popup_ext.set(Some(self.clone()));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl JayPopupExtV1RequestHandler for JayPopupExtV1 {
|
||||
type Error = JayPopupExtV1Error;
|
||||
|
||||
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.popup.jay_popup_ext.take();
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn move_(&self, req: Move, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
let seat = self.client.lookup(req.seat)?;
|
||||
let Some(serial) = self.client.map_serial(req.serial) else {
|
||||
return Ok(());
|
||||
};
|
||||
if self.popup.seat_state.pointer_not_inside(&seat.global) {
|
||||
return Ok(());
|
||||
}
|
||||
seat.global.start_popup_move(&self.popup, serial);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn resize(&self, req: Resize, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
let Some(edges) = map_resize_edges(req.edges) else {
|
||||
return Err(JayPopupExtV1Error::UnknownResizeEdges(req.edges));
|
||||
};
|
||||
let seat = self.client.lookup(req.seat)?;
|
||||
let Some(serial) = self.client.map_serial(req.serial) else {
|
||||
return Ok(());
|
||||
};
|
||||
if self.popup.seat_state.pointer_not_inside(&seat.global) {
|
||||
return Ok(());
|
||||
}
|
||||
seat.global.start_popup_resize(&self.popup, edges, serial);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
self = JayPopupExtV1;
|
||||
version = self.version;
|
||||
}
|
||||
|
||||
impl Object for JayPopupExtV1 {}
|
||||
|
||||
simple_add_obj!(JayPopupExtV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum JayPopupExtV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("The xdg_popup already has a jay_popup_ext_v1 extension")]
|
||||
HasExt,
|
||||
#[error("The resize edge {0} is unknown")]
|
||||
UnknownResizeEdges(u32),
|
||||
}
|
||||
efrom!(JayPopupExtV1Error, ClientError);
|
||||
|
|
@ -79,6 +79,11 @@ pub const SUSPENDED_SINCE: Version = Version(6);
|
|||
pub const TILED_SINCE: Version = Version(2);
|
||||
pub const CONSTRAINTS_SINCE: Version = Version(7);
|
||||
|
||||
const RESIZE_EDGE_TOP: u32 = 1;
|
||||
const RESIZE_EDGE_BOTTOM: u32 = 2;
|
||||
const RESIZE_EDGE_LEFT: u32 = 4;
|
||||
const RESIZE_EDGE_RIGHT: u32 = 8;
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
pub enum Decoration {
|
||||
#[expect(dead_code)]
|
||||
|
|
@ -834,6 +839,18 @@ pub enum XdgToplevelError {
|
|||
}
|
||||
efrom!(XdgToplevelError, ClientError);
|
||||
|
||||
pub fn map_resize_edges(edge: u32) -> Option<ResizeEdges> {
|
||||
if !matches!(edge, 0 | 1 | 2 | 4 | 5 | 6 | 8 | 9 | 10) {
|
||||
return None;
|
||||
}
|
||||
Some(ResizeEdges {
|
||||
top: edge.contains(RESIZE_EDGE_TOP),
|
||||
left: edge.contains(RESIZE_EDGE_LEFT),
|
||||
right: edge.contains(RESIZE_EDGE_RIGHT),
|
||||
bottom: edge.contains(RESIZE_EDGE_BOTTOM),
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ResizeEdges {
|
||||
pub top: bool,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue