Skip to content

Commit

Permalink
Add CGSSpace to pin SystemBezel to the screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Vaidyam committed Feb 15, 2018
1 parent c6847b6 commit 39334f5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
14 changes: 5 additions & 9 deletions Hangouts/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ private let log = Logger(subsystem: "Hangouts.Event")
/* TODO: Refactor ChatMessageSegment to match hangups and Protobuf docs. */
/* TODO: Include Markdown, HTML, and URL formatting parsers. */


/*
ConversationNotification
EventNotification
Expand All @@ -24,9 +23,6 @@ private let log = Logger(subsystem: "Hangouts.Event")
RichPresenceEnabledStateNotification
*/




// An event which becomes part of the permanent record of a conversation.
// Acts as a base class for the events defined below.
public class IEvent: ParrotServiceExtension.Event, Hashable, Equatable {
Expand Down Expand Up @@ -59,17 +55,17 @@ public class IEvent: ParrotServiceExtension.Event, Hashable, Equatable {
}

// A timestamp of when the event occurred.
public lazy var timestamp: Date = {
public var timestamp: Date {
return Date(UTC: self.event.timestamp ?? 0)
}()
}

// A User.ID indicating who created the event.
public lazy var userID: User.ID = {
public var userID: User.ID {
return User.ID(
chatID: self.event.sender_id!.chat_id!,
gaiaID: self.event.sender_id!.gaia_id!
)
}()
}

// The ID of the conversation the event belongs to.
public lazy var conversation_id: String = {
Expand Down Expand Up @@ -227,7 +223,7 @@ public class IMembershipChangeEvent : IEvent, ParrotServiceExtension.MembershipC
}

// An event in a Hangouts voice/video call.
public class IHangoutEvent: IEvent, VideoCall {
public class IHangoutEvent: IEvent, ParrotServiceExtension.VideoCall {
/*
public var transferred_conversation_id: ConversationId? = nil
public var refresh_timeout_secs: UInt64? = nil
Expand Down
50 changes: 50 additions & 0 deletions MochaUI/NSWindow+Transforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,53 @@ private func CAMesh(_ m: CGSMeshPoint, _ f: CGRect, _ o: CGPoint, _ t: CATransfo
let n = CAPointApplyCATransform3D(t, f, CGPoint(x: Double(m.x), y: Double(m.y)))
return CGSMeshPoint(x: Float(n.x + o.x), y: Float(n.y + o.y))
}

/// Small Spaces API wrapper.
public final class CGSSpace {
private let identifier: CGSSpaceID

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])
}
}

public init(level: Int = 0) {
self.identifier = CGSSpaceCreate(_CGSDefaultConnection(), 0x0 /*0x1=facetime?*/, nil)
CGSSpaceSetAbsoluteLevel(_CGSDefaultConnection(), self.identifier, level/*400=facetime?*/)
CGSShowSpaces(_CGSDefaultConnection(), [self.identifier])
}

deinit {
CGSHideSpaces(_CGSDefaultConnection(), [self.identifier])
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)
4 changes: 4 additions & 0 deletions MochaUI/SystemBezel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class SystemBezel: Hashable, Equatable {
return NSAppearance.systemAppearance.name == .vibrantDark ? .dark : .light
}

public static var _space = CGSSpace(level: 1)

//
//
//
Expand Down Expand Up @@ -202,6 +204,7 @@ public class SystemBezel: Hashable, Equatable {

self.window.alphaValue = 0.0
self.window.orderFront(nil)
SystemBezel._space.windows.insert(self.window)
NSAnimationContext.runAnimationGroup({
$0.duration = 0.33
self.window.animator().alphaValue = 1.0
Expand All @@ -216,6 +219,7 @@ public class SystemBezel: Hashable, Equatable {
self.window.animator().alphaValue = 0.0
}, completionHandler: {
self.window.close()
SystemBezel._space.windows.remove(self.window)
handler()
})
}
Expand Down
2 changes: 1 addition & 1 deletion Parrot/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public struct BezelAction: EventAction {

public static func perform(with event: EventDescriptor) {
SystemBezel(image: event.image, text: event.contents)
.show().hide(after: 2.seconds)
.show().hide(after: 5.seconds)
}
}

Expand Down

0 comments on commit 39334f5

Please sign in to comment.