Skip to content
Snippets Groups Projects
Commit 263831c1 authored by George Nachman's avatar George Nachman
Browse files

Add logging for issue 5198

parent bf3d25c5
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -69,6 +69,7 @@ NSString *const iTermEventTapEventTappedNotification = @"iTermEventTapEventTappe
#pragma mark - Accessors
 
- (void)setEnabled:(BOOL)enabled {
NSLog(@"iTermEventTap setEnabled:%@", @(enabled));
if (enabled && !self.isEnabled) {
[self startEventTap];
} else if (!enabled && self.isEnabled) {
Loading
Loading
@@ -101,6 +102,7 @@ static CGEventRef OnTappedEvent(CGEventTapProxy proxy,
CGEventType type,
CGEventRef event,
void *refcon) {
NSLog(@"Event tap running");
if (type == kCGEventTapDisabledByTimeout || type == kCGEventTapDisabledByUserInput) {
ELog(@"Event tap disabled (type is %@)", @(type));
if ([[iTermEventTap sharedInstance] isEnabled]) {
Loading
Loading
@@ -110,10 +112,12 @@ static CGEventRef OnTappedEvent(CGEventTapProxy proxy,
return NULL;
}
if (![[[iTermApplication sharedApplication] delegate] workspaceSessionActive]) {
NSLog(@"Workspace session not active");
return event;
}
if (![[iTermEventTap sharedInstance] userIsActive]) {
NSLog(@"User not active");
// Fast user switching has switched to another user, don't do any remapping.
DLog(@"** not doing any remapping for event %@", [NSEvent eventWithCGEvent:event]);
return event;
Loading
Loading
@@ -121,9 +125,11 @@ static CGEventRef OnTappedEvent(CGEventTapProxy proxy,
id<iTermEventTapRemappingDelegate> delegate = [[iTermEventTap sharedInstance] remappingDelegate];
if (delegate) {
NSLog(@"Calling delegate");
event = [delegate remappedEventFromEventTappedWithType:type event:event];
}
NSLog(@"Notifying observers");
[[iTermEventTap sharedInstance] postEventToObservers:event type:type];
 
return event;
Loading
Loading
@@ -168,6 +174,7 @@ static CGEventRef OnTappedEvent(CGEventTapProxy proxy,
}
 
- (void)stopEventTap {
NSLog(@"Stop event tap %@", [NSThread callStackSymbols]);
assert(self.isEnabled);
CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
_runLoopEventSource,
Loading
Loading
@@ -178,6 +185,7 @@ static CGEventRef OnTappedEvent(CGEventTapProxy proxy,
}
 
- (BOOL)startEventTap {
NSLog(@"Start event tap");
assert(!self.isEnabled);
 
DLog(@"Register event tap.");
Loading
Loading
@@ -188,19 +196,20 @@ static CGEventRef OnTappedEvent(CGEventTapProxy proxy,
(CGEventTapCallBack)OnTappedEvent,
self);
if (!_eventTapMachPort) {
NSLog(@"CGEventTapCreate failed");
return NO;
}
 
DLog(@"Create runloop source");
NSLog(@"Create runloop source");
_runLoopEventSource = CFMachPortCreateRunLoopSource(NULL, _eventTapMachPort, 0);
if (_runLoopEventSource == NULL) {
ELog(@"CFMachPortCreateRunLoopSource failed.");
NSLog(@"CFMachPortCreateRunLoopSource failed.");
CFRelease(_eventTapMachPort);
_eventTapMachPort = NULL;
return NO;
}
 
DLog(@"Adding run loop source.");
NSLog(@"Adding run loop source.");
// Get the CFRunLoop primitive for the Carbon Main Event Loop, and add the new event souce
CFRunLoopAddSource(CFRunLoopGetCurrent(),
_runLoopEventSource,
Loading
Loading
Loading
Loading
@@ -1000,6 +1000,7 @@ exit:
{
// This function copied from cmd-key happy. See copyright notice at top.
CGEventFlags flags = CGEventGetFlags(cgEvent);
NSLog(@"Performing remapping. On input CGEventFlags=%@", @(flags));
const CGEventFlags origFlags = flags;
CGEventFlags andMask = -1;
CGEventFlags orMask = 0;
Loading
Loading
@@ -1042,6 +1043,7 @@ exit:
orMask |= [self _nxMaskForRightControlKey];
}
}
NSLog(@"On output CGEventFlags=%@", @((flags & andMask) | orMask));
 
CGEventSetFlags(cgEvent, (flags & andMask) | orMask);
return cgEvent;
Loading
Loading
#import <Cocoa/Cocoa.h>
 
#import "iTermModifierRemapper.h"
#import "DebugLogging.h"
#import "iTermApplicationDelegate.h"
#import "iTermHotKeyController.h"
#import "iTermKeyBindingMgr.h"
Loading
Loading
@@ -69,9 +69,11 @@
#pragma mark - Private
 
- (void)beginRemappingModifiers {
ELog(@"Begin remapping modifiers");
[[iTermEventTap sharedInstance] setRemappingDelegate:self];
if (![[iTermEventTap sharedInstance] isEnabled]) {
ELog(@"The event tap is NOT enabled");
if (IsMavericksOrLater()) {
[self requestAccessibilityPermissionMavericks];
return;
Loading
Loading
@@ -99,6 +101,7 @@
}
 
- (void)requestAccessibilityPermissionMavericks {
ELog(@"Requesting mavericks accessibility permission");
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSDictionary *options = @{ (NSString *)kAXTrustedCheckOptionPrompt: @YES };
Loading
Loading
@@ -122,11 +125,21 @@
#pragma mark - iTermEventTapRemappingDelegate
 
- (CGEventRef)remappedEventFromEventTappedWithType:(CGEventType)type event:(CGEventRef)event {
ELog(@"Modifier remapper got an event");
if ([NSApp isActive]) {
ELog(@"App is active, performing remapping");
// Remap modifier keys only while iTerm2 is active; otherwise you could just use the
// OS's remap feature.
return [self eventByRemappingEvent:event];
} else {
ELog(@"App not active");
for (NSRunningApplication *currApp in [[NSWorkspace sharedWorkspace] runningApplications]) {
if ([currApp isActive]) {
ELog(@"This app is active: %@", [currApp localizedName]);
} else {
ELog(@"This app is not active: %@", [currApp localizedName]);
}
}
return event;
}
}
Loading
Loading
@@ -134,6 +147,7 @@
// Only called when the app is active.
- (CGEventRef)eventByRemappingEvent:(CGEventRef)event {
NSEvent *cocoaEvent = [NSEvent eventWithCGEvent:event];
ELog(@"Remapping event %@", cocoaEvent);
iTermShortcutInputView *shortcutView = nil;
NSResponder *firstResponder = [[NSApp keyWindow] firstResponder];
if ([firstResponder isKindOfClass:[iTermShortcutInputView class]]) {
Loading
Loading
@@ -141,6 +155,7 @@
}
 
if (shortcutView.disableKeyRemapping) {
ELog(@"Shortcut view is active so return nil");
// Send keystroke directly to preference panel when setting do-not-remap for a key; for
// system keys, NSApp sendEvent: is never called so this is the last chance.
[shortcutView handleShortcutEvent:cocoaEvent];
Loading
Loading
@@ -149,14 +164,17 @@
 
switch ([self boundActionForEvent:cocoaEvent]) {
case KEY_ACTION_REMAP_LOCALLY:
ELog(@"Calling sendEvent:");
[iTermKeyBindingMgr remapModifiersInCGEvent:event];
[NSApp sendEvent:[NSEvent eventWithCGEvent:event]];
return nil;
 
case KEY_ACTION_DO_NOT_REMAP_MODIFIERS:
ELog(@"Action is do not remap");
return event;
 
default:
ELog(@"Remapping as usual");
[iTermKeyBindingMgr remapModifiersInCGEvent:event];
return event;
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment