From 5fef530aa0c68975fbecd9090b9935ea43866c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Panzenb=C3=B6ck?= Date: Sat, 15 Feb 2014 06:07:53 +0100 Subject: [PATCH] started to reduce globals, set signal handlers after everything used in them initialized --- src/axis.cpp | 2 +- src/button.cpp | 2 +- src/event.cpp | 4 ++-- src/event.h | 3 ++- src/main.cpp | 34 +++++++++++++++++++++------------- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/axis.cpp b/src/axis.cpp index 7c9cb33..c135309 100644 --- a/src/axis.cpp +++ b/src/axis.cpp @@ -425,5 +425,5 @@ void Axis::move( bool press ) { } } //actually create the event - sendevent(e); + sendevent(display, e); } diff --git a/src/button.cpp b/src/button.cpp index ae8c9b1..518a237 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -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() { diff --git a/src/event.cpp b/src/event.cpp index 6ace5fc..ae64e6b 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -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); diff --git a/src/event.h b/src/event.h index 183fcde..b9c0eec 100644 --- a/src/event.h +++ b/src/event.h @@ -16,7 +16,8 @@ struct xevent { int value2; //y }; +extern Display* display; -void sendevent( xevent e ); +void sendevent( Display* display, xevent e ); #endif diff --git a/src/main.cpp b/src/main.cpp index 799ee5a..d10e899 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,12 +22,11 @@ #include //for making universally available variables -extern Display* display; //from event.h QHash available; //to device.h QHash 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();