Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖

Ilya Kulakov Kentzo

🤖
  • GreatFruit, Wireload
  • San Francisco, CA
View GitHub Profile
View fpvector_from_uint64.asm
punpckldq xmm0, 0x4530000043300000
subpd xmm0, 0x4330000000000000
haddpd xmm0, xmm0
@Kentzo
Kentzo / FB7642814
Created Mar 28, 2020
Carbon API to handle Global Hot Keys should propagate hot key events as regular KeyDown / KeyUp events if not handled
View FB7642814
Among the small subset of Carbon API that still exists and has no modern replacement is an API to register Global Hot Keys. This API works in 2 steps:
1. Install an Event Handler for GetEventDispatcherTarget() for kEventHotKeyPressed and kEventHotKeyReleased
2. Registering Hot Keys with RegisterEventHotKey for GetEventDispatcherTarget()
Once the registered key combination is pressed, custom Event Handler gets called. The handler can then either return a noErr indicating that the event was processed and does not need to be propagated further, return eventNotHandledErr indicating that event should be propagated or any other error.
This issue with this API is that once a keyboard event is recognized as a Hot Key it's not put back onto event queues by macOS as a regular KeyDown / KeyUp event. Not even when all installed event handlers return eventNotHandledErr.
The workaround is to construct the appropriate KeyDown / KeyUp and manually post it on an event queue. This, unfortunately, requires the app to have t
View _0_NoReentryScope.m
void _NoReentryScopeEnter(BOOL *aVar)
{
if (*aVar)
[NSException raise:NSInternalInconsistencyException format:@"the method is not reentrable"];
*aVar = YES;
}
void _NoReentryScopeLeave(BOOL **aVar)
{
View final_attempt.m
NS_SWIFT_NAME(RecorderControlStyle)
@interface SRRecorderControlStyle: NSObject
@end
NS_SWIFT_NAME(SRRecorderControlStyle.Components)
// NS_SWIFT_NAME(RecorderControlStyle.Components) also works!
@interface SRRecorderControlStyleComponents: NSObject
@end
typedef NS_ENUM(NSUInteger, SRRecorderControlStyleComponentsAppearance)
View apple.swift
var sandwich: Sandwich?
var preferences: Sandwich.Preferences?
var breadType: Sandwich.Preferences.BreadType?
View apple.m
@interface Sandwich: NSObject
@end
NS_SWIFT_NAME(Sandwich.Preferences)
@interface SandwichPreferences: NSObject
@end
typedef NS_ENUM(NSInteger, SandwichBreadType) {
} NS_SWIFT_NAME(SandwichPreferences.BreadType);
View first_attempt.m
NS_SWIFT_NAME(RecorderControlStyle)
@interface SRRecorderControlStyle: NSObject
@end
NS_SWIFT_NAME(RecorderControlStyle.Components)
@interface SRRecorderControlStyleComponents: NSObject
@end
typedef NS_ENUM(NSUInteger, SRRecorderControlStyleComponentsAppearance)
{} NS_SWIFT_NAME(RecorderControlStyle.Components.Appearance);
View expected.swift
var style: RecorderControlStyle?
var components: RecorderControlStyle.Components?
var appearance: RecorderControlStyle.Components.Appearance?
View problem.m
@interface SRRecorderControlStyle: NSObject
@end
@interface SRRecorderControlStyleComponents: NSObject
@end
typedef NS_ENUM(NSUInteger, SRRecorderControlStyleComponentsAppearance) {};
@Kentzo
Kentzo / appledocs.m
Created May 23, 2019
NS_SWIFT_NAME is recursive
View appledocs.m
@interface Sandwich: NSObject
@end
NS_SWIFT_NAME(Sandwich.Preferences)
@interface SandwichPreferences: NSObject
@end
typedef NS_ENUM(NSInteger, SandwichBreadType) {
} NS_SWIFT_NAME(SandwichPreferences.BreadType);