replace NSVisualEffectView with ultraThinMaterial plus a background color

This commit is contained in:
Aaron Ruan
2025-04-25 10:42:22 +08:00
parent 3827ce9e4c
commit 1acb1715c3
2 changed files with 19 additions and 18 deletions

View File

@ -18,6 +18,7 @@ struct CommandOption: Identifiable, Hashable {
struct CommandPaletteView: View { struct CommandPaletteView: View {
@Binding var isPresented: Bool @Binding var isPresented: Bool
var backgroundColor: Color = Color(nsColor: .windowBackgroundColor)
var options: [CommandOption] var options: [CommandOption]
@State private var query = "" @State private var query = ""
@State private var selectedIndex: UInt? @State private var selectedIndex: UInt?
@ -43,6 +44,12 @@ struct CommandPaletteView: View {
} }
var body: some View { var body: some View {
@State var scheme: ColorScheme = if OSColor(backgroundColor).isLightColor {
.light
} else {
.dark
}
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
CommandPaletteQuery(query: $query) { event in CommandPaletteQuery(query: $query) { event in
switch (event) { switch (event) {
@ -98,7 +105,16 @@ struct CommandPaletteView: View {
} }
} }
.frame(maxWidth: 500) .frame(maxWidth: 500)
.background(BackgroundVisualEffectView()) .background(
ZStack {
Rectangle()
.fill(.ultraThinMaterial)
Rectangle()
.fill(backgroundColor)
.blendMode(.color)
}
.compositingGroup()
)
.clipShape(RoundedRectangle(cornerRadius: 10)) .clipShape(RoundedRectangle(cornerRadius: 10))
.overlay( .overlay(
RoundedRectangle(cornerRadius: 10) RoundedRectangle(cornerRadius: 10)
@ -106,6 +122,7 @@ struct CommandPaletteView: View {
) )
.shadow(radius: 32, x: 0, y: 12) .shadow(radius: 32, x: 0, y: 12)
.padding() .padding()
.environment(\.colorScheme, scheme)
} }
} }
@ -244,23 +261,6 @@ fileprivate struct CommandRow: View {
} }
} }
/// A view that creates a semi-transparent blurry background.
fileprivate struct BackgroundVisualEffectView: NSViewRepresentable {
func makeNSView(context: Context) -> NSVisualEffectView {
let view = NSVisualEffectView()
view.blendingMode = .withinWindow
view.state = .active
view.material = .sidebar
return view
}
func updateNSView(_ nsView: NSVisualEffectView, context: Context) {
//
}
}
/// A row of Text representing a shortcut. /// A row of Text representing a shortcut.
fileprivate struct ShortcutSymbolsView: View { fileprivate struct ShortcutSymbolsView: View {
let symbols: [String] let symbols: [String]

View File

@ -59,6 +59,7 @@ struct TerminalCommandPaletteView: View {
CommandPaletteView( CommandPaletteView(
isPresented: $isPresented, isPresented: $isPresented,
backgroundColor: ghosttyConfig.backgroundColor,
options: commandOptions options: commandOptions
) )
.transition( .transition(