BlueGit

ict rusty-teams

feat(calls): sharing bar with red border, mini call window when minimized

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

metis Daniel Däschle · pushed by metis

Authored 2026-10-11 · 7 weeks ago

Hash
875bc8797b66b1c041e91d5c4ead2f66bac52bc7
Parent
ff739ffa
13 files changed +1115 −12
crates/app/src/call/mod.rs +3 −0
@@ -7,6 +7,8 @@ mod history;
7 7 mod join;
8 8 mod launcher;
9 9 mod model;
10 mod overlay;
11 mod overlay_layout;
10 12 mod pictures;
11 13 mod ring;
12 14 mod target;
@@ -17,6 +19,7 @@ pub use features::TransferCandidate;
17 19 pub use demo::DemoScene;
18 20 pub use history::{CallRow, call_rows};
19 21 pub use launcher::CallLauncher;
22 pub use overlay::CallWindows;
20 23 pub use model::{
21 24 ActiveCall, CAPTION_SHOWN, CHAT_OPEN_TILES, CallKind, CallModel, Focus, GridLayout, MAX_TILES, REACTION_SHOWN, Tile, TileSize, TileState,
22 25 grid_layout, tile_size,
@@ -7,6 +7,8 @@ mod history;
7mod join;
7mod join;
8mod launcher;
8mod launcher;
9mod model;
9mod model;
10mod overlay;
11mod overlay_layout;
10mod pictures;
12mod pictures;
11mod ring;
13mod ring;
12mod target;
14mod target;
@@ -17,6 +19,7 @@ pub use features::TransferCandidate;
17pub use demo::DemoScene;
19pub use demo::DemoScene;
18pub use history::{CallRow, call_rows};
20pub use history::{CallRow, call_rows};
19pub use launcher::CallLauncher;
21pub use launcher::CallLauncher;
22pub use overlay::CallWindows;
20pub use model::{
23pub use model::{
21 ActiveCall, CAPTION_SHOWN, CHAT_OPEN_TILES, CallKind, CallModel, Focus, GridLayout, MAX_TILES, REACTION_SHOWN, Tile, TileSize, TileState,
24 ActiveCall, CAPTION_SHOWN, CHAT_OPEN_TILES, CallKind, CallModel, Focus, GridLayout, MAX_TILES, REACTION_SHOWN, Tile, TileSize, TileState,
22 grid_layout, tile_size,
25 grid_layout, tile_size,
crates/app/src/call/overlay.rs added +354 −0
@@ -0,0 +1,354 @@
1 use std::collections::{HashMap, HashSet};
2 use std::time::{Duration, Instant};
3
4 use calling::{ShareKind, ShareSource};
5 use gpui_kit::*;
6
7 use super::model::format_elapsed;
8 use super::overlay_layout::{
9 MINI_POSITION_KEY, bar_collapsed, bar_rect, border_rects, border_thickness, format_position, mini_rect,
10 mini_wanted, parse_position,
11 };
12 use crate::app_state::AppState;
13 use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
14 use crate::views::call_mini_window::MiniWindowView;
15 use crate::views::share_bar::{ShareBarView, ShareBorderView};
16
17 const TICK: Duration = Duration::from_millis(100);
18 const SLOW_TICK_EVERY: u32 = 5;
19 const BORDER_SIDES: usize = 4;
20
21 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22 enum Role {
23 Bar,
24 Mini,
25 Border(usize),
26 }
27
28 struct Placed {
29 handle: AnyWindowHandle,
30 native: Option<NativeHandle>,
31 rect: Option<ScreenRect>,
32 }
33
34 impl Placed {
35 fn place(&mut self, rect: ScreenRect, cx: &mut App) {
36 self.rect = Some(rect);
37 let Some(native) = self.native else {
38 return;
39 };
40 platform::place(native, rect.left, rect.top, rect.width(), rect.height());
41 // WM_SIZE arrives while the app is borrowed, so GPUI drops its own resize report.
42 self.handle.update(cx, |_, window, cx| window.bounds_changed(cx)).ok();
43 }
44 }
45
46 struct ShareSession {
47 started: Instant,
48 source: Option<ShareSource>,
49 geometry: Option<ShareGeometry>,
50 }
51
52 pub struct CallWindows {
53 app: Entity<AppState>,
54 main_window: AnyWindowHandle,
55 main_native: Option<NativeHandle>,
56 work_area: Option<WorkArea>,
57 minimized: bool,
58 windows: HashMap<Role, Placed>,
59 opening: HashSet<Role>,
60 share: Option<ShareSession>,
61 pinned: bool,
62 bar_idle_since: Instant,
63 bar_collapsed: bool,
64 shown_second: u64,
65 mini_saved: Option<(i32, i32)>,
66 mini_seen: Option<(i32, i32)>,
67 ticks: u32,
68 }
69
70 fn display_work_area(cx: &App) -> Option<WorkArea> {
71 let bounds = cx.primary_display()?.bounds();
72 let left = f32::from(bounds.origin.x) as i32;
73 let top = f32::from(bounds.origin.y) as i32;
74 Some(WorkArea {
75 left,
76 top,
77 right: left + f32::from(bounds.size.width) as i32,
78 bottom: top + f32::from(bounds.size.height) as i32,
79 scale: 1.,
80 })
81 }
82
83 fn overlay_options(role: Role, rect: ScreenRect, scale: f32) -> WindowOptions {
84 let bounds = Bounds::new(
85 point(px(rect.left as f32 / scale), px(rect.top as f32 / scale)),
86 size(px(rect.width() as f32 / scale), px(rect.height() as f32 / scale)),
87 );
88 WindowOptions {
89 window_bounds: Some(WindowBounds::Windowed(bounds)),
90 titlebar: None,
91 focus: false,
92 show: true,
93 kind: WindowKind::PopUp,
94 is_movable: role == Role::Mini,
95 is_resizable: false,
96 is_minimizable: false,
97 window_background: match role {
98 Role::Border(_) => WindowBackgroundAppearance::Opaque,
99 Role::Bar | Role::Mini => WindowBackgroundAppearance::Transparent,
100 },
101 ..Default::default()
102 }
103 }
104
105 impl CallWindows {
106 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
107 let mini_saved = app
108 .read(cx)
109 .store
110 .meta(MINI_POSITION_KEY)
111 .ok()
112 .flatten()
113 .and_then(|text| parse_position(&text));
114 let windows = CallWindows {
115 app,
116 main_window: window.window_handle(),
117 main_native: platform::native_handle(window),
118 work_area: None,
119 minimized: false,
120 windows: HashMap::new(),
121 opening: HashSet::new(),
122 share: None,
123 pinned: false,
124 bar_idle_since: Instant::now(),
125 bar_collapsed: false,
126 shown_second: 0,
127 mini_saved,
128 mini_seen: None,
129 ticks: 0,
130 };
131 cx.spawn(async move |this, cx| {
132 loop {
133 cx.background_executor().timer(TICK).await;
134 if this.update(cx, |windows, cx| windows.tick(cx)).is_err() {
135 break;
136 }
137 }
138 })
139 .detach();
140 windows
141 }
142
143 pub fn app(&self) -> &Entity<AppState> {
144 &self.app
145 }
146
147 pub fn pinned(&self) -> bool {
148 self.pinned
149 }
150
151 pub fn bar_collapsed(&self) -> bool {
152 self.bar_collapsed
153 }
154
155 pub fn share_text(&self) -> String {
156 let Some(session) = &self.share else {
157 return String::new();
158 };
159 let what = match session.source.as_ref().map(|source| source.kind) {
160 Some(ShareKind::Window) => "window",
161 _ => "screen",
162 };
163 format!("Sharing {what} {}", format_elapsed(session.started.elapsed()))
164 }
165
166 pub fn toggle_pin(&mut self, cx: &mut Context<Self>) {
167 self.pinned = !self.pinned;
168 self.bar_idle_since = Instant::now();
169 cx.notify();
170 }
171
172 pub fn wake_bar(&mut self, cx: &mut Context<Self>) {
173 self.bar_idle_since = Instant::now();
174 if self.bar_collapsed {
175 self.bar_collapsed = false;
176 cx.notify();
177 }
178 }
179
180 pub fn return_to_call(&mut self, cx: &mut Context<Self>) {
181 if let Some(native) = self.main_native {
182 platform::restore_and_raise(native);
183 }
184 self.main_window.update(cx, |_, window, _| window.activate_window()).ok();
185 self.app.update(cx, |state, cx| state.show_call(true, cx));
186 }
187
188 fn tick(&mut self, cx: &mut Context<Self>) {
189 self.ticks = self.ticks.wrapping_add(1);
190 let slow = self.ticks % SLOW_TICK_EVERY == 0;
191 self.refresh_main_window();
192 self.sync_share(slow, cx);
193 self.sync_mini(cx);
194 if slow {
195 self.track_mini_position(cx);
196 }
197 }
198
199 fn refresh_main_window(&mut self) {
200 let Some(native) = self.main_native else {
201 return;
202 };
203 self.minimized = platform::window_minimized(native);
204 if !self.minimized {
205 self.work_area = platform::work_area(native).or(self.work_area);
206 }
207 }
208
209 fn local_share(&self, cx: &App) -> Option<Option<ShareSource>> {
210 let model = &self.app.read(cx).call.as_ref()?.model;
211 let label = model.local_share.as_ref()?;
212 Some(model.share_sources.iter().find(|source| &source.label() == label).cloned())
213 }
214
215 fn sync_share(&mut self, refresh_geometry: bool, cx: &mut Context<Self>) {
216 let Some(source) = self.local_share(cx) else {
217 self.end_share(cx);
218 return;
219 };
220 let mut refresh_geometry = refresh_geometry;
221 if self.share.is_none() {
222 self.bar_idle_since = Instant::now();
223 self.share = Some(ShareSession { started: Instant::now(), source: None, geometry: None });
224 refresh_geometry = true;
225 }
226 let Some(session) = self.share.as_mut() else {
227 return;
228 };
229 session.source = source;
230 if refresh_geometry {
231 session.geometry = session.source.as_ref().and_then(|source| platform::share_geometry(source.kind, source.id));
232 }
233 let geometry = session.geometry;
234 let elapsed_seconds = session.started.elapsed().as_secs();
235 let Some(work) = geometry.map(|geometry| geometry.work).or(self.work_area).or_else(|| display_work_area(cx)) else {
236 return;
237 };
238 let can_collapse = self.windows.get(&Role::Bar).is_some_and(|placed| placed.native.is_some());
239 let collapsed = can_collapse && bar_collapsed(self.pinned, self.bar_idle_since.elapsed());
240 if collapsed != self.bar_collapsed || elapsed_seconds != self.shown_second {
241 self.bar_collapsed = collapsed;
242 self.shown_second = elapsed_seconds;
243 cx.notify();
244 }
245 self.ensure_window(Role::Bar, bar_rect(work, collapsed), work.scale, true, cx);
246 match geometry {
247 Some(geometry) => {
248 let thickness = border_thickness(geometry.work.scale);
249 for (side, rect) in border_rects(geometry.target, thickness).into_iter().enumerate() {
250 self.ensure_window(Role::Border(side), rect, geometry.work.scale, true, cx);
251 }
252 }
253 None => self.close_borders(cx),
254 }
255 }
256
257 fn end_share(&mut self, cx: &mut Context<Self>) {
258 if self.share.take().is_none() {
259 return;
260 }
261 self.bar_collapsed = false;
262 self.close(Role::Bar, cx);
263 self.close_borders(cx);
264 }
265
266 fn close_borders(&mut self, cx: &mut Context<Self>) {
267 for side in 0..BORDER_SIDES {
268 self.close(Role::Border(side), cx);
269 }
270 }
271
272 fn sync_mini(&mut self, cx: &mut Context<Self>) {
273 let in_call = self.app.read(cx).call.is_some();
274 let work = self.work_area.or_else(|| display_work_area(cx));
275 match work.filter(|_| mini_wanted(in_call, self.minimized)) {
276 Some(work) => {
277 let rect = mini_rect(work, self.mini_saved);
278 self.ensure_window(Role::Mini, rect, work.scale, false, cx);
279 }
280 None => self.close(Role::Mini, cx),
281 }
282 }
283
284 fn track_mini_position(&mut self, cx: &mut Context<Self>) {
285 let Some(native) = self.windows.get(&Role::Mini).and_then(|placed| placed.native) else {
286 return;
287 };
288 let Some(rect) = platform::window_rect(native) else {
289 return;
290 };
291 let position = (rect.left, rect.top);
292 let settled = self.mini_seen == Some(position);
293 self.mini_seen = Some(position);
294 if settled && self.mini_saved != Some(position) {
295 self.mini_saved = Some(position);
296 let _ = self.app.read(cx).store.set_meta(MINI_POSITION_KEY, &format_position(position.0, position.1));
297 }
298 }
299
300 fn ensure_window(&mut self, role: Role, rect: ScreenRect, scale: f32, follow: bool, cx: &mut Context<Self>) {
301 match self.windows.get_mut(&role) {
302 Some(placed) => {
303 if placed.rect.is_none() || follow && placed.rect != Some(rect) {
304 placed.place(rect, cx);
305 }
306 }
307 None => self.open(role, rect, scale, cx),
308 }
309 }
310
311 fn close(&mut self, role: Role, cx: &mut Context<Self>) {
312 if let Some(placed) = self.windows.remove(&role) {
313 placed.handle.update(cx, |_, window, _| window.remove_window()).ok();
314 }
315 }
316
317 fn open(&mut self, role: Role, rect: ScreenRect, scale: f32, cx: &mut Context<Self>) {
318 if !self.opening.insert(role) {
319 return;
320 }
321 let controller = cx.entity();
322 let options = overlay_options(role, rect, scale);
323 // open_window draws right away, and the views read this entity while rendering.
324 cx.defer(move |cx| {
325 let view_controller = controller.clone();
326 let opened = cx.open_window(options, move |window, cx| {
327 let view: AnyView = match role {
328 Role::Bar => cx.new(|cx| ShareBarView::new(view_controller, cx)).into(),
329 Role::Mini => cx.new(|cx| MiniWindowView::new(view_controller, cx)).into(),
330 Role::Border(_) => cx.new(|_| ShareBorderView).into(),
331 };
332 cx.new(|cx| base::Root::new(view, window, cx).bg(transparent_black()))
333 });
334 let placed = opened.ok().map(|handle| {
335 let handle = AnyWindowHandle::from(handle);
336 let native = handle.update(cx, |_, window, _| platform::native_handle(window)).ok().flatten();
337 if let Some(native) = native {
338 platform::prepare_toast_window(native);
339 platform::exclude_from_capture(native);
340 if matches!(role, Role::Border(_)) {
341 platform::make_click_through(native);
342 }
343 }
344 Placed { handle, native, rect: None }
345 });
346 controller.update(cx, |this, _| {
347 this.opening.remove(&role);
348 if let Some(placed) = placed {
349 this.windows.insert(role, placed);
350 }
351 });
352 });
353 }
354 }
@@ -0,0 +1,354 @@
1use std::collections::{HashMap, HashSet};
2use std::time::{Duration, Instant};
3
4use calling::{ShareKind, ShareSource};
5use gpui_kit::*;
6
7use super::model::format_elapsed;
8use super::overlay_layout::{
9 MINI_POSITION_KEY, bar_collapsed, bar_rect, border_rects, border_thickness, format_position, mini_rect,
10 mini_wanted, parse_position,
11};
12use crate::app_state::AppState;
13use crate::notify::platform::{self, NativeHandle, ScreenRect, ShareGeometry, WorkArea};
14use crate::views::call_mini_window::MiniWindowView;
15use crate::views::share_bar::{ShareBarView, ShareBorderView};
16
17const TICK: Duration = Duration::from_millis(100);
18const SLOW_TICK_EVERY: u32 = 5;
19const BORDER_SIDES: usize = 4;
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22enum Role {
23 Bar,
24 Mini,
25 Border(usize),
26}
27
28struct Placed {
29 handle: AnyWindowHandle,
30 native: Option<NativeHandle>,
31 rect: Option<ScreenRect>,
32}
33
34impl Placed {
35 fn place(&mut self, rect: ScreenRect, cx: &mut App) {
36 self.rect = Some(rect);
37 let Some(native) = self.native else {
38 return;
39 };
40 platform::place(native, rect.left, rect.top, rect.width(), rect.height());
41 // WM_SIZE arrives while the app is borrowed, so GPUI drops its own resize report.
42 self.handle.update(cx, |_, window, cx| window.bounds_changed(cx)).ok();
43 }
44}
45
46struct ShareSession {
47 started: Instant,
48 source: Option<ShareSource>,
49 geometry: Option<ShareGeometry>,
50}
51
52pub struct CallWindows {
53 app: Entity<AppState>,
54 main_window: AnyWindowHandle,
55 main_native: Option<NativeHandle>,
56 work_area: Option<WorkArea>,
57 minimized: bool,
58 windows: HashMap<Role, Placed>,
59 opening: HashSet<Role>,
60 share: Option<ShareSession>,
61 pinned: bool,
62 bar_idle_since: Instant,
63 bar_collapsed: bool,
64 shown_second: u64,
65 mini_saved: Option<(i32, i32)>,
66 mini_seen: Option<(i32, i32)>,
67 ticks: u32,
68}
69
70fn display_work_area(cx: &App) -> Option<WorkArea> {
71 let bounds = cx.primary_display()?.bounds();
72 let left = f32::from(bounds.origin.x) as i32;
73 let top = f32::from(bounds.origin.y) as i32;
74 Some(WorkArea {
75 left,
76 top,
77 right: left + f32::from(bounds.size.width) as i32,
78 bottom: top + f32::from(bounds.size.height) as i32,
79 scale: 1.,
80 })
81}
82
83fn overlay_options(role: Role, rect: ScreenRect, scale: f32) -> WindowOptions {
84 let bounds = Bounds::new(
85 point(px(rect.left as f32 / scale), px(rect.top as f32 / scale)),
86 size(px(rect.width() as f32 / scale), px(rect.height() as f32 / scale)),
87 );
88 WindowOptions {
89 window_bounds: Some(WindowBounds::Windowed(bounds)),
90 titlebar: None,
91 focus: false,
92 show: true,
93 kind: WindowKind::PopUp,
94 is_movable: role == Role::Mini,
95 is_resizable: false,
96 is_minimizable: false,
97 window_background: match role {
98 Role::Border(_) => WindowBackgroundAppearance::Opaque,
99 Role::Bar | Role::Mini => WindowBackgroundAppearance::Transparent,
100 },
101 ..Default::default()
102 }
103}
104
105impl CallWindows {
106 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
107 let mini_saved = app
108 .read(cx)
109 .store
110 .meta(MINI_POSITION_KEY)
111 .ok()
112 .flatten()
113 .and_then(|text| parse_position(&text));
114 let windows = CallWindows {
115 app,
116 main_window: window.window_handle(),
117 main_native: platform::native_handle(window),
118 work_area: None,
119 minimized: false,
120 windows: HashMap::new(),
121 opening: HashSet::new(),
122 share: None,
123 pinned: false,
124 bar_idle_since: Instant::now(),
125 bar_collapsed: false,
126 shown_second: 0,
127 mini_saved,
128 mini_seen: None,
129 ticks: 0,
130 };
131 cx.spawn(async move |this, cx| {
132 loop {
133 cx.background_executor().timer(TICK).await;
134 if this.update(cx, |windows, cx| windows.tick(cx)).is_err() {
135 break;
136 }
137 }
138 })
139 .detach();
140 windows
141 }
142
143 pub fn app(&self) -> &Entity<AppState> {
144 &self.app
145 }
146
147 pub fn pinned(&self) -> bool {
148 self.pinned
149 }
150
151 pub fn bar_collapsed(&self) -> bool {
152 self.bar_collapsed
153 }
154
155 pub fn share_text(&self) -> String {
156 let Some(session) = &self.share else {
157 return String::new();
158 };
159 let what = match session.source.as_ref().map(|source| source.kind) {
160 Some(ShareKind::Window) => "window",
161 _ => "screen",
162 };
163 format!("Sharing {what} {}", format_elapsed(session.started.elapsed()))
164 }
165
166 pub fn toggle_pin(&mut self, cx: &mut Context<Self>) {
167 self.pinned = !self.pinned;
168 self.bar_idle_since = Instant::now();
169 cx.notify();
170 }
171
172 pub fn wake_bar(&mut self, cx: &mut Context<Self>) {
173 self.bar_idle_since = Instant::now();
174 if self.bar_collapsed {
175 self.bar_collapsed = false;
176 cx.notify();
177 }
178 }
179
180 pub fn return_to_call(&mut self, cx: &mut Context<Self>) {
181 if let Some(native) = self.main_native {
182 platform::restore_and_raise(native);
183 }
184 self.main_window.update(cx, |_, window, _| window.activate_window()).ok();
185 self.app.update(cx, |state, cx| state.show_call(true, cx));
186 }
187
188 fn tick(&mut self, cx: &mut Context<Self>) {
189 self.ticks = self.ticks.wrapping_add(1);
190 let slow = self.ticks % SLOW_TICK_EVERY == 0;
191 self.refresh_main_window();
192 self.sync_share(slow, cx);
193 self.sync_mini(cx);
194 if slow {
195 self.track_mini_position(cx);
196 }
197 }
198
199 fn refresh_main_window(&mut self) {
200 let Some(native) = self.main_native else {
201 return;
202 };
203 self.minimized = platform::window_minimized(native);
204 if !self.minimized {
205 self.work_area = platform::work_area(native).or(self.work_area);
206 }
207 }
208
209 fn local_share(&self, cx: &App) -> Option<Option<ShareSource>> {
210 let model = &self.app.read(cx).call.as_ref()?.model;
211 let label = model.local_share.as_ref()?;
212 Some(model.share_sources.iter().find(|source| &source.label() == label).cloned())
213 }
214
215 fn sync_share(&mut self, refresh_geometry: bool, cx: &mut Context<Self>) {
216 let Some(source) = self.local_share(cx) else {
217 self.end_share(cx);
218 return;
219 };
220 let mut refresh_geometry = refresh_geometry;
221 if self.share.is_none() {
222 self.bar_idle_since = Instant::now();
223 self.share = Some(ShareSession { started: Instant::now(), source: None, geometry: None });
224 refresh_geometry = true;
225 }
226 let Some(session) = self.share.as_mut() else {
227 return;
228 };
229 session.source = source;
230 if refresh_geometry {
231 session.geometry = session.source.as_ref().and_then(|source| platform::share_geometry(source.kind, source.id));
232 }
233 let geometry = session.geometry;
234 let elapsed_seconds = session.started.elapsed().as_secs();
235 let Some(work) = geometry.map(|geometry| geometry.work).or(self.work_area).or_else(|| display_work_area(cx)) else {
236 return;
237 };
238 let can_collapse = self.windows.get(&Role::Bar).is_some_and(|placed| placed.native.is_some());
239 let collapsed = can_collapse && bar_collapsed(self.pinned, self.bar_idle_since.elapsed());
240 if collapsed != self.bar_collapsed || elapsed_seconds != self.shown_second {
241 self.bar_collapsed = collapsed;
242 self.shown_second = elapsed_seconds;
243 cx.notify();
244 }
245 self.ensure_window(Role::Bar, bar_rect(work, collapsed), work.scale, true, cx);
246 match geometry {
247 Some(geometry) => {
248 let thickness = border_thickness(geometry.work.scale);
249 for (side, rect) in border_rects(geometry.target, thickness).into_iter().enumerate() {
250 self.ensure_window(Role::Border(side), rect, geometry.work.scale, true, cx);
251 }
252 }
253 None => self.close_borders(cx),
254 }
255 }
256
257 fn end_share(&mut self, cx: &mut Context<Self>) {
258 if self.share.take().is_none() {
259 return;
260 }
261 self.bar_collapsed = false;
262 self.close(Role::Bar, cx);
263 self.close_borders(cx);
264 }
265
266 fn close_borders(&mut self, cx: &mut Context<Self>) {
267 for side in 0..BORDER_SIDES {
268 self.close(Role::Border(side), cx);
269 }
270 }
271
272 fn sync_mini(&mut self, cx: &mut Context<Self>) {
273 let in_call = self.app.read(cx).call.is_some();
274 let work = self.work_area.or_else(|| display_work_area(cx));
275 match work.filter(|_| mini_wanted(in_call, self.minimized)) {
276 Some(work) => {
277 let rect = mini_rect(work, self.mini_saved);
278 self.ensure_window(Role::Mini, rect, work.scale, false, cx);
279 }
280 None => self.close(Role::Mini, cx),
281 }
282 }
283
284 fn track_mini_position(&mut self, cx: &mut Context<Self>) {
285 let Some(native) = self.windows.get(&Role::Mini).and_then(|placed| placed.native) else {
286 return;
287 };
288 let Some(rect) = platform::window_rect(native) else {
289 return;
290 };
291 let position = (rect.left, rect.top);
292 let settled = self.mini_seen == Some(position);
293 self.mini_seen = Some(position);
294 if settled && self.mini_saved != Some(position) {
295 self.mini_saved = Some(position);
296 let _ = self.app.read(cx).store.set_meta(MINI_POSITION_KEY, &format_position(position.0, position.1));
297 }
298 }
299
300 fn ensure_window(&mut self, role: Role, rect: ScreenRect, scale: f32, follow: bool, cx: &mut Context<Self>) {
301 match self.windows.get_mut(&role) {
302 Some(placed) => {
303 if placed.rect.is_none() || follow && placed.rect != Some(rect) {
304 placed.place(rect, cx);
305 }
306 }
307 None => self.open(role, rect, scale, cx),
308 }
309 }
310
311 fn close(&mut self, role: Role, cx: &mut Context<Self>) {
312 if let Some(placed) = self.windows.remove(&role) {
313 placed.handle.update(cx, |_, window, _| window.remove_window()).ok();
314 }
315 }
316
317 fn open(&mut self, role: Role, rect: ScreenRect, scale: f32, cx: &mut Context<Self>) {
318 if !self.opening.insert(role) {
319 return;
320 }
321 let controller = cx.entity();
322 let options = overlay_options(role, rect, scale);
323 // open_window draws right away, and the views read this entity while rendering.
324 cx.defer(move |cx| {
325 let view_controller = controller.clone();
326 let opened = cx.open_window(options, move |window, cx| {
327 let view: AnyView = match role {
328 Role::Bar => cx.new(|cx| ShareBarView::new(view_controller, cx)).into(),
329 Role::Mini => cx.new(|cx| MiniWindowView::new(view_controller, cx)).into(),
330 Role::Border(_) => cx.new(|_| ShareBorderView).into(),
331 };
332 cx.new(|cx| base::Root::new(view, window, cx).bg(transparent_black()))
333 });
334 let placed = opened.ok().map(|handle| {
335 let handle = AnyWindowHandle::from(handle);
336 let native = handle.update(cx, |_, window, _| platform::native_handle(window)).ok().flatten();
337 if let Some(native) = native {
338 platform::prepare_toast_window(native);
339 platform::exclude_from_capture(native);
340 if matches!(role, Role::Border(_)) {
341 platform::make_click_through(native);
342 }
343 }
344 Placed { handle, native, rect: None }
345 });
346 controller.update(cx, |this, _| {
347 this.opening.remove(&role);
348 if let Some(placed) = placed {
349 this.windows.insert(role, placed);
350 }
351 });
352 });
353 }
354}
crates/app/src/call/overlay_layout.rs added +179 −0
@@ -0,0 +1,179 @@
1 use std::time::Duration;
2
3 use crate::notify::platform::{ScreenRect, WorkArea};
4
5 pub const BAR_WIDTH: f32 = 380.;
6 pub const BAR_HEIGHT: f32 = 40.;
7 pub const HANDLE_WIDTH: f32 = 120.;
8 pub const HANDLE_HEIGHT: f32 = 6.;
9 pub const BORDER_THICKNESS: f32 = 4.;
10 pub const MINI_WIDTH: f32 = 320.;
11 pub const MINI_HEIGHT: f32 = 180.;
12 pub const MINI_MARGIN: f32 = 16.;
13 pub const BAR_IDLE_BEFORE_COLLAPSE: Duration = Duration::from_secs(3);
14 pub const MINI_POSITION_KEY: &str = "call_mini_position";
15
16 fn scaled(logical: f32, scale: f32) -> i32 {
17 (logical * scale).round() as i32
18 }
19
20 pub fn border_thickness(scale: f32) -> i32 {
21 scaled(BORDER_THICKNESS, scale).max(1)
22 }
23
24 pub fn bar_rect(work: WorkArea, collapsed: bool) -> ScreenRect {
25 let (width, height) = if collapsed {
26 (HANDLE_WIDTH, HANDLE_HEIGHT)
27 } else {
28 (BAR_WIDTH, BAR_HEIGHT)
29 };
30 let width = scaled(width, work.scale);
31 let left = work.left + ((work.right - work.left) - width) / 2;
32 ScreenRect {
33 left,
34 top: work.top,
35 right: left + width,
36 bottom: work.top + scaled(height, work.scale),
37 }
38 }
39
40 pub fn bar_collapsed(pinned: bool, idle: Duration) -> bool {
41 !pinned && idle >= BAR_IDLE_BEFORE_COLLAPSE
42 }
43
44 pub fn border_rects(target: ScreenRect, thickness: i32) -> [ScreenRect; 4] {
45 let thickness = thickness.clamp(1, (target.width().min(target.height()) / 2).max(1));
46 let ScreenRect { left, top, right, bottom } = target;
47 [
48 ScreenRect { left, top, right, bottom: top + thickness },
49 ScreenRect { left, top: bottom - thickness, right, bottom },
50 ScreenRect { left, top: top + thickness, right: left + thickness, bottom: bottom - thickness },
51 ScreenRect { left: right - thickness, top: top + thickness, right, bottom: bottom - thickness },
52 ]
53 }
54
55 pub fn mini_rect(work: WorkArea, saved: Option<(i32, i32)>) -> ScreenRect {
56 let width = scaled(MINI_WIDTH, work.scale);
57 let height = scaled(MINI_HEIGHT, work.scale);
58 let margin = scaled(MINI_MARGIN, work.scale);
59 let (left, top) = saved.unwrap_or((work.right - width - margin, work.bottom - height - margin));
60 let left = left.clamp(work.left, (work.right - width).max(work.left));
61 let top = top.clamp(work.top, (work.bottom - height).max(work.top));
62 ScreenRect {
63 left,
64 top,
65 right: left + width,
66 bottom: top + height,
67 }
68 }
69
70 pub fn mini_wanted(call_active: bool, main_minimized: bool) -> bool {
71 call_active && main_minimized
72 }
73
74 pub fn parse_position(text: &str) -> Option<(i32, i32)> {
75 let (left, top) = text.split_once(',')?;
76 Some((left.trim().parse().ok()?, top.trim().parse().ok()?))
77 }
78
79 pub fn format_position(left: i32, top: i32) -> String {
80 format!("{left},{top}")
81 }
82
83 #[cfg(test)]
84 mod tests {
85 use super::*;
86
87 fn work(scale: f32) -> WorkArea {
88 WorkArea { left: 0, top: 0, right: 1920, bottom: 1040, scale }
89 }
90
91 #[test]
92 fn bar_is_centred_at_the_top() {
93 let rect = bar_rect(work(1.), false);
94 assert_eq!((rect.left, rect.top, rect.right, rect.bottom), (770, 0, 1150, 40));
95 }
96
97 #[test]
98 fn bar_follows_a_secondary_monitor_and_scale() {
99 let second = WorkArea { left: 1920, top: 100, right: 3840, bottom: 1140, scale: 1.5 };
100 let rect = bar_rect(second, false);
101 assert_eq!(rect.width(), 570);
102 assert_eq!(rect.height(), 60);
103 assert_eq!(rect.top, 100);
104 assert_eq!(rect.left, 1920 + (1920 - 570) / 2);
105 }
106
107 #[test]
108 fn collapsed_bar_is_a_thin_handle() {
109 let rect = bar_rect(work(1.), true);
110 assert_eq!((rect.width(), rect.height(), rect.top), (120, 6, 0));
111 }
112
113 #[test]
114 fn bar_collapses_only_when_unpinned_and_idle() {
115 assert!(!bar_collapsed(false, Duration::from_secs(2)));
116 assert!(bar_collapsed(false, Duration::from_secs(3)));
117 assert!(!bar_collapsed(true, Duration::from_secs(60)));
118 }
119
120 #[test]
121 fn border_thickness_scales_but_stays_visible() {
122 assert_eq!(border_thickness(1.), 4);
123 assert_eq!(border_thickness(2.), 8);
124 assert_eq!(border_thickness(0.01), 1);
125 }
126
127 #[test]
128 fn border_rects_frame_the_target_without_overlap() {
129 let target = ScreenRect { left: 100, top: 50, right: 500, bottom: 350 };
130 let [top, bottom, left, right] = border_rects(target, 4);
131 assert_eq!((top.left, top.top, top.right, top.bottom), (100, 50, 500, 54));
132 assert_eq!((bottom.top, bottom.bottom), (346, 350));
133 assert_eq!((left.left, left.right, left.top, left.bottom), (100, 104, 54, 346));
134 assert_eq!((right.left, right.right), (496, 500));
135 }
136
137 #[test]
138 fn border_thickness_never_exceeds_half_the_target() {
139 let target = ScreenRect { left: 0, top: 0, right: 6, bottom: 100 };
140 let [top, _, left, right] = border_rects(target, 4);
141 assert_eq!(top.bottom, 3);
142 assert_eq!(left.right, 3);
143 assert_eq!(right.left, 3);
144 }
145
146 #[test]
147 fn mini_defaults_to_the_bottom_right_corner() {
148 let rect = mini_rect(work(1.), None);
149 assert_eq!((rect.left, rect.top, rect.right, rect.bottom), (1584, 844, 1904, 1024));
150 }
151
152 #[test]
153 fn mini_keeps_a_saved_position_inside_the_work_area() {
154 assert_eq!(mini_rect(work(1.), Some((300, 200))).left, 300);
155 let pushed = mini_rect(work(1.), Some((5000, -40)));
156 assert_eq!((pushed.right, pushed.top), (1920, 0));
157 let pulled = mini_rect(work(1.), Some((-500, 5000)));
158 assert_eq!((pulled.left, pulled.bottom), (0, 1040));
159 }
160
161 #[test]
162 fn mini_scales_with_the_monitor() {
163 let rect = mini_rect(work(2.), None);
164 assert_eq!((rect.width(), rect.height()), (640, 360));
165 }
166
167 #[test]
168 fn mini_shows_only_in_a_call_with_the_main_window_minimized() {
169 assert!(mini_wanted(true, true));
170 assert!(!mini_wanted(true, false));
171 assert!(!mini_wanted(false, true));
172 }
173
174 #[test]
175 fn position_round_trips() {
176 assert_eq!(parse_position(&format_position(-1200, 80)), Some((-1200, 80)));
177 assert_eq!(parse_position("garbage"), None);
178 }
179 }
@@ -0,0 +1,179 @@
1use std::time::Duration;
2
3use crate::notify::platform::{ScreenRect, WorkArea};
4
5pub const BAR_WIDTH: f32 = 380.;
6pub const BAR_HEIGHT: f32 = 40.;
7pub const HANDLE_WIDTH: f32 = 120.;
8pub const HANDLE_HEIGHT: f32 = 6.;
9pub const BORDER_THICKNESS: f32 = 4.;
10pub const MINI_WIDTH: f32 = 320.;
11pub const MINI_HEIGHT: f32 = 180.;
12pub const MINI_MARGIN: f32 = 16.;
13pub const BAR_IDLE_BEFORE_COLLAPSE: Duration = Duration::from_secs(3);
14pub const MINI_POSITION_KEY: &str = "call_mini_position";
15
16fn scaled(logical: f32, scale: f32) -> i32 {
17 (logical * scale).round() as i32
18}
19
20pub fn border_thickness(scale: f32) -> i32 {
21 scaled(BORDER_THICKNESS, scale).max(1)
22}
23
24pub fn bar_rect(work: WorkArea, collapsed: bool) -> ScreenRect {
25 let (width, height) = if collapsed {
26 (HANDLE_WIDTH, HANDLE_HEIGHT)
27 } else {
28 (BAR_WIDTH, BAR_HEIGHT)
29 };
30 let width = scaled(width, work.scale);
31 let left = work.left + ((work.right - work.left) - width) / 2;
32 ScreenRect {
33 left,
34 top: work.top,
35 right: left + width,
36 bottom: work.top + scaled(height, work.scale),
37 }
38}
39
40pub fn bar_collapsed(pinned: bool, idle: Duration) -> bool {
41 !pinned && idle >= BAR_IDLE_BEFORE_COLLAPSE
42}
43
44pub fn border_rects(target: ScreenRect, thickness: i32) -> [ScreenRect; 4] {
45 let thickness = thickness.clamp(1, (target.width().min(target.height()) / 2).max(1));
46 let ScreenRect { left, top, right, bottom } = target;
47 [
48 ScreenRect { left, top, right, bottom: top + thickness },
49 ScreenRect { left, top: bottom - thickness, right, bottom },
50 ScreenRect { left, top: top + thickness, right: left + thickness, bottom: bottom - thickness },
51 ScreenRect { left: right - thickness, top: top + thickness, right, bottom: bottom - thickness },
52 ]
53}
54
55pub fn mini_rect(work: WorkArea, saved: Option<(i32, i32)>) -> ScreenRect {
56 let width = scaled(MINI_WIDTH, work.scale);
57 let height = scaled(MINI_HEIGHT, work.scale);
58 let margin = scaled(MINI_MARGIN, work.scale);
59 let (left, top) = saved.unwrap_or((work.right - width - margin, work.bottom - height - margin));
60 let left = left.clamp(work.left, (work.right - width).max(work.left));
61 let top = top.clamp(work.top, (work.bottom - height).max(work.top));
62 ScreenRect {
63 left,
64 top,
65 right: left + width,
66 bottom: top + height,
67 }
68}
69
70pub fn mini_wanted(call_active: bool, main_minimized: bool) -> bool {
71 call_active && main_minimized
72}
73
74pub fn parse_position(text: &str) -> Option<(i32, i32)> {
75 let (left, top) = text.split_once(',')?;
76 Some((left.trim().parse().ok()?, top.trim().parse().ok()?))
77}
78
79pub fn format_position(left: i32, top: i32) -> String {
80 format!("{left},{top}")
81}
82
83#[cfg(test)]
84mod tests {
85 use super::*;
86
87 fn work(scale: f32) -> WorkArea {
88 WorkArea { left: 0, top: 0, right: 1920, bottom: 1040, scale }
89 }
90
91 #[test]
92 fn bar_is_centred_at_the_top() {
93 let rect = bar_rect(work(1.), false);
94 assert_eq!((rect.left, rect.top, rect.right, rect.bottom), (770, 0, 1150, 40));
95 }
96
97 #[test]
98 fn bar_follows_a_secondary_monitor_and_scale() {
99 let second = WorkArea { left: 1920, top: 100, right: 3840, bottom: 1140, scale: 1.5 };
100 let rect = bar_rect(second, false);
101 assert_eq!(rect.width(), 570);
102 assert_eq!(rect.height(), 60);
103 assert_eq!(rect.top, 100);
104 assert_eq!(rect.left, 1920 + (1920 - 570) / 2);
105 }
106
107 #[test]
108 fn collapsed_bar_is_a_thin_handle() {
109 let rect = bar_rect(work(1.), true);
110 assert_eq!((rect.width(), rect.height(), rect.top), (120, 6, 0));
111 }
112
113 #[test]
114 fn bar_collapses_only_when_unpinned_and_idle() {
115 assert!(!bar_collapsed(false, Duration::from_secs(2)));
116 assert!(bar_collapsed(false, Duration::from_secs(3)));
117 assert!(!bar_collapsed(true, Duration::from_secs(60)));
118 }
119
120 #[test]
121 fn border_thickness_scales_but_stays_visible() {
122 assert_eq!(border_thickness(1.), 4);
123 assert_eq!(border_thickness(2.), 8);
124 assert_eq!(border_thickness(0.01), 1);
125 }
126
127 #[test]
128 fn border_rects_frame_the_target_without_overlap() {
129 let target = ScreenRect { left: 100, top: 50, right: 500, bottom: 350 };
130 let [top, bottom, left, right] = border_rects(target, 4);
131 assert_eq!((top.left, top.top, top.right, top.bottom), (100, 50, 500, 54));
132 assert_eq!((bottom.top, bottom.bottom), (346, 350));
133 assert_eq!((left.left, left.right, left.top, left.bottom), (100, 104, 54, 346));
134 assert_eq!((right.left, right.right), (496, 500));
135 }
136
137 #[test]
138 fn border_thickness_never_exceeds_half_the_target() {
139 let target = ScreenRect { left: 0, top: 0, right: 6, bottom: 100 };
140 let [top, _, left, right] = border_rects(target, 4);
141 assert_eq!(top.bottom, 3);
142 assert_eq!(left.right, 3);
143 assert_eq!(right.left, 3);
144 }
145
146 #[test]
147 fn mini_defaults_to_the_bottom_right_corner() {
148 let rect = mini_rect(work(1.), None);
149 assert_eq!((rect.left, rect.top, rect.right, rect.bottom), (1584, 844, 1904, 1024));
150 }
151
152 #[test]
153 fn mini_keeps_a_saved_position_inside_the_work_area() {
154 assert_eq!(mini_rect(work(1.), Some((300, 200))).left, 300);
155 let pushed = mini_rect(work(1.), Some((5000, -40)));
156 assert_eq!((pushed.right, pushed.top), (1920, 0));
157 let pulled = mini_rect(work(1.), Some((-500, 5000)));
158 assert_eq!((pulled.left, pulled.bottom), (0, 1040));
159 }
160
161 #[test]
162 fn mini_scales_with_the_monitor() {
163 let rect = mini_rect(work(2.), None);
164 assert_eq!((rect.width(), rect.height()), (640, 360));
165 }
166
167 #[test]
168 fn mini_shows_only_in_a_call_with_the_main_window_minimized() {
169 assert!(mini_wanted(true, true));
170 assert!(!mini_wanted(true, false));
171 assert!(!mini_wanted(false, true));
172 }
173
174 #[test]
175 fn position_round_trips() {
176 assert_eq!(parse_position(&format_position(-1200, 80)), Some((-1200, 80)));
177 assert_eq!(parse_position("garbage"), None);
178 }
179}
crates/app/src/notify/mod.rs +1 −1
@@ -4,7 +4,7 @@ mod center;
4 4 mod incoming;
5 5 mod layout;
6 6 #[cfg_attr(not(windows), allow(dead_code))]
7 mod platform;
7 pub(crate) mod platform;
8 8 #[cfg_attr(not(windows), allow(dead_code))]
9 9 mod ring_tone;
10 10 mod ring_view;
@@ -4,7 +4,7 @@ mod center;
4mod incoming;
4mod incoming;
5mod layout;
5mod layout;
6#[cfg_attr(not(windows), allow(dead_code))]
6#[cfg_attr(not(windows), allow(dead_code))]
7mod platform;
7pub(crate) mod platform;
8#[cfg_attr(not(windows), allow(dead_code))]
8#[cfg_attr(not(windows), allow(dead_code))]
9mod ring_tone;
9mod ring_tone;
10mod ring_view;
10mod ring_view;
crates/app/src/notify/platform/mod.rs +24 −0
@@ -19,6 +19,30 @@ pub struct WorkArea {
19 19 pub scale: f32,
20 20 }
21 21
22 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
23 pub struct ScreenRect {
24 pub left: i32,
25 pub top: i32,
26 pub right: i32,
27 pub bottom: i32,
28 }
29
30 impl ScreenRect {
31 pub fn width(&self) -> i32 {
32 self.right - self.left
33 }
34
35 pub fn height(&self) -> i32 {
36 self.bottom - self.top
37 }
38 }
39
40 #[derive(Debug, Clone, Copy, PartialEq)]
41 pub struct ShareGeometry {
42 pub target: ScreenRect,
43 pub work: WorkArea,
44 }
45
22 46 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
23 47 pub enum TrayCommand {
24 48 Toggle,
@@ -19,6 +19,30 @@ pub struct WorkArea {
19 pub scale: f32,
19 pub scale: f32,
20}
20}
21
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub struct ScreenRect {
24 pub left: i32,
25 pub top: i32,
26 pub right: i32,
27 pub bottom: i32,
28}
29
30impl ScreenRect {
31 pub fn width(&self) -> i32 {
32 self.right - self.left
33 }
34
35 pub fn height(&self) -> i32 {
36 self.bottom - self.top
37 }
38}
39
40#[derive(Debug, Clone, Copy, PartialEq)]
41pub struct ShareGeometry {
42 pub target: ScreenRect,
43 pub work: WorkArea,
44}
45
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum TrayCommand {
47pub enum TrayCommand {
24 Toggle,
48 Toggle,
crates/app/src/notify/platform/stub.rs +19 −1
@@ -1,6 +1,8 @@
1 1 use gpui_kit::Window;
2 2
3 use super::{NativeHandle, TrayCommand, WorkArea};
3 use calling::ShareKind;
4
5 use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
4 6 use crate::notify::badge::Badge;
5 7
6 8 pub fn native_handle(_window: &Window) -> Option<NativeHandle> {
@@ -17,6 +19,22 @@ pub fn work_area(_handle: NativeHandle) -> Option<WorkArea> {
17 19
18 20 pub fn place(_handle: NativeHandle, _x: i32, _y: i32, _width: i32, _height: i32) {}
19 21
22 pub fn exclude_from_capture(_handle: NativeHandle) {}
23
24 pub fn make_click_through(_handle: NativeHandle) {}
25
26 pub fn window_minimized(_handle: NativeHandle) -> bool {
27 false
28 }
29
30 pub fn window_rect(_handle: NativeHandle) -> Option<ScreenRect> {
31 None
32 }
33
34 pub fn share_geometry(_kind: ShareKind, _id: u64) -> Option<ShareGeometry> {
35 None
36 }
37
20 38 pub fn system_quiet() -> bool {
21 39 false
22 40 }
@@ -1,6 +1,8 @@
1use gpui_kit::Window;
1use gpui_kit::Window;
2
2
3use super::{NativeHandle, TrayCommand, WorkArea};
3use calling::ShareKind;
4
5use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
4use crate::notify::badge::Badge;
6use crate::notify::badge::Badge;
5
7
6pub fn native_handle(_window: &Window) -> Option<NativeHandle> {
8pub fn native_handle(_window: &Window) -> Option<NativeHandle> {
@@ -17,6 +19,22 @@ pub fn work_area(_handle: NativeHandle) -> Option<WorkArea> {
17
19
18pub fn place(_handle: NativeHandle, _x: i32, _y: i32, _width: i32, _height: i32) {}
20pub fn place(_handle: NativeHandle, _x: i32, _y: i32, _width: i32, _height: i32) {}
19
21
22pub fn exclude_from_capture(_handle: NativeHandle) {}
23
24pub fn make_click_through(_handle: NativeHandle) {}
25
26pub fn window_minimized(_handle: NativeHandle) -> bool {
27 false
28}
29
30pub fn window_rect(_handle: NativeHandle) -> Option<ScreenRect> {
31 None
32}
33
34pub fn share_geometry(_kind: ShareKind, _id: u64) -> Option<ShareGeometry> {
35 None
36}
37
20pub fn system_quiet() -> bool {
38pub fn system_quiet() -> bool {
21 false
39 false
22}
40}
crates/app/src/notify/platform/windows_impl.rs +132 −9
@@ -5,21 +5,23 @@ use std::sync::Arc;
5 5 use std::sync::atomic::{AtomicBool, Ordering};
6 6 use std::time::Duration;
7 7
8 use calling::ShareKind;
8 9 use gpui_kit::Window;
9 10 use raw_window_handle::{HasWindowHandle, RawWindowHandle};
10 11 use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem};
11 12 use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};
12 use windows::Win32::Foundation::{HWND, RECT};
13 use windows::Win32::Foundation::{COLORREF, HWND, RECT};
13 14 use windows::Win32::Graphics::Dwm::{
14 DWMWA_BORDER_COLOR, DWMWA_COLOR_NONE, DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_DONOTROUND,
15 DwmSetWindowAttribute,
15 DWMWA_BORDER_COLOR, DWMWA_COLOR_NONE, DWMWA_EXTENDED_FRAME_BOUNDS, DWMWA_WINDOW_CORNER_PREFERENCE,
16 DWMWCP_DONOTROUND, DwmGetWindowAttribute, DwmSetWindowAttribute,
16 17 };
17 18 use windows::Win32::Graphics::Gdi::{
18 CreateBitmap, DeleteObject, GetMonitorInfoW, HGDIOBJ, MONITOR_DEFAULTTONEAREST, MONITORINFO,
19 MonitorFromWindow,
19 CreateBitmap, DEVMODEW, DISPLAY_DEVICE_ACTIVE, DISPLAY_DEVICEW, DeleteObject, ENUM_CURRENT_SETTINGS,
20 EnumDisplayDevicesW, EnumDisplaySettingsW, GetMonitorInfoW, HGDIOBJ, MONITOR_DEFAULTTONEAREST, MONITORINFO,
21 MonitorFromRect, MonitorFromWindow,
20 22 };
21 23 use windows::Win32::System::Com::{CLSCTX_INPROC_SERVER, CoCreateInstance};
22 use windows::Win32::UI::HiDpi::GetDpiForWindow;
24 use windows::Win32::UI::HiDpi::{GetDpiForWindow, GetDpiForMonitor, MDT_EFFECTIVE_DPI};
23 25 use windows::Win32::UI::Shell::{
24 26 ITaskbarList3, QUNS_BUSY, QUNS_PRESENTATION_MODE, QUNS_QUIET_TIME, QUNS_RUNNING_D3D_FULL_SCREEN,
25 27 SHQueryUserNotificationState, TaskbarList,
@@ -30,11 +32,12 @@ use windows::Win32::UI::WindowsAndMessaging::{
30 32 SPI_GETCLIENTAREAANIMATION, SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
31 33 SWP_NOZORDER, WS_CAPTION, WS_POPUP, WS_THICKFRAME, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,
32 34 SetWindowLongPtrW, SetWindowPos, ShowWindow, SystemParametersInfoW,
33 WS_EX_NOACTIVATE,
35 WS_EX_NOACTIVATE, WS_EX_LAYERED, WS_EX_TRANSPARENT, LWA_ALPHA, SetLayeredWindowAttributes, SetWindowDisplayAffinity,
36 WDA_EXCLUDEFROMCAPTURE, GetWindowRect,
34 37 };
35 use windows::core::{BOOL, w};
38 use windows::core::{BOOL, PCWSTR, w};
36 39
37 use super::{NativeHandle, TrayCommand, WorkArea};
40 use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
38 41 use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};
39 42 use crate::notify::ring_tone::{SAMPLE_RATE, ring_cycle};
40 43
@@ -151,6 +154,126 @@ pub fn place(handle: NativeHandle, x: i32, y: i32, width: i32, height: i32) {
151 154 }
152 155 }
153 156
157 pub fn exclude_from_capture(handle: NativeHandle) {
158 unsafe {
159 let _ = SetWindowDisplayAffinity(hwnd(handle), WDA_EXCLUDEFROMCAPTURE);
160 }
161 }
162
163 pub fn make_click_through(handle: NativeHandle) {
164 unsafe {
165 let style = GetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE);
166 let added = (WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE).0 as isize;
167 SetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE, style | added);
168 // A layered window stays invisible until its alpha is set.
169 let _ = SetLayeredWindowAttributes(hwnd(handle), COLORREF(0), u8::MAX, LWA_ALPHA);
170 }
171 }
172
173 pub fn window_minimized(handle: NativeHandle) -> bool {
174 unsafe { IsIconic(hwnd(handle)).as_bool() }
175 }
176
177 fn screen_rect(rect: RECT) -> ScreenRect {
178 ScreenRect {
179 left: rect.left,
180 top: rect.top,
181 right: rect.right,
182 bottom: rect.bottom,
183 }
184 }
185
186 pub fn window_rect(handle: NativeHandle) -> Option<ScreenRect> {
187 let mut rect = RECT::default();
188 unsafe { GetWindowRect(hwnd(handle), &mut rect).ok()? };
189 Some(screen_rect(rect))
190 }
191
192 fn visible_frame(window: HWND) -> Option<ScreenRect> {
193 let mut rect = RECT::default();
194 unsafe {
195 if IsIconic(window).as_bool() {
196 return None;
197 }
198 // Excludes the invisible resize margin that GetWindowRect includes.
199 let framed = DwmGetWindowAttribute(
200 window,
201 DWMWA_EXTENDED_FRAME_BOUNDS,
202 &mut rect as *mut _ as *mut c_void,
203 size_of::<RECT>() as u32,
204 );
205 if framed.is_err() {
206 GetWindowRect(window, &mut rect).ok()?;
207 }
208 }
209 Some(screen_rect(rect))
210 }
211
212 fn screen_frame(index: u32) -> Option<ScreenRect> {
213 unsafe {
214 let mut device = DISPLAY_DEVICEW {
215 cb: size_of::<DISPLAY_DEVICEW>() as u32,
216 ..Default::default()
217 };
218 if !EnumDisplayDevicesW(PCWSTR::null(), index, &mut device, 0).as_bool()
219 || device.StateFlags & DISPLAY_DEVICE_ACTIVE == Default::default()
220 {
221 return None;
222 }
223 let mut mode = DEVMODEW {
224 dmSize: size_of::<DEVMODEW>() as u16,
225 ..Default::default()
226 };
227 if !EnumDisplaySettingsW(PCWSTR(device.DeviceName.as_ptr()), ENUM_CURRENT_SETTINGS, &mut mode).as_bool() {
228 return None;
229 }
230 let position = mode.Anonymous1.Anonymous2.dmPosition;
231 Some(ScreenRect {
232 left: position.x,
233 top: position.y,
234 right: position.x + mode.dmPelsWidth as i32,
235 bottom: position.y + mode.dmPelsHeight as i32,
236 })
237 }
238 }
239
240 fn geometry_around(target: ScreenRect) -> Option<ShareGeometry> {
241 unsafe {
242 let rect = RECT {
243 left: target.left,
244 top: target.top,
245 right: target.right,
246 bottom: target.bottom,
247 };
248 let monitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
249 let mut info = MONITORINFO {
250 cbSize: size_of::<MONITORINFO>() as u32,
251 ..Default::default()
252 };
253 if !GetMonitorInfoW(monitor, &mut info).as_bool() {
254 return None;
255 }
256 let (mut dpi_x, mut dpi_y) = (0, 0);
257 let scale = match GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &mut dpi_x, &mut dpi_y) {
258 Ok(()) if dpi_x > 0 => dpi_x as f32 / BASE_DPI,
259 _ => 1.,
260 };
261 let RECT { left, top, right, bottom } = info.rcWork;
262 Some(ShareGeometry {
263 target,
264 work: WorkArea { left, top, right, bottom, scale },
265 })
266 }
267 }
268
269 pub fn share_geometry(kind: ShareKind, id: u64) -> Option<ShareGeometry> {
270 let target = match kind {
271 ShareKind::Screen => screen_frame(u32::try_from(id).ok()?)?,
272 ShareKind::Window => visible_frame(hwnd(id as NativeHandle))?,
273 };
274 geometry_around(target)
275 }
276
154 277 pub fn system_quiet() -> bool {
155 278 let state = unsafe { SHQueryUserNotificationState() };
156 279 matches!(
@@ -5,21 +5,23 @@ use std::sync::Arc;
5use std::sync::atomic::{AtomicBool, Ordering};
5use std::sync::atomic::{AtomicBool, Ordering};
6use std::time::Duration;
6use std::time::Duration;
7
7
8use calling::ShareKind;
8use gpui_kit::Window;
9use gpui_kit::Window;
9use raw_window_handle::{HasWindowHandle, RawWindowHandle};
10use raw_window_handle::{HasWindowHandle, RawWindowHandle};
10use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem};
11use tray_icon::menu::{CheckMenuItem, Menu, MenuEvent, MenuItem, PredefinedMenuItem};
11use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};
12use tray_icon::{Icon, MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent};
12use windows::Win32::Foundation::{HWND, RECT};
13use windows::Win32::Foundation::{COLORREF, HWND, RECT};
13use windows::Win32::Graphics::Dwm::{
14use windows::Win32::Graphics::Dwm::{
14 DWMWA_BORDER_COLOR, DWMWA_COLOR_NONE, DWMWA_WINDOW_CORNER_PREFERENCE, DWMWCP_DONOTROUND,
15 DWMWA_BORDER_COLOR, DWMWA_COLOR_NONE, DWMWA_EXTENDED_FRAME_BOUNDS, DWMWA_WINDOW_CORNER_PREFERENCE,
15 DwmSetWindowAttribute,
16 DWMWCP_DONOTROUND, DwmGetWindowAttribute, DwmSetWindowAttribute,
16};
17};
17use windows::Win32::Graphics::Gdi::{
18use windows::Win32::Graphics::Gdi::{
18 CreateBitmap, DeleteObject, GetMonitorInfoW, HGDIOBJ, MONITOR_DEFAULTTONEAREST, MONITORINFO,
19 CreateBitmap, DEVMODEW, DISPLAY_DEVICE_ACTIVE, DISPLAY_DEVICEW, DeleteObject, ENUM_CURRENT_SETTINGS,
19 MonitorFromWindow,
20 EnumDisplayDevicesW, EnumDisplaySettingsW, GetMonitorInfoW, HGDIOBJ, MONITOR_DEFAULTTONEAREST, MONITORINFO,
21 MonitorFromRect, MonitorFromWindow,
20};
22};
21use windows::Win32::System::Com::{CLSCTX_INPROC_SERVER, CoCreateInstance};
23use windows::Win32::System::Com::{CLSCTX_INPROC_SERVER, CoCreateInstance};
22use windows::Win32::UI::HiDpi::GetDpiForWindow;
24use windows::Win32::UI::HiDpi::{GetDpiForWindow, GetDpiForMonitor, MDT_EFFECTIVE_DPI};
23use windows::Win32::UI::Shell::{
25use windows::Win32::UI::Shell::{
24 ITaskbarList3, QUNS_BUSY, QUNS_PRESENTATION_MODE, QUNS_QUIET_TIME, QUNS_RUNNING_D3D_FULL_SCREEN,
26 ITaskbarList3, QUNS_BUSY, QUNS_PRESENTATION_MODE, QUNS_QUIET_TIME, QUNS_RUNNING_D3D_FULL_SCREEN,
25 SHQueryUserNotificationState, TaskbarList,
27 SHQueryUserNotificationState, TaskbarList,
@@ -30,11 +32,12 @@ use windows::Win32::UI::WindowsAndMessaging::{
30 SPI_GETCLIENTAREAANIMATION, SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
32 SPI_GETCLIENTAREAANIMATION, SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
31 SWP_NOZORDER, WS_CAPTION, WS_POPUP, WS_THICKFRAME, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,
33 SWP_NOZORDER, WS_CAPTION, WS_POPUP, WS_THICKFRAME, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,
32 SetWindowLongPtrW, SetWindowPos, ShowWindow, SystemParametersInfoW,
34 SetWindowLongPtrW, SetWindowPos, ShowWindow, SystemParametersInfoW,
33 WS_EX_NOACTIVATE,
35 WS_EX_NOACTIVATE, WS_EX_LAYERED, WS_EX_TRANSPARENT, LWA_ALPHA, SetLayeredWindowAttributes, SetWindowDisplayAffinity,
36 WDA_EXCLUDEFROMCAPTURE, GetWindowRect,
34};
37};
35use windows::core::{BOOL, w};
38use windows::core::{BOOL, PCWSTR, w};
36
39
37use super::{NativeHandle, TrayCommand, WorkArea};
40use super::{NativeHandle, ScreenRect, ShareGeometry, TrayCommand, WorkArea};
38use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};
41use crate::notify::badge::{BADGE_SIZE, Badge, render_badge};
39use crate::notify::ring_tone::{SAMPLE_RATE, ring_cycle};
42use crate::notify::ring_tone::{SAMPLE_RATE, ring_cycle};
40
43
@@ -151,6 +154,126 @@ pub fn place(handle: NativeHandle, x: i32, y: i32, width: i32, height: i32) {
151 }
154 }
152}
155}
153
156
157pub fn exclude_from_capture(handle: NativeHandle) {
158 unsafe {
159 let _ = SetWindowDisplayAffinity(hwnd(handle), WDA_EXCLUDEFROMCAPTURE);
160 }
161}
162
163pub fn make_click_through(handle: NativeHandle) {
164 unsafe {
165 let style = GetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE);
166 let added = (WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE).0 as isize;
167 SetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE, style | added);
168 // A layered window stays invisible until its alpha is set.
169 let _ = SetLayeredWindowAttributes(hwnd(handle), COLORREF(0), u8::MAX, LWA_ALPHA);
170 }
171}
172
173pub fn window_minimized(handle: NativeHandle) -> bool {
174 unsafe { IsIconic(hwnd(handle)).as_bool() }
175}
176
177fn screen_rect(rect: RECT) -> ScreenRect {
178 ScreenRect {
179 left: rect.left,
180 top: rect.top,
181 right: rect.right,
182 bottom: rect.bottom,
183 }
184}
185
186pub fn window_rect(handle: NativeHandle) -> Option<ScreenRect> {
187 let mut rect = RECT::default();
188 unsafe { GetWindowRect(hwnd(handle), &mut rect).ok()? };
189 Some(screen_rect(rect))
190}
191
192fn visible_frame(window: HWND) -> Option<ScreenRect> {
193 let mut rect = RECT::default();
194 unsafe {
195 if IsIconic(window).as_bool() {
196 return None;
197 }
198 // Excludes the invisible resize margin that GetWindowRect includes.
199 let framed = DwmGetWindowAttribute(
200 window,
201 DWMWA_EXTENDED_FRAME_BOUNDS,
202 &mut rect as *mut _ as *mut c_void,
203 size_of::<RECT>() as u32,
204 );
205 if framed.is_err() {
206 GetWindowRect(window, &mut rect).ok()?;
207 }
208 }
209 Some(screen_rect(rect))
210}
211
212fn screen_frame(index: u32) -> Option<ScreenRect> {
213 unsafe {
214 let mut device = DISPLAY_DEVICEW {
215 cb: size_of::<DISPLAY_DEVICEW>() as u32,
216 ..Default::default()
217 };
218 if !EnumDisplayDevicesW(PCWSTR::null(), index, &mut device, 0).as_bool()
219 || device.StateFlags & DISPLAY_DEVICE_ACTIVE == Default::default()
220 {
221 return None;
222 }
223 let mut mode = DEVMODEW {
224 dmSize: size_of::<DEVMODEW>() as u16,
225 ..Default::default()
226 };
227 if !EnumDisplaySettingsW(PCWSTR(device.DeviceName.as_ptr()), ENUM_CURRENT_SETTINGS, &mut mode).as_bool() {
228 return None;
229 }
230 let position = mode.Anonymous1.Anonymous2.dmPosition;
231 Some(ScreenRect {
232 left: position.x,
233 top: position.y,
234 right: position.x + mode.dmPelsWidth as i32,
235 bottom: position.y + mode.dmPelsHeight as i32,
236 })
237 }
238}
239
240fn geometry_around(target: ScreenRect) -> Option<ShareGeometry> {
241 unsafe {
242 let rect = RECT {
243 left: target.left,
244 top: target.top,
245 right: target.right,
246 bottom: target.bottom,
247 };
248 let monitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
249 let mut info = MONITORINFO {
250 cbSize: size_of::<MONITORINFO>() as u32,
251 ..Default::default()
252 };
253 if !GetMonitorInfoW(monitor, &mut info).as_bool() {
254 return None;
255 }
256 let (mut dpi_x, mut dpi_y) = (0, 0);
257 let scale = match GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &mut dpi_x, &mut dpi_y) {
258 Ok(()) if dpi_x > 0 => dpi_x as f32 / BASE_DPI,
259 _ => 1.,
260 };
261 let RECT { left, top, right, bottom } = info.rcWork;
262 Some(ShareGeometry {
263 target,
264 work: WorkArea { left, top, right, bottom, scale },
265 })
266 }
267}
268
269pub fn share_geometry(kind: ShareKind, id: u64) -> Option<ShareGeometry> {
270 let target = match kind {
271 ShareKind::Screen => screen_frame(u32::try_from(id).ok()?)?,
272 ShareKind::Window => visible_frame(hwnd(id as NativeHandle))?,
273 };
274 geometry_around(target)
275}
276
154pub fn system_quiet() -> bool {
277pub fn system_quiet() -> bool {
155 let state = unsafe { SHQueryUserNotificationState() };
278 let state = unsafe { SHQueryUserNotificationState() };
156 matches!(
279 matches!(
crates/app/src/views/call_mini.rs +41 −0
@@ -2,6 +2,7 @@ use std::time::Instant;
2 2
3 3 use gpui_kit::assets::IconName;
4 4 use gpui_kit::component::{h_flex, v_flex};
5 use gpui_kit::prelude::FluentBuilder as _;
5 6 use gpui_kit::*;
6 7
7 8 use super::call_view::{leave_button, mute_button, status_line};
@@ -14,6 +15,45 @@ const MINI_RIGHT: f32 = 16.;
14 15 const MINI_BOTTOM: f32 = 40.;
15 16 const MUTE_SIZE: f32 = 28.;
16 17
18 fn sharing_badge(app: &Entity<AppState>) -> Stateful<Div> {
19 let stop_app = app.clone();
20 h_flex()
21 .id("call-mini-sharing")
22 .gap(px(8.))
23 .items_center()
24 .justify_between()
25 .child(
26 h_flex()
27 .gap(px(6.))
28 .items_center()
29 .text_size(px(12.))
30 .font_weight(FontWeight::SEMIBOLD)
31 .text_color(theme::red())
32 .child(icon(IconName::ScreenShare, 14., theme::red()))
33 .child("Sharing"),
34 )
35 .child(
36 div()
37 .id("call-mini-stop-sharing")
38 .h(px(24.))
39 .px(px(10.))
40 .flex()
41 .items_center()
42 .rounded_full()
43 .bg(theme::red())
44 .text_color(theme::white())
45 .text_size(px(12.))
46 .font_weight(FontWeight::SEMIBOLD)
47 .cursor_pointer()
48 .hover(|button| button.opacity(0.85))
49 .child("Stop")
50 .on_click(move |_, _, cx| {
51 cx.stop_propagation();
52 stop_app.update(cx, |state, cx| state.stop_call_share(cx));
53 }),
54 )
55 }
56
17 57 pub fn render_call_mini(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {
18 58 let call = state.call.as_ref().filter(|call| !call.viewing)?;
19 59 let model = &call.model;
@@ -59,6 +99,7 @@ pub fn render_call_mini(app: &Entity<AppState>, state: &AppState) -> Option<AnyE
59 99 )
60 100 .child(div().text_size(px(12.)).text_color(status_color).child(status)),
61 101 )
102 .when(model.local_share.is_some(), |mini| mini.child(sharing_badge(app)))
62 103 .child(
63 104 h_flex()
64 105 .gap(px(8.))
@@ -2,6 +2,7 @@ use std::time::Instant;
2
2
3use gpui_kit::assets::IconName;
3use gpui_kit::assets::IconName;
4use gpui_kit::component::{h_flex, v_flex};
4use gpui_kit::component::{h_flex, v_flex};
5use gpui_kit::prelude::FluentBuilder as _;
5use gpui_kit::*;
6use gpui_kit::*;
6
7
7use super::call_view::{leave_button, mute_button, status_line};
8use super::call_view::{leave_button, mute_button, status_line};
@@ -14,6 +15,45 @@ const MINI_RIGHT: f32 = 16.;
14const MINI_BOTTOM: f32 = 40.;
15const MINI_BOTTOM: f32 = 40.;
15const MUTE_SIZE: f32 = 28.;
16const MUTE_SIZE: f32 = 28.;
16
17
18fn sharing_badge(app: &Entity<AppState>) -> Stateful<Div> {
19 let stop_app = app.clone();
20 h_flex()
21 .id("call-mini-sharing")
22 .gap(px(8.))
23 .items_center()
24 .justify_between()
25 .child(
26 h_flex()
27 .gap(px(6.))
28 .items_center()
29 .text_size(px(12.))
30 .font_weight(FontWeight::SEMIBOLD)
31 .text_color(theme::red())
32 .child(icon(IconName::ScreenShare, 14., theme::red()))
33 .child("Sharing"),
34 )
35 .child(
36 div()
37 .id("call-mini-stop-sharing")
38 .h(px(24.))
39 .px(px(10.))
40 .flex()
41 .items_center()
42 .rounded_full()
43 .bg(theme::red())
44 .text_color(theme::white())
45 .text_size(px(12.))
46 .font_weight(FontWeight::SEMIBOLD)
47 .cursor_pointer()
48 .hover(|button| button.opacity(0.85))
49 .child("Stop")
50 .on_click(move |_, _, cx| {
51 cx.stop_propagation();
52 stop_app.update(cx, |state, cx| state.stop_call_share(cx));
53 }),
54 )
55}
56
17pub fn render_call_mini(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {
57pub fn render_call_mini(app: &Entity<AppState>, state: &AppState) -> Option<AnyElement> {
18 let call = state.call.as_ref().filter(|call| !call.viewing)?;
58 let call = state.call.as_ref().filter(|call| !call.viewing)?;
19 let model = &call.model;
59 let model = &call.model;
@@ -59,6 +99,7 @@ pub fn render_call_mini(app: &Entity<AppState>, state: &AppState) -> Option<AnyE
59 )
99 )
60 .child(div().text_size(px(12.)).text_color(status_color).child(status)),
100 .child(div().text_size(px(12.)).text_color(status_color).child(status)),
61 )
101 )
102 .when(model.local_share.is_some(), |mini| mini.child(sharing_badge(app)))
62 .child(
103 .child(
63 h_flex()
104 h_flex()
64 .gap(px(8.))
105 .gap(px(8.))
crates/app/src/views/call_mini_window.rs added +224 −0
@@ -0,0 +1,224 @@
1 use std::time::Instant;
2
3 use calling::VideoKey;
4 use gpui_kit::assets::IconName;
5 use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
6 use gpui_kit::*;
7
8 use super::avatar::person_avatar;
9 use super::call_view::{camera_button, leave_button, mute_button, round_control, status_line};
10 use super::widgets::icon;
11 use crate::app_state::AppState;
12 use crate::call::{CallModel, CallWindows, Tile, TileState};
13 use crate::theme;
14
15 const CONTROLS_HEIGHT: f32 = 44.;
16 const CONTROL_SIZE: f32 = 30.;
17 const WINDOW_RADIUS: f32 = 10.;
18 const SELF_VIEW_WIDTH: f32 = 80.;
19 const SELF_VIEW_HEIGHT: f32 = 45.;
20 const SPEAKER_AVATAR: f32 = 56.;
21 const CHIP_BACKGROUND: f32 = 0.6;
22 const SHADE_BACKGROUND: f32 = 0.55;
23
24 pub struct MiniWindowView {
25 windows: Entity<CallWindows>,
26 app: Entity<AppState>,
27 _app_subscription: Subscription,
28 }
29
30 impl MiniWindowView {
31 pub fn new(windows: Entity<CallWindows>, cx: &mut Context<Self>) -> Self {
32 let app = windows.read(cx).app().clone();
33 let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());
34 MiniWindowView {
35 windows,
36 app,
37 _app_subscription: app_subscription,
38 }
39 }
40 }
41
42 pub fn speaker_tile(model: &CallModel) -> Option<&Tile> {
43 let present: Vec<&Tile> = model.visible_tiles().into_iter().filter(|tile| tile.state == TileState::Present).collect();
44 let focused = model
45 .focus()
46 .filter(|focus| !focus.own)
47 .and_then(|focus| present.iter().find(|tile| tile.mri == focus.mri).copied());
48 focused
49 .or_else(|| present.iter().find(|tile| model.tile_speaking(tile)).copied())
50 .or_else(|| present.first().copied())
51 }
52
53 fn chip(text: String) -> Div {
54 div()
55 .max_w(px(180.))
56 .truncate()
57 .px(px(8.))
58 .py(px(3.))
59 .rounded(px(6.))
60 .bg(hsla(0., 0., 0., CHIP_BACKGROUND))
61 .text_size(px(12.))
62 .font_weight(FontWeight::SEMIBOLD)
63 .text_color(theme::white())
64 .child(text)
65 }
66
67 fn cover(image: std::sync::Arc<RenderImage>) -> Img {
68 img(ImageSource::Render(image)).size_full().object_fit(ObjectFit::Cover)
69 }
70
71 fn speaker_layer(state: &AppState, model: &CallModel, now: Instant) -> AnyElement {
72 let Some(call) = state.call.as_ref() else {
73 return div().into_any_element();
74 };
75 let Some(tile) = speaker_tile(model) else {
76 return v_flex()
77 .size_full()
78 .items_center()
79 .justify_center()
80 .gap(px(8.))
81 .child(icon(IconName::Phone, 28., theme::accent_text()))
82 .child(div().max_w_full().truncate().text_size(px(13.)).child(model.title.clone()))
83 .into_any_element();
84 };
85 let video = (tile.has_video || model.is_one_to_one())
86 .then(|| call.pictures.live(&VideoKey::Person(tile.mri.clone()), now))
87 .flatten();
88 match video {
89 Some(image) => cover(image).into_any_element(),
90 None => v_flex()
91 .size_full()
92 .items_center()
93 .justify_center()
94 .gap(px(8.))
95 .child(person_avatar(&state.directory, tile.user_id.as_deref(), &tile.name, SPEAKER_AVATAR))
96 .child(div().max_w_full().truncate().text_size(px(13.)).font_weight(FontWeight::SEMIBOLD).child(tile.name.clone()))
97 .into_any_element(),
98 }
99 }
100
101 fn self_view(state: &AppState, model: &CallModel, now: Instant) -> Option<AnyElement> {
102 let image = state
103 .call
104 .as_ref()
105 .filter(|_| model.camera_on)
106 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now))?;
107 Some(
108 div()
109 .absolute()
110 .top(px(8.))
111 .right(px(8.))
112 .w(px(SELF_VIEW_WIDTH))
113 .h(px(SELF_VIEW_HEIGHT))
114 .overflow_hidden()
115 .rounded(px(6.))
116 .border_1()
117 .border_color(theme::border_strong())
118 .child(cover(image))
119 .into_any_element(),
120 )
121 }
122
123 impl Render for MiniWindowView {
124 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
125 let state = self.app.read(cx);
126 let Some(call) = state.call.as_ref() else {
127 return div().into_any_element();
128 };
129 let model = &call.model;
130 let now = Instant::now();
131 let (status, _) = status_line(model, now);
132 let windows = self.windows.clone();
133 let speaking = speaker_tile(model).is_some_and(|tile| model.tile_speaking(tile));
134 let speaker_name = speaker_tile(model).map(|tile| tile.name.clone());
135 div()
136 .id("call-mini-window")
137 .group("call-mini-window")
138 .relative()
139 .size_full()
140 .overflow_hidden()
141 .rounded(px(WINDOW_RADIUS))
142 .bg(theme::surface())
143 .border_2()
144 .border_color(if speaking { theme::green() } else { theme::border_strong() })
145 .text_color(theme::text())
146 .child(speaker_layer(state, model, now))
147 .child(
148 div()
149 .id("call-mini-window-drag")
150 .absolute()
151 .top_0()
152 .left_0()
153 .right_0()
154 .bottom(px(CONTROLS_HEIGHT))
155 .window_control_area(WindowControlArea::Drag)
156 .on_mouse_down(MouseButton::Left, |_, window, _| window.start_window_move())
157 .child(div().absolute().top(px(8.)).left(px(8.)).child(chip(status)))
158 .children(speaker_name.map(|name| div().absolute().bottom(px(6.)).left(px(8.)).child(chip(name))))
159 .children(self_view(state, model, now)),
160 )
161 .child(
162 h_flex()
163 .absolute()
164 .left_0()
165 .right_0()
166 .bottom_0()
167 .h(px(CONTROLS_HEIGHT))
168 .gap(px(10.))
169 .items_center()
170 .justify_center()
171 .bg(hsla(0., 0., 0., SHADE_BACKGROUND))
172 .opacity(0.)
173 .group_hover("call-mini-window", |controls| controls.opacity(1.))
174 .child(mute_button(&self.app, model, "call-mini-window-mute", CONTROL_SIZE))
175 .child(camera_button(&self.app, model).size(px(CONTROL_SIZE)))
176 .child(
177 round_control("call-mini-window-back", IconName::Maximize2, theme::surface_raised(), theme::text())
178 .size(px(CONTROL_SIZE))
179 .tooltip(|window, cx| Tooltip::new("Back to call").build(window, cx))
180 .on_click(move |_, _, cx| windows.update(cx, |windows, cx| windows.return_to_call(cx))),
181 )
182 .child(leave_button(&self.app, model, "call-mini-window-leave", true)),
183 )
184 .into_any_element()
185 }
186 }
187
188 #[cfg(test)]
189 mod tests {
190 use super::speaker_tile;
191 use crate::call::{CallModel, Tile, TileState};
192
193 fn present(mri: &str, name: &str) -> Tile {
194 Tile {
195 state: TileState::Present,
196 ..Tile::invited(mri, name)
197 }
198 }
199
200 #[test]
201 fn speaker_is_the_speaking_tile_before_the_first_one() {
202 let mut model = CallModel::test();
203 model.tiles = vec![present("8:a", "Ada"), present("8:b", "Bo")];
204 assert_eq!(speaker_tile(&model).map(|tile| tile.name.as_str()), Some("Ada"));
205 model.speaking_mris = vec!["8:b".to_owned()];
206 assert_eq!(speaker_tile(&model).map(|tile| tile.name.as_str()), Some("Bo"));
207 }
208
209 #[test]
210 fn speaker_is_the_pinned_tile_over_the_speaking_one() {
211 let mut model = CallModel::test();
212 model.tiles = vec![present("8:a", "Ada"), present("8:b", "Bo")];
213 model.speaking_mris = vec!["8:b".to_owned()];
214 model.toggle_pin("8:a");
215 assert_eq!(speaker_tile(&model).map(|tile| tile.name.as_str()), Some("Ada"));
216 }
217
218 #[test]
219 fn nobody_present_means_no_speaker() {
220 let mut model = CallModel::test();
221 model.tiles = vec![Tile::invited("8:a", "Ada")];
222 assert!(speaker_tile(&model).is_none());
223 }
224 }
@@ -0,0 +1,224 @@
1use std::time::Instant;
2
3use calling::VideoKey;
4use gpui_kit::assets::IconName;
5use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
6use gpui_kit::*;
7
8use super::avatar::person_avatar;
9use super::call_view::{camera_button, leave_button, mute_button, round_control, status_line};
10use super::widgets::icon;
11use crate::app_state::AppState;
12use crate::call::{CallModel, CallWindows, Tile, TileState};
13use crate::theme;
14
15const CONTROLS_HEIGHT: f32 = 44.;
16const CONTROL_SIZE: f32 = 30.;
17const WINDOW_RADIUS: f32 = 10.;
18const SELF_VIEW_WIDTH: f32 = 80.;
19const SELF_VIEW_HEIGHT: f32 = 45.;
20const SPEAKER_AVATAR: f32 = 56.;
21const CHIP_BACKGROUND: f32 = 0.6;
22const SHADE_BACKGROUND: f32 = 0.55;
23
24pub struct MiniWindowView {
25 windows: Entity<CallWindows>,
26 app: Entity<AppState>,
27 _app_subscription: Subscription,
28}
29
30impl MiniWindowView {
31 pub fn new(windows: Entity<CallWindows>, cx: &mut Context<Self>) -> Self {
32 let app = windows.read(cx).app().clone();
33 let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());
34 MiniWindowView {
35 windows,
36 app,
37 _app_subscription: app_subscription,
38 }
39 }
40}
41
42pub fn speaker_tile(model: &CallModel) -> Option<&Tile> {
43 let present: Vec<&Tile> = model.visible_tiles().into_iter().filter(|tile| tile.state == TileState::Present).collect();
44 let focused = model
45 .focus()
46 .filter(|focus| !focus.own)
47 .and_then(|focus| present.iter().find(|tile| tile.mri == focus.mri).copied());
48 focused
49 .or_else(|| present.iter().find(|tile| model.tile_speaking(tile)).copied())
50 .or_else(|| present.first().copied())
51}
52
53fn chip(text: String) -> Div {
54 div()
55 .max_w(px(180.))
56 .truncate()
57 .px(px(8.))
58 .py(px(3.))
59 .rounded(px(6.))
60 .bg(hsla(0., 0., 0., CHIP_BACKGROUND))
61 .text_size(px(12.))
62 .font_weight(FontWeight::SEMIBOLD)
63 .text_color(theme::white())
64 .child(text)
65}
66
67fn cover(image: std::sync::Arc<RenderImage>) -> Img {
68 img(ImageSource::Render(image)).size_full().object_fit(ObjectFit::Cover)
69}
70
71fn speaker_layer(state: &AppState, model: &CallModel, now: Instant) -> AnyElement {
72 let Some(call) = state.call.as_ref() else {
73 return div().into_any_element();
74 };
75 let Some(tile) = speaker_tile(model) else {
76 return v_flex()
77 .size_full()
78 .items_center()
79 .justify_center()
80 .gap(px(8.))
81 .child(icon(IconName::Phone, 28., theme::accent_text()))
82 .child(div().max_w_full().truncate().text_size(px(13.)).child(model.title.clone()))
83 .into_any_element();
84 };
85 let video = (tile.has_video || model.is_one_to_one())
86 .then(|| call.pictures.live(&VideoKey::Person(tile.mri.clone()), now))
87 .flatten();
88 match video {
89 Some(image) => cover(image).into_any_element(),
90 None => v_flex()
91 .size_full()
92 .items_center()
93 .justify_center()
94 .gap(px(8.))
95 .child(person_avatar(&state.directory, tile.user_id.as_deref(), &tile.name, SPEAKER_AVATAR))
96 .child(div().max_w_full().truncate().text_size(px(13.)).font_weight(FontWeight::SEMIBOLD).child(tile.name.clone()))
97 .into_any_element(),
98 }
99}
100
101fn self_view(state: &AppState, model: &CallModel, now: Instant) -> Option<AnyElement> {
102 let image = state
103 .call
104 .as_ref()
105 .filter(|_| model.camera_on)
106 .and_then(|call| call.pictures.live(&VideoKey::LocalCamera, now))?;
107 Some(
108 div()
109 .absolute()
110 .top(px(8.))
111 .right(px(8.))
112 .w(px(SELF_VIEW_WIDTH))
113 .h(px(SELF_VIEW_HEIGHT))
114 .overflow_hidden()
115 .rounded(px(6.))
116 .border_1()
117 .border_color(theme::border_strong())
118 .child(cover(image))
119 .into_any_element(),
120 )
121}
122
123impl Render for MiniWindowView {
124 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
125 let state = self.app.read(cx);
126 let Some(call) = state.call.as_ref() else {
127 return div().into_any_element();
128 };
129 let model = &call.model;
130 let now = Instant::now();
131 let (status, _) = status_line(model, now);
132 let windows = self.windows.clone();
133 let speaking = speaker_tile(model).is_some_and(|tile| model.tile_speaking(tile));
134 let speaker_name = speaker_tile(model).map(|tile| tile.name.clone());
135 div()
136 .id("call-mini-window")
137 .group("call-mini-window")
138 .relative()
139 .size_full()
140 .overflow_hidden()
141 .rounded(px(WINDOW_RADIUS))
142 .bg(theme::surface())
143 .border_2()
144 .border_color(if speaking { theme::green() } else { theme::border_strong() })
145 .text_color(theme::text())
146 .child(speaker_layer(state, model, now))
147 .child(
148 div()
149 .id("call-mini-window-drag")
150 .absolute()
151 .top_0()
152 .left_0()
153 .right_0()
154 .bottom(px(CONTROLS_HEIGHT))
155 .window_control_area(WindowControlArea::Drag)
156 .on_mouse_down(MouseButton::Left, |_, window, _| window.start_window_move())
157 .child(div().absolute().top(px(8.)).left(px(8.)).child(chip(status)))
158 .children(speaker_name.map(|name| div().absolute().bottom(px(6.)).left(px(8.)).child(chip(name))))
159 .children(self_view(state, model, now)),
160 )
161 .child(
162 h_flex()
163 .absolute()
164 .left_0()
165 .right_0()
166 .bottom_0()
167 .h(px(CONTROLS_HEIGHT))
168 .gap(px(10.))
169 .items_center()
170 .justify_center()
171 .bg(hsla(0., 0., 0., SHADE_BACKGROUND))
172 .opacity(0.)
173 .group_hover("call-mini-window", |controls| controls.opacity(1.))
174 .child(mute_button(&self.app, model, "call-mini-window-mute", CONTROL_SIZE))
175 .child(camera_button(&self.app, model).size(px(CONTROL_SIZE)))
176 .child(
177 round_control("call-mini-window-back", IconName::Maximize2, theme::surface_raised(), theme::text())
178 .size(px(CONTROL_SIZE))
179 .tooltip(|window, cx| Tooltip::new("Back to call").build(window, cx))
180 .on_click(move |_, _, cx| windows.update(cx, |windows, cx| windows.return_to_call(cx))),
181 )
182 .child(leave_button(&self.app, model, "call-mini-window-leave", true)),
183 )
184 .into_any_element()
185 }
186}
187
188#[cfg(test)]
189mod tests {
190 use super::speaker_tile;
191 use crate::call::{CallModel, Tile, TileState};
192
193 fn present(mri: &str, name: &str) -> Tile {
194 Tile {
195 state: TileState::Present,
196 ..Tile::invited(mri, name)
197 }
198 }
199
200 #[test]
201 fn speaker_is_the_speaking_tile_before_the_first_one() {
202 let mut model = CallModel::test();
203 model.tiles = vec![present("8:a", "Ada"), present("8:b", "Bo")];
204 assert_eq!(speaker_tile(&model).map(|tile| tile.name.as_str()), Some("Ada"));
205 model.speaking_mris = vec!["8:b".to_owned()];
206 assert_eq!(speaker_tile(&model).map(|tile| tile.name.as_str()), Some("Bo"));
207 }
208
209 #[test]
210 fn speaker_is_the_pinned_tile_over_the_speaking_one() {
211 let mut model = CallModel::test();
212 model.tiles = vec![present("8:a", "Ada"), present("8:b", "Bo")];
213 model.speaking_mris = vec!["8:b".to_owned()];
214 model.toggle_pin("8:a");
215 assert_eq!(speaker_tile(&model).map(|tile| tile.name.as_str()), Some("Ada"));
216 }
217
218 #[test]
219 fn nobody_present_means_no_speaker() {
220 let mut model = CallModel::test();
221 model.tiles = vec![Tile::invited("8:a", "Ada")];
222 assert!(speaker_tile(&model).is_none());
223 }
224}
crates/app/src/views/call_view.rs +1 −1
@@ -357,7 +357,7 @@ pub fn leave_button(app: &Entity<AppState>, model: &CallModel, id: &'static str,
357 357 })
358 358 }
359 359
360 fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
360 pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
361 361 let (glyph, background, foreground) = if model.camera_on {
362 362 (IconName::Video, theme::accent(), theme::on_accent())
363 363 } else {
@@ -357,7 +357,7 @@ pub fn leave_button(app: &Entity<AppState>, model: &CallModel, id: &'static str,
357 })
357 })
358}
358}
359
359
360fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
360pub(super) fn camera_button(app: &Entity<AppState>, model: &CallModel) -> Stateful<Div> {
361 let (glyph, background, foreground) = if model.camera_on {
361 let (glyph, background, foreground) = if model.camera_on {
362 (IconName::Video, theme::accent(), theme::on_accent())
362 (IconName::Video, theme::accent(), theme::on_accent())
363 } else {
363 } else {
crates/app/src/views/mod.rs +2 −0
@@ -7,6 +7,7 @@ pub mod call_controls;
7 7 pub mod call_extras;
8 8 pub mod calls_tab;
9 9 pub mod call_mini;
10 pub mod call_mini_window;
10 11 pub mod call_organizer;
11 12 pub mod call_stage;
12 13 pub mod call_view;
@@ -39,6 +40,7 @@ pub mod reaction_picker;
39 40 pub mod reaction_pills;
40 41 pub mod saved_panel;
41 42 pub mod scheduled_toolbar;
43 pub mod share_bar;
42 44 pub mod shared_tab;
43 45 pub mod shell;
44 46 pub mod shortcuts;
@@ -7,6 +7,7 @@ pub mod call_controls;
7pub mod call_extras;
7pub mod call_extras;
8pub mod calls_tab;
8pub mod calls_tab;
9pub mod call_mini;
9pub mod call_mini;
10pub mod call_mini_window;
10pub mod call_organizer;
11pub mod call_organizer;
11pub mod call_stage;
12pub mod call_stage;
12pub mod call_view;
13pub mod call_view;
@@ -39,6 +40,7 @@ pub mod reaction_picker;
39pub mod reaction_pills;
40pub mod reaction_pills;
40pub mod saved_panel;
41pub mod saved_panel;
41pub mod scheduled_toolbar;
42pub mod scheduled_toolbar;
43pub mod share_bar;
42pub mod shared_tab;
44pub mod shared_tab;
43pub mod shell;
45pub mod shell;
44pub mod shortcuts;
46pub mod shortcuts;
crates/app/src/views/share_bar.rs added +131 −0
@@ -0,0 +1,131 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::{h_flex, tooltip::Tooltip};
3 use gpui_kit::*;
4
5 use super::call_view::{camera_button, mute_button, round_control};
6 use crate::app_state::AppState;
7 use crate::call::CallWindows;
8 use crate::theme;
9
10 const BUTTON_SIZE: f32 = 26.;
11 const BAR_RADIUS: f32 = 10.;
12 const HANDLE_RADIUS: f32 = 3.;
13 const STOP_HEIGHT: f32 = 26.;
14
15 pub struct ShareBarView {
16 windows: Entity<CallWindows>,
17 app: Entity<AppState>,
18 _windows_subscription: Subscription,
19 _app_subscription: Subscription,
20 }
21
22 impl ShareBarView {
23 pub fn new(windows: Entity<CallWindows>, cx: &mut Context<Self>) -> Self {
24 let app = windows.read(cx).app().clone();
25 let windows_subscription = cx.observe(&windows, |_, _, cx| cx.notify());
26 let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());
27 ShareBarView {
28 windows,
29 app,
30 _windows_subscription: windows_subscription,
31 _app_subscription: app_subscription,
32 }
33 }
34 }
35
36 fn stop_button(app: &Entity<AppState>) -> Stateful<Div> {
37 let app = app.clone();
38 h_flex()
39 .id("share-bar-stop")
40 .h(px(STOP_HEIGHT))
41 .px(px(10.))
42 .flex_none()
43 .items_center()
44 .rounded_full()
45 .bg(theme::red())
46 .text_color(theme::white())
47 .text_size(px(12.))
48 .font_weight(FontWeight::SEMIBOLD)
49 .cursor_pointer()
50 .hover(|button| button.opacity(0.85))
51 .child("Stop sharing")
52 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.stop_call_share(cx)))
53 }
54
55 fn sound_button(app: &Entity<AppState>, sound: bool) -> Stateful<Div> {
56 let app = app.clone();
57 let (glyph, background, foreground) = if sound {
58 (IconName::Volume2, theme::accent(), theme::on_accent())
59 } else {
60 (IconName::VolumeOff, theme::surface(), theme::text())
61 };
62 round_control("share-bar-sound", glyph, background, foreground)
63 .size(px(BUTTON_SIZE))
64 .tooltip(|window, cx| Tooltip::new("Include computer sound").build(window, cx))
65 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
66 }
67
68 fn pin_button(windows: &Entity<CallWindows>, pinned: bool) -> Stateful<Div> {
69 let windows = windows.clone();
70 let (glyph, background, foreground) = if pinned {
71 (IconName::PinOff, theme::accent(), theme::on_accent())
72 } else {
73 (IconName::Pin, theme::surface(), theme::text())
74 };
75 round_control("share-bar-pin", glyph, background, foreground)
76 .size(px(BUTTON_SIZE))
77 .tooltip(move |window, cx| Tooltip::new(if pinned { "Unpin the bar" } else { "Keep the bar visible" }).build(window, cx))
78 .on_click(move |_, _, cx| windows.update(cx, |windows, cx| windows.toggle_pin(cx)))
79 }
80
81 impl Render for ShareBarView {
82 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
83 let windows = self.windows.read(cx);
84 let wake = self.windows.clone();
85 let wake_on_move = move |_: &MouseMoveEvent, _: &mut Window, cx: &mut App| wake.update(cx, |windows, cx| windows.wake_bar(cx));
86 if windows.bar_collapsed() {
87 return div()
88 .id("share-bar-handle")
89 .size_full()
90 .on_mouse_move(wake_on_move)
91 .child(div().size_full().rounded_b(px(HANDLE_RADIUS)).bg(theme::red()))
92 .into_any_element();
93 }
94 let text = windows.share_text();
95 let pinned = windows.pinned();
96 let state = self.app.read(cx);
97 let Some(call) = state.call.as_ref() else {
98 return div().into_any_element();
99 };
100 h_flex()
101 .id("share-bar")
102 .size_full()
103 .px(px(10.))
104 .gap(px(6.))
105 .items_center()
106 .rounded_b(px(BAR_RADIUS))
107 .bg(theme::surface_raised())
108 .border_1()
109 .border_color(theme::red())
110 .text_color(theme::text())
111 .text_size(px(12.))
112 .font_weight(FontWeight::SEMIBOLD)
113 .on_mouse_move(wake_on_move)
114 .child(div().size(px(8.)).flex_none().rounded_full().bg(theme::red()))
115 .child(div().flex_1().min_w_0().truncate().child(text))
116 .child(mute_button(&self.app, &call.model, "share-bar-mute", BUTTON_SIZE))
117 .child(camera_button(&self.app, &call.model).size(px(BUTTON_SIZE)))
118 .child(sound_button(&self.app, state.call_share_sound))
119 .child(stop_button(&self.app))
120 .child(pin_button(&self.windows, pinned))
121 .into_any_element()
122 }
123 }
124
125 pub struct ShareBorderView;
126
127 impl Render for ShareBorderView {
128 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
129 div().size_full().bg(theme::red())
130 }
131 }
@@ -0,0 +1,131 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{h_flex, tooltip::Tooltip};
3use gpui_kit::*;
4
5use super::call_view::{camera_button, mute_button, round_control};
6use crate::app_state::AppState;
7use crate::call::CallWindows;
8use crate::theme;
9
10const BUTTON_SIZE: f32 = 26.;
11const BAR_RADIUS: f32 = 10.;
12const HANDLE_RADIUS: f32 = 3.;
13const STOP_HEIGHT: f32 = 26.;
14
15pub struct ShareBarView {
16 windows: Entity<CallWindows>,
17 app: Entity<AppState>,
18 _windows_subscription: Subscription,
19 _app_subscription: Subscription,
20}
21
22impl ShareBarView {
23 pub fn new(windows: Entity<CallWindows>, cx: &mut Context<Self>) -> Self {
24 let app = windows.read(cx).app().clone();
25 let windows_subscription = cx.observe(&windows, |_, _, cx| cx.notify());
26 let app_subscription = cx.observe(&app, |_, _, cx| cx.notify());
27 ShareBarView {
28 windows,
29 app,
30 _windows_subscription: windows_subscription,
31 _app_subscription: app_subscription,
32 }
33 }
34}
35
36fn stop_button(app: &Entity<AppState>) -> Stateful<Div> {
37 let app = app.clone();
38 h_flex()
39 .id("share-bar-stop")
40 .h(px(STOP_HEIGHT))
41 .px(px(10.))
42 .flex_none()
43 .items_center()
44 .rounded_full()
45 .bg(theme::red())
46 .text_color(theme::white())
47 .text_size(px(12.))
48 .font_weight(FontWeight::SEMIBOLD)
49 .cursor_pointer()
50 .hover(|button| button.opacity(0.85))
51 .child("Stop sharing")
52 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.stop_call_share(cx)))
53}
54
55fn sound_button(app: &Entity<AppState>, sound: bool) -> Stateful<Div> {
56 let app = app.clone();
57 let (glyph, background, foreground) = if sound {
58 (IconName::Volume2, theme::accent(), theme::on_accent())
59 } else {
60 (IconName::VolumeOff, theme::surface(), theme::text())
61 };
62 round_control("share-bar-sound", glyph, background, foreground)
63 .size(px(BUTTON_SIZE))
64 .tooltip(|window, cx| Tooltip::new("Include computer sound").build(window, cx))
65 .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_share_sound(!sound, cx)))
66}
67
68fn pin_button(windows: &Entity<CallWindows>, pinned: bool) -> Stateful<Div> {
69 let windows = windows.clone();
70 let (glyph, background, foreground) = if pinned {
71 (IconName::PinOff, theme::accent(), theme::on_accent())
72 } else {
73 (IconName::Pin, theme::surface(), theme::text())
74 };
75 round_control("share-bar-pin", glyph, background, foreground)
76 .size(px(BUTTON_SIZE))
77 .tooltip(move |window, cx| Tooltip::new(if pinned { "Unpin the bar" } else { "Keep the bar visible" }).build(window, cx))
78 .on_click(move |_, _, cx| windows.update(cx, |windows, cx| windows.toggle_pin(cx)))
79}
80
81impl Render for ShareBarView {
82 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
83 let windows = self.windows.read(cx);
84 let wake = self.windows.clone();
85 let wake_on_move = move |_: &MouseMoveEvent, _: &mut Window, cx: &mut App| wake.update(cx, |windows, cx| windows.wake_bar(cx));
86 if windows.bar_collapsed() {
87 return div()
88 .id("share-bar-handle")
89 .size_full()
90 .on_mouse_move(wake_on_move)
91 .child(div().size_full().rounded_b(px(HANDLE_RADIUS)).bg(theme::red()))
92 .into_any_element();
93 }
94 let text = windows.share_text();
95 let pinned = windows.pinned();
96 let state = self.app.read(cx);
97 let Some(call) = state.call.as_ref() else {
98 return div().into_any_element();
99 };
100 h_flex()
101 .id("share-bar")
102 .size_full()
103 .px(px(10.))
104 .gap(px(6.))
105 .items_center()
106 .rounded_b(px(BAR_RADIUS))
107 .bg(theme::surface_raised())
108 .border_1()
109 .border_color(theme::red())
110 .text_color(theme::text())
111 .text_size(px(12.))
112 .font_weight(FontWeight::SEMIBOLD)
113 .on_mouse_move(wake_on_move)
114 .child(div().size(px(8.)).flex_none().rounded_full().bg(theme::red()))
115 .child(div().flex_1().min_w_0().truncate().child(text))
116 .child(mute_button(&self.app, &call.model, "share-bar-mute", BUTTON_SIZE))
117 .child(camera_button(&self.app, &call.model).size(px(BUTTON_SIZE)))
118 .child(sound_button(&self.app, state.call_share_sound))
119 .child(stop_button(&self.app))
120 .child(pin_button(&self.windows, pinned))
121 .into_any_element()
122 }
123}
124
125pub struct ShareBorderView;
126
127impl Render for ShareBorderView {
128 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
129 div().size_full().bg(theme::red())
130 }
131}
crates/app/src/views/shell.rs +4 −0
@@ -24,6 +24,7 @@ use super::switcher::{Switcher, SwitcherEvent, candidates_from};
24 24 use super::title_bar::render_title_bar;
25 25 use crate::activity::ActivityCenter;
26 26 use crate::app_state::{AppEvent, AppState, Selection};
27 use crate::call::CallWindows;
27 28 use crate::embedded_web::{Overlays, RootFocus};
28 29 use crate::notice::NoticeAction;
29 30 use crate::notify::{NotificationCenter, selection_for};
@@ -58,6 +59,7 @@ pub struct AppShell {
58 59 call_chat: Option<(String, Entity<ConversationView>)>,
59 60 switcher: Option<Entity<Switcher>>,
60 61 notifications: Entity<NotificationCenter>,
62 _call_windows: Entity<CallWindows>,
61 63 activity: Entity<ActivityCenter>,
62 64 activity_panel: Option<Entity<ActivityPanel>>,
63 65 saved_panel: Option<Entity<SavedPanel>>,
@@ -120,6 +122,7 @@ impl AppShell {
120 122 window.focus(&focus_handle, cx);
121 123 cx.set_global(RootFocus(focus_handle.clone()));
122 124 let notifications = cx.new(|cx| NotificationCenter::new(state.clone(), window, cx));
125 let call_windows = cx.new(|cx| CallWindows::new(state.clone(), window, cx));
123 126 let activity = cx.new(|cx| ActivityCenter::new(state.clone(), window, cx));
124 127 let activity_observation = cx.observe(&activity, |_, _, cx| cx.notify());
125 128 let escape_observation = cx.observe_keystrokes(|this, event, _, cx| {
@@ -136,6 +139,7 @@ impl AppShell {
136 139 call_chat: None,
137 140 switcher: None,
138 141 notifications,
142 _call_windows: call_windows,
139 143 activity,
140 144 activity_panel: None,
141 145 saved_panel: None,
@@ -24,6 +24,7 @@ use super::switcher::{Switcher, SwitcherEvent, candidates_from};
24use super::title_bar::render_title_bar;
24use super::title_bar::render_title_bar;
25use crate::activity::ActivityCenter;
25use crate::activity::ActivityCenter;
26use crate::app_state::{AppEvent, AppState, Selection};
26use crate::app_state::{AppEvent, AppState, Selection};
27use crate::call::CallWindows;
27use crate::embedded_web::{Overlays, RootFocus};
28use crate::embedded_web::{Overlays, RootFocus};
28use crate::notice::NoticeAction;
29use crate::notice::NoticeAction;
29use crate::notify::{NotificationCenter, selection_for};
30use crate::notify::{NotificationCenter, selection_for};
@@ -58,6 +59,7 @@ pub struct AppShell {
58 call_chat: Option<(String, Entity<ConversationView>)>,
59 call_chat: Option<(String, Entity<ConversationView>)>,
59 switcher: Option<Entity<Switcher>>,
60 switcher: Option<Entity<Switcher>>,
60 notifications: Entity<NotificationCenter>,
61 notifications: Entity<NotificationCenter>,
62 _call_windows: Entity<CallWindows>,
61 activity: Entity<ActivityCenter>,
63 activity: Entity<ActivityCenter>,
62 activity_panel: Option<Entity<ActivityPanel>>,
64 activity_panel: Option<Entity<ActivityPanel>>,
63 saved_panel: Option<Entity<SavedPanel>>,
65 saved_panel: Option<Entity<SavedPanel>>,
@@ -120,6 +122,7 @@ impl AppShell {
120 window.focus(&focus_handle, cx);
122 window.focus(&focus_handle, cx);
121 cx.set_global(RootFocus(focus_handle.clone()));
123 cx.set_global(RootFocus(focus_handle.clone()));
122 let notifications = cx.new(|cx| NotificationCenter::new(state.clone(), window, cx));
124 let notifications = cx.new(|cx| NotificationCenter::new(state.clone(), window, cx));
125 let call_windows = cx.new(|cx| CallWindows::new(state.clone(), window, cx));
123 let activity = cx.new(|cx| ActivityCenter::new(state.clone(), window, cx));
126 let activity = cx.new(|cx| ActivityCenter::new(state.clone(), window, cx));
124 let activity_observation = cx.observe(&activity, |_, _, cx| cx.notify());
127 let activity_observation = cx.observe(&activity, |_, _, cx| cx.notify());
125 let escape_observation = cx.observe_keystrokes(|this, event, _, cx| {
128 let escape_observation = cx.observe_keystrokes(|this, event, _, cx| {
@@ -136,6 +139,7 @@ impl AppShell {
136 call_chat: None,
139 call_chat: None,
137 switcher: None,
140 switcher: None,
138 notifications,
141 notifications,
142 _call_windows: call_windows,
139 activity,
143 activity,
140 activity_panel: None,
144 activity_panel: None,
141 saved_panel: None,
145 saved_panel: None,