mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-29 08:04:32 +00:00
Restored files from old Mac, force pushing
This commit is contained in:
parent
5dd95228b8
commit
5040381840
126 changed files with 10431 additions and 67 deletions
76
DynamicIsland/private/CGSSpace.swift
Normal file
76
DynamicIsland/private/CGSSpace.swift
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// CGSSpace.swift
|
||||
// boringNotch
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
//
|
||||
// Original source: https://github.com/avaidyam/Parrot/
|
||||
// Modified by Alexander Greco on 2024-10-27
|
||||
|
||||
import AppKit
|
||||
|
||||
/// Small Spaces API wrapper.
|
||||
public final class CGSSpace {
|
||||
private let identifier: CGSSpaceID
|
||||
private let createdByInit: Bool
|
||||
|
||||
public var windows: Set<NSWindow> = [] {
|
||||
didSet {
|
||||
let remove = oldValue.subtracting(self.windows)
|
||||
let add = self.windows.subtracting(oldValue)
|
||||
|
||||
CGSRemoveWindowsFromSpaces(_CGSDefaultConnection(),
|
||||
remove.map { $0.windowNumber } as NSArray,
|
||||
[self.identifier])
|
||||
CGSAddWindowsToSpaces(_CGSDefaultConnection(),
|
||||
add.map { $0.windowNumber } as NSArray,
|
||||
[self.identifier])
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialized `CGSSpace`s *MUST* be de-initialized upon app exit!
|
||||
public init(level: Int = 0) {
|
||||
let flag = 0x1 // this value MUST be 1, otherwise, Finder decides to draw desktop icons
|
||||
self.identifier = CGSSpaceCreate(_CGSDefaultConnection(), flag, nil)
|
||||
CGSSpaceSetAbsoluteLevel(_CGSDefaultConnection(), self.identifier, level)
|
||||
CGSShowSpaces(_CGSDefaultConnection(), [self.identifier])
|
||||
self.createdByInit = true // Mark as created by the first init
|
||||
}
|
||||
|
||||
public init(id: UInt64) {
|
||||
let flag = 0x1 // this value MUST be 1, otherwise, Finder decides to draw desktop icons
|
||||
self.identifier = id
|
||||
CGSShowSpaces(_CGSDefaultConnection(), [self.identifier])
|
||||
self.createdByInit = false // Mark as created externally
|
||||
}
|
||||
|
||||
deinit {
|
||||
CGSHideSpaces(_CGSDefaultConnection(), [self.identifier])
|
||||
// Only call CGSSpaceDestroy if the space was created by the first init
|
||||
if createdByInit {
|
||||
CGSSpaceDestroy(_CGSDefaultConnection(), self.identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CGSSpace stuff:
|
||||
fileprivate typealias CGSConnectionID = UInt
|
||||
fileprivate typealias CGSSpaceID = UInt64
|
||||
@_silgen_name("_CGSDefaultConnection")
|
||||
fileprivate func _CGSDefaultConnection() -> CGSConnectionID
|
||||
@_silgen_name("CGSSpaceCreate")
|
||||
fileprivate func CGSSpaceCreate(_ cid: CGSConnectionID, _ unknown: Int, _ options: NSDictionary?) -> CGSSpaceID
|
||||
@_silgen_name("CGSSpaceDestroy")
|
||||
fileprivate func CGSSpaceDestroy(_ cid: CGSConnectionID, _ space: CGSSpaceID)
|
||||
@_silgen_name("CGSSpaceSetAbsoluteLevel")
|
||||
fileprivate func CGSSpaceSetAbsoluteLevel(_ cid: CGSConnectionID, _ space: CGSSpaceID, _ level: Int)
|
||||
@_silgen_name("CGSAddWindowsToSpaces")
|
||||
fileprivate func CGSAddWindowsToSpaces(_ cid: CGSConnectionID, _ windows: NSArray, _ spaces: NSArray)
|
||||
@_silgen_name("CGSRemoveWindowsFromSpaces")
|
||||
fileprivate func CGSRemoveWindowsFromSpaces(_ cid: CGSConnectionID, _ windows: NSArray, _ spaces: NSArray)
|
||||
@_silgen_name("CGSHideSpaces")
|
||||
fileprivate func CGSHideSpaces(_ cid: CGSConnectionID, _ spaces: NSArray)
|
||||
@_silgen_name("CGSShowSpaces")
|
||||
fileprivate func CGSShowSpaces(_ cid: CGSConnectionID, _ spaces: NSArray)
|
||||
Loading…
Add table
Add a link
Reference in a new issue