From 18febae805bc4ca127cefb799301b65b0e948e88 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Mon, 26 Jun 2023 08:01:17 +0200 Subject: [PATCH] feat: set transient for by propagating root window --- src/ui/app.rs | 1 + src/ui/install_wivrn_box.rs | 2 ++ src/ui/main_view.rs | 8 +++++++- src/ui/profile_editor.rs | 5 ++++- src/ui/widgets.rs | 22 ---------------------- 5 files changed, 14 insertions(+), 24 deletions(-) delete mode 100644 src/ui/widgets.rs diff --git a/src/ui/app.rs b/src/ui/app.rs index e517258..aee203b 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -457,6 +457,7 @@ impl SimpleComponent for App { .launch(MainViewInit { config: config.clone(), selected_profile: config.get_selected_profile(&profiles), + root_win: root.clone().into(), }) .forward(sender.input_sender(), |message| match message { MainViewOutMsg::EnableDebugViewChanged(val) => Msg::EnableDebugViewChanged(val), diff --git a/src/ui/install_wivrn_box.rs b/src/ui/install_wivrn_box.rs index e1c4fea..cfcffa2 100644 --- a/src/ui/install_wivrn_box.rs +++ b/src/ui/install_wivrn_box.rs @@ -41,6 +41,7 @@ pub enum InstallWivrnBoxMsg { #[derive(Debug)] pub struct InstallWivrnBoxInit { pub selected_profile: Profile, + pub root_win: gtk::Window, } #[relm4::component(pub)] @@ -202,6 +203,7 @@ impl SimpleComponent for InstallWivrnBox { ) -> ComponentParts { let adb_missing_dialog = adw::MessageDialog::builder() .modal(true) + .transient_for(&init.root_win) .heading("ADB is not installed") .body("Please install ADB on your computer to install WiVRn on your Android headset") .hide_on_close(true) diff --git a/src/ui/main_view.rs b/src/ui/main_view.rs index 674cb62..14f7ce5 100644 --- a/src/ui/main_view.rs +++ b/src/ui/main_view.rs @@ -68,6 +68,7 @@ pub enum MainViewOutMsg { pub struct MainViewInit { pub config: Config, pub selected_profile: Profile, + pub root_win: gtk::Window, } #[relm4::component(pub)] @@ -301,6 +302,7 @@ impl SimpleComponent for MainView { ) -> ComponentParts { let profile_not_editable_dialog = adw::MessageDialog::builder() .modal(true) + .transient_for(&init.root_win) .hide_on_close(true) .heading("This profile is not editable") .body(concat!( @@ -324,6 +326,7 @@ impl SimpleComponent for MainView { let profile_delete_confirm_dialog = adw::MessageDialog::builder() .modal(true) + .transient_for(&init.root_win) .hide_on_close(true) .heading("Are you sure you want to delete this profile?") .build(); @@ -351,6 +354,7 @@ impl SimpleComponent for MainView { install_wivrn_box: InstallWivrnBox::builder() .launch(InstallWivrnBoxInit { selected_profile: init.selected_profile.clone(), + root_win: init.root_win.clone(), }) .detach(), runtime_switcher_box: RuntimeSwitcherBox::builder() @@ -359,7 +363,9 @@ impl SimpleComponent for MainView { }) .detach(), profile_editor: ProfileEditor::builder() - .launch(ProfileEditorInit {}) + .launch(ProfileEditorInit { + root_win: init.root_win.clone(), + }) .forward(sender.input_sender(), |message| match message { ProfileEditorOutMsg::SaveProfile(p) => Self::Input::SaveProfile(p), }), diff --git a/src/ui/profile_editor.rs b/src/ui/profile_editor.rs index 7b030e2..a1dd873 100644 --- a/src/ui/profile_editor.rs +++ b/src/ui/profile_editor.rs @@ -53,7 +53,9 @@ pub enum ProfileEditorOutMsg { SaveProfile(Profile), } -pub struct ProfileEditorInit {} +pub struct ProfileEditorInit { + pub root_win: gtk::Window, +} #[relm4::component(pub)] impl SimpleComponent for ProfileEditor { @@ -66,6 +68,7 @@ impl SimpleComponent for ProfileEditor { adw::PreferencesWindow { set_hide_on_close: true, set_modal: true, + set_transient_for: Some(&init.root_win), #[track = "model.changed(Self::profile())"] set_title: match model.profile.as_ref() { Some(p) => Some(p.name.as_str()), diff --git a/src/ui/widgets.rs b/src/ui/widgets.rs deleted file mode 100644 index 97964e5..0000000 --- a/src/ui/widgets.rs +++ /dev/null @@ -1,22 +0,0 @@ -#[macro_use] -pub mod widgets { - use iced::Length; - use iced_aw::quad::{Quad, InnerBounds}; - pub fn vseparator() -> Quad { - Quad { - width: Length::Fixed(1.0), - height: Length::Fill, - inner_bounds: InnerBounds::Ratio(0.0001, 0.9999), - ..Default::default() - } - } - - pub fn hseparator() -> Quad { - Quad { - width: Length::Fill, - height: Length::Fixed(1.0), - inner_bounds: InnerBounds::Ratio(0.9999, 0.0001), - ..Default::default() - } - } -}