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

This commit is contained in:
Max Brunsfeld 2022-11-30 09:29:49 -08:00
parent 6120d6488b
commit a48cd9125b
2 changed files with 33 additions and 4 deletions

View File

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

View File

@ -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