diff --git a/src/joypad.cpp b/src/joypad.cpp index 0b45b0c..0f20fcb 100644 --- a/src/joypad.cpp +++ b/src/joypad.cpp @@ -19,14 +19,6 @@ JoyPad::JoyPad( int i, int dev, QObject *parent ) debug_mesg("Valid file handle, setting up handlers and reading axis configs...\n"); open(dev); debug_mesg("done resetting and setting up device index %d\n", i); - char id[256]; - memset(id, 0, sizeof(id)); - if (ioctl(joydev, JSIOCGNAME(sizeof(id)), id) < 0) { - deviceId = "Unknown"; - } - else { - deviceId = id; - } } else { debug_mesg("This joypad does not have a valid file handle, not setting up event listeners\n"); } @@ -70,6 +62,15 @@ void JoyPad::open(int dev) { close(); joydev = dev; + char id[256]; + memset(id, 0, sizeof(id)); + if (ioctl(joydev, JSIOCGNAME(sizeof(id)), id) < 0) { + deviceId = "Unknown"; + } + else { + deviceId = id; + } + //read in the number of axes / buttons axisCount = 0; ioctl (joydev, JSIOCGAXES, &axisCount); @@ -176,7 +177,7 @@ bool JoyPad::readConfig( QTextStream &stream ) { //only actually writes something if this JoyPad is NON DEFAULT. void JoyPad::write( QTextStream &stream ) { if (!axes.empty() || !buttons.empty()) { - stream << getName() << " {\n"; + stream << "Joystick " << index << " {\n"; foreach (Axis *axis, axes) { axis->write(stream); } diff --git a/src/joypad.h b/src/joypad.h index b6e70e1..ac69671 100644 --- a/src/joypad.h +++ b/src/joypad.h @@ -46,8 +46,8 @@ class JoyPad : public QObject { bool isDefault(); //read the dimensions on the real joystick and use them void open( int dev ); - //generates a name ("Joystick 1") - QString getName() const { return QString("Joystick %1").arg(index+1);} + const QString& getDeviceId() const { return deviceId; } + QString getName() const { return QString("Joystick %1 (%2)").arg(index+1).arg(deviceId); } int getIndex() const { return index; } private: