Traduz inglese
parent
efb473c6fc
commit
93d44a0c99
58
src/main.rs
58
src/main.rs
|
|
@ -11,11 +11,11 @@ use std::env::args;
|
|||
use std::thread;
|
||||
|
||||
mod menu;
|
||||
mod stato_finestra;
|
||||
mod tabs;
|
||||
mod wake_listener;
|
||||
mod window_state;
|
||||
use crate::vte::TerminalExt;
|
||||
use stato_finestra::{OperazStato, PosizFinestra, StatoFinestra, StatoFull};
|
||||
use window_state::{FullScreenState, StateOperations, WindowPos, WindowState};
|
||||
|
||||
fn build_ui(application: >k::Application) {
|
||||
let window = gtk::ApplicationWindow::new(application);
|
||||
|
|
@ -45,7 +45,7 @@ fn build_ui(application: >k::Application) {
|
|||
modifier,
|
||||
gtk::AccelFlags::VISIBLE,
|
||||
clone!(@weak window, @weak nb => @default-return true, move |_accel_g, _window, _key, _modif| {
|
||||
tabs::apri_tab(&window, &nb, true, None, None, None);
|
||||
tabs::open_tab(&window, &nb, true, None, None, None);
|
||||
true
|
||||
}),
|
||||
);
|
||||
|
|
@ -86,26 +86,26 @@ fn build_ui(application: >k::Application) {
|
|||
}),
|
||||
);
|
||||
let (key, modifier) = gtk::accelerator_parse("F11");
|
||||
let stato = StatoFinestra::new_arc(PosizFinestra::Su, StatoFull::NonFull);
|
||||
let stato0 = stato.clone();
|
||||
let stato1 = stato.clone();
|
||||
let stato2 = stato.clone();
|
||||
let stato3 = stato.clone();
|
||||
let stato4 = stato.clone();
|
||||
let stato5 = stato.clone();
|
||||
let w_state = WindowState::new_arc(WindowPos::Up, FullScreenState::NotFull);
|
||||
let w_state0 = w_state.clone();
|
||||
let w_state1 = w_state.clone();
|
||||
let w_state2 = w_state.clone();
|
||||
let w_state3 = w_state.clone();
|
||||
let w_state4 = w_state.clone();
|
||||
let w_state5 = w_state.clone();
|
||||
accel_group.connect_accel_group(
|
||||
key,
|
||||
modifier,
|
||||
gtk::AccelFlags::VISIBLE,
|
||||
clone!(@weak window => @default-return true, move |_accel_g, _win, _key, _modif| {
|
||||
match stato5.get_full() {
|
||||
StatoFull::Full => {
|
||||
match w_state5.get_full() {
|
||||
FullScreenState::Full => {
|
||||
window.unfullscreen();
|
||||
stato5.set_full(StatoFull::NonFull);
|
||||
w_state5.set_full(FullScreenState::NotFull);
|
||||
}
|
||||
StatoFull::NonFull => {
|
||||
FullScreenState::NotFull => {
|
||||
window.fullscreen();
|
||||
stato5.set_full(StatoFull::Full);
|
||||
w_state5.set_full(FullScreenState::Full);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -128,8 +128,8 @@ fn build_ui(application: >k::Application) {
|
|||
window.add_accel_group(&accel_group);
|
||||
|
||||
window.add(&nb);
|
||||
if let Ok(first_tab) = tabs::build_tab(&window, &nb, None, None) {
|
||||
tabs::passa_a_tab(&window, &nb, &first_tab);
|
||||
if let Ok(first_tab) = tabs::build_tab(&nb, None, None) {
|
||||
tabs::go_to_tab(&window, &nb, &first_tab);
|
||||
}
|
||||
window.set_skip_taskbar_hint(true);
|
||||
window.set_skip_pager_hint(true);
|
||||
|
|
@ -145,17 +145,17 @@ fn build_ui(application: >k::Application) {
|
|||
);
|
||||
}*/
|
||||
|
||||
window.connect_focus_out_event(move |_widget, _b| stato_finestra::focus_out(&stato1));
|
||||
window.connect_focus_out_event(move |_widget, _b| window_state::focus_out(&w_state1));
|
||||
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| window_state::focus_in(&window, &w_state2)));
|
||||
nb.connect_destroy(move |_nb| {
|
||||
stato.set_pos(PosizFinestra::Chiudendo);
|
||||
w_state.set_pos(WindowPos::Closing);
|
||||
});
|
||||
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);
|
||||
if w_state0.get_pos() != WindowPos::Closing {
|
||||
crate::tabs::open_tab(&window, ¬ebook, false,None, None, None);
|
||||
window_state::hide(&window, &w_state0);
|
||||
}
|
||||
} else {
|
||||
tabs::set_titles(¬ebook);
|
||||
|
|
@ -174,24 +174,24 @@ fn build_ui(application: >k::Application) {
|
|||
});
|
||||
|
||||
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||
stato_finestra::tira_su(&window, &stato4, 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 = || {
|
||||
stato_finestra::tira_su(&window, &stato3, gtk::get_current_event_time());
|
||||
window_state::bring_up(&window, &w_state3, gtk::get_current_event_time());
|
||||
};
|
||||
use wake_listener::RpcCommand::*;
|
||||
match cmd {
|
||||
Toggle => {
|
||||
stato_finestra::esegui_toggle(&window, &nb, &stato3);
|
||||
window_state::esegui_toggle(&window, &nb, &w_state3);
|
||||
}
|
||||
RunShell { cwd, shell } => {
|
||||
tira_su();
|
||||
tabs::apri_tab(&window, &nb, true, cwd, Some(shell), None);
|
||||
tabs::open_tab(&window, &nb, true, cwd, Some(shell), None);
|
||||
}
|
||||
RunInDefaultShell { cwd, command } => {
|
||||
tira_su();
|
||||
tabs::apri_tab(&window, &nb, true, cwd, None, Some(command));
|
||||
tabs::open_tab(&window, &nb, true, cwd, None, Some(command));
|
||||
}
|
||||
RunInCustomShell {
|
||||
cwd,
|
||||
|
|
@ -199,7 +199,7 @@ fn build_ui(application: >k::Application) {
|
|||
command,
|
||||
} => {
|
||||
tira_su();
|
||||
tabs::apri_tab(&window, &nb, true, cwd, Some(shell), Some(command));
|
||||
tabs::open_tab(&window, &nb, true, cwd, Some(shell), Some(command));
|
||||
}
|
||||
}
|
||||
glib::Continue(true)
|
||||
|
|
|
|||
21
src/tabs.rs
21
src/tabs.rs
|
|
@ -4,26 +4,16 @@ use std::{env::var, path::Path};
|
|||
use vte::TerminalExt;
|
||||
|
||||
pub fn build_tab(
|
||||
window: >k::ApplicationWindow,
|
||||
nb: >k::Notebook,
|
||||
cwd: Option<String>,
|
||||
shell: Option<Vec<String>>,
|
||||
) -> Result<vte::Terminal, glib::Error> {
|
||||
let new_accel_g = gtk::AccelGroup::new();
|
||||
let l = gtk::Label::new(Some("~"));
|
||||
l.set_width_chars(14);
|
||||
l.set_ellipsize(pango::EllipsizeMode::Middle);
|
||||
//gtk::Window::set_interactive_debugging(true);
|
||||
let vte = vte::Terminal::new();
|
||||
vte.set_scrollback_lines(-1);
|
||||
// let (key, modifier) = gtk::accelerator_parse("<Control><Shift>c");
|
||||
// vte.add_accelerator(
|
||||
// "copy-clipboard",
|
||||
// &new_accel_g,
|
||||
// key,
|
||||
// modifier,
|
||||
// gtk::AccelFlags::VISIBLE,
|
||||
// );
|
||||
|
||||
let font = pango::FontDescription::from_string("Iosevka Regular 13");
|
||||
vte.set_font(Some(&font));
|
||||
|
|
@ -66,7 +56,6 @@ pub fn build_tab(
|
|||
vte.connect_window_title_changed(clone!(@weak nb => move |term| {
|
||||
set_title(term, &nb);
|
||||
}));
|
||||
window.add_accel_group(&new_accel_g);
|
||||
// Setto colori terminale
|
||||
use glib::translate::ToGlibPtr;
|
||||
use std::str::FromStr;
|
||||
|
|
@ -130,12 +119,12 @@ pub fn set_titles(nb: >k::Notebook) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn passa_a_tab(win: >k::ApplicationWindow, nb: >k::Notebook, vte: &vte::Terminal) {
|
||||
pub fn go_to_tab(win: >k::ApplicationWindow, nb: >k::Notebook, vte: &vte::Terminal) {
|
||||
let p_num = nb.page_num(vte);
|
||||
nb.set_current_page(p_num);
|
||||
win.set_focus(Some(vte));
|
||||
}
|
||||
pub fn focus_tab_corrente(nb: >k::Notebook) {
|
||||
pub fn focus_current_tab(nb: >k::Notebook) {
|
||||
let n_p = nb.get_current_page();
|
||||
let vte = nb.get_nth_page(n_p);
|
||||
if let Some(vte) = vte {
|
||||
|
|
@ -149,7 +138,7 @@ pub fn focus_tab_corrente(nb: >k::Notebook) {
|
|||
fn inject(term: &vte::Terminal, command: String) {
|
||||
term.feed_child_binary(format!("{}\n", command.trim()).as_bytes());
|
||||
}
|
||||
pub fn apri_tab(
|
||||
pub fn open_tab(
|
||||
window: >k::ApplicationWindow,
|
||||
nb: >k::Notebook,
|
||||
focus: bool,
|
||||
|
|
@ -157,11 +146,11 @@ pub fn apri_tab(
|
|||
shell: Option<Vec<String>>,
|
||||
inject_command: Option<String>,
|
||||
) {
|
||||
let new_tab = build_tab(window, nb, cwd, shell);
|
||||
let new_tab = build_tab(nb, cwd, shell);
|
||||
if let Ok(new_tab) = new_tab {
|
||||
window.show_all();
|
||||
if focus {
|
||||
crate::tabs::passa_a_tab(&window, &nb, &new_tab);
|
||||
crate::tabs::go_to_tab(&window, &nb, &new_tab);
|
||||
}
|
||||
if let Some(command) = inject_command {
|
||||
inject(&new_tab, command);
|
||||
|
|
|
|||
|
|
@ -5,68 +5,68 @@ use std::sync::RwLock;
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
|
||||
pub enum PosizFinestra {
|
||||
Su,
|
||||
TirandoSu,
|
||||
Nascondendo,
|
||||
Nascosta,
|
||||
SuNonFocusata,
|
||||
Chiudendo,
|
||||
Sconosciuta,
|
||||
pub enum WindowPos {
|
||||
Up,
|
||||
BringingUp,
|
||||
Hiding,
|
||||
Hidden,
|
||||
UpWithoutFocus,
|
||||
Closing,
|
||||
Unknown,
|
||||
}
|
||||
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
|
||||
pub enum StatoFull {
|
||||
pub enum FullScreenState {
|
||||
Full,
|
||||
NonFull,
|
||||
Sconosciuto,
|
||||
NotFull,
|
||||
Unknown,
|
||||
}
|
||||
pub use PosizFinestra::*;
|
||||
pub use StatoFull::*;
|
||||
pub struct StatoFinestra {
|
||||
posiz: PosizFinestra,
|
||||
full: StatoFull,
|
||||
pub use FullScreenState::*;
|
||||
pub use WindowPos::*;
|
||||
pub struct WindowState {
|
||||
position: WindowPos,
|
||||
full: FullScreenState,
|
||||
last_toggle: Option<Instant>,
|
||||
}
|
||||
impl StatoFinestra {
|
||||
pub fn new_arc(p: PosizFinestra, f: StatoFull) -> Rc<RwLock<Self>> {
|
||||
Rc::new(RwLock::new(StatoFinestra {
|
||||
impl WindowState {
|
||||
pub fn new_arc(p: WindowPos, f: FullScreenState) -> Rc<RwLock<Self>> {
|
||||
Rc::new(RwLock::new(WindowState {
|
||||
full: f,
|
||||
posiz: p,
|
||||
position: p,
|
||||
last_toggle: None,
|
||||
}))
|
||||
}
|
||||
}
|
||||
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;
|
||||
pub trait StateOperations {
|
||||
fn set_pos(&self, p: WindowPos);
|
||||
fn get_pos(&self) -> WindowPos;
|
||||
fn set_full(&self, f: FullScreenState);
|
||||
fn get_full(&self) -> FullScreenState;
|
||||
fn set_last_toggle(&self, instant: Option<Instant>);
|
||||
fn get_last_toggle(&self) -> Option<Instant>;
|
||||
}
|
||||
impl OperazStato for Rc<RwLock<StatoFinestra>> {
|
||||
fn set_pos(&self, p: PosizFinestra) {
|
||||
impl StateOperations for Rc<RwLock<WindowState>> {
|
||||
fn set_pos(&self, p: WindowPos) {
|
||||
if let Ok(mut w_lock) = self.write() {
|
||||
w_lock.posiz = p;
|
||||
w_lock.position = p;
|
||||
}
|
||||
}
|
||||
fn get_pos(&self) -> PosizFinestra {
|
||||
fn get_pos(&self) -> WindowPos {
|
||||
if let Ok(r_lock) = self.read() {
|
||||
r_lock.posiz
|
||||
r_lock.position
|
||||
} else {
|
||||
Sconosciuta
|
||||
WindowPos::Unknown
|
||||
}
|
||||
}
|
||||
fn set_full(&self, full: StatoFull) {
|
||||
fn set_full(&self, full: FullScreenState) {
|
||||
if let Ok(mut w_lock) = self.write() {
|
||||
w_lock.full = full;
|
||||
}
|
||||
}
|
||||
fn get_full(&self) -> StatoFull {
|
||||
fn get_full(&self) -> FullScreenState {
|
||||
if let Ok(r_lock) = self.read() {
|
||||
r_lock.full
|
||||
} else {
|
||||
Sconosciuto
|
||||
FullScreenState::Unknown
|
||||
}
|
||||
}
|
||||
fn get_last_toggle(&self) -> Option<Instant> {
|
||||
|
|
@ -83,15 +83,15 @@ impl OperazStato for Rc<RwLock<StatoFinestra>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn tira_su(window: >k::ApplicationWindow, stato: &Rc<RwLock<StatoFinestra>>, ts: u32) {
|
||||
if let Some(instant) = stato.get_last_toggle() {
|
||||
pub fn bring_up(window: >k::ApplicationWindow, w_state: &Rc<RwLock<WindowState>>, ts: u32) {
|
||||
if let Some(instant) = w_state.get_last_toggle() {
|
||||
if instant.elapsed() < Duration::from_millis(300) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
stato.set_last_toggle(Some(Instant::now()));
|
||||
let new_pos = match stato.get_pos() {
|
||||
Nascosta | Nascondendo => {
|
||||
w_state.set_last_toggle(Some(Instant::now()));
|
||||
let new_pos = match w_state.get_pos() {
|
||||
Hidden | Hiding => {
|
||||
// Shameless copy from guake
|
||||
/*window.hide();
|
||||
window.present();
|
||||
|
|
@ -105,9 +105,9 @@ pub fn tira_su(window: >k::ApplicationWindow, stato: &Rc<RwLock<StatoFinestra>
|
|||
/*if let Some(ref gdk_window) = gdk_window {
|
||||
gdk_window.focus(0);
|
||||
}*/
|
||||
Some(TirandoSu)
|
||||
Some(BringingUp)
|
||||
}
|
||||
SuNonFocusata => {
|
||||
UpWithoutFocus => {
|
||||
window.hide();
|
||||
window.show();
|
||||
let gdk_window = window.get_window();
|
||||
|
|
@ -117,43 +117,43 @@ pub fn tira_su(window: >k::ApplicationWindow, stato: &Rc<RwLock<StatoFinestra>
|
|||
}
|
||||
let s = calc_w_h(window);
|
||||
window.get_window().map(|w| w.resize(s.0, s.1));
|
||||
Some(Su)
|
||||
Some(Up)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some(new_pos) = new_pos {
|
||||
stato.set_pos(new_pos);
|
||||
w_state.set_pos(new_pos);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn butta_giu(window: >k::ApplicationWindow, stato: &Rc<RwLock<StatoFinestra>>) {
|
||||
stato.set_pos(Nascondendo);
|
||||
pub fn hide(window: >k::ApplicationWindow, stato: &Rc<RwLock<WindowState>>) {
|
||||
stato.set_pos(Hiding);
|
||||
window.hide();
|
||||
}
|
||||
|
||||
pub fn esegui_toggle(
|
||||
window: >k::ApplicationWindow,
|
||||
nb: >k::Notebook,
|
||||
stato: &Rc<RwLock<StatoFinestra>>,
|
||||
w_state: &Rc<RwLock<WindowState>>,
|
||||
) {
|
||||
let ts = gtk::get_current_event_time();
|
||||
match stato.get_pos() {
|
||||
Nascosta | Nascondendo | SuNonFocusata => {
|
||||
tira_su(window, stato, ts);
|
||||
crate::tabs::focus_tab_corrente(&nb);
|
||||
match w_state.get_pos() {
|
||||
Hidden | Hiding | UpWithoutFocus => {
|
||||
bring_up(window, w_state, ts);
|
||||
crate::tabs::focus_current_tab(&nb);
|
||||
}
|
||||
Su => butta_giu(window, &stato),
|
||||
Up => hide(window, &w_state),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn focus_out(stato: &Rc<RwLock<StatoFinestra>>) -> gtk::Inhibit {
|
||||
match stato.get_pos() {
|
||||
Nascondendo => {
|
||||
stato.set_pos(Nascosta);
|
||||
pub fn focus_out(w_state: &Rc<RwLock<WindowState>>) -> gtk::Inhibit {
|
||||
match w_state.get_pos() {
|
||||
Hiding => {
|
||||
w_state.set_pos(Hidden);
|
||||
}
|
||||
_ => {
|
||||
stato.set_pos(SuNonFocusata);
|
||||
w_state.set_pos(UpWithoutFocus);
|
||||
}
|
||||
}
|
||||
gtk::Inhibit(false)
|
||||
|
|
@ -161,14 +161,14 @@ pub fn focus_out(stato: &Rc<RwLock<StatoFinestra>>) -> gtk::Inhibit {
|
|||
|
||||
pub fn focus_in(
|
||||
window: >k::ApplicationWindow,
|
||||
stato: &Rc<RwLock<StatoFinestra>>,
|
||||
w_state: &Rc<RwLock<WindowState>>,
|
||||
) -> gtk::Inhibit {
|
||||
stato.set_pos(Su);
|
||||
w_state.set_pos(Up);
|
||||
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) && stato.get_full() != Full {
|
||||
if (height != s.1 || width != s.0) && w_state.get_full() != Full {
|
||||
window.hide();
|
||||
window.resize(s.0, s.1);
|
||||
window.show();
|
||||
Loading…
Reference in New Issue