oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1#if os(macOS)
2 import AppKit
3 import SwiftUI
4
5 public struct MacCallView: View {
6 @ObservedObject var call: Call
7 let leave: () -> Void
8 let rejoin: (() -> Void)?
9 @ObservedObject var arrangement: CallArrangement
10 @ObservedObject var speakerNow: SpeakerNow
11 @State var showingChat: Bool
12 /// A tile being dragged to a new place, and where every tile is.
13 @State var drag: TileDrag?
14 @State var tileFrames: [String: CGRect] = [:]
15 @State var readChatCount = 0
16 @State var showingDevices: Bool
17 @State var showingLayout = false
18 @State var showingInvitation = false
19 @State var showingMore = false
20 @State var devicesHeight: CGFloat = 360
21 @StateObject var chatWindow = MacChatWindow()
22 @StateObject var chrome: ControlsVisibilityModel
23 @AppStorage(CallLayoutStyle.key) private var layoutChoice = CallLayoutStyle.defaultStyle.rawValue
24 @AppStorage(PiPCorner.key) var pipCorner = PiPCorner.bottomTrailing.rawValue
25 @State var pipDrag: CGSize = .zero
26 @State var menuTracking = false
27 @State var sheetShowing = false
28 @State var dismissedNotices: Set<String> = []
29 @State var barFrame: CGRect = .zero
30 @FocusState var focusedControl: CallControlID?
31 @Environment(\.accessibilityReduceMotion) var reduceMotion
32 @Environment(\.accessibilityVoiceOverEnabled) var voiceOver
33 @Environment(\.fixtureBackdrop) var fixtureBackdrop
34 @Environment(\.fixtureFeeds) var fixtureFeeds
35 /// Your own picture's shape, once it arrives: the floating self view
36 /// takes it (a Continuity Camera held upright floats upright).
37 @State var selfShape: VideoShape?
38 private let style: CallLayoutStyle?
39
40 /// - Parameters:
41 /// - grid: Grid (true) or Speaker (false) for this call, when not
42 /// the person's own choice (fixtures).
43 /// - style: the layout, when not the person's own choice (fixtures).
44 /// - controlsShown: pins the full-window controls shown or hidden
45 /// (fixtures); nil lets the pointer decide.
46 public init(
47 call: Call, grid: Bool? = nil, showingChat: Bool = false, showingDevices: Bool = false,
48 style: CallLayoutStyle? = nil, controlsShown: Bool? = nil, leave: @escaping () -> Void,
49 rejoin: (() -> Void)? = nil
50 ) {
51 self.call = call
52 self.leave = leave
53 self.rejoin = rejoin
54 self.style = style
55 if let grid { call.arrangement.show(grid ? .grid : .speaker) }
56 arrangement = call.arrangement
57 speakerNow = call.levels.speaker
58 _showingChat = State(initialValue: showingChat)
59 _showingDevices = State(initialValue: showingDevices)
60 _chrome = StateObject(wrappedValue: ControlsVisibilityModel(input: .pointer, pinned: controlsShown))
61 }
62
63 var layout: CallLayoutStyle { style ?? CallLayoutStyle(rawValue: layoutChoice) ?? .defaultStyle }
64
65 public var body: some View {
66 Group {
67 if layout == .classic {
68 classic.padding(24)
69 } else {
70 immersive
71 }
72 }
73 .overlay(alignment: .bottom) {
74 CallToast(call: call).padding(.bottom, layout == .classic ? 100 : Self.barReserve + 16)
75 }
76 .onAppear {
77 if showingChat { readChatCount = call.receivedChatCount }
78 }
79 .task { await call.watchAudio() }
80 // Space mutes and unmutes, unless a text field or a control has the
81 // keyboard. The Call menu's ⌘⇧M is the same toggle, for when it has.
82 .spaceToMute(call)
83 .onChange(of: call.receivedChatCount) { _, count in
84 if showingChat || chatWindow.isOpen { readChatCount = count }
85 }
86 .onChange(of: showingChat) { _, visible in
87 if visible { readChatCount = call.receivedChatCount }
88 }
89 .onChange(of: chatWindow.isOpen) { _, visible in
90 if visible { readChatCount = call.receivedChatCount }
91 }
92 .onDisappear { chatWindow.close() }
93 .reportProblemSheet(call)
94 }
95
96 /// The call as it was before the full-window layout: a title block,
97 /// the stage in a rounded card, and the controls in a row beneath.
98 private var classic: some View {
99 VStack(spacing: 14) {
100 HStack {
101 VStack(alignment: .leading, spacing: 4) {
102 Text(call.title).font(.title2.bold()).lineLimit(1)
103 Text(call.status).font(.callout).foregroundStyle(.secondary)
104 .accessibilityAddTraits(.updatesFrequently)
105 // Said in words as well as by the button's state: a person
106 // sharing a screen should never have to wonder whether they
107 // still are.
108 if call.sharingScreen {
109 Label("You are sharing your screen", systemImage: "rectangle.on.rectangle")
110 .font(.callout.bold()).foregroundStyle(.orange)
111 if !call.screenRecovery.isEmpty {
112 Text(call.screenRecovery).font(.callout).foregroundStyle(.secondary)
113 .accessibilityIdentifier("screenRecovery")
114 }
115 } else if !call.screenNote.isEmpty {
116 Text(call.screenNote).font(.callout).foregroundStyle(.secondary)
117 }
118 }
119 Spacer()
120 if !grid, peers.count > 1 || !call.screens.isEmpty {
121 Menu {
122 pinChoices
123 } label: {
124 Label("Pin to the stage", systemImage: arrangement.pinned == nil ? "pin" : "pin.fill")
125 }
126 .help("Pin a participant or screen to the main stage, or follow whoever is speaking")
127 }
128 layoutPicker.pickerStyle(.segmented).fixedSize()
129 }
130 if call.floor {
131 Text("Direct connections only. People on some networks may be unable to connect.")
132 .font(.callout).foregroundStyle(.secondary).frame(
133 maxWidth: .infinity, alignment: .leading)
134 }
135 HStack(alignment: .top, spacing: 16) {
136 stage.frame(maxWidth: .infinity, maxHeight: .infinity)
137 if showingDevices {
138 VStack(spacing: 0) {
139 HStack {
140 Text("Devices").font(.headline)
141 Spacer()
142 Button("Hide devices", systemImage: "xmark") { showingDevices = false }
143 .labelStyle(.iconOnly).buttonStyle(.borderless).help("Hide devices")
144 }.padding(.horizontal, 16).padding(.top, 16)
145 DevicePanel(call: call)
146 Spacer(minLength: 0)
147 }.frame(width: 300)
148 .background(.quaternary.opacity(0.4), in: RoundedRectangle(cornerRadius: 16))
149 }
150 if showingChat {
151 VStack(spacing: 14) {
152 HStack {
153 Text("Chat").font(.headline)
154 Spacer()
155 Button("Open chat in a window", systemImage: "arrow.up.forward.app") {
156 showingChat = false
157 chatWindow.open(call: call)
158 }.help("Open chat in a separate window")
159 Button("Hide chat", systemImage: "xmark") { showingChat = false }
160 .help("Hide chat")
161 }.labelStyle(.iconOnly).buttonStyle(.borderless)
162 ChatView(call: call, draft: chatWindow.draft)
163 }.padding(16).frame(width: 280)
164 .background(.quaternary.opacity(0.4), in: RoundedRectangle(cornerRadius: 16))
165 }
166 }.frame(maxWidth: .infinity, maxHeight: .infinity)
167 ForEach(call.state?.waiting ?? []) { peer in
168 HStack {
169 Text("\(peer.name) is waiting")
170 Spacer()
171 Button("Let in") { call.admit(peer.peer) }.buttonStyle(.borderedProminent)
172 }
173 }
174 if call.state?.phase == "full" { Button("Try joining again") { call.retryJoin() } }
175 // An ended call used to stay on screen as a call with no way back
176 // into it but Leave and the lobby.
177 if call.state?.phase == "ended" {
178 HStack {
179 if let rejoin {
180 Button("Join again", action: rejoin).buttonStyle(.borderedProminent)
181 .accessibilityIdentifier("joinAgain")
182 }
183 ReportProblemButton { call.reportProblem() }.buttonStyle(.bordered)
184 }
185 }
186 controls(fullWindow: false)
187 }
188 }
189
190 var grid: Bool { arrangement.layout == .grid }
191
192 /// Everyone else, in this viewer's order.
193 var peers: [RosterPeer] {
194 let roster = call.state?.peers ?? []
195 return arrangement.others.compactMap { id in roster.first { $0.peer == id } }
196 }
197 /// What Speaker view's stage shows.
198 var focused: StageItem? { arrangement.stage(active: speakerNow.peer, screens: call.screens) }
199 /// Speaker view's filmstrip: everything not on the stage.
200 var filmstrip: [StageItem] { arrangement.filmstrip(stage: focused, screens: call.screens) }
201 /// You float over the stage, rather than sit in the filmstrip, when
202 /// you would be all there is in it (see Stage.selfFloats).
203 var selfFloats: Bool { Stage.selfFloats(filmstrip: filmstrip, me: arrangement.me) }
204 /// Grid's tiles: the screens, newest first, then everyone in order.
205 var gridItems: [StageItem] {
206 call.screens.reversed().map(StageItem.screen) + arrangement.people.map(StageItem.camera)
207 }
208
209 /// A tile for anything the call can show, as it is seen now.
210 func macTile(
211 _ item: StageItem, cornerRadius: CGFloat = 16, compact: Bool = false, labelLift: CGFloat = 0,
212 backdrop: Color = .black, onStage: Bool = false, iconOnly: Bool = false
213 ) -> MacVideoTile {
214 let pinned = onStage && arrangement.pinned == item
215 switch item {
216 case .screen(let peer):
217 return MacVideoTile(
218 track: call.remoteScreens[peer], label: screenCaption(call.name(of: peer)), screen: true,
219 cornerRadius: cornerRadius, compact: compact, labelLift: labelLift, backdrop: backdrop,
220 onStage: onStage, pinned: pinned, iconOnly: iconOnly)
221 case .camera(let peer) where peer == arrangement.me:
222 return MacVideoTile(
223 track: call.localTrack, label: "You", muted: call.muted, mirrored: true,
224 cameraOff: call.cameraOff, placeholder: call.selfPlaceholder, cornerRadius: cornerRadius,
225 compact: compact, labelLift: labelLift, backdrop: backdrop, audio: call.selfAudio,
226 onStage: onStage, pinned: pinned, iconOnly: iconOnly, fixtureVideo: fixtureFeeds["me"])
227 case .camera(let peer):
228 return MacVideoTile(
229 track: call.remoteTracks[peer], label: call.name(of: peer), muted: call.isMuted(peer),
230 cameraOff: call.isCameraOff(peer), lowBandwidth: call.isLowBandwidth(peer),
231 videoPaused: call.isVideoPaused(peer) ? call.videoPausedWords(peer) : nil,
232 cornerRadius: cornerRadius, compact: compact,
233 labelLift: labelLift, backdrop: backdrop, audio: call.tileAudio(peer), onStage: onStage,
234 pinned: pinned, iconOnly: iconOnly, fixtureVideo: fixtureFeeds[peer])
235 }
236 }
237
238 /// The name a menu or VoiceOver uses for `item`.
239 func itemTitle(_ item: StageItem) -> String {
240 switch item {
241 case .screen(let peer): screenCaption(call.name(of: peer))
242 case .camera(let peer): peer == arrangement.me ? "You" : call.name(of: peer)
243 }
244 }
245
246 /// A tile of Grid or the filmstrip: dragged to a new place, pinned by
247 /// a click (the filmstrip) or its menu, and both said to VoiceOver.
248 func arrangeable(_ item: StageItem, tapToPin: Bool) -> ArrangeableTile {
249 ArrangeableTile(
250 item: item, title: itemTitle(item), arrangement: arrangement, drag: $drag,
251 frames: tileFrames, tapToPin: tapToPin, touch: false, reduceMotion: reduceMotion,
252 fixtureLift: item == .camera(arrangement.fixtureLift ?? "") ? CGSize(width: 36, height: -22) : nil)
253 }
254
255 var layoutPicker: some View {
256 Picker(
257 "Video layout",
258 selection: Binding(get: { arrangement.layout }, set: { arrangement.choose($0) })
259 ) {
260 ForEach(VideoLayout.allCases) { layout in
261 Label(layout.title, systemImage: layout.symbol).tag(layout)
262 }
263 }
264 }
265
266 /// Automatic, then every screen and every person, as pin choices.
267 @ViewBuilder var pinChoices: some View {
268 Button {
269 arrangement.pin(nil)
270 } label: {
271 Label(
272 "Whoever is speaking",
273 systemImage: arrangement.pinned == nil ? "checkmark" : "waveform")
274 }
275 ForEach(call.screens.reversed(), id: \.self) { peer in
276 pinChoice(.screen(peer))
277 }
278 ForEach(arrangement.people, id: \.self) { peer in
279 pinChoice(.camera(peer))
280 }
281 }
282
283 private func pinChoice(_ item: StageItem) -> some View {
284 Button {
285 arrangement.pin(item)
286 } label: {
287 Label(itemTitle(item), systemImage: arrangement.pinned == item ? "checkmark" : "pin")
288 }
289 }
290
291 var stageShowsScreen: Bool {
292 if case .screen = focused { return true }
293 return false
294 }
295
296 @ViewBuilder private var stage: some View {
297 if grid {
298 ScrollView {
299 LazyVGrid(columns: [GridItem(.adaptive(minimum: 240))], spacing: 12) {
300 ForEach(gridItems, id: \.self) { item in
301 macTile(item)
302 .aspectRatio(16 / 9, contentMode: .fit)
303 .modifier(arrangeable(item, tapToPin: false))
304 }
305 }
306 }
307 .coordinateSpace(name: arrangeSpace)
308 .onPreferenceChange(TileFramesKey.self) { tileFrames = $0 }
309 } else {
310 GeometryReader { geometry in
311 ZStack(alignment: .bottomTrailing) {
312 if let focused {
313 macTile(focused, onStage: true)
314 .overlay(alignment: .topTrailing) {
315 if arrangement.pinned == focused {
316 PinBadge(title: itemTitle(focused)) { arrangement.pin(nil) }.padding(10)
317 }
318 }
319 } else {
320 ContentUnavailableView(
321 "Waiting for others", systemImage: "person.2",
322 description: Text("Your meeting is ready. Others will appear here when they join.")
323 )
324 .frame(maxWidth: .infinity, maxHeight: .infinity)
325 .background(CallsAppearance.background, in: RoundedRectangle(cornerRadius: 16))
326 }
327 // Everyone not on the stage, as thumbnails up its trailing
328 // edge; in a call of two, just you.
329 let strip = selfFloats ? [StageItem.camera(arrangement.me ?? "")] : filmstrip
330 let size = thumbnail(count: strip.count, in: geometry.size)
331 VStack(spacing: 10) {
332 ForEach(strip, id: \.self) { item in
333 macTile(item)
334 .frame(width: size.width, height: size.height)
335 .modifier(arrangeable(item, tapToPin: !selfFloats))
336 }
337 }
338 .shadow(color: .black.opacity(0.25), radius: 8, y: 3).padding(14)
339 }
340 .coordinateSpace(name: arrangeSpace)
341 .onPreferenceChange(TileFramesKey.self) { tileFrames = $0 }
342 }
343 }
344 }
345
346 /// A thumbnail's size, when `count` of them stack up the stage's
347 /// trailing edge: the size one always had, until there are enough of
348 /// them that it would run off the top.
349 func thumbnail(count: Int, in stage: CGSize) -> CGSize {
350 let room = (stage.height - 28 - CGFloat(count - 1) * 10) / CGFloat(max(count, 1))
351 let height = max(60, min(135, stage.height * 0.3, room))
352 return CGSize(width: min(180, stage.width * 0.3, height * 4 / 3), height: height)
353 }
354
355 /// The controls this person's bar holds, in order (CallBarFit).
356 var barControls: [CallBarFit.Control] {
357 CallBarFit.Control.allCases.filter { $0 != .link || call.standing == "member" }
358 }
359
360 /// The call's buttons, in the classic row or the full-window bar. The
361 /// bar adds the layout menu (the classic view has its picker above the
362 /// stage) and tells the controls' visibility when one has focus.
363 /// `fit` is the full-window bar's, which may tighten them and move
364 /// some into ⋯ (CallBarFit); the classic row has none and shows
365 /// everything.
366 func controls(fullWindow: Bool, fit: CallBarFit? = nil) -> some View {
367 HStack(spacing: fit?.spacing.between ?? (fullWindow ? 10 : 12)) {
368 Button(
369 call.muted ? "Unmute microphone" : "Mute microphone",
370 glyph: call.muted ? "mic.slash.fill" : "mic.fill"
371 ) { call.mute() }
372 .buttonStyle(
373 CallActionStyle(
374 color: call.muted ? Color(red: 0.65, green: 0.30, blue: 0.02) : CallsAppearance.accent,
375 emphasized: call.muted, overlay: tone(fullWindow, call.muted ? .off : .normal))
376 )
377 .help(call.muted ? "Unmute microphone" : "Mute microphone")
378 .accessibilityIdentifier("mute")
379 .focused($focusedControl, equals: .mute)
380 .modifier(CallBarEndProbe(last: false))
381 Button(
382 call.cameraOff ? "Turn camera on" : "Turn camera off",
383 glyph: call.cameraOff ? "video.slash.fill" : "video.fill"
384 ) { call.toggleCamera() }
385 .buttonStyle(
386 CallActionStyle(
387 color: call.cameraOff ? Color(red: 0.65, green: 0.30, blue: 0.02) : .blue,
388 emphasized: call.cameraOff, overlay: tone(fullWindow, call.cameraOff ? .off : .normal))
389 )
390 .help(call.cameraOff ? "Turn camera on" : "Turn camera off")
391 .accessibilityIdentifier("camera")
392 .focused($focusedControl, equals: .camera)
393 if fit?.shows(.share) ?? true {
394 Button(
395 call.sharingScreen ? "Stop sharing your screen" : "Share your screen",
396 glyph: call.sharingScreen ? "rectangle.on.rectangle.slash" : "rectangle.on.rectangle"
397 ) {
398 if call.sharingScreen {
399 call.stopSharingScreen()
400 } else {
401 Task { await call.shareScreen(MacScreenCapture()) }
402 }
403 }
404 .buttonStyle(
405 CallActionStyle(
406 color: .orange, emphasized: call.sharingScreen,
407 overlay: tone(fullWindow, call.sharingScreen ? .on : .normal)))
408 .help(call.sharingScreen ? "Stop sharing your screen" : "Share a window or your whole screen")
409 .disabled(call.state?.phase != "admitted")
410 .accessibilityIdentifier("shareScreen")
411 .focused($focusedControl, equals: .share)
412 }
413 if fit?.shows(.devices) ?? true {
414 Button("Devices", glyph: "slider.horizontal.3") {
415 withAnimation(panelAnimation) { showingDevices.toggle() }
416 }
417 .buttonStyle(
418 CallActionStyle(
419 color: .teal, emphasized: showingDevices,
420 overlay: tone(fullWindow, showingDevices ? .on : .normal)))
421 .help("Choose the camera, microphone and speaker for this call")
422 .accessibilityIdentifier("devices")
423 .focused($focusedControl, equals: .devices)
424 }
425 if fullWindow, fit?.shows(.layout) ?? true {
426 layoutMenu.focused($focusedControl, equals: .layout)
427 }
428 if fit?.shows(.link) ?? true {
429 MeetingShareButton(call: call)
430 .buttonStyle(CallActionStyle(color: .indigo, overlay: tone(fullWindow, .normal)))
431 .help("Share meeting link")
432 .focused($focusedControl, equals: .link)
433 }
434 if let fit, !fit.overflow.isEmpty {
435 moreMenu(fit.overflow)
436 }
437 Spacer(minLength: fit?.spacing.gap ?? (fullWindow ? 24 : nil))
438 Button(chatTitle, glyph: "bubble.left.and.bubble.right.fill") {
439 if chatWindow.isOpen { chatWindow.close() }
440 withAnimation(panelAnimation) { showingChat.toggle() }
441 }.buttonStyle(
442 CallActionStyle(
443 color: .purple, emphasized: showingChat || chatWindow.isOpen,
444 overlay: tone(fullWindow, showingChat || chatWindow.isOpen ? .on : .normal)))
445 .help(chatTitle)
446 .accessibilityIdentifier("openChat")
447 .focused($focusedControl, equals: .chat)
448 .overlay(alignment: .topTrailing) {
449 if unread > 0 {
450 Text("\(unread)").font(.caption.bold()).foregroundStyle(.white)
451 .padding(4).background(fullWindow ? CallOverlay.badgeFill : .purple, in: Capsule())
452 .offset(x: 5, y: -5)
453 .accessibilityHidden(true)
454 }
455 }
456 .contextMenu {
457 Button("Open chat in a window", systemImage: "arrow.up.forward.app") {
458 showingChat = false
459 chatWindow.open(call: call)
460 }
461 }
462 Button("Leave meeting", glyph: "phone.down.fill", role: .destructive, action: leave)
463 .buttonStyle(CallActionStyle(color: .red, emphasized: true, overlay: tone(fullWindow, .leave)))
464 .help("Leave meeting")
465 .accessibilityIdentifier("leave")
466 .focused($focusedControl, equals: .leave)
467 .modifier(CallBarEndProbe(last: true))
468 }.frame(maxWidth: .infinity)
469 }
470
471 /// ⋯ on a bar too narrow for everything (CallBarFit): the controls
472 /// that did not fit, as menu items, in the bar's order.
473 private func moreMenu(_ overflow: [CallBarFit.Control]) -> some View {
474 Button("More controls", glyph: "ellipsis") { showingMore.toggle() }
475 .buttonStyle(CallActionStyle(color: .gray, emphasized: showingMore, overlay: showingMore ? .on : .normal))
476 .help("More controls")
477 .accessibilityIdentifier("moreControls")
478 .popover(isPresented: $showingMore, arrowEdge: .top) {
479 VStack(alignment: .leading, spacing: 10) {
480 ForEach(overflow, id: \.self) { control in
481 moreItem(control)
482 }
483 // Spec §15.26: wherever the bar has a ⋯, "Report a problem"
484 // is in it, as it is in the ⓘ panel and the Call menu.
485 Divider()
486 Button(ProblemWords.title, systemImage: "exclamationmark.bubble") {
487 showingMore = false
488 // The popover goes first: a sheet asked for while it is
489 // still closing is not shown (DevicePanel's same wait).
490 DispatchQueue.main.asyncAfter(deadline: .now() + DevicePanel.handOver) { call.reportProblem() }
491 }
492 .accessibilityIdentifier("moreReportProblem")
493 }
494 .buttonStyle(.borderless)
495 .padding(14)
496 .frame(minWidth: 220, alignment: .leading)
497 }
498 .sheet(isPresented: $showingInvitation) {
499 MeetingInvitationView(call: call, close: { showingInvitation = false })
500 .task { await call.loadInvitation() }
501 }
502 }
503
504 @ViewBuilder private func moreItem(_ control: CallBarFit.Control) -> some View {
505 switch control {
506 case .share:
507 Button(
508 call.sharingScreen ? "Stop sharing your screen" : "Share your screen",
509 systemImage: call.sharingScreen ? "rectangle.on.rectangle.slash" : "rectangle.on.rectangle"
510 ) {
511 showingMore = false
512 if call.sharingScreen {
513 call.stopSharingScreen()
514 } else {
515 Task { await call.shareScreen(MacScreenCapture()) }
516 }
517 }
518 .disabled(call.state?.phase != "admitted")
519 case .devices:
520 Button(showingDevices ? "Hide devices" : "Devices", systemImage: "slider.horizontal.3") {
521 showingMore = false
522 withAnimation(panelAnimation) { showingDevices.toggle() }
523 }
524 case .layout:
525 layoutPicker.pickerStyle(.segmented).labelsHidden().fixedSize()
526 if !grid, peers.count > 1 || !call.screens.isEmpty {
527 Text("On the stage").font(.headline)
528 VStack(alignment: .leading, spacing: 6) { pinChoices }
529 }
530 case .link:
531 Button("Share meeting link", systemImage: "square.and.arrow.up") {
532 showingMore = false
533 showingInvitation = true
534 }
535 default:
536 EmptyView()
537 }
538 }
539
540 /// Speaker or Grid, and in Speaker, what is pinned to the stage: the
541 /// classic view's picker and pin menu, folded into one bar button and
542 /// the small popover it opens.
543 private var layoutMenu: some View {
544 Button(
545 "Video layout", glyph: arrangement.layout.symbol
546 ) { showingLayout.toggle() }
547 .buttonStyle(CallActionStyle(color: .gray, emphasized: showingLayout, overlay: showingLayout ? .on : .normal))
548 .help("Video layout: Speaker or Grid, and who is pinned to the stage")
549 .accessibilityIdentifier("videoLayout")
550 .popover(isPresented: $showingLayout, arrowEdge: .top) {
551 VStack(alignment: .leading, spacing: 12) {
552 layoutPicker.pickerStyle(.segmented).labelsHidden().fixedSize()
553 if peers.count > 1 || !call.screens.isEmpty {
554 Text("On the stage").font(.headline)
555 VStack(alignment: .leading, spacing: 6) { pinChoices }
556 .buttonStyle(.borderless)
557 }
558 }
559 .padding(14)
560 .frame(minWidth: 220, alignment: .leading)
561 }
562 }
563
564 /// The full-window bar's look for a button in `state`; the classic
565 /// row keeps its own colours.
566 private func tone(_ fullWindow: Bool, _ state: CallOverlayButtonStyle.Tone)
567 -> CallOverlayButtonStyle.Tone?
568 {
569 fullWindow ? state : nil
570 }
571
572 var panelAnimation: Animation? {
573 reduceMotion ? .linear(duration: 0.1) : .easeOut(duration: 0.2)
574 }
575
576 var unread: Int { max(0, call.receivedChatCount - readChatCount) }
577 var chatTitle: String {
578 chatWindow.isOpen
579 ? "Move chat into the sidebar"
580 : unread > 0 ? "Chat (\(unread) new)" : showingChat ? "Hide chat" : "Show chat"
581 }
582 }
583#endif
584