Commit 02fb8b4b authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx/AppleRemote: simplify setters and getters

parent d94d377a
......@@ -93,9 +93,9 @@ The class is not thread safe
NSMutableDictionary* cookieToButtonMapping;
CFRunLoopSourceRef eventSource;
BOOL openInExclusiveMode;
BOOL simulatePlusMinusHold;
BOOL processesBacklog;
BOOL _openInExclusiveMode;
BOOL _simulatePlusMinusHold;
BOOL _processesBacklog;
/* state for simulating plus/minus hold */
BOOL lastEventSimulatedHold;
......@@ -103,25 +103,20 @@ The class is not thread safe
NSTimeInterval lastPlusMinusEventTime;
int remoteId;
unsigned int clickCountEnabledButtons;
NSTimeInterval maxClickTimeDifference;
unsigned int _clickCountEnabledButtons;
NSTimeInterval _maxClickTimeDifference;
NSTimeInterval lastClickCountEventTime;
AppleRemoteEventIdentifier lastClickCountEvent;
unsigned int eventClickCount;
IBOutlet id delegate;
id delegate;
}
+ (AppleRemote *)sharedInstance;
- (int) remoteId;
- (BOOL) isRemoteAvailable;
- (BOOL) isListeningToRemote;
- (void) setListeningToRemote: (BOOL) value;
- (BOOL) isOpenInExclusiveMode;
- (void) setOpenInExclusiveMode: (BOOL) value;
@property (readonly) int remoteId;
@property (readonly) BOOL remoteAvailable;
@property (readwrite) BOOL listeningToRemote;
@property (readwrite) BOOL openInExclusiveMode;
/* click counting makes it possible to recognize if the user has pressed a button repeatedly
* click counting does delay each event as it has to wait if there is another event (second click)
......@@ -129,38 +124,31 @@ The class is not thread safe
* of the user and the call of your delegate method
* click counting can be enabled individually for specific buttons. Use the property clickCountEnableButtons
* to set the buttons for which click counting shall be enabled */
- (BOOL) clickCountingEnabled;
- (void) setClickCountingEnabled: (BOOL) value;
@property (readwrite) BOOL clickCountingEnabled;
- (unsigned int) clickCountEnabledButtons;
- (void) setClickCountEnabledButtons: (unsigned int)value;
@property (readwrite) unsigned int clickCountEnabledButtons;
/* the maximum time difference till which clicks are recognized as multi clicks */
- (NSTimeInterval) maximumClickCountTimeDifference;
- (void) setMaximumClickCountTimeDifference: (NSTimeInterval) timeDiff;
@property (readwrite) NSTimeInterval maximumClickCountTimeDifference;
/* When your application needs to much time on the main thread when processing an event other events
* may already be received which are put on a backlog. As soon as your main thread
* has some spare time this backlog is processed and may flood your delegate with calls.
* Backlog processing is turned off by default. */
- (BOOL) processesBacklog;
- (void) setProcessesBacklog: (BOOL) value;
@property (readwrite) BOOL processesBacklog;
/* Sets an NSApplication delegate which starts listening when application is becoming active
* and stops listening when application resigns being active.
* If an NSApplication delegate has been already set all method calls will be forwarded to this delegate, too. */
- (BOOL) listeningOnAppActivate;
- (void) setListeningOnAppActivate: (BOOL) value;
@property (readwrite) BOOL listeningOnAppActivate;
/* Simulating plus/minus hold does deactivate sending of individual requests for plus/minus pressed down/released.
* Instead special hold events are being triggered when the user is pressing and holding plus/minus for a small period.
* With simulating enabled the plus/minus buttons do behave as the left/right buttons */
- (BOOL) simulatesPlusMinusHold;
- (void) setSimulatesPlusMinusHold: (BOOL) value;
@property (readwrite) BOOL simulatesPlusMinusHold;
/* Delegates are not retained */
- (void) setDelegate: (id) delegate;
- (id) delegate;
@property (readwrite, assign) id delegate;
- (IBAction) startListening: (id) sender;
- (IBAction) stopListening: (id) sender;
......
......@@ -64,6 +64,8 @@ const NSTimeInterval HOLD_RECOGNITION_TIME_INTERVAL=0.4;
@implementation AppleRemote
@synthesize openInExclusiveMode = _openInExclusiveMode, clickCountEnabledButtons = _clickCountEnabledButtons, maximumClickCountTimeDifference = _maxClickTimeDifference, processesBacklog=_processesBacklog, simulatesPlusMinusHold = _simulatePlusMinusHold;
#pragma public interface
static AppleRemote *_o_sharedInstance = nil;
......@@ -79,7 +81,7 @@ static AppleRemote *_o_sharedInstance = nil;
[self dealloc];
} else {
_o_sharedInstance = [super init];
openInExclusiveMode = YES;
_openInExclusiveMode = YES;
queue = NULL;
hidDeviceInterface = NULL;
cookieToButtonMapping = [[NSMutableDictionary alloc] init];
......@@ -139,7 +141,7 @@ static AppleRemote *_o_sharedInstance = nil;
/* defaults */
[self setSimulatesPlusMinusHold: YES];
maxClickTimeDifference = DEFAULT_MAXIMUM_CLICK_TIME_DIFFERENCE;
_maxClickTimeDifference = DEFAULT_MAXIMUM_CLICK_TIME_DIFFERENCE;
}
return _o_sharedInstance;
......@@ -155,7 +157,7 @@ static AppleRemote *_o_sharedInstance = nil;
return remoteId;
}
- (BOOL) isRemoteAvailable {
- (BOOL) remoteAvailable {
io_object_t hidDevice = [self findAppleRemoteDevice];
if (hidDevice != 0) {
IOObjectRelease(hidDevice);
......@@ -165,7 +167,7 @@ static AppleRemote *_o_sharedInstance = nil;
}
}
- (BOOL) isListeningToRemote {
- (BOOL) listeningToRemote {
return (hidDeviceInterface != NULL && allCookies != NULL && queue != NULL);
}
......@@ -191,15 +193,8 @@ static AppleRemote *_o_sharedInstance = nil;
return delegate;
}
- (BOOL) isOpenInExclusiveMode {
return openInExclusiveMode;
}
- (void) setOpenInExclusiveMode: (BOOL) value {
openInExclusiveMode = value;
}
- (BOOL) clickCountingEnabled {
return clickCountEnabledButtons != 0;
return self.clickCountEnabledButtons != 0;
}
- (void) setClickCountingEnabled: (BOOL) value {
if (value) {
......@@ -209,27 +204,6 @@ static AppleRemote *_o_sharedInstance = nil;
}
}
- (unsigned int) clickCountEnabledButtons {
return clickCountEnabledButtons;
}
- (void) setClickCountEnabledButtons: (unsigned int)value {
clickCountEnabledButtons = value;
}
- (NSTimeInterval) maximumClickCountTimeDifference {
return maxClickTimeDifference;
}
- (void) setMaximumClickCountTimeDifference: (NSTimeInterval) timeDiff {
maxClickTimeDifference = timeDiff;
}
- (BOOL) processesBacklog {
return processesBacklog;
}
- (void) setProcessesBacklog: (BOOL) value {
processesBacklog = value;
}
- (BOOL) listeningOnAppActivate {
id appDelegate = [NSApp delegate];
return (appDelegate!=nil && [appDelegate isKindOfClass: [AppleRemoteApplicationDelegate class]]);
......@@ -249,15 +223,8 @@ static AppleRemote *_o_sharedInstance = nil;
}
}
- (BOOL) simulatesPlusMinusHold {
return simulatePlusMinusHold;
}
- (void) setSimulatesPlusMinusHold: (BOOL) value {
simulatePlusMinusHold = value;
}
- (IBAction) startListening: (id) sender {
if ([self isListeningToRemote]) return;
if ([self listeningToRemote]) return;
io_object_t hidDevice = [self findAppleRemoteDevice];
if (hidDevice == 0) return;
......@@ -401,7 +368,7 @@ static AppleRemote* sharedInstance=nil;
- (void) sendRemoteButtonEvent: (AppleRemoteEventIdentifier) event pressedDown: (BOOL) pressedDown {
if (delegate) {
if (simulatePlusMinusHold) {
if (self.simulatesPlusMinusHold) {
if (event == kRemoteButtonVolume_Plus || event == kRemoteButtonVolume_Minus) {
if (pressedDown) {
lastPlusMinusEvent = event;
......@@ -425,7 +392,7 @@ static AppleRemote* sharedInstance=nil;
}
}
if (([self clickCountEnabledButtons] & event) == event) {
if ((self.clickCountEnabledButtons & event) == event) {
if (pressedDown==NO && (event == kRemoteButtonVolume_Minus || event == kRemoteButtonVolume_Plus)) {
return; // this one is triggered automatically by the handler
}
......@@ -444,7 +411,7 @@ static AppleRemote* sharedInstance=nil;
}
[self performSelector: @selector(executeClickCountEvent:)
withObject: [NSArray arrayWithObjects:eventNumber, timeNumber, nil]
afterDelay: maxClickTimeDifference];
afterDelay: _maxClickTimeDifference];
} else {
[delegate appleRemoteButton:event pressedDown: pressedDown clickCount:1];
}
......@@ -493,9 +460,9 @@ static AppleRemote* sharedInstance=nil;
while((subCookieString = [self validCookieSubstring: cookieString])) {
cookieString = [cookieString substringFromIndex: [subCookieString length]];
lastSubCookieString = subCookieString;
if (processesBacklog) [self handleEventWithCookieString: subCookieString sumOfValues:sumOfValues];
if (self.processesBacklog) [self handleEventWithCookieString: subCookieString sumOfValues:sumOfValues];
}
if (processesBacklog == NO && lastSubCookieString != nil) {
if (self.processesBacklog == NO && lastSubCookieString != nil) {
// process the last event of the backlog and assume that the button is not pressed down any longer.
// The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be
// a button pressed down event while in reality the user has released it.
......@@ -661,7 +628,7 @@ static void QueueCallbackFunction(void* target, IOReturn result, void* refcon,
HRESULT result;
IOHIDOptionsType openMode = kIOHIDOptionsTypeNone;
if ([self isOpenInExclusiveMode]) openMode = kIOHIDOptionsTypeSeizeDevice;
if ([self openInExclusiveMode]) openMode = kIOHIDOptionsTypeSeizeDevice;
IOReturn ioReturnValue = (*hidDeviceInterface)->open(hidDeviceInterface, openMode);
if (ioReturnValue == KERN_SUCCESS) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment