aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Shared
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-05-01 21:22:18 -0700
committerDustin Mierau <dustin@mierau.me>2024-05-01 21:32:15 -0700
commit60a3f2d29dfff945f59787f5a7786c6e78ba7bb9 (patch)
treee3d0aa6ae541790ea700353b0ac01fe8b4950f9f /Hotline/Shared
parentb9529a0d255ad41c62a4e3b93a47ebb5bb82a565 (diff)
New Hotline toolbar window for banner.
Diffstat (limited to 'Hotline/Shared')
-rw-r--r--Hotline/Shared/HotlinePanel.swift48
-rw-r--r--Hotline/Shared/VisualEffectView.swift22
2 files changed, 70 insertions, 0 deletions
diff --git a/Hotline/Shared/HotlinePanel.swift b/Hotline/Shared/HotlinePanel.swift
new file mode 100644
index 0000000..60d1337
--- /dev/null
+++ b/Hotline/Shared/HotlinePanel.swift
@@ -0,0 +1,48 @@
+import Cocoa
+import SwiftUI
+
+class HotlinePanel: NSPanel {
+ init(_ view: HotlinePanelView) {
+ super.init(contentRect: .zero, styleMask: [.nonactivatingPanel, .titled, .closable, .utilityWindow, .fullSizeContentView], backing: .buffered, defer: false)
+
+ // Make sure that the panel is in front of almost all other windows
+ self.isFloatingPanel = false
+ self.level = .floating
+ self.hidesOnDeactivate = true
+ self.animationBehavior = .utilityWindow
+
+ // Allow the panel to appear in a fullscreen space
+ self.collectionBehavior.insert(.fullScreenAuxiliary)
+
+ // Don't delete panel state when it's closed.
+ self.isReleasedWhenClosed = false
+
+ self.standardWindowButton(.closeButton)?.isHidden = true
+ self.standardWindowButton(.zoomButton)?.isHidden = true
+ self.standardWindowButton(.miniaturizeButton)?.isHidden = true
+
+ // Make it transparent, the view inside will have to set the background.
+ // This is necessary because otherwise, we will have some space for the titlebar on top of the height of the view itself which we don't want.
+ self.isOpaque = false
+ self.backgroundColor = .clear
+
+ // Since we don't show a statusbar, this allows us to drag the window by its background instead of the titlebar.
+ self.isMovableByWindowBackground = true
+ self.titlebarAppearsTransparent = true
+
+ let hostingView = NSHostingView(rootView: view.edgesIgnoringSafeArea(.top))
+ hostingView.sizingOptions = [.standardBounds]
+
+ self.contentView = hostingView
+
+ self.cascadeTopLeft(from: NSMakePoint(16, 16))
+ }
+
+ override var canBecomeKey: Bool {
+ return false
+ }
+
+ override var canBecomeMain: Bool {
+ return false
+ }
+}
diff --git a/Hotline/Shared/VisualEffectView.swift b/Hotline/Shared/VisualEffectView.swift
new file mode 100644
index 0000000..e595c55
--- /dev/null
+++ b/Hotline/Shared/VisualEffectView.swift
@@ -0,0 +1,22 @@
+import SwiftUI
+
+struct VisualEffectView: NSViewRepresentable
+{
+ let material: NSVisualEffectView.Material
+ let blendingMode: NSVisualEffectView.BlendingMode
+
+ func makeNSView(context: Context) -> NSVisualEffectView
+ {
+ let visualEffectView = NSVisualEffectView()
+ visualEffectView.material = material
+ visualEffectView.blendingMode = blendingMode
+ visualEffectView.state = NSVisualEffectView.State.active
+ return visualEffectView
+ }
+
+ func updateNSView(_ visualEffectView: NSVisualEffectView, context: Context)
+ {
+ visualEffectView.material = material
+ visualEffectView.blendingMode = blendingMode
+ }
+}