Esempio n. 1
0
void GamepadManager::makeGamepadVisible(PlatformGamepad& platformGamepad, HashSet<NavigatorGamepad*>& navigatorSet, HashSet<DOMWindow*>& domWindowSet)
{
    if (navigatorSet.isEmpty() && domWindowSet.isEmpty())
        return;

    for (auto* navigator : navigatorSet)
        navigator->gamepadConnected(platformGamepad);

    Vector<WeakPtr<DOMWindow>> weakWindows;
    for (auto* domWindow : m_domWindows)
        weakWindows.append(domWindow->createWeakPtr());

    for (auto& window : weakWindows) {
        // Event dispatch might have made this window go away.
        if (!window)
            continue;

        // This DOMWindow's Navigator might not be accessible. e.g. The DOMWindow might be in the back/forward cache.
        // If this happens the DOMWindow will not get this gamepadconnected event.
        // The new gamepad will still be visibile to it once it is restored from the back/forward cache.
        NavigatorGamepad* navigator = navigatorGamepadFromDOMWindow(window.get());
        if (!navigator)
            continue;

        Ref<Gamepad> gamepad(navigator->gamepadFromPlatformGamepad(platformGamepad));
        window->dispatchEvent(GamepadEvent::create(eventNames().gamepadconnectedEvent, gamepad.get()), window->document());
    }
}
Esempio n. 2
0
void GamepadManager::platformGamepadDisconnected(PlatformGamepad& platformGamepad)
{
    Vector<WeakPtr<DOMWindow>> weakWindows;
    for (auto* domWindow : m_domWindows)
        weakWindows.append(domWindow->createWeakPtr());

    HashSet<NavigatorGamepad*> notifiedNavigators;

    // Handle the disconnect for all DOMWindows with event listeners and their Navigators.
    for (auto& window : weakWindows) {
        // Event dispatch might have made this window go away.
        if (!window)
            continue;

        // This DOMWindow's Navigator might not be accessible. e.g. The DOMWindow might be in the back/forward cache.
        // If this happens the DOMWindow will not get this gamepaddisconnected event.
        NavigatorGamepad* navigator = navigatorGamepadFromDOMWindow(window.get());
        if (!navigator)
            continue;

        // If this Navigator hasn't seen gamepads yet then its Window should not get the disconnect event.
        if (m_gamepadBlindNavigators.contains(navigator))
            continue;

        Ref<Gamepad> gamepad(navigator->gamepadFromPlatformGamepad(platformGamepad));

        navigator->gamepadDisconnected(platformGamepad);
        notifiedNavigators.add(navigator);

        window->dispatchEvent(GamepadEvent::create(eventNames().gamepaddisconnectedEvent, gamepad.get()), window->document());
    }

    // Notify all the Navigators that haven't already been notified.
    for (auto* navigator : m_navigators) {
        if (!notifiedNavigators.contains(navigator))
            navigator->gamepadDisconnected(platformGamepad);
    }
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
	qsrand(QDateTime::currentMSecsSinceEpoch());
	QApplication app(argc, argv);
	QStringList args = app.arguments();

	if (args.count() < 2) {
		printUsage();
		return 1;
	}

	QString configPath = "./";
	if (app.arguments().contains("-c")) {
		const int index = app.arguments().indexOf("-c");
		if (app.arguments().count() <= index + 1) {
			printUsage();
			return 1;
		}

		configPath = app.arguments()[index + 1];
		if (configPath.right(1) != "/") {
			configPath += "/";
		}
	}

	QString startDirPath = QDir::currentPath();
	if (app.arguments().contains("-d")) {
		const int index = app.arguments().indexOf("-d");
		if (app.arguments().count() <= index + 1) {
			printUsage();
			return 1;
		}

		startDirPath = app.arguments()[index + 1];
	}

	if (startDirPath.right(1) != "/") {
		startDirPath += "/";
	}

	trikKernel::coreDumping::initCoreDumping(startDirPath);

#ifdef Q_WS_QWS
	QWSServer * const server = QWSServer::instance();
	if (server) {
		server->setCursorVisible(false);
	}
#endif

	trikKernel::LoggingHelper loggingHelper(startDirPath);
	Q_UNUSED(loggingHelper);

	QLOG_INFO() << "TrikRun started";

	QScopedPointer<trikControl::BrickInterface> brick(trikControl::BrickFactory::create(configPath, startDirPath));

	trikKernel::Configurer configurer(configPath + "/system-config.xml", configPath + "/model-config.xml");
	QScopedPointer<trikNetwork::GamepadInterface> gamepad(trikNetwork::GamepadFactory::create(configurer));
	QScopedPointer<trikNetwork::MailboxInterface> mailbox(trikNetwork::MailboxFactory::create(configurer));
	trikScriptRunner::TrikScriptRunner runner(*brick, mailbox.data(), gamepad.data(), startDirPath);

	QObject::connect(&runner, SIGNAL(completed(QString, int)), &app, SLOT(quit()));

	if (app.arguments().contains("-s")) {
		runner.run(args[app.arguments().indexOf("-s") + 1]);
	} else {
		args.removeAll("-qws");
		if (args.contains("-c")) {
			args.removeAt(args.indexOf("-c") + 1);
			args.removeAll("-c");
		}

		if (args.contains("-d")) {
			args.removeAt(args.indexOf("-d") + 1);
			args.removeAll("-d");
		}

		if (args.count() != 2) {
			printUsage();
			return 1;
		}

		runner.run(trikKernel::FileUtils::readFromFile(args[1]));
	}

	return app.exec();
}
Esempio n. 4
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();
        }
    }
}