From e4950f964dffb8a0453c768ba44aa036e901a2cc Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 30 Sep 2019 22:42:25 -0700 Subject: MacOS app: added tracking area in order to always receive mouse events --- .../NativeApp/Apple/Source/Classes/OSX/ViewController.mm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'Common') diff --git a/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm b/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm index c8f9228..253f725 100644 --- a/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm +++ b/Common/NativeApp/Apple/Source/Classes/OSX/ViewController.mm @@ -26,6 +26,18 @@ @implementation ViewController +- (void)viewDidLoad +{ + [super viewDidLoad]; + + // Add a tracking area in order to receive mouse events whenever the mouse is within the bounds of our view + NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect + options:NSTrackingMouseMoved | NSTrackingInVisibleRect | NSTrackingActiveAlways + owner:self + userInfo:nil]; + [self.view addTrackingArea:trackingArea]; +} + - (void)handleEvent : (NSEvent *)theEvent { auto* view = (ViewBase*)self.view; auto* theApp = [view lockApp]; @@ -35,9 +47,6 @@ [view unlockApp]; } -- (void)mouseMove:(NSEvent *)theEvent { - [self handleEvent:theEvent]; -} - (void)mouseDown:(NSEvent *)theEvent { [self handleEvent:theEvent]; -- cgit v1.2.3