DashInterface, DashInterfaceEmulated
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -5848,6 +5848,7 @@ dependencies = [
|
||||
"vulkano-shaders",
|
||||
"wgui",
|
||||
"winit",
|
||||
"wlx-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6841,11 +6842,13 @@ dependencies = [
|
||||
name = "wlx-common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"glam",
|
||||
"idmap",
|
||||
"idmap-derive",
|
||||
"serde",
|
||||
"wayvr_ipc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -34,3 +34,4 @@ vulkano = { version = "0.35.2", default-features = false, features = [
|
||||
] }
|
||||
vulkano-shaders = "0.35.0"
|
||||
wayland-client = { version = "0.31.11" }
|
||||
wayvr_ipc = { git = "https://github.com/olekolek1000/wayvr-ipc.git", rev = "a72587d23f3bb8624d9aeb1f13c0a21e65350f51", default-features = false }
|
||||
|
||||
@@ -13,7 +13,7 @@ use wgui::{
|
||||
widget::{label::WidgetLabel, rectangle::WidgetRectangle},
|
||||
windowing::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra, WguiWindowPlacement},
|
||||
};
|
||||
use wlx_common::timestep::Timestep;
|
||||
use wlx_common::{dash_interface, timestep::Timestep};
|
||||
|
||||
use crate::{
|
||||
assets, settings,
|
||||
@@ -41,6 +41,7 @@ pub struct Frontend {
|
||||
globals: WguiGlobals,
|
||||
|
||||
pub settings: Box<dyn settings::SettingsIO>,
|
||||
pub interface: Box<dyn dash_interface::DashInterface>,
|
||||
|
||||
#[allow(dead_code)]
|
||||
state: ParserState,
|
||||
@@ -62,6 +63,7 @@ pub struct Frontend {
|
||||
|
||||
pub struct InitParams {
|
||||
pub settings: Box<dyn settings::SettingsIO>,
|
||||
pub interface: Box<dyn dash_interface::DashInterface>,
|
||||
}
|
||||
|
||||
pub type RcFrontend = Rc<RefCell<Frontend>>;
|
||||
@@ -139,6 +141,7 @@ impl Frontend {
|
||||
},
|
||||
timestep,
|
||||
settings: params.settings,
|
||||
interface: params.interface,
|
||||
popup_manager,
|
||||
toast_manager,
|
||||
window_audio_settings: WguiWindow::default(),
|
||||
|
||||
@@ -15,3 +15,4 @@ winit = "0.30.12"
|
||||
vulkano = { workspace = true }
|
||||
vulkano-shaders = { workspace = true }
|
||||
dash-frontend = { path = "../dash-frontend/" }
|
||||
wlx-common = { path = "../wlx-common" }
|
||||
|
||||
@@ -4,6 +4,7 @@ use dash_frontend::{
|
||||
settings::{self, SettingsIO},
|
||||
};
|
||||
use wgui::layout::RcLayout;
|
||||
use wlx_common::dash_interface_emulated::DashInterfaceEmulated;
|
||||
|
||||
struct SimpleSettingsIO {
|
||||
settings: settings::Settings,
|
||||
@@ -59,9 +60,11 @@ pub struct TestbedDashboard {
|
||||
impl TestbedDashboard {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
let settings = SimpleSettingsIO::new();
|
||||
let interface = DashInterfaceEmulated::new();
|
||||
|
||||
let (frontend, layout) = frontend::Frontend::new(frontend::InitParams {
|
||||
settings: Box::new(settings),
|
||||
interface: Box::new(interface),
|
||||
})?;
|
||||
Ok(Self { frontend, layout })
|
||||
}
|
||||
|
||||
@@ -10,3 +10,5 @@ glam = { workspace = true }
|
||||
chrono = "0.4.42"
|
||||
idmap = { workspace = true, features = ["serde"] }
|
||||
idmap-derive = { workspace = true }
|
||||
wayvr_ipc = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
|
||||
25
wlx-common/src/dash_interface.rs
Normal file
25
wlx-common/src/dash_interface.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use wayvr_ipc::{
|
||||
packet_client::{WvrDisplayCreateParams, WvrProcessLaunchParams},
|
||||
packet_server::{
|
||||
WvrDisplay, WvrDisplayHandle, WvrDisplayWindowLayout, WvrProcess, WvrProcessHandle, WvrWindow, WvrWindowHandle,
|
||||
},
|
||||
};
|
||||
|
||||
pub trait DashInterface {
|
||||
fn display_create(&mut self, params: WvrDisplayCreateParams) -> anyhow::Result<WvrDisplayHandle>;
|
||||
fn display_get(&mut self, handle: WvrDisplayHandle) -> Option<WvrDisplay>;
|
||||
fn display_list(&mut self) -> anyhow::Result<Vec<WvrDisplay>>;
|
||||
fn display_remove(&mut self, handle: WvrDisplayHandle) -> anyhow::Result<()>;
|
||||
fn display_set_visible(&mut self, handle: WvrDisplayHandle, visible: bool) -> anyhow::Result<()>;
|
||||
fn display_set_window_layout(
|
||||
&mut self,
|
||||
handle: WvrDisplayHandle,
|
||||
layout: WvrDisplayWindowLayout,
|
||||
) -> anyhow::Result<()>;
|
||||
fn display_window_list(&mut self, handle: WvrDisplayHandle) -> anyhow::Result<Vec<WvrWindow>>;
|
||||
fn process_get(&mut self, handle: WvrProcessHandle) -> Option<WvrProcess>;
|
||||
fn process_launch(&mut self, params: WvrProcessLaunchParams) -> anyhow::Result<WvrProcessHandle>;
|
||||
fn process_list(&mut self) -> anyhow::Result<Vec<WvrProcess>>;
|
||||
fn process_terminate(&mut self, handle: WvrProcessHandle) -> anyhow::Result<()>;
|
||||
fn window_set_visible(&mut self, handle: WvrWindowHandle, visible: bool) -> anyhow::Result<()>;
|
||||
}
|
||||
173
wlx-common/src/dash_interface_emulated.rs
Normal file
173
wlx-common/src/dash_interface_emulated.rs
Normal file
@@ -0,0 +1,173 @@
|
||||
use wayvr_ipc::{
|
||||
packet_client::{WvrDisplayCreateParams, WvrProcessLaunchParams},
|
||||
packet_server::{
|
||||
WvrDisplay, WvrDisplayHandle, WvrDisplayWindowLayout, WvrProcess, WvrProcessHandle, WvrWindow, WvrWindowHandle,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{dash_interface::DashInterface, gen_id};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EmuProcess {
|
||||
display_handle: WvrDisplayHandle,
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl EmuProcess {
|
||||
fn to(&self, handle: EmuProcessHandle) -> WvrProcess {
|
||||
WvrProcess {
|
||||
display_handle: self.display_handle.clone(),
|
||||
handle: WvrProcessHandle {
|
||||
generation: handle.generation,
|
||||
idx: handle.idx,
|
||||
},
|
||||
name: self.name.clone(),
|
||||
userdata: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EmuDisplay {
|
||||
width: u16,
|
||||
height: u16,
|
||||
name: String,
|
||||
visible: bool,
|
||||
layout: WvrDisplayWindowLayout,
|
||||
}
|
||||
|
||||
impl EmuDisplay {
|
||||
fn to(&self, handle: EmuDisplayHandle) -> WvrDisplay {
|
||||
WvrDisplay {
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
name: self.name.clone(),
|
||||
visible: self.visible,
|
||||
handle: WvrDisplayHandle {
|
||||
generation: handle.generation,
|
||||
idx: handle.idx,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gen_id!(EmuDisplayVec, EmuDisplay, EmuDisplayCell, EmuDisplayHandle);
|
||||
gen_id!(EmuProcessVec, EmuProcess, EmuProcessCell, EmuProcessHandle);
|
||||
|
||||
pub struct DashInterfaceEmulated {
|
||||
displays: EmuDisplayVec,
|
||||
processes: EmuProcessVec,
|
||||
}
|
||||
|
||||
impl DashInterfaceEmulated {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
displays: EmuDisplayVec::new(),
|
||||
processes: EmuProcessVec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DashInterface for DashInterfaceEmulated {
|
||||
fn display_create(&mut self, params: WvrDisplayCreateParams) -> anyhow::Result<WvrDisplayHandle> {
|
||||
let res = self.displays.add(EmuDisplay {
|
||||
width: params.width,
|
||||
height: params.height,
|
||||
name: params.name,
|
||||
visible: true,
|
||||
layout: WvrDisplayWindowLayout::Tiling,
|
||||
});
|
||||
|
||||
Ok(WvrDisplayHandle {
|
||||
generation: res.generation,
|
||||
idx: res.idx,
|
||||
})
|
||||
}
|
||||
|
||||
fn display_get(&mut self, handle: WvrDisplayHandle) -> Option<WvrDisplay> {
|
||||
let emu_handle = EmuDisplayHandle::new(handle.idx, handle.generation);
|
||||
self.displays.get(&emu_handle).map(|disp| disp.to(emu_handle))
|
||||
}
|
||||
|
||||
fn display_list(&mut self) -> anyhow::Result<Vec<WvrDisplay>> {
|
||||
Ok(self.displays.iter().map(|(handle, disp)| disp.to(handle)).collect())
|
||||
}
|
||||
|
||||
fn display_remove(&mut self, handle: WvrDisplayHandle) -> anyhow::Result<()> {
|
||||
self
|
||||
.displays
|
||||
.remove(&EmuDisplayHandle::new(handle.idx, handle.generation));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn display_set_visible(&mut self, handle: WvrDisplayHandle, visible: bool) -> anyhow::Result<()> {
|
||||
let Some(disp) = self
|
||||
.displays
|
||||
.get_mut(&EmuDisplayHandle::new(handle.idx, handle.generation))
|
||||
else {
|
||||
anyhow::bail!("Display not found");
|
||||
};
|
||||
|
||||
disp.visible = visible;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn display_set_window_layout(
|
||||
&mut self,
|
||||
handle: WvrDisplayHandle,
|
||||
layout: WvrDisplayWindowLayout,
|
||||
) -> anyhow::Result<()> {
|
||||
let Some(disp) = self
|
||||
.displays
|
||||
.get_mut(&EmuDisplayHandle::new(handle.idx, handle.generation))
|
||||
else {
|
||||
anyhow::bail!("Display not found");
|
||||
};
|
||||
|
||||
disp.layout = layout;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn display_window_list(&mut self, _handle: WvrDisplayHandle) -> anyhow::Result<Vec<WvrWindow>> {
|
||||
// stub!
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
fn process_get(&mut self, handle: WvrProcessHandle) -> Option<WvrProcess> {
|
||||
let emu_handle = EmuProcessHandle::new(handle.idx, handle.generation);
|
||||
self.processes.get(&emu_handle).map(|process| process.to(emu_handle))
|
||||
}
|
||||
|
||||
fn process_launch(&mut self, params: WvrProcessLaunchParams) -> anyhow::Result<WvrProcessHandle> {
|
||||
let res = self.processes.add(EmuProcess {
|
||||
display_handle: params.target_display,
|
||||
name: params.name,
|
||||
});
|
||||
Ok(WvrProcessHandle {
|
||||
generation: res.generation,
|
||||
idx: res.idx,
|
||||
})
|
||||
}
|
||||
|
||||
fn process_list(&mut self) -> anyhow::Result<Vec<WvrProcess>> {
|
||||
Ok(
|
||||
self
|
||||
.processes
|
||||
.iter()
|
||||
.map(|(handle, process)| process.to(handle))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn process_terminate(&mut self, handle: WvrProcessHandle) -> anyhow::Result<()> {
|
||||
self
|
||||
.processes
|
||||
.remove(&EmuProcessHandle::new(handle.idx, handle.generation));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn window_set_visible(&mut self, _handle: WvrWindowHandle, _visible: bool) -> anyhow::Result<()> {
|
||||
// stub!
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
176
wlx-common/src/handle.rs
Normal file
176
wlx-common/src/handle.rs
Normal file
@@ -0,0 +1,176 @@
|
||||
#[macro_export]
|
||||
macro_rules! gen_id {
|
||||
(
|
||||
$container_name:ident,
|
||||
$instance_name:ident,
|
||||
$cell_name:ident,
|
||||
$handle_name:ident) => {
|
||||
//ThingCell
|
||||
#[derive(Debug)]
|
||||
pub struct $cell_name {
|
||||
pub obj: $instance_name,
|
||||
pub generation: u64,
|
||||
}
|
||||
|
||||
//ThingVec
|
||||
#[derive(Debug)]
|
||||
pub struct $container_name {
|
||||
// Vec<Option<ThingCell>>
|
||||
pub vec: Vec<Option<$cell_name>>,
|
||||
|
||||
cur_generation: u64,
|
||||
}
|
||||
|
||||
//ThingHandle
|
||||
#[derive(Default, Debug, Clone, Copy, PartialEq, Hash, Eq)]
|
||||
pub struct $handle_name {
|
||||
idx: u32,
|
||||
generation: u64,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl $handle_name {
|
||||
pub const fn reset(&mut self) {
|
||||
self.generation = 0;
|
||||
}
|
||||
|
||||
pub const fn is_set(&self) -> bool {
|
||||
self.generation > 0
|
||||
}
|
||||
|
||||
pub const fn id(&self) -> u32 {
|
||||
self.idx
|
||||
}
|
||||
|
||||
pub const fn new(idx: u32, generation: u64) -> Self {
|
||||
Self { idx, generation }
|
||||
}
|
||||
}
|
||||
|
||||
//ThingVec
|
||||
impl $container_name {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
vec: Vec::new(),
|
||||
cur_generation: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = ($handle_name, &$instance_name)> {
|
||||
self.vec.iter().enumerate().filter_map(|(idx, opt_cell)| {
|
||||
opt_cell.as_ref().map(|cell| {
|
||||
let handle = $container_name::get_handle(&cell, idx);
|
||||
(handle, &cell.obj)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn iter_mut(
|
||||
&mut self,
|
||||
) -> impl Iterator<Item = ($handle_name, &mut $instance_name)> {
|
||||
self.vec
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
.filter_map(|(idx, opt_cell)| {
|
||||
opt_cell.as_mut().map(|cell| {
|
||||
let handle = $container_name::get_handle(&cell, idx);
|
||||
(handle, &mut cell.obj)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub const fn get_handle(cell: &$cell_name, idx: usize) -> $handle_name {
|
||||
$handle_name {
|
||||
idx: idx as u32,
|
||||
generation: cell.generation,
|
||||
}
|
||||
}
|
||||
|
||||
fn find_unused_idx(&mut self) -> Option<u32> {
|
||||
for (num, obj) in self.vec.iter().enumerate() {
|
||||
if obj.is_none() {
|
||||
return Some(num as u32);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn add(&mut self, obj: $instance_name) -> $handle_name {
|
||||
self.cur_generation += 1;
|
||||
let generation = self.cur_generation;
|
||||
|
||||
let unused_idx = self.find_unused_idx();
|
||||
|
||||
let idx = if let Some(idx) = unused_idx {
|
||||
idx
|
||||
} else {
|
||||
self.vec.len() as u32
|
||||
};
|
||||
|
||||
let handle = $handle_name { idx, generation };
|
||||
|
||||
let cell = $cell_name { obj, generation };
|
||||
|
||||
if let Some(idx) = unused_idx {
|
||||
self.vec[idx as usize] = Some(cell);
|
||||
} else {
|
||||
self.vec.push(Some(cell))
|
||||
}
|
||||
|
||||
handle
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, handle: &$handle_name) {
|
||||
// Out of bounds, ignore
|
||||
if handle.idx as usize >= self.vec.len() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove only if the generation matches
|
||||
if let Some(cell) = &self.vec[handle.idx as usize] {
|
||||
if cell.generation == handle.generation {
|
||||
self.vec[handle.idx as usize] = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, handle: &$handle_name) -> Option<&$instance_name> {
|
||||
// Out of bounds, ignore
|
||||
if handle.idx as usize >= self.vec.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(cell) = &self.vec[handle.idx as usize] {
|
||||
if cell.generation == handle.generation {
|
||||
return Some(&cell.obj);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, handle: &$handle_name) -> Option<&mut $instance_name> {
|
||||
// Out of bounds, ignore
|
||||
if handle.idx as usize >= self.vec.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(cell) = &mut self.vec[handle.idx as usize] {
|
||||
if cell.generation == handle.generation {
|
||||
return Some(&mut cell.obj);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/* Example usage:
|
||||
gen_id!(ThingVec, ThingInstance, ThingCell, ThingHandle);
|
||||
|
||||
struct ThingInstance {}
|
||||
|
||||
impl ThingInstance {}
|
||||
*/
|
||||
@@ -1,6 +1,9 @@
|
||||
pub mod astr_containers;
|
||||
pub mod common;
|
||||
pub mod config;
|
||||
pub mod dash_interface;
|
||||
pub mod dash_interface_emulated;
|
||||
mod handle;
|
||||
pub mod overlays;
|
||||
pub mod timestep;
|
||||
pub mod windowing;
|
||||
|
||||
@@ -80,6 +80,7 @@ tracing = "0.1.43"
|
||||
vulkano = { workspace = true }
|
||||
vulkano-shaders = { workspace = true }
|
||||
wgui = { path = "../wgui" }
|
||||
wayvr_ipc = { workspace = true }
|
||||
|
||||
################################
|
||||
#WayVR-only deps
|
||||
@@ -96,7 +97,6 @@ uuid = { version = "1.19.0", features = ["v4", "fast-rng"], optional = true }
|
||||
wayland-client = { workspace = true, optional = true }
|
||||
wayland-egl = { version = "0.32.8", optional = true }
|
||||
bytes = { version = "1.11.0", optional = true }
|
||||
wayvr_ipc = { git = "https://github.com/olekolek1000/wayvr-ipc.git", rev = "a72587d23f3bb8624d9aeb1f13c0a21e65350f51", default-features = false, optional = true }
|
||||
rust-embed = { workspace = true }
|
||||
signal-hook = "0.3.18"
|
||||
################################
|
||||
@@ -121,6 +121,5 @@ wayvr = [
|
||||
"dep:wayland-client",
|
||||
"dep:wayland-egl",
|
||||
"dep:bytes",
|
||||
"dep:wayvr_ipc",
|
||||
]
|
||||
as-raw-xcb-connection = []
|
||||
|
||||
Reference in New Issue
Block a user