From 2addb6ae636b0c2f5bb4313436cb42973d397760 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Mon, 22 Jul 2024 13:15:20 +0200 Subject: [PATCH] feat: hide wivrn configuration under the menu, enable/disable it depending on selected profile; update wivrn configuration doc link; add warning in wivrn config dialog --- src/ui/app.rs | 109 +++++++++++++++++++++--------------- src/ui/main_view.rs | 31 +--------- src/ui/wivrn_conf_editor.rs | 2 +- 3 files changed, 68 insertions(+), 74 deletions(-) diff --git a/src/ui/app.rs b/src/ui/app.rs index 46737ad..08e69ed 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -109,6 +109,8 @@ pub struct App { #[tracker::do_not_track] wivrn_appimage_warn_shown: bool, + #[tracker::do_not_track] + configure_wivrn_action: gtk::gio::SimpleAction, } #[derive(Debug)] @@ -659,6 +661,8 @@ impl SimpleComponent for App { ); self.wivrn_appimage_warn_shown = true; } + self.configure_wivrn_action + .set_enabled(prof.xrservice_type == XRServiceType::Wivrn); if prof.uuid == self.config.selected_profile_uuid { return; } @@ -762,6 +766,64 @@ impl SimpleComponent for App { }); } + let mut actions = RelmActionGroup::::new(); + + stateless_action!( + actions, + BuildProfileAction, + clone!(@strong sender => move |_| { + sender.input_sender().emit(Msg::BuildProfile(false)); + }) + ); + stateless_action!( + actions, + BuildProfileCleanAction, + clone!(@strong sender => move |_| { + sender.input_sender().emit(Msg::BuildProfile(true)); + }) + ); + stateless_action!( + actions, + QuitAction, + clone!(@strong sender => move |_| { + sender.input(Msg::Quit); + }) + ); + stateless_action!( + actions, + DebugOpenDataAction, + clone!(@strong sender => move |_| { + sender.input(Msg::DebugOpenData); + }) + ); + stateless_action!( + actions, + DebugOpenPrefixAction, + clone!(@strong sender => move |_| { + sender.input(Msg::DebugOpenPrefix); + }) + ); + stateless_action!( + actions, + DebugCopyEnvVarsAction, + clone!(@strong sender => move |_| { + sender.input(Msg::DebugCopyEnvVars); + }) + ); + // this bypasses the macro because I need the underlying gio action + // to enable/disable it in update() + let configure_wivrn_action = { + let action = RelmAction::::new_stateless( + clone!(@strong sender => move |_| { + sender.input(Msg::OpenWivrnConfig); + }), + ); + let ret = action.gio_action().clone(); + actions.add_action(action); + ret.set_enabled(false); + ret + }; + let mut model = App { tracker: 0, application: init.application, @@ -780,7 +842,6 @@ impl SimpleComponent for App { MainViewOutMsg::DeleteProfile => Msg::DeleteProfile, MainViewOutMsg::SaveProfile(p) => Msg::SaveProfile(p), MainViewOutMsg::OpenLibsurviveSetup => Msg::OpenLibsurviveSetup, - MainViewOutMsg::OpenWivrnConfig => Msg::OpenWivrnConfig, }), debug_view: DebugView::builder().launch(DebugViewInit {}).forward( sender.input_sender(), @@ -816,59 +877,16 @@ impl SimpleComponent for App { wivrn_conf_editor: None, skip_depcheck: false, wivrn_appimage_warn_shown: false, + configure_wivrn_action, }; let widgets = view_output!(); - let mut actions = RelmActionGroup::::new(); - - stateless_action!( - actions, - BuildProfileAction, - clone!(@strong sender => move |_| { - sender.input_sender().emit(Msg::BuildProfile(false)); - }) - ); - stateless_action!( - actions, - BuildProfileCleanAction, - clone!(@strong sender => move |_| { - sender.input_sender().emit(Msg::BuildProfile(true)); - }) - ); { let abd_sender = model.about_dialog.sender().clone(); stateless_action!(actions, AboutAction, move |_| { abd_sender.send(()).unwrap(); }); } - stateless_action!( - actions, - QuitAction, - clone!(@strong sender => move |_| { - sender.input(Msg::Quit); - }) - ); - stateless_action!( - actions, - DebugOpenDataAction, - clone!(@strong sender => move |_| { - sender.input(Msg::DebugOpenData); - }) - ); - stateless_action!( - actions, - DebugOpenPrefixAction, - clone!(@strong sender => move |_| { - sender.input(Msg::DebugOpenPrefix); - }) - ); - stateless_action!( - actions, - DebugCopyEnvVarsAction, - clone!(@strong sender => move |_| { - sender.input(Msg::DebugCopyEnvVars); - }) - ); actions.add_action(RelmAction::::new_stateful( &model.enable_debug_view, clone!(@strong sender => move |_, state| { @@ -912,6 +930,7 @@ new_stateless_action!(pub BuildProfileAction, AppActionGroup, "buildprofile"); new_stateless_action!(pub BuildProfileCleanAction, AppActionGroup, "buildprofileclean"); new_stateless_action!(pub QuitAction, AppActionGroup, "quit"); new_stateful_action!(pub DebugViewToggleAction, AppActionGroup, "debugviewtoggle", (), bool); +new_stateless_action!(pub ConfigureWivrnAction, AppActionGroup, "configurewivrn"); new_stateless_action!(pub DebugOpenDataAction, AppActionGroup, "debugopendata"); new_stateless_action!(pub DebugOpenPrefixAction, AppActionGroup, "debugopenprefix"); diff --git a/src/ui/main_view.rs b/src/ui/main_view.rs index 4fb23be..711508b 100644 --- a/src/ui/main_view.rs +++ b/src/ui/main_view.rs @@ -11,7 +11,8 @@ use crate::gpu_profile::{get_amd_gpu_power_profile, GpuPowerProfile}; use crate::profile::{LighthouseDriver, Profile, XRServiceType}; use crate::steamvr_utils::chaperone_info_exists; use crate::ui::app::{ - AboutAction, BuildProfileAction, BuildProfileCleanAction, DebugViewToggleAction, + AboutAction, BuildProfileAction, BuildProfileCleanAction, ConfigureWivrnAction, + DebugViewToggleAction, }; use crate::ui::profile_editor::ProfileEditorInit; use crate::ui::steamvr_calibration_box::SteamVrCalibrationBoxMsg; @@ -76,7 +77,6 @@ pub enum MainViewOutMsg { DeleteProfile, SaveProfile(Profile), OpenLibsurviveSetup, - OpenWivrnConfig, } pub struct MainViewInit { @@ -113,6 +113,7 @@ impl SimpleComponent for MainView { "_Debug View" => DebugViewToggleAction, "_Build Profile" => BuildProfileAction, "C_lean Build Profile" => BuildProfileCleanAction, + "Configure _WiVRn" => ConfigureWivrnAction, }, section! { "_About" => AboutAction, @@ -296,32 +297,6 @@ impl SimpleComponent for MainView { model.steam_launch_options_box.widget(), model.install_wivrn_box.widget(), - gtk::Box { - set_orientation: gtk::Orientation::Horizontal, - set_hexpand: true, - set_vexpand: false, - set_spacing: 12, - add_css_class: "card", - add_css_class: "padded", - #[track = "model.changed(Self::selected_profile())"] - set_visible: model.selected_profile.xrservice_type == XRServiceType::Wivrn, - gtk::Label { - add_css_class: "heading", - set_hexpand: true, - set_xalign: 0.0, - set_label: "Configure WiVRn", - set_wrap: true, - set_wrap_mode: gtk::pango::WrapMode::Word, - }, - gtk::Button { - add_css_class: "suggested-action", - set_label: "Configure", - set_halign: gtk::Align::End, - connect_clicked[sender] => move |_| { - sender.output(Self::Output::OpenWivrnConfig).expect("Sender output failed"); - } - }, - }, model.steamvr_calibration_box.widget(), gtk::Box { diff --git a/src/ui/wivrn_conf_editor.rs b/src/ui/wivrn_conf_editor.rs index 27229e0..efaf035 100644 --- a/src/ui/wivrn_conf_editor.rs +++ b/src/ui/wivrn_conf_editor.rs @@ -82,7 +82,7 @@ impl SimpleComponent for WivrnConfEditor { set_content: pref_page = &adw::PreferencesPage { set_hexpand: true, set_vexpand: true, - set_description: "WiVRn Configuration Documentation", + set_description: "Warning: you likely don't need to change the default configuration, this is for advanced users only. Proceed at your own risk!\n\nWiVRn Configuration Documentation", add: scalegrp = &adw::PreferencesGroup { set_title: "Scale", set_description: Some("Render resolution scale. 1.0 is 100%."),