feat(panel item): queue up material applications
This commit is contained in:
@@ -32,7 +32,9 @@ use stereokit as sk;
|
|||||||
use stereokit::StereoKit;
|
use stereokit::StereoKit;
|
||||||
use surface::CoreSurface;
|
use surface::CoreSurface;
|
||||||
|
|
||||||
use self::seat::SeatDelegate;
|
use crate::nodes::core::Node;
|
||||||
|
|
||||||
|
use self::{panel_item::PanelItem, seat::SeatDelegate};
|
||||||
|
|
||||||
struct EGLRawHandles {
|
struct EGLRawHandles {
|
||||||
display: *const c_void,
|
display: *const c_void,
|
||||||
@@ -165,6 +167,9 @@ impl WaylandState {
|
|||||||
with_states(surf.wl_surface(), |data| {
|
with_states(surf.wl_surface(), |data| {
|
||||||
if let Some(core_surface) = data.data_map.get::<CoreSurface>() {
|
if let Some(core_surface) = data.data_map.get::<CoreSurface>() {
|
||||||
core_surface.update_tex(sk);
|
core_surface.update_tex(sk);
|
||||||
|
if let Some(panel_item) = data.data_map.get::<Arc<Node>>() {
|
||||||
|
PanelItem::apply_surface_materials(panel_item, core_surface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
send_frames_surface_tree(surf.wl_surface(), time_ms);
|
send_frames_surface_tree(surf.wl_surface(), time_ms);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use crate::{
|
|||||||
nodes::{
|
nodes::{
|
||||||
core::Node,
|
core::Node,
|
||||||
item::{register_item_ui_flex, Item, ItemSpecialization, ItemType, TypeInfo},
|
item::{register_item_ui_flex, Item, ItemSpecialization, ItemType, TypeInfo},
|
||||||
|
model::Model,
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -26,7 +27,6 @@ use smithay::{
|
|||||||
DisplayHandle, Resource,
|
DisplayHandle, Resource,
|
||||||
},
|
},
|
||||||
utils::{user_data::UserDataMap, Logical, Size},
|
utils::{user_data::UserDataMap, Logical, Size},
|
||||||
wayland::compositor,
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
@@ -61,6 +61,7 @@ lazy_static! {
|
|||||||
|
|
||||||
pub struct PanelItem {
|
pub struct PanelItem {
|
||||||
node: Weak<Node>,
|
node: Weak<Node>,
|
||||||
|
pending_material_applications: Mutex<Vec<(Arc<Model>, u32)>>,
|
||||||
pub toplevel_surface: WlSurface,
|
pub toplevel_surface: WlSurface,
|
||||||
seat_data: SeatData,
|
seat_data: SeatData,
|
||||||
size: Mutex<Size<i32, Logical>>,
|
size: Mutex<Size<i32, Logical>>,
|
||||||
@@ -88,6 +89,7 @@ impl PanelItem {
|
|||||||
|
|
||||||
let specialization = ItemType::Panel(PanelItem {
|
let specialization = ItemType::Panel(PanelItem {
|
||||||
node: Arc::downgrade(&node),
|
node: Arc::downgrade(&node),
|
||||||
|
pending_material_applications: Mutex::new(Vec::new()),
|
||||||
toplevel_surface,
|
toplevel_surface,
|
||||||
seat_data,
|
seat_data,
|
||||||
size,
|
size,
|
||||||
@@ -97,14 +99,23 @@ impl PanelItem {
|
|||||||
.items
|
.items
|
||||||
.add(Item::new(&node, &ITEM_TYPE_INFO_PANEL, specialization));
|
.add(Item::new(&node, &ITEM_TYPE_INFO_PANEL, specialization));
|
||||||
let _ = node.item.set(item);
|
let _ = node.item.set(item);
|
||||||
node.add_local_signal("applySurfaceMaterial", PanelItem::apply_surface_material);
|
node.add_local_signal(
|
||||||
node.add_local_signal("pointerDeactivate", PanelItem::pointer_deactivate);
|
"applySurfaceMaterial",
|
||||||
node.add_local_signal("pointerScroll", PanelItem::pointer_scroll);
|
PanelItem::apply_surface_material_flex,
|
||||||
node.add_local_signal("pointerButton", PanelItem::pointer_button);
|
);
|
||||||
node.add_local_signal("pointerMotion", PanelItem::pointer_motion);
|
node.add_local_signal("pointerDeactivate", PanelItem::pointer_deactivate_flex);
|
||||||
node.add_local_signal("keyboardSetActive", PanelItem::keyboard_set_active);
|
node.add_local_signal("pointerScroll", PanelItem::pointer_scroll_flex);
|
||||||
node.add_local_signal("keyboardSetKeyState", PanelItem::keyboard_set_key_state);
|
node.add_local_signal("pointerButton", PanelItem::pointer_button_flex);
|
||||||
node.add_local_signal("keyboardSetModifiers", PanelItem::keyboard_set_modifiers);
|
node.add_local_signal("pointerMotion", PanelItem::pointer_motion_flex);
|
||||||
|
node.add_local_signal("keyboardSetActive", PanelItem::keyboard_set_active_flex);
|
||||||
|
node.add_local_signal(
|
||||||
|
"keyboardSetKeyState",
|
||||||
|
PanelItem::keyboard_set_key_state_flex,
|
||||||
|
);
|
||||||
|
node.add_local_signal(
|
||||||
|
"keyboardSetModifiers",
|
||||||
|
PanelItem::keyboard_set_modifiers_flex,
|
||||||
|
);
|
||||||
node
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +133,11 @@ impl PanelItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_surface_material(node: &Node, calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
fn apply_surface_material_flex(
|
||||||
|
node: &Node,
|
||||||
|
calling_client: Arc<Client>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
|
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
|
||||||
let material_idx = flex_vec.idx(1).get_u64()?;
|
let material_idx = flex_vec.idx(1).get_u64()?;
|
||||||
let model_node = calling_client
|
let model_node = calling_client
|
||||||
@@ -135,26 +150,34 @@ impl PanelItem {
|
|||||||
.ok_or_else(|| anyhow!("Node is not a model"))?;
|
.ok_or_else(|| anyhow!("Node is not a model"))?;
|
||||||
|
|
||||||
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
||||||
compositor::with_states(&panel_item.toplevel_surface, |states| {
|
panel_item
|
||||||
let sk_mat = states
|
.pending_material_applications
|
||||||
.data_map
|
.lock()
|
||||||
.get::<CoreSurface>()
|
.push((model.clone(), material_idx as u32));
|
||||||
.unwrap()
|
|
||||||
.sk_mat
|
|
||||||
.get()
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
|
||||||
model
|
|
||||||
.pending_material_replacements
|
|
||||||
.lock()
|
|
||||||
.insert(material_idx as u32, sk_mat);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pointer_deactivate(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
|
pub fn apply_surface_materials(node: &Node, core_surface: &CoreSurface) {
|
||||||
|
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
||||||
|
let mut pending_material_applications = panel_item.pending_material_applications.lock();
|
||||||
|
for (model, material_idx) in &*pending_material_applications {
|
||||||
|
let sk_mat = core_surface.sk_mat.get().unwrap().clone();
|
||||||
|
model
|
||||||
|
.pending_material_replacements
|
||||||
|
.lock()
|
||||||
|
.insert(*material_idx, sk_mat);
|
||||||
|
}
|
||||||
|
pending_material_applications.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pointer_deactivate_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
_data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
||||||
if *panel_item.seat_data.pointer_active.lock() {
|
if *panel_item.seat_data.pointer_active.lock() {
|
||||||
if let Some(pointer) = panel_item.seat_data.pointer() {
|
if let Some(pointer) = panel_item.seat_data.pointer() {
|
||||||
@@ -167,7 +190,7 @@ impl PanelItem {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pointer_motion(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
fn pointer_motion_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
||||||
if let Some(pointer) = panel_item.seat_data.pointer() {
|
if let Some(pointer) = panel_item.seat_data.pointer() {
|
||||||
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
|
let flex_vec = flexbuffers::Reader::get_root(data)?.get_vector()?;
|
||||||
@@ -187,7 +210,7 @@ impl PanelItem {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pointer_button(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
fn pointer_button_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
||||||
if let Some(pointer) = panel_item.seat_data.pointer() {
|
if let Some(pointer) = panel_item.seat_data.pointer() {
|
||||||
if *panel_item.seat_data.pointer_active.lock() {
|
if *panel_item.seat_data.pointer_active.lock() {
|
||||||
@@ -212,7 +235,7 @@ impl PanelItem {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pointer_scroll(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
fn pointer_scroll_flex(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
||||||
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
||||||
if let Some(pointer) = panel_item.seat_data.pointer() {
|
if let Some(pointer) = panel_item.seat_data.pointer() {
|
||||||
if *panel_item.seat_data.pointer_active.lock() {
|
if *panel_item.seat_data.pointer_active.lock() {
|
||||||
@@ -240,7 +263,11 @@ impl PanelItem {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_set_active(node: &Node, _calling_client: Arc<Client>, data: &[u8]) -> Result<()> {
|
fn keyboard_set_active_flex(
|
||||||
|
node: &Node,
|
||||||
|
_calling_client: Arc<Client>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
if let ItemType::Panel(panel_item) = &node.item.get().unwrap().specialization {
|
||||||
if let Some(keyboard) = panel_item.seat_data.keyboard() {
|
if let Some(keyboard) = panel_item.seat_data.keyboard() {
|
||||||
let mut keyboard_active = panel_item.seat_data.keyboard_active.lock();
|
let mut keyboard_active = panel_item.seat_data.keyboard_active.lock();
|
||||||
@@ -259,7 +286,7 @@ impl PanelItem {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_set_key_state(
|
fn keyboard_set_key_state_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
_calling_client: Arc<Client>,
|
_calling_client: Arc<Client>,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
@@ -281,7 +308,7 @@ impl PanelItem {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn keyboard_set_modifiers(
|
fn keyboard_set_modifiers_flex(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
_calling_client: Arc<Client>,
|
_calling_client: Arc<Client>,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
|
|||||||
Reference in New Issue
Block a user