Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DDHidLib/DDHidDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
BOOL mListenInExclusiveMode;
DDHidQueue * mDefaultQueue;
int mTag;
int mLogicalDeviceNumber;
NSUInteger mLogicalDeviceNumber;
}

- (id) initWithDevice: (io_object_t) device error: (NSError **) error;
- (id) initLogicalWithDevice: (io_object_t) device
logicalDeviceNumber: (int) logicalDeviceNumber
error: (NSError **) error;
- (int) logicalDeviceCount;
- (NSUInteger) logicalDeviceCount;

#pragma mark -
#pragma mark Finding Devices
Expand Down
4 changes: 2 additions & 2 deletions DDHidLib/DDHidDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ + (NSArray *) allDevicesMatchingCFDictionary: (CFDictionaryRef) matchDictionary
return devices;
}

- (int) logicalDeviceCount;
- (NSUInteger) logicalDeviceCount;
{
return 1;
}
Expand Down Expand Up @@ -287,7 +287,7 @@ - (NSString *) productName
if ([self logicalDeviceCount] > 1)
{
productName = [productName stringByAppendingString:
[NSString stringWithFormat:@" #%d", mLogicalDeviceNumber + 1]];
[NSString stringWithFormat:@" #%lu", mLogicalDeviceNumber + 1]];
}
return productName;
}
Expand Down
10 changes: 5 additions & 5 deletions DDHidLib/DDHidJoystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
#pragma mark -
#pragma mark StickElements - indexed accessors

- (unsigned int) countOfStickElements;
- (NSUInteger) countOfStickElements;
- (DDHidElement *) objectInStickElementsAtIndex: (unsigned int)index;

#pragma mark -
#pragma mark PovElements - indexed accessors

- (unsigned int) countOfPovElements;
- (NSUInteger) countOfPovElements;
- (DDHidElement *) objectInPovElementsAtIndex: (unsigned int)index;

- (NSArray *) allElements;
Expand All @@ -74,19 +74,19 @@
logicalDeviceNumber: (int) logicalDeviceNumber
error: (NSError **) error;

- (int) logicalDeviceCount;
- (NSUInteger) logicalDeviceCount;

#pragma mark -
#pragma mark Joystick Elements

- (unsigned) numberOfButtons;
- (NSUInteger) numberOfButtons;

- (NSArray *) buttonElements;

#pragma mark -
#pragma mark Sticks - indexed accessors

- (unsigned int) countOfSticks;
- (NSUInteger) countOfSticks;
- (DDHidJoystickStick *) objectInSticksAtIndex: (unsigned int)index;

- (void) addElementsToQueue: (DDHidQueue *) queue;
Expand Down
22 changes: 11 additions & 11 deletions DDHidLib/DDHidJoystick.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ - (id) initLogicalWithDevice: (io_object_t) device
mLogicalDeviceElements = [[NSMutableArray alloc] init];

[self initLogicalDeviceElements];
int logicalDeviceCount = [mLogicalDeviceElements count];
NSUInteger logicalDeviceCount = [mLogicalDeviceElements count];
if (logicalDeviceCount == 0)
{
return nil;
Expand Down Expand Up @@ -151,7 +151,7 @@ - (void) dealloc
mButtonElements = nil;
}

- (int) logicalDeviceCount;
- (NSUInteger) logicalDeviceCount;
{
return [mLogicalDeviceElements count];
}
Expand All @@ -167,15 +167,15 @@ - (NSArray *) buttonElements;
return mButtonElements;
}

- (unsigned) numberOfButtons;
- (NSUInteger) numberOfButtons;
{
return [mButtonElements count];
}

#pragma mark -
#pragma mark Sticks - indexed accessors

- (unsigned int) countOfSticks
- (NSUInteger) countOfSticks
{
return [mSticks count];
}
Expand Down Expand Up @@ -233,7 +233,7 @@ - (void) initLogicalDeviceElements;
if (usagePage == kHIDPage_GenericDesktop &&
(usageId == kHIDUsage_GD_Joystick || usageId == kHIDUsage_GD_GamePad))
{
[mLogicalDeviceElements addObject: [NSArray arrayWithObject: element]];
[mLogicalDeviceElements addObject: @[element]];
}
}
}
Expand Down Expand Up @@ -351,11 +351,11 @@ - (int) normalizeValue: (int) value
forElement: (DDHidElement *) element;
{
int normalizedUnits = DDHID_JOYSTICK_VALUE_MAX - DDHID_JOYSTICK_VALUE_MIN;
int elementUnits = [element maxValue] - [element minValue];
long elementUnits = [element maxValue] - [element minValue];

int normalizedValue = (((int64_t)(value - [element minValue]) * normalizedUnits) /
long normalizedValue = (((int64_t)(value - [element minValue]) * normalizedUnits) /
elementUnits) + DDHID_JOYSTICK_VALUE_MIN;
return normalizedValue;
return (int)normalizedValue;
}

- (int) povValue: (int) value
Expand All @@ -373,7 +373,7 @@ - (int) povValue: (int) value

// Do like DirectInput and express the hatswitch value in hundredths of a
// degree, clockwise from north.
return 36000 / (max - min + 1) * (value - min);
return (int)(36000 / (max - min + 1) * (value - min));
}

- (BOOL) findStick: (unsigned *) stick
Expand Down Expand Up @@ -613,7 +613,7 @@ - (DDHidElement *) yAxisElement;
#pragma mark -
#pragma mark mStickElements - indexed accessors

- (unsigned int) countOfStickElements
- (NSUInteger) countOfStickElements
{
return [mStickElements count];
}
Expand All @@ -626,7 +626,7 @@ - (DDHidElement *) objectInStickElementsAtIndex: (unsigned int)index
#pragma mark -
#pragma mark PovElements - indexed accessors

- (unsigned int) countOfPovElements;
- (NSUInteger) countOfPovElements;
{
return [mPovElements count];
}
Expand Down
2 changes: 1 addition & 1 deletion DDHidLib/DDHidKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

- (NSArray *) keyElements;

- (unsigned) numberOfKeys;
- (NSUInteger) numberOfKeys;

- (void) addElementsToQueue: (DDHidQueue *) queue;

Expand Down
2 changes: 1 addition & 1 deletion DDHidLib/DDHidKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ - (NSArray *) keyElements;
return mKeyElements;
}

- (unsigned) numberOfKeys;
- (NSUInteger) numberOfKeys;
{
return [mKeyElements count];
}
Expand Down
2 changes: 1 addition & 1 deletion DDHidLib/DDHidKeyboardBarcodeScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

- (NSArray *) keyElements;

- (unsigned) numberOfKeys;
- (NSUInteger) numberOfKeys;

- (void) addElementsToQueue: (DDHidQueue *) queue;

Expand Down
2 changes: 1 addition & 1 deletion DDHidLib/DDHidKeyboardBarcodeScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (NSArray *) keyElements;
return mKeyElements;
}

- (unsigned) numberOfKeys;
- (NSUInteger) numberOfKeys;
{
return [mKeyElements count];
}
Expand Down
2 changes: 1 addition & 1 deletion DDHidLib/DDHidMouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

- (NSArray *) buttonElements;

- (unsigned) numberOfButtons;
- (NSUInteger) numberOfButtons;

- (void) addElementsToQueue: (DDHidQueue *) queue;

Expand Down
2 changes: 1 addition & 1 deletion DDHidLib/DDHidMouse.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ - (NSArray *) buttonElements;
return mButtonElements;
}

- (unsigned) numberOfButtons;
- (NSUInteger) numberOfButtons;
{
return [mButtonElements count];
}
Expand Down
19 changes: 11 additions & 8 deletions DDHidLib/NSXReturnThrowError/NSXReturnThrowError.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,16 @@ void NSXMakeErrorImp(const char *objCType_, intptr_t result_, const char *file_,
}

if (errorDomain) {
*error_ = [NSError errorWithDomain:errorDomain
code:errorCode
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithUTF8String:file_], @"reportingFile",
[NSNumber numberWithInt:line_], @"reportingLine",
[NSString stringWithUTF8String:function_], @"reportingMethod",
[NSString stringWithUTF8String:code_], @"origin",
nil]];
if (error_ != nil)
{
*error_ = [NSError errorWithDomain:errorDomain
code:errorCode
userInfo:@{
@"reportingFile" : @(file_),
@"reportingLine" : @(line_),
@"reportingMethod" : @(function_),
@"origin" : @(code_),
}];
}
}
}
7 changes: 5 additions & 2 deletions FFHelperApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
CGEventSourceRef sourceRef = CGEventCreateSourceFromEvent(ev);
CGEventRef newEvent = CGEventCreateKeyboardEvent(sourceRef, [regularKey intValue], keyState);
CFRelease(sourceRef);
CFAutorelease(newEvent);
return newEvent;
}
}
Expand All @@ -114,7 +115,6 @@
newE = [NSEvent otherEventWithType:NSSystemDefined location:[e locationInWindow] modifierFlags:([e modifierFlags] | ([e type] == NSKeyDown ? 0xa00 : 0xb00)) timestamp:[e timestamp] windowNumber:[e windowNumber] context:[e context] subtype:8 data1:(specialCode << 16) + (([e type] == NSKeyDown ? 0x0a : 0x0b) << 8) data2:-1];
}
CGEventRef newEvent = [newE CGEvent];
CFRetain(newEvent); // newEvent gets released by the event system
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-[NSEvent CGEvent] is documented thusly:

The CGEventRef opaque type returned is autoreleased. If no CGEventRef object corresponding to the NSEvent object can be created, this method returns NULL.

Since it's autoreleased, I don't think we need to retain it here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, but events returned by event taps are otherwise released:

If the event tap is an active filter, your callback function should return one of the following:
...
A newly-constructed event. After the new event has been passed back to the event system, the new event will be released along with the original event.

(https://developer.apple.com/documentation/coregraphics/cgeventtapcallback)

I read that as saying it needs to be retained before it's returned. Do you agree, @ZevEisenberg?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s effectively what an autorelease does. It’s a deferred release, so the +1 retain count from being created will be in effect until the run loop drains the main autorelease pool. Caveat: I’m a little sleep deprived at the moment, but my reading is that, since the value returned from [newE CGEvent] is autoreleased already, it will not get a further release until the pool drains.

return newEvent;
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ - (void)listenForKeyEvents

if (AXIsProcessTrustedWithOptions != NULL) {
// 10.9 or higher
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:(id)kCFBooleanFalse, kAXTrustedCheckOptionPrompt, nil];
NSDictionary *options = @{ (__bridge NSString *)kAXTrustedCheckOptionPrompt : (id)kCFBooleanFalse };
eventTapTest = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, 0,
eventMask, myCGEventCallback, NULL);
if (!AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)options) || !eventTapTest) {
Expand Down Expand Up @@ -204,6 +204,9 @@ - (void)listenForKeyEvents
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource,
kCFRunLoopCommonModes);

// Source is retained by the run loop.
CFRelease(runLoopSource);

// Enable the event tap.
CGEventTapEnable(eventTap, true);

Expand Down
2 changes: 1 addition & 1 deletion FFHelperAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ + (void) launchHelperApp {
NSURL *helperAppURL = [NSURL fileURLWithPath:[FFHelperAppController pathToHelperApp]];

unsigned options = NSWorkspaceLaunchWithoutAddingToRecents | NSWorkspaceLaunchWithoutActivation | NSWorkspaceLaunchAsync;
[[NSWorkspace sharedWorkspace] openURLs:[NSArray arrayWithObject:helperAppURL]
[[NSWorkspace sharedWorkspace] openURLs:@[helperAppURL]
withAppBundleIdentifier:nil
options:options
additionalEventParamDescriptor:nil
Expand Down
Loading