BlueGit

ict rusty-teams

feat(call): stacked gallery while sharing, main window out of capture

- Screen share minimizes the main window like Teams (5 % overlap with the shared monitor) and restores it when sharing stops
- Minimized while sharing: narrow stacked gallery (192 wide, up to 4 tiles, divider with +N, own tile, mic/camera/leave) instead of the single mini tile
- "Show only active speaker" / "Show more people" switch between gallery and mini tile
- Main window excluded from capture during a screen share, included again after
- Window share keeps the main window as it is (Daniel-approved deviation, GUARDRAILS.md "Call windows")
- Pure decision logic in share_overlay (share kind x minimized -> overlay, exclusion set, gallery layout) with tests
- Demo scenes gallery-share and window-share

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
93c4ac493096acaee2c37524d445ac27535e4192
Parent
b23730cf
12 files changed +883 −60
GUARDRAILS.md +1 −0
@@ -24,6 +24,7 @@ Rules for every change, by people and by agents. If a rule here and a habit else
24 24 | Local bugs | Fix Teams bugs that are purely local (rendering, scroll, focus). Anything touching server data or other people stays as Teams does it. |
25 25 | Performance | Faster, less memory, offline reading from the cache. |
26 26 | Platform | OS-native toasts, tray, title bar and sounds. |
27 | Call windows | Daniel-approved (2026-10-17): a call stays in the main window with the sidebar, Teams opens its own meeting window. A window share leaves the main window as it is (side by side), Teams minimizes it. Only our own window behaviour, nothing others see changes. |
27 28 | Own features | MCP, agents, session inbox: allowed when nobody else can tell. Nothing sent automatically, no own message formats. |
28 29 | Own settings | Settings Teams does not know stay in the local DB, never in Teams account properties. |
29 30
@@ -24,6 +24,7 @@ Rules for every change, by people and by agents. If a rule here and a habit else
24| Local bugs | Fix Teams bugs that are purely local (rendering, scroll, focus). Anything touching server data or other people stays as Teams does it. |
24| Local bugs | Fix Teams bugs that are purely local (rendering, scroll, focus). Anything touching server data or other people stays as Teams does it. |
25| Performance | Faster, less memory, offline reading from the cache. |
25| Performance | Faster, less memory, offline reading from the cache. |
26| Platform | OS-native toasts, tray, title bar and sounds. |
26| Platform | OS-native toasts, tray, title bar and sounds. |
27| Call windows | Daniel-approved (2026-10-17): a call stays in the main window with the sidebar, Teams opens its own meeting window. A window share leaves the main window as it is (side by side), Teams minimizes it. Only our own window behaviour, nothing others see changes. |
27| Own features | MCP, agents, session inbox: allowed when nobody else can tell. Nothing sent automatically, no own message formats. |
28| Own features | MCP, agents, session inbox: allowed when nobody else can tell. Nothing sent automatically, no own message formats. |
28| Own settings | Settings Teams does not know stay in the local DB, never in Teams account properties. |
29| Own settings | Settings Teams does not know stay in the local DB, never in Teams account properties. |
29
30
crates/app-base/src/notify/platform/stub.rs +2 −0
@@ -34,6 +34,8 @@ pub fn show_window_inactive(_handle: NativeHandle) {}
34 34
35 35 pub fn exclude_from_capture(_handle: NativeHandle) {}
36 36
37 pub fn include_in_capture(_handle: NativeHandle) {}
38
37 39 #[cfg(target_os = "linux")]
38 40 pub fn make_window_click_through(window: &Window) {
39 41 super::x11_input::make_input_transparent(window);
@@ -34,6 +34,8 @@ pub fn show_window_inactive(_handle: NativeHandle) {}
34
34
35pub fn exclude_from_capture(_handle: NativeHandle) {}
35pub fn exclude_from_capture(_handle: NativeHandle) {}
36
36
37pub fn include_in_capture(_handle: NativeHandle) {}
38
37#[cfg(target_os = "linux")]
39#[cfg(target_os = "linux")]
38pub fn make_window_click_through(window: &Window) {
40pub fn make_window_click_through(window: &Window) {
39 super::x11_input::make_input_transparent(window);
41 super::x11_input::make_input_transparent(window);
crates/app-base/src/notify/platform/windows_impl.rs +7 −1
@@ -34,7 +34,7 @@ use windows::Win32::UI::WindowsAndMessaging::{
34 34 SW_SHOWNOACTIVATE, SWP_FRAMECHANGED, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
35 35 SWP_NOZORDER, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SendMessageW, SetForegroundWindow,
36 36 SetLayeredWindowAttributes, SetWindowDisplayAffinity, SetWindowLongPtrW, SetWindowPos,
37 ShowWindow, SystemParametersInfoW, WDA_EXCLUDEFROMCAPTURE, WM_SETICON, WS_CAPTION,
37 ShowWindow, SystemParametersInfoW, WDA_EXCLUDEFROMCAPTURE, WDA_NONE, WM_SETICON, WS_CAPTION,
38 38 WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOPMOST, WS_EX_TRANSPARENT, WS_POPUP, WS_THICKFRAME,
39 39 };
40 40 use windows::core::{BOOL, PCWSTR, w};
@@ -272,6 +272,12 @@ pub fn exclude_from_capture(handle: NativeHandle) {
272 272 }
273 273 }
274 274
275 pub fn include_in_capture(handle: NativeHandle) {
276 unsafe {
277 let _ = SetWindowDisplayAffinity(hwnd(handle), WDA_NONE);
278 }
279 }
280
275 281 pub fn make_window_click_through(window: &Window) {
276 282 if let Some(handle) = native_handle(window) {
277 283 make_click_through(handle);
@@ -34,7 +34,7 @@ use windows::Win32::UI::WindowsAndMessaging::{
34 SW_SHOWNOACTIVATE, SWP_FRAMECHANGED, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
34 SW_SHOWNOACTIVATE, SWP_FRAMECHANGED, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
35 SWP_NOZORDER, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SendMessageW, SetForegroundWindow,
35 SWP_NOZORDER, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SendMessageW, SetForegroundWindow,
36 SetLayeredWindowAttributes, SetWindowDisplayAffinity, SetWindowLongPtrW, SetWindowPos,
36 SetLayeredWindowAttributes, SetWindowDisplayAffinity, SetWindowLongPtrW, SetWindowPos,
37 ShowWindow, SystemParametersInfoW, WDA_EXCLUDEFROMCAPTURE, WM_SETICON, WS_CAPTION,
37 ShowWindow, SystemParametersInfoW, WDA_EXCLUDEFROMCAPTURE, WDA_NONE, WM_SETICON, WS_CAPTION,
38 WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOPMOST, WS_EX_TRANSPARENT, WS_POPUP, WS_THICKFRAME,
38 WS_EX_LAYERED, WS_EX_NOACTIVATE, WS_EX_TOPMOST, WS_EX_TRANSPARENT, WS_POPUP, WS_THICKFRAME,
39};
39};
40use windows::core::{BOOL, PCWSTR, w};
40use windows::core::{BOOL, PCWSTR, w};
@@ -272,6 +272,12 @@ pub fn exclude_from_capture(handle: NativeHandle) {
272 }
272 }
273}
273}
274
274
275pub fn include_in_capture(handle: NativeHandle) {
276 unsafe {
277 let _ = SetWindowDisplayAffinity(hwnd(handle), WDA_NONE);
278 }
279}
280
275pub fn make_window_click_through(window: &Window) {
281pub fn make_window_click_through(window: &Window) {
276 if let Some(handle) = native_handle(window) {
282 if let Some(handle) = native_handle(window) {
277 make_click_through(handle);
283 make_click_through(handle);
crates/app-call-model/src/demo.rs +13 −3
@@ -104,6 +104,8 @@ pub enum DemoScene {
104 104 Mini,
105 105 MiniOff,
106 106 MiniShare,
107 GalleryShare,
108 WindowShare,
107 109 Blocked,
108 110 Removed,
109 111 Dropped,
@@ -126,6 +128,8 @@ impl DemoScene {
126 128 "mini" => DemoScene::Mini,
127 129 "mini-off" => DemoScene::MiniOff,
128 130 "mini-share" => DemoScene::MiniShare,
131 "gallery-share" => DemoScene::GalleryShare,
132 "window-share" => DemoScene::WindowShare,
129 133 "blocked" => DemoScene::Blocked,
130 134 "removed" => DemoScene::Removed,
131 135 "dropped" => DemoScene::Dropped,
@@ -163,7 +167,9 @@ impl DemoScene {
163 167 pub fn guests(self) -> Option<usize> {
164 168 match self {
165 169 DemoScene::Gallery => Some(DEMO_GALLERY_GUESTS),
166 DemoScene::Sharing => Some(DEMO_SHARING_GUESTS),
170 DemoScene::Sharing | DemoScene::GalleryShare | DemoScene::WindowShare => {
171 Some(DEMO_SHARING_GUESTS)
172 }
167 173 _ => None,
168 174 }
169 175 }
@@ -186,6 +192,7 @@ impl DemoScene {
186 192
187 193 pub const DEMO_GALLERY_GUESTS: usize = 12;
188 194 const DEMO_SHARING_GUESTS: usize = 9;
195 const DEMO_SHARED_WINDOW: &str = "Standup board";
189 196 const BREAKOUT_AT_TICKS: u32 = 20;
190 197 const WHITEBOARD_AT_TICKS: u32 = 5;
191 198 const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
@@ -269,7 +276,7 @@ fn demo_share_sources() -> Vec<ShareSource> {
269 276 title: String::new(),
270 277 },
271 278 window(2, "Release notes - Docs"),
272 window(3, "Standup board"),
279 window(3, DEMO_SHARED_WINDOW),
273 280 window(4, "Terminal"),
274 281 ]
275 282 }
@@ -451,9 +458,12 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
451 458 DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),
452 459 DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),
453 460 DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),
454 DemoScene::MiniShare => {
461 DemoScene::MiniShare | DemoScene::GalleryShare => {
455 462 control.send(CallUpdate::LocalShare(Some("Entire screen".to_owned())))
456 463 }
464 DemoScene::WindowShare => {
465 control.send(CallUpdate::LocalShare(Some(DEMO_SHARED_WINDOW.to_owned())))
466 }
457 467 DemoScene::Call
458 468 | DemoScene::Mini
459 469 | DemoScene::MiniOff
@@ -104,6 +104,8 @@ pub enum DemoScene {
104 Mini,
104 Mini,
105 MiniOff,
105 MiniOff,
106 MiniShare,
106 MiniShare,
107 GalleryShare,
108 WindowShare,
107 Blocked,
109 Blocked,
108 Removed,
110 Removed,
109 Dropped,
111 Dropped,
@@ -126,6 +128,8 @@ impl DemoScene {
126 "mini" => DemoScene::Mini,
128 "mini" => DemoScene::Mini,
127 "mini-off" => DemoScene::MiniOff,
129 "mini-off" => DemoScene::MiniOff,
128 "mini-share" => DemoScene::MiniShare,
130 "mini-share" => DemoScene::MiniShare,
131 "gallery-share" => DemoScene::GalleryShare,
132 "window-share" => DemoScene::WindowShare,
129 "blocked" => DemoScene::Blocked,
133 "blocked" => DemoScene::Blocked,
130 "removed" => DemoScene::Removed,
134 "removed" => DemoScene::Removed,
131 "dropped" => DemoScene::Dropped,
135 "dropped" => DemoScene::Dropped,
@@ -163,7 +167,9 @@ impl DemoScene {
163 pub fn guests(self) -> Option<usize> {
167 pub fn guests(self) -> Option<usize> {
164 match self {
168 match self {
165 DemoScene::Gallery => Some(DEMO_GALLERY_GUESTS),
169 DemoScene::Gallery => Some(DEMO_GALLERY_GUESTS),
166 DemoScene::Sharing => Some(DEMO_SHARING_GUESTS),
170 DemoScene::Sharing | DemoScene::GalleryShare | DemoScene::WindowShare => {
171 Some(DEMO_SHARING_GUESTS)
172 }
167 _ => None,
173 _ => None,
168 }
174 }
169 }
175 }
@@ -186,6 +192,7 @@ impl DemoScene {
186
192
187pub const DEMO_GALLERY_GUESTS: usize = 12;
193pub const DEMO_GALLERY_GUESTS: usize = 12;
188const DEMO_SHARING_GUESTS: usize = 9;
194const DEMO_SHARING_GUESTS: usize = 9;
195const DEMO_SHARED_WINDOW: &str = "Standup board";
189const BREAKOUT_AT_TICKS: u32 = 20;
196const BREAKOUT_AT_TICKS: u32 = 20;
190const WHITEBOARD_AT_TICKS: u32 = 5;
197const WHITEBOARD_AT_TICKS: u32 = 5;
191const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
198const DEMO_BOARD_URL: &str = "https://app.whiteboard.microsoft.com/me/whiteboards/demo";
@@ -269,7 +276,7 @@ fn demo_share_sources() -> Vec<ShareSource> {
269 title: String::new(),
276 title: String::new(),
270 },
277 },
271 window(2, "Release notes - Docs"),
278 window(2, "Release notes - Docs"),
272 window(3, "Standup board"),
279 window(3, DEMO_SHARED_WINDOW),
273 window(4, "Terminal"),
280 window(4, "Terminal"),
274 ]
281 ]
275}
282}
@@ -451,9 +458,12 @@ fn start_scene(control: &CallControl, scene: DemoScene) {
451 DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),
458 DemoScene::Hold => control.send(CallUpdate::Hold(HoldState::Local)),
452 DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),
459 DemoScene::Held => control.send(CallUpdate::Hold(HoldState::Remote)),
453 DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),
460 DemoScene::Network => control.send(CallUpdate::Health(poor_network_health())),
454 DemoScene::MiniShare => {
461 DemoScene::MiniShare | DemoScene::GalleryShare => {
455 control.send(CallUpdate::LocalShare(Some("Entire screen".to_owned())))
462 control.send(CallUpdate::LocalShare(Some("Entire screen".to_owned())))
456 }
463 }
464 DemoScene::WindowShare => {
465 control.send(CallUpdate::LocalShare(Some(DEMO_SHARED_WINDOW.to_owned())))
466 }
457 DemoScene::Call
467 DemoScene::Call
458 | DemoScene::Mini
468 | DemoScene::Mini
459 | DemoScene::MiniOff
469 | DemoScene::MiniOff
crates/app-state/src/call/mod.rs +1 −0
@@ -14,6 +14,7 @@ pub mod prejoin;
14 14 pub mod record_load;
15 15 pub mod reminder;
16 16 pub mod share_actions;
17 pub mod share_overlay;
17 18 pub mod schedule;
18 19 pub mod target;
19 20 pub mod view_actions;
@@ -14,6 +14,7 @@ pub mod prejoin;
14pub mod record_load;
14pub mod record_load;
15pub mod reminder;
15pub mod reminder;
16pub mod share_actions;
16pub mod share_actions;
17pub mod share_overlay;
17pub mod schedule;
18pub mod schedule;
18pub mod target;
19pub mod target;
19pub mod view_actions;
20pub mod view_actions;
crates/app-state/src/call/overlay_layout.rs +0 −11
@@ -117,10 +117,6 @@ pub fn mini_work_area(
117 117 .unwrap_or(main)
118 118 }
119 119
120 pub fn mini_wanted(call_active: bool, main_minimized: bool) -> bool {
121 call_active && main_minimized
122 }
123
124 120 pub fn parse_position(text: &str) -> Option<(i32, i32)> {
125 121 let (left, top) = text.split_once(',')?;
126 122 Some((left.trim().parse().ok()?, top.trim().parse().ok()?))
@@ -276,13 +272,6 @@ mod tests {
276 272 assert_eq!((rect.width(), rect.height()), (640, 360));
277 273 }
278 274
279 #[test]
280 fn mini_shows_only_in_a_call_with_the_main_window_minimized() {
281 assert!(mini_wanted(true, true));
282 assert!(!mini_wanted(true, false));
283 assert!(!mini_wanted(false, true));
284 }
285
286 275 #[test]
287 276 fn position_round_trips() {
288 277 assert_eq!(
@@ -117,10 +117,6 @@ pub fn mini_work_area(
117 .unwrap_or(main)
117 .unwrap_or(main)
118}
118}
119
119
120pub fn mini_wanted(call_active: bool, main_minimized: bool) -> bool {
121 call_active && main_minimized
122}
123
124pub fn parse_position(text: &str) -> Option<(i32, i32)> {
120pub fn parse_position(text: &str) -> Option<(i32, i32)> {
125 let (left, top) = text.split_once(',')?;
121 let (left, top) = text.split_once(',')?;
126 Some((left.trim().parse().ok()?, top.trim().parse().ok()?))
122 Some((left.trim().parse().ok()?, top.trim().parse().ok()?))
@@ -276,13 +272,6 @@ mod tests {
276 assert_eq!((rect.width(), rect.height()), (640, 360));
272 assert_eq!((rect.width(), rect.height()), (640, 360));
277 }
273 }
278
274
279 #[test]
280 fn mini_shows_only_in_a_call_with_the_main_window_minimized() {
281 assert!(mini_wanted(true, true));
282 assert!(!mini_wanted(true, false));
283 assert!(!mini_wanted(false, true));
284 }
285
286 #[test]
275 #[test]
287 fn position_round_trips() {
276 fn position_round_trips() {
288 assert_eq!(
277 assert_eq!(
crates/app-state/src/call/share_overlay.rs added +434 −0
@@ -0,0 +1,434 @@
1 use calling::ShareKind;
2
3 use super::model::{CallModel, Tile, TileState};
4 use crate::notify::platform::{ScreenRect, WorkArea};
5
6 pub const GALLERY_WIDTH: f32 = 192.;
7 pub const GALLERY_INSET: f32 = 3.;
8 pub const GALLERY_TILE_WIDTH: f32 = GALLERY_WIDTH - 2. * GALLERY_INSET;
9 pub const GALLERY_TILE_HEIGHT: f32 = GALLERY_TILE_WIDTH * 9. / 16.;
10 pub const GALLERY_TITLE_HEIGHT: f32 = 32.;
11 pub const GALLERY_CONTROLS_HEIGHT: f32 = 40.;
12 pub const GALLERY_DIVIDER_HEIGHT: f32 = 20.;
13 pub const GALLERY_MAX_TILES: usize = 4;
14 pub const GALLERY_MARGIN: f32 = 30.;
15 pub const GALLERY_POSITION_KEY: &str = "call_gallery_position";
16 pub const MINIMIZE_OVERLAP_PERCENT: i64 = 5;
17
18 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
19 pub enum LocalShare {
20 None,
21 Screen,
22 Window,
23 }
24
25 impl LocalShare {
26 pub fn of(kind: Option<ShareKind>, sharing: bool) -> LocalShare {
27 match (sharing, kind) {
28 (false, _) => LocalShare::None,
29 (true, Some(ShareKind::Window)) => LocalShare::Window,
30 (true, _) => LocalShare::Screen,
31 }
32 }
33 }
34
35 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
36 pub enum Monitor {
37 None,
38 Mini,
39 Gallery,
40 }
41
42 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
43 pub enum Surface {
44 Main,
45 ShareBar,
46 Border,
47 Mini,
48 Gallery,
49 }
50
51 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
52 pub struct OverlayPlan {
53 pub monitor: Monitor,
54 pub share_bar: bool,
55 pub exclude_main: bool,
56 }
57
58 pub fn overlay_plan(
59 in_call: bool,
60 share: LocalShare,
61 main_minimized: bool,
62 speaker_only: bool,
63 ) -> OverlayPlan {
64 let monitor = match (in_call && main_minimized, share) {
65 (false, _) => Monitor::None,
66 (true, LocalShare::None) => Monitor::Mini,
67 (true, _) if speaker_only => Monitor::Mini,
68 (true, _) => Monitor::Gallery,
69 };
70 OverlayPlan {
71 monitor,
72 share_bar: in_call && share != LocalShare::None,
73 exclude_main: excluded_from_capture(Surface::Main, share),
74 }
75 }
76
77 pub fn excluded_from_capture(surface: Surface, share: LocalShare) -> bool {
78 match surface {
79 Surface::Main => share == LocalShare::Screen,
80 Surface::ShareBar | Surface::Border | Surface::Mini | Surface::Gallery => true,
81 }
82 }
83
84 fn overlap_area(first: ScreenRect, second: ScreenRect) -> i64 {
85 let width = (first.right.min(second.right) - first.left.max(second.left)).max(0);
86 let height = (first.bottom.min(second.bottom) - first.top.max(second.top)).max(0);
87 i64::from(width) * i64::from(height)
88 }
89
90 pub fn minimize_on_share_start(
91 share: LocalShare,
92 main: Option<ScreenRect>,
93 shared: Option<ScreenRect>,
94 ) -> bool {
95 if share != LocalShare::Screen {
96 return false;
97 }
98 let (Some(main), Some(shared)) = (main, shared) else {
99 return true;
100 };
101 let main_area = i64::from(main.width().max(0)) * i64::from(main.height().max(0));
102 if main_area == 0 {
103 return true;
104 }
105 overlap_area(main, shared) * 100 >= MINIMIZE_OVERLAP_PERCENT * main_area
106 }
107
108 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
109 pub struct GalleryLayout {
110 pub tiles: usize,
111 pub overflow: usize,
112 pub divider: bool,
113 pub self_tile: bool,
114 }
115
116 impl GalleryLayout {
117 pub fn height(&self) -> f32 {
118 let segments = self.tiles + usize::from(self.self_tile);
119 let gaps = (segments + usize::from(self.divider)).saturating_sub(1);
120 GALLERY_TITLE_HEIGHT
121 + GALLERY_INSET
122 + segments as f32 * GALLERY_TILE_HEIGHT
123 + if self.divider {
124 GALLERY_DIVIDER_HEIGHT
125 } else {
126 0.
127 }
128 + gaps as f32 * GALLERY_INSET
129 + GALLERY_INSET
130 + GALLERY_CONTROLS_HEIGHT
131 }
132 }
133
134 pub fn gallery_layout(others: usize, self_tile: bool, available_height: f32) -> GalleryLayout {
135 let build = |tiles: usize| GalleryLayout {
136 tiles,
137 overflow: others - tiles,
138 divider: others > 0 && self_tile,
139 self_tile,
140 };
141 let mut layout = build(others.min(GALLERY_MAX_TILES));
142 while layout.tiles > 1 && layout.height() > available_height {
143 layout = build(layout.tiles - 1);
144 }
145 layout
146 }
147
148 pub fn gallery_available_height(work: WorkArea) -> f32 {
149 (work.bottom - work.top) as f32 / work.scale - 2. * GALLERY_MARGIN
150 }
151
152 pub fn gallery_rect(
153 work: WorkArea,
154 layout: GalleryLayout,
155 origin: Option<(i32, i32)>,
156 ) -> ScreenRect {
157 let scaled = |logical: f32| (logical * work.scale).round() as i32;
158 let width = scaled(GALLERY_WIDTH);
159 let height = scaled(layout.height());
160 let margin = scaled(GALLERY_MARGIN);
161 let (left, top) =
162 origin.unwrap_or((work.right - width - margin, work.bottom - height - margin));
163 let left = left.clamp(work.left, (work.right - width).max(work.left));
164 let top = top.clamp(work.top, (work.bottom - height).max(work.top));
165 ScreenRect {
166 left,
167 top,
168 right: left + width,
169 bottom: top + height,
170 }
171 }
172
173 fn prioritized(model: &CallModel, tile: &Tile) -> bool {
174 model.is_pinned(&tile.mri) || tile.spotlight.is_some() || tile.hand.is_some()
175 }
176
177 pub fn gallery_candidates(model: &CallModel) -> Vec<&Tile> {
178 let mut tiles: Vec<&Tile> = model
179 .layout_tiles()
180 .into_iter()
181 .filter(|tile| tile.state == TileState::Present)
182 .collect();
183 tiles.sort_by_key(|tile| {
184 (
185 !prioritized(model, tile),
186 !(model.tile_speaking(tile) || model.is_recent_speaker(&tile.mri)),
187 )
188 });
189 tiles
190 }
191
192 #[cfg(test)]
193 mod tests {
194 use super::*;
195
196 fn work(scale: f32) -> WorkArea {
197 WorkArea {
198 left: 0,
199 top: 0,
200 right: 1920,
201 bottom: 1040,
202 scale,
203 }
204 }
205
206 fn rect(left: i32, top: i32, right: i32, bottom: i32) -> ScreenRect {
207 ScreenRect {
208 left,
209 top,
210 right,
211 bottom,
212 }
213 }
214
215 #[test]
216 fn decision_table() {
217 use LocalShare::*;
218 use Monitor as M;
219 let rows = [
220 (None, false, M::None, false, false),
221 (None, true, M::Mini, false, false),
222 (Screen, false, M::None, true, true),
223 (Screen, true, M::Gallery, true, true),
224 (Window, false, M::None, true, false),
225 (Window, true, M::Gallery, true, false),
226 ];
227 for (share, minimized, monitor, share_bar, exclude_main) in rows {
228 assert_eq!(
229 overlay_plan(true, share, minimized, false),
230 OverlayPlan {
231 monitor,
232 share_bar,
233 exclude_main
234 },
235 "{share:?} minimized={minimized}"
236 );
237 }
238 }
239
240 #[test]
241 fn speaker_only_swaps_the_gallery_for_the_mini_tile() {
242 let plan = overlay_plan(true, LocalShare::Screen, true, true);
243 assert_eq!(plan.monitor, Monitor::Mini);
244 assert!(plan.exclude_main);
245 assert_eq!(
246 overlay_plan(true, LocalShare::None, true, true).monitor,
247 Monitor::Mini
248 );
249 }
250
251 #[test]
252 fn nothing_shows_outside_a_call() {
253 let plan = overlay_plan(false, LocalShare::None, true, false);
254 assert_eq!(plan.monitor, Monitor::None);
255 assert!(!plan.share_bar);
256 }
257
258 #[test]
259 fn overlays_are_always_excluded_and_main_only_for_a_screen() {
260 for share in [LocalShare::None, LocalShare::Screen, LocalShare::Window] {
261 for surface in [
262 Surface::ShareBar,
263 Surface::Border,
264 Surface::Mini,
265 Surface::Gallery,
266 ] {
267 assert!(excluded_from_capture(surface, share));
268 }
269 }
270 assert!(excluded_from_capture(Surface::Main, LocalShare::Screen));
271 assert!(!excluded_from_capture(Surface::Main, LocalShare::Window));
272 assert!(!excluded_from_capture(Surface::Main, LocalShare::None));
273 }
274
275 #[test]
276 fn unknown_source_kind_counts_as_a_screen() {
277 assert_eq!(LocalShare::of(None, true), LocalShare::Screen);
278 assert_eq!(
279 LocalShare::of(Some(ShareKind::Window), true),
280 LocalShare::Window
281 );
282 assert_eq!(
283 LocalShare::of(Some(ShareKind::Screen), false),
284 LocalShare::None
285 );
286 }
287
288 #[test]
289 fn screen_share_minimizes_only_when_the_main_window_is_on_the_shared_monitor() {
290 let monitor = rect(0, 0, 1920, 1080);
291 let on_monitor = Some(rect(100, 100, 1100, 800));
292 let other_monitor = Some(rect(2000, 100, 3000, 800));
293 let edge = Some(rect(1880, 0, 2880, 1000));
294 assert!(minimize_on_share_start(
295 LocalShare::Screen,
296 on_monitor,
297 Some(monitor)
298 ));
299 assert!(!minimize_on_share_start(
300 LocalShare::Screen,
301 other_monitor,
302 Some(monitor)
303 ));
304 assert!(!minimize_on_share_start(
305 LocalShare::Screen,
306 edge,
307 Some(monitor)
308 ));
309 assert!(minimize_on_share_start(
310 LocalShare::Screen,
311 None,
312 Some(monitor)
313 ));
314 assert!(minimize_on_share_start(
315 LocalShare::Screen,
316 on_monitor,
317 None
318 ));
319 }
320
321 #[test]
322 fn window_share_and_no_share_never_minimize() {
323 let monitor = Some(rect(0, 0, 1920, 1080));
324 assert!(!minimize_on_share_start(
325 LocalShare::Window,
326 monitor,
327 monitor
328 ));
329 assert!(!minimize_on_share_start(LocalShare::None, monitor, monitor));
330 }
331
332 #[test]
333 fn gallery_stacks_four_tiles_a_divider_and_the_own_tile() {
334 let layout = gallery_layout(9, true, 2000.);
335 assert_eq!(
336 layout,
337 GalleryLayout {
338 tiles: 4,
339 overflow: 5,
340 divider: true,
341 self_tile: true
342 }
343 );
344 let expected = GALLERY_TITLE_HEIGHT
345 + 5. * GALLERY_TILE_HEIGHT
346 + GALLERY_DIVIDER_HEIGHT
347 + 7. * GALLERY_INSET
348 + GALLERY_CONTROLS_HEIGHT;
349 assert!((layout.height() - expected).abs() < 0.01);
350 }
351
352 #[test]
353 fn gallery_chrome_matches_teams() {
354 let chrome = GalleryLayout {
355 tiles: 0,
356 overflow: 0,
357 divider: false,
358 self_tile: false,
359 }
360 .height();
361 assert_eq!(chrome, 78.);
362 assert_eq!(GALLERY_TILE_WIDTH, 186.);
363 }
364
365 #[test]
366 fn gallery_drops_tiles_to_fit_a_short_screen() {
367 let layout = gallery_layout(9, true, 500.);
368 assert!(layout.height() <= 500.);
369 assert_eq!(layout.tiles, 2);
370 assert_eq!(layout.overflow, 7);
371 assert_eq!(gallery_layout(9, true, 10.).tiles, 1);
372 }
373
374 #[test]
375 fn gallery_without_others_has_no_divider() {
376 let layout = gallery_layout(0, true, 2000.);
377 assert_eq!(
378 (layout.tiles, layout.divider, layout.self_tile),
379 (0, false, true)
380 );
381 let hidden_self = gallery_layout(3, false, 2000.);
382 assert_eq!((hidden_self.tiles, hidden_self.divider), (3, false));
383 }
384
385 #[test]
386 fn gallery_defaults_to_the_bottom_right_with_the_teams_margin() {
387 let layout = gallery_layout(2, true, 2000.);
388 let placed = gallery_rect(work(1.), layout, None);
389 assert_eq!(placed.width(), 192);
390 assert_eq!((placed.right, placed.bottom), (1920 - 30, 1040 - 30));
391 assert_eq!(placed.height(), layout.height().round() as i32);
392 }
393
394 #[test]
395 fn gallery_keeps_a_dragged_origin_inside_the_work_area() {
396 let layout = gallery_layout(4, true, 2000.);
397 assert_eq!(gallery_rect(work(1.), layout, Some((200, 100))).left, 200);
398 let pushed = gallery_rect(work(1.), layout, Some((5000, 900)));
399 assert_eq!((pushed.right, pushed.bottom), (1920, 1040));
400 }
401
402 #[test]
403 fn gallery_scales_with_the_monitor() {
404 let layout = gallery_layout(1, false, 2000.);
405 let placed = gallery_rect(work(2.), layout, None);
406 assert_eq!(placed.width(), 384);
407 assert_eq!(gallery_available_height(work(2.)), 520. - 60.);
408 }
409
410 fn present(mri: &str, name: &str) -> Tile {
411 Tile {
412 state: TileState::Present,
413 ..Tile::invited(mri, name)
414 }
415 }
416
417 #[test]
418 fn candidates_put_pinned_then_speakers_first() {
419 let mut model = CallModel::test();
420 model.tiles = vec![
421 present("8:a", "Ada"),
422 present("8:b", "Bo"),
423 present("8:c", "Cy"),
424 Tile::invited("8:d", "Dee"),
425 ];
426 model.speaking_mris = vec!["8:c".to_owned()];
427 model.toggle_pin("8:b");
428 let names: Vec<&str> = gallery_candidates(&model)
429 .iter()
430 .map(|tile| tile.name.as_str())
431 .collect();
432 assert_eq!(names, ["Bo", "Cy", "Ada"]);
433 }
434 }
@@ -0,0 +1,434 @@
1use calling::ShareKind;
2
3use super::model::{CallModel, Tile, TileState};
4use crate::notify::platform::{ScreenRect, WorkArea};
5
6pub const GALLERY_WIDTH: f32 = 192.;
7pub const GALLERY_INSET: f32 = 3.;
8pub const GALLERY_TILE_WIDTH: f32 = GALLERY_WIDTH - 2. * GALLERY_INSET;
9pub const GALLERY_TILE_HEIGHT: f32 = GALLERY_TILE_WIDTH * 9. / 16.;
10pub const GALLERY_TITLE_HEIGHT: f32 = 32.;
11pub const GALLERY_CONTROLS_HEIGHT: f32 = 40.;
12pub const GALLERY_DIVIDER_HEIGHT: f32 = 20.;
13pub const GALLERY_MAX_TILES: usize = 4;
14pub const GALLERY_MARGIN: f32 = 30.;
15pub const GALLERY_POSITION_KEY: &str = "call_gallery_position";
16pub const MINIMIZE_OVERLAP_PERCENT: i64 = 5;
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum LocalShare {
20 None,
21 Screen,
22 Window,
23}
24
25impl LocalShare {
26 pub fn of(kind: Option<ShareKind>, sharing: bool) -> LocalShare {
27 match (sharing, kind) {
28 (false, _) => LocalShare::None,
29 (true, Some(ShareKind::Window)) => LocalShare::Window,
30 (true, _) => LocalShare::Screen,
31 }
32 }
33}
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum Monitor {
37 None,
38 Mini,
39 Gallery,
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum Surface {
44 Main,
45 ShareBar,
46 Border,
47 Mini,
48 Gallery,
49}
50
51#[derive(Debug, Clone, Copy, PartialEq, Eq)]
52pub struct OverlayPlan {
53 pub monitor: Monitor,
54 pub share_bar: bool,
55 pub exclude_main: bool,
56}
57
58pub fn overlay_plan(
59 in_call: bool,
60 share: LocalShare,
61 main_minimized: bool,
62 speaker_only: bool,
63) -> OverlayPlan {
64 let monitor = match (in_call && main_minimized, share) {
65 (false, _) => Monitor::None,
66 (true, LocalShare::None) => Monitor::Mini,
67 (true, _) if speaker_only => Monitor::Mini,
68 (true, _) => Monitor::Gallery,
69 };
70 OverlayPlan {
71 monitor,
72 share_bar: in_call && share != LocalShare::None,
73 exclude_main: excluded_from_capture(Surface::Main, share),
74 }
75}
76
77pub fn excluded_from_capture(surface: Surface, share: LocalShare) -> bool {
78 match surface {
79 Surface::Main => share == LocalShare::Screen,
80 Surface::ShareBar | Surface::Border | Surface::Mini | Surface::Gallery => true,
81 }
82}
83
84fn overlap_area(first: ScreenRect, second: ScreenRect) -> i64 {
85 let width = (first.right.min(second.right) - first.left.max(second.left)).max(0);
86 let height = (first.bottom.min(second.bottom) - first.top.max(second.top)).max(0);
87 i64::from(width) * i64::from(height)
88}
89
90pub fn minimize_on_share_start(
91 share: LocalShare,
92 main: Option<ScreenRect>,
93 shared: Option<ScreenRect>,
94) -> bool {
95 if share != LocalShare::Screen {
96 return false;
97 }
98 let (Some(main), Some(shared)) = (main, shared) else {
99 return true;
100 };
101 let main_area = i64::from(main.width().max(0)) * i64::from(main.height().max(0));
102 if main_area == 0 {
103 return true;
104 }
105 overlap_area(main, shared) * 100 >= MINIMIZE_OVERLAP_PERCENT * main_area
106}
107
108#[derive(Debug, Clone, Copy, PartialEq, Eq)]
109pub struct GalleryLayout {
110 pub tiles: usize,
111 pub overflow: usize,
112 pub divider: bool,
113 pub self_tile: bool,
114}
115
116impl GalleryLayout {
117 pub fn height(&self) -> f32 {
118 let segments = self.tiles + usize::from(self.self_tile);
119 let gaps = (segments + usize::from(self.divider)).saturating_sub(1);
120 GALLERY_TITLE_HEIGHT
121 + GALLERY_INSET
122 + segments as f32 * GALLERY_TILE_HEIGHT
123 + if self.divider {
124 GALLERY_DIVIDER_HEIGHT
125 } else {
126 0.
127 }
128 + gaps as f32 * GALLERY_INSET
129 + GALLERY_INSET
130 + GALLERY_CONTROLS_HEIGHT
131 }
132}
133
134pub fn gallery_layout(others: usize, self_tile: bool, available_height: f32) -> GalleryLayout {
135 let build = |tiles: usize| GalleryLayout {
136 tiles,
137 overflow: others - tiles,
138 divider: others > 0 && self_tile,
139 self_tile,
140 };
141 let mut layout = build(others.min(GALLERY_MAX_TILES));
142 while layout.tiles > 1 && layout.height() > available_height {
143 layout = build(layout.tiles - 1);
144 }
145 layout
146}
147
148pub fn gallery_available_height(work: WorkArea) -> f32 {
149 (work.bottom - work.top) as f32 / work.scale - 2. * GALLERY_MARGIN
150}
151
152pub fn gallery_rect(
153 work: WorkArea,
154 layout: GalleryLayout,
155 origin: Option<(i32, i32)>,
156) -> ScreenRect {
157 let scaled = |logical: f32| (logical * work.scale).round() as i32;
158 let width = scaled(GALLERY_WIDTH);
159 let height = scaled(layout.height());
160 let margin = scaled(GALLERY_MARGIN);
161 let (left, top) =
162 origin.unwrap_or((work.right - width - margin, work.bottom - height - margin));
163 let left = left.clamp(work.left, (work.right - width).max(work.left));
164 let top = top.clamp(work.top, (work.bottom - height).max(work.top));
165 ScreenRect {
166 left,
167 top,
168 right: left + width,
169 bottom: top + height,
170 }
171}
172
173fn prioritized(model: &CallModel, tile: &Tile) -> bool {
174 model.is_pinned(&tile.mri) || tile.spotlight.is_some() || tile.hand.is_some()
175}
176
177pub fn gallery_candidates(model: &CallModel) -> Vec<&Tile> {
178 let mut tiles: Vec<&Tile> = model
179 .layout_tiles()
180 .into_iter()
181 .filter(|tile| tile.state == TileState::Present)
182 .collect();
183 tiles.sort_by_key(|tile| {
184 (
185 !prioritized(model, tile),
186 !(model.tile_speaking(tile) || model.is_recent_speaker(&tile.mri)),
187 )
188 });
189 tiles
190}
191
192#[cfg(test)]
193mod tests {
194 use super::*;
195
196 fn work(scale: f32) -> WorkArea {
197 WorkArea {
198 left: 0,
199 top: 0,
200 right: 1920,
201 bottom: 1040,
202 scale,
203 }
204 }
205
206 fn rect(left: i32, top: i32, right: i32, bottom: i32) -> ScreenRect {
207 ScreenRect {
208 left,
209 top,
210 right,
211 bottom,
212 }
213 }
214
215 #[test]
216 fn decision_table() {
217 use LocalShare::*;
218 use Monitor as M;
219 let rows = [
220 (None, false, M::None, false, false),
221 (None, true, M::Mini, false, false),
222 (Screen, false, M::None, true, true),
223 (Screen, true, M::Gallery, true, true),
224 (Window, false, M::None, true, false),
225 (Window, true, M::Gallery, true, false),
226 ];
227 for (share, minimized, monitor, share_bar, exclude_main) in rows {
228 assert_eq!(
229 overlay_plan(true, share, minimized, false),
230 OverlayPlan {
231 monitor,
232 share_bar,
233 exclude_main
234 },
235 "{share:?} minimized={minimized}"
236 );
237 }
238 }
239
240 #[test]
241 fn speaker_only_swaps_the_gallery_for_the_mini_tile() {
242 let plan = overlay_plan(true, LocalShare::Screen, true, true);
243 assert_eq!(plan.monitor, Monitor::Mini);
244 assert!(plan.exclude_main);
245 assert_eq!(
246 overlay_plan(true, LocalShare::None, true, true).monitor,
247 Monitor::Mini
248 );
249 }
250
251 #[test]
252 fn nothing_shows_outside_a_call() {
253 let plan = overlay_plan(false, LocalShare::None, true, false);
254 assert_eq!(plan.monitor, Monitor::None);
255 assert!(!plan.share_bar);
256 }
257
258 #[test]
259 fn overlays_are_always_excluded_and_main_only_for_a_screen() {
260 for share in [LocalShare::None, LocalShare::Screen, LocalShare::Window] {
261 for surface in [
262 Surface::ShareBar,
263 Surface::Border,
264 Surface::Mini,
265 Surface::Gallery,
266 ] {
267 assert!(excluded_from_capture(surface, share));
268 }
269 }
270 assert!(excluded_from_capture(Surface::Main, LocalShare::Screen));
271 assert!(!excluded_from_capture(Surface::Main, LocalShare::Window));
272 assert!(!excluded_from_capture(Surface::Main, LocalShare::None));
273 }
274
275 #[test]
276 fn unknown_source_kind_counts_as_a_screen() {
277 assert_eq!(LocalShare::of(None, true), LocalShare::Screen);
278 assert_eq!(
279 LocalShare::of(Some(ShareKind::Window), true),
280 LocalShare::Window
281 );
282 assert_eq!(
283 LocalShare::of(Some(ShareKind::Screen), false),
284 LocalShare::None
285 );
286 }
287
288 #[test]
289 fn screen_share_minimizes_only_when_the_main_window_is_on_the_shared_monitor() {
290 let monitor = rect(0, 0, 1920, 1080);
291 let on_monitor = Some(rect(100, 100, 1100, 800));
292 let other_monitor = Some(rect(2000, 100, 3000, 800));
293 let edge = Some(rect(1880, 0, 2880, 1000));
294 assert!(minimize_on_share_start(
295 LocalShare::Screen,
296 on_monitor,
297 Some(monitor)
298 ));
299 assert!(!minimize_on_share_start(
300 LocalShare::Screen,
301 other_monitor,
302 Some(monitor)
303 ));
304 assert!(!minimize_on_share_start(
305 LocalShare::Screen,
306 edge,
307 Some(monitor)
308 ));
309 assert!(minimize_on_share_start(
310 LocalShare::Screen,
311 None,
312 Some(monitor)
313 ));
314 assert!(minimize_on_share_start(
315 LocalShare::Screen,
316 on_monitor,
317 None
318 ));
319 }
320
321 #[test]
322 fn window_share_and_no_share_never_minimize() {
323 let monitor = Some(rect(0, 0, 1920, 1080));
324 assert!(!minimize_on_share_start(
325 LocalShare::Window,
326 monitor,
327 monitor
328 ));
329 assert!(!minimize_on_share_start(LocalShare::None, monitor, monitor));
330 }
331
332 #[test]
333 fn gallery_stacks_four_tiles_a_divider_and_the_own_tile() {
334 let layout = gallery_layout(9, true, 2000.);
335 assert_eq!(
336 layout,
337 GalleryLayout {
338 tiles: 4,
339 overflow: 5,
340 divider: true,
341 self_tile: true
342 }
343 );
344 let expected = GALLERY_TITLE_HEIGHT
345 + 5. * GALLERY_TILE_HEIGHT
346 + GALLERY_DIVIDER_HEIGHT
347 + 7. * GALLERY_INSET
348 + GALLERY_CONTROLS_HEIGHT;
349 assert!((layout.height() - expected).abs() < 0.01);
350 }
351
352 #[test]
353 fn gallery_chrome_matches_teams() {
354 let chrome = GalleryLayout {
355 tiles: 0,
356 overflow: 0,
357 divider: false,
358 self_tile: false,
359 }
360 .height();
361 assert_eq!(chrome, 78.);
362 assert_eq!(GALLERY_TILE_WIDTH, 186.);
363 }
364
365 #[test]
366 fn gallery_drops_tiles_to_fit_a_short_screen() {
367 let layout = gallery_layout(9, true, 500.);
368 assert!(layout.height() <= 500.);
369 assert_eq!(layout.tiles, 2);
370 assert_eq!(layout.overflow, 7);
371 assert_eq!(gallery_layout(9, true, 10.).tiles, 1);
372 }
373
374 #[test]
375 fn gallery_without_others_has_no_divider() {
376 let layout = gallery_layout(0, true, 2000.);
377 assert_eq!(
378 (layout.tiles, layout.divider, layout.self_tile),
379 (0, false, true)
380 );
381 let hidden_self = gallery_layout(3, false, 2000.);
382 assert_eq!((hidden_self.tiles, hidden_self.divider), (3, false));
383 }
384
385 #[test]
386 fn gallery_defaults_to_the_bottom_right_with_the_teams_margin() {
387 let layout = gallery_layout(2, true, 2000.);
388 let placed = gallery_rect(work(1.), layout, None);
389 assert_eq!(placed.width(), 192);
390 assert_eq!((placed.right, placed.bottom), (1920 - 30, 1040 - 30));
391 assert_eq!(placed.height(), layout.height().round() as i32);
392 }
393
394 #[test]
395 fn gallery_keeps_a_dragged_origin_inside_the_work_area() {
396 let layout = gallery_layout(4, true, 2000.);
397 assert_eq!(gallery_rect(work(1.), layout, Some((200, 100))).left, 200);
398 let pushed = gallery_rect(work(1.), layout, Some((5000, 900)));
399 assert_eq!((pushed.right, pushed.bottom), (1920, 1040));
400 }
401
402 #[test]
403 fn gallery_scales_with_the_monitor() {
404 let layout = gallery_layout(1, false, 2000.);
405 let placed = gallery_rect(work(2.), layout, None);
406 assert_eq!(placed.width(), 384);
407 assert_eq!(gallery_available_height(work(2.)), 520. - 60.);
408 }
409
410 fn present(mri: &str, name: &str) -> Tile {
411 Tile {
412 state: TileState::Present,
413 ..Tile::invited(mri, name)
414 }
415 }
416
417 #[test]
418 fn candidates_put_pinned_then_speakers_first() {
419 let mut model = CallModel::test();
420 model.tiles = vec![
421 present("8:a", "Ada"),
422 present("8:b", "Bo"),
423 present("8:c", "Cy"),
424 Tile::invited("8:d", "Dee"),
425 ];
426 model.speaking_mris = vec!["8:c".to_owned()];
427 model.toggle_pin("8:b");
428 let names: Vec<&str> = gallery_candidates(&model)
429 .iter()
430 .map(|tile| tile.name.as_str())
431 .collect();
432 assert_eq!(names, ["Bo", "Cy", "Ada"]);
433 }
434}
crates/app/src/call/overlay.rs +173 −26
@@ -7,12 +7,18 @@ use gpui_kit::*;
7 7 use super::model::format_elapsed;
8 8 use super::overlay_layout::{
9 9 BorderVisibility, MINI_POSITION_KEY, bar_collapsed, bar_rect, border_rects, border_thickness,
10 border_visibility, format_position, mini_rect, mini_wanted, mini_work_area, parse_position,
10 border_visibility, format_position, mini_rect, mini_work_area, parse_position,
11 };
12 use super::share_overlay::{
13 GALLERY_POSITION_KEY, GalleryLayout, LocalShare, Monitor, Surface, excluded_from_capture,
14 gallery_available_height, gallery_candidates, gallery_layout, gallery_rect,
15 minimize_on_share_start, overlay_plan,
11 16 };
12 17 use crate::app_state::AppState;
13 18 use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
14 19 use crate::views::call_mini_window::MiniWindowView;
15 20 use crate::views::call_pop_out::{POP_OUT_SIZE, POP_OUT_TITLE, SharePopOutView};
21 use crate::views::call_share_gallery::ShareGalleryView;
16 22 use crate::views::share_bar::{ShareBarView, ShareBorderView};
17 23
18 24 const TICK: Duration = Duration::from_millis(100);
@@ -24,6 +30,7 @@ const BORDER_SIDES: usize = 4;
24 30 enum Role {
25 31 Bar,
26 32 Mini,
33 Gallery,
27 34 Border(usize),
28 35 }
29 36
@@ -76,6 +83,7 @@ struct ShareSession {
76 83 started: Instant,
77 84 source: Option<ShareSource>,
78 85 geometry: Option<ShareGeometry>,
86 minimize_checked: bool,
79 87 }
80 88
81 89 pub struct CallWindows {
@@ -95,6 +103,12 @@ pub struct CallWindows {
95 103 shown_second: u64,
96 104 mini_saved: Option<(i32, i32)>,
97 105 mini_seen: Option<(i32, i32)>,
106 gallery_saved: Option<(i32, i32)>,
107 gallery_seen: Option<(i32, i32)>,
108 gallery_layout: GalleryLayout,
109 speaker_only: bool,
110 main_excluded: bool,
111 minimized_for_share: bool,
98 112 ticks: u32,
99 113 }
100 114
@@ -125,12 +139,12 @@ fn overlay_options(role: Role, rect: ScreenRect, scale: f32) -> WindowOptions {
125 139 focus: false,
126 140 show: true,
127 141 kind: WindowKind::PopUp,
128 is_movable: role == Role::Mini,
142 is_movable: matches!(role, Role::Mini | Role::Gallery),
129 143 is_resizable: false,
130 144 is_minimizable: false,
131 145 window_background: match role {
132 146 Role::Border(_) => WindowBackgroundAppearance::Opaque,
133 Role::Bar | Role::Mini => WindowBackgroundAppearance::Transparent,
147 Role::Bar | Role::Mini | Role::Gallery => WindowBackgroundAppearance::Transparent,
134 148 },
135 149 ..Default::default()
136 150 }
@@ -138,13 +152,16 @@ fn overlay_options(role: Role, rect: ScreenRect, scale: f32) -> WindowOptions {
138 152
139 153 impl CallWindows {
140 154 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
141 let mini_saved = app
142 .read(cx)
143 .store
144 .meta(MINI_POSITION_KEY)
145 .ok()
146 .flatten()
147 .and_then(|text| parse_position(&text));
155 let saved_position = |key: &str, cx: &App| {
156 app.read(cx)
157 .store
158 .meta(key)
159 .ok()
160 .flatten()
161 .and_then(|text| parse_position(&text))
162 };
163 let mini_saved = saved_position(MINI_POSITION_KEY, cx);
164 let gallery_saved = saved_position(GALLERY_POSITION_KEY, cx);
148 165 let windows = CallWindows {
149 166 app,
150 167 main_window: window.window_handle(),
@@ -162,6 +179,12 @@ impl CallWindows {
162 179 shown_second: 0,
163 180 mini_saved,
164 181 mini_seen: None,
182 gallery_saved,
183 gallery_seen: None,
184 gallery_layout: gallery_layout(0, true, f32::MAX),
185 speaker_only: false,
186 main_excluded: false,
187 minimized_for_share: false,
165 188 ticks: 0,
166 189 };
167 190 cx.spawn(async move |this, cx| {
@@ -190,6 +213,19 @@ impl CallWindows {
190 213 self.bar_collapsed
191 214 }
192 215
216 pub fn gallery_layout(&self) -> GalleryLayout {
217 self.gallery_layout
218 }
219
220 pub fn sharing(&self) -> bool {
221 self.share.is_some()
222 }
223
224 pub fn toggle_speaker_only(&mut self, cx: &mut Context<Self>) {
225 self.speaker_only = !self.speaker_only;
226 cx.notify();
227 }
228
193 229 pub fn share_text(&self) -> String {
194 230 let Some(session) = &self.share else {
195 231 return String::new();
@@ -233,6 +269,7 @@ impl CallWindows {
233 269 && self.share.is_none()
234 270 && self.windows.is_empty()
235 271 && self.opening.is_empty()
272 && !self.main_excluded
236 273 }
237 274
238 275 fn tick(&mut self, cx: &mut Context<Self>) -> Duration {
@@ -243,10 +280,12 @@ impl CallWindows {
243 280 let slow = self.ticks % SLOW_TICK_EVERY == 0;
244 281 self.refresh_main_window();
245 282 self.sync_share(slow, cx);
283 self.sync_capture_exclusion();
246 284 self.sync_pop_out(cx);
247 self.sync_mini(cx);
285 self.sync_monitor(cx);
248 286 if slow {
249 self.track_mini_position(cx);
287 self.track_position(Role::Mini, cx);
288 self.track_position(Role::Gallery, cx);
250 289 }
251 290 TICK
252 291 }
@@ -255,7 +294,11 @@ impl CallWindows {
255 294 let Some(native) = self.main_native else {
256 295 return;
257 296 };
258 self.minimized = platform::window_minimized(native);
297 let minimized = platform::window_minimized(native);
298 if self.minimized && !minimized {
299 self.minimized_for_share = false;
300 }
301 self.minimized = minimized;
259 302 if !self.minimized {
260 303 self.work_area = platform::work_area(native).or(self.work_area);
261 304 }
@@ -285,6 +328,7 @@ impl CallWindows {
285 328 started: Instant::now(),
286 329 source: None,
287 330 geometry: None,
331 minimize_checked: false,
288 332 });
289 333 refresh_geometry = true;
290 334 }
@@ -305,6 +349,10 @@ impl CallWindows {
305 349 }
306 350 let geometry = session.geometry;
307 351 let elapsed_seconds = session.started.elapsed().as_secs();
352 let check_minimize = !std::mem::replace(&mut session.minimize_checked, true);
353 if check_minimize {
354 self.minimize_for_share(geometry.map(|geometry| geometry.target), cx);
355 }
308 356 let Some(work) = geometry
309 357 .map(|geometry| geometry.work)
310 358 .or(self.work_area)
@@ -347,10 +395,55 @@ impl CallWindows {
347 395 }
348 396 }
349 397
398 fn local_share_mode(&self) -> LocalShare {
399 let kind = self
400 .share
401 .as_ref()
402 .and_then(|session| session.source.as_ref())
403 .map(|source| source.kind);
404 LocalShare::of(kind, self.share.is_some())
405 }
406
407 fn minimize_for_share(&mut self, shared: Option<ScreenRect>, cx: &mut Context<Self>) {
408 let Some(native) = self.main_native.filter(|_| !self.minimized) else {
409 return;
410 };
411 if !minimize_on_share_start(
412 self.local_share_mode(),
413 platform::window_rect(native),
414 shared,
415 ) {
416 return;
417 }
418 self.minimized_for_share = true;
419 self.main_window
420 .update(cx, |_, window, _| window.minimize_window())
421 .ok();
422 }
423
424 fn sync_capture_exclusion(&mut self) {
425 let Some(native) = self.main_native else {
426 return;
427 };
428 let wanted = excluded_from_capture(Surface::Main, self.local_share_mode());
429 if wanted == self.main_excluded {
430 return;
431 }
432 self.main_excluded = wanted;
433 if wanted {
434 platform::exclude_from_capture(native);
435 } else {
436 platform::include_in_capture(native);
437 }
438 }
439
350 440 fn end_share(&mut self, cx: &mut Context<Self>) {
351 441 if self.share.take().is_none() {
352 442 return;
353 443 }
444 if std::mem::take(&mut self.minimized_for_share) && self.minimized {
445 self.return_to_call(cx);
446 }
354 447 self.bar_collapsed = false;
355 448 self.close(Role::Bar, cx);
356 449 self.close_borders(cx);
@@ -419,40 +512,91 @@ impl CallWindows {
419 512 });
420 513 }
421 514
422 fn sync_mini(&mut self, cx: &mut Context<Self>) {
515 fn sync_monitor(&mut self, cx: &mut Context<Self>) {
423 516 let in_call = self.app.read(cx).call.is_some();
517 let plan = overlay_plan(
518 in_call,
519 self.local_share_mode(),
520 self.minimized,
521 self.speaker_only,
522 );
424 523 let work = self.work_area.or_else(|| display_work_area(cx));
425 match work.filter(|_| mini_wanted(in_call, self.minimized)) {
426 Some(main_work) => {
524 match (plan.monitor, work) {
525 (Monitor::Mini, Some(main_work)) => {
526 self.close(Role::Gallery, cx);
427 527 let work = mini_work_area(main_work, self.mini_saved, platform::work_area_at);
428 528 let rect = mini_rect(work, self.mini_saved);
429 529 self.ensure_window(Role::Mini, rect, work.scale, false, cx);
430 530 }
431 None => self.close(Role::Mini, cx),
531 (Monitor::Gallery, Some(main_work)) => {
532 self.close(Role::Mini, cx);
533 self.place_gallery(main_work, cx);
534 }
535 _ => {
536 self.close(Role::Mini, cx);
537 self.close(Role::Gallery, cx);
538 }
432 539 }
433 540 }
434 541
435 fn track_mini_position(&mut self, cx: &mut Context<Self>) {
436 let Some(native) = self
542 fn place_gallery(&mut self, main_work: WorkArea, cx: &mut Context<Self>) {
543 let work = mini_work_area(main_work, self.gallery_saved, platform::work_area_at);
544 let (others, self_tile) = self.app.read(cx).call.as_ref().map_or((0, true), |call| {
545 (
546 gallery_candidates(&call.model).len(),
547 !call.model.view.hide_me,
548 )
549 });
550 let layout = gallery_layout(others, self_tile, gallery_available_height(work));
551 if layout != self.gallery_layout {
552 self.gallery_layout = layout;
553 cx.notify();
554 }
555 let origin = self
437 556 .windows
438 .get(&Role::Mini)
557 .get(&Role::Gallery)
439 558 .and_then(|placed| placed.native)
440 else {
559 .and_then(platform::window_rect)
560 .map(|rect| (rect.left, rect.top))
561 .or(self.gallery_saved);
562 let rect = gallery_rect(work, layout, origin);
563 match self.windows.get_mut(&Role::Gallery) {
564 Some(placed) => {
565 let size = |rect: ScreenRect| (rect.width(), rect.height());
566 if placed.rect.map(size) != Some(size(rect)) {
567 placed.place(rect, cx);
568 }
569 }
570 None => self.open(Role::Gallery, rect, work.scale, cx),
571 }
572 }
573
574 fn track_position(&mut self, role: Role, cx: &mut Context<Self>) {
575 let Some(native) = self.windows.get(&role).and_then(|placed| placed.native) else {
441 576 return;
442 577 };
443 578 let Some(rect) = platform::window_rect(native) else {
444 579 return;
445 580 };
581 let (key, saved, seen) = match role {
582 Role::Mini => (MINI_POSITION_KEY, &mut self.mini_saved, &mut self.mini_seen),
583 Role::Gallery => (
584 GALLERY_POSITION_KEY,
585 &mut self.gallery_saved,
586 &mut self.gallery_seen,
587 ),
588 Role::Bar | Role::Border(_) => return,
589 };
446 590 let position = (rect.left, rect.top);
447 let settled = self.mini_seen == Some(position);
448 self.mini_seen = Some(position);
449 if settled && self.mini_saved != Some(position) {
450 self.mini_saved = Some(position);
591 let settled = *seen == Some(position);
592 *seen = Some(position);
593 if settled && *saved != Some(position) {
594 *saved = Some(position);
451 595 let _ = self
452 596 .app
453 597 .read(cx)
454 598 .store
455 .set_meta(MINI_POSITION_KEY, &format_position(position.0, position.1));
599 .set_meta(key, &format_position(position.0, position.1));
456 600 }
457 601 }
458 602
@@ -506,6 +650,9 @@ impl CallWindows {
506 650 let view: AnyView = match role {
507 651 Role::Bar => cx.new(|cx| ShareBarView::new(view_controller, cx)).into(),
508 652 Role::Mini => cx.new(|cx| MiniWindowView::new(view_controller, cx)).into(),
653 Role::Gallery => cx
654 .new(|cx| ShareGalleryView::new(view_controller, cx))
655 .into(),
509 656 Role::Border(_) => cx.new(|_| ShareBorderView).into(),
510 657 };
511 658 cx.new(|cx| base::Root::new(view, window, cx).bg(transparent_black()))
@@ -7,12 +7,18 @@ use gpui_kit::*;
7use super::model::format_elapsed;
7use super::model::format_elapsed;
8use super::overlay_layout::{
8use super::overlay_layout::{
9 BorderVisibility, MINI_POSITION_KEY, bar_collapsed, bar_rect, border_rects, border_thickness,
9 BorderVisibility, MINI_POSITION_KEY, bar_collapsed, bar_rect, border_rects, border_thickness,
10 border_visibility, format_position, mini_rect, mini_wanted, mini_work_area, parse_position,
10 border_visibility, format_position, mini_rect, mini_work_area, parse_position,
11};
12use super::share_overlay::{
13 GALLERY_POSITION_KEY, GalleryLayout, LocalShare, Monitor, Surface, excluded_from_capture,
14 gallery_available_height, gallery_candidates, gallery_layout, gallery_rect,
15 minimize_on_share_start, overlay_plan,
11};
16};
12use crate::app_state::AppState;
17use crate::app_state::AppState;
13use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
18use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
14use crate::views::call_mini_window::MiniWindowView;
19use crate::views::call_mini_window::MiniWindowView;
15use crate::views::call_pop_out::{POP_OUT_SIZE, POP_OUT_TITLE, SharePopOutView};
20use crate::views::call_pop_out::{POP_OUT_SIZE, POP_OUT_TITLE, SharePopOutView};
21use crate::views::call_share_gallery::ShareGalleryView;
16use crate::views::share_bar::{ShareBarView, ShareBorderView};
22use crate::views::share_bar::{ShareBarView, ShareBorderView};
17
23
18const TICK: Duration = Duration::from_millis(100);
24const TICK: Duration = Duration::from_millis(100);
@@ -24,6 +30,7 @@ const BORDER_SIDES: usize = 4;
24enum Role {
30enum Role {
25 Bar,
31 Bar,
26 Mini,
32 Mini,
33 Gallery,
27 Border(usize),
34 Border(usize),
28}
35}
29
36
@@ -76,6 +83,7 @@ struct ShareSession {
76 started: Instant,
83 started: Instant,
77 source: Option<ShareSource>,
84 source: Option<ShareSource>,
78 geometry: Option<ShareGeometry>,
85 geometry: Option<ShareGeometry>,
86 minimize_checked: bool,
79}
87}
80
88
81pub struct CallWindows {
89pub struct CallWindows {
@@ -95,6 +103,12 @@ pub struct CallWindows {
95 shown_second: u64,
103 shown_second: u64,
96 mini_saved: Option<(i32, i32)>,
104 mini_saved: Option<(i32, i32)>,
97 mini_seen: Option<(i32, i32)>,
105 mini_seen: Option<(i32, i32)>,
106 gallery_saved: Option<(i32, i32)>,
107 gallery_seen: Option<(i32, i32)>,
108 gallery_layout: GalleryLayout,
109 speaker_only: bool,
110 main_excluded: bool,
111 minimized_for_share: bool,
98 ticks: u32,
112 ticks: u32,
99}
113}
100
114
@@ -125,12 +139,12 @@ fn overlay_options(role: Role, rect: ScreenRect, scale: f32) -> WindowOptions {
125 focus: false,
139 focus: false,
126 show: true,
140 show: true,
127 kind: WindowKind::PopUp,
141 kind: WindowKind::PopUp,
128 is_movable: role == Role::Mini,
142 is_movable: matches!(role, Role::Mini | Role::Gallery),
129 is_resizable: false,
143 is_resizable: false,
130 is_minimizable: false,
144 is_minimizable: false,
131 window_background: match role {
145 window_background: match role {
132 Role::Border(_) => WindowBackgroundAppearance::Opaque,
146 Role::Border(_) => WindowBackgroundAppearance::Opaque,
133 Role::Bar | Role::Mini => WindowBackgroundAppearance::Transparent,
147 Role::Bar | Role::Mini | Role::Gallery => WindowBackgroundAppearance::Transparent,
134 },
148 },
135 ..Default::default()
149 ..Default::default()
136 }
150 }
@@ -138,13 +152,16 @@ fn overlay_options(role: Role, rect: ScreenRect, scale: f32) -> WindowOptions {
138
152
139impl CallWindows {
153impl CallWindows {
140 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
154 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
141 let mini_saved = app
155 let saved_position = |key: &str, cx: &App| {
142 .read(cx)
156 app.read(cx)
143 .store
157 .store
144 .meta(MINI_POSITION_KEY)
158 .meta(key)
145 .ok()
159 .ok()
146 .flatten()
160 .flatten()
147 .and_then(|text| parse_position(&text));
161 .and_then(|text| parse_position(&text))
162 };
163 let mini_saved = saved_position(MINI_POSITION_KEY, cx);
164 let gallery_saved = saved_position(GALLERY_POSITION_KEY, cx);
148 let windows = CallWindows {
165 let windows = CallWindows {
149 app,
166 app,
150 main_window: window.window_handle(),
167 main_window: window.window_handle(),
@@ -162,6 +179,12 @@ impl CallWindows {
162 shown_second: 0,
179 shown_second: 0,
163 mini_saved,
180 mini_saved,
164 mini_seen: None,
181 mini_seen: None,
182 gallery_saved,
183 gallery_seen: None,
184 gallery_layout: gallery_layout(0, true, f32::MAX),
185 speaker_only: false,
186 main_excluded: false,
187 minimized_for_share: false,
165 ticks: 0,
188 ticks: 0,
166 };
189 };
167 cx.spawn(async move |this, cx| {
190 cx.spawn(async move |this, cx| {
@@ -190,6 +213,19 @@ impl CallWindows {
190 self.bar_collapsed
213 self.bar_collapsed
191 }
214 }
192
215
216 pub fn gallery_layout(&self) -> GalleryLayout {
217 self.gallery_layout
218 }
219
220 pub fn sharing(&self) -> bool {
221 self.share.is_some()
222 }
223
224 pub fn toggle_speaker_only(&mut self, cx: &mut Context<Self>) {
225 self.speaker_only = !self.speaker_only;
226 cx.notify();
227 }
228
193 pub fn share_text(&self) -> String {
229 pub fn share_text(&self) -> String {
194 let Some(session) = &self.share else {
230 let Some(session) = &self.share else {
195 return String::new();
231 return String::new();
@@ -233,6 +269,7 @@ impl CallWindows {
233 && self.share.is_none()
269 && self.share.is_none()
234 && self.windows.is_empty()
270 && self.windows.is_empty()
235 && self.opening.is_empty()
271 && self.opening.is_empty()
272 && !self.main_excluded
236 }
273 }
237
274
238 fn tick(&mut self, cx: &mut Context<Self>) -> Duration {
275 fn tick(&mut self, cx: &mut Context<Self>) -> Duration {
@@ -243,10 +280,12 @@ impl CallWindows {
243 let slow = self.ticks % SLOW_TICK_EVERY == 0;
280 let slow = self.ticks % SLOW_TICK_EVERY == 0;
244 self.refresh_main_window();
281 self.refresh_main_window();
245 self.sync_share(slow, cx);
282 self.sync_share(slow, cx);
283 self.sync_capture_exclusion();
246 self.sync_pop_out(cx);
284 self.sync_pop_out(cx);
247 self.sync_mini(cx);
285 self.sync_monitor(cx);
248 if slow {
286 if slow {
249 self.track_mini_position(cx);
287 self.track_position(Role::Mini, cx);
288 self.track_position(Role::Gallery, cx);
250 }
289 }
251 TICK
290 TICK
252 }
291 }
@@ -255,7 +294,11 @@ impl CallWindows {
255 let Some(native) = self.main_native else {
294 let Some(native) = self.main_native else {
256 return;
295 return;
257 };
296 };
258 self.minimized = platform::window_minimized(native);
297 let minimized = platform::window_minimized(native);
298 if self.minimized && !minimized {
299 self.minimized_for_share = false;
300 }
301 self.minimized = minimized;
259 if !self.minimized {
302 if !self.minimized {
260 self.work_area = platform::work_area(native).or(self.work_area);
303 self.work_area = platform::work_area(native).or(self.work_area);
261 }
304 }
@@ -285,6 +328,7 @@ impl CallWindows {
285 started: Instant::now(),
328 started: Instant::now(),
286 source: None,
329 source: None,
287 geometry: None,
330 geometry: None,
331 minimize_checked: false,
288 });
332 });
289 refresh_geometry = true;
333 refresh_geometry = true;
290 }
334 }
@@ -305,6 +349,10 @@ impl CallWindows {
305 }
349 }
306 let geometry = session.geometry;
350 let geometry = session.geometry;
307 let elapsed_seconds = session.started.elapsed().as_secs();
351 let elapsed_seconds = session.started.elapsed().as_secs();
352 let check_minimize = !std::mem::replace(&mut session.minimize_checked, true);
353 if check_minimize {
354 self.minimize_for_share(geometry.map(|geometry| geometry.target), cx);
355 }
308 let Some(work) = geometry
356 let Some(work) = geometry
309 .map(|geometry| geometry.work)
357 .map(|geometry| geometry.work)
310 .or(self.work_area)
358 .or(self.work_area)
@@ -347,10 +395,55 @@ impl CallWindows {
347 }
395 }
348 }
396 }
349
397
398 fn local_share_mode(&self) -> LocalShare {
399 let kind = self
400 .share
401 .as_ref()
402 .and_then(|session| session.source.as_ref())
403 .map(|source| source.kind);
404 LocalShare::of(kind, self.share.is_some())
405 }
406
407 fn minimize_for_share(&mut self, shared: Option<ScreenRect>, cx: &mut Context<Self>) {
408 let Some(native) = self.main_native.filter(|_| !self.minimized) else {
409 return;
410 };
411 if !minimize_on_share_start(
412 self.local_share_mode(),
413 platform::window_rect(native),
414 shared,
415 ) {
416 return;
417 }
418 self.minimized_for_share = true;
419 self.main_window
420 .update(cx, |_, window, _| window.minimize_window())
421 .ok();
422 }
423
424 fn sync_capture_exclusion(&mut self) {
425 let Some(native) = self.main_native else {
426 return;
427 };
428 let wanted = excluded_from_capture(Surface::Main, self.local_share_mode());
429 if wanted == self.main_excluded {
430 return;
431 }
432 self.main_excluded = wanted;
433 if wanted {
434 platform::exclude_from_capture(native);
435 } else {
436 platform::include_in_capture(native);
437 }
438 }
439
350 fn end_share(&mut self, cx: &mut Context<Self>) {
440 fn end_share(&mut self, cx: &mut Context<Self>) {
351 if self.share.take().is_none() {
441 if self.share.take().is_none() {
352 return;
442 return;
353 }
443 }
444 if std::mem::take(&mut self.minimized_for_share) && self.minimized {
445 self.return_to_call(cx);
446 }
354 self.bar_collapsed = false;
447 self.bar_collapsed = false;
355 self.close(Role::Bar, cx);
448 self.close(Role::Bar, cx);
356 self.close_borders(cx);
449 self.close_borders(cx);
@@ -419,40 +512,91 @@ impl CallWindows {
419 });
512 });
420 }
513 }
421
514
422 fn sync_mini(&mut self, cx: &mut Context<Self>) {
515 fn sync_monitor(&mut self, cx: &mut Context<Self>) {
423 let in_call = self.app.read(cx).call.is_some();
516 let in_call = self.app.read(cx).call.is_some();
517 let plan = overlay_plan(
518 in_call,
519 self.local_share_mode(),
520 self.minimized,
521 self.speaker_only,
522 );
424 let work = self.work_area.or_else(|| display_work_area(cx));
523 let work = self.work_area.or_else(|| display_work_area(cx));
425 match work.filter(|_| mini_wanted(in_call, self.minimized)) {
524 match (plan.monitor, work) {
426 Some(main_work) => {
525 (Monitor::Mini, Some(main_work)) => {
526 self.close(Role::Gallery, cx);
427 let work = mini_work_area(main_work, self.mini_saved, platform::work_area_at);
527 let work = mini_work_area(main_work, self.mini_saved, platform::work_area_at);
428 let rect = mini_rect(work, self.mini_saved);
528 let rect = mini_rect(work, self.mini_saved);
429 self.ensure_window(Role::Mini, rect, work.scale, false, cx);
529 self.ensure_window(Role::Mini, rect, work.scale, false, cx);
430 }
530 }
431 None => self.close(Role::Mini, cx),
531 (Monitor::Gallery, Some(main_work)) => {
532 self.close(Role::Mini, cx);
533 self.place_gallery(main_work, cx);
534 }
535 _ => {
536 self.close(Role::Mini, cx);
537 self.close(Role::Gallery, cx);
538 }
432 }
539 }
433 }
540 }
434
541
435 fn track_mini_position(&mut self, cx: &mut Context<Self>) {
542 fn place_gallery(&mut self, main_work: WorkArea, cx: &mut Context<Self>) {
436 let Some(native) = self
543 let work = mini_work_area(main_work, self.gallery_saved, platform::work_area_at);
544 let (others, self_tile) = self.app.read(cx).call.as_ref().map_or((0, true), |call| {
545 (
546 gallery_candidates(&call.model).len(),
547 !call.model.view.hide_me,
548 )
549 });
550 let layout = gallery_layout(others, self_tile, gallery_available_height(work));
551 if layout != self.gallery_layout {
552 self.gallery_layout = layout;
553 cx.notify();
554 }
555 let origin = self
437 .windows
556 .windows
438 .get(&Role::Mini)
557 .get(&Role::Gallery)
439 .and_then(|placed| placed.native)
558 .and_then(|placed| placed.native)
440 else {
559 .and_then(platform::window_rect)
560 .map(|rect| (rect.left, rect.top))
561 .or(self.gallery_saved);
562 let rect = gallery_rect(work, layout, origin);
563 match self.windows.get_mut(&Role::Gallery) {
564 Some(placed) => {
565 let size = |rect: ScreenRect| (rect.width(), rect.height());
566 if placed.rect.map(size) != Some(size(rect)) {
567 placed.place(rect, cx);
568 }
569 }
570 None => self.open(Role::Gallery, rect, work.scale, cx),
571 }
572 }
573
574 fn track_position(&mut self, role: Role, cx: &mut Context<Self>) {
575 let Some(native) = self.windows.get(&role).and_then(|placed| placed.native) else {
441 return;
576 return;
442 };
577 };
443 let Some(rect) = platform::window_rect(native) else {
578 let Some(rect) = platform::window_rect(native) else {
444 return;
579 return;
445 };
580 };
581 let (key, saved, seen) = match role {
582 Role::Mini => (MINI_POSITION_KEY, &mut self.mini_saved, &mut self.mini_seen),
583 Role::Gallery => (
584 GALLERY_POSITION_KEY,
585 &mut self.gallery_saved,
586 &mut self.gallery_seen,
587 ),
588 Role::Bar | Role::Border(_) => return,
589 };
446 let position = (rect.left, rect.top);
590 let position = (rect.left, rect.top);
447 let settled = self.mini_seen == Some(position);
591 let settled = *seen == Some(position);
448 self.mini_seen = Some(position);
592 *seen = Some(position);
449 if settled && self.mini_saved != Some(position) {
593 if settled && *saved != Some(position) {
450 self.mini_saved = Some(position);
594 *saved = Some(position);
451 let _ = self
595 let _ = self
452 .app
596 .app
453 .read(cx)
597 .read(cx)
454 .store
598 .store
455 .set_meta(MINI_POSITION_KEY, &format_position(position.0, position.1));
599 .set_meta(key, &format_position(position.0, position.1));
456 }
600 }
457 }
601 }
458
602
@@ -506,6 +650,9 @@ impl CallWindows {
506 let view: AnyView = match role {
650 let view: AnyView = match role {
507 Role::Bar => cx.new(|cx| ShareBarView::new(view_controller, cx)).into(),
651 Role::Bar => cx.new(|cx| ShareBarView::new(view_controller, cx)).into(),
508 Role::Mini => cx.new(|cx| MiniWindowView::new(view_controller, cx)).into(),
652 Role::Mini => cx.new(|cx| MiniWindowView::new(view_controller, cx)).into(),
653 Role::Gallery => cx
654 .new(|cx| ShareGalleryView::new(view_controller, cx))
655 .into(),
509 Role::Border(_) => cx.new(|_| ShareBorderView).into(),
656 Role::Border(_) => cx.new(|_| ShareBorderView).into(),
510 };
657 };
511 cx.new(|cx| base::Root::new(view, window, cx).bg(transparent_black()))
658 cx.new(|cx| base::Root::new(view, window, cx).bg(transparent_black()))
crates/app/src/views/call_mini_window.rs +27 −11
@@ -3,9 +3,11 @@ use std::time::Instant;
3 3 use calling::VideoKey;
4 4 use gpui_kit::assets::IconName;
5 5 use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
6 use gpui_kit::prelude::FluentBuilder as _;
6 7 use gpui_kit::*;
7 8
8 9 use super::avatar::person_avatar;
10 use super::call_share_gallery::{SHOW_MORE_PEOPLE, view_switch_button};
9 11 use super::call_view::{camera_button, leave_button, mute_button, round_control, status_line};
10 12 use super::widgets::icon;
11 13 use crate::app_state::AppState;
@@ -234,6 +236,7 @@ impl Render for MiniWindowView {
234 236 let now = Instant::now();
235 237 let (status, _) = status_line(model, now);
236 238 let windows = self.windows.clone();
239 let sharing = self.windows.read(cx).sharing();
237 240 let speaking = speaker_speaking(model);
238 241 let speaker_name = speaker_name_chip(state, model, now);
239 242 div()
@@ -274,17 +277,30 @@ impl Render for MiniWindowView {
274 277 }))
275 278 .children(self_view(state, model, now)),
276 279 )
277 .child(controls_row(
278 &self.app,
279 model,
280 ControlIds {
281 mute: "call-mini-window-mute",
282 back: "call-mini-window-back",
283 leave: "call-mini-window-leave",
284 },
285 "call-mini-window",
286 move |cx| windows.update(cx, |windows, cx| windows.return_to_call(cx)),
287 ))
280 .child(
281 controls_row(
282 &self.app,
283 model,
284 ControlIds {
285 mute: "call-mini-window-mute",
286 back: "call-mini-window-back",
287 leave: "call-mini-window-leave",
288 },
289 "call-mini-window",
290 move |cx| windows.update(cx, |windows, cx| windows.return_to_call(cx)),
291 )
292 .when(sharing, |row| {
293 row.child(
294 view_switch_button(
295 &self.windows,
296 "call-mini-window-more-people",
297 IconName::Users,
298 SHOW_MORE_PEOPLE,
299 )
300 .size(px(CONTROL_SIZE)),
301 )
302 }),
303 )
288 304 .into_any_element()
289 305 }
290 306 }
@@ -3,9 +3,11 @@ use std::time::Instant;
3use calling::VideoKey;
3use calling::VideoKey;
4use gpui_kit::assets::IconName;
4use gpui_kit::assets::IconName;
5use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
5use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
6use gpui_kit::prelude::FluentBuilder as _;
6use gpui_kit::*;
7use gpui_kit::*;
7
8
8use super::avatar::person_avatar;
9use super::avatar::person_avatar;
10use super::call_share_gallery::{SHOW_MORE_PEOPLE, view_switch_button};
9use super::call_view::{camera_button, leave_button, mute_button, round_control, status_line};
11use super::call_view::{camera_button, leave_button, mute_button, round_control, status_line};
10use super::widgets::icon;
12use super::widgets::icon;
11use crate::app_state::AppState;
13use crate::app_state::AppState;
@@ -234,6 +236,7 @@ impl Render for MiniWindowView {
234 let now = Instant::now();
236 let now = Instant::now();
235 let (status, _) = status_line(model, now);
237 let (status, _) = status_line(model, now);
236 let windows = self.windows.clone();
238 let windows = self.windows.clone();
239 let sharing = self.windows.read(cx).sharing();
237 let speaking = speaker_speaking(model);
240 let speaking = speaker_speaking(model);
238 let speaker_name = speaker_name_chip(state, model, now);
241 let speaker_name = speaker_name_chip(state, model, now);
239 div()
242 div()
@@ -274,17 +277,30 @@ impl Render for MiniWindowView {
274 }))
277 }))
275 .children(self_view(state, model, now)),
278 .children(self_view(state, model, now)),
276 )
279 )
277 .child(controls_row(
280 .child(
278 &self.app,
281 controls_row(
279 model,
282 &self.app,
280 ControlIds {
283 model,
281 mute: "call-mini-window-mute",
284 ControlIds {
282 back: "call-mini-window-back",
285 mute: "call-mini-window-mute",
283 leave: "call-mini-window-leave",
286 back: "call-mini-window-back",
284 },
287 leave: "call-mini-window-leave",
285 "call-mini-window",
288 },
286 move |cx| windows.update(cx, |windows, cx| windows.return_to_call(cx)),
289 "call-mini-window",
287 ))
290 move |cx| windows.update(cx, |windows, cx| windows.return_to_call(cx)),
291 )
292 .when(sharing, |row| {
293 row.child(
294 view_switch_button(
295 &self.windows,
296 "call-mini-window-more-people",
297 IconName::Users,
298 SHOW_MORE_PEOPLE,
299 )
300 .size(px(CONTROL_SIZE)),
301 )
302 }),
303 )
288 .into_any_element()
304 .into_any_element()
289 }
305 }
290}
306}
crates/app/src/views/call_view.rs +28 −8
@@ -963,6 +963,17 @@ pub(super) fn person_tile(
963 963 remote: &Tile,
964 964 size: TileSize,
965 965 now: Instant,
966 ) -> AnyElement {
967 let element = plain_person_tile(state, model, remote, size, now);
968 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
969 }
970
971 pub(super) fn plain_person_tile(
972 state: &AppState,
973 model: &CallModel,
974 remote: &Tile,
975 size: TileSize,
976 now: Instant,
966 977 ) -> AnyElement {
967 978 let extras = TileExtras {
968 979 hand: remote.hand.map(|rank| model.hand_position(rank)),
@@ -973,8 +984,7 @@ pub(super) fn person_tile(
973 984 spotlight: remote.spotlight.is_some(),
974 985 pinned: model.is_pinned(&remote.mri),
975 986 };
976 let element = person_tile_body(state, model, remote, size, now, &extras);
977 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
987 person_tile_body(state, model, remote, size, now, &extras)
978 988 }
979 989
980 990 fn person_tile_body(
@@ -1042,18 +1052,28 @@ pub(super) fn own_tile(
1042 1052 now: Instant,
1043 1053 ) -> AnyElement {
1044 1054 let own_mri = model.own_mri.clone().unwrap_or_default();
1055 let element = plain_own_tile(state, model, size, now);
1056 if own_mri.is_empty() {
1057 return element;
1058 }
1059 with_tile_menu(app, model, &own_mri, "You", true, element)
1060 }
1061
1062 pub(super) fn plain_own_tile(
1063 state: &AppState,
1064 model: &CallModel,
1065 size: TileSize,
1066 now: Instant,
1067 ) -> AnyElement {
1068 let own_mri = model.own_mri.as_deref().unwrap_or_default();
1045 1069 let extras = TileExtras {
1046 1070 hand: model.own_hand.map(|rank| model.hand_position(rank)),
1047 1071 own: true,
1048 1072 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
1049 1073 spotlight: model.own_spotlight.is_some(),
1050 pinned: model.is_pinned(&own_mri),
1074 pinned: model.is_pinned(own_mri),
1051 1075 };
1052 let element = own_tile_body(state, model, size, now, &extras);
1053 if own_mri.is_empty() {
1054 return element;
1055 }
1056 with_tile_menu(app, model, &own_mri, "You", true, element)
1076 own_tile_body(state, model, size, now, &extras)
1057 1077 }
1058 1078
1059 1079 fn own_tile_body(
@@ -963,6 +963,17 @@ pub(super) fn person_tile(
963 remote: &Tile,
963 remote: &Tile,
964 size: TileSize,
964 size: TileSize,
965 now: Instant,
965 now: Instant,
966) -> AnyElement {
967 let element = plain_person_tile(state, model, remote, size, now);
968 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
969}
970
971pub(super) fn plain_person_tile(
972 state: &AppState,
973 model: &CallModel,
974 remote: &Tile,
975 size: TileSize,
976 now: Instant,
966) -> AnyElement {
977) -> AnyElement {
967 let extras = TileExtras {
978 let extras = TileExtras {
968 hand: remote.hand.map(|rank| model.hand_position(rank)),
979 hand: remote.hand.map(|rank| model.hand_position(rank)),
@@ -973,8 +984,7 @@ pub(super) fn person_tile(
973 spotlight: remote.spotlight.is_some(),
984 spotlight: remote.spotlight.is_some(),
974 pinned: model.is_pinned(&remote.mri),
985 pinned: model.is_pinned(&remote.mri),
975 };
986 };
976 let element = person_tile_body(state, model, remote, size, now, &extras);
987 person_tile_body(state, model, remote, size, now, &extras)
977 with_tile_menu(app, model, &remote.mri, &remote.name, false, element)
978}
988}
979
989
980fn person_tile_body(
990fn person_tile_body(
@@ -1042,18 +1052,28 @@ pub(super) fn own_tile(
1042 now: Instant,
1052 now: Instant,
1043) -> AnyElement {
1053) -> AnyElement {
1044 let own_mri = model.own_mri.clone().unwrap_or_default();
1054 let own_mri = model.own_mri.clone().unwrap_or_default();
1055 let element = plain_own_tile(state, model, size, now);
1056 if own_mri.is_empty() {
1057 return element;
1058 }
1059 with_tile_menu(app, model, &own_mri, "You", true, element)
1060}
1061
1062pub(super) fn plain_own_tile(
1063 state: &AppState,
1064 model: &CallModel,
1065 size: TileSize,
1066 now: Instant,
1067) -> AnyElement {
1068 let own_mri = model.own_mri.as_deref().unwrap_or_default();
1045 let extras = TileExtras {
1069 let extras = TileExtras {
1046 hand: model.own_hand.map(|rank| model.hand_position(rank)),
1070 hand: model.own_hand.map(|rank| model.hand_position(rank)),
1047 own: true,
1071 own: true,
1048 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
1072 reaction: model.own_chip(now).map(|chip| (chip.reaction, chip.serial)),
1049 spotlight: model.own_spotlight.is_some(),
1073 spotlight: model.own_spotlight.is_some(),
1050 pinned: model.is_pinned(&own_mri),
1074 pinned: model.is_pinned(own_mri),
1051 };
1075 };
1052 let element = own_tile_body(state, model, size, now, &extras);
1076 own_tile_body(state, model, size, now, &extras)
1053 if own_mri.is_empty() {
1054 return element;
1055 }
1056 with_tile_menu(app, model, &own_mri, "You", true, element)
1057}
1077}
1058
1078
1059fn own_tile_body(
1079fn own_tile_body(
crates/app/src/views/mod.rs +1 −0
@@ -18,6 +18,7 @@ pub mod call_mini_window;
18 18 pub mod call_organizer;
19 19 pub mod call_people;
20 20 pub mod call_pop_out;
21 pub mod call_share_gallery;
21 22 pub mod call_record;
22 23 pub mod call_stage;
23 24 pub mod call_transcript;
@@ -18,6 +18,7 @@ pub mod call_mini_window;
18pub mod call_organizer;
18pub mod call_organizer;
19pub mod call_people;
19pub mod call_people;
20pub mod call_pop_out;
20pub mod call_pop_out;
21pub mod call_share_gallery;
21pub mod call_record;
22pub mod call_record;
22pub mod call_stage;
23pub mod call_stage;
23pub mod call_transcript;
24pub mod call_transcript;