diff --git a/src/nodes/item.rs b/src/nodes/item.rs index 5506e9b..85e6238 100644 --- a/src/nodes/item.rs +++ b/src/nodes/item.rs @@ -4,6 +4,7 @@ use super::spatial::{get_spatial_parent_flex, get_transform_pose_flex, Spatial}; use crate::core::client::{Client, INTERNAL_CLIENT}; use crate::core::nodelist::LifeLinkedNodeList; use crate::core::registry::Registry; +use crate::wayland::panel_item::PanelItem; use anyhow::{anyhow, ensure, Result}; use lazy_static::lazy_static; use nanoid::nanoid; @@ -32,32 +33,6 @@ lazy_static! { items: Registry::new(), acceptors: Registry::new(), }; - static ref ITEM_TYPE_INFO_PANEL: TypeInfo = TypeInfo { - type_name: "panel", - aliased_local_signals: vec![ - "applySurfaceMaterial", - "setPointerActive", - "setPointerPosition", - "setPointerButtonPressed", - "scrollPointerAxis", - "touchDown", - "touchMove", - "touchUp", - "setKeyboardActive", - "setKeymap", - "setKeyState", - "setKeyModStates", - "setKeyRepeat", - "resize", - "close", - ], - aliased_local_methods: vec![], - aliased_remote_signals: vec![], - aliased_remote_methods: vec![], - ui: Default::default(), - items: Registry::new(), - acceptors: Registry::new(), - }; } fn capture(item: &Arc, acceptor: &Arc) { @@ -81,14 +56,14 @@ fn release(item: &Arc) { } pub struct TypeInfo { - type_name: &'static str, - aliased_local_signals: Vec<&'static str>, - aliased_local_methods: Vec<&'static str>, - aliased_remote_signals: Vec<&'static str>, - aliased_remote_methods: Vec<&'static str>, - ui: Mutex>, - items: Registry, - acceptors: Registry, + pub type_name: &'static str, + pub aliased_local_signals: Vec<&'static str>, + pub aliased_local_methods: Vec<&'static str>, + pub aliased_remote_signals: Vec<&'static str>, + pub aliased_remote_methods: Vec<&'static str>, + pub ui: Mutex>, + pub items: Registry, + pub acceptors: Registry, } fn capture_into_flex(node: &Node, calling_client: Arc, data: &[u8]) -> Result<()> { @@ -115,7 +90,7 @@ pub struct Item { specialization: ItemType, } impl Item { - fn new(node: &Arc, type_info: &'static TypeInfo, specialization: ItemType) -> Self { + pub fn new(node: &Arc, type_info: &'static TypeInfo, specialization: ItemType) -> Self { node.add_local_signal("captureInto", capture_into_flex); let item = Item { node: Arc::downgrade(node), @@ -168,6 +143,7 @@ impl Drop for Item { pub enum ItemType { Environment(EnvironmentItem), + Panel(PanelItem), } pub struct EnvironmentItem { @@ -188,7 +164,7 @@ impl EnvironmentItem { fn get_path_flex(node: &Node, _calling_client: Arc, _data: &[u8]) -> Result> { let path: Result = match &node.item.get().unwrap().specialization { ItemType::Environment(env) => Ok(env.path.clone()), - // _ => Err(anyhow!("")), + _ => Err(anyhow!("")), }; Ok(flexbuffers::singleton(path?.as_str())) } diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 842235a..1214b07 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -1,3 +1,4 @@ +pub mod panel_item; pub mod compositor; pub mod shaders; pub mod surface; diff --git a/src/wayland/panel_item.rs b/src/wayland/panel_item.rs new file mode 100644 index 0000000..904a6c9 --- /dev/null +++ b/src/wayland/panel_item.rs @@ -0,0 +1,62 @@ +use crate::{ + core::{client::INTERNAL_CLIENT, registry::Registry}, + nodes::{ + core::Node, + item::{Item, ItemType, TypeInfo}, + spatial::Spatial, + }, +}; +use glam::Mat4; +use lazy_static::lazy_static; +use nanoid::nanoid; +use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; +use std::sync::Arc; + +lazy_static! { + static ref ITEM_TYPE_INFO_PANEL: TypeInfo = TypeInfo { + type_name: "panel", + aliased_local_signals: vec![ + "applySurfaceMaterial", + "setPointerActive", + "setPointerPosition", + "setPointerButtonPressed", + "scrollPointerAxis", + "touchDown", + "touchMove", + "touchUp", + "setKeyboardActive", + "setKeymap", + "setKeyState", + "setKeyModStates", + "setKeyRepeat", + "resize", + "close", + ], + aliased_local_methods: vec![], + aliased_remote_signals: vec![], + aliased_remote_methods: vec![], + ui: Default::default(), + items: Registry::new(), + acceptors: Registry::new(), + }; +} + +pub struct PanelItem { + toplevel_surface: WlSurface, +} +impl PanelItem { + pub fn create(toplevel_surface: WlSurface) -> Arc { + let node = Node::create(&INTERNAL_CLIENT, "/item/panel/item", &nanoid!(), true) + .add_to_scenegraph(); + Spatial::add_to(&node, None, Mat4::IDENTITY).unwrap(); + + let specialization = ItemType::Panel(PanelItem { toplevel_surface }); + let item = + ITEM_TYPE_INFO_PANEL + .items + .add(Item::new(&node, &ITEM_TYPE_INFO_PANEL, specialization)); + let _ = node.item.set(item); + // node.add_local_method("getPath", PanelItem::get_path_flex); + node + } +} diff --git a/src/wayland/xdg_shell.rs b/src/wayland/xdg_shell.rs index 96cf968..536d00e 100644 --- a/src/wayland/xdg_shell.rs +++ b/src/wayland/xdg_shell.rs @@ -7,7 +7,7 @@ use smithay::{ wayland::{compositor, shell::xdg::XdgShellHandler}, }; -use super::{surface::CoreSurface, WaylandState}; +use super::{panel_item::PanelItem, surface::CoreSurface, WaylandState}; impl XdgShellHandler for WaylandState { fn xdg_shell_state(&mut self) -> &mut smithay::wayland::shell::xdg::XdgShellState { @@ -29,6 +29,8 @@ impl XdgShellHandler for WaylandState { compositor::with_states(surface.wl_surface(), |data| { data.data_map.insert_if_missing(CoreSurface::new); + data.data_map + .insert_if_missing(|| PanelItem::create(surface.wl_surface().clone())); }); }