fix reading js events, debug_mesg as variadic macro
This commit is contained in:
@ -17,7 +17,7 @@ if(PLAIN_KEYS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wno-deprecated-declarations")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wno-deprecated-declarations -Wno-variadic-macros")
|
||||||
|
|
||||||
if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug"))
|
if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug"))
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#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.
|
||||||
|
|
||||||
inline void error(const QString &type, const QString &message ) {
|
inline void errorBox(const QString &type, const QString &message, QWidget *parent = 0) {
|
||||||
QMessageBox::warning(0, QString("%1 - %2").arg(NAME, type),
|
QMessageBox::warning(parent, QString("%1 - %2").arg(NAME, type),
|
||||||
message, QMessageBox::Ok, Qt::NoButton);
|
message, QMessageBox::Ok, Qt::NoButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,5 +19,6 @@ inline void debug_mesg(const char *fmt, ...) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
inline void debug_mesg(...) {}
|
inline void debug_mesg(...) {}
|
||||||
|
#define debug_mesg(...)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <poll.h>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#include "joypad.h"
|
#include "joypad.h"
|
||||||
@ -88,14 +87,6 @@ void JoyPad::open(int dev) {
|
|||||||
for (int i = 0; i < buttonCount; i++) {
|
for (int i = 0; i < buttonCount; i++) {
|
||||||
if (buttons[i] == 0) buttons.insert(i, new Button( i, this ));
|
if (buttons[i] == 0) buttons.insert(i, new Button( i, this ));
|
||||||
}
|
}
|
||||||
struct pollfd read_struct;
|
|
||||||
read_struct.fd = joydev;
|
|
||||||
read_struct.events = POLLIN;
|
|
||||||
char buf[10];
|
|
||||||
while (poll(&read_struct, 1, 5) != 0) {
|
|
||||||
debug_mesg("reading junk data\n");
|
|
||||||
if (read(joydev, buf, 10) <= 0) break;
|
|
||||||
}
|
|
||||||
debug_mesg("Setting up joyDeviceListeners\n");
|
debug_mesg("Setting up joyDeviceListeners\n");
|
||||||
readNotifier = new QSocketNotifier(joydev, QSocketNotifier::Read, this);
|
readNotifier = new QSocketNotifier(joydev, QSocketNotifier::Read, this);
|
||||||
connect(readNotifier, SIGNAL(activated(int)), this, SLOT(handleJoyEvents()));
|
connect(readNotifier, SIGNAL(activated(int)), this, SLOT(handleJoyEvents()));
|
||||||
@ -141,14 +132,14 @@ bool JoyPad::readConfig( QTextStream &stream ) {
|
|||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
stream >> ch;
|
stream >> ch;
|
||||||
if (ch != ':') {
|
if (ch != ':') {
|
||||||
error("Layout file error", QString("Expected ':', found '%1'.").arg(ch));
|
errorBox("Layout file error", QString("Expected ':', found '%1'.").arg(ch));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (buttons[num-1] == 0) {
|
if (buttons[num-1] == 0) {
|
||||||
buttons.insert(num-1,new Button(num-1));
|
buttons.insert(num-1,new Button(num-1,this));
|
||||||
}
|
}
|
||||||
if (!buttons[num-1]->read( stream )) {
|
if (!buttons[num-1]->read( stream )) {
|
||||||
error("Layout file error", QString("Error reading Button %1").arg(num));
|
errorBox("Layout file error", QString("Error reading Button %1").arg(num));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,20 +152,20 @@ bool JoyPad::readConfig( QTextStream &stream ) {
|
|||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
stream >> ch;
|
stream >> ch;
|
||||||
if (ch != ':') {
|
if (ch != ':') {
|
||||||
error("Layout file error", QString("Expected ':', found '%1'.").arg(ch));
|
errorBox("Layout file error", QString("Expected ':', found '%1'.").arg(ch));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (axes[num-1] == 0) {
|
if (axes[num-1] == 0) {
|
||||||
axes.insert(num-1,new Axis(num-1));
|
axes.insert(num-1,new Axis(num-1,this));
|
||||||
}
|
}
|
||||||
if (!axes[num-1]->read(stream)) {
|
if (!axes[num-1]->read(stream)) {
|
||||||
error("Layout file error", QString("Error reading Axis %1").arg(num));
|
errorBox("Layout file error", QString("Error reading Axis %1").arg(num));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error( "Layout file error", QString("Error while reading layout. Unrecognized word: %1").arg(word) );
|
errorBox( "Layout file error", QString("Error while reading layout. Unrecognized word: %1").arg(word) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
stream >> word;
|
stream >> word;
|
||||||
@ -219,7 +210,7 @@ void JoyPad::jsevent(const js_event &msg) {
|
|||||||
|
|
||||||
//otherwise, lets create us a fake event! Pass on the event to whichever
|
//otherwise, lets create us a fake event! Pass on the event to whichever
|
||||||
//Button or Axis was pressed and let them decide what to do with it.
|
//Button or Axis was pressed and let them decide what to do with it.
|
||||||
qulonglong type = msg.type & ~JS_EVENT_INIT;
|
unsigned int type = msg.type & ~JS_EVENT_INIT;
|
||||||
if (type == JS_EVENT_AXIS) {
|
if (type == JS_EVENT_AXIS) {
|
||||||
debug_mesg("DEBUG: passing on an axis event\n");
|
debug_mesg("DEBUG: passing on an axis event\n");
|
||||||
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
|
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
|
||||||
|
@ -88,7 +88,7 @@ void JoyPadWidget::setAll() {
|
|||||||
void JoyPadWidget::jsevent( const js_event& msg ) {
|
void JoyPadWidget::jsevent( const js_event& msg ) {
|
||||||
//notify the component this event applies to. this cannot generate anything
|
//notify the component this event applies to. this cannot generate anything
|
||||||
//other than a flash :)
|
//other than a flash :)
|
||||||
qulonglong type = msg.type & ~JS_EVENT_INIT;
|
unsigned int type = msg.type & ~JS_EVENT_INIT;
|
||||||
if (type == JS_EVENT_AXIS) {
|
if (type == JS_EVENT_AXIS) {
|
||||||
if (msg.number < axes.count()) axes[msg.number]->jsevent(msg.value);
|
if (msg.number < axes.count()) axes[msg.number]->jsevent(msg.value);
|
||||||
}
|
}
|
||||||
|
@ -48,13 +48,13 @@ bool LayoutManager::load(const QString& name) {
|
|||||||
|
|
||||||
//if the file isn't available,
|
//if the file isn't available,
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
error("Load error","Failed to find a layout named " + name);
|
errorBox("Load error","Failed to find a layout named " + name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the file isn't readable,
|
//if the file isn't readable,
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
error("Load error","Error reading from file " + file.fileName());
|
errorBox("Load error","Error reading from file " + file.fileName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ bool LayoutManager::load(const QString& name) {
|
|||||||
num = word.toInt(&okay);
|
num = word.toInt(&okay);
|
||||||
//make sure the number of the joystick is valid
|
//make sure the number of the joystick is valid
|
||||||
if (!okay || num < 1) {
|
if (!okay || num < 1) {
|
||||||
error( "Load error", QString("Error reading joystick definition. Unexpected token \"%1\". Expected a positive number.").arg(word));
|
errorBox( "Load error", QString("Error reading joystick definition. Unexpected token \"%1\". Expected a positive number.").arg(word));
|
||||||
if (name != currentLayout) reload();
|
if (name != currentLayout) reload();
|
||||||
else clear();
|
else clear();
|
||||||
return false;
|
return false;
|
||||||
@ -93,7 +93,7 @@ bool LayoutManager::load(const QString& name) {
|
|||||||
stream.skipWhiteSpace();
|
stream.skipWhiteSpace();
|
||||||
stream >> ch;
|
stream >> ch;
|
||||||
if (ch != QChar('{')) {
|
if (ch != QChar('{')) {
|
||||||
error( "Load error", QString("Error reading joystick definition. Unexpected character \"%1\". Expected '{'.").arg(ch));
|
errorBox( "Load error", QString("Error reading joystick definition. Unexpected character \"%1\". Expected '{'.").arg(ch));
|
||||||
if (name != currentLayout) reload();
|
if (name != currentLayout) reload();
|
||||||
else clear();
|
else clear();
|
||||||
return false;
|
return false;
|
||||||
@ -105,7 +105,7 @@ bool LayoutManager::load(const QString& name) {
|
|||||||
}
|
}
|
||||||
//try to read the joypad, report error on fail.
|
//try to read the joypad, report error on fail.
|
||||||
if (!joypads[index]->readConfig(stream)) {
|
if (!joypads[index]->readConfig(stream)) {
|
||||||
error( "Load error", QString("Error reading definition for joystick %1.").arg(index));
|
errorBox( "Load error", QString("Error reading definition for joystick %1.").arg(index));
|
||||||
//if this was attempting to change to a new layout and it failed,
|
//if this was attempting to change to a new layout and it failed,
|
||||||
//revert back to the old layout.
|
//revert back to the old layout.
|
||||||
if (name != currentLayout) reload();
|
if (name != currentLayout) reload();
|
||||||
@ -120,7 +120,7 @@ bool LayoutManager::load(const QString& name) {
|
|||||||
stream.readLine();
|
stream.readLine();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error("Load error", QString("Error reading joystick definition. Unexpected token \"%1\". Expected \"Joystick\".").arg(word));
|
errorBox("Load error", QString("Error reading joystick definition. Unexpected token \"%1\". Expected \"Joystick\".").arg(word));
|
||||||
if (name != currentLayout) reload();
|
if (name != currentLayout) reload();
|
||||||
else clear();
|
else clear();
|
||||||
return false;
|
return false;
|
||||||
@ -185,7 +185,7 @@ void LayoutManager::save() {
|
|||||||
}
|
}
|
||||||
//if it's not, error.
|
//if it's not, error.
|
||||||
else
|
else
|
||||||
error("Save error", "Could not open file " + filename + ", layout not saved.");
|
errorBox("Save error", "Could not open file " + filename + ", layout not saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ void LayoutManager::saveAs() {
|
|||||||
QFile file(settingsDir + name + ".lyt");
|
QFile file(settingsDir + name + ".lyt");
|
||||||
//don't overwrite an existing layout.
|
//don't overwrite an existing layout.
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
error("Save error", "That name's already taken!");
|
errorBox("Save error", "That name's already taken!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ void LayoutManager::remove() {
|
|||||||
if (QMessageBox::warning( 0, NAME" - Delete layout?","Remove layout permanently from your hard drive?", "Yes", "No", 0, 0, 1 ) == 1) return;
|
if (QMessageBox::warning( 0, NAME" - Delete layout?","Remove layout permanently from your hard drive?", "Yes", "No", 0, 0, 1 ) == 1) return;
|
||||||
QString filename = getFileName( currentLayout );
|
QString filename = getFileName( currentLayout );
|
||||||
if (!QFile(filename).remove()) {
|
if (!QFile(filename).remove()) {
|
||||||
error("Remove error", "Could not remove file " + filename);
|
errorBox("Remove error", "Could not remove file " + filename);
|
||||||
}
|
}
|
||||||
fillPopup();
|
fillPopup();
|
||||||
|
|
||||||
@ -266,15 +266,15 @@ void LayoutManager::setLayoutName(QString name) {
|
|||||||
void LayoutManager::iconClick() {
|
void LayoutManager::iconClick() {
|
||||||
//don't show the dialog if there aren't any joystick devices plugged in
|
//don't show the dialog if there aren't any joystick devices plugged in
|
||||||
if (available.isEmpty()) {
|
if (available.isEmpty()) {
|
||||||
error("No joystick devices available","No joystick devices are currently available to configure.\nPlease plug in a gaming device and select\n\"Update Joystick Devices\" from the popup menu.");
|
errorBox("No joystick devices available","No joystick devices are currently available to configure.\nPlease plug in a gaming device and select\n\"Update Joystick Devices\" from the popup menu.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (le) {
|
if (le) {
|
||||||
if (le->hasFocus()) {
|
if (le->isActiveWindow()) {
|
||||||
le->close();
|
le->close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
le->raise();
|
le->activateWindow();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ void LayoutManager::trayMenu(QAction *menuItemAction) {
|
|||||||
//if they clicked on a Layout name, load it!
|
//if they clicked on a Layout name, load it!
|
||||||
//note that the other options are handled with their own special functions
|
//note that the other options are handled with their own special functions
|
||||||
if (trayMenuPopup.actions().indexOf(menuItemAction) > 1 && menuItemAction->text() != "Quit" &&
|
if (trayMenuPopup.actions().indexOf(menuItemAction) > 1 && menuItemAction->text() != "Quit" &&
|
||||||
menuItemAction->text() != "Update lyaout list" &&
|
menuItemAction->text() != "Update layout list" &&
|
||||||
menuItemAction->text() != "Update joystick devices") {
|
menuItemAction->text() != "Update joystick devices") {
|
||||||
load(menuItemAction->text());
|
load(menuItemAction->text());
|
||||||
}
|
}
|
||||||
@ -369,14 +369,6 @@ void LayoutManager::updateJoyDevs() {
|
|||||||
JoyPad* joypad = joypads[index];
|
JoyPad* joypad = joypads[index];
|
||||||
//if we've never seen this device before, make a new one!
|
//if we've never seen this device before, make a new one!
|
||||||
if (joypad == 0) {
|
if (joypad == 0) {
|
||||||
struct pollfd read_struct;
|
|
||||||
read_struct.fd = joydev;
|
|
||||||
read_struct.events = POLLIN;
|
|
||||||
char buf[10];
|
|
||||||
while (poll(&read_struct, 1, 5) != 0) {
|
|
||||||
debug_mesg("reading junk data\n");
|
|
||||||
if (read(joydev, buf, 10) <= 0) break;
|
|
||||||
}
|
|
||||||
joypad = new JoyPad( index, joydev, this );
|
joypad = new JoyPad( index, joydev, this );
|
||||||
joypads.insert(index,joypad);
|
joypads.insert(index,joypad);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <poll.h>
|
|
||||||
|
|
||||||
//a layout handles several joypads
|
//a layout handles several joypads
|
||||||
#include "joypad.h"
|
#include "joypad.h"
|
||||||
|
@ -199,7 +199,7 @@ int main( int argc, char **argv )
|
|||||||
//however, if we are setting the layout or updating the device
|
//however, if we are setting the layout or updating the device
|
||||||
//list, this is not an error and we shouldn't make one!
|
//list, this is not an error and we shouldn't make one!
|
||||||
if (layout.isEmpty() && update == false)
|
if (layout.isEmpty() && update == false)
|
||||||
error("Instance Error","There is already a running instance of QJoyPad; please close\nthe old instance before starting a new one.");
|
errorBox("Instance Error","There is already a running instance of QJoyPad; please close\nthe old instance before starting a new one.");
|
||||||
else {
|
else {
|
||||||
//if one of these is the case, send the approrpriate signal!
|
//if one of these is the case, send the approrpriate signal!
|
||||||
if (update == true)
|
if (update == true)
|
||||||
|
@ -24,7 +24,7 @@ void QuickSet::jsevent(const js_event &msg ) {
|
|||||||
if (setting) return;
|
if (setting) return;
|
||||||
|
|
||||||
//if a button was pressed on the joystick
|
//if a button was pressed on the joystick
|
||||||
qulonglong type = msg.type & ~JS_EVENT_INIT;
|
unsigned int type = msg.type & ~JS_EVENT_INIT;
|
||||||
if (type == JS_EVENT_BUTTON) {
|
if (type == JS_EVENT_BUTTON) {
|
||||||
//capture that button.
|
//capture that button.
|
||||||
Button* button = joypad->buttons[msg.number];
|
Button* button = joypad->buttons[msg.number];
|
||||||
|
Reference in New Issue
Block a user