Risolto flashing psichedelico con full screen
parent
e3b6cfc336
commit
a0425f01f5
34
src/main.rs
34
src/main.rs
|
|
@ -15,6 +15,7 @@ mod menu;
|
||||||
mod stato_finestra;
|
mod stato_finestra;
|
||||||
mod tabs;
|
mod tabs;
|
||||||
mod wake_listener;
|
mod wake_listener;
|
||||||
|
use stato_finestra::OperazStato;
|
||||||
|
|
||||||
fn build_ui(application: >k::Application) {
|
fn build_ui(application: >k::Application) {
|
||||||
let window = gtk::ApplicationWindow::new(application);
|
let window = gtk::ApplicationWindow::new(application);
|
||||||
|
|
@ -70,6 +71,13 @@ fn build_ui(application: >k::Application) {
|
||||||
);
|
);
|
||||||
let (key, modifier) = gtk::accelerator_parse("F11");
|
let (key, modifier) = gtk::accelerator_parse("F11");
|
||||||
let full_screen = Arc::new(RwLock::new(false));
|
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(
|
accel_group.connect_accel_group(
|
||||||
key,
|
key,
|
||||||
modifier,
|
modifier,
|
||||||
|
|
@ -78,8 +86,10 @@ fn build_ui(application: >k::Application) {
|
||||||
if let Ok(mut lock) = full_screen.write(){
|
if let Ok(mut lock) = full_screen.write(){
|
||||||
if *lock {
|
if *lock {
|
||||||
window.unfullscreen();
|
window.unfullscreen();
|
||||||
|
stato5.set_full(stato_finestra::StatoFull::NonFull);
|
||||||
} else {
|
} else {
|
||||||
window.fullscreen();
|
window.fullscreen();
|
||||||
|
stato5.set_full(stato_finestra::StatoFull::Full);
|
||||||
}
|
}
|
||||||
*lock = !*lock;
|
*lock = !*lock;
|
||||||
}
|
}
|
||||||
|
|
@ -118,29 +128,19 @@ fn build_ui(application: >k::Application) {
|
||||||
true.to_glib(),
|
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_out_event(move |_widget, _b| stato_finestra::focus_out(&stato1));
|
||||||
window.connect_focus_in_event(clone!(@weak window => @default-return gtk::Inhibit(false),
|
window.connect_focus_in_event(clone!(@weak window => @default-return gtk::Inhibit(false),
|
||||||
move |_widget, _b| stato_finestra::focus_in(&window, &stato2)));
|
move |_widget, _b| stato_finestra::focus_in(&window, &stato2)));
|
||||||
nb.connect_destroy(move |_nb| {
|
nb.connect_destroy(move |_nb| {
|
||||||
if let Ok(mut lock_stato) = stato.write() {
|
stato.set_pos(stato_finestra::PosizFinestra::Chiudendo);
|
||||||
*lock_stato = stato_finestra::StatoFinestra::Chiudendo;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
nb.connect_page_removed(
|
nb.connect_page_removed(
|
||||||
clone!(@weak window => move |notebook, _vte, _index| {
|
clone!(@weak window => move |notebook, _vte, _index| {
|
||||||
if notebook.get_n_pages() == 0 {
|
if notebook.get_n_pages() == 0 {
|
||||||
if let Ok(mut lock_stato) = stato0.write() {
|
if stato0.get_pos() != stato_finestra::PosizFinestra::Chiudendo {
|
||||||
if *lock_stato != stato_finestra::StatoFinestra::Chiudendo {
|
|
||||||
crate::tabs::apri_tab(&window, ¬ebook, false,None, None, None);
|
crate::tabs::apri_tab(&window, ¬ebook, false,None, None, None);
|
||||||
stato_finestra::butta_giu(&window, &mut lock_stato);
|
stato_finestra::butta_giu(&window, &stato0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tabs::set_titles(¬ebook);
|
tabs::set_titles(¬ebook);
|
||||||
|
|
@ -160,15 +160,11 @@ fn build_ui(application: >k::Application) {
|
||||||
});
|
});
|
||||||
|
|
||||||
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||||
if let Ok(ref mut lock_stato) = stato4.write() {
|
stato_finestra::tira_su(&window, &stato4, gtk::get_current_event_time());
|
||||||
stato_finestra::tira_su(&window, lock_stato, 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 = || {
|
||||||
if let Ok(ref mut lock_stato) = stato3.write() {
|
stato_finestra::tira_su(&window, &stato3, gtk::get_current_event_time());
|
||||||
stato_finestra::tira_su(&window, lock_stato, gtk::get_current_event_time());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
use wake_listener::RpcCommand::*;
|
use wake_listener::RpcCommand::*;
|
||||||
match cmd {
|
match cmd {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,72 @@
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
|
||||||
pub enum StatoFinestra {
|
pub enum PosizFinestra {
|
||||||
Su,
|
Su,
|
||||||
TirandoSu,
|
TirandoSu,
|
||||||
Nascondendo,
|
Nascondendo,
|
||||||
Nascosta,
|
Nascosta,
|
||||||
SuNonFocusata,
|
SuNonFocusata,
|
||||||
Chiudendo,
|
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 gdk::WindowExt;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
pub fn tira_su(window: >k::ApplicationWindow, stato: &mut StatoFinestra, ts: u32) {
|
pub fn tira_su(window: >k::ApplicationWindow, stato: &Arc<RwLock<StatoFinestra>>, ts: u32) {
|
||||||
match *stato {
|
let new_pos = match stato.get_pos() {
|
||||||
StatoFinestra::Nascosta | StatoFinestra::Nascondendo => {
|
Nascosta | Nascondendo => {
|
||||||
// Shameless copy from guake
|
// Shameless copy from guake
|
||||||
/*window.hide();
|
/*window.hide();
|
||||||
window.present();
|
window.present();
|
||||||
|
|
@ -27,9 +80,9 @@ pub fn tira_su(window: >k::ApplicationWindow, stato: &mut StatoFinestra, ts: u
|
||||||
/*if let Some(ref gdk_window) = gdk_window {
|
/*if let Some(ref gdk_window) = gdk_window {
|
||||||
gdk_window.focus(0);
|
gdk_window.focus(0);
|
||||||
}*/
|
}*/
|
||||||
*stato = StatoFinestra::TirandoSu;
|
Some(TirandoSu)
|
||||||
}
|
}
|
||||||
StatoFinestra::SuNonFocusata => {
|
SuNonFocusata => {
|
||||||
window.hide();
|
window.hide();
|
||||||
window.show();
|
window.show();
|
||||||
let gdk_window = window.get_window();
|
let gdk_window = window.get_window();
|
||||||
|
|
@ -39,14 +92,17 @@ pub fn tira_su(window: >k::ApplicationWindow, stato: &mut StatoFinestra, ts: u
|
||||||
}
|
}
|
||||||
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));
|
||||||
*stato = StatoFinestra::Su;
|
Some(Su)
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => None,
|
||||||
|
};
|
||||||
|
if let Some(new_pos) = new_pos {
|
||||||
|
stato.set_pos(new_pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn butta_giu(window: >k::ApplicationWindow, stato: &mut StatoFinestra) {
|
pub fn butta_giu(window: >k::ApplicationWindow, stato: &Arc<RwLock<StatoFinestra>>) {
|
||||||
*stato = StatoFinestra::Nascondendo;
|
stato.set_pos(Nascondendo);
|
||||||
window.hide();
|
window.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,27 +112,23 @@ pub fn esegui_toggle(
|
||||||
stato: &Arc<RwLock<StatoFinestra>>,
|
stato: &Arc<RwLock<StatoFinestra>>,
|
||||||
) {
|
) {
|
||||||
let ts = gtk::get_current_event_time();
|
let ts = gtk::get_current_event_time();
|
||||||
if let Ok(mut inner) = stato.write() {
|
match stato.get_pos() {
|
||||||
match *inner {
|
Nascosta | Nascondendo | SuNonFocusata => {
|
||||||
StatoFinestra::Nascosta | StatoFinestra::Nascondendo | StatoFinestra::SuNonFocusata => {
|
tira_su(window, stato, ts);
|
||||||
tira_su(window, &mut inner, ts);
|
|
||||||
crate::tabs::focus_tab_corrente(&nb);
|
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 {
|
pub fn focus_out(stato: &Arc<RwLock<StatoFinestra>>) -> gtk::Inhibit {
|
||||||
if let Ok(mut inner) = stato.write() {
|
match stato.get_pos() {
|
||||||
if *inner == StatoFinestra::Nascondendo {
|
Nascondendo => {
|
||||||
*inner = StatoFinestra::Nascosta;
|
stato.set_pos(Nascosta);
|
||||||
} else {
|
}
|
||||||
*inner = StatoFinestra::SuNonFocusata;
|
_ => {
|
||||||
//widget.unstick();
|
stato.set_pos(SuNonFocusata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gtk::Inhibit(false)
|
gtk::Inhibit(false)
|
||||||
|
|
@ -86,18 +138,16 @@ pub fn focus_in(
|
||||||
window: >k::ApplicationWindow,
|
window: >k::ApplicationWindow,
|
||||||
stato: &Arc<RwLock<StatoFinestra>>,
|
stato: &Arc<RwLock<StatoFinestra>>,
|
||||||
) -> gtk::Inhibit {
|
) -> gtk::Inhibit {
|
||||||
if let Ok(mut inner) = stato.write() {
|
stato.set_pos(Su);
|
||||||
*inner = StatoFinestra::Su;
|
|
||||||
}
|
|
||||||
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);
|
||||||
if let Some((_x, _y, width, height)) = window.get_window().and_then(|x| Some(x.get_geometry()))
|
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.hide();
|
||||||
window.resize( s.0, s.1);
|
window.resize(s.0, s.1);
|
||||||
window.show();
|
window.show();
|
||||||
window.move_(0,0);
|
window.move_(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gtk::Inhibit(false)
|
gtk::Inhibit(false)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue