Skip to content

Commit

Permalink
WayVR: WayVRDisplayList ui type, toggle display visibility and pause …
Browse files Browse the repository at this point in the history
…rendering of them
  • Loading branch information
olekolek1000 committed Oct 20, 2024
1 parent 8a56711 commit 5443cc7
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 95 deletions.
10 changes: 3 additions & 7 deletions src/backend/openvr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::{
};

#[cfg(feature = "wayvr")]
use crate::overlays::wayvr::action_wayvr;
use crate::overlays::wayvr::wayvr_action;

pub mod helpers;
pub mod input;
Expand Down Expand Up @@ -266,12 +266,8 @@ pub fn openvr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(),
}
},
#[cfg(feature = "wayvr")]
TaskType::WayVR(task) => {
if let Some(overlay) =
action_wayvr(&task.catalog_name, &task.app_name, &mut state)
{
overlays.add(overlay);
}
TaskType::WayVR(action) => {
wayvr_action(&mut state, &mut overlays, &action);
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/backend/openxr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{
};

#[cfg(feature = "wayvr")]
use crate::overlays::wayvr::action_wayvr;
use crate::overlays::wayvr::wayvr_action;

mod helpers;
mod input;
Expand Down Expand Up @@ -491,12 +491,8 @@ pub fn openxr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(),
_ => {}
},
#[cfg(feature = "wayvr")]
TaskType::WayVR(task) => {
if let Some(overlay) =
action_wayvr(&task.catalog_name, &task.app_name, &mut app_state)
{
overlays.add(overlay);
}
TaskType::WayVR(action) => {
wayvr_action(&mut app_state, &mut overlays, &action);
}
}
}
Expand Down
14 changes: 4 additions & 10 deletions src/backend/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use std::{
time::Instant,
};

#[cfg(feature = "wayvr")]
use std::sync::Arc;

use serde::Deserialize;

use crate::state::AppState;

#[cfg(feature = "wayvr")]
use crate::overlays::wayvr::WayVRAction;

use super::{
common::OverlaySelector,
overlay::{OverlayBackend, OverlayState},
Expand Down Expand Up @@ -52,12 +52,6 @@ pub enum SystemTask {
ShowHide,
}

#[cfg(feature = "wayvr")]
pub struct WayVRTask {
pub catalog_name: Arc<str>,
pub app_name: Arc<str>,
}

pub type OverlayTask = dyn FnOnce(&mut AppState, &mut OverlayState) + Send;
pub type CreateOverlayTask =
dyn FnOnce(&mut AppState) -> Option<(OverlayState, Box<dyn OverlayBackend>)> + Send;
Expand All @@ -69,7 +63,7 @@ pub enum TaskType {
DropOverlay(OverlaySelector),
System(SystemTask),
#[cfg(feature = "wayvr")]
WayVR(WayVRTask),
WayVR(WayVRAction),
}

#[derive(Deserialize, Clone, Copy)]
Expand Down
11 changes: 10 additions & 1 deletion src/backend/wayvr/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use smithay::{
wayland::shell::xdg::ToplevelSurface,
};

use crate::gen_id;
use crate::{backend::overlay::OverlayID, gen_id};

use super::{
client::WayVRManager, comp::send_frames_surface_tree, egl_data, smithay_wrapper, window,
Expand Down Expand Up @@ -47,6 +47,8 @@ pub struct Display {
pub width: u32,
pub height: u32,
pub name: String,
pub visible: bool,
pub overlay_id: Option<OverlayID>,
wm: Rc<RefCell<window::WindowManager>>,
displayed_windows: Vec<DisplayWindow>,
wayland_env: super::WaylandEnv,
Expand Down Expand Up @@ -112,6 +114,8 @@ impl Display {
gles_texture,
wayland_env,
processes: Vec::new(),
visible: true,
overlay_id: None,
})
}

Expand Down Expand Up @@ -216,6 +220,11 @@ impl Display {
None
}

pub fn set_visible(&mut self, visible: bool) {
log::info!("Display \"{}\" visible: {}", self.name.as_str(), visible);
self.visible = visible;
}

pub fn send_mouse_move(&self, manager: &mut WayVRManager, x: u32, y: u32) {
if let Some(window_handle) = self.get_hovered_window(x, y) {
let wm = self.wm.borrow();
Expand Down
24 changes: 14 additions & 10 deletions src/backend/wayvr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl WaylandEnv {
pub struct WayVR {
time_start: u64,
gles_renderer: GlesRenderer,
displays: display::DisplayVec,
pub displays: display::DisplayVec,
manager: client::WayVRManager,
wm: Rc<RefCell<window::WindowManager>>,
egl_data: Rc<egl_data::EGLData>,
Expand Down Expand Up @@ -102,13 +102,19 @@ impl WayVR {

pub fn tick_display(&mut self, display: display::DisplayHandle) -> anyhow::Result<()> {
// millis since the start of wayvr
let time_ms = get_millis() - self.time_start;

let display = self
.displays
.get(&display)
.ok_or(anyhow::anyhow!("Invalid display handle"))?;

let time_ms = get_millis() - self.time_start;

if !display.visible {
// Display is invisible, do not render
return Ok(());
}

display.tick_render(&mut self.gles_renderer, time_ms)?;

Ok(())
Expand Down Expand Up @@ -172,6 +178,12 @@ impl WayVR {
self.manager.send_key(virtual_key, down);
}

pub fn set_display_visible(&mut self, display: display::DisplayHandle, visible: bool) {
if let Some(display) = self.displays.get_mut(&display) {
display.set_visible(visible);
}
}

pub fn get_dmabuf_data(&self, display: display::DisplayHandle) -> Option<egl_data::DMAbufData> {
self.displays
.get(&display)
Expand All @@ -188,14 +200,6 @@ impl WayVR {
}
None
}

pub fn get_display_by_handle(
&self,
display: display::DisplayHandle,
) -> Option<&display::Display> {
self.displays.get(&display)
}

pub fn create_display(
&mut self,
width: u32,
Expand Down
4 changes: 2 additions & 2 deletions src/config_wayvr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "wayvr"))]
compile_error!("WayVR feature is not enabled");

use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -38,7 +38,7 @@ impl WayVRCatalog {
pub struct WayVRConfig {
pub version: u32,
pub catalogs: HashMap<String, WayVRCatalog>,
pub displays: HashMap<String, WayVRDisplay>,
pub displays: BTreeMap<String, WayVRDisplay>, // sorted alphabetically
}

impl WayVRConfig {
Expand Down
17 changes: 4 additions & 13 deletions src/gui/modular/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
};

#[cfg(feature = "wayvr")]
use crate::backend::task::WayVRTask;
use crate::overlays::wayvr::WayVRAction;

use super::{ExecArgs, ModularControl, ModularData};

Expand Down Expand Up @@ -138,10 +138,7 @@ pub enum ButtonAction {
action: OverlayAction,
},
#[cfg(feature = "wayvr")]
WayVR {
catalog_name: Arc<str>,
app_name: Arc<str>,
},
WayVR(WayVRAction),
Window {
target: Arc<str>,
action: WindowAction,
Expand Down Expand Up @@ -336,14 +333,8 @@ fn handle_action(action: &ButtonAction, press: &mut PressData, app: &mut AppStat
ButtonAction::Overlay { target, action } => run_overlay(target, action, app),
ButtonAction::Window { target, action } => run_window(target, action, app),
#[cfg(feature = "wayvr")]
ButtonAction::WayVR {
catalog_name,
app_name,
} => {
app.tasks.enqueue(TaskType::WayVR(WayVRTask {
catalog_name: catalog_name.clone(),
app_name: app_name.clone(),
}));
ButtonAction::WayVR(action) => {
app.tasks.enqueue(TaskType::WayVR(action.clone()));
}
ButtonAction::VirtualKey { keycode, action } => app
.hid_provider
Expand Down
70 changes: 67 additions & 3 deletions src/gui/modular/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use crate::{
graphics::dds::WlxCommandBufferDds, state::AppState,
};

#[cfg(feature = "wayvr")]
use crate::overlays::wayvr::{WayVRAction, WayVRDisplayClickAction};

use self::{
button::{modular_button_init, ButtonAction, ButtonData, OverlayAction},
label::{modular_label_init, LabelContent, LabelData},
Expand Down Expand Up @@ -119,6 +122,14 @@ pub enum ModularElement {
bg_color: Arc<str>,
catalog_name: Arc<str>,
},
// Ignored if "wayvr" feature is not enabled
WayVRDisplayList {
rect: [f32; 4],
corner_radius: Option<f32>,
font_size: isize,
fg_color: Arc<str>,
bg_color: Arc<str>,
},
}

#[derive(Deserialize, Clone)]
Expand Down Expand Up @@ -440,10 +451,10 @@ pub fn modular_canvas(
);

let data = ButtonData {
click_down: Some(vec![ButtonAction::WayVR {
click_up: Some(vec![ButtonAction::WayVR(WayVRAction::AppClick {
catalog_name: catalog_name.clone(),
app_name: Arc::from(app.name.as_str()),
}]),
})]),
..Default::default()
};

Expand All @@ -456,7 +467,60 @@ pub fn modular_canvas(
}
#[cfg(not(feature = "wayvr"))]
{
log::error!("WayVR feature is not available, ignoring");
log::error!("WayVR feature is not enabled, ignoring");
}
}
#[allow(unused_variables)]
ModularElement::WayVRDisplayList {
rect: [x, y, w, h],
corner_radius,
font_size,
fg_color,
bg_color,
} => {
#[cfg(feature = "wayvr")]
{
let mut button_x = *x;
let button_y = *y;
let displays = &state.session.wayvr_config.displays;
for (display_name, display) in displays {
let button_w: f32 = (*w / displays.len() as f32).min(80.0);
let button_h: f32 = *h;

canvas.bg_color = color_parse(bg_color).unwrap_or(*FALLBACK_COLOR);
canvas.fg_color = color_parse(fg_color).unwrap_or(*FALLBACK_COLOR);
canvas.font_size = *font_size;

let button = canvas.button(
button_x + 2.,
button_y + 2.,
button_w - 4.,
button_h - 4.,
corner_radius.unwrap_or_default(),
Arc::from(display_name.as_str()),
);

let data = ButtonData {
click_up: Some(vec![ButtonAction::WayVR(WayVRAction::DisplayClick {
display_name: Arc::from(display_name.as_str()),
action: WayVRDisplayClickAction::ToggleVisibility,
})]),
long_click_up: Some(vec![ButtonAction::WayVR(
WayVRAction::DisplayClick {
display_name: Arc::from(display_name.as_str()),
action: WayVRDisplayClickAction::Reset,
},
)]),
..Default::default()
};

modular_button_init(button, &data);
button_x += button_w;
}
}
#[cfg(not(feature = "wayvr"))]
{
log::error!("WayVR feature is not enabled, ignoring")
}
}
}
Expand Down
Loading

0 comments on commit 5443cc7

Please sign in to comment.