diff --git a/src/main.rs b/src/main.rs index e110492..930e34e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,14 +8,13 @@ use gtk::prelude::*; use glib::clone; use gtk::SettingsExt; use std::env::args; -use std::sync::{Arc, RwLock}; use std::thread; mod menu; mod stato_finestra; mod tabs; mod wake_listener; -use stato_finestra::OperazStato; +use stato_finestra::{OperazStato, PosizFinestra, StatoFinestra, StatoFull}; fn build_ui(application: >k::Application) { let window = gtk::ApplicationWindow::new(application); @@ -70,8 +69,7 @@ fn build_ui(application: >k::Application) { }), ); let (key, modifier) = gtk::accelerator_parse("F11"); - let full_screen = Arc::new(RwLock::new(false)); - let stato = Arc::new(RwLock::new(stato_finestra::StatoFinestra::new(stato_finestra::PosizFinestra::Su))); + let stato = StatoFinestra::new_arc(PosizFinestra::Su, StatoFull::NonFull); let stato0 = stato.clone(); let stato1 = stato.clone(); let stato2 = stato.clone(); @@ -83,15 +81,16 @@ fn build_ui(application: >k::Application) { modifier, gtk::AccelFlags::VISIBLE, clone!(@weak window => @default-return true, move |_accel_g, _win, _key, _modif| { - if let Ok(mut lock) = full_screen.write(){ - if *lock { + match stato5.get_full() { + StatoFull::Full => { window.unfullscreen(); - stato5.set_full(stato_finestra::StatoFull::NonFull); - } else { - window.fullscreen(); - stato5.set_full(stato_finestra::StatoFull::Full); + stato5.set_full(StatoFull::NonFull); } - *lock = !*lock; + StatoFull::NonFull => { + window.fullscreen(); + stato5.set_full(StatoFull::Full); + } + _ => {} } true }), @@ -133,23 +132,21 @@ fn build_ui(application: >k::Application) { window.connect_focus_in_event(clone!(@weak window => @default-return gtk::Inhibit(false), move |_widget, _b| stato_finestra::focus_in(&window, &stato2))); nb.connect_destroy(move |_nb| { - stato.set_pos(stato_finestra::PosizFinestra::Chiudendo); + stato.set_pos(PosizFinestra::Chiudendo); }); - nb.connect_page_removed( - clone!(@weak window => move |notebook, _vte, _index| { - if notebook.get_n_pages() == 0 { - if stato0.get_pos() != stato_finestra::PosizFinestra::Chiudendo { - crate::tabs::apri_tab(&window, ¬ebook, false,None, None, None); - stato_finestra::butta_giu(&window, &stato0); - } - } else { - tabs::set_titles(¬ebook); - if notebook.get_n_pages() == 1 { - notebook.set_show_tabs(false); - } + nb.connect_page_removed(clone!(@weak window => move |notebook, _vte, _index| { + if notebook.get_n_pages() == 0 { + if stato0.get_pos() != PosizFinestra::Chiudendo { + crate::tabs::apri_tab(&window, ¬ebook, false,None, None, None); + stato_finestra::butta_giu(&window, &stato0); } - }), - ); + } else { + tabs::set_titles(¬ebook); + if notebook.get_n_pages() == 1 { + notebook.set_show_tabs(false); + } + } + })); nb.connect_page_added(move |notebook, _vte, _index| { if notebook.get_n_pages() > 1 { notebook.set_show_tabs(true); @@ -185,14 +182,7 @@ fn build_ui(application: >k::Application) { command, } => { tira_su(); - tabs::apri_tab( - &window, - &nb, - true, - cwd, - Some(shell), - Some(command), - ); + tabs::apri_tab(&window, &nb, true, cwd, Some(shell), Some(command)); } } glib::Continue(true) diff --git a/src/stato_finestra.rs b/src/stato_finestra.rs index 1e5abd9..798ded7 100644 --- a/src/stato_finestra.rs +++ b/src/stato_finestra.rs @@ -21,11 +21,8 @@ pub struct StatoFinestra { full: StatoFull, } impl StatoFinestra { - pub fn new(p: PosizFinestra) -> Self { - StatoFinestra { - full: NonFull, - posiz: p, - } + pub fn new_arc(p: PosizFinestra, f: StatoFull) -> Arc> { + Arc::new(RwLock::new(StatoFinestra { full: f, posiz: p })) } } pub trait OperazStato { diff --git a/src/tabs.rs b/src/tabs.rs index 2346dce..f4efb9a 100644 --- a/src/tabs.rs +++ b/src/tabs.rs @@ -31,7 +31,7 @@ pub fn build_tab( let shell = shell.unwrap_or(vec![var("SHELL").unwrap_or("/bin/sh".to_string())]); let shell: Vec<_> = shell.iter().map(Path::new).collect(); let stringa: String; - let cwd = if cwd.is_some() { + let cwd = if cwd.is_some() { stringa = cwd.unwrap(); Some(stringa.as_str()) } else {