Risolto flashing psichedelico con full screen

master
Pietro Brenna 2020-03-20 20:54:10 +01:00
parent e3b6cfc336
commit a0425f01f5
2 changed files with 99 additions and 53 deletions

View File

@ -15,6 +15,7 @@ mod menu;
mod stato_finestra;
mod tabs;
mod wake_listener;
use stato_finestra::OperazStato;
fn build_ui(application: &gtk::Application) {
let window = gtk::ApplicationWindow::new(application);
@ -70,6 +71,13 @@ fn build_ui(application: &gtk::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 stato0 = stato.clone();
let stato1 = stato.clone();
let stato2 = stato.clone();
let stato3 = stato.clone();
let stato4 = stato.clone();
let stato5 = stato.clone();
accel_group.connect_accel_group(
key,
modifier,
@ -78,8 +86,10 @@ fn build_ui(application: &gtk::Application) {
if let Ok(mut lock) = full_screen.write(){
if *lock {
window.unfullscreen();
stato5.set_full(stato_finestra::StatoFull::NonFull);
} else {
window.fullscreen();
stato5.set_full(stato_finestra::StatoFull::Full);
}
*lock = !*lock;
}
@ -118,29 +128,19 @@ fn build_ui(application: &gtk::Application) {
true.to_glib(),
);
}*/
let stato = Arc::new(RwLock::new(stato_finestra::StatoFinestra::Su));
let stato0 = stato.clone();
let stato1 = stato.clone();
let stato2 = stato.clone();
let stato3 = stato.clone();
let stato4 = stato.clone();
window.connect_focus_out_event(move |_widget, _b| stato_finestra::focus_out(&stato1));
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| {
if let Ok(mut lock_stato) = stato.write() {
*lock_stato = stato_finestra::StatoFinestra::Chiudendo;
}
stato.set_pos(stato_finestra::PosizFinestra::Chiudendo);
});
nb.connect_page_removed(
clone!(@weak window => move |notebook, _vte, _index| {
if notebook.get_n_pages() == 0 {
if let Ok(mut lock_stato) = stato0.write() {
if *lock_stato != stato_finestra::StatoFinestra::Chiudendo {
if stato0.get_pos() != stato_finestra::PosizFinestra::Chiudendo {
crate::tabs::apri_tab(&window, &notebook, false,None, None, None);
stato_finestra::butta_giu(&window, &mut lock_stato);
}
stato_finestra::butta_giu(&window, &stato0);
}
} else {
tabs::set_titles(&notebook);
@ -160,15 +160,11 @@ fn build_ui(application: &gtk::Application) {
});
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
if let Ok(ref mut lock_stato) = stato4.write() {
stato_finestra::tira_su(&window, lock_stato, gtk::get_current_event_time());
}
stato_finestra::tira_su(&window, &stato4, gtk::get_current_event_time());
//tabs::focus_tab_corrente(&nb);
rx.attach(None, move |cmd| {
let tira_su = || {
if let Ok(ref mut lock_stato) = stato3.write() {
stato_finestra::tira_su(&window, lock_stato, gtk::get_current_event_time());
}
stato_finestra::tira_su(&window, &stato3, gtk::get_current_event_time());
};
use wake_listener::RpcCommand::*;
match cmd {

View File

@ -1,19 +1,72 @@
#[derive(Eq, PartialEq, Debug)]
pub enum StatoFinestra {
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum PosizFinestra {
Su,
TirandoSu,
Nascondendo,
Nascosta,
SuNonFocusata,
Chiudendo,
Sconosciuta,
}
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum StatoFull {
Full,
NonFull,
Sconosciuto,
}
pub use PosizFinestra::*;
pub use StatoFull::*;
pub struct StatoFinestra {
posiz: PosizFinestra,
full: StatoFull,
}
impl StatoFinestra {
pub fn new(p: PosizFinestra) -> Self {
StatoFinestra {
full: NonFull,
posiz: p,
}
}
}
pub trait OperazStato {
fn set_pos(&self, p: PosizFinestra);
fn get_pos(&self) -> PosizFinestra;
fn set_full(&self, f: StatoFull);
fn get_full(&self) -> StatoFull;
}
impl OperazStato for Arc<RwLock<StatoFinestra>> {
fn set_pos(&self, p: PosizFinestra) {
if let Ok(mut w_lock) = self.write() {
w_lock.posiz = p;
}
}
fn get_pos(&self) -> PosizFinestra {
if let Ok(r_lock) = self.read() {
r_lock.posiz
} else {
Sconosciuta
}
}
fn set_full(&self, full: StatoFull) {
if let Ok(mut w_lock) = self.write() {
w_lock.full = full;
}
}
fn get_full(&self) -> StatoFull {
if let Ok(r_lock) = self.read() {
r_lock.full
} else {
Sconosciuto
}
}
}
use gdk::WindowExt;
use gtk::prelude::*;
use std::sync::{Arc, RwLock};
pub fn tira_su(window: &gtk::ApplicationWindow, stato: &mut StatoFinestra, ts: u32) {
match *stato {
StatoFinestra::Nascosta | StatoFinestra::Nascondendo => {
pub fn tira_su(window: &gtk::ApplicationWindow, stato: &Arc<RwLock<StatoFinestra>>, ts: u32) {
let new_pos = match stato.get_pos() {
Nascosta | Nascondendo => {
// Shameless copy from guake
/*window.hide();
window.present();
@ -27,9 +80,9 @@ pub fn tira_su(window: &gtk::ApplicationWindow, stato: &mut StatoFinestra, ts: u
/*if let Some(ref gdk_window) = gdk_window {
gdk_window.focus(0);
}*/
*stato = StatoFinestra::TirandoSu;
Some(TirandoSu)
}
StatoFinestra::SuNonFocusata => {
SuNonFocusata => {
window.hide();
window.show();
let gdk_window = window.get_window();
@ -39,14 +92,17 @@ pub fn tira_su(window: &gtk::ApplicationWindow, stato: &mut StatoFinestra, ts: u
}
let s = calc_w_h(window);
window.get_window().map(|w| w.resize(s.0, s.1));
*stato = StatoFinestra::Su;
Some(Su)
}
_ => {}
_ => None,
};
if let Some(new_pos) = new_pos {
stato.set_pos(new_pos);
}
}
pub fn butta_giu(window: &gtk::ApplicationWindow, stato: &mut StatoFinestra) {
*stato = StatoFinestra::Nascondendo;
pub fn butta_giu(window: &gtk::ApplicationWindow, stato: &Arc<RwLock<StatoFinestra>>) {
stato.set_pos(Nascondendo);
window.hide();
}
@ -56,27 +112,23 @@ pub fn esegui_toggle(
stato: &Arc<RwLock<StatoFinestra>>,
) {
let ts = gtk::get_current_event_time();
if let Ok(mut inner) = stato.write() {
match *inner {
StatoFinestra::Nascosta | StatoFinestra::Nascondendo | StatoFinestra::SuNonFocusata => {
tira_su(window, &mut inner, ts);
match stato.get_pos() {
Nascosta | Nascondendo | SuNonFocusata => {
tira_su(window, stato, ts);
crate::tabs::focus_tab_corrente(&nb);
}
StatoFinestra::Su => butta_giu(window, &mut inner),
Su => butta_giu(window, &stato),
_ => {}
}
} else {
eprintln!("Can't acquire lock!");
}
}
pub fn focus_out(stato: &Arc<RwLock<StatoFinestra>>) -> gtk::Inhibit {
if let Ok(mut inner) = stato.write() {
if *inner == StatoFinestra::Nascondendo {
*inner = StatoFinestra::Nascosta;
} else {
*inner = StatoFinestra::SuNonFocusata;
//widget.unstick();
match stato.get_pos() {
Nascondendo => {
stato.set_pos(Nascosta);
}
_ => {
stato.set_pos(SuNonFocusata);
}
}
gtk::Inhibit(false)
@ -86,18 +138,16 @@ pub fn focus_in(
window: &gtk::ApplicationWindow,
stato: &Arc<RwLock<StatoFinestra>>,
) -> gtk::Inhibit {
if let Ok(mut inner) = stato.write() {
*inner = StatoFinestra::Su;
}
stato.set_pos(Su);
let s = calc_w_h(window);
window.set_type_hint(gdk::WindowTypeHint::Dock);
if let Some((_x, _y, width, height)) = window.get_window().and_then(|x| Some(x.get_geometry()))
{
if height != s.1 || width != s.0 {
if (height != s.1 || width != s.0) && stato.get_full() != Full {
window.hide();
window.resize( s.0, s.1);
window.resize(s.0, s.1);
window.show();
window.move_(0,0);
window.move_(0, 0);
}
}
gtk::Inhibit(false)