コード例 #1
0
ファイル: mouse_cocoa.cpp プロジェクト: blezek/marathon-ios
static int OSX_Mouse_Thread(void *ctx)
{
	if (!ctx)
		return 0;
	struct osx_mouse_data *mdata = static_cast<struct osx_mouse_data *>(ctx);
	
	IOHIDManagerRef hid_manager = IOHIDManagerCreate(kCFAllocatorSystemDefault, kIOHIDOptionsTypeNone);
	if (!hid_manager) {
		SDL_DestroyMutex(mdata->mouse_mutex);
		delete mdata;
		return 0;
	}
	
	if (IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
		CFRelease(hid_manager);
		SDL_DestroyMutex(mdata->mouse_mutex);
		delete mdata;
		return 0;
	}
	
	IOHIDManagerRegisterInputValueCallback(hid_manager, input_callback, mdata);
	IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
		
	uint32_t page = kHIDPage_GenericDesktop;
	uint32_t usage = kHIDUsage_GD_Mouse;
	CFDictionaryRef dict = NULL;
	CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page);
	CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage);
	const void *keys[2] = { CFSTR(kIOHIDDeviceUsagePageKey), CFSTR(kIOHIDDeviceUsageKey) };
	const void *vals[2] = { pageNumRef, usageNumRef };

	if (pageNumRef && usageNumRef)
		dict = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	if (pageNumRef)
		CFRelease(pageNumRef);
	if (usageNumRef)
		CFRelease(usageNumRef);
	IOHIDManagerSetDeviceMatching(hid_manager, dict);
	if (dict)
		CFRelease(dict);

	while (!mdata->should_exit) {
		CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, false);
	}

	IOHIDManagerUnscheduleFromRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
	IOHIDManagerClose(hid_manager, kIOHIDOptionsTypeNone);
	
	CFRelease(hid_manager);
	SDL_DestroyMutex(mdata->mouse_mutex);
	delete mdata;
	return 0;
}
コード例 #2
0
ファイル: sleepwatcher.c プロジェクト: Gems/majormaco
static void initializeResumeNotifications (void)	// see TN 2187
{
	IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
	if (! hidManager) {
		message (LOG_ERR, "IOHIDManagerCreate failed\n");
		exit (1);
	}
	if (IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) {
		message (LOG_ERR, "IOHIDManagerOpen failed\n");
		exit (1);
	}
	IOHIDManagerScheduleWithRunLoop (hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
	IOHIDManagerSetDeviceMatchingMultiple (hidManager, createGenericDesktopMatchingDictionaries());
	IOHIDManagerRegisterInputValueCallback (hidManager, hidCallback, (void *) -1);
}
コード例 #3
0
HIDGamepadProvider::HIDGamepadProvider()
    : m_shouldDispatchCallbacks(false)
    , m_connectionDelayTimer(this, &HIDGamepadProvider::connectionDelayTimerFired)
    , m_inputNotificationTimer(this, &HIDGamepadProvider::inputNotificationTimerFired)
{
    m_manager = adoptCF(IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone));

    RetainPtr<CFDictionaryRef> joystickDictionary = deviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick);
    RetainPtr<CFDictionaryRef> gamepadDictionary = deviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad);

    CFDictionaryRef devices[] = { joystickDictionary.get(), gamepadDictionary.get() };

    RetainPtr<CFArrayRef> matchingArray = adoptCF(CFArrayCreate(kCFAllocatorDefault, (const void**)devices, 2, &kCFTypeArrayCallBacks));

    IOHIDManagerSetDeviceMatchingMultiple(m_manager.get(), matchingArray.get());
    IOHIDManagerRegisterDeviceMatchingCallback(m_manager.get(), deviceAddedCallback, this);
    IOHIDManagerRegisterDeviceRemovalCallback(m_manager.get(), deviceRemovedCallback, this);
    IOHIDManagerRegisterInputValueCallback(m_manager.get(), deviceValuesChangedCallback, this);
}
コード例 #4
0
static void *Sys_Input_Thread(void *inarg)
{
	struct input_data *input;
	IOReturn tIOReturn;

	input = inarg;

	pthread_mutex_lock(&input->thread_mutex);
	input->threadrunloop = CFRunLoopGetCurrent();
	pthread_cond_signal(&input->thread_has_spawned);
	pthread_mutex_unlock(&input->thread_mutex);

	input->hid_manager = IOHIDManagerCreate(kCFAllocatorSystemDefault, kIOHIDOptionsTypeNone);
	if (input->hid_manager)
	{
		IOHIDManagerSetDeviceMatching(input->hid_manager, NULL);
		IOHIDManagerRegisterInputValueCallback(input->hid_manager, input_callback, input);
		IOHIDManagerScheduleWithRunLoop(input->hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

		tIOReturn = IOHIDManagerOpen(input->hid_manager, kIOHIDOptionsTypeNone);
		if (tIOReturn == kIOReturnSuccess)
		{
			do
			{
				CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true);
			}
			while (!input->thread_shutdown);
		}

		IOHIDManagerUnscheduleFromRunLoop(input->hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

	}

	CFRelease(input->hid_manager);

	return 0;
}
コード例 #5
0
CPH_HidMacOSX::CPH_HidMacOSX()
{
	m_bindings[PS2::CControllerInfo::ANALOG_LEFT_X] = std::make_shared<CSimulatedAxisBinding>(kHIDUsage_KeyboardD, kHIDUsage_KeyboardG);
	m_bindings[PS2::CControllerInfo::ANALOG_LEFT_Y] = std::make_shared<CSimulatedAxisBinding>(kHIDUsage_KeyboardR, kHIDUsage_KeyboardF);

	m_bindings[PS2::CControllerInfo::ANALOG_RIGHT_X] = std::make_shared<CSimulatedAxisBinding>(kHIDUsage_KeyboardH, kHIDUsage_KeyboardK);
	m_bindings[PS2::CControllerInfo::ANALOG_RIGHT_Y] = std::make_shared<CSimulatedAxisBinding>(kHIDUsage_KeyboardU, kHIDUsage_KeyboardJ);

	m_bindings[PS2::CControllerInfo::START] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardReturnOrEnter);
	m_bindings[PS2::CControllerInfo::SELECT] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardRightShift);
	m_bindings[PS2::CControllerInfo::DPAD_LEFT] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardLeftArrow);
	m_bindings[PS2::CControllerInfo::DPAD_RIGHT] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardRightArrow);
	m_bindings[PS2::CControllerInfo::DPAD_UP] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardUpArrow);
	m_bindings[PS2::CControllerInfo::DPAD_DOWN] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardDownArrow);
	m_bindings[PS2::CControllerInfo::SQUARE] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardA);
	m_bindings[PS2::CControllerInfo::CROSS] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardZ);
	m_bindings[PS2::CControllerInfo::TRIANGLE] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardS);
	m_bindings[PS2::CControllerInfo::CIRCLE] = std::make_shared<CSimpleBinding>(kHIDUsage_KeyboardX);

	m_bindings[PS2::CControllerInfo::L1] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard1);
	m_bindings[PS2::CControllerInfo::L2] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard2);
	m_bindings[PS2::CControllerInfo::L3] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard3);
	m_bindings[PS2::CControllerInfo::R1] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard8);
	m_bindings[PS2::CControllerInfo::R2] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard9);
	m_bindings[PS2::CControllerInfo::R3] = std::make_shared<CSimpleBinding>(kHIDUsage_Keyboard0);

	m_hidManager = IOHIDManagerCreate(kCFAllocatorDefault, 0);
	{
		CFDictionaryRef matchingDict = CreateDeviceMatchingDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard);
		IOHIDManagerSetDeviceMatching(m_hidManager, matchingDict);
		CFRelease(matchingDict);
	}
	IOHIDManagerScheduleWithRunLoop(m_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
	IOHIDManagerOpen(m_hidManager, kIOHIDOptionsTypeNone);
	IOHIDManagerRegisterInputValueCallback(m_hidManager, InputValueCallbackStub, this);
}
コード例 #6
0
void CocoaVideoDriver::loop(Card* initial) {
    CGLPixelFormatAttribute attrs[] = {
        kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core,
        kCGLPFADisplayMask, static_cast<CGLPixelFormatAttribute>(
                CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay)),
        kCGLPFAColorSize, static_cast<CGLPixelFormatAttribute>(24),
        kCGLPFADoubleBuffer,
        kCGLPFAAccelerated,
        static_cast<CGLPixelFormatAttribute>(0),
    };

    cgl::PixelFormat pixel_format(attrs);
    cgl::Context context(pixel_format.c_obj(), NULL);
    unique_ptr<CocoaFullscreen> fullscreen;
    unique_ptr<CocoaWindowed> windowed;
    if (_fullscreen) {
        fullscreen.reset(new CocoaFullscreen(pixel_format, context, _screen_size));
        antares_event_translator_set_window(_translator.c_obj(), fullscreen->window());
        _viewport_size = fullscreen->viewport_size();
    } else {
        windowed.reset(new CocoaWindowed(pixel_format, context, _screen_size, false, true));
        antares_event_translator_set_window(_translator.c_obj(), windowed->window());
        _viewport_size = windowed->viewport_size();
    }
    GLint swap_interval = 1;
    CGLSetParameter(context.c_obj(), kCGLCPSwapInterval, &swap_interval);
    CGLSetCurrentContext(context.c_obj());

    MainLoop main_loop(*this, initial);
    main_loop.draw();
    CGLFlushDrawable(context.c_obj());
    EventBridge bridge = {_event_tracker, main_loop, context, _translator};

    antares_event_translator_set_mouse_down_callback(
            _translator.c_obj(), EventBridge::mouse_down, &bridge);
    antares_event_translator_set_mouse_up_callback(
            _translator.c_obj(), EventBridge::mouse_up, &bridge);
    antares_event_translator_set_mouse_move_callback(
            _translator.c_obj(), EventBridge::mouse_move, &bridge);
    antares_event_translator_set_caps_lock_callback(
            _translator.c_obj(), EventBridge::caps_lock, &bridge);
    antares_event_translator_set_caps_unlock_callback(
            _translator.c_obj(), EventBridge::caps_unlock, &bridge);

    cf::MutableDictionary keyboard(CFDictionaryCreateMutable(
                NULL, 0,
                &kCFCopyStringDictionaryKeyCallBacks,
                &kCFTypeDictionaryValueCallBacks));
    keyboard.set(CFSTR(kIOHIDDeviceUsagePageKey), cf::wrap(kHIDPage_GenericDesktop).c_obj());
    keyboard.set(CFSTR(kIOHIDDeviceUsageKey), cf::wrap(kHIDUsage_GD_Keyboard).c_obj());
    cf::MutableDictionary gamepad(CFDictionaryCreateMutable(
                NULL, 0,
                &kCFCopyStringDictionaryKeyCallBacks,
                &kCFTypeDictionaryValueCallBacks));
    gamepad.set(CFSTR(kIOHIDDeviceUsagePageKey), cf::wrap(kHIDPage_GenericDesktop).c_obj());
    gamepad.set(CFSTR(kIOHIDDeviceUsageKey), cf::wrap(kHIDUsage_GD_GamePad).c_obj());
    cf::MutableArray criteria(CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks));
    criteria.append(keyboard.c_obj());
    criteria.append(gamepad.c_obj());

    auto hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
    IOHIDManagerSetDeviceMatchingMultiple(hid_manager, criteria.c_obj());
    IOHIDManagerScheduleWithRunLoop(hid_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
    IOReturn r = IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone);
    if (r != 0) {
        throw Exception("IOHIDManagerOpen");
    }
    IOHIDManagerRegisterInputValueCallback(hid_manager, EventBridge::hid_event, &bridge);

    while (!main_loop.done()) {
        int64_t at;
        if (main_loop.top()->next_timer(at)) {
            at += _start_time;
            if (antares_event_translator_next(_translator.c_obj(), at)) {
                bridge.send_all();
            } else {
                main_loop.top()->fire_timer();
                main_loop.draw();
                CGLFlushDrawable(context.c_obj());
            }
        } else {
            at = std::numeric_limits<int64_t>::max();
            antares_event_translator_next(_translator.c_obj(), at);
            bridge.send_all();
        }
    }
}