feat: wayland feature

This commit is contained in:
Nova
2022-11-09 11:13:07 -05:00
parent 6b578fe044
commit 41e76c9d0a
5 changed files with 22 additions and 8 deletions

View File

@@ -31,7 +31,7 @@ send_wrapper = "0.6.0"
prisma = "0.1.1"
slog = "2.7.0"
slog-stdlog = "4.1.1"
xkbcommon = { version = "0.5.0", default-features = false }
xkbcommon = { version = "0.5.0", default-features = false, optional = true }
stardust-xr = "0.7.1"
directories = "4.0.1"
serde = { version = "1.0.145", features = ["derive"] }
@@ -46,3 +46,8 @@ git = "https://github.com/Smithay/smithay.git"
default-features = false
features = ["desktop", "renderer_gl", "wayland_frontend"]
version = "*"
optional = true
[features]
default = ["wayland"]
wayland = ["dep:smithay", "dep:xkbcommon"]

View File

@@ -1,6 +1,7 @@
mod core;
mod nodes;
mod objects;
#[cfg(feature = "wayland")]
mod wayland;
use crate::core::destroy_queue;
@@ -8,13 +9,11 @@ use crate::nodes::{drawable, hmd, input};
use crate::objects::input::mouse_pointer::MousePointer;
use crate::objects::input::sk_controller::SkController;
use crate::objects::input::sk_hand::SkHand;
use crate::wayland::Wayland;
use self::core::eventloop::EventLoop;
use anyhow::Result;
use clap::Parser;
use directories::ProjectDirs;
use slog::Drain;
use std::sync::Arc;
use stereokit::input::Handed;
use stereokit::lifecycle::DepthMode;
@@ -42,8 +41,6 @@ struct CliArgs {
fn main() -> Result<()> {
let project_dirs = ProjectDirs::from("", "", "stardust").unwrap();
let cli_args = Arc::new(CliArgs::parse());
let log = ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), slog::o!());
slog_stdlog::init()?;
let mut stereokit = Settings::default()
.app_name("Stardust XR")
@@ -105,11 +102,13 @@ fn main() -> Result<()> {
.spawn(move || event_loop(handle_sender, event_stop_rx))?;
let _tokio_handle = handle_receiver.blocking_recv()?.enter();
let mut wayland = Wayland::new(log)?;
#[cfg(feature = "wayland")]
let mut wayland = wayland::Wayland::new()?;
println!("Stardust ready!");
stereokit.run(
|sk, draw_ctx| {
hmd::frame(sk);
#[cfg(feature = "wayland")]
wayland.frame(sk);
destroy_queue::clear();
@@ -128,6 +127,7 @@ fn main() -> Result<()> {
nodes::root::Root::logic_step(sk.time_elapsed());
drawable::draw(sk, draw_ctx);
#[cfg(feature = "wayland")]
wayland.make_context_current();
},
|_| {
@@ -135,6 +135,7 @@ fn main() -> Result<()> {
},
);
#[cfg(feature = "wayland")]
drop(wayland);
let _ = event_stop_tx.send(());

View File

@@ -45,6 +45,7 @@ impl EnvironmentItem {
}
fn get_path_flex(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<Vec<u8>> {
#[allow(unreachable_patterns)]
let path: Result<String> = match &node.item.get().unwrap().specialization {
ItemType::Environment(env) => Ok(env.path.clone()),
_ => Err(anyhow!("")),

View File

@@ -9,6 +9,7 @@ use crate::core::node_collections::LifeLinkedNodeList;
use crate::core::registry::Registry;
use crate::nodes::alias::AliasInfo;
use crate::nodes::fields::find_field;
#[cfg(feature = "wayland")]
use crate::wayland::panel_item::{PanelItem, ITEM_TYPE_INFO_PANEL};
use anyhow::{anyhow, ensure, Result};
use lazy_static::lazy_static;
@@ -152,6 +153,7 @@ pub trait ItemSpecialization {
pub enum ItemType {
Environment(EnvironmentItem),
#[cfg(feature = "wayland")]
Panel(PanelItem),
}
impl Deref for ItemType {
@@ -160,6 +162,7 @@ impl Deref for ItemType {
fn deref(&self) -> &Self::Target {
match self {
ItemType::Environment(item) => item,
#[cfg(feature = "wayland")]
ItemType::Panel(item) => item,
}
}
@@ -325,6 +328,7 @@ pub fn create_interface(client: &Arc<Client>) {
fn type_info(name: &str) -> Result<&'static TypeInfo> {
match name {
"environment" => Ok(&ITEM_TYPE_INFO_ENVIRONMENT),
#[cfg(feature = "wayland")]
"panel" => Ok(&ITEM_TYPE_INFO_PANEL),
_ => Err(anyhow!("Invalid item type")),
}

View File

@@ -14,7 +14,7 @@ use crate::wayland::state::ClientState;
use anyhow::{ensure, Result};
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use slog::Logger;
use slog::Drain;
use smithay::{
backend::{egl::EGLContext, renderer::gles2::Gles2Renderer},
reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket, Resource},
@@ -63,7 +63,10 @@ pub struct Wayland {
state: Arc<Mutex<WaylandState>>,
}
impl Wayland {
pub fn new(log: Logger) -> Result<Self> {
pub fn new() -> Result<Self> {
let log = ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), slog::o!());
slog_stdlog::init()?;
let egl_raw_handles = get_sk_egl()?;
let renderer = unsafe {
Gles2Renderer::new(