diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-08-30 08:52:59 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-08-30 08:53:22 +0200 |
commit | 4ad662d67bb12feed12095cd9a41a46bfac16d1c (patch) | |
tree | f3dbd54f9079eadea8a9d08ceb3ac64a8c191cfe /ftnoir_tracker_joystick | |
parent | 1dae49c90d62d7f0f627e1ac2401b94a2c67775a (diff) |
win32-joystick: fix duplicate device name selection logic
Tested-by: @nanospork
Closes #230
Diffstat (limited to 'ftnoir_tracker_joystick')
3 files changed, 53 insertions, 6 deletions
diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h index 76bafbd4..75305f07 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick.h @@ -14,6 +14,7 @@ #include <QList> #include <QMutex> #include <QFrame> +#include <QStringList> #include <cmath> #include "opentrack/plugin-api.hpp" #ifndef DIRECTINPUT_VERSION @@ -86,6 +87,11 @@ public: Ui::UIJoystickControls ui; FTNoIR_Tracker* tracker; settings s; + struct joys { + QString name; + QString guid; + }; + QList<joys> _joys; private slots: void doOK(); void doCancel(); diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui index 3533f93d..88737023 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_controls.ui @@ -9,7 +9,7 @@ <rect> <x>0</x> <y>0</y> - <width>251</width> + <width>498</width> <height>303</height> </rect> </property> @@ -79,6 +79,12 @@ <layout class="QGridLayout" name="gridLayout"> <item row="0" column="1"> <widget class="QComboBox" name="joy_1"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="currentIndex"> <number>1</number> </property> @@ -131,6 +137,12 @@ </item> <item row="1" column="1"> <widget class="QComboBox" name="joy_2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="currentIndex"> <number>2</number> </property> @@ -183,6 +195,12 @@ </item> <item row="2" column="1"> <widget class="QComboBox" name="joy_3"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="currentIndex"> <number>3</number> </property> @@ -235,6 +253,12 @@ </item> <item row="3" column="1"> <widget class="QComboBox" name="joy_4"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="currentIndex"> <number>4</number> </property> @@ -287,6 +311,12 @@ </item> <item row="4" column="1"> <widget class="QComboBox" name="joy_5"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="currentIndex"> <number>5</number> </property> @@ -339,6 +369,12 @@ </item> <item row="5" column="1"> <widget class="QComboBox" name="joy_6"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="currentIndex"> <number>6</number> </property> diff --git a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp index f3b7077c..0463933f 100644 --- a/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp +++ b/ftnoir_tracker_joystick/ftnoir_tracker_joystick_dialog.cpp @@ -4,9 +4,12 @@ static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext ) { auto self = ( TrackerControls* )pContext; + auto name = QString(pdidInstance->tszInstanceName); + auto guid = guid_to_string(pdidInstance->guidInstance); + TrackerControls::joys cur { name, guid }; + self->_joys.append(cur); - self->ui.joylist->addItem(QString(pdidInstance->tszInstanceName), - guid_to_string(pdidInstance->guidInstance)); + self->ui.joylist->addItem(name + " " + guid); return DIENUM_CONTINUE; } @@ -38,8 +41,6 @@ fin: g_pDI->Release(); } - tie_setting(s.joyid, ui.joylist); - tie_setting(s.joy_1, ui.joy_1); tie_setting(s.joy_2, ui.joy_2); tie_setting(s.joy_3, ui.joy_3); @@ -49,7 +50,11 @@ fin: } void TrackerControls::doOK() { - s.guid = ui.joylist->currentData().toString(); + int idx = ui.joylist->currentIndex(); + joys def { "", "" }; + auto val = _joys.value(idx, def); + s.guid = val.guid; + s.joyid = val.name; s.b->save(); if (tracker) tracker->reload(); |