fix reading js events, debug_mesg as variadic macro
This commit is contained in:
@ -17,7 +17,7 @@ if(PLAIN_KEYS)
|
||||
endif()
|
||||
|
||||
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"))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||
|
@ -5,8 +5,8 @@
|
||||
#include <stdarg.h>
|
||||
//a nice simple way of throwing up an error message if something goes wrong.
|
||||
|
||||
inline void error(const QString &type, const QString &message ) {
|
||||
QMessageBox::warning(0, QString("%1 - %2").arg(NAME, type),
|
||||
inline void errorBox(const QString &type, const QString &message, QWidget *parent = 0) {
|
||||
QMessageBox::warning(parent, QString("%1 - %2").arg(NAME, type),
|
||||
message, QMessageBox::Ok, Qt::NoButton);
|
||||
}
|
||||
|
||||
@ -19,5 +19,6 @@ inline void debug_mesg(const char *fmt, ...) {
|
||||
}
|
||||
#else
|
||||
inline void debug_mesg(...) {}
|
||||
#define debug_mesg(...)
|
||||
#endif
|
||||
#endif
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <poll.h>
|
||||
#include <QApplication>
|
||||
|
||||
#include "joypad.h"
|
||||
@ -88,14 +87,6 @@ void JoyPad::open(int dev) {
|
||||
for (int i = 0; i < buttonCount; i++) {
|
||||
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");
|
||||
readNotifier = new QSocketNotifier(joydev, QSocketNotifier::Read, this);
|
||||
connect(readNotifier, SIGNAL(activated(int)), this, SLOT(handleJoyEvents()));
|
||||
@ -141,14 +132,14 @@ bool JoyPad::readConfig( QTextStream &stream ) {
|
||||
if (num > 0) {
|
||||
stream >> 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;
|
||||
}
|
||||
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 )) {
|
||||
error("Layout file error", QString("Error reading Button %1").arg(num));
|
||||
errorBox("Layout file error", QString("Error reading Button %1").arg(num));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -161,20 +152,20 @@ bool JoyPad::readConfig( QTextStream &stream ) {
|
||||
if (num > 0) {
|
||||
stream >> 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;
|
||||
}
|
||||
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)) {
|
||||
error("Layout file error", QString("Error reading Axis %1").arg(num));
|
||||
errorBox("Layout file error", QString("Error reading Axis %1").arg(num));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
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
|
||||
//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) {
|
||||
debug_mesg("DEBUG: passing on an axis event\n");
|
||||
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
|
||||
|
@ -88,7 +88,7 @@ void JoyPadWidget::setAll() {
|
||||
void JoyPadWidget::jsevent( const js_event& msg ) {
|
||||
//notify the component this event applies to. this cannot generate anything
|
||||
//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 (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 (!file.exists()) {
|
||||
error("Load error","Failed to find a layout named " + name);
|
||||
errorBox("Load error","Failed to find a layout named " + name);
|
||||
return false;
|
||||
}
|
||||
|
||||
//if the file isn't readable,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ bool LayoutManager::load(const QString& name) {
|
||||
num = word.toInt(&okay);
|
||||
//make sure the number of the joystick is valid
|
||||
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();
|
||||
else clear();
|
||||
return false;
|
||||
@ -93,7 +93,7 @@ bool LayoutManager::load(const QString& name) {
|
||||
stream.skipWhiteSpace();
|
||||
stream >> ch;
|
||||
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();
|
||||
else clear();
|
||||
return false;
|
||||
@ -105,7 +105,7 @@ bool LayoutManager::load(const QString& name) {
|
||||
}
|
||||
//try to read the joypad, report error on fail.
|
||||
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,
|
||||
//revert back to the old layout.
|
||||
if (name != currentLayout) reload();
|
||||
@ -120,7 +120,7 @@ bool LayoutManager::load(const QString& name) {
|
||||
stream.readLine();
|
||||
}
|
||||
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();
|
||||
else clear();
|
||||
return false;
|
||||
@ -185,7 +185,7 @@ void LayoutManager::save() {
|
||||
}
|
||||
//if it's not, error.
|
||||
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");
|
||||
//don't overwrite an existing layout.
|
||||
if (file.exists()) {
|
||||
error("Save error", "That name's already taken!");
|
||||
errorBox("Save error", "That name's already taken!");
|
||||
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;
|
||||
QString filename = getFileName( currentLayout );
|
||||
if (!QFile(filename).remove()) {
|
||||
error("Remove error", "Could not remove file " + filename);
|
||||
errorBox("Remove error", "Could not remove file " + filename);
|
||||
}
|
||||
fillPopup();
|
||||
|
||||
@ -266,15 +266,15 @@ void LayoutManager::setLayoutName(QString name) {
|
||||
void LayoutManager::iconClick() {
|
||||
//don't show the dialog if there aren't any joystick devices plugged in
|
||||
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;
|
||||
}
|
||||
if (le) {
|
||||
if (le->hasFocus()) {
|
||||
if (le->isActiveWindow()) {
|
||||
le->close();
|
||||
}
|
||||
else {
|
||||
le->raise();
|
||||
le->activateWindow();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -293,7 +293,7 @@ void LayoutManager::trayMenu(QAction *menuItemAction) {
|
||||
//if they clicked on a Layout name, load it!
|
||||
//note that the other options are handled with their own special functions
|
||||
if (trayMenuPopup.actions().indexOf(menuItemAction) > 1 && menuItemAction->text() != "Quit" &&
|
||||
menuItemAction->text() != "Update lyaout list" &&
|
||||
menuItemAction->text() != "Update layout list" &&
|
||||
menuItemAction->text() != "Update joystick devices") {
|
||||
load(menuItemAction->text());
|
||||
}
|
||||
@ -369,14 +369,6 @@ void LayoutManager::updateJoyDevs() {
|
||||
JoyPad* joypad = joypads[index];
|
||||
//if we've never seen this device before, make a new one!
|
||||
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 );
|
||||
joypads.insert(index,joypad);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include <QPointer>
|
||||
#include <QInputDialog>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <poll.h>
|
||||
|
||||
//a layout handles several joypads
|
||||
#include "joypad.h"
|
||||
|
@ -199,7 +199,7 @@ int main( int argc, char **argv )
|
||||
//however, if we are setting the layout or updating the device
|
||||
//list, this is not an error and we shouldn't make one!
|
||||
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 {
|
||||
//if one of these is the case, send the approrpriate signal!
|
||||
if (update == true)
|
||||
|
@ -24,7 +24,7 @@ void QuickSet::jsevent(const js_event &msg ) {
|
||||
if (setting) return;
|
||||
|
||||
//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) {
|
||||
//capture that button.
|
||||
Button* button = joypad->buttons[msg.number];
|
||||
|
Reference in New Issue
Block a user