Optionally disable header bars with NVIM_GTK_NO_HEADERBAR=1

This commit is contained in:
Fabian Knorr 2017-09-10 20:49:41 +02:00
parent 9120c02d83
commit 3f2386885b

View File

@ -1,5 +1,5 @@
use std::cell::{RefCell, Ref, RefMut}; use std::cell::{RefCell, Ref, RefMut};
use std::thread; use std::{env, thread};
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
@ -25,7 +25,6 @@ pub struct Ui {
pub struct Components { pub struct Components {
window: Option<ApplicationWindow>, window: Option<ApplicationWindow>,
header_bar: HeaderBar,
open_btn: ToolButton, open_btn: ToolButton,
} }
@ -37,7 +36,6 @@ impl Components {
Components { Components {
open_btn: ToolButton::new(Some(&save_image), "Open"), open_btn: ToolButton::new(Some(&save_image), "Open"),
window: None, window: None,
header_bar: HeaderBar::new(),
} }
} }
@ -74,18 +72,35 @@ impl Ui {
} }
self.initialized = true; self.initialized = true;
// Only add an application menu if requested by the desktop environment as to avoid an
// additional menu bar just for the "About" item
if app.prefers_app_menu() {
self.create_main_menu(app); self.create_main_menu(app);
}
let mut settings = self.settings.borrow_mut(); let mut settings = self.settings.borrow_mut();
settings.init(); settings.init();
let mut comps = self.comps.borrow_mut(); let mut comps = self.comps.borrow_mut();
comps.header_bar.set_show_close_button(true); self.shell.borrow_mut().init();
comps.window = Some(ApplicationWindow::new(app));
let window = comps.window.as_ref().unwrap();
// Client side decorations including the toolbar are disabled via NVIM_GTK_NO_HEADERBAR=1
let mut use_header_bar = true;
if let Ok(opt) = env::var("NVIM_GTK_NO_HEADERBAR") {
if opt.trim() == "1" {
use_header_bar = false;
}
}
if use_header_bar {
let header_bar = HeaderBar::new();
let projects = self.projects.clone(); let projects = self.projects.clone();
comps.header_bar.pack_start(&comps.open_btn); header_bar.pack_start(&comps.open_btn);
comps comps
.open_btn .open_btn
.connect_clicked(move |_| projects.borrow_mut().show()); .connect_clicked(move |_| projects.borrow_mut().show());
@ -96,21 +111,19 @@ impl Ui {
let shell = self.shell.clone(); let shell = self.shell.clone();
save_btn.connect_clicked(move |_| shell.borrow_mut().edit_save_all()); save_btn.connect_clicked(move |_| shell.borrow_mut().edit_save_all());
comps.header_bar.pack_start(&save_btn); header_bar.pack_start(&save_btn);
let paste_image = Image::new_from_icon_name("edit-paste", let paste_image = Image::new_from_icon_name("edit-paste",
gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32); gtk_sys::GTK_ICON_SIZE_SMALL_TOOLBAR as i32);
let paste_btn = ToolButton::new(Some(&paste_image), "Paste"); let paste_btn = ToolButton::new(Some(&paste_image), "Paste");
let shell = self.shell.clone(); let shell = self.shell.clone();
paste_btn.connect_clicked(move |_| shell.borrow_mut().edit_paste()); paste_btn.connect_clicked(move |_| shell.borrow_mut().edit_paste());
comps.header_bar.pack_start(&paste_btn); header_bar.pack_start(&paste_btn);
header_bar.set_show_close_button(true);
self.shell.borrow_mut().init(); window.set_titlebar(Some(&header_bar));
}
comps.window = Some(ApplicationWindow::new(app));
let window = comps.window.as_ref().unwrap();
window.set_titlebar(Some(&comps.header_bar));
window.set_default_size(800, 600); window.set_default_size(800, 600);
let shell = self.shell.borrow(); let shell = self.shell.borrow();
@ -144,7 +157,6 @@ impl Ui {
app.set_app_menu(Some(&menu)); app.set_app_menu(Some(&menu));
let about_action = SimpleAction::new("HelpAbout", None); let about_action = SimpleAction::new("HelpAbout", None);
let comps = self.comps.clone(); let comps = self.comps.clone();
about_action.connect_activate(move |_, _| on_help_about(&*comps.borrow())); about_action.connect_activate(move |_, _| on_help_about(&*comps.borrow()));