From bc77393ededc7ea7ad6b42264533f34bcf1d485a Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 10 Feb 2020 17:42:28 +0700 Subject: [PATCH] Don't bork Touch Bar on MacBook Pro 16inch --- .../Touch Bar Simulator-Bridging-Header.h | 1 + Touch Bar Simulator/TouchBarView.swift | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Touch Bar Simulator/Touch Bar Simulator-Bridging-Header.h b/Touch Bar Simulator/Touch Bar Simulator-Bridging-Header.h index b346e02..502ea09 100644 --- a/Touch Bar Simulator/Touch Bar Simulator-Bridging-Header.h +++ b/Touch Bar Simulator/Touch Bar Simulator-Bridging-Header.h @@ -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) diff --git a/Touch Bar Simulator/TouchBarView.swift b/Touch Bar Simulator/TouchBarView.swift index 565a0b3..53aa348 100644 --- a/Touch Bar Simulator/TouchBarView.swift +++ b/Touch Bar Simulator/TouchBarView.swift @@ -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()) @@ -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, @@ -35,7 +43,6 @@ final class TouchBarView: NSView { layer.contents = frameSurface }.takeUnretainedValue() - DFRSetStatus(2) stream?.start() } @@ -44,9 +51,9 @@ final class TouchBarView: NSView { return } - DFRSetStatus(0) stream.stop() self.stream = nil + DFRSetStatus(initialDFRStatus) } private func mouseEvent(_ event: NSEvent) {