Mission Control Turbo: macOS multitasking turbocharged
1import SwiftUI
2
3/// Displays a window thumbnail with an always-visible title below it.
4struct WindowThumbnailView: View {
5 let windowInfo: WindowInfo
6 let size: CGSize
7 let isSelected: Bool
8 var showAppBadge: Bool = true
9
10 private var thumbnailHeight: CGFloat {
11 size.height - LayoutGeometry.titleHeight
12 }
13
14 var body: some View {
15 VStack(spacing: 0) {
16 // Thumbnail
17 ZStack(alignment: .topLeading) {
18 RoundedRectangle(cornerRadius: 8)
19 .fill(.ultraThinMaterial)
20
21 if let thumbnail = windowInfo.thumbnail {
22 Image(decorative: thumbnail, scale: 1.0)
23 .resizable()
24 .scaledToFill()
25 .frame(width: size.width, height: thumbnailHeight)
26 .clipped()
27 .clipShape(RoundedRectangle(cornerRadius: 6))
28 } else {
29 Image(systemName: "macwindow")
30 .font(.system(size: min(32, size.width * 0.3)))
31 .foregroundStyle(.secondary)
32 .frame(maxWidth: .infinity, maxHeight: .infinity)
33 }
34
35 // App icon badge in compact mode
36 if showAppBadge, let icon = windowInfo.appIcon {
37 Image(nsImage: icon)
38 .resizable()
39 .frame(width: 80, height: 80)
40 .shadow(color: .black.opacity(0.5), radius: 3)
41 .padding(6)
42 }
43 }
44 .frame(width: size.width, height: thumbnailHeight)
45 .overlay(
46 RoundedRectangle(cornerRadius: 8)
47 .stroke(isSelected ? Color.accentColor : Color.white.opacity(0.2), lineWidth: isSelected ? 3 : 1)
48 )
49 .shadow(color: .black.opacity(0.3), radius: isSelected ? 8 : 4)
50
51 // Always-visible title (includes app name in compact mode)
52 Text(displayTitle)
53 .font(.system(size: 16, weight: .medium))
54 .foregroundStyle(.white)
55 .lineLimit(1)
56 .truncationMode(.middle)
57 .frame(width: size.width, height: LayoutGeometry.titleHeight)
58 }
59 .contentShape(Rectangle())
60 }
61
62 private var displayTitle: String {
63 return "\(windowInfo.appName) — \(windowInfo.title)"
64 }
65}