Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 62 additions & 32 deletions AKPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,20 @@ private struct AKAppSettingsData: Codable {
var resolution: Int?
var resizableAspectRatioWidth: Int?
var resizableAspectRatioHeight: Int?
var appearanceStyle: Int?
}

class AKPlugin: NSObject, Plugin {
fileprivate static let windowVisibilityDidChangeNotification =
Notification.Name("PTWindowVisibilityDidChangeNotification")

required override init() {
super.init()
if let window = NSApplication.shared.windows.first {
window.styleMask.insert([.resizable])
window.collectionBehavior = [.fullScreenPrimary, .managed, .participatesInCycle]
window.isMovable = true
window.isMovableByWindowBackground = true

if self.hideTitleBarSetting == true {
window.styleMask.insert([.fullSizeContentView])
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
window.toolbar = nil
window.title = ""
}

if self.floatingWindowSetting == true {
window.level = .floating
}

configureAppearance(for: window, initial: true)
if let aspectRatio = self.aspectRatioSetting {
window.contentAspectRatio = aspectRatio
}

NSWindow.allowsAutomaticWindowTabbing = true
}

Expand All @@ -52,24 +39,13 @@ class AKPlugin: NSObject, Plugin {
object: nil,
queue: .main) { notif in
guard let win = notif.object as? NSWindow else { return }
win.styleMask.insert([.resizable])

if self.hideTitleBarSetting == true {
win.styleMask.insert([.fullSizeContentView])
win.titlebarAppearsTransparent = true
win.titleVisibility = .hidden
win.toolbar = nil
win.title = ""
}

if self.floatingWindowSetting == true {
win.level = .floating
}

self.configureAppearance(for: win, initial: false)
if let aspectRatio = self.aspectRatioSetting {
win.contentAspectRatio = aspectRatio
}
}

installVisibilityObservers()
}

var screenCount: Int {
Expand All @@ -96,6 +72,18 @@ class AKPlugin: NSObject, Plugin {
NSApplication.shared.windows.first!.styleMask.contains(.fullScreen)
}

var isApplicationActive: Bool { NSApplication.shared.isActive }

var hasVisibleUnminiaturizedWindow: Bool {
NSApplication.shared.windows.contains { $0.isVisible && !$0.isMiniaturized }
}

var hasUnoccludedVisibleWindow: Bool {
NSApplication.shared.windows.contains {
$0.isVisible && !$0.isMiniaturized && $0.occlusionState.contains(.visible)
}
}

var cmdPressed: Bool = false
var cursorHideLevel = 0
func hideCursor() {
Expand Down Expand Up @@ -290,6 +278,7 @@ class AKPlugin: NSObject, Plugin {
/// Convenience instance property that exposes the cached static preference.
private var hideTitleBarSetting: Bool { Self.akAppSettingsData?.hideTitleBar ?? false }
private var floatingWindowSetting: Bool { Self.akAppSettingsData?.floatingWindow ?? false }
fileprivate var appearanceStyleSetting: Int { Self.akAppSettingsData?.appearanceStyle ?? 0 }
private var aspectRatioSetting: NSSize? {
guard Self.akAppSettingsData?.resolution == 6 else {
return nil
Expand All @@ -314,3 +303,44 @@ class AKPlugin: NSObject, Plugin {
return decoded
}()
}

private extension AKPlugin {
func configureAppearance(for window: NSWindow, initial: Bool) {
if appearanceStyleSetting == 1 {
window.appearance = NSAppearance(named: .aqua)
} else if appearanceStyleSetting == 2 {
window.appearance = NSAppearance(named: .darkAqua)
}
window.styleMask.insert([.resizable])
if initial {
window.collectionBehavior = [.fullScreenPrimary, .managed, .participatesInCycle]
window.isMovable = true
window.isMovableByWindowBackground = true
}
if hideTitleBarSetting {
window.styleMask.insert([.fullSizeContentView])
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
window.toolbar = nil
window.title = ""
}
if floatingWindowSetting {
window.level = .floating
}
}

func installVisibilityObservers() {
for name: Notification.Name in [
NSWindow.didChangeOcclusionStateNotification,
NSWindow.didMiniaturizeNotification,
NSWindow.didDeminiaturizeNotification,
NSApplication.didHideNotification,
NSApplication.didUnhideNotification
] {
NotificationCenter.default.addObserver(forName: name, object: nil, queue: .main) { [weak self] _ in
guard let self else { return }
NotificationCenter.default.post(name: Self.windowVisibilityDidChangeNotification, object: self)
}
}
}
}
8 changes: 8 additions & 0 deletions PlayTools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
95D474FB2C0BA77B0072797F /* JoystickElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D474FA2C0BA77B0072797F /* JoystickElement.swift */; };
95D474FF2C0BDAB20072797F /* DraggableButtonElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D474FE2C0BDAB20072797F /* DraggableButtonElement.swift */; };
AA71970B287A44D200623C15 /* PlayLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = AA719702287A44D200623C15 /* PlayLoader.m */; };
E1F2A3B4C5D60718293A4B03 /* PlayEfficiencyHooks.h in Headers */ = {isa = PBXBuildFile; fileRef = E1F2A3B4C5D60718293A4B01 /* PlayEfficiencyHooks.h */; };
E1F2A3B4C5D60718293A4B04 /* PlayEfficiencyHooks.m in Sources */ = {isa = PBXBuildFile; fileRef = E1F2A3B4C5D60718293A4B02 /* PlayEfficiencyHooks.m */; };
AA71970D287A44D200623C15 /* PlaySettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA719704287A44D200623C15 /* PlaySettings.swift */; };
AA71970E287A44D200623C15 /* PlayLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = AA719705287A44D200623C15 /* PlayLoader.h */; };
AA71970F287A44D200623C15 /* PlayCover.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA719706287A44D200623C15 /* PlayCover.swift */; };
Expand Down Expand Up @@ -146,6 +148,8 @@
95D474FE2C0BDAB20072797F /* DraggableButtonElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraggableButtonElement.swift; sourceTree = "<group>"; };
AA7196D8287A447700623C15 /* PlayTools.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PlayTools.framework; sourceTree = BUILT_PRODUCTS_DIR; };
AA719702287A44D200623C15 /* PlayLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayLoader.m; sourceTree = "<group>"; };
E1F2A3B4C5D60718293A4B01 /* PlayEfficiencyHooks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlayEfficiencyHooks.h; sourceTree = "<group>"; };
E1F2A3B4C5D60718293A4B02 /* PlayEfficiencyHooks.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayEfficiencyHooks.m; sourceTree = "<group>"; };
AA719704287A44D200623C15 /* PlaySettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlaySettings.swift; sourceTree = "<group>"; };
AA719705287A44D200623C15 /* PlayLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlayLoader.h; sourceTree = "<group>"; };
AA719706287A44D200623C15 /* PlayCover.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayCover.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -450,6 +454,8 @@
AA719706287A44D200623C15 /* PlayCover.swift */,
AA719705287A44D200623C15 /* PlayLoader.h */,
AA719702287A44D200623C15 /* PlayLoader.m */,
E1F2A3B4C5D60718293A4B01 /* PlayEfficiencyHooks.h */,
E1F2A3B4C5D60718293A4B02 /* PlayEfficiencyHooks.m */,
AA719708287A44D200623C15 /* PlayTools.h */,
2847AE47298EFC0F00B0F983 /* PlayScreen.swift */,
);
Expand Down Expand Up @@ -576,6 +582,7 @@
AA71986D287A81A000623C15 /* PTFakeMetaTouch.h in Headers */,
AA719870287A81A000623C15 /* UIEvent+Private.h in Headers */,
AA71970E287A44D200623C15 /* PlayLoader.h in Headers */,
E1F2A3B4C5D60718293A4B03 /* PlayEfficiencyHooks.h in Headers */,
AA719872287A81A000623C15 /* UITouch+Private.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -758,6 +765,7 @@
AA7197AA287A481500623C15 /* Toast.swift in Sources */,
AA719789287A480D00623C15 /* PlayInput.swift in Sources */,
AA71970B287A44D200623C15 /* PlayLoader.m in Sources */,
E1F2A3B4C5D60718293A4B04 /* PlayEfficiencyHooks.m in Sources */,
9555ED332C058E36006E469C /* DebugController.swift in Sources */,
9562D1512AB484C7002C329D /* EventAdapters.swift in Sources */,
AA7197AF287A481500623C15 /* KeyCodeNames.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions PlayTools/PlayCover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PlayCover: NSObject {
PlayScreen.shared.initialize()
PlayInput.shared.initialize()
DiscordIPC.shared.initialize()
PlayInfo.installPowerStateHooksIfNeeded()

if PlaySettings.shared.rootWorkDir {
// Change the working directory to / just like iOS
Expand Down
20 changes: 20 additions & 0 deletions PlayTools/PlayEfficiencyHooks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// PlayEfficiencyHooks.h
// PlayTools
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface PTEfficiencyHooks : NSObject

+ (void)installIfNeeded;
+ (void)trimRegisteredNSCaches;
+ (NSInteger)currentEffectiveFPSCeiling;
+ (BOOL)isFPSOverlayInstalled;
+ (BOOL)isAdaptiveMotionHoldActive;

@end

NS_ASSUME_NONNULL_END
Loading