1.1 --- a/src/drivers/joy_linux.c Mon Jan 28 11:17:15 2008 +0000
1.2 +++ b/src/drivers/joy_linux.c Wed Jan 30 11:31:21 2008 +0000
1.4 * GNU General Public License for more details.
1.8 #include <sys/types.h>
1.9 #include <sys/ioctl.h>
1.12 +#include <signal.h>
1.17 static uint16_t linux_joystick_resolve_keysym( input_driver_t dev, const gchar *str );
1.18 static gchar *linux_joystick_keysym_for_keycode( input_driver_t dev, uint16_t keycode );
1.19 static void linux_joystick_destroy( input_driver_t joy );
1.20 +static gboolean linux_joystick_install_watch( const gchar *dir );
1.21 +static void linux_joystick_uninstall_watch( void );
1.24 * Convert keysym to keycode. Keysyms are either Button%d or Axis%d[+-], with buttons
1.26 linux_joystick_t joy = (linux_joystick_t)data;
1.28 if( condition & G_IO_HUP ) {
1.30 INFO( "Joystick '%s' disconnected\n", joy->name );
1.31 input_unregister_device((input_driver_t)joy);
1.33 @@ -195,6 +198,12 @@
1.35 int linux_joystick_init()
1.37 + linux_joystick_install_watch(INPUT_PATH);
1.38 + linux_joystick_scan();
1.41 +int linux_joystick_scan()
1.45 DIR *dir = opendir(INPUT_PATH);
1.46 @@ -224,3 +233,51 @@
1.50 +void linux_joystick_shutdown(void)
1.52 + linux_joystick_uninstall_watch();
1.55 +/*************************** dnotify support **********************/
1.57 +static volatile gboolean need_input_rescan = FALSE;
1.58 +static int watch_dir_fd;
1.60 +static gboolean gtk_loop_check_input(gpointer data)
1.62 + if( need_input_rescan ) {
1.63 + int js = linux_joystick_scan();
1.65 + maple_reattach_all();
1.71 +static void dnotify_handler(int sig )
1.73 + need_input_rescan = TRUE;
1.76 +static gboolean linux_joystick_install_watch( const gchar *dir )
1.78 + int fd = open( dir, O_RDONLY|O_NONBLOCK );
1.83 + signal( SIGRTMIN+1, dnotify_handler );
1.84 + fcntl(fd, F_SETSIG, SIGRTMIN + 1);
1.85 + if( fcntl(fd, F_NOTIFY, DN_CREATE|DN_MULTISHOT) == -1 ) {
1.89 + watch_dir_fd = fd;
1.90 + g_timeout_add( 500, gtk_loop_check_input, NULL );
1.93 +static void linux_joystick_uninstall_watch(void)
1.95 + signal( SIGRTMIN+1, SIG_IGN );
1.96 + close( watch_dir_fd );