Skip to content

Commit

Permalink
Merge pull request #7 from banjun/borderless
Browse files Browse the repository at this point in the history
Use borderless window during non-active
  • Loading branch information
banjun authored Dec 20, 2017
2 parents 6ef0347 + 436ea7c commit 9df8ff9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions PhotoStudioPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
13CD48001FE9CA96002F23F8 /* ChromaKeyFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13CD47FF1FE9CA96002F23F8 /* ChromaKeyFilter.swift */; };
13CD48021FEA7E58002F23F8 /* BorderlessWindowDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13CD48011FEA7E58002F23F8 /* BorderlessWindowDelegate.swift */; };
EA7073111FAC34FC00EF0DC9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7073101FAC34FC00EF0DC9 /* AppDelegate.swift */; };
EA7073131FAC34FC00EF0DC9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7073121FAC34FC00EF0DC9 /* ViewController.swift */; };
EA7073151FAC34FC00EF0DC9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EA7073141FAC34FC00EF0DC9 /* Assets.xcassets */; };
Expand All @@ -16,6 +17,7 @@

/* Begin PBXFileReference section */
13CD47FF1FE9CA96002F23F8 /* ChromaKeyFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaKeyFilter.swift; sourceTree = "<group>"; };
13CD48011FEA7E58002F23F8 /* BorderlessWindowDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorderlessWindowDelegate.swift; sourceTree = "<group>"; };
EA70730D1FAC34FC00EF0DC9 /* PhotoStudioPlayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PhotoStudioPlayer.app; sourceTree = BUILT_PRODUCTS_DIR; };
EA7073101FAC34FC00EF0DC9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
EA7073121FAC34FC00EF0DC9 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -56,6 +58,7 @@
isa = PBXGroup;
children = (
EA7073101FAC34FC00EF0DC9 /* AppDelegate.swift */,
13CD48011FEA7E58002F23F8 /* BorderlessWindowDelegate.swift */,
EA7073121FAC34FC00EF0DC9 /* ViewController.swift */,
13CD47FF1FE9CA96002F23F8 /* ChromaKeyFilter.swift */,
EA7073141FAC34FC00EF0DC9 /* Assets.xcassets */,
Expand Down Expand Up @@ -139,6 +142,7 @@
buildActionMask = 2147483647;
files = (
EA7073131FAC34FC00EF0DC9 /* ViewController.swift in Sources */,
13CD48021FEA7E58002F23F8 /* BorderlessWindowDelegate.swift in Sources */,
13CD48001FE9CA96002F23F8 /* ChromaKeyFilter.swift in Sources */,
EA7073111FAC34FC00EF0DC9 /* AppDelegate.swift in Sources */,
);
Expand Down
10 changes: 6 additions & 4 deletions PhotoStudioPlayer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
static let AppGlobalStateDidChange = NSNotification.Name(rawValue: "AppGlobalStateDidChange")

private var windowControllers = [NSWindowController]()
private let windowDelegate = BorderlessWindowDelegate()

@objc var enabledCaptureFrame = false {
didSet {
Expand Down Expand Up @@ -55,16 +56,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
return
}

guard let window = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil).instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("Window")) as? NSWindowController else {
guard let windowController = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil).instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("Window")) as? NSWindowController else {
return
}
self.windowControllers.append(window)
windowController.window?.delegate = windowDelegate
self.windowControllers.append(windowController)

guard let vc = window.contentViewController as? ViewController else {
guard let vc = windowController.contentViewController as? ViewController else {
return
}
vc.device = self.availableDevices().first { $0.uniqueID == uniqueID }
window.showWindow(nil)
windowController.showWindow(nil)
}

private func availableDevices() -> [AVCaptureDevice] {
Expand Down
24 changes: 24 additions & 0 deletions PhotoStudioPlayer/BorderlessWindowDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// BorderlessWindowDelegate.swift
// PhotoStudioPlayer
//
// Created by mzp on 2017/12/20.
// Copyright © 2017 banjun. All rights reserved.
//
import Cocoa

class BorderlessWindowDelegate: NSObject, NSWindowDelegate {
func windowDidBecomeKey(_ notification: Notification) {
guard let window = notification.object as? NSWindow else {
return
}
window.styleMask = [.titled, .fullSizeContentView, .closable, .miniaturizable, .resizable]

}
func windowDidResignKey(_ notification: Notification) {
guard let window = notification.object as? NSWindow else {
return
}
window.styleMask = [.titled, .fullSizeContentView, .borderless]
}
}

0 comments on commit 9df8ff9

Please sign in to comment.