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 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_state1 = 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_pager_hint(true);
window.show_all();
window.hide();
/*unsafe {
gdk_sys::gdk_window_set_skip_pager_hint(
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);
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);
rx.attach(None, move |cmd| {
let tira_su = || {

View File

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