- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[drawer open];
self.targetController.enabled = NO;
- self.active = NO;
[self.jsController setup];
[self.configsController load];
[[NSWorkspace sharedWorkspace].notificationCenter
object:nil];
}
-// TODO: Active state should probably be in the ConfigsController or
-// JoystickController, not here.
-
-- (BOOL)active {
- return active;
-}
-
-- (void)setActive:(BOOL)newActive {
- activeButton.label = newActive ? @"Stop" : @"Start";
- activeButton.image = [NSImage imageNamed:newActive ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"];
- activeMenuItem.state = newActive;
- active = newActive;
-}
-
- (IBAction)toggleActivity:(id)sender {
- self.active = !self.active;
+ BOOL sendRealEvents = !self.jsController.sendingRealEvents;
+ self.jsController.sendingRealEvents = sendRealEvents;
+ activeButton.label = sendRealEvents ? @"Stop" : @"Start";
+ activeButton.image = [NSImage imageNamed:sendRealEvents ? @"NSStopProgressFreestandingTemplate" : @"NSGoRightTemplate"];
+ activeMenuItem.state = sendRealEvents;
}
- (NSUInteger)firstConfigMenuIndex {
#import "JoystickController.h"
-#import "ApplicationController.h"
#import "Config.h"
#import "ConfigsController.h"
#import "Joystick.h"
@synthesize selectedAction;
@synthesize frontWindowOnly;
@synthesize mouseLoc;
+@synthesize sendingRealEvents;
- (id)init {
if ((self = [super init])) {
IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender);
Joystick *js = [controller findJoystickByRef:device];
- if (((ApplicationController *)[NSApplication sharedApplication].delegate).active) {
+ if (controller.sendingRealEvents) {
JSAction *mainAction = [js actionForEvent:value];
[mainAction notifyEvent:value];
NSArray *children = mainAction.children ? mainAction.children : mainAction ? @[mainAction] : @[];
}
} else if ([NSApplication sharedApplication].isActive
&& [NSApplication sharedApplication].mainWindow.isVisible) {
- // joysticks not active, use it to select stuff
JSAction *handler = [js handlerForEvent:value];
if (!handler)
return;
IOHIDManagerSetDeviceMatchingMultiple(hidManager, (__bridge CFArrayRef)criteria);
IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
- IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone); // FIXME: If an error happens, report it!
+ IOReturn ret = IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone);
+ if (ret == kIOReturnSuccess) {
+ [[NSAlert alertWithMessageText:@"Input devices are unavailable"
+ defaultButton:nil
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:@"Error 0x%08x occured trying to access your devices. "
+ @"Input may not be correctly detected or mapped.",
+ ret]
+ runModal];
+ }
IOHIDManagerRegisterDeviceMatchingCallback(hidManager, add_callback, (__bridge void *)self);
IOHIDManagerRegisterDeviceRemovalCallback(hidManager, remove_callback, (__bridge void *)self);