From 59b035c49dbb0b0b4e97392f6759171c376eee1e Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Thu, 17 Oct 2024 18:21:03 +0200 Subject: [PATCH] feat: openhmd calibration reset box in main view --- src/ui/main_view.rs | 19 ++++++ src/ui/mod.rs | 1 + src/ui/openhmd_calibration_box.rs | 100 ++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 src/ui/openhmd_calibration_box.rs diff --git a/src/ui/main_view.rs b/src/ui/main_view.rs index a152b5c..43484e3 100644 --- a/src/ui/main_view.rs +++ b/src/ui/main_view.rs @@ -6,6 +6,7 @@ use super::{ }, devices_box::{DevicesBox, DevicesBoxMsg}, install_wivrn_box::{InstallWivrnBox, InstallWivrnBoxInit, InstallWivrnBoxMsg}, + openhmd_calibration_box::{OpenHmdCalibrationBox, OpenHmdCalibrationBoxMsg}, profile_editor::{ProfileEditor, ProfileEditorInit, ProfileEditorMsg, ProfileEditorOutMsg}, steam_launch_options_box::{SteamLaunchOptionsBox, SteamLaunchOptionsBoxMsg}, steamvr_calibration_box::{SteamVrCalibrationBox, SteamVrCalibrationBoxMsg}, @@ -62,6 +63,8 @@ pub struct MainView { #[tracker::do_not_track] steamvr_calibration_box: Controller, #[tracker::do_not_track] + openhmd_calibration_box: Controller, + #[tracker::do_not_track] root_win: gtk::Window, #[tracker::do_not_track] profile_delete_action: gtk::gio::SimpleAction, @@ -404,6 +407,7 @@ impl SimpleComponent for MainView { model.wivrn_wired_start_box.widget(), model.install_wivrn_box.widget(), model.steamvr_calibration_box.widget(), + model.openhmd_calibration_box.widget(), gtk::Box { set_orientation: gtk::Orientation::Vertical, @@ -505,6 +509,9 @@ impl SimpleComponent for MainView { self.steamvr_calibration_box .sender() .emit(SteamVrCalibrationBoxMsg::XRServiceActiveChanged(active)); + self.openhmd_calibration_box + .sender() + .emit(OpenHmdCalibrationBoxMsg::XRServiceActiveChanged(active)); if !active { sender.input(Self::Input::UpdateDevices(vec![])); } @@ -529,6 +536,11 @@ impl SimpleComponent for MainView { .emit(SteamVrCalibrationBoxMsg::SetVisible( prof.lighthouse_driver == LighthouseDriver::SteamVR, )); + self.openhmd_calibration_box + .sender() + .emit(OpenHmdCalibrationBoxMsg::SetVisible( + prof.features.openhmd.enabled, + )); self.install_wivrn_box .sender() .emit(InstallWivrnBoxMsg::UpdateSelectedProfile(prof.clone())); @@ -788,6 +800,12 @@ impl SimpleComponent for MainView { .emit(SteamVrCalibrationBoxMsg::SetVisible( init.selected_profile.lighthouse_driver == LighthouseDriver::SteamVR, )); + let openhmd_calibration_box = OpenHmdCalibrationBox::builder().launch(()).detach(); + openhmd_calibration_box + .sender() + .emit(OpenHmdCalibrationBoxMsg::SetVisible( + init.selected_profile.features.openhmd.enabled, + )); let mut actions = RelmActionGroup::::new(); @@ -842,6 +860,7 @@ impl SimpleComponent for MainView { profile_delete_confirm_dialog, root_win: init.root_win.clone(), steamvr_calibration_box, + openhmd_calibration_box, profile_editor: None, xrservice_ready: false, profile_delete_action, diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 1d34c35..2a5dd01 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -12,6 +12,7 @@ pub mod job_worker; mod libsurvive_setup_window; mod macros; mod main_view; +mod openhmd_calibration_box; mod preference_rows; mod profile_editor; mod steam_launch_options_box; diff --git a/src/ui/openhmd_calibration_box.rs b/src/ui/openhmd_calibration_box.rs new file mode 100644 index 0000000..c8da5dc --- /dev/null +++ b/src/ui/openhmd_calibration_box.rs @@ -0,0 +1,100 @@ +use crate::{constants::APP_NAME, xdg::XDG}; +use relm4::{ + gtk::{self, prelude::*}, + ComponentParts, ComponentSender, SimpleComponent, +}; + +#[tracker::track] +pub struct OpenHmdCalibrationBox { + visible: bool, + xrservice_active: bool, +} + +#[derive(Debug)] +pub enum OpenHmdCalibrationBoxMsg { + SetVisible(bool), + XRServiceActiveChanged(bool), +} + +#[relm4::component(pub)] +impl SimpleComponent for OpenHmdCalibrationBox { + type Init = (); + type Input = OpenHmdCalibrationBoxMsg; + type Output = (); + + view! { + gtk::Box { + set_orientation: gtk::Orientation::Vertical, + set_hexpand: true, + set_vexpand: false, + set_spacing: 12, + add_css_class: "card", + add_css_class: "padded", + #[track = "model.changed(Self::visible())"] + set_visible: model.visible, + gtk::Label { + add_css_class: "heading", + set_hexpand: true, + set_xalign: 0.0, + set_label: "Rift CV1 Calibration", + set_wrap: true, + set_wrap_mode: gtk::pango::WrapMode::Word, + }, + gtk::Label { + add_css_class: "dim-label", + set_hexpand: true, + set_label: &format!( + "On the first run, start {APP_NAME} with your headset in full clear view of both camera bases for a functioning and effective calibration.\n\nYou can reset the calibration with the button below.", + ), + set_xalign: 0.0, + set_wrap: true, + set_wrap_mode: gtk::pango::WrapMode::Word, + }, + gtk::Button { + set_label: "Reset Calibration", + set_halign: gtk::Align::Start, + #[track = "model.changed(Self::xrservice_active())"] + set_sensitive: !model.xrservice_active, + connect_clicked => move |_| { + let target = XDG.get_config_home().join("openhmd/rift-room-config.json"); + if target.is_file() { + if let Err(e) = std::fs::remove_file(target) { + eprintln!("Failed to remove openhmd config: {e}"); + } + } else { + println!("info: trying to delete openhmd calibration config, but file is missing") + } + } + }, + }, + } + + fn update(&mut self, message: Self::Input, _sender: ComponentSender) { + self.reset(); + + match message { + Self::Input::SetVisible(state) => { + self.set_visible(state); + } + Self::Input::XRServiceActiveChanged(active) => { + self.set_xrservice_active(active); + } + } + } + + fn init( + _init: Self::Init, + root: Self::Root, + _sender: ComponentSender, + ) -> ComponentParts { + let model = Self { + tracker: 0, + visible: false, + xrservice_active: false, + }; + + let widgets = view_output!(); + + ComponentParts { model, widgets } + } +}