Skip to content

Commit

Permalink
Fix switching between controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulik committed Jul 4, 2023
1 parent f3833bc commit 4fe08f5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
10 changes: 0 additions & 10 deletions resources/qml/DebugOverlay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ Item {
root.visible = !root.visible
}

SteamInputControl {
objectName: "DebugOverlayInput"
controller: steam_input.lastController

enabled: visible

actionSet: "deckfm"
actionSetLayers: []
}

Rectangle {
anchors.fill: parent
color: "black"
Expand Down
2 changes: 2 additions & 0 deletions src/QSteamworks/QSteamInput/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ void Controller::onActionEvent(SteamInputActionEvent_t *event) {

auto digital = event->eEventType == ESteamInputActionEventType_DigitalAction;

emit userInteracted();

if (digital) {
actionHandle = event->digitalAction.actionHandle;

Expand Down
1 change: 1 addition & 0 deletions src/QSteamworks/QSteamInput/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Controller : public QObject {
void actionSetsChanged();
void actionSetChanged();

void userInteracted();
void inputEvent(const QSteamworks::QSteamInput::InputEvent &event);

void actionStatesChanged();
Expand Down
12 changes: 6 additions & 6 deletions src/QSteamworks/steaminput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@ void SteamInput::onControllerConnected(SteamInputDeviceConnected_t *cb) {

auto controller = new Controller(handle, name, m_iga);

connect(controller, &Controller::inputEvent, controller, [controller, this](auto e) {
connect(controller, &Controller::userInteracted, controller, [controller, this]() {
if (m_lastController != controller) {
m_lastController = controller;
emit lastControllerChanged();
}
emit inputEvent(e);
});

connect(controller, &Controller::inputEvent, this, &SteamInput::inputEvent);
connect(this, &SteamInput::configurationLoaded, controller, &Controller::loadActions);

controller->moveToThread(QGuiApplication::instance()->thread());
controller->setParent(this);

m_controllers[handle] = controller;
emit controllersChanged();

if (m_controllers.count() == 1) { // First added controller
m_lastController = controller;
emit lastControllerChanged();
}
m_lastController = controller;
emit lastControllerChanged();

qDebug() << "Controller connected:" << controller->name() << controller->handle();
}
Expand Down

0 comments on commit 4fe08f5

Please sign in to comment.