diff --git a/TouchBar Simulator.xcodeproj/project.pbxproj b/TouchBar Simulator.xcodeproj/project.pbxproj index 067557d..b6df062 100644 --- a/TouchBar Simulator.xcodeproj/project.pbxproj +++ b/TouchBar Simulator.xcodeproj/project.pbxproj @@ -419,6 +419,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; + MARKETING_VERSION = 1.1; PRODUCT_BUNDLE_IDENTIFIER = "com.github.jslegendre.TouchBar-Simulator"; PRODUCT_NAME = "$(TARGET_NAME)"; SYSTEM_FRAMEWORK_SEARCH_PATHS = ( @@ -445,6 +446,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; + MARKETING_VERSION = 1.1; PRODUCT_BUNDLE_IDENTIFIER = "com.github.jslegendre.TouchBar-Simulator"; PRODUCT_NAME = "$(TARGET_NAME)"; SYSTEM_FRAMEWORK_SEARCH_PATHS = ( @@ -464,6 +466,7 @@ HEADER_SEARCH_PATHS = "$(PROJECT_DIR)"; INFOPLIST_FILE = TouchBarSimulatorService/Info.plist; MACOSX_DEPLOYMENT_TARGET = 10.15; + MARKETING_VERSION = 1.1; PRODUCT_BUNDLE_IDENTIFIER = com.github.jslegendre.TouchBarSimulatorService; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -484,6 +487,7 @@ HEADER_SEARCH_PATHS = "$(PROJECT_DIR)"; INFOPLIST_FILE = TouchBarSimulatorService/Info.plist; MACOSX_DEPLOYMENT_TARGET = 10.15; + MARKETING_VERSION = 1.1; PRODUCT_BUNDLE_IDENTIFIER = com.github.jslegendre.TouchBarSimulatorService; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; diff --git a/TouchBar Simulator.xcodeproj/xcuserdata/j.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/TouchBar Simulator.xcodeproj/xcuserdata/j.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 7611e98..b817ab9 100644 --- a/TouchBar Simulator.xcodeproj/xcuserdata/j.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/TouchBar Simulator.xcodeproj/xcuserdata/j.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,22 +3,4 @@ uuid = "5F44A03D-51A9-4BC0-969F-DDCD69FD825D" type = "1" version = "2.0"> - - - - - - diff --git a/TouchBar Simulator/AppDelegate.m b/TouchBar Simulator/AppDelegate.m index e995413..1d76179 100644 --- a/TouchBar Simulator/AppDelegate.m +++ b/TouchBar Simulator/AppDelegate.m @@ -23,7 +23,12 @@ @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.window.worksWhenModal = YES; [self.window _setPreventsActivation:YES]; - self.window.styleMask |= NSWindowStyleMaskUtilityWindow; + [self.window setIgnoresMouseEvents:NO]; + // Touchbar pixel size @2x scaled is 2008 x 60 + //self.window.aspectRatio = NSMakeSize(502, 15); + + // Retina scaling (1004 x 30) + 10px padding is 1014 x 40 + self.window.aspectRatio = NSMakeSize(507, 20); //NSMakeSize(169, 5); self.window.movableByWindowBackground = NO; self.window.contentView.wantsLayer = YES; self.window.contentView.layer.backgroundColor = NSColor.blackColor.CGColor; @@ -34,7 +39,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { }]; } - - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return YES; } diff --git a/TouchBar Simulator/Base.lproj/MainMenu.xib b/TouchBar Simulator/Base.lproj/MainMenu.xib index fe7cad4..2760374 100644 --- a/TouchBar Simulator/Base.lproj/MainMenu.xib +++ b/TouchBar Simulator/Base.lproj/MainMenu.xib @@ -1,7 +1,8 @@ - + - + + @@ -11,7 +12,7 @@ - + @@ -681,10 +682,11 @@ - + + diff --git a/TouchBar Simulator/Info.plist b/TouchBar Simulator/Info.plist index 2c5c41c..24059dd 100644 --- a/TouchBar Simulator/Info.plist +++ b/TouchBar Simulator/Info.plist @@ -17,16 +17,16 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion 1 + LSBackgroundOnly + LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSMainNibFile MainMenu NSPrincipalClass NSApplication - LSUIElement - diff --git a/TouchBar Simulator/main.m b/TouchBar Simulator/main.m index f840baf..baf2a68 100644 --- a/TouchBar Simulator/main.m +++ b/TouchBar Simulator/main.m @@ -8,8 +8,5 @@ #import int main(int argc, const char * argv[]) { - @autoreleasepool { - // Setup code that might create autoreleased objects goes here. - } return NSApplicationMain(argc, argv); } diff --git a/TouchBarSimulatorService/Info.plist b/TouchBarSimulatorService/Info.plist index 21ffd36..a5a528f 100644 --- a/TouchBarSimulatorService/Info.plist +++ b/TouchBarSimulatorService/Info.plist @@ -17,19 +17,19 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 1.0 + $(MARKETING_VERSION) CFBundleVersion 1 NSPrincipalClass NSViewServiceApplication XPCService - ServiceType - Application JoinExistingSession RunLoopType _NSApplicationMain + ServiceType + Application diff --git a/TouchBarSimulatorService/TouchBarSimulatorService.m b/TouchBarSimulatorService/TouchBarSimulatorService.m index 40a7155..364463d 100644 --- a/TouchBarSimulatorService/TouchBarSimulatorService.m +++ b/TouchBarSimulatorService/TouchBarSimulatorService.m @@ -6,9 +6,10 @@ // #import +#import +#import #import "TouchBarSimulatorService.h" #import "DFRFoundation.h" -@import QuartzCore; @interface TouchBarSimulatorStreamView : NSView @@ -42,11 +43,6 @@ - (void)mouseMoved:(NSEvent *)event { [self mouseEvent:event]; } -//- (void)awakeFromNib { -// self.layer.backgroundColor = NSColor.blackColor.CGColor; -// self.wantsLayer = YES; -//} - - (instancetype)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; self.layer.backgroundColor = NSColor.blackColor.CGColor; @@ -69,34 +65,64 @@ - (void)awakeFromNib { @end -@interface TouchBarSimulatorService () +@interface TouchBarSimulatorService () @property CGDisplayStreamRef touchBarStream; @property DFRTouchBarSimulator *simulator; +@property (nonatomic,strong) MTKView *mtlView; +@property (nonatomic,strong) CIImage *frame; +@property (nonatomic,strong) id device; +@property (nonatomic,strong) id commandQueue; +@property (nonatomic,strong) CIContext *context; @end @implementation TouchBarSimulatorService +- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {} + +- (void)drawInMTKView:(MTKView *)view { + if(!_frame) return; + id outputTexture = _mtlView.currentDrawable.texture; + if (!outputTexture) return; + if (_frame.extent.size.width == 0) return; + + _mtlView.drawableSize = _frame.extent.size; + id commandBuffer = [self.commandQueue commandBuffer]; + [self.context render:_frame toMTLTexture:outputTexture commandBuffer:commandBuffer bounds:_frame.extent colorSpace:CGColorSpaceCreateDeviceRGB()]; + [commandBuffer presentDrawable:self.mtlView.currentDrawable]; + [commandBuffer commit]; +} - (void)viewDidLoad { [super viewDidLoad]; - + + self.frame = nil; + self.device = MTLCreateSystemDefaultDevice(); + self.mtlView = [[MTKView alloc] initWithFrame:self.view.frame device:self.device]; + self.mtlView.clearColor = MTLClearColorMake(0, 0, 0, 0); + self.mtlView.delegate = self; + self.mtlView.framebufferOnly = NO; + self.mtlView.autoResizeDrawable = YES; + self.mtlView.enableSetNeedsDisplay = YES; + self.context = [CIContext contextWithMTLDevice:self.device options:@{kCIContextWorkingColorSpace: (__bridge id)CGColorSpaceCreateDeviceRGB(), kCIContextUseSoftwareRenderer: [NSNumber numberWithBool:NO], kCIContextHighQualityDownsample: [NSNumber numberWithBool:YES]}]; + self.commandQueue = [self.device newCommandQueue]; + self.mtlView.frame = NSMakeRect(5, 5, 1004, 30); + [self.view addSubview:_mtlView]; + TouchBarSimulatorStreamView *streamView = [[TouchBarSimulatorStreamView alloc] initWithFrame:NSMakeRect(5, 5, 1004, 30)]; [self.view addSubview:streamView]; - + self.simulator = DFRTouchBarSimulatorCreate(3, 0, 3); - DFRTouchBar *touchBar = DFRTouchBarSimulatorGetTouchBar(self.simulator); + [streamView setSimulator:self.simulator]; + DFRTouchBar *touchBar = DFRTouchBarSimulatorGetTouchBar(self.simulator); self.touchBarStream = DFRTouchBarCreateDisplayStream(touchBar, 0, dispatch_get_main_queue(), ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef _Nullable frameSurface, CGDisplayStreamUpdateRef _Nullable updateRef) { - [CATransaction begin]; - [CATransaction setDisableActions:YES]; - [streamView.layer setContents:(__bridge id _Nullable)(frameSurface)]; - [CATransaction commit]; + self->_frame = [CIImage imageWithIOSurface:frameSurface]; + self->_mtlView.needsDisplay = YES; +// streamView.layer.contents = (__bridge id _Nullable)(frameSurface); }); if (self.touchBarStream) { CGDisplayStreamStart(self.touchBarStream); } - - [streamView setSimulator:self.simulator]; } - (void)viewWillDisappear { diff --git a/TouchBarSimulatorService/TouchBarSimulatorService.xib b/TouchBarSimulatorService/TouchBarSimulatorService.xib index 93b25ee..e4402ba 100644 --- a/TouchBarSimulatorService/TouchBarSimulatorService.xib +++ b/TouchBarSimulatorService/TouchBarSimulatorService.xib @@ -1,7 +1,8 @@ - + - + + diff --git a/TouchBarSimulatorService/main.m b/TouchBarSimulatorService/main.m index 87a54c5..5c40db7 100644 --- a/TouchBarSimulatorService/main.m +++ b/TouchBarSimulatorService/main.m @@ -7,44 +7,8 @@ #import #import -#import "TouchBarSimulatorService.h" -//@interface ServiceDelegate : NSObject -//@end -// -//@implementation ServiceDelegate -// -//- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection { -// // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection. -// -// // Configure the connection. -// // First, set the interface that the exported object implements. -// newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(TouchBarSimulatorServiceProtocol)]; -// -// // Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object. -// TouchBarSimulatorService *exportedObject = [TouchBarSimulatorService new]; -// newConnection.exportedObject = exportedObject; -// -// // Resuming the connection allows the system to deliver more incoming messages. -// [newConnection resume]; -// -// // Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO. -// return YES; -//} -// -//@end - -int main(int argc, const char *argv[]) -{ -// // Create the delegate for the service. -// ServiceDelegate *delegate = [ServiceDelegate new]; -// -// // Set up the one NSXPCListener for this service. It will handle all incoming connections. -// NSXPCListener *listener = [NSXPCListener serviceListener]; -// listener.delegate = delegate; -// -// // Resuming the serviceListener starts this service. This method does not return. -// [listener resume]; +int main(int argc, const char *argv[]) { NSViewServiceApplicationMain(); return 0; }