Prova notebook + fix listener

master
Pietro Brenna 2020-03-13 16:20:06 +01:00
parent 90fecb55c2
commit e9da738f93
3 changed files with 21 additions and 16 deletions

View File

@ -30,6 +30,8 @@ fn build_ui(application: &gtk::Application) {
window.set_can_focus(true); window.set_can_focus(true);
window.set_keep_above(true); window.set_keep_above(true);
let nb = gtk::Notebook::new();
let l = gtk::Label::new(Some("Prova1"));
//gtk::Window::set_interactive_debugging(true); //gtk::Window::set_interactive_debugging(true);
let vte = vte::Terminal::new(); let vte = vte::Terminal::new();
let accel_group = gtk::AccelGroup::new(); let accel_group = gtk::AccelGroup::new();
@ -52,15 +54,14 @@ fn build_ui(application: &gtk::Application) {
) )
.unwrap(); .unwrap();
vte.watch_child(pid); vte.watch_child(pid);
let button = gtk::Button::new_with_label("Click me!"); nb.set_show_border(false);
button.connect_clicked(|_asd| { nb.append_page(&vte, Some(&l));
println!("ciao");
});
window.add(&vte); window.add(&nb);
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.set_focus(Some(&vte));
window.show_all(); window.show_all();
unsafe { unsafe {
gdk_sys::gdk_window_set_skip_pager_hint(window.get_window().unwrap().to_glib_none().0, true.to_glib()); gdk_sys::gdk_window_set_skip_pager_hint(window.get_window().unwrap().to_glib_none().0, true.to_glib());
@ -86,6 +87,7 @@ fn build_ui(application: &gtk::Application) {
gtk::Inhibit(false) gtk::Inhibit(false)
}); });
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
stato_finestra::focussa(&window, &vte, gtk::get_current_event_time());
rx.attach(None, move |_cmd| { rx.attach(None, move |_cmd| {
stato_finestra::esegui_toggle(&window, &vte, &stato) stato_finestra::esegui_toggle(&window, &vte, &stato)
}); });

View File

@ -10,6 +10,18 @@ use gdk::WindowExt;
use gtk::prelude::*; use gtk::prelude::*;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
pub fn focussa(window: &gtk::ApplicationWindow, vte: &impl glib::IsA<gtk::Widget>, ts: u32) {
// Shameless copy from guake
window.present();
window.deiconify();
window.show();
window.get_window().unwrap().focus(ts);
window.set_type_hint(gdk::WindowTypeHint::Dock);
window.set_type_hint(gdk::WindowTypeHint::Normal);
window.get_window().unwrap().focus(0);
window.set_focus(Some(vte));
}
pub fn esegui_toggle( pub fn esegui_toggle(
window: &gtk::ApplicationWindow, window: &gtk::ApplicationWindow,
vte: &impl glib::IsA<gtk::Widget>, vte: &impl glib::IsA<gtk::Widget>,
@ -19,16 +31,8 @@ pub fn esegui_toggle(
if let Ok(mut inner) = stato.write() { if let Ok(mut inner) = stato.write() {
match *inner { match *inner {
StatoFinestra::Nascosta | StatoFinestra::Nascondendo => { StatoFinestra::Nascosta | StatoFinestra::Nascondendo => {
// Shameless copy from guake
*inner = StatoFinestra::TirandoSu; *inner = StatoFinestra::TirandoSu;
window.present(); focussa(window, vte, ts);
window.deiconify();
window.show();
window.get_window().unwrap().focus(ts);
window.set_type_hint(gdk::WindowTypeHint::Dock);
window.set_type_hint(gdk::WindowTypeHint::Normal);
window.get_window().unwrap().focus(0);
window.set_focus(Some(vte));
} }
StatoFinestra::SuNonFocusata => { StatoFinestra::SuNonFocusata => {
window.hide(); window.hide();

View File

@ -1,5 +1,4 @@
use glib::Sender; use glib::Sender;
use gtk::get_current_event_time;
pub fn listener(tx: &Sender<u32>) { pub fn listener(tx: &Sender<u32>) {
use std::io::Read; use std::io::Read;
@ -12,7 +11,7 @@ pub fn listener(tx: &Sender<u32>) {
let mut buf = [0u8]; let mut buf = [0u8];
if let Ok(_n) = stream.read_exact(&mut buf) { if let Ok(_n) = stream.read_exact(&mut buf) {
let _s = String::from_utf8_lossy(&buf).into_owned(); let _s = String::from_utf8_lossy(&buf).into_owned();
tx.send(get_current_event_time()).expect("can't send"); tx.send(0).expect("can't send");
} }
} }
Err(err) => { Err(err) => {