Skip to content

Commit

Permalink
Patches from michael.klein@puffin.lb.shuttle.de:
Browse files Browse the repository at this point in the history
Anyway, the attached patch fixes some obviously broken restart code in VTApplicationDelegate.m in SVN head revision (just reverting to r354) and 
improves hotkey display when Unicode keyboard layouts are used. Previously, no key names were displayed in the Trigger PrefPane when a Unicode 
keyboard layout was being used.
  • Loading branch information
tonyarnold committed Jan 13, 2009
1 parent bfc3133 commit 1484faf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
5 changes: 2 additions & 3 deletions Source/Application/Controllers/VTApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,8 @@ - (IBAction) fixExecutablePermissions: (id) sender {
mConfirmQuitOverridden = YES;

// Thanks to Allan Odgaard for this restart code, which is much more clever than mine was.
setenv("LAUNCH_PATH", [[[NSBundle mainBundle] bundlePath] UTF8String], 1);
system("/bin/bash -c '{ for (
); do\n"
setenv("LAUNCH_PATH", [[[NSBundle mainBundle] bundlePath] UTF8String], 1);
system("/bin/bash -c '{ for (( i = 0; i < 3000 && $(echo $(/bin/ps -xp $PPID|/usr/bin/wc -l))-1; i++ )); do\n"
" /bin/sleep .2;\n"
" done\n"
" if [[ $(/bin/ps -xp $PPID|/usr/bin/wc -l) -ne 2 ]]; then\n"
Expand Down
70 changes: 42 additions & 28 deletions Source/Application/Hotkeys/VTHotkeyTrigger.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,35 +169,49 @@ - (NSString*) stringValue {
// code and then translate that to the resulting string that we return

KeyboardLayoutRef kbdLayout;
Handle kchrHandle;

Handle kchrHandle;

UInt32 state = 0;
UniChar charCode = 0;
UniCharCount length;

KLGetCurrentKeyboardLayout(&kbdLayout);
KLGetKeyboardLayoutProperty(kbdLayout, kKLKCHRData, (const void**) &kchrHandle);

if (kchrHandle) {
UInt32 state = 0;
UInt32 charCode = KeyTranslate(kchrHandle, mKeyCode, &state);

NSMutableString* stringValue = [NSMutableString string];

// handle modifiers and append them to the resulting string representation
if (mKeyModifiers & NSControlKeyMask)
[stringValue appendString: [self unicodeToString: kControlUnicode]];
if (mKeyModifiers & NSShiftKeyMask)
[stringValue appendString: [self unicodeToString: kShiftUnicode]];
if (mKeyModifiers & NSAlternateKeyMask)
[stringValue appendString: [self unicodeToString: kOptionUnicode]];
if (mKeyModifiers & NSCommandKeyMask)
[stringValue appendString: [self unicodeToString: kCommandUnicode]];
KLGetKeyboardLayoutProperty(kbdLayout, kKLKCHRData, (const void**) &kchrHandle);
if (kchrHandle) {
// non-Unicode keyboard
charCode = KeyTranslate(kchrHandle, mKeyCode, &state);
} else {
KLGetKeyboardLayoutProperty(kbdLayout, kKLuchrData, (const void**) &kchrHandle);
if (kchrHandle) {
// unicode keyboard
OSErr err = UCKeyTranslate(kchrHandle, mKeyCode,
kUCKeyActionDisplay, 0,
LMGetKbdType(),
kUCKeyTranslateNoDeadKeysMask,
&state, 1, &length, &charCode);
} else {
return @"";
}
}

NSMutableString * stringValue = [NSMutableString string];

// handle modifiers and append them to the resulting string representation
if (mKeyModifiers & NSControlKeyMask)
[stringValue appendString: [self unicodeToString: kControlUnicode]];
if (mKeyModifiers & NSShiftKeyMask)
[stringValue appendString: [self unicodeToString: kShiftUnicode]];
if (mKeyModifiers & NSAlternateKeyMask)
[stringValue appendString: [self unicodeToString: kOptionUnicode]];
if (mKeyModifiers & NSCommandKeyMask)
[stringValue appendString: [self unicodeToString: kCommandUnicode]];

[stringValue appendString: @" "];
[stringValue appendString: [self charCodeToString: charCode fromKeyCode: mKeyCode]];

[stringValue appendString: @" "];
[stringValue appendString: [self charCodeToString: charCode fromKeyCode: mKeyCode]];

mStringValue = [[NSString stringWithString: stringValue] retain];
return mStringValue;
}

return @"";
mStringValue = [[NSString stringWithString: stringValue] retain];

return mStringValue;
}

#pragma mark -
Expand Down Expand Up @@ -320,4 +334,4 @@ - (NSString*) charCodeToString: (UInt32) charCode fromKeyCode: (int) keyCode {
return [[self unicodeToString: charCode] uppercaseString];
};

@end
@end

0 comments on commit 1484faf

Please sign in to comment.