WayVRData → WayVRState in the RefCell

This commit is contained in:
galister
2025-12-26 17:40:22 +09:00
parent dc6d03605f
commit 400952177e
10 changed files with 70 additions and 149 deletions

View File

@@ -230,8 +230,6 @@ pub fn openvr_run(show_by_default: bool, headless: bool) -> Result<(), BackendEr
let _ = adjust_gain(&mut settings_mgr, channel, value); let _ = adjust_gain(&mut settings_mgr, channel, value);
} }
}, },
#[cfg(feature = "wayvr")]
TaskType::WayVR(_action) => { /* TODO */ }
} }
} }

View File

@@ -492,8 +492,6 @@ pub fn openxr_run(show_by_default: bool, headless: bool) -> Result<(), BackendEr
} }
#[cfg(feature = "openvr")] #[cfg(feature = "openvr")]
TaskType::OpenVR(_) => {} TaskType::OpenVR(_) => {}
#[cfg(feature = "wayvr")]
TaskType::WayVR(_action) => { /* TODO */ }
} }
} }

View File

@@ -13,9 +13,6 @@ use crate::{
windowing::{OverlaySelector, window::OverlayWindowConfig}, windowing::{OverlaySelector, window::OverlayWindowConfig},
}; };
#[cfg(feature = "wayvr")]
use crate::backend::wayvr::WayVRAction;
static TASK_AUTO_INCREMENT: AtomicUsize = AtomicUsize::new(0); static TASK_AUTO_INCREMENT: AtomicUsize = AtomicUsize::new(0);
struct AppTask { struct AppTask {
@@ -100,8 +97,6 @@ pub enum TaskType {
Playspace(PlayspaceTask), Playspace(PlayspaceTask),
#[cfg(feature = "openvr")] #[cfg(feature = "openvr")]
OpenVR(OpenVrTask), OpenVR(OpenVrTask),
#[cfg(feature = "wayvr")]
WayVR(WayVRAction),
} }
#[derive(Deserialize, Clone, Copy)] #[derive(Deserialize, Clone, Copy)]

View File

@@ -8,7 +8,6 @@ pub mod window;
use anyhow::Context; use anyhow::Context;
use comp::Application; use comp::Application;
use process::ProcessVec; use process::ProcessVec;
use serde::Deserialize;
use slotmap::SecondaryMap; use slotmap::SecondaryMap;
use smallvec::SmallVec; use smallvec::SmallVec;
use smithay::{ use smithay::{
@@ -122,10 +121,6 @@ pub struct WayVRState {
overlay_to_window: SecondaryMap<OverlayID, window::WindowHandle>, overlay_to_window: SecondaryMap<OverlayID, window::WindowHandle>,
} }
pub struct WayVR {
pub state: WayVRState,
}
pub enum MouseIndex { pub enum MouseIndex {
Left, Left,
Center, Center,
@@ -136,7 +131,7 @@ pub enum TickTask {
NewExternalProcess(ExternalProcessRequest), // Call WayVRCompositor::add_client after receiving this message NewExternalProcess(ExternalProcessRequest), // Call WayVRCompositor::add_client after receiving this message
} }
impl WayVR { impl WayVRState {
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] #[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
pub fn new( pub fn new(
gfx: Arc<WGfx>, gfx: Arc<WGfx>,
@@ -144,7 +139,7 @@ impl WayVR {
config: Config, config: Config,
signals: SyncEventQueue<WayVRSignal>, signals: SyncEventQueue<WayVRSignal>,
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
log::info!("Initializing WayVR"); log::info!("Initializing WayVR server");
let display: wayland_server::Display<Application> = wayland_server::Display::new()?; let display: wayland_server::Display<Application> = wayland_server::Display::new()?;
let dh = display.handle(); let dh = display.handle();
let compositor = compositor::CompositorState::new::<Application>(&dh); let compositor = compositor::CompositorState::new::<Application>(&dh);
@@ -235,7 +230,7 @@ impl WayVR {
let time_start = get_millis(); let time_start = get_millis();
let state = WayVRState { Ok(WayVRState {
time_start, time_start,
manager: client::WayVRCompositor::new(state, display, seat_keyboard, seat_pointer)?, manager: client::WayVRCompositor::new(state, display, seat_keyboard, seat_pointer)?,
processes: ProcessVec::new(), processes: ProcessVec::new(),
@@ -248,9 +243,7 @@ impl WayVR {
mouse_freeze: Instant::now(), mouse_freeze: Instant::now(),
window_to_overlay: HashMap::new(), window_to_overlay: HashMap::new(),
overlay_to_window: SecondaryMap::new(), overlay_to_window: SecondaryMap::new(),
}; })
Ok(Self { state })
} }
#[allow(clippy::too_many_lines, clippy::cognitive_complexity)] #[allow(clippy::too_many_lines, clippy::cognitive_complexity)]
@@ -258,7 +251,7 @@ impl WayVR {
let mut tasks: Vec<TickTask> = Vec::new(); let mut tasks: Vec<TickTask> = Vec::new();
app.ipc_server.tick(&mut ipc_server::TickParams { app.ipc_server.tick(&mut ipc_server::TickParams {
wayland_state: &mut self.state, wayland_state: self,
input_state: &app.input_state, input_state: &app.input_state,
tasks: &mut tasks, tasks: &mut tasks,
signals: &app.wayvr_signals, signals: &app.wayvr_signals,
@@ -267,14 +260,14 @@ impl WayVR {
// Tick all child processes // Tick all child processes
let mut to_remove: SmallVec<[process::ProcessHandle; 2]> = SmallVec::new(); let mut to_remove: SmallVec<[process::ProcessHandle; 2]> = SmallVec::new();
for (handle, process) in self.state.processes.iter_mut() { for (handle, process) in self.processes.iter_mut() {
if !process.is_running() { if !process.is_running() {
to_remove.push(handle); to_remove.push(handle);
} }
} }
for p_handle in &to_remove { for p_handle in &to_remove {
self.state.processes.remove(p_handle); self.processes.remove(p_handle);
} }
if !to_remove.is_empty() { if !to_remove.is_empty() {
@@ -283,20 +276,20 @@ impl WayVR {
)); ));
} }
while let Some(task) = self.state.tasks.read() { while let Some(task) = self.tasks.read() {
match task { match task {
WayVRTask::NewExternalProcess(req) => { WayVRTask::NewExternalProcess(req) => {
tasks.push(TickTask::NewExternalProcess(req)); tasks.push(TickTask::NewExternalProcess(req));
} }
WayVRTask::NewToplevel(client_id, toplevel) => { WayVRTask::NewToplevel(client_id, toplevel) => {
// Attach newly created toplevel surfaces to displays // Attach newly created toplevel surfaces to displays
for client in &self.state.manager.clients { for client in &self.manager.clients {
if client.client.id() != client_id { if client.client.id() != client_id {
continue; continue;
} }
let Some(process_handle) = let Some(process_handle) =
process::find_by_pid(&self.state.processes, client.pid) process::find_by_pid(&self.processes, client.pid)
else { else {
log::error!( log::error!(
"WayVR window creation failed: Unexpected process ID {}. It wasn't registered before.", "WayVR window creation failed: Unexpected process ID {}. It wasn't registered before.",
@@ -305,7 +298,7 @@ impl WayVR {
continue; continue;
}; };
let window_handle = self.state.wm.create_window(&toplevel, process_handle); let window_handle = self.wm.create_window(&toplevel, process_handle);
let title: Arc<str> = with_states(toplevel.wl_surface(), |states| { let title: Arc<str> = with_states(toplevel.wl_surface(), |states| {
states states
@@ -323,7 +316,7 @@ impl WayVR {
create_wl_window_overlay( create_wl_window_overlay(
title, title,
app.xr_backend, app.xr_backend,
app.wayland_server.as_ref().unwrap().clone(), app.wayvr_server.as_ref().unwrap().clone(),
window_handle, window_handle,
) )
.inspect_err(|e| { .inspect_err(|e| {
@@ -334,37 +327,34 @@ impl WayVR {
}), }),
))); )));
//TODO: populate window_to_overlay
app.wayvr_signals.send(WayVRSignal::BroadcastStateChanged( app.wayvr_signals.send(WayVRSignal::BroadcastStateChanged(
packet_server::WvrStateChanged::WindowCreated, packet_server::WvrStateChanged::WindowCreated,
)); ));
} }
} }
WayVRTask::DropToplevel(client_id, toplevel) => { WayVRTask::DropToplevel(client_id, toplevel) => {
for client in &self.state.manager.clients { for client in &self.manager.clients {
if client.client.id() != client_id { if client.client.id() != client_id {
continue; continue;
} }
let Some(window_handle) = self.state.wm.find_window_handle(&toplevel) let Some(window_handle) = self.wm.find_window_handle(&toplevel) else {
else {
log::warn!("DropToplevel: Couldn't find matching window handle"); log::warn!("DropToplevel: Couldn't find matching window handle");
continue; continue;
}; };
if let Some(oid) = self.state.window_to_overlay.remove(&window_handle) { if let Some(oid) = self.window_to_overlay.remove(&window_handle) {
app.tasks.enqueue(TaskType::Overlay(OverlayTask::Drop( app.tasks.enqueue(TaskType::Overlay(OverlayTask::Drop(
OverlaySelector::Id(oid), OverlaySelector::Id(oid),
))); )));
self.state.overlay_to_window.remove(oid); self.overlay_to_window.remove(oid);
} }
self.state.wm.remove_window(window_handle); self.wm.remove_window(window_handle);
} }
} }
WayVRTask::ProcessTerminationRequest(process_handle) => { WayVRTask::ProcessTerminationRequest(process_handle) => {
if let Some(process) = self.state.processes.get_mut(&process_handle) { if let Some(process) = self.processes.get_mut(&process_handle) {
process.terminate(); process.terminate();
} }
@@ -373,31 +363,28 @@ impl WayVR {
} }
} }
self.state.manager.tick_wayland(&mut self.state.processes)?; self.manager.tick_wayland(&mut self.processes)?;
if self.state.ticks.is_multiple_of(200) { if self.ticks.is_multiple_of(200) {
self.state.manager.cleanup_clients(); self.manager.cleanup_clients();
self.state.manager.cleanup_handles(); self.manager.cleanup_handles();
} }
self.state.ticks += 1; self.ticks += 1;
Ok(tasks) Ok(tasks)
} }
pub fn terminate_process(&mut self, process_handle: process::ProcessHandle) { pub fn terminate_process(&mut self, process_handle: process::ProcessHandle) {
self.state self.tasks
.tasks
.send(WayVRTask::ProcessTerminationRequest(process_handle)); .send(WayVRTask::ProcessTerminationRequest(process_handle));
} }
pub fn overlay_added(&mut self, oid: OverlayID, window: window::WindowHandle) { pub fn overlay_added(&mut self, oid: OverlayID, window: window::WindowHandle) {
self.state.overlay_to_window.insert(oid, window); self.overlay_to_window.insert(oid, window);
self.state.window_to_overlay.insert(window, oid); self.window_to_overlay.insert(window, oid);
}
} }
impl WayVRState {
pub fn send_mouse_move(&mut self, handle: window::WindowHandle, x: u32, y: u32) { pub fn send_mouse_move(&mut self, handle: window::WindowHandle, x: u32, y: u32) {
if self.mouse_freeze > Instant::now() { if self.mouse_freeze > Instant::now() {
return; return;
@@ -544,25 +531,6 @@ pub struct SpawnProcessResult {
pub child: std::process::Child, pub child: std::process::Child,
} }
#[derive(Deserialize, Clone)]
pub enum WayVRDisplayClickAction {
ToggleVisibility,
Reset,
}
#[derive(Deserialize, Clone)]
pub enum WayVRAction {
AppClick {
catalog_name: Arc<str>,
app_name: Arc<str>,
},
DisplayClick {
display_name: Arc<str>,
action: WayVRDisplayClickAction,
},
ToggleDashboard,
}
struct SurfaceBufWithImageContainer { struct SurfaceBufWithImageContainer {
inner: RefCell<SurfaceBufWithImage>, inner: RefCell<SurfaceBufWithImage>,
} }

View File

@@ -15,14 +15,13 @@ use wlx_common::{common::LeftRight, config::GeneralConfig, windowing::Positionin
use crate::{ use crate::{
backend::{ backend::{
task::{TaskContainer, TaskType}, task::TaskContainer,
wayvr::{self, WayVRAction}, wayvr::{self, WayVRState},
}, },
config::load_config_with_conf_d, config::load_config_with_conf_d,
config_io, config_io,
graphics::WGfxExtras, graphics::WGfxExtras,
ipc::{event_queue::SyncEventQueue, signal::WayVRSignal}, ipc::{event_queue::SyncEventQueue, signal::WayVRSignal},
overlays::wayvr::WayVRData,
}; };
// Flat version of RelativeTo // Flat version of RelativeTo
@@ -206,7 +205,7 @@ impl WayVRConfig {
config: &GeneralConfig, config: &GeneralConfig,
tasks: &mut TaskContainer, tasks: &mut TaskContainer,
signals: SyncEventQueue<WayVRSignal>, signals: SyncEventQueue<WayVRSignal>,
) -> anyhow::Result<Rc<RefCell<WayVRData>>> { ) -> anyhow::Result<Rc<RefCell<WayVRState>>> {
let primary_count = self let primary_count = self
.displays .displays
.iter() .iter()
@@ -222,15 +221,12 @@ impl WayVRConfig {
if let Some(b) = app.shown_at_start if let Some(b) = app.shown_at_start
&& b && b
{ {
tasks.enqueue(TaskType::WayVR(WayVRAction::AppClick { //CLEANUP: is this needed?
catalog_name: Arc::from(catalog_name.as_str()),
app_name: Arc::from(app.name.as_str()),
}));
} }
} }
} }
Ok(Rc::new(RefCell::new(WayVRData::new( Ok(Rc::new(RefCell::new(WayVRState::new(
gfx, gfx,
gfx_extras, gfx_extras,
Self::get_wayvr_config(config, self)?, Self::get_wayvr_config(config, self)?,

View File

@@ -26,9 +26,6 @@ use crate::{
windowing::OverlaySelector, windowing::OverlaySelector,
}; };
#[cfg(feature = "wayvr")]
use crate::backend::wayvr::WayVRAction;
pub const BUTTON_EVENTS: [( pub const BUTTON_EVENTS: [(
&str, &str,
EventListenerKind, EventListenerKind,
@@ -200,8 +197,7 @@ pub(super) fn setup_custom_button<S: 'static>(
return Ok(EventResult::Pass); return Ok(EventResult::Pass);
} }
app.tasks //FIXME
.enqueue(TaskType::WayVR(WayVRAction::ToggleDashboard));
Ok(EventResult::Consumed) Ok(EventResult::Consumed)
}), }),
"::SetToggle" => { "::SetToggle" => {

View File

@@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
use wayvr_ipc::packet_server; use wayvr_ipc::packet_server;
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
use crate::{backend::wayvr, overlays::wayvr::WayVRData}; use crate::backend::wayvr::{self, WayVRState};
use crate::{ use crate::{
backend::{ backend::{
@@ -18,7 +18,7 @@ use crate::{
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
fn process_tick_tasks( fn process_tick_tasks(
tick_tasks: Vec<backend::wayvr::TickTask>, tick_tasks: Vec<backend::wayvr::TickTask>,
r_wayvr: &Rc<RefCell<WayVRData>>, r_wayvr: &Rc<RefCell<WayVRState>>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
for tick_task in tick_tasks { for tick_task in tick_tasks {
match tick_task { match tick_task {
@@ -27,13 +27,9 @@ fn process_tick_tasks(
log::info!("Registering external process with PID {}", request.pid); log::info!("Registering external process with PID {}", request.pid);
wayvr.data.state.add_external_process(request.pid); wayvr.add_external_process(request.pid);
wayvr wayvr.manager.add_client(wayvr::client::WayVRClient {
.data
.state
.manager
.add_client(wayvr::client::WayVRClient {
client: request.client, client: request.client,
pid: request.pid, pid: request.pid,
}); });
@@ -52,7 +48,7 @@ where
O: Default, O: Default,
{ {
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
let wayland_server = app.wayland_server.clone(); let wayvr_server = app.wayvr_server.clone();
while let Some(signal) = app.wayvr_signals.read() { while let Some(signal) = app.wayvr_signals.read() {
match signal { match signal {
@@ -80,9 +76,9 @@ where
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
{ {
if let Some(wayland_server) = wayland_server { if let Some(wayvr_server) = wayvr_server {
let tick_tasks = wayland_server.borrow_mut().data.tick_events(app)?; let tick_tasks = wayvr_server.borrow_mut().tick_events(app)?;
process_tick_tasks(tick_tasks, &wayland_server)?; process_tick_tasks(tick_tasks, &wayvr_server)?;
} }
} }

View File

@@ -1,8 +1,7 @@
use glam::{Affine2, Affine3A, Quat, Vec3, vec3}; use glam::{Affine2, Affine3A, Quat, Vec3, vec3};
use smithay::wayland::compositor::with_states; use smithay::wayland::compositor::with_states;
use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc}; use std::{cell::RefCell, rc::Rc, sync::Arc};
use vulkano::image::view::ImageView; use vulkano::image::view::ImageView;
use wgui::gfx::WGfx;
use wlx_capture::frame::MouseMeta; use wlx_capture::frame::MouseMeta;
use wlx_common::{ use wlx_common::{
overlays::{BackendAttrib, BackendAttribValue, StereoMode}, overlays::{BackendAttrib, BackendAttribValue, StereoMode},
@@ -13,15 +12,13 @@ use crate::{
backend::{ backend::{
XrBackend, XrBackend,
input::{self, HoverResult}, input::{self, HoverResult},
wayvr::{self, SurfaceBufWithImage, WayVR}, wayvr::{self, SurfaceBufWithImage, WayVRState},
}, },
graphics::{ExtentExt, WGfxExtras}, graphics::ExtentExt,
ipc::{event_queue::SyncEventQueue, signal::WayVRSignal},
overlays::screen::capture::ScreenPipeline, overlays::screen::capture::ScreenPipeline,
state::{self, AppState}, state::{self, AppState},
subsystem::{hid::WheelDelta, input::KeyboardFocus}, subsystem::{hid::WheelDelta, input::KeyboardFocus},
windowing::{ windowing::{
OverlayID,
backend::{ backend::{
FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender, FrameMeta, OverlayBackend, OverlayEventData, RenderResources, ShouldRender,
ui_transform, ui_transform,
@@ -30,29 +27,10 @@ use crate::{
}, },
}; };
pub struct WayVRData {
pub window_handle_map: HashMap<wayvr::window::WindowHandle, OverlayID>,
pub data: WayVR,
}
impl WayVRData {
pub fn new(
gfx: Arc<WGfx>,
gfx_extras: &WGfxExtras,
config: wayvr::Config,
signals: SyncEventQueue<WayVRSignal>,
) -> anyhow::Result<Self> {
Ok(Self {
window_handle_map: HashMap::default(),
data: WayVR::new(gfx, &gfx_extras, config, signals)?,
})
}
}
pub fn create_wl_window_overlay( pub fn create_wl_window_overlay(
name: Arc<str>, name: Arc<str>,
xr_backend: XrBackend, xr_backend: XrBackend,
wayvr: Rc<RefCell<WayVRData>>, wayvr: Rc<RefCell<WayVRState>>,
window: wayvr::window::WindowHandle, window: wayvr::window::WindowHandle,
) -> anyhow::Result<OverlayWindowConfig> { ) -> anyhow::Result<OverlayWindowConfig> {
Ok(OverlayWindowConfig { Ok(OverlayWindowConfig {
@@ -83,7 +61,7 @@ pub struct WayVRBackend {
pipeline: Option<ScreenPipeline>, pipeline: Option<ScreenPipeline>,
interaction_transform: Option<Affine2>, interaction_transform: Option<Affine2>,
window: wayvr::window::WindowHandle, window: wayvr::window::WindowHandle,
wayvr: Rc<RefCell<WayVRData>>, wayvr: Rc<RefCell<WayVRState>>,
just_resumed: bool, just_resumed: bool,
meta: Option<FrameMeta>, meta: Option<FrameMeta>,
stereo: Option<StereoMode>, stereo: Option<StereoMode>,
@@ -94,7 +72,7 @@ impl WayVRBackend {
fn new( fn new(
name: Arc<str>, name: Arc<str>,
xr_backend: XrBackend, xr_backend: XrBackend,
wayvr: Rc<RefCell<WayVRData>>, wayvr: Rc<RefCell<WayVRState>>,
window: wayvr::window::WindowHandle, window: wayvr::window::WindowHandle,
) -> anyhow::Result<Self> { ) -> anyhow::Result<Self> {
Ok(Self { Ok(Self {
@@ -130,8 +108,8 @@ impl OverlayBackend for WayVRBackend {
} }
fn should_render(&mut self, app: &mut AppState) -> anyhow::Result<ShouldRender> { fn should_render(&mut self, app: &mut AppState) -> anyhow::Result<ShouldRender> {
let wayvr = &self.wayvr.borrow().data; let wayvr = &self.wayvr.borrow();
let Some(window) = wayvr.state.wm.windows.get(&self.window) else { let Some(window) = wayvr.wm.windows.get(&self.window) else {
log::debug!( log::debug!(
"{:?}: WayVR overlay without matching window entry", "{:?}: WayVR overlay without matching window entry",
self.name self.name
@@ -196,9 +174,8 @@ impl OverlayBackend for WayVRBackend {
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let image = self.cur_image.as_ref().unwrap().clone(); let image = self.cur_image.as_ref().unwrap().clone();
let wayvr = &self.wayvr.borrow().data; let wayvr = &self.wayvr.borrow();
let mouse = wayvr let mouse = wayvr
.state
.wm .wm
.mouse .mouse
.as_ref() .as_ref()
@@ -229,19 +206,19 @@ impl OverlayBackend for WayVRBackend {
event_data: OverlayEventData, event_data: OverlayEventData,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
if let OverlayEventData::IdAssigned(oid) = event_data { if let OverlayEventData::IdAssigned(oid) = event_data {
let wayvr = &mut self.wayvr.borrow_mut().data; let wayvr = &mut self.wayvr.borrow_mut();
wayvr.overlay_added(oid, self.window.clone()); wayvr.overlay_added(oid, self.window.clone());
} }
Ok(()) Ok(())
} }
fn on_hover(&mut self, _app: &mut state::AppState, hit: &input::PointerHit) -> HoverResult { fn on_hover(&mut self, _app: &mut state::AppState, hit: &input::PointerHit) -> HoverResult {
let wayvr = &mut self.wayvr.borrow_mut().data; let wayvr = &mut self.wayvr.borrow_mut();
if let Some(meta) = self.meta.as_ref() { if let Some(meta) = self.meta.as_ref() {
let x = ((hit.uv.x * (meta.extent[0] as f32)) as u32).max(0); let x = ((hit.uv.x * (meta.extent[0] as f32)) as u32).max(0);
let y = ((hit.uv.y * (meta.extent[1] as f32)) as u32).max(0); let y = ((hit.uv.y * (meta.extent[1] as f32)) as u32).max(0);
wayvr.state.send_mouse_move(self.window, x, y); wayvr.send_mouse_move(self.window, x, y);
} }
HoverResult { HoverResult {
@@ -264,11 +241,11 @@ impl OverlayBackend for WayVRBackend {
None None
} }
} { } {
let wayvr = &mut self.wayvr.borrow_mut().data; let wayvr = &mut self.wayvr.borrow_mut();
if pressed { if pressed {
wayvr.state.send_mouse_down(self.window, index); wayvr.send_mouse_down(self.window, index);
} else { } else {
wayvr.state.send_mouse_up(index); wayvr.send_mouse_up(index);
} }
} }
} }
@@ -279,7 +256,7 @@ impl OverlayBackend for WayVRBackend {
_hit: &input::PointerHit, _hit: &input::PointerHit,
delta: WheelDelta, delta: WheelDelta,
) { ) {
self.wayvr.borrow_mut().data.state.send_mouse_scroll(delta); self.wayvr.borrow_mut().send_mouse_scroll(delta);
} }
fn get_interaction_transform(&mut self) -> Option<Affine2> { fn get_interaction_transform(&mut self) -> Option<Affine2> {

View File

@@ -14,10 +14,11 @@ use wlx_common::{
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
use { use {
crate::config_wayvr::{self, WayVRConfig}, crate::config_wayvr::{self, WayVRConfig},
crate::overlays::wayvr::WayVRData,
std::{cell::RefCell, rc::Rc}, std::{cell::RefCell, rc::Rc},
}; };
#[cfg(feature = "wayvr")]
use crate::backend::wayvr::WayVRState;
#[cfg(feature = "osc")] #[cfg(feature = "osc")]
use crate::subsystem::osc::OscSender; use crate::subsystem::osc::OscSender;
@@ -61,7 +62,7 @@ pub struct AppState {
pub osc_sender: Option<OscSender>, pub osc_sender: Option<OscSender>,
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
pub wayland_server: Option<Rc<RefCell<WayVRData>>>, pub wayvr_server: Option<Rc<RefCell<WayVRState>>>,
} }
#[allow(unused_mut)] #[allow(unused_mut)]
@@ -78,7 +79,7 @@ impl AppState {
let wayvr_signals = SyncEventQueue::new(); let wayvr_signals = SyncEventQueue::new();
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
let wayland_server = session let wayvr_server = session
.wayvr_config .wayvr_config
.post_load( .post_load(
gfx.clone(), gfx.clone(),
@@ -93,7 +94,7 @@ impl AppState {
let mut hid_provider = HidWrapper::new(); let mut hid_provider = HidWrapper::new();
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
if let Some(wayland_server) = wayland_server.as_ref() { if let Some(wayland_server) = wayvr_server.as_ref() {
hid_provider.set_wayvr(wayland_server.clone()); hid_provider.set_wayvr(wayland_server.clone());
} }
@@ -157,7 +158,7 @@ impl AppState {
osc_sender, osc_sender,
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
wayland_server, wayvr_server,
}) })
} }

View File

@@ -1,7 +1,7 @@
use super::hid::{self, HidProvider, VirtualKey}; use super::hid::{self, HidProvider, VirtualKey};
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
use crate::overlays::wayvr::WayVRData; use crate::backend::wayvr::WayVRState;
use crate::subsystem::hid::XkbKeymap; use crate::subsystem::hid::XkbKeymap;
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
@@ -19,7 +19,7 @@ pub struct HidWrapper {
pub inner: Box<dyn HidProvider>, pub inner: Box<dyn HidProvider>,
pub keymap: Option<XkbKeymap>, pub keymap: Option<XkbKeymap>,
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
pub wayvr: Option<Rc<RefCell<WayVRData>>>, // Dynamically created if requested pub wayvr: Option<Rc<RefCell<WayVRState>>>, // Dynamically created if requested
} }
impl HidWrapper { impl HidWrapper {
@@ -34,12 +34,10 @@ impl HidWrapper {
} }
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
pub fn set_wayvr(&mut self, wayvr: Rc<RefCell<WayVRData>>) { pub fn set_wayvr(&mut self, wayvr: Rc<RefCell<WayVRState>>) {
if let Some(keymap) = self.keymap.take() { if let Some(keymap) = self.keymap.take() {
let _ = wayvr let _ = wayvr
.borrow_mut() .borrow_mut()
.data
.state
.set_keymap(&keymap.inner) .set_keymap(&keymap.inner)
.inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}")); .inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}"));
} }
@@ -53,7 +51,7 @@ impl HidWrapper {
{ {
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
if let Some(wayvr) = &self.wayvr { if let Some(wayvr) = &self.wayvr {
wayvr.borrow_mut().data.state.send_key(key as u32, down); wayvr.borrow_mut().send_key(key as u32, down);
} }
} }
} }
@@ -64,8 +62,6 @@ impl HidWrapper {
if let Some(wayvr) = &self.wayvr { if let Some(wayvr) = &self.wayvr {
let _ = wayvr let _ = wayvr
.borrow_mut() .borrow_mut()
.data
.state
.set_keymap(&keymap.inner) .set_keymap(&keymap.inner)
.inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}")); .inspect_err(|e| log::error!("Could not set WayVR keymap: {e:?}"));
} else { } else {
@@ -85,7 +81,7 @@ impl HidWrapper {
{ {
#[cfg(feature = "wayvr")] #[cfg(feature = "wayvr")]
if let Some(wayvr) = &self.wayvr { if let Some(wayvr) = &self.wayvr {
wayvr.borrow_mut().data.state.set_modifiers(mods); wayvr.borrow_mut().set_modifiers(mods);
} }
} }
} }