an axis may now press a mouse button and fix many warnings

This commit is contained in:
Mathias Panzenböck
2014-01-31 02:38:47 +01:00
parent ca7da9dad6
commit 6fa91c4529
9 changed files with 78 additions and 30 deletions

View File

@ -97,6 +97,26 @@ bool Axis::read( QTextStream* stream ) {
if (ok && val >= 0 && val <= MAXKEY) nkeycode = val; if (ok && val >= 0 && val <= MAXKEY) nkeycode = val;
else return false; else return false;
} }
else if (*it == "+mouse") {
++it;
if (it == words.end()) return false;
val = (*it).toInt(&ok);
if (ok && val >= 0 && val <= MAXKEY) {
puseMouse = true;
pkeycode = val;
}
else return false;
}
else if (*it == "-mouse") {
++it;
if (it == words.end()) return false;
val = (*it).toInt(&ok);
if (ok && val >= 0 && val <= MAXKEY) {
nuseMouse = true;
nkeycode = val;
}
else return false;
}
//the rest of the options are keywords without integers //the rest of the options are keywords without integers
else if (*it == "gradient") { else if (*it == "gradient") {
gradient = true; gradient = true;
@ -144,8 +164,9 @@ void Axis::write( QTextStream* stream ) {
if (dZone != DZONE) *stream << "dZone " << dZone << ", "; if (dZone != DZONE) *stream << "dZone " << dZone << ", ";
if (xZone != XZONE) *stream << "xZone " << xZone << ", "; if (xZone != XZONE) *stream << "xZone " << xZone << ", ";
if (mode == keybd) { if (mode == keybd) {
*stream << "+key " << pkeycode << ", " *stream
<< "-key " << nkeycode << "\n"; << (puseMouse ? "+mouse " : "+key ") << pkeycode << ", "
<< (nuseMouse ? "-mouse " : "-key ") << nkeycode << "\n";
} }
else { else {
if (gradient) *stream << "maxSpeed " << maxSpeed << ", "; if (gradient) *stream << "maxSpeed " << maxSpeed << ", ";
@ -226,6 +247,8 @@ void Axis::toDefault() {
mode = keybd; mode = keybd;
pkeycode = 0; pkeycode = 0;
nkeycode = 0; nkeycode = 0;
puseMouse = false;
nuseMouse = false;
downkey = 0; downkey = 0;
state = 0; state = 0;
adjustGradient(); adjustGradient();
@ -239,7 +262,9 @@ bool Axis::isDefault() {
(xZone == XZONE) && (xZone == XZONE) &&
(mode == keybd) && (mode == keybd) &&
(pkeycode == 0) && (pkeycode == 0) &&
(nkeycode == 0); (nkeycode == 0) &&
(puseMouse == false) &&
(nuseMouse == false) ;
} }
bool Axis::inDeadZone( int val ) { bool Axis::inDeadZone( int val ) {
@ -256,19 +281,34 @@ bool Axis::inDeadZone( int val ) {
QString Axis::status() { QString Axis::status() {
QString result = getName() + " : ["; QString result = getName() + " : [";
if (mode == keybd) { if (mode == keybd) {
if (throttle == 0) if (throttle == 0) {
result += "KEYBOARD"; if (puseMouse != nuseMouse) {
else result += "THROTTLE"; result += "KEYBOARD/MOUSE";
}
else if (puseMouse) {
result += "MOUSE";
}
else {
result += "KEYBOARD";
}
}
else {
result += "THROTTLE";
}
} }
else result += "MOUSE"; else result += "MOUSE";
return result + "]"; return result + "]";
} }
void Axis::setKey(bool positive, int value) { void Axis::setKey(bool positive, int value) {
if (positive) if (positive) {
pkeycode = value; pkeycode = value;
else puseMouse = false;
}
else {
nkeycode = value; nkeycode = value;
nuseMouse = false;
}
} }
void Axis::timerTick( int tick ) { void Axis::timerTick( int tick ) {
@ -310,12 +350,13 @@ void Axis::move( bool press ) {
//dialog being open and blocking events from happening. //dialog being open and blocking events from happening.
if (isDown == press) return; if (isDown == press) return;
isDown = press; isDown = press;
bool useMouse = (state > 0)?puseMouse:nuseMouse;
if (press) { if (press) {
e.type = KPRESS; e.type = useMouse?BPRESS:KPRESS;
downkey = (state > 0)?pkeycode:nkeycode; downkey = (state > 0)?pkeycode:nkeycode;
} }
else { else {
e.type = KREL; e.type = useMouse?BREL:KREL;
} }
e.value1 = downkey; e.value1 = downkey;
e.value2 = 0; e.value2 = 0;

View File

@ -85,6 +85,8 @@ class Axis : public QObject {
int pkeycode; int pkeycode;
//negative keycode //negative keycode
int nkeycode; int nkeycode;
bool puseMouse;
bool nuseMouse;
//the key that is currently pressed //the key that is currently pressed
int downkey; int downkey;
//the position of the axis, as from jsevent //the position of the axis, as from jsevent

View File

@ -28,7 +28,7 @@ AxisEdit::AxisEdit( Axis* ax )
v2->addWidget(CGradient); v2->addWidget(CGradient);
CMode = new QComboBox(this); CMode = new QComboBox(this);
CMode->insertItem((int)keybd, QString("Keyboard"), Qt::DisplayRole); CMode->insertItem((int)keybd, QString("Keyboard/Mouse Button"), Qt::DisplayRole);
CMode->insertItem((int) mousepv,QString("Mouse (Vert.)"),Qt::DisplayRole); CMode->insertItem((int) mousepv,QString("Mouse (Vert.)"),Qt::DisplayRole);
CMode->insertItem((int) mousenv, QString("Mouse (Vert. Rev.)"), Qt::DisplayRole); CMode->insertItem((int) mousenv, QString("Mouse (Vert. Rev.)"), Qt::DisplayRole);
CMode->insertItem((int) mouseph, "Mouse (Hor.)", Qt::DisplayRole); CMode->insertItem((int) mouseph, "Mouse (Hor.)", Qt::DisplayRole);
@ -80,7 +80,7 @@ AxisEdit::AxisEdit( Axis* ax )
h->setSpacing(5); h->setSpacing(5);
h->setMargin(5); h->setMargin(5);
//h->setAutoAdd(true); //h->setAutoAdd(true);
BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox); BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox,true,axis->nuseMouse);
CThrottle = new QComboBox(KeyBox); CThrottle = new QComboBox(KeyBox);
CThrottle->insertItem(0,"Neg. Throttle",Qt::DisplayRole); CThrottle->insertItem(0,"Neg. Throttle",Qt::DisplayRole);
@ -89,7 +89,7 @@ AxisEdit::AxisEdit( Axis* ax )
CThrottle->setCurrentIndex(axis->throttle + 1); CThrottle->setCurrentIndex(axis->throttle + 1);
connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int ))); connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int )));
BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox); BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox,true,axis->puseMouse);
h->addWidget(BNeg); h->addWidget(BNeg);
h->addWidget(CThrottle); h->addWidget(CThrottle);
h->addWidget(BPos); h->addWidget(BPos);
@ -183,6 +183,8 @@ void AxisEdit::accept() {
axis->mode = (AxisMode) CMode->currentIndex(); axis->mode = (AxisMode) CMode->currentIndex();
axis->pkeycode = BPos->getValue(); axis->pkeycode = BPos->getValue();
axis->nkeycode = BNeg->getValue(); axis->nkeycode = BNeg->getValue();
axis->puseMouse = BPos->choseMouse();
axis->nuseMouse = BNeg->choseMouse();
axis->adjustGradient(); axis->adjustGradient();
QDialog::accept(); QDialog::accept();

View File

@ -5,20 +5,20 @@
#include <stdarg.h> #include <stdarg.h>
//a nice simple way of throwing up an error message if something goes wrong. //a nice simple way of throwing up an error message if something goes wrong.
static void error(QString type, QString message ) { inline void error(QString type, QString message ) {
QMessageBox::warning(0,NAME" - " + type, QMessageBox::warning(0,NAME" - " + type,
message, QMessageBox::Ok, Qt::NoButton); message, QMessageBox::Ok, Qt::NoButton);
} }
#ifdef _DEBUG #ifdef _DEBUG
static void debug_mesg(const char *fmt, ...) { inline void debug_mesg(const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, NULL); va_start(ap, NULL);
vprintf(fmt, ap); vprintf(fmt, ap);
va_end(ap); va_end(ap);
} }
#else #else
static void debug_mesg(...) { inline void debug_mesg(...) {
return; return;
} }
#endif #endif

View File

@ -55,7 +55,7 @@ void JoyPad::resetToDev(int dev ) {
char buf[10]; char buf[10];
while(poll(&read_struct, 1, 5)!=0) { while(poll(&read_struct, 1, 5)!=0) {
debug_mesg("reading junk data\n"); debug_mesg("reading junk data\n");
read(joydev, buf, 10); if (read(joydev, buf, 10) <= 0) break;
} }
setupJoyDeviceListener(dev); setupJoyDeviceListener(dev);
debug_mesg("done resetting to dev\n"); debug_mesg("done resetting to dev\n");
@ -249,6 +249,8 @@ JoyPadWidget* JoyPad::widget( QWidget* parent, int i) {
} }
void JoyPad::handleJoyEvents(int fd) { void JoyPad::handleJoyEvents(int fd) {
Q_UNUSED(fd);
js_event msg; js_event msg;
int len; int len;

View File

@ -357,7 +357,7 @@ void LayoutManager::updateJoyDevs() {
char buf[10]; char buf[10];
while(poll(&read_struct, 1, 5)!=0) { while(poll(&read_struct, 1, 5)!=0) {
debug_mesg("reading junk data\n"); debug_mesg("reading junk data\n");
read(joydev, buf, 10); if (read(joydev, buf, 10) <= 0) break;
} }
joypad = new JoyPad( index, joydev ); joypad = new JoyPad( index, joydev );
joypads.insert(index,joypad); joypads.insert(index,joypad);

View File

@ -102,7 +102,7 @@ void LayoutEdit::setLayout(QString layout) {
//change the text, //change the text,
CLayouts->setCurrentIndex(lm->getLayoutNames().indexOf(layout)); CLayouts->setCurrentIndex(lm->getLayoutNames().indexOf(layout));
//update all the JoyPadWidgets. //update all the JoyPadWidgets.
for (uint i = 0; i < available.count(); i++) { for (int i = 0; i < available.count(); i++) {
((JoyPadWidget*)PadStack->widget(i))->update(); ((JoyPadWidget*)PadStack->widget(i))->update();
} }
} }

View File

@ -147,7 +147,7 @@ int main( int argc, char **argv )
if (pidFile.exists()) if (pidFile.exists())
{ {
int pid; int pid;
if (pidFile.open( QIODevice::ReadOnly )); if (pidFile.open( QIODevice::ReadOnly ))
{ {
//try to get that pid... //try to get that pid...
QTextStream( &pidFile ) >> pid; QTextStream( &pidFile ) >> pid;

View File

@ -32,46 +32,47 @@ DEFINES += ICON64='\\\"$${icons.conf_path}/icon64.png\\\"'
TEMPLATE = app TEMPLATE = app
INCLUDEPATH += . INCLUDEPATH += .
QMAKE_LIBS += -lXtst -lX11 QMAKE_LIBS += -lXtst -lX11
QMAKE_CXXFLAGS += -Werror -Wno-deprecated-declarations
# Input # Input
HEADERS += axis.h \ HEADERS += axis.h \
axis_edit.h \ axis_edit.h \
axisw.h \ axisw.h \
button.h \ button.h \
button_edit.h \ button_edit.h \
buttonw.h \ buttonw.h \
constant.h \ constant.h \
device.h \ device.h \
error.h \ error.h \
event.h \ event.h \
flash.h \ flash.h \
icon.h \ icon.h \
joypad.h \ joypad.h \
joypadw.h \ joypadw.h \
joyslider.h \ joyslider.h \
keycode.h \ keycode.h \
layout.h \ layout.h \
getkey.h \ getkey.h \
layout_edit.h \ layout_edit.h \
quickset.h quickset.h
SOURCES += axis.cpp \ SOURCES += axis.cpp \
axis_edit.cpp \ axis_edit.cpp \
axisw.cpp \ axisw.cpp \
button.cpp \ button.cpp \
button_edit.cpp \ button_edit.cpp \
buttonw.cpp \ buttonw.cpp \
event.cpp \ event.cpp \
flash.cpp \ flash.cpp \
icon.cpp \ icon.cpp \
joypad.cpp \ joypad.cpp \
joypadw.cpp \ joypadw.cpp \
joyslider.cpp \ joyslider.cpp \
keycode.cpp \ keycode.cpp \
layout.cpp \ layout.cpp \
layout_edit.cpp \ layout_edit.cpp \
main.cpp \ main.cpp \
quickset.cpp \ quickset.cpp \
getkey.cpp getkey.cpp
##### Install ##### ##### Install #####