globals--, fmt string fix, foreeach++, better names++, close fds, tray icon activates/closes
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
#include <QX11Info>
|
||||
#include "axis.h"
|
||||
#include "event.h"
|
||||
#include "time.h"
|
||||
@ -423,5 +424,5 @@ void Axis::move( bool press ) {
|
||||
}
|
||||
}
|
||||
//actually create the event
|
||||
sendevent(display, e);
|
||||
sendevent(QX11Info::display(), e);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
AxisWidget::AxisWidget( Axis* a, QWidget* parent )
|
||||
: FlashButton( "",parent) {
|
||||
: FlashButton(QString::null, QString::null, parent) {
|
||||
axis = a;
|
||||
ae = NULL;
|
||||
update();
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <QX11Info>
|
||||
#include "button.h"
|
||||
#include "event.h"
|
||||
|
||||
@ -125,7 +126,7 @@ bool Button::isDefault() {
|
||||
|
||||
QString Button::status() {
|
||||
if (useMouse) {
|
||||
return QString("%1 : Mouse %2").arg(getName(), keycode);
|
||||
return QString("%1 : Mouse %2").arg(getName()).arg(keycode);
|
||||
}
|
||||
else {
|
||||
return QString("%1 : %2").arg(getName(), ktos(keycode));
|
||||
@ -161,7 +162,7 @@ void Button::click( bool press ) {
|
||||
click.value1 = keycode;
|
||||
click.value2 = 0;
|
||||
//and send it.
|
||||
sendevent( display, click );
|
||||
sendevent( QX11Info::display(), click );
|
||||
}
|
||||
|
||||
void Button::timerCalled() {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
ButtonWidget::ButtonWidget( Button* b, QWidget* parent )
|
||||
: FlashButton( "", parent) {
|
||||
: FlashButton(QString::null, QString::null, parent) {
|
||||
button = b;
|
||||
update();
|
||||
on = false;
|
||||
|
@ -18,8 +18,6 @@ inline void debug_mesg(const char *fmt, ...) {
|
||||
va_end(ap);
|
||||
}
|
||||
#else
|
||||
inline void debug_mesg(...) {
|
||||
return;
|
||||
}
|
||||
inline void debug_mesg(...) {}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -4,7 +4,7 @@
|
||||
Display *display = 0;
|
||||
|
||||
//actually creates an XWindows event :)
|
||||
void sendevent( Display* display, xevent e ) {
|
||||
void sendevent(Display* display, const xevent &e ) {
|
||||
if (e.value1 == 0 && e.value2 == 0) return;
|
||||
if (e.type == WARP) {
|
||||
XTestFakeRelativeMotionEvent(display, e.value1, e.value2, 0);
|
||||
|
@ -16,8 +16,6 @@ struct xevent {
|
||||
int value2; //y
|
||||
};
|
||||
|
||||
extern Display* display;
|
||||
|
||||
void sendevent( Display* display, xevent e );
|
||||
void sendevent( Display* display, const xevent& e );
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,7 @@
|
||||
//Modified here (and in .h) to not have default arguments for 2 and 3.
|
||||
//This caused an error with a development version of g++ on a Mandrake system
|
||||
//in Sweden.
|
||||
FlashButton::FlashButton( QString text, QWidget* parent, QString name )
|
||||
FlashButton::FlashButton( QString text, QString name, QWidget* parent )
|
||||
:QPushButton( text, parent )
|
||||
{
|
||||
this->setObjectName(name);
|
||||
@ -47,41 +47,38 @@ FlashRadioArray::FlashRadioArray( const QStringList &names, bool horizontal, QWi
|
||||
:QWidget( parent )
|
||||
{
|
||||
if (horizontal) {
|
||||
LMain = new QHBoxLayout( this);
|
||||
LMain->setMargin(5);
|
||||
LMain->setSpacing(5);
|
||||
mainLayout = new QHBoxLayout( this);
|
||||
mainLayout->setMargin(5);
|
||||
mainLayout->setSpacing(5);
|
||||
} else {
|
||||
LMain = new QVBoxLayout( this);
|
||||
LMain->setMargin(5);
|
||||
LMain->setSpacing(5);
|
||||
mainLayout = new QVBoxLayout( this);
|
||||
mainLayout->setMargin(5);
|
||||
mainLayout->setSpacing(5);
|
||||
}
|
||||
// TODO: fix memleak
|
||||
int count = names.size();
|
||||
int i = 0;
|
||||
Buttons = new FlashButton*[count];
|
||||
foreach (const QString &name, names) {
|
||||
Buttons[i] = new FlashButton( name, this, "" );
|
||||
FlashButton *button = new FlashButton( name, QString::null, this );
|
||||
buttons.append(button);
|
||||
//when any of the buttons is clicked, it calls the same function on this.
|
||||
connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() ));
|
||||
LMain->addWidget(Buttons[i]);
|
||||
++i;
|
||||
connect( button, SIGNAL( clicked() ), this, SLOT( clicked() ));
|
||||
mainLayout->addWidget(button);
|
||||
}
|
||||
|
||||
Count = count;
|
||||
State = 0;
|
||||
if (count > 0) {
|
||||
Buttons[0]->setDown( true );
|
||||
state = 0;
|
||||
if (!buttons.isEmpty()) {
|
||||
buttons[0]->setDown( true );
|
||||
}
|
||||
}
|
||||
|
||||
int FlashRadioArray::getState()
|
||||
{
|
||||
return State;
|
||||
return state;
|
||||
}
|
||||
|
||||
void FlashRadioArray::flash( int index )
|
||||
{
|
||||
Buttons[index]->flash();
|
||||
if (index < buttons.size()) {
|
||||
buttons[index]->flash();
|
||||
}
|
||||
}
|
||||
|
||||
void FlashRadioArray::clicked()
|
||||
@ -89,15 +86,16 @@ void FlashRadioArray::clicked()
|
||||
//go through each button. If it wasn't the button that was just clicked,
|
||||
//then make sure that it is up. If it WAS the button that was clicked,
|
||||
//remember that index as the new state.
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if ( Buttons[i] != sender() )
|
||||
Buttons[i]->setDown( false );
|
||||
else
|
||||
{
|
||||
State = i;
|
||||
Buttons[i]->setDown( true );
|
||||
int i = 0;
|
||||
foreach (FlashButton *button, buttons) {
|
||||
if ( button != sender() ) {
|
||||
button->setDown( false );
|
||||
}
|
||||
else {
|
||||
state = i;
|
||||
button->setDown( true );
|
||||
}
|
||||
emit changed( State );
|
||||
++ i;
|
||||
}
|
||||
emit changed( state );
|
||||
}
|
||||
|
10
src/flash.h
10
src/flash.h
@ -30,7 +30,7 @@ class FlashButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FlashButton( QString text, QWidget* parent, QString name = "" );
|
||||
FlashButton(QString text, QString name = "" , QWidget* parent = 0);
|
||||
public slots:
|
||||
//make the button turn blue if it was gray, or visa versa.
|
||||
void flash();
|
||||
@ -65,14 +65,12 @@ class FlashRadioArray : public QWidget
|
||||
//happens when the state changes. The int is the new state.
|
||||
void changed( int );
|
||||
private:
|
||||
//how many buttons
|
||||
int Count;
|
||||
//which is currently down
|
||||
int State;
|
||||
int state;
|
||||
//the array of buttons
|
||||
FlashButton** Buttons;
|
||||
QList<FlashButton*> buttons;
|
||||
//the main layout.
|
||||
QBoxLayout* LMain;
|
||||
QBoxLayout* mainLayout;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <QX11Info>
|
||||
#include "getkey.h"
|
||||
|
||||
GetKey::GetKey( QString button, bool m )
|
||||
@ -33,7 +34,7 @@ bool GetKey::x11Event( XEvent* e )
|
||||
//On a key press, return the key and quit
|
||||
//Ctrl+X == [No Key]
|
||||
if (e->type == KeyRelease) {
|
||||
if (XKeycodeToKeysym(display,e->xkey.keycode,0) == XK_x ) {
|
||||
if (XKeycodeToKeysym(QX11Info::display(),e->xkey.keycode,0) == XK_x ) {
|
||||
if (e->xkey.state & ControlMask) done( 0 );
|
||||
else done( e->xkey.keycode );
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
//The KeySym for "x"
|
||||
#define XK_x 0x078
|
||||
|
||||
extern Display *display;
|
||||
|
||||
//a keycode dialog box
|
||||
class GetKey : public QDialog {
|
||||
Q_OBJECT
|
||||
|
160
src/joypad.cpp
160
src/joypad.cpp
@ -1,21 +1,24 @@
|
||||
#include "unistd.h"
|
||||
#include "joypad.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <poll.h>
|
||||
#include <QApplication>
|
||||
|
||||
JoyPad::JoyPad( int i, int dev, QObject *parent ) : QObject(parent) {
|
||||
#include "joypad.h"
|
||||
|
||||
JoyPad::JoyPad( int i, int dev, QObject *parent )
|
||||
: QObject(parent), joydev(-1), axisCount(0), buttonCount(0), jpw(0), readNotifier(0), errorNotifier(0) {
|
||||
debug_mesg("Constructing the joypad device with index %d and fd %d\n", i, dev);
|
||||
//remember the index,
|
||||
index = i;
|
||||
|
||||
//load data from the joystick device, if available.
|
||||
joydevFileHandle = NULL;
|
||||
if (dev >= 0) {
|
||||
debug_mesg("Valid file handle, setting up handlers and reading axis configs...\n");
|
||||
resetToDev(dev);
|
||||
open(dev);
|
||||
debug_mesg("done resetting and setting up device index %d\n", i);
|
||||
char id[256];
|
||||
memset(id, 0, sizeof(id));
|
||||
@ -28,32 +31,62 @@ JoyPad::JoyPad( int i, int dev, QObject *parent ) : QObject(parent) {
|
||||
} else {
|
||||
debug_mesg("This joypad does not have a valid file handle, not setting up event listeners\n");
|
||||
}
|
||||
//there is no JoyPadWidget yet.
|
||||
jpw = NULL;
|
||||
debug_mesg("Done constructing the joypad device %d\n", i);
|
||||
}
|
||||
|
||||
void JoyPad::resetToDev(int dev ) {
|
||||
JoyPad::~JoyPad() {
|
||||
close();
|
||||
}
|
||||
|
||||
void JoyPad::close() {
|
||||
if (readNotifier) {
|
||||
disconnect(readNotifier, 0, 0, 0);
|
||||
|
||||
readNotifier->blockSignals(true);
|
||||
readNotifier->setEnabled(false);
|
||||
|
||||
delete readNotifier;
|
||||
readNotifier = 0;
|
||||
}
|
||||
if (errorNotifier) {
|
||||
disconnect(errorNotifier, 0, 0, 0);
|
||||
|
||||
errorNotifier->blockSignals(true);
|
||||
errorNotifier->setEnabled(false);
|
||||
|
||||
delete errorNotifier;
|
||||
errorNotifier = 0;
|
||||
}
|
||||
if (joydev >= 0) {
|
||||
if (::close(joydev) != 0) {
|
||||
debug_mesg("close(js%d %d): %s\n", index, joydev, strerror(errno));
|
||||
}
|
||||
joydev = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void JoyPad::open(int dev) {
|
||||
debug_mesg("resetting to dev\n");
|
||||
//remember the device file descriptor
|
||||
close();
|
||||
joydev = dev;
|
||||
|
||||
//read in the number of axes / buttons
|
||||
axes = 0;
|
||||
ioctl (joydev, JSIOCGAXES, &axes);
|
||||
buttons = 0;
|
||||
ioctl (joydev, JSIOCGBUTTONS, &buttons);
|
||||
axisCount = 0;
|
||||
ioctl (joydev, JSIOCGAXES, &axisCount);
|
||||
buttonCount = 0;
|
||||
ioctl (joydev, JSIOCGBUTTONS, &buttonCount);
|
||||
//make sure that we have the axes we need.
|
||||
//if one that we need doesn't yet exist, add it in.
|
||||
//Note: if the current layout has a key assigned to an axis that did not
|
||||
//have a real joystick axis mapped to it, and this function suddenly brings
|
||||
//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, this ));
|
||||
for (int i = 0; i < axisCount; 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, this ));
|
||||
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;
|
||||
@ -63,35 +96,31 @@ void JoyPad::resetToDev(int dev ) {
|
||||
debug_mesg("reading junk data\n");
|
||||
if (read(joydev, buf, 10) <= 0) break;
|
||||
}
|
||||
setupJoyDeviceListener(dev);
|
||||
debug_mesg("done resetting to dev\n");
|
||||
}
|
||||
|
||||
void JoyPad::setupJoyDeviceListener(int dev) {
|
||||
debug_mesg("Setting up joyDeviceListeners\n");
|
||||
joydevFileHandle = new QSocketNotifier(dev, QSocketNotifier::Read, this);
|
||||
connect(joydevFileHandle, SIGNAL(activated(int)), this, SLOT(handleJoyEvents(int)));
|
||||
joydevFileException = new QSocketNotifier(dev, QSocketNotifier::Exception, this);
|
||||
connect(joydevFileException, SIGNAL(activated(int)), this, SLOT(errorRead(int)));
|
||||
readNotifier = new QSocketNotifier(joydev, QSocketNotifier::Read, this);
|
||||
connect(readNotifier, SIGNAL(activated(int)), this, SLOT(handleJoyEvents()));
|
||||
errorNotifier = new QSocketNotifier(joydev, QSocketNotifier::Exception, this);
|
||||
connect(errorNotifier, SIGNAL(activated(int)), this, SLOT(handleJoyEvents()));
|
||||
debug_mesg("Done setting up joyDeviceListeners\n");
|
||||
debug_mesg("done resetting to dev\n");
|
||||
}
|
||||
|
||||
void JoyPad::toDefault() {
|
||||
//to reset the whole, reset all the parts.
|
||||
foreach (Axis *axis, Axes) {
|
||||
foreach (Axis *axis, axes) {
|
||||
axis->toDefault();
|
||||
}
|
||||
foreach (Button *button, Buttons) {
|
||||
foreach (Button *button, buttons) {
|
||||
button->toDefault();
|
||||
}
|
||||
}
|
||||
|
||||
bool JoyPad::isDefault() {
|
||||
//if any of the parts are not at default, then the whole isn't either.
|
||||
foreach (Axis *axis, Axes) {
|
||||
foreach (Axis *axis, axes) {
|
||||
if (!axis->isDefault()) return false;
|
||||
}
|
||||
foreach (Button *button, Buttons) {
|
||||
foreach (Button *button, buttons) {
|
||||
if (!button->isDefault()) return false;
|
||||
}
|
||||
return true;
|
||||
@ -115,10 +144,10 @@ bool JoyPad::readConfig( QTextStream &stream ) {
|
||||
error("Layout file error", QString("Expected ':', found '%1'.").arg(ch));
|
||||
return false;
|
||||
}
|
||||
if (Buttons[num-1] == 0) {
|
||||
Buttons.insert(num-1,new Button(num-1));
|
||||
if (buttons[num-1] == 0) {
|
||||
buttons.insert(num-1,new Button(num-1));
|
||||
}
|
||||
if (!Buttons[num-1]->read( stream )) {
|
||||
if (!buttons[num-1]->read( stream )) {
|
||||
error("Layout file error", QString("Error reading Button %1").arg(num));
|
||||
return false;
|
||||
}
|
||||
@ -135,10 +164,10 @@ bool JoyPad::readConfig( QTextStream &stream ) {
|
||||
error("Layout file error", QString("Expected ':', found '%1'.").arg(ch));
|
||||
return false;
|
||||
}
|
||||
if (Axes[num-1] == 0) {
|
||||
Axes.insert(num-1,new Axis(num-1));
|
||||
if (axes[num-1] == 0) {
|
||||
axes.insert(num-1,new Axis(num-1));
|
||||
}
|
||||
if (!Axes[num-1]->read(stream)) {
|
||||
if (!axes[num-1]->read(stream)) {
|
||||
error("Layout file error", QString("Error reading Axis %1").arg(num));
|
||||
return false;
|
||||
}
|
||||
@ -155,12 +184,12 @@ 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()) {
|
||||
if (!axes.empty() || !buttons.empty()) {
|
||||
stream << getName() << " {\n";
|
||||
foreach (Axis *axis, Axes) {
|
||||
foreach (Axis *axis, axes) {
|
||||
axis->write(stream);
|
||||
}
|
||||
foreach (Button *button, Buttons) {
|
||||
foreach (Button *button, buttons) {
|
||||
button->write(stream);
|
||||
}
|
||||
stream << "}\n\n";
|
||||
@ -168,15 +197,15 @@ void JoyPad::write( QTextStream &stream ) {
|
||||
}
|
||||
|
||||
void JoyPad::release() {
|
||||
foreach (Axis *axis, Axes) {
|
||||
foreach (Axis *axis, axes) {
|
||||
axis->release();
|
||||
}
|
||||
foreach (Button *button, Buttons) {
|
||||
foreach (Button *button, buttons) {
|
||||
button->release();
|
||||
}
|
||||
}
|
||||
|
||||
void JoyPad::jsevent( js_event msg ) {
|
||||
void JoyPad::jsevent(const js_event &msg) {
|
||||
//if there is a JoyPadWidget around, ie, if the joypad is being edited
|
||||
if (jpw != NULL && hasFocus) {
|
||||
//tell the dialog there was an event. It will use this to flash
|
||||
@ -190,15 +219,18 @@ void JoyPad::jsevent( 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.
|
||||
if (msg.type & JS_EVENT_AXIS) {
|
||||
qulonglong 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);
|
||||
Axes[msg.number]->jsevent(msg.value);
|
||||
Axis *axis = axes[msg.number];
|
||||
if (axis) axis->jsevent(msg.value);
|
||||
}
|
||||
else {
|
||||
else if (type == JS_EVENT_BUTTON) {
|
||||
debug_mesg("DEBUG: passing on a button event\n");
|
||||
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
|
||||
Buttons[msg.number]->jsevent(msg.value);
|
||||
Button *button = buttons[msg.number];
|
||||
if (button) button->jsevent(msg.value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,15 +240,11 @@ JoyPadWidget* JoyPad::widget( QWidget* parent, int i) {
|
||||
return jpw;
|
||||
}
|
||||
|
||||
void JoyPad::handleJoyEvents(int fd) {
|
||||
Q_UNUSED(fd);
|
||||
|
||||
void JoyPad::handleJoyEvents() {
|
||||
js_event msg;
|
||||
int len;
|
||||
|
||||
len = read( joydev, &msg, sizeof(js_event));
|
||||
ssize_t len = read(joydev, &msg, sizeof(js_event));
|
||||
//if there was a real event waiting,
|
||||
if (len == (int) sizeof(js_event)) {
|
||||
if (len == sizeof(js_event)) {
|
||||
//pass that event on to the joypad!
|
||||
jsevent(msg);
|
||||
}
|
||||
@ -227,30 +255,10 @@ void JoyPad::releaseWidget() {
|
||||
jpw = NULL;
|
||||
}
|
||||
|
||||
void JoyPad::unsetDev() {
|
||||
close(joydev);
|
||||
joydev = -1;
|
||||
if(joydevFileHandle != NULL) {
|
||||
delete joydevFileHandle;
|
||||
}
|
||||
}
|
||||
|
||||
void JoyPad::errorRead(int fd) {
|
||||
debug_mesg("There was an error reading off of the device with fd %d, disabling\n", fd);
|
||||
joydevFileHandle->blockSignals(true);
|
||||
joydevFileHandle->setEnabled(false);
|
||||
close(joydev);
|
||||
if(disconnect(joydevFileHandle , 0, 0, 0)) {
|
||||
joydevFileHandle->deleteLater();
|
||||
joydevFileHandle = NULL;
|
||||
}
|
||||
if(disconnect(joydevFileException, 0, 0, 0)) {
|
||||
joydevFileException->setEnabled(false);
|
||||
joydevFileException->deleteLater();
|
||||
joydevFileException = NULL;
|
||||
}
|
||||
joydev = -1;
|
||||
debug_mesg("Done disabling device with fd %d\n", fd);
|
||||
void JoyPad::errorRead() {
|
||||
debug_mesg("There was an error reading off of the device with fd %d, disabling\n", joydev);
|
||||
close();
|
||||
debug_mesg("Done disabling device with fd %d\n", joydev);
|
||||
}
|
||||
|
||||
void JoyPad::focusChange(bool focusState) {
|
||||
|
26
src/joypad.h
26
src/joypad.h
@ -28,8 +28,10 @@ class JoyPad : public QObject {
|
||||
friend class JoyPadWidget;
|
||||
friend class QuickSet;
|
||||
public:
|
||||
void setupJoyDeviceListener(int dev);
|
||||
JoyPad( int i, int dev, QObject* parent );
|
||||
~JoyPad();
|
||||
// close file descriptor and socket notifier
|
||||
void close();
|
||||
//read from a stream
|
||||
bool readConfig( QTextStream &stream );
|
||||
//write to a stream
|
||||
@ -37,15 +39,13 @@ class JoyPad : public QObject {
|
||||
//release any pushed buttons and return to a neutral state
|
||||
void release();
|
||||
//handle an event from the joystick device this is associated with
|
||||
void jsevent( js_event msg );
|
||||
void jsevent( const js_event& msg );
|
||||
//reset to default settings
|
||||
void toDefault();
|
||||
//true iff this is currently at default settings
|
||||
bool isDefault();
|
||||
//release the connection to the real joystick
|
||||
void unsetDev();
|
||||
//read the dimensions on the real joystick and use them
|
||||
void resetToDev( int dev );
|
||||
void open( int dev );
|
||||
//generates a name ("Joystick 1")
|
||||
QString getName() const { return QString("Joystick %1").arg(index+1);}
|
||||
int getIndex() const { return index; }
|
||||
@ -54,8 +54,8 @@ class JoyPad : public QObject {
|
||||
|
||||
//it's just easier to have these publicly available.
|
||||
int joydev; //the actual file descriptor to the joystick device
|
||||
int axes; //the number of axes available on this device
|
||||
int buttons; //the number of buttons
|
||||
char axisCount; //the number of axes available on this device
|
||||
char buttonCount; //the number of buttons
|
||||
|
||||
public:
|
||||
//request the joypad to make a JoyPadWidget. We create them this way
|
||||
@ -68,21 +68,21 @@ class JoyPad : public QObject {
|
||||
//layouts with different numbers of axes/buttons than the current
|
||||
//devices. Note that with the current layout settings, the defined
|
||||
//buttons that don't actually exist on the device may not be contiguous.
|
||||
QHash<int, Axis*> Axes;
|
||||
QHash<int, Button*> Buttons;
|
||||
QHash<int, Axis*> axes;
|
||||
QHash<int, Button*> buttons;
|
||||
//the index of this device (devicenum)
|
||||
int index;
|
||||
|
||||
//the widget that edits this. Mainly I keep track of this to know if
|
||||
//the joypad is currently being edited.
|
||||
JoyPadWidget* jpw;
|
||||
QSocketNotifier *joydevFileHandle;
|
||||
QSocketNotifier *joydevFileException;
|
||||
QSocketNotifier *readNotifier;
|
||||
QSocketNotifier *errorNotifier;
|
||||
QString deviceId;
|
||||
bool hasFocus;
|
||||
public slots:
|
||||
void handleJoyEvents(int fd);
|
||||
void errorRead(int fd);
|
||||
void handleJoyEvents();
|
||||
void errorRead();
|
||||
void focusChange(bool windowHasFocus);
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,7 @@ JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent )
|
||||
int insertCounter = 0;
|
||||
quickset = NULL;
|
||||
|
||||
foreach (Axis *axis, joypad->Axes) {
|
||||
foreach (Axis *axis, joypad->axes) {
|
||||
AxisWidget *aw = new AxisWidget(axis,this);
|
||||
axes.append(aw);
|
||||
connect( aw, SIGNAL( flashed( bool ) ), this, SLOT( flash( bool )));
|
||||
@ -23,7 +23,7 @@ JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent )
|
||||
insertCounter++;
|
||||
}
|
||||
|
||||
foreach (Button *button, joypad->Buttons) {
|
||||
foreach (Button *button, joypad->buttons) {
|
||||
ButtonWidget *bw = new ButtonWidget(button,this);
|
||||
buttons.append(bw);
|
||||
connect( bw, SIGNAL( flashed( bool ) ), this, SLOT( flash( bool )));
|
||||
@ -31,7 +31,6 @@ JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent )
|
||||
insertCounter++;
|
||||
}
|
||||
|
||||
|
||||
if (insertCounter % 2 == 1) {
|
||||
insertCounter ++;
|
||||
}
|
||||
@ -86,16 +85,18 @@ void JoyPadWidget::setAll() {
|
||||
quickset = NULL;
|
||||
}
|
||||
|
||||
void JoyPadWidget::jsevent( js_event msg ) {
|
||||
void JoyPadWidget::jsevent( const js_event& msg ) {
|
||||
//notify the component this event applies to. this cannot generate anything
|
||||
//other than a flash :)
|
||||
if (msg.type == JS_EVENT_AXIS) {
|
||||
qulonglong type = msg.type & ~JS_EVENT_INIT;
|
||||
if (type == JS_EVENT_AXIS) {
|
||||
if (msg.number < axes.count()) axes[msg.number]->jsevent(msg.value);
|
||||
}
|
||||
else {
|
||||
else if (type == JS_EVENT_BUTTON) {
|
||||
if (msg.number < buttons.count()) buttons[msg.number]->jsevent(msg.value);
|
||||
}
|
||||
//if we're doing quickset, it needs to know when we do something.
|
||||
if (quickset != NULL)
|
||||
if (quickset != NULL) {
|
||||
quickset->jsevent(msg);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class JoyPadWidget : public QWidget {
|
||||
JoyPadWidget( JoyPad* jp, int i, QWidget* parent);
|
||||
~JoyPadWidget();
|
||||
//takes in an event and decides whether or not to flash anything
|
||||
void jsevent( js_event msg );
|
||||
void jsevent(const js_event &msg );
|
||||
public slots:
|
||||
//called whenever one of the subwidgets flashes... used to determine
|
||||
//when to emit the flashed() signal.
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <QX11Info>
|
||||
#include "keycode.h"
|
||||
#include "getkey.h"
|
||||
|
||||
@ -7,7 +8,7 @@ const QString ktos( int keycode )
|
||||
|
||||
if (keycode == 0) return "[NO KEY]";
|
||||
|
||||
QString xname = XKeysymToString(XKeycodeToKeysym(display, keycode,0));
|
||||
QString xname = XKeysymToString(XKeycodeToKeysym(QX11Info::display(), keycode,0));
|
||||
|
||||
//this section of code converts standard X11 keynames into much nicer names
|
||||
//which are prettier, fit the dialogs better, and are more readily understandable.
|
||||
|
@ -13,9 +13,6 @@
|
||||
//Produce a string for any keycode
|
||||
const QString ktos( int keycode );
|
||||
|
||||
//The X11 display, taken from main.cpp
|
||||
extern Display* display;
|
||||
|
||||
|
||||
//a button that requests a keycode from the user when clicked.
|
||||
class KeyButton : public QPushButton {
|
||||
|
@ -17,16 +17,23 @@ LayoutManager::LayoutManager( bool useTrayIcon, const QString &devdir, const QSt
|
||||
}
|
||||
//or make a floating icon
|
||||
else {
|
||||
FloatingIcon* Icon = new FloatingIcon(QPixmap(ICON64),&trayMenuPopup,0,"tray");
|
||||
connect(Icon, SIGNAL( clicked()), this, SLOT( iconClick()));
|
||||
connect(Icon, SIGNAL( closed()), qApp, SLOT( quit()));
|
||||
Icon->show();
|
||||
FloatingIcon* icon = new FloatingIcon(QPixmap(ICON64),&trayMenuPopup,0,"tray");
|
||||
connect(icon, SIGNAL( clicked()), this, SLOT( iconClick()));
|
||||
connect(icon, SIGNAL( closed()), qApp, SLOT( quit()));
|
||||
icon->show();
|
||||
}
|
||||
|
||||
//no layout loaded at start.
|
||||
setLayoutName(NL);
|
||||
}
|
||||
|
||||
LayoutManager::~LayoutManager() {
|
||||
if (le) {
|
||||
le->close();
|
||||
le = 0;
|
||||
}
|
||||
}
|
||||
|
||||
QString LayoutManager::getFileName( QString layoutname ) {
|
||||
return QString("%1%2.lyt").arg(settingsDir, layoutname);
|
||||
}
|
||||
@ -204,7 +211,7 @@ void LayoutManager::saveAs() {
|
||||
|
||||
//add the new name to our lists
|
||||
fillPopup();
|
||||
if (le != NULL) {
|
||||
if (le) {
|
||||
le->updateLayoutList();
|
||||
}
|
||||
}
|
||||
@ -227,7 +234,7 @@ void LayoutManager::remove() {
|
||||
}
|
||||
fillPopup();
|
||||
|
||||
if (le != NULL) {
|
||||
if (le) {
|
||||
le->updateLayoutList();
|
||||
}
|
||||
clear();
|
||||
@ -238,7 +245,8 @@ QStringList LayoutManager::getLayoutNames() const {
|
||||
QStringList result = QDir(settingsDir).entryList(QStringList("*.lyt"));
|
||||
|
||||
for (int i = 0; i < result.size(); ++ i) {
|
||||
result[i] = result[i].left(result[i].length() - 4);
|
||||
QString& name = result[i];
|
||||
name.truncate(name.length() - 4);
|
||||
}
|
||||
//and, of course, there's always NL.
|
||||
result.prepend(NL);
|
||||
@ -250,7 +258,7 @@ void LayoutManager::setLayoutName(QString name) {
|
||||
currentLayout = name;
|
||||
fillPopup();
|
||||
|
||||
if (le != NULL) {
|
||||
if (le) {
|
||||
le->setLayout(name);
|
||||
}
|
||||
}
|
||||
@ -262,6 +270,12 @@ void LayoutManager::iconClick() {
|
||||
return;
|
||||
}
|
||||
if (le) {
|
||||
if (le->hasFocus()) {
|
||||
le->close();
|
||||
}
|
||||
else {
|
||||
le->raise();
|
||||
}
|
||||
return;
|
||||
}
|
||||
//otherwise, make a new LayoutEdit dialog and show it.
|
||||
@ -328,7 +342,7 @@ void LayoutManager::updateJoyDevs() {
|
||||
|
||||
//reset all joydevs to sentinal value (-1)
|
||||
foreach (JoyPad *joypad, joypads) {
|
||||
joypad->unsetDev();
|
||||
joypad->close();
|
||||
}
|
||||
|
||||
//clear out the list of previously available joysticks
|
||||
@ -338,8 +352,8 @@ void LayoutManager::updateJoyDevs() {
|
||||
QDir deviceDir(devdir);
|
||||
QStringList devices = deviceDir.entryList(QStringList("js*"), QDir::System);
|
||||
QRegExp devicename(".*\\js(\\d+)");
|
||||
int joydev = 0;
|
||||
int index = 0;
|
||||
int joydev = -1;
|
||||
int index = -1;
|
||||
//for every joystick device in the directory listing...
|
||||
//(note, with devfs, only available devices are listed)
|
||||
foreach (const QString &device, devices) {
|
||||
@ -349,7 +363,7 @@ void LayoutManager::updateJoyDevs() {
|
||||
joydev = open( qPrintable(devpath), O_RDONLY | O_NONBLOCK);
|
||||
//if it worked, then we have a live joystick! Make sure it's properly
|
||||
//setup.
|
||||
if (joydev > 0) {
|
||||
if (joydev >= 0) {
|
||||
devicename.indexIn(device);
|
||||
index = devicename.cap(1).toInt();
|
||||
JoyPad* joypad = joypads[index];
|
||||
@ -368,7 +382,7 @@ void LayoutManager::updateJoyDevs() {
|
||||
}
|
||||
else {
|
||||
debug_mesg("found previously open joypad with index %d, ignoring", index);
|
||||
joypad->resetToDev(joydev);
|
||||
joypad->open(joydev);
|
||||
}
|
||||
//make this joystick device available.
|
||||
available.insert(index,joypad);
|
||||
@ -385,7 +399,3 @@ void LayoutManager::updateJoyDevs() {
|
||||
}
|
||||
debug_mesg("done updating joydevs\n");
|
||||
}
|
||||
|
||||
void LayoutManager::leWindowClosed() {
|
||||
le=NULL;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <QMenu>
|
||||
#include <QApplication>
|
||||
#include <QDialog>
|
||||
#include <QPointer>
|
||||
#include <QInputDialog>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <poll.h>
|
||||
@ -35,10 +36,10 @@ class LayoutManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LayoutManager(bool useTrayIcon, const QString &devdir, const QString &settingsDir);
|
||||
~LayoutManager();
|
||||
|
||||
//produces a list of the names of all the available layout.
|
||||
QStringList getLayoutNames() const;
|
||||
void leWindowClosed();
|
||||
public slots:
|
||||
//load a layout with a given name
|
||||
bool load(const QString& name);
|
||||
@ -82,7 +83,7 @@ class LayoutManager : public QObject {
|
||||
QMenu trayMenuPopup;
|
||||
|
||||
//if there is a LayoutEdit open, this points to it. Otherwise, NULL.
|
||||
LayoutEdit* le;
|
||||
QPointer<LayoutEdit> le;
|
||||
|
||||
QHash<int, JoyPad*> available;
|
||||
QHash<int, JoyPad*> joypads;
|
||||
|
@ -130,11 +130,6 @@ void LayoutEdit::updateJoypadWidgets() {
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutEdit::closeEvent(QCloseEvent *event) {
|
||||
lm->leWindowClosed();
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void LayoutEdit::appFocusChanged(QWidget *old, QWidget *now) {
|
||||
if (now != NULL && old == NULL) {
|
||||
emit focusStateChanged(false);
|
||||
|
@ -29,7 +29,6 @@ class LayoutEdit : public QWidget {
|
||||
protected:
|
||||
//the layout manager this represents
|
||||
LayoutManager* lm;
|
||||
virtual void closeEvent(QCloseEvent *event);
|
||||
//parts of the dialog:
|
||||
QVBoxLayout *mainLayout;
|
||||
QStackedWidget *padStack;
|
||||
|
10
src/main.cpp
10
src/main.cpp
@ -14,7 +14,6 @@
|
||||
#include "event.h"
|
||||
//to produce errors!
|
||||
#include "error.h"
|
||||
#include <QX11Info>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QPointer>
|
||||
#include <getopt.h>
|
||||
@ -57,8 +56,8 @@ int main( int argc, char **argv )
|
||||
{
|
||||
//create a new event loop. This will be captured by the QApplication
|
||||
//when it gets created
|
||||
QApplication a( argc, argv );
|
||||
a.setQuitOnLastWindowClosed(false);
|
||||
QApplication app( argc, argv );
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
|
||||
//where QJoyPad saves its settings!
|
||||
@ -231,9 +230,6 @@ int main( int argc, char **argv )
|
||||
}
|
||||
}
|
||||
}
|
||||
//capture the current display for event.h
|
||||
display = QX11Info::display();
|
||||
|
||||
//create a new LayoutManager with a tray icon / floating icon, depending
|
||||
//on the user's request
|
||||
LayoutManager layoutManager(useTrayIcon,devdir,settingsDir);
|
||||
@ -252,7 +248,7 @@ int main( int argc, char **argv )
|
||||
// signal( SIGUSR2, catchSIGUSR2 );
|
||||
|
||||
//and run the program!
|
||||
int result = a.exec();
|
||||
int result = app.exec();
|
||||
|
||||
//when everything is done, save the current layout for next time...
|
||||
layoutManager.saveDefault();
|
||||
|
@ -19,14 +19,15 @@ QuickSet::QuickSet( JoyPad* jp, QWidget *parent)
|
||||
connect( button, SIGNAL(clicked()), this, SLOT(accept()));
|
||||
}
|
||||
|
||||
void QuickSet::jsevent( js_event msg ) {
|
||||
void QuickSet::jsevent(const js_event &msg ) {
|
||||
//ignore any joystick events if we're waiting for a keypress
|
||||
if (setting) return;
|
||||
|
||||
//if a button was pressed on the joystick
|
||||
if (msg.type == JS_EVENT_BUTTON) {
|
||||
qulonglong type = msg.type & ~JS_EVENT_INIT;
|
||||
if (type == JS_EVENT_BUTTON) {
|
||||
//capture that button.
|
||||
Button* button = joypad->Buttons[msg.number];
|
||||
Button* button = joypad->buttons[msg.number];
|
||||
|
||||
//go into setting mode and request a key/mousebutton
|
||||
setting = true;
|
||||
@ -41,16 +42,16 @@ void QuickSet::jsevent( js_event msg ) {
|
||||
//otherwise, tell it to use a keycode.
|
||||
button->setKey(false, code);
|
||||
}
|
||||
else {
|
||||
else if (type == JS_EVENT_AXIS) {
|
||||
//require a signal strength of at least 5000 to consider an axis moved.
|
||||
if (abs(msg.value) < 5000) return;
|
||||
|
||||
//capture the axis that moved
|
||||
Axis* axis = joypad->Axes[msg.number];
|
||||
Axis* axis = joypad->axes[msg.number];
|
||||
|
||||
//grab a keycode for that axis and that direction
|
||||
setting = true;
|
||||
int code = GetKey(axis->getName() + ", " + QString((msg.value > 0)?"positive":"negative"), false).exec();
|
||||
int code = GetKey(QString("%1, %2").arg(axis->getName(), msg.value > 0 ? "positive" : "negative"), false).exec();
|
||||
setting = false;
|
||||
|
||||
//assign the key to the axis.
|
||||
|
@ -23,7 +23,7 @@ class QuickSet : public QDialog {
|
||||
public:
|
||||
QuickSet(JoyPad* jp, QWidget *parent = 0);
|
||||
//this needs to see js_events so it can capture them directly
|
||||
void jsevent( js_event msg );
|
||||
void jsevent( const js_event& msg );
|
||||
private:
|
||||
//the joypad that is being configured
|
||||
JoyPad* joypad;
|
||||
|
Reference in New Issue
Block a user