Merge pull request #201 from aelkazdadi/window_dims

Allow user provided geometry
macos-click-through
Keith Simmons 5 years ago committed by GitHub
commit a1a8ce3afe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,7 @@ use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use crate::error_handling::ResultPanicExplanation; use crate::error_handling::ResultPanicExplanation;
use crate::settings::*; use crate::settings::*;
use crate::INITIAL_DIMENSIONS; use crate::window::window_geometry_or_default;
pub use events::*; pub use events::*;
use handler::NeovimHandler; use handler::NeovimHandler;
pub use layouts::*; 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>) { 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, _) = let (mut nvim, io_handler, _) =
create::new_child_cmd(&mut create_nvim_command(), NeovimHandler()) create::new_child_cmd(&mut create_nvim_command(), NeovimHandler())
.await .await

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

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

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

@ -56,6 +56,48 @@ struct WindowWrapper {
fullscreen: bool, 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 { impl WindowWrapper {
pub fn new() -> WindowWrapper { pub fn new() -> WindowWrapper {
let context = sdl2::init().expect("Failed to initialize sdl2"); let context = sdl2::init().expect("Failed to initialize sdl2");
@ -64,7 +106,7 @@ impl WindowWrapper {
.expect("Failed to create sdl video subsystem"); .expect("Failed to create sdl video subsystem");
video_subsystem.text_input().start(); video_subsystem.text_input().start();
let (width, height) = INITIAL_DIMENSIONS; let (width, height) = window_geometry_or_default();
let renderer = Renderer::new(); let renderer = Renderer::new();
let logical_size = LogicalSize { let logical_size = LogicalSize {

Loading…
Cancel
Save