Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for Issue #5: Only invert scroll events if our CGSession is active.

  • Loading branch information...
commit 17007bdd22e110b2cb49d8b11b00630df4e6488e 1 parent 1e8b4fc
Jim Correia authored
2  Source/ScrollingInverterEventTap.h
View
@@ -10,6 +10,7 @@
@interface ScrollingInverterEventTap : NSObject {
@private
BOOL _enabled;
+ BOOL _sessionActive;
CFMachPortRef _eventTapMachPort;
CFRunLoopSourceRef _eventTapRunLoopSource;
}
@@ -19,5 +20,6 @@
- (void)invalidate;
@property (nonatomic, getter=isEnabled) BOOL enabled;
+@property (nonatomic, readonly, getter=isSessionActive) BOOL sessionActive;
@end
26 Source/ScrollingInverterEventTap.m
View
@@ -13,6 +13,9 @@ @interface ScrollingInverterEventTap ()
- (CGEventRef)_eventTapCallbackWithProxy:(CGEventTapProxy)proxy type:(CGEventType)type event:(CGEventRef)event;
+- (void)_workspaceSessionDidBecomeActive:(NSNotification *)notification;
+- (void)_workspaceSessionDidResignActive:(NSNotification *)notification;
+
@end
@implementation ScrollingInverterEventTap
@@ -24,9 +27,14 @@ - (id)init;
return nil;
_enabled = YES;
+ _sessionActive = YES;
_eventTapMachPort = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, CGEventMaskBit(kCGEventScrollWheel), _eventTap, self);
_eventTapRunLoopSource = CFMachPortCreateRunLoopSource(NULL, _eventTapMachPort, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), _eventTapRunLoopSource, kCFRunLoopCommonModes);
+
+ NSNotificationCenter *notificationCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
+ [notificationCenter addObserver:self selector:@selector(_workspaceSessionDidBecomeActive:) name:NSWorkspaceSessionDidBecomeActiveNotification object:nil];
+ [notificationCenter addObserver:self selector:@selector(_workspaceSessionDidResignActive:) name:NSWorkspaceSessionDidResignActiveNotification object:nil];
return self;
}
@@ -39,6 +47,9 @@ - (void)dealloc;
- (void)invalidate;
{
+ NSNotificationCenter *notificationCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
+ [notificationCenter removeObserver:self];
+
if (_eventTapMachPort) {
CFMachPortInvalidate(_eventTapMachPort);
CFRelease(_eventTapMachPort);
@@ -53,6 +64,7 @@ - (void)invalidate;
}
@synthesize enabled = _enabled;
+@synthesize sessionActive = _sessionActive;
#pragma mark -
#pragma mark Private
@@ -67,7 +79,7 @@ - (CGEventRef)_eventTapCallbackWithProxy:(CGEventTapProxy)proxy type:(CGEventTyp
{
switch (type) {
case kCGEventScrollWheel: {
- if ([self isEnabled]) {
+ if ([self isEnabled] && [self isSessionActive]) {
int64_t deltaAxis1 = CGEventGetIntegerValueField(event, kCGScrollWheelEventDeltaAxis1);;
int64_t deltaAxis2 = CGEventGetIntegerValueField(event, kCGScrollWheelEventDeltaAxis2);;
double fixedPtDeltaAxis1 = CGEventGetDoubleValueField(event, kCGScrollWheelEventFixedPtDeltaAxis1);
@@ -107,4 +119,16 @@ - (CGEventRef)_eventTapCallbackWithProxy:(CGEventTapProxy)proxy type:(CGEventTyp
return event;
}
+- (void)_workspaceSessionDidBecomeActive:(NSNotification *)notification;
+{
+ _sessionActive = YES;
+}
+
+- (void)_workspaceSessionDidResignActive:(NSNotification *)notification;
+{
+ _sessionActive = NO;
+}
+
@end
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.