gnome ha cambiato qualcosa e si era rotto tutto

master
Pietro Brenna 2020-03-29 13:08:00 +02:00
parent 93d44a0c99
commit 8468537f1c
2 changed files with 58 additions and 17 deletions

View File

@ -86,7 +86,7 @@ fn build_ui(application: &gtk::Application) {
}), }),
); );
let (key, modifier) = gtk::accelerator_parse("F11"); let (key, modifier) = gtk::accelerator_parse("F11");
let w_state = WindowState::new_arc(WindowPos::Up, FullScreenState::NotFull); let w_state = WindowState::new_arc(WindowPos::Hidden, FullScreenState::NotFull);
let w_state0 = w_state.clone(); let w_state0 = w_state.clone();
let w_state1 = w_state.clone(); let w_state1 = w_state.clone();
let w_state2 = w_state.clone(); let w_state2 = w_state.clone();
@ -134,6 +134,7 @@ fn build_ui(application: &gtk::Application) {
window.set_skip_taskbar_hint(true); window.set_skip_taskbar_hint(true);
window.set_skip_pager_hint(true); window.set_skip_pager_hint(true);
window.show_all(); window.show_all();
window.hide();
/*unsafe { /*unsafe {
gdk_sys::gdk_window_set_skip_pager_hint( gdk_sys::gdk_window_set_skip_pager_hint(
window.get_window().unwrap().to_glib_none().0, window.get_window().unwrap().to_glib_none().0,
@ -174,7 +175,7 @@ fn build_ui(application: &gtk::Application) {
}); });
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
window_state::bring_up(&window, &w_state4, gtk::get_current_event_time()); //window_state::bring_up(&window, &w_state4, gtk::get_current_event_time());
//tabs::focus_tab_corrente(&nb); //tabs::focus_tab_corrente(&nb);
rx.attach(None, move |cmd| { rx.attach(None, move |cmd| {
let tira_su = || { let tira_su = || {

View File

@ -7,7 +7,7 @@ use std::time::{Duration, Instant};
#[derive(Eq, PartialEq, Debug, Copy, Clone)] #[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum WindowPos { pub enum WindowPos {
Up, Up,
BringingUp, // BringingUp,
Hiding, Hiding,
Hidden, Hidden,
UpWithoutFocus, UpWithoutFocus,
@ -26,6 +26,7 @@ pub struct WindowState {
position: WindowPos, position: WindowPos,
full: FullScreenState, full: FullScreenState,
last_toggle: Option<Instant>, last_toggle: Option<Instant>,
focus_lost: Option<Instant>,
} }
impl WindowState { impl WindowState {
pub fn new_arc(p: WindowPos, f: FullScreenState) -> Rc<RwLock<Self>> { pub fn new_arc(p: WindowPos, f: FullScreenState) -> Rc<RwLock<Self>> {
@ -33,6 +34,7 @@ impl WindowState {
full: f, full: f,
position: p, position: p,
last_toggle: None, last_toggle: None,
focus_lost: None
})) }))
} }
} }
@ -43,11 +45,15 @@ pub trait StateOperations {
fn get_full(&self) -> FullScreenState; fn get_full(&self) -> FullScreenState;
fn set_last_toggle(&self, instant: Option<Instant>); fn set_last_toggle(&self, instant: Option<Instant>);
fn get_last_toggle(&self) -> Option<Instant>; fn get_last_toggle(&self) -> Option<Instant>;
fn set_focus_lost(&self, instant: Option<Instant>);
fn get_focus_lost(&self) -> Option<Instant>;
} }
impl StateOperations for Rc<RwLock<WindowState>> { impl StateOperations for Rc<RwLock<WindowState>> {
fn set_pos(&self, p: WindowPos) { fn set_pos(&self, p: WindowPos) {
if let Ok(mut w_lock) = self.write() { if let Ok(mut w_lock) = self.write() {
w_lock.position = p; w_lock.position = p;
} else {
eprintln!("Can't acquire lock");
} }
} }
fn get_pos(&self) -> WindowPos { fn get_pos(&self) -> WindowPos {
@ -60,6 +66,8 @@ impl StateOperations for Rc<RwLock<WindowState>> {
fn set_full(&self, full: FullScreenState) { fn set_full(&self, full: FullScreenState) {
if let Ok(mut w_lock) = self.write() { if let Ok(mut w_lock) = self.write() {
w_lock.full = full; w_lock.full = full;
} else {
eprintln!("Can't acquire lock");
} }
} }
fn get_full(&self) -> FullScreenState { fn get_full(&self) -> FullScreenState {
@ -79,6 +87,22 @@ impl StateOperations for Rc<RwLock<WindowState>> {
fn set_last_toggle(&self, instant: Option<Instant>) { fn set_last_toggle(&self, instant: Option<Instant>) {
if let Ok(mut w_lock) = self.write() { if let Ok(mut w_lock) = self.write() {
w_lock.last_toggle = instant; w_lock.last_toggle = instant;
} else {
eprintln!("Can't acquire lock");
}
}
fn get_focus_lost(&self) -> Option<Instant> {
if let Ok(r_lock) = self.read() {
r_lock.focus_lost
} else {
None
}
}
fn set_focus_lost(&self, instant: Option<Instant>) {
if let Ok(mut w_lock) = self.write() {
w_lock.focus_lost = instant;
} else {
eprintln!("Can't acquire lock");
} }
} }
} }
@ -90,24 +114,26 @@ pub fn bring_up(window: &gtk::ApplicationWindow, w_state: &Rc<RwLock<WindowState
} }
} }
w_state.set_last_toggle(Some(Instant::now())); w_state.set_last_toggle(Some(Instant::now()));
let new_pos = match w_state.get_pos() { let pos = w_state.get_pos();
Hidden | Hiding => { let new_pos = match pos {
/*Hidden | Hiding => {
// Shameless copy from guake // Shameless copy from guake
/*window.hide(); //window.hide();
window.present(); // window.present();
window.deiconify();*/ // window.deiconify();
window.show(); window.show();
let gdk_window = window.get_window(); let gdk_window = window.get_window();
if let Some(ref gdk_window) = gdk_window { if let Some(ref gdk_window) = gdk_window {
gdk_window.focus(ts); gdk_window.focus(ts);
} gdk_window.focus(0);
}/*
window.set_type_hint(gdk::WindowTypeHint::Dock); window.set_type_hint(gdk::WindowTypeHint::Dock);
/*if let Some(ref gdk_window) = gdk_window { if let Some(ref gdk_window) = gdk_window {
gdk_window.focus(0); gdk_window.focus(0);
}*/ }*/
Some(BringingUp) Some(BringingUp)
} }*/
UpWithoutFocus => { Hidden | Hiding | UpWithoutFocus => {
window.hide(); window.hide();
window.show(); window.show();
let gdk_window = window.get_window(); let gdk_window = window.get_window();
@ -117,7 +143,7 @@ pub fn bring_up(window: &gtk::ApplicationWindow, w_state: &Rc<RwLock<WindowState
} }
let s = calc_w_h(window); let s = calc_w_h(window);
window.get_window().map(|w| w.resize(s.0, s.1)); window.get_window().map(|w| w.resize(s.0, s.1));
Some(Up) None
} }
_ => None, _ => None,
}; };
@ -137,18 +163,31 @@ pub fn esegui_toggle(
w_state: &Rc<RwLock<WindowState>>, w_state: &Rc<RwLock<WindowState>>,
) { ) {
let ts = gtk::get_current_event_time(); let ts = gtk::get_current_event_time();
match w_state.get_pos() { let pos = w_state.get_pos();
Hidden | Hiding | UpWithoutFocus => { match pos {
Hidden | Hiding => {
bring_up(window, w_state, ts);
crate::tabs::focus_current_tab(&nb);
},
UpWithoutFocus => {
let f_l = w_state.get_focus_lost() ;
if f_l.is_some() && f_l.unwrap().elapsed() < Duration::from_millis(200) {
hide(window, &w_state);
} else {
bring_up(window, w_state, ts); bring_up(window, w_state, ts);
crate::tabs::focus_current_tab(&nb); crate::tabs::focus_current_tab(&nb);
} }
},
Up => hide(window, &w_state), Up => hide(window, &w_state),
_ => {} _ => {}
} }
} }
pub fn focus_out(w_state: &Rc<RwLock<WindowState>>) -> gtk::Inhibit { pub fn focus_out(w_state: &Rc<RwLock<WindowState>>) -> gtk::Inhibit {
match w_state.get_pos() { // eprintln!("<<<<<<<<<<<< Focus out!");
w_state.set_focus_lost(Some(Instant::now()));
let pos = w_state.get_pos();
match pos {
Hiding => { Hiding => {
w_state.set_pos(Hidden); w_state.set_pos(Hidden);
} }
@ -163,6 +202,7 @@ pub fn focus_in(
window: &gtk::ApplicationWindow, window: &gtk::ApplicationWindow,
w_state: &Rc<RwLock<WindowState>>, w_state: &Rc<RwLock<WindowState>>,
) -> gtk::Inhibit { ) -> gtk::Inhibit {
//eprintln!(">>>>>>>>>>> Focus in!");
w_state.set_pos(Up); w_state.set_pos(Up);
let s = calc_w_h(window); let s = calc_w_h(window);
window.set_type_hint(gdk::WindowTypeHint::Dock); window.set_type_hint(gdk::WindowTypeHint::Dock);