started to reduce globals, set signal handlers after everything used in them initialized
This commit is contained in:
@ -425,5 +425,5 @@ void Axis::move( bool press ) {
|
||||
}
|
||||
}
|
||||
//actually create the event
|
||||
sendevent(e);
|
||||
sendevent(display, e);
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ void Button::click( bool press ) {
|
||||
click.value1 = useMouse?mousecode:keycode;
|
||||
click.value2 = 0;
|
||||
//and send it.
|
||||
sendevent( click );
|
||||
sendevent( display, click );
|
||||
}
|
||||
|
||||
void Button::timerCalled() {
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "event.h"
|
||||
|
||||
//this should be initialized by main.cpp as soon as the program starts.
|
||||
Display* display = 0;
|
||||
Display *display = 0;
|
||||
|
||||
//actually creates an XWindows event :)
|
||||
void sendevent( xevent e ) {
|
||||
void sendevent( Display* display, xevent e ) {
|
||||
if (e.value1 == 0 && e.value2 == 0) return;
|
||||
if (e.type == WARP) {
|
||||
XTestFakeRelativeMotionEvent(display, e.value1, e.value2, 0);
|
||||
|
@ -16,7 +16,8 @@ struct xevent {
|
||||
int value2; //y
|
||||
};
|
||||
|
||||
extern Display* display;
|
||||
|
||||
void sendevent( xevent e );
|
||||
void sendevent( Display* display, xevent e );
|
||||
|
||||
#endif
|
||||
|
34
src/main.cpp
34
src/main.cpp
@ -22,12 +22,11 @@
|
||||
#include <cstdlib>
|
||||
|
||||
//for making universally available variables
|
||||
extern Display* display; //from event.h
|
||||
QHash<int, JoyPad*> available; //to device.h
|
||||
QHash<int, JoyPad*> joypads; //to device.h
|
||||
|
||||
//variables needed in various functions in this file
|
||||
LayoutManager* lm;
|
||||
LayoutManager* lm = 0;
|
||||
QString devdir = DEVDIR;
|
||||
|
||||
//signal handler for SIGIO
|
||||
@ -112,7 +111,20 @@ int main( int argc, char **argv )
|
||||
}
|
||||
//if help was requested,
|
||||
else if (QRegExp("-{1,2}h(elp)?").exactMatch(a.argv()[i])) {
|
||||
printf(NAME"\nUsage: qjoypad [--device \"/device/path\"] [--notray] [\"layout name\"]\n\nOptions:\n --device path Look for joystick devices in \"path\". This should\n be something like \"/dev/input\" if your game\n devices are in /dev/input/js0, /dev/input/js1, etc.\n --notray Do not use a system tray icon. This is useful for\n window managers that don't support this feature.\n --update Force a running instance of QJoyPad to update its\n list of devices and layouts.\n \"layout name\" Load the given layout in an already running\n instance of QJoyPad, or start QJoyPad using the\n given layout.\n");
|
||||
printf("%s\n"
|
||||
"Usage: qjoypad [--device \"/device/path\"] [--notray] [\"layout name\"]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" --device path Look for joystick devices in \"path\". This should\n"
|
||||
" be something like \"/dev/input\" if your game\n"
|
||||
" devices are in /dev/input/js0, /dev/input/js1, etc.\n"
|
||||
" --notray Do not use a system tray icon. This is useful for\n"
|
||||
" window managers that don't support this feature.\n"
|
||||
" --update Force a running instance of QJoyPad to update its\n"
|
||||
" list of devices and layouts.\n"
|
||||
" \"layout name\" Load the given layout in an already running\n"
|
||||
" instance of QJoyPad, or start QJoyPad using the\n"
|
||||
" given layout.\n", NAME);
|
||||
return 1;
|
||||
} else if(QRegExp("--force-tray").exactMatch(a.argv()[i])) {
|
||||
useTrayIcon = true;
|
||||
@ -146,7 +158,7 @@ int main( int argc, char **argv )
|
||||
//if that file already exists, then qjoypad is already running!
|
||||
if (pidFile.exists())
|
||||
{
|
||||
int pid;
|
||||
int pid = 0;
|
||||
if (pidFile.open( QIODevice::ReadOnly ))
|
||||
{
|
||||
//try to get that pid...
|
||||
@ -178,15 +190,6 @@ int main( int argc, char **argv )
|
||||
pidFile.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//prepare the signal handlers
|
||||
signal( SIGIO, catchSIGIO );
|
||||
signal( SIGUSR1, catchSIGUSR1 );
|
||||
// signal( SIGUSR2, catchSIGUSR2 );
|
||||
|
||||
|
||||
if(forceTrayIcon) {
|
||||
int sleepCounter = 0;
|
||||
while(!QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||
@ -212,6 +215,11 @@ int main( int argc, char **argv )
|
||||
//load the last used layout (Or the one given as a command-line argument)
|
||||
lm->load();
|
||||
|
||||
//prepare the signal handlers
|
||||
signal( SIGIO, catchSIGIO );
|
||||
signal( SIGUSR1, catchSIGUSR1 );
|
||||
// signal( SIGUSR2, catchSIGUSR2 );
|
||||
|
||||
//and run the program!
|
||||
int result = a.exec();
|
||||
|
||||
|
Reference in New Issue
Block a user