Skip to content

Commit

Permalink
Cocoa based implementation, fullscreen mode
Browse files Browse the repository at this point in the history
Move from SwiftUI to NSApplication
Implement system-wide fullscreen overlay
Ignore mouse events
  • Loading branch information
starkdmi committed Mar 31, 2023
1 parent efc6d7a commit c591388
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 133 deletions.
22 changes: 14 additions & 8 deletions BrightXDR.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
objects = {

/* Begin PBXBuildFile section */
1DCF1F4F29D2FABA005D14C3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DCF1F4E29D2FABA005D14C3 /* App.swift */; };
1D2D10E429D7777200D7A887 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2D10E329D7777200D7A887 /* main.swift */; };
1D2D10E629D7778100D7A887 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2D10E529D7778100D7A887 /* AppDelegate.swift */; };
1DCF1F5329D2FABB005D14C3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1DCF1F5229D2FABB005D14C3 /* Assets.xcassets */; };
1DCF1F5E29D2FBB5005D14C3 /* TransparentWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DCF1F5D29D2FBB5005D14C3 /* TransparentWindow.swift */; };
1DCF1F6029D2FBD9005D14C3 /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DCF1F5F29D2FBD9005D14C3 /* MetalView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
1D2D10E329D7777200D7A887 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
1D2D10E529D7778100D7A887 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
1D2D10E729D777EA00D7A887 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
1DCF1F4B29D2FABA005D14C3 /* BrightXDR.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BrightXDR.app; sourceTree = BUILT_PRODUCTS_DIR; };
1DCF1F4E29D2FABA005D14C3 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
1DCF1F5229D2FABB005D14C3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
1DCF1F5729D2FABB005D14C3 /* BrightXDR.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = BrightXDR.entitlements; sourceTree = "<group>"; };
1DCF1F5D29D2FBB5005D14C3 /* TransparentWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransparentWindow.swift; sourceTree = "<group>"; };
1DCF1F5F29D2FBD9005D14C3 /* MetalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetalView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -52,9 +53,10 @@
1DCF1F4D29D2FABA005D14C3 /* BrightXDR */ = {
isa = PBXGroup;
children = (
1DCF1F4E29D2FABA005D14C3 /* App.swift */,
1D2D10E729D777EA00D7A887 /* Info.plist */,
1D2D10E329D7777200D7A887 /* main.swift */,
1D2D10E529D7778100D7A887 /* AppDelegate.swift */,
1DCF1F5F29D2FBD9005D14C3 /* MetalView.swift */,
1DCF1F5D29D2FBB5005D14C3 /* TransparentWindow.swift */,
1DCF1F5229D2FABB005D14C3 /* Assets.xcassets */,
1DCF1F5729D2FABB005D14C3 /* BrightXDR.entitlements */,
);
Expand Down Expand Up @@ -131,8 +133,8 @@
buildActionMask = 2147483647;
files = (
1DCF1F6029D2FBD9005D14C3 /* MetalView.swift in Sources */,
1DCF1F5E29D2FBB5005D14C3 /* TransparentWindow.swift in Sources */,
1DCF1F4F29D2FABA005D14C3 /* App.swift in Sources */,
1D2D10E429D7777200D7A887 /* main.swift in Sources */,
1D2D10E629D7778100D7A887 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -266,8 +268,10 @@
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = BrightXDR/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Bright XDR";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -296,8 +300,10 @@
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = BrightXDR/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Bright XDR";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "7B8C64E6-FB6D-40E6-BF89-2F09C5B82A54"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "2D99A84E-BC09-4FC0-90AF-0FD9F7B6F491"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BrightXDR/AppDelegate.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "39"
endingLineNumber = "39"
landmarkName = "applicationDidFinishLaunching(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "04D399E1-E8C3-426C-9953-48172FA223C4"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BrightXDR/AppDelegate.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "36"
endingLineNumber = "36"
landmarkName = "applicationDidFinishLaunching(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
17 changes: 0 additions & 17 deletions BrightXDR/App.swift

This file was deleted.

50 changes: 50 additions & 0 deletions BrightXDR/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// AppDelegate.swift
// BrightXDR
//
// Created by Dmitry Starkov on 31/03/2023.
//

import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {
// The overlay window
private var window: NSWindow!

// The MTKView instance
private var metalView: MetalView!

func applicationDidFinishLaunching(_ aNotification: Notification) {
guard let mainScreen = NSScreen.main else { return }

// let splitViewRect = NSRect(x: mainScreen.frame.width/2, y: 0, width: mainScreen.frame.width/2, height: mainScreen.frame.height)
let fullScreenRect = NSRect(x: 0, y: 0, width: mainScreen.frame.width, height: mainScreen.frame.height)

// Create a new transparent, borderless window
window = NSWindow(contentRect: fullScreenRect, styleMask: [.borderless], backing: .buffered, defer: false)
window.isOpaque = false
window.backgroundColor = NSColor.clear
// Ignore all mouse events
window.ignoresMouseEvents = true

// Set the window's level to mainMenu to make it float above all other windows
// Requires "Application is agent (UIElement)" set to "YES" in info.plist for system-wide support
// The maximum possible values is NSWindow.Level(rawValue: Int(CGShieldingWindowLevel() + 19))
window.level = NSWindow.Level.mainMenu

// Allow window to overlay in Mission Control and Spaces
window.collectionBehavior = [.stationary, .canJoinAllSpaces, .fullScreenAuxiliary, .ignoresCycle, .managed]

// Keep visible all time (required for overlays)
window.hidesOnDeactivate = false

// Add metal view with HDR overlay
guard let view = window.contentView else { return }
metalView = MetalView(frame: view.bounds)
metalView.autoresizingMask = [.width, .height]
view.addSubview(metalView)

// Present the window
window.makeKeyAndOrderFront(nil)
}
}
5 changes: 5 additions & 0 deletions BrightXDR/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
Loading

0 comments on commit c591388

Please sign in to comment.