From a48cd9125b50fe90b56980be56746d3b1e6cd114 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 30 Nov 2022 09:29:49 -0800 Subject: [PATCH] Start-local-collaboration script: put peers' windows at different positions --- crates/zed/src/zed.rs | 27 +++++++++++++++++++++++++-- script/start-local-collaboration | 10 ++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index bb33109d0d..cbbbe1cfea 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -17,7 +17,10 @@ use lazy_static::lazy_static; use gpui::{ actions, - geometry::vector::vec2f, + geometry::{ + rect::RectF, + vector::{vec2f, Vector2F}, + }, impl_actions, platform::{WindowBounds, WindowOptions}, AssetSource, AsyncAppContext, TitlebarOptions, ViewContext, WindowKind, @@ -71,6 +74,14 @@ actions!( const MIN_FONT_SIZE: f32 = 6.0; lazy_static! { + static ref ZED_WINDOW_SIZE: Option = env::var("ZED_WINDOW_SIZE") + .ok() + .as_deref() + .and_then(parse_pixel_position_env_var); + static ref ZED_WINDOW_POSITION: Option = env::var("ZED_WINDOW_POSITION") + .ok() + .as_deref() + .and_then(parse_pixel_position_env_var); pub static ref RELEASE_CHANNEL_NAME: String = env::var("ZED_RELEASE_CHANNEL").unwrap_or(include_str!("../RELEASE_CHANNEL").to_string()); pub static ref RELEASE_CHANNEL: ReleaseChannel = match RELEASE_CHANNEL_NAME.as_str() { @@ -346,8 +357,13 @@ pub fn initialize_workspace( } pub fn build_window_options() -> WindowOptions<'static> { + let bounds = if let Some((position, size)) = ZED_WINDOW_POSITION.zip(*ZED_WINDOW_SIZE) { + WindowBounds::Fixed(RectF::new(position, size)) + } else { + WindowBounds::Maximized + }; WindowOptions { - bounds: WindowBounds::Maximized, + bounds, titlebar: Some(TitlebarOptions { title: None, appears_transparent: true, @@ -612,6 +628,13 @@ fn schema_file_match(path: &Path) -> &Path { .unwrap() } +fn parse_pixel_position_env_var(value: &str) -> Option { + 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::*; diff --git a/script/start-local-collaboration b/script/start-local-collaboration index 1d3d74600b..643205532c 100755 --- a/script/start-local-collaboration +++ b/script/start-local-collaboration @@ -26,8 +26,14 @@ fi export ZED_ADMIN_API_TOKEN=secret export ZED_SERVER_URL=http://localhost:8080 +export ZED_WINDOW_SIZE=800,600 + +cargo build +sleep 0.1 trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT -ZED_IMPERSONATE=${github_login} cargo run --quiet $@ & -ZED_IMPERSONATE=${other_github_login} cargo run --quiet & +ZED_WINDOW_POSITION=0,0 ZED_IMPERSONATE=${github_login} target/debug/Zed $@ & +sleep 0.1 +ZED_WINDOW_POSITION=800,0 ZED_IMPERSONATE=${other_github_login} target/debug/Zed & +sleep 0.1 wait