diff --git a/wayvr/src/state.rs b/wayvr/src/state.rs index 9e8d7da2..3692f771 100644 --- a/wayvr/src/state.rs +++ b/wayvr/src/state.rs @@ -92,7 +92,7 @@ impl AppState { .log_err("Could not initialize WayVR Server") .ok(); - let mut hid_provider = HidWrapper::new(); + let (hid_provider, mut hid_error) = HidWrapper::new(); #[cfg(feature = "osc")] let osc_sender = crate::subsystem::osc::OscSender::new(session.config.osc_out_port).ok(); @@ -159,7 +159,7 @@ impl AppState { let executor = Rc::new(smol::LocalExecutor::new()); - Ok(Self { + let mut app_state = Self { session, tasks, executor, @@ -193,7 +193,12 @@ impl AppState { #[cfg(feature = "openxr")] monado_state: None, - }) + }; + + if let Some(error_toast) = hid_error { + error_toast.submit(&mut app_state); + } + Ok(app_state) } #[cfg(feature = "openxr")] diff --git a/wayvr/src/subsystem/hid/mod.rs b/wayvr/src/subsystem/hid/mod.rs index b48f8ee7..01135c61 100644 --- a/wayvr/src/subsystem/hid/mod.rs +++ b/wayvr/src/subsystem/hid/mod.rs @@ -12,6 +12,9 @@ use std::sync::LazyLock; use std::{fs::File, sync::atomic::AtomicBool}; use strum::{EnumIter, EnumString, IntoEnumIterator}; use xkbcommon::xkb; +use wlx_common::overlays::ToastTopic; + +use crate::overlays::toast::Toast; #[cfg(feature = "wayland")] pub mod wayland; @@ -21,27 +24,35 @@ mod x11; pub static USE_UINPUT: AtomicBool = AtomicBool::new(true); -pub(super) fn initialize() -> Box { +pub(super) fn initialize() -> Result { if !USE_UINPUT.load(std::sync::atomic::Ordering::Relaxed) { - log::info!("Uinput disabled by user."); - return Box::new(DummyProvider {}); + const UINPUT_DISABLED: &str = "Uinput disabled by user."; + log::info!("{UINPUT_DISABLED}"); + return Err(Toast::new(ToastTopic::System, String::with_capacity(0), String::from(UINPUT_DISABLED)).with_timeout(5.0)); } if let Some(uinput) = UInputProvider::try_new() { log::info!("Initialized uinput."); - return Box::new(uinput); + return Ok(uinput); } - log::error!("Could not create uinput provider. Keyboard/Mouse input will not work!"); - log::error!("Check if the uinput kernel module is loaded: lsmod | grep uinput"); - log::error!( - " - If not loaded, follow your distro's instructions to load the uinput kernel module." - ); - log::error!("Check if you're in input group, run: id -nG"); + const CHECK_UINPUT_MESSAGE: &str = "Could not create uinput provider. Keyboard/Mouse input will not work! + +Check if the uinput kernel module is loaded: lsmod | grep uinput + - If not loaded, follow your distro's instructions to load the uinput kernel module. + +Check if you're in input group, run: id -nG"; + let mut full_uinput_error = String::from(CHECK_UINPUT_MESSAGE); if let Ok(user) = std::env::var("USER") { - log::error!(" - To add yourself to the input group, run: sudo usermod -aG input {user}"); - log::error!(" - After adding yourself to the input group, you will need to reboot."); + let check_group_message = format!(" - To add yourself to the input group, run: sudo usermod -aG input {user} + - After adding yourself to the input group, you will need to reboot."); + full_uinput_error.push_str(&check_group_message); } - Box::new(DummyProvider {}) + for error_line in full_uinput_error.lines() { + if !error_line.is_empty() { + log::error!("{error_line}"); + } + } + Err(Toast::new(ToastTopic::Error, String::with_capacity(0), full_uinput_error).with_timeout(10.0)) } pub struct WheelDelta { diff --git a/wayvr/src/subsystem/input.rs b/wayvr/src/subsystem/input.rs index c51f4876..f69f74bf 100644 --- a/wayvr/src/subsystem/input.rs +++ b/wayvr/src/subsystem/input.rs @@ -1,6 +1,10 @@ use super::hid::{self, HidProvider, VirtualKey}; -use crate::{backend::wayvr::WvrServerState, subsystem::hid::XkbKeymap}; +use crate::{ + backend::wayvr::WvrServerState, + overlays::toast::Toast, + subsystem::hid::{DummyProvider, XkbKeymap} +}; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum KeyboardFocus { @@ -15,12 +19,25 @@ pub struct HidWrapper { } impl HidWrapper { - pub fn new() -> Self { - Self { - keyboard_focus: KeyboardFocus::PhysicalScreen, - inner: hid::initialize(), - keymap: None, + pub fn new() -> (Self, Option) { + let hid_result = hid::initialize(); + let hid_provider: Box; + let error: Option; + match hid_result { + Ok(uinput) => { + hid_provider = Box::new(uinput); + error = None; + }, + Err(toast) => { + hid_provider = Box::new(DummyProvider {}); + error = Some(toast); + } } + (Self { + keyboard_focus: KeyboardFocus::PhysicalScreen, + inner: hid_provider, + keymap: None, + }, error) } pub fn send_key_routed(