Disable load window size option
This commit is contained in:
parent
0f377b7240
commit
babf2171f2
56
src/main.rs
56
src/main.rs
@ -1,29 +1,29 @@
|
|||||||
extern crate gtk;
|
extern crate cairo;
|
||||||
extern crate gtk_sys;
|
extern crate env_logger;
|
||||||
extern crate gio;
|
|
||||||
extern crate gdk;
|
extern crate gdk;
|
||||||
extern crate gdk_sys;
|
extern crate gdk_sys;
|
||||||
|
extern crate gio;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate glib;
|
extern crate glib;
|
||||||
extern crate glib_sys as glib_ffi;
|
extern crate glib_sys as glib_ffi;
|
||||||
extern crate gobject_sys as gobject_ffi;
|
extern crate gobject_sys as gobject_ffi;
|
||||||
extern crate cairo;
|
extern crate gtk;
|
||||||
extern crate pango;
|
extern crate gtk_sys;
|
||||||
extern crate pango_sys;
|
extern crate htmlescape;
|
||||||
extern crate pangocairo;
|
|
||||||
extern crate pango_cairo_sys;
|
|
||||||
extern crate neovim_lib;
|
|
||||||
extern crate phf;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate env_logger;
|
extern crate neovim_lib;
|
||||||
extern crate htmlescape;
|
extern crate pango;
|
||||||
|
extern crate pango_cairo_sys;
|
||||||
|
extern crate pango_sys;
|
||||||
|
extern crate pangocairo;
|
||||||
|
extern crate phf;
|
||||||
|
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate toml;
|
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
extern crate toml;
|
||||||
|
|
||||||
mod sys;
|
mod sys;
|
||||||
|
|
||||||
@ -49,7 +49,6 @@ mod project;
|
|||||||
mod tabline;
|
mod tabline;
|
||||||
mod error;
|
mod error;
|
||||||
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -61,6 +60,7 @@ use shell::ShellOptions;
|
|||||||
|
|
||||||
const BIN_PATH_ARG: &str = "--nvim-bin-path";
|
const BIN_PATH_ARG: &str = "--nvim-bin-path";
|
||||||
const TIMEOUT_ARG: &str = "--timeout";
|
const TIMEOUT_ARG: &str = "--timeout";
|
||||||
|
const DISABLE_WIN_STATE_RESTORE: &str = "--disable-win-restore";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init().expect("Can't initialize env_logger");
|
env_logger::init().expect("Can't initialize env_logger");
|
||||||
@ -89,6 +89,7 @@ fn main() {
|
|||||||
let argv: Vec<String> = args.iter()
|
let argv: Vec<String> = args.iter()
|
||||||
.filter(|a| !a.starts_with(BIN_PATH_ARG))
|
.filter(|a| !a.starts_with(BIN_PATH_ARG))
|
||||||
.filter(|a| !a.starts_with(TIMEOUT_ARG))
|
.filter(|a| !a.starts_with(TIMEOUT_ARG))
|
||||||
|
.filter(|a| !a.starts_with(DISABLE_WIN_STATE_RESTORE))
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
app.run(&argv);
|
app.run(&argv);
|
||||||
@ -102,7 +103,7 @@ fn open(app: >k::Application, files: &[gio::File], _: &str) {
|
|||||||
nvim_timeout(std::env::args()),
|
nvim_timeout(std::env::args()),
|
||||||
));
|
));
|
||||||
|
|
||||||
ui.init(app);
|
ui.init(app, !nvim_disable_win_state(std::env::args()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,16 +114,15 @@ fn activate(app: >k::Application) {
|
|||||||
nvim_timeout(std::env::args()),
|
nvim_timeout(std::env::args()),
|
||||||
));
|
));
|
||||||
|
|
||||||
ui.init(app);
|
ui.init(app, !nvim_disable_win_state(std::env::args()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nvim_bin_path<I>(mut args: I) -> Option<String>
|
fn nvim_bin_path<I>(mut args: I) -> Option<String>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = String>,
|
I: Iterator<Item = String>,
|
||||||
{
|
{
|
||||||
args.find(|a| a.starts_with(BIN_PATH_ARG)).and_then(|p| {
|
args.find(|a| a.starts_with(BIN_PATH_ARG))
|
||||||
p.split('=').nth(1).map(str::to_owned)
|
.and_then(|p| p.split('=').nth(1).map(str::to_owned))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nvim_timeout<I>(mut args: I) -> Option<Duration>
|
fn nvim_timeout<I>(mut args: I) -> Option<Duration>
|
||||||
@ -141,6 +141,15 @@ where
|
|||||||
.map(|timeout| Duration::from_secs(timeout))
|
.map(|timeout| Duration::from_secs(timeout))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn nvim_disable_win_state<I>(mut args: I) -> bool
|
||||||
|
where
|
||||||
|
I: Iterator<Item = String>,
|
||||||
|
{
|
||||||
|
args.find(|a| a.starts_with(DISABLE_WIN_STATE_RESTORE))
|
||||||
|
.map(|_| true)
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -157,14 +166,15 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_timeout_arg() {
|
fn test_timeout_arg() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Some(Duration::from_secs(100)),
|
Some(Duration::from_secs(100)),
|
||||||
nvim_timeout(vec!["neovim-gtk", "--timeout=100"].iter().map(
|
nvim_timeout(
|
||||||
|s| s.to_string(),
|
vec!["neovim-gtk", "--timeout=100"]
|
||||||
))
|
.iter()
|
||||||
|
.map(|s| s.to_string(),)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/ui.rs
27
src/ui.rs
@ -35,6 +35,9 @@ macro_rules! clone {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFAULT_WIDTH: i32 = 800;
|
||||||
|
const DEFAULT_HEIGHT: i32 = 600;
|
||||||
|
|
||||||
pub struct Ui {
|
pub struct Ui {
|
||||||
initialized: bool,
|
initialized: bool,
|
||||||
comps: Arc<UiMutex<Components>>,
|
comps: Arc<UiMutex<Components>>,
|
||||||
@ -93,7 +96,7 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&mut self, app: >k::Application) {
|
pub fn init(&mut self, app: >k::Application, restore_win_state: bool) {
|
||||||
if self.initialized {
|
if self.initialized {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -165,12 +168,17 @@ impl Ui {
|
|||||||
window.set_titlebar(Some(&header_bar));
|
window.set_titlebar(Some(&header_bar));
|
||||||
}
|
}
|
||||||
|
|
||||||
window.set_default_size(
|
if restore_win_state {
|
||||||
comps.window_state.current_width,
|
if comps.window_state.is_maximized {
|
||||||
comps.window_state.current_height,
|
window.maximize();
|
||||||
);
|
}
|
||||||
if comps.window_state.is_maximized {
|
|
||||||
window.maximize();
|
window.set_default_size(
|
||||||
|
comps.window_state.current_width,
|
||||||
|
comps.window_state.current_height,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
window.set_default_size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,8 +317,8 @@ struct WindowState {
|
|||||||
impl WindowState {
|
impl WindowState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
WindowState {
|
WindowState {
|
||||||
current_width: 800,
|
current_width: DEFAULT_WIDTH,
|
||||||
current_height: 600,
|
current_height: DEFAULT_HEIGHT,
|
||||||
is_maximized: false,
|
is_maximized: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -328,7 +336,6 @@ impl SettingsLoader for WindowState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct UiMutex<T: ?Sized> {
|
pub struct UiMutex<T: ?Sized> {
|
||||||
thread: thread::ThreadId,
|
thread: thread::ThreadId,
|
||||||
data: RefCell<T>,
|
data: RefCell<T>,
|
||||||
|
Loading…
Reference in New Issue
Block a user