Start-local-collaboration script: put peers' windows at different positions

Max Brunsfeld created

Change summary

crates/zed/src/zed.rs            | 27 +++++++++++++++++++++++++--
script/start-local-collaboration | 10 ++++++++--
2 files changed, 33 insertions(+), 4 deletions(-)

Detailed changes

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<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 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<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::*;

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