Fix handling of ZED_WINDOW_{SIZE,POSITION} env vars

Co-authored-by: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-02-20 14:57:12 -08:00
parent 48b76f96fc
commit 927f7b3363
3 changed files with 67 additions and 55 deletions

View file

@ -17,16 +17,12 @@ use feedback::{
use futures::StreamExt;
use gpui::{
actions,
geometry::{
rect::RectF,
vector::{vec2f, Vector2F},
},
geometry::vector::vec2f,
impl_actions,
platform::{WindowBounds, WindowOptions},
AssetSource, AsyncAppContext, Platform, PromptLevel, TitlebarOptions, ViewContext, WindowKind,
};
use language::Rope;
use lazy_static::lazy_static;
pub use lsp;
pub use project;
use project_panel::ProjectPanel;
@ -76,17 +72,6 @@ actions!(
const MIN_FONT_SIZE: f32 = 6.0;
lazy_static! {
static ref ZED_WINDOW_SIZE: Option<Vector2F> = env::var("ZED_WINDOW_SIZE")
.ok()
.as_deref()
.and_then(parse_pixel_position_env_var);
static ref ZED_WINDOW_POSITION: Option<Vector2F> = env::var("ZED_WINDOW_POSITION")
.ok()
.as_deref()
.and_then(parse_pixel_position_env_var);
}
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
cx.add_action(about);
cx.add_global_action(|_: &Hide, cx: &mut gpui::MutableAppContext| {
@ -378,14 +363,7 @@ pub fn build_window_options(
display: Option<Uuid>,
platform: &dyn Platform,
) -> WindowOptions<'static> {
let bounds = bounds
.or_else(|| {
ZED_WINDOW_POSITION
.zip(*ZED_WINDOW_SIZE)
.map(|(position, size)| WindowBounds::Fixed(RectF::new(position, size)))
})
.unwrap_or(WindowBounds::Maximized);
let bounds = bounds.unwrap_or(WindowBounds::Maximized);
let screen = display.and_then(|display| platform.screen_by_id(display));
WindowOptions {
@ -683,13 +661,6 @@ fn schema_file_match(path: &Path) -> &Path {
.unwrap()
}
fn parse_pixel_position_env_var(value: &str) -> Option<Vector2F> {
let mut parts = value.split(',');
let width: usize = parts.next()?.parse().ok()?;
let height: usize = parts.next()?.parse().ok()?;
Some(vec2f(width as f32, height as f32))
}
#[cfg(test)]
mod tests {
use super::*;