diff --git a/src/axis.cpp b/src/axis.cpp index e1b4349..2bb4eeb 100644 --- a/src/axis.cpp +++ b/src/axis.cpp @@ -7,7 +7,7 @@ ((a) < (a_low) ? (a_low) : (a) > (a_high) ? (a_high) : (a)) -Axis::Axis( int i ) { +Axis::Axis( int i, QObject *parent ) : QObject(parent) { index = i; isOn = false; isDown = false; diff --git a/src/axis.h b/src/axis.h index b76e57a..d05f510 100644 --- a/src/axis.h +++ b/src/axis.h @@ -26,7 +26,7 @@ class Axis : public QObject { //so AxisEdit can manipulate fields directly. friend class AxisEdit; public: - Axis( int i ); + Axis( int i, QObject *parent = 0 ); ~Axis(); //read axis settings from a stream bool read( QTextStream* stream ); diff --git a/src/button.cpp b/src/button.cpp index 438058f..0683954 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -1,7 +1,7 @@ #include "button.h" #include "event.h" -Button::Button( int i ) { +Button::Button( int i, QObject *parent ) : QObject(parent) { index = i; isButtonPressed = false; isDown = false; diff --git a/src/button.h b/src/button.h index a0954be..11c4bc3 100644 --- a/src/button.h +++ b/src/button.h @@ -14,7 +14,7 @@ class Button : public QObject { Q_OBJECT friend class ButtonEdit; public: - Button( int i ); + Button( int i, QObject *parent = 0 ); ~Button(); //read from stream bool read( QTextStream* stream ); diff --git a/src/joypad.cpp b/src/joypad.cpp index d44834c..a8bb838 100644 --- a/src/joypad.cpp +++ b/src/joypad.cpp @@ -16,6 +16,9 @@ JoyPad::JoyPad( int i, int dev ) { debug_mesg("Valid file handle, setting up handlers and reading axis configs...\n"); resetToDev(dev); debug_mesg("done resetting and setting up device index %d\n", i); + char id[200]; + ioctl(joydev, JSIOCGNAME(199), id); + deviceId = id; } else { debug_mesg("This joypad does not have a valid file handle, not setting up event listeners\n"); } @@ -41,10 +44,10 @@ void JoyPad::resetToDev(int dev ) { //that axis into use, the key assignment will not be lost because the axis //will already exist and no new axis will be created. for (int i = 0; i < axes; i++) { - if (Axes[i] == 0) Axes.insert(i, new Axis( i )); + if (Axes[i] == 0) Axes.insert(i, new Axis( i, this )); } for (int i = 0; i < buttons; i++) { - if (Buttons[i] == 0) Buttons.insert(i, new Button( i )); + if (Buttons[i] == 0) Buttons.insert(i, new Button( i, this )); } struct pollfd read_struct; read_struct.fd = joydev; @@ -215,7 +218,7 @@ void JoyPad::release() { void JoyPad::jsevent( js_event msg ) { //if there is a JoyPadWidget around, ie, if the joypad is being edited - if (jpw != NULL) { + if (jpw != NULL && hasFocus) { //tell the dialog there was an event. It will use this to flash //the appropriate button, if necesary. jpw->jsevent(msg); @@ -291,3 +294,7 @@ void JoyPad::errorRead(int fd) { joydev = -1; debug_mesg("Done disabling device with fd %d\n", fd); } + +void JoyPad::focusChange(bool focusState) { + hasFocus = !focusState; +} diff --git a/src/joypad.h b/src/joypad.h index 8ab6a99..c58475c 100644 --- a/src/joypad.h +++ b/src/joypad.h @@ -59,6 +59,7 @@ class JoyPad : public QObject{ JoyPadWidget* widget(QWidget* parent, int i); //called when the joypad is no longer being edited. void releaseWidget(); + QString getId(); protected: //lookup axes and buttons. These are dictionaries to support //layouts with different numbers of axes/buttons than the current @@ -74,9 +75,12 @@ class JoyPad : public QObject{ JoyPadWidget* jpw; QSocketNotifier *joydevFileHandle; QSocketNotifier *joydevFileException; + QString deviceId; + bool hasFocus; public slots: void handleJoyEvents(int fd); void errorRead(int fd); + void focusChange(bool windowHasFocus); }; #endif diff --git a/src/joypadw.cpp b/src/joypadw.cpp index c5d85c2..824b59a 100644 --- a/src/joypadw.cpp +++ b/src/joypadw.cpp @@ -1,5 +1,4 @@ #include "joypadw.h" -//Added by qt3to4: JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent ) : QWidget(parent) { diff --git a/src/layout_edit.cpp b/src/layout_edit.cpp index 0c22387..e7b5a93 100644 --- a/src/layout_edit.cpp +++ b/src/layout_edit.cpp @@ -48,6 +48,7 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) { { it.next(); names[i] = it.value()->getName(); + connect(this, SIGNAL(focusChange(bool)), it.value(), SLOT(focusChange(bool))); ++i; } } while (0); @@ -157,6 +158,7 @@ void LayoutEdit::updateJoypadWidgets() { } void LayoutEdit::windowActivationChange( bool oldActive ) { + emit focusChange(oldActive); if (oldActive) return; //whenever the window becomes active, release all pressed buttons! This way //you don't get any presses without releases to confuse things. diff --git a/src/layout_edit.h b/src/layout_edit.h index e1c5658..adb9035 100644 --- a/src/layout_edit.h +++ b/src/layout_edit.h @@ -16,6 +16,7 @@ class LayoutEdit; class LayoutManager; class LayoutEdit : public QWidget { + Q_OBJECT public: LayoutEdit( LayoutManager* l ); //swap to a new layout @@ -23,6 +24,8 @@ class LayoutEdit : public QWidget { //update the list of available layouts void updateLayoutList(); void updateJoypadWidgets(); + signals: + void focusChange(bool); protected: //the layout manager this represents LayoutManager* lm;