Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Don't bork Touch Bar on MacBook Pro 16inch
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 10, 2020
1 parent 2ecf880 commit bc77393
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions Touch Bar Simulator/Touch Bar Simulator-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
CGDisplayStreamRef SLSDFRDisplayStreamCreate(int displayID, dispatch_queue_t queue, CGDisplayStreamFrameAvailableHandler handler);
CGSize DFRGetScreenSize(void);
void DFRSetStatus(int);
int DFRGetStatus(void);
void DFRFoundationPostEventWithMouseActivity(NSEventType type, CGPoint point);

@interface NSWindow (Private)
Expand Down
11 changes: 9 additions & 2 deletions Touch Bar Simulator/TouchBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import Cocoa
final class TouchBarView: NSView {
private var stream: CGDisplayStream?
private let displayView = NSView()
private let initialDFRStatus: Int32

override init(frame: CGRect) {
initialDFRStatus = DFRGetStatus()

super.init(frame: .zero)

wantsLayer = true
start()
setFrameSize(DFRGetScreenSize())
Expand All @@ -23,6 +27,10 @@ final class TouchBarView: NSView {
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }

func start() {
if (initialDFRStatus & 0x01) == 0 {
DFRSetStatus(2)
}

stream = SLSDFRDisplayStreamCreate(0, .main) { [weak self] status, _, frameSurface, _ in
guard
let self = self,
Expand All @@ -35,7 +43,6 @@ final class TouchBarView: NSView {
layer.contents = frameSurface
}.takeUnretainedValue()

DFRSetStatus(2)
stream?.start()
}

Expand All @@ -44,9 +51,9 @@ final class TouchBarView: NSView {
return
}

DFRSetStatus(0)
stream.stop()
self.stream = nil
DFRSetStatus(initialDFRStatus)
}

private func mouseEvent(_ event: NSEvent) {
Expand Down

0 comments on commit bc77393

Please sign in to comment.