Ejemplo n.º 1
0
bool Joystick::controllerAxisChanged(const SDL_Event *event) {
    if (!ControllerMatchEvent(event->caxis))
        return false;

    const SDL_ControllerAxisEvent *caxis = &event->caxis;
    auto ev = ControllerAxisEvent::fromSDLEvent(*caxis);
    emit inputEventReceived(&ev, caxis->value);
    emit inputEventReceivedQML(QString(ev), caxis->value);

    // make analog stick emulate dpad
    if (m_mapping->deviceType() == RETRO_DEVICE_JOYPAD) {
        static int16_t threshold = 25000; // arbitrary. TODO: make it configurable
        static const QMap<SDL_GameControllerAxis, QPair<unsigned, unsigned>> mapping {
            { SDL_CONTROLLER_AXIS_LEFTX, { RETRO_DEVICE_ID_JOYPAD_LEFT,
                                           RETRO_DEVICE_ID_JOYPAD_RIGHT } },
            { SDL_CONTROLLER_AXIS_LEFTY, { RETRO_DEVICE_ID_JOYPAD_UP,
                                           RETRO_DEVICE_ID_JOYPAD_DOWN } }
        };
        auto axis = static_cast<SDL_GameControllerAxis>(caxis->axis);
        if (mapping.contains(axis)) {
            auto buttons_id = mapping.value(axis);
            setState(buttons_id.first, (caxis->value < -threshold) ? true : false);
            setState(buttons_id.second, (caxis->value > threshold) ? true : false);
        }
    }
    return true;
}
Ejemplo n.º 2
0
void Ut_EventEater::testButtonEvents()
{
    QFETCH(int, eventType);
    QFETCH(Window, winId);
    QFETCH(int, verifyButtonEventSpyCount);

    XEvent event;
    event.type = eventType;
    event.xany.window = winId;

    QSignalSpy spy(m_subject, SIGNAL(inputEventReceived()));
    m_subject->handleXEvent(event);

    QCOMPARE(spy.count(), verifyButtonEventSpyCount);
}
void ScreenLockBusinessLogic::toggleEventEater(bool toggle)
{
    if (toggle) {
        if (eventEaterWindow == NULL) {
            // Create the event eater window if it doesn't exist yet
            eventEaterWindow = new EventEater;
            eventEaterWindow->installEventFilter(new CloseEventEater(this));
            connect(eventEaterWindow, SIGNAL(inputEventReceived()), this, SLOT(hideEventEater()));
        }

        eventEaterWindow->show();
    } else {
        if (eventEaterWindow != NULL) {
            eventEaterWindow->hide();
        }
    }
}
Ejemplo n.º 4
0
bool Joystick::controllerButtonChanged(const SDL_Event *event) {
    if (!ControllerMatchEvent(event->cbutton))
        return false;

    const SDL_ControllerButtonEvent *cbutton = &event->cbutton;
    auto ev = ControllerButtonEvent::fromSDLEvent(*cbutton);
    bool is_pressed = (cbutton->type == SDL_CONTROLLERBUTTONDOWN) ? true : false;

    emit inputEventReceived(&ev, is_pressed);
    emit inputEventReceivedQML(QString(ev), is_pressed);

    auto retro_id = m_mapping->getMapping(&ev);
    if (retro_id != (unsigned)~0)
        setState(retro_id, is_pressed);

    return true;
}