iced-yoda/runtime/src/platform_specific/wayland/subsurface.rs

90 lines
2.3 KiB
Rust
Raw Normal View History

2025-03-14 11:16:25 -04:00
use std::any::Any;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::sync::Arc;
use cctk::sctk::reexports::protocols::xdg::shell::client::xdg_positioner::{
Anchor, Gravity,
};
use iced_core::layout::Limits;
use iced_core::window::Id;
use iced_core::{Element, Point, Rectangle, Size};
/// Subsurface creation details
#[derive(Debug, Clone)]
pub struct SctkSubsurfaceSettings {
/// XXX must be unique, id of the parent
pub parent: Id,
/// XXX must be unique, id of the subsurface
pub id: Id,
/// anchor position of the subsurface
pub loc: Point,
/// size of the subsurface
pub size: Option<Size>,
// pub subsurface_view: Option<Arc<dyn Any + Send + Sync>>,
/// Z
pub z: i32,
2025-03-14 11:16:25 -04:00
/// Steal Keyboard focus from parent while open.
/// Will not work on a regular window.
pub steal_keyboard_focus: bool,
/// offset of the subsurface from the anchor
pub offset: (i32, i32),
/// the gravity of the popup
pub gravity: Gravity,
/// input zone
/// None results in accepting all input
pub input_zone: Option<Vec<Rectangle>>,
2025-03-14 11:16:25 -04:00
}
impl Hash for SctkSubsurfaceSettings {
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
#[derive(Clone)]
/// Window Action
pub enum Action {
/// create a window and receive a message with its Id
Subsurface {
/// subsurface
subsurface: SctkSubsurfaceSettings,
},
/// destroy the subsurface
Destroy {
/// id of the subsurface
id: Id,
},
2025-08-25 00:16:31 -04:00
/// reposition the subsurface
Reposition {
/// id of the subsurface
id: Id,
x: i32,
y: i32,
},
2025-03-14 11:16:25 -04:00
}
impl fmt::Debug for Action {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Action::Subsurface { subsurface, .. } => write!(
f,
"Action::SubsurfaceAction::Subsurface {{ subsurface: {:?} }}",
subsurface
),
Action::Destroy { id } => write!(
f,
"Action::SubsurfaceAction::Destroy {{ id: {:?} }}",
id
),
2025-08-25 00:16:31 -04:00
Action::Reposition { id, x, y } => write!(
f,
"Action::SubsurfaceAction::Reposition {{ id: {:?}, x: {:?}, y: {:?} }}",
id, x, y
),
2025-03-14 11:16:25 -04:00
}
}
}