Allow user provided geometry

macos-click-through
Aamr El Kazdadi 5 years ago
parent 2815a28e68
commit 89e8a839b4

@ -17,7 +17,7 @@ use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use crate::error_handling::ResultPanicExplanation;
use crate::settings::*;
use crate::INITIAL_DIMENSIONS;
use crate::window::window_geometry_or_default;
pub use events::*;
use handler::NeovimHandler;
pub use layouts::*;
@ -58,7 +58,7 @@ async fn drain(receiver: &mut UnboundedReceiver<UiCommand>) -> Option<Vec<UiComm
}
async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
let (width, height) = INITIAL_DIMENSIONS;
let (width, height) = window_geometry_or_default();
let (mut nvim, io_handler, _) =
create::new_child_cmd(&mut create_nvim_command(), NeovimHandler())
.await

@ -12,7 +12,7 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::bridge::{GridLineCell, GuiOption, RedrawEvent};
use crate::redraw_scheduler::REDRAW_SCHEDULER;
use crate::INITIAL_DIMENSIONS;
use crate::window::window_geometry_or_default;
pub use cursor::{Cursor, CursorMode, CursorShape};
pub use grid::CharacterGrid;
pub use style::{Colors, Style};
@ -43,7 +43,7 @@ pub struct Editor {
impl Editor {
pub fn new() -> Editor {
let mut editor = Editor {
grid: CharacterGrid::new(INITIAL_DIMENSIONS),
grid: CharacterGrid::new(window_geometry_or_default()),
title: "Neovide".to_string(),
font_name: None,
font_size: None,

@ -20,11 +20,17 @@ extern crate lazy_static;
use lazy_static::initialize;
use bridge::BRIDGE;
use std::process;
use window::ui_loop;
use window::window_geometry;
pub const INITIAL_DIMENSIONS: (u64, u64) = (100, 50);
fn main() {
if let Err(err) = window_geometry() {
eprintln!("{}", err);
process::exit(1);
};
window::initialize_settings();
redraw_scheduler::initialize_settings();
renderer::cursor_renderer::initialize_settings();

@ -138,6 +138,8 @@ impl Settings {
if arg == "--log" {
log_to_file = true;
false
} else if arg.starts_with("--geometry=") {
false
} else {
true
}

@ -56,6 +56,48 @@ struct WindowWrapper {
fullscreen: bool,
}
pub fn window_geometry() -> Result<(u64, u64), String> {
let prefix = "--geometry=";
std::env::args()
.filter(|arg| arg.starts_with(prefix))
.next()
.map_or(Ok(INITIAL_DIMENSIONS), |arg| {
let input = &arg[prefix.len()..];
let invalid_parse_err = format!(
"Invalid geometry: {}\nValid format: <width>x<height>",
input
);
input
.split('x')
.map(|dimension| {
dimension
.parse::<u64>()
.or(Err(invalid_parse_err.as_str()))
.and_then(|dimension| {
if dimension > 0 {
Ok(dimension)
} else {
Err("Invalid geometry: Window dimensions should be greater than 0.")
}
})
})
.collect::<Result<Vec<_>, &str>>()
.and_then(|dimensions| {
if let [width, height] = dimensions[..] {
Ok((width, height))
} else {
Err(invalid_parse_err.as_str())
}
})
.map_err(|msg| msg.to_owned())
})
}
pub fn window_geometry_or_default() -> (u64, u64) {
window_geometry().unwrap_or(INITIAL_DIMENSIONS)
}
impl WindowWrapper {
pub fn new() -> WindowWrapper {
let context = sdl2::init().expect("Failed to initialize sdl2");
@ -64,7 +106,7 @@ impl WindowWrapper {
.expect("Failed to create sdl video subsystem");
video_subsystem.text_input().start();
let (width, height) = INITIAL_DIMENSIONS;
let (width, height) = window_geometry_or_default();
let renderer = Renderer::new();
let logical_size = LogicalSize {

Loading…
Cancel
Save