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

Add debugging for keydown.

parent 2f6baccd
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -580,6 +580,19 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
 
- (void)writeTask:(NSData*)data
{
static BOOL checkedDebug;
static BOOL debugKeyDown;
if (!checkedDebug) {
debugKeyDown = [[[NSUserDefaults standardUserDefaults] objectForKey:@"DebugKeyDown"] boolValue];
checkedDebug = YES;
}
if (debugKeyDown) {
const char *bytes = [data bytes];
for (int i = 0; i < [data length]; i++) {
NSLog(@"writeTask keydown %d: %d (%c)", (int) bytes[i], bytes[i]);
}
}
// check if we want to send this input to all the sessions
if (![[[self tab] realParentWindow] broadcastInputToSession:self]) {
// Send to only this session
Loading
Loading
@@ -847,6 +860,7 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
// pass the keystroke as input.
- (void)keyDown:(NSEvent *)event
{
BOOL debugKeyDown = [[[NSUserDefaults standardUserDefaults] objectForKey:@"DebugKeyDown"] boolValue];
unsigned char *send_str = NULL;
unsigned char *dataPtr = NULL;
int dataLength = 0;
Loading
Loading
@@ -873,10 +887,15 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
}
unicode = [keystr length] > 0 ? [keystr characterAtIndex:0] : 0;
unmodunicode = [unmodkeystr length] > 0 ? [unmodkeystr characterAtIndex:0] : 0;
if (debugKeyDown) {
NSLog(@"PTYSession keyDown modflag=%d keystr=%@ unmodkeystr=%@ unicode=%d unmodunicode=%d", (int)modflag, keystr, unmodkeystr, (int)unicode, (int)unmodunicode);
}
gettimeofday(&lastInput, NULL);
 
if ([[[self tab] realParentWindow] inInstantReplay]) {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown in IR");
}
// Special key handling in IR mode, and keys never get sent to the live
// session, even though it might be displayed.
if (unicode == 27) {
Loading
Loading
@@ -909,7 +928,9 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
 
 
unsigned short keycode = [event keyCode];
//NSLog([NSString stringWithFormat:@"event:%@ (%x+%x)[%@][%@]:%x(%c) <%d>", event,modflag,keycode,keystr,unmodkeystr,unicode,unicode,(modflag & NSNumericPadKeyMask)]);
if (debugKeyDown) {
NSLog([NSString stringWithFormat:@"event:%@ (%x+%x)[%@][%@]:%x(%c) <%d>", event,modflag,keycode,keystr,unmodkeystr,unicode,unicode,(modflag & NSNumericPadKeyMask)]);
}
DebugLog([NSString stringWithFormat:@"event:%@ (%x+%x)[%@][%@]:%x(%c) <%d>", event,modflag,keycode,keystr,unmodkeystr,unicode,unicode,(modflag & NSNumericPadKeyMask)]);
 
// Check if we have a custom key mapping for this event
Loading
Loading
@@ -919,6 +940,9 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
keyMappings:[[self addressBookEntry] objectForKey:KEY_KEYBOARD_MAP]];
 
if (keyBindingAction >= 0) {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown action=%d", keyBindingAction);
}
DebugLog([NSString stringWithFormat:@"keyBindingAction=%d", keyBindingAction]);
// A special action was bound to this key combination.
NSString *aString;
Loading
Loading
@@ -1097,6 +1121,9 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
break;
}
} else {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown no keybinding action");
}
DebugLog(@"No keybinding action");
if (EXIT) {
DebugLog(@"Terminal already dead");
Loading
Loading
@@ -1104,6 +1131,9 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
}
// No special binding for this key combination.
if (modflag & NSFunctionKeyMask) {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown is a function key");
}
DebugLog(@"Is a function key");
// Handle all "special" keys (arrows, etc.)
NSData *data = nil;
Loading
Loading
@@ -1163,7 +1193,10 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
([self optionKey] != OPT_NORMAL)) ||
((modflag & NSRightAlternateKeyMask) == NSRightAlternateKeyMask &&
([self rightOptionKey] != OPT_NORMAL))) {
DebugLog(@"Option + key -> modified key");
if (debugKeyDown) {
NSLog(@"PTYSession keyDown opt + key -> modkey");
}
DebugLog(@"Option + key -> modified key");
// A key was pressed while holding down option and the option key
// is not behaving normally. Apply the modified behavior.
int mode; // The modified behavior based on which modifier is pressed.
Loading
Loading
@@ -1189,15 +1222,24 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
}
}
} else {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown regular path");
}
DebugLog(@"Regular path for keypress");
// Regular path for inserting a character from a keypress.
int max = [keystr length];
NSData *data=nil;
 
if (max != 1||[keystr characterAtIndex:0] > 0x7f) {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown non-ascii");
}
DebugLog(@"Non-ascii input");
data = [keystr dataUsingEncoding:[TERMINAL encoding]];
} else {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown ascii");
}
DebugLog(@"ASCII input");
data = [keystr dataUsingEncoding:NSUTF8StringEncoding];
}
Loading
Loading
@@ -1205,11 +1247,17 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
// Enter key is on numeric keypad, but not marked as such
if (unicode == NSEnterCharacter && unmodunicode == NSEnterCharacter) {
modflag |= NSNumericPadKeyMask;
if (debugKeyDown) {
NSLog(@"PTYSession keyDown enter key");
}
DebugLog(@"Enter key");
keystr = @"\015"; // Enter key -> 0x0d
}
// Check if we are in keypad mode
if (modflag & NSNumericPadKeyMask) {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown numeric keyoad");
}
DebugLog(@"Numeric keypad mask");
data = [TERMINAL keypadData:unicode keystr:keystr];
}
Loading
Loading
@@ -1224,6 +1272,9 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
// Do not send anything for cmd+[shift]+enter if it wasn't
// caught by the menu.
DebugLog(@"Cmd + 0-9 or cmd + enter");
if (debugKeyDown) {
NSLog(@"PTYSession keyDown cmd+0-9 or cmd+enter");
}
data = nil;
}
if (data != nil) {
Loading
Loading
@@ -1231,11 +1282,18 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
send_strlen = [data length];
DebugLog([NSString stringWithFormat:@"modflag = 0x%x; send_strlen = %d; send_str[0] = '%c (0x%x)'",
modflag, send_strlen, send_str[0]]);
if (debugKeyDown) {
DebugLog([NSString stringWithFormat:@"modflag = 0x%x; send_strlen = %d; send_str[0] = '%c (0x%x)'",
modflag, send_strlen, send_str[0]]);
}
}
 
if ((modflag & NSControlKeyMask) &&
send_strlen == 1 &&
send_str[0] == '|') {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown c-|");
}
// Control-| is sent as Control-backslash
send_str = (unsigned char*)"\034";
send_strlen = 1;
Loading
Loading
@@ -1243,18 +1301,27 @@ static NSString* SESSION_ARRANGEMENT_WORKING_DIRECTORY = @"Working Directory";
(modflag & NSShiftKeyMask) &&
send_strlen == 1 &&
send_str[0] == '/') {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown c-?");
}
// Control-shift-/ is sent as Control-?
send_str = (unsigned char*)"\177";
send_strlen = 1;
} else if ((modflag & NSControlKeyMask) &&
send_strlen == 1 &&
send_str[0] == '/') {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown c-/");
}
// Control-/ is sent as Control-/, but needs some help to do so.
send_str = (unsigned char*)"\037"; // control-/
send_strlen = 1;
} else if ((modflag & NSShiftKeyMask) &&
send_strlen == 1 &&
send_str[0] == '\031') {
if (debugKeyDown) {
NSLog(@"PTYSession keyDown shift-tab -> esc[Z");
}
// Shift-tab is sent as Esc-[Z (or "backtab")
send_str = (unsigned char*)"\033[Z";
send_strlen = 3;
Loading
Loading
Loading
Loading
@@ -1953,9 +1953,17 @@ static BOOL RectsEqual(NSRect* a, NSRect* b) {
 
- (void)keyDown:(NSEvent*)event
{
BOOL debugKeyDown = [[[NSUserDefaults standardUserDefaults] objectForKey:@"DebugKeyDown"] boolValue];
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown BEGIN %@", event);
}
DebugLog(@"PTYTextView keyDown");
id delegate = [self delegate];
if ([[[[[self dataSource] session] tab] realParentWindow] inInstantReplay]) {
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown: in instant replay, send to delegate");
}
// Delegate has special handling for this case.
[delegate keyDown:event];
return;
Loading
Loading
@@ -1965,6 +1973,9 @@ static BOOL RectsEqual(NSRect* a, NSRect* b) {
BOOL prev = [self hasMarkedText];
 
keyIsARepeat = [event isARepeat];
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown modflag=%d keycode=%d", modflag, (int)keyCode);
}
 
// Hide the cursor
[NSCursor setHiddenUntilMouseMoves:YES];
Loading
Loading
@@ -1978,6 +1989,9 @@ static BOOL RectsEqual(NSRect* a, NSRect* b) {
((modflag & NSRightAlternateKeyMask) == NSRightAlternateKeyMask && [delegate rightOptionKey] != OPT_NORMAL))) ||
((modflag & NSControlKeyMask) && // a few special cases
(keyCode == 0x2c /* slash */ || keyCode == 0x2a /* backslash */)))) {
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown: process in delegate");
}
[delegate keyDown:event];
return;
}
Loading
Loading
@@ -1985,6 +1999,9 @@ static BOOL RectsEqual(NSRect* a, NSRect* b) {
if (modflag & NSCommandKeyMask) {
// You pressed cmd+something but it's not handled by the delegate. Going further would
// send the unmodified key to the terminal which doesn't make sense.adsjflsd
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown You pressed cmd+something");
}
return;
}
 
Loading
Loading
@@ -2014,6 +2031,9 @@ static BOOL RectsEqual(NSRect* a, NSRect* b) {
}
if (cc != 0xffff) {
[self insertText:[NSString stringWithCharacters:&cc length:1]];
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown work around control bug. cc=%d", (int)cc);
}
workAroundControlBug = YES;
}
}
Loading
Loading
@@ -2022,15 +2042,24 @@ static BOOL RectsEqual(NSRect* a, NSRect* b) {
if (!workAroundControlBug) {
// Let the IME process key events
IM_INPUT_INSERT = NO;
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown send to IME");
}
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
 
// If the IME didn't want it, pass it on to the delegate
if (!prev &&
!IM_INPUT_INSERT &&
![self hasMarkedText]) {
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown IME no, send to delegate");
}
[delegate keyDown:event];
}
}
if (debugKeyDown) {
NSLog(@"PTYTextView keyDown END");
}
}
 
- (BOOL)keyIsARepeat
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