From ae9f3eed24474b18c04cf10178222653a0f1b7ad Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 7 Mar 2014 15:32:22 +1000 Subject: [PATCH synaptics 2/2] syndaemon: when failing to find the default trackstick, continue If all we want is trackstick monitoring with the default device, just continue if we cannot find the device. This enables a caller to simply start up syndaemon -P -M and have syndaemon handle the trackstick or not, depending on whether one exists. This makes starting it in a generic fashion a lot easier. Signed-off-by: Peter Hutterer --- man/syndaemon.man | 8 ++++-- tools/syndaemon.c | 73 +++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/man/syndaemon.man b/man/syndaemon.man index e9a18db..9f86b46 100644 --- a/man/syndaemon.man +++ b/man/syndaemon.man @@ -63,6 +63,10 @@ given without the name of a pointing stick, it defaults to . When using this option, keyboard monitoring is disabled unless explicitly enabled by specifying \fB\-R\fP or \fB\-M\fP. +. +If \fB\-R\fP or \fB\-M\fP is specified and no pointing stick device name has been +provided and syndaemon does not find a pointing stick, syndaemon continues +with keyboard monitoring only. .LP .TP \fB\-M\fP @@ -118,8 +122,8 @@ the server. .LP .TP \fBExit code 6 -Pointing stick monitoring requested, but a pointing stick could not be found -(try specifying the name manually when using \fB\-P\fP). +Pointing stick monitoring requested for a specific device, but the device +could not be found. .SH "CAVEATS" .LP It doesn't make much sense to connect to a remote X server, because diff --git a/tools/syndaemon.c b/tools/syndaemon.c index bd91343..bf25a55 100644 --- a/tools/syndaemon.c +++ b/tools/syndaemon.c @@ -39,6 +39,7 @@ #endif /* HAVE_X11_EXTENSIONS_RECORD_H */ #include +#include #include #include #include @@ -873,6 +874,27 @@ parse_idle_mode(const char * state) { return InvalidState; } +static void +pstick_error_msg(int fatal, int exitcode, const char *msg, ...) +{ + FILE *s = NULL; + va_list args; + + if (fatal) + s = stderr; + else if (verbose) + s = stdout; + else + return; + + va_start(args, msg); + vfprintf(s, msg, args); + va_end(args); + + if (fatal) + exit(exitcode); +} + int main(int argc, char *argv[]) { @@ -880,6 +902,7 @@ main(int argc, char *argv[]) int poll_delay = 200; /* ms */ int c; const char *pstick_name; + int pstick_name_provided = 0; int use_xrecord = 0; idle_state[KeyboardIdle] = TouchpadOff; @@ -920,10 +943,12 @@ main(int argc, char *argv[]) if (optopt == 'P') { monitor_pstick = True; if (optind < argc) { - if (argv[optind][0] == '-') + if (argv[optind][0] == '-') { pstick_name = DEFAULT_POINTING_STICK; - else + } else { pstick_name = argv[optind]; + pstick_name_provided = 1; + } } else pstick_name = DEFAULT_POINTING_STICK; @@ -1007,29 +1032,31 @@ main(int argc, char *argv[]) if (monitor_pstick) { int pstick_id; /* trackpoint device */ + int fatal_exit = pstick_name_provided || !monitor_keyboard; + if (setup_xsync(display) != 0) { - fprintf(stderr, "Monitoring of pointing stick requested, but " - "XSync could not be initialized.\n"); - exit(5); - } + pstick_error_msg(fatal_exit, 5, + "Monitoring of pointing stick requested, but " + "XSync could not be initialized.\n"); + } else { + pstick_id = get_device_id(display, pstick_name, XI_MOUSE); + if (pstick_id == 0) { + pstick_error_msg(fatal_exit, 6, + "Couldn't find pointing stick %s\n", pstick_name); + } else { + pstick_leave_idle_alarm = + setup_device_alarm(display, pstick_id, XSyncNegativeTransition, + idle_time * 1000); + pstick_enter_idle_alarm = + setup_device_alarm(display, pstick_id, XSyncPositiveTransition, + idle_time * 1000); - pstick_id = get_device_id(display, pstick_name, XI_MOUSE); - if (pstick_id == 0) { - fprintf(stderr, "Couldn't find pointing stick %s\n", pstick_name); - exit(6); - } - - pstick_leave_idle_alarm = - setup_device_alarm(display, pstick_id, XSyncNegativeTransition, - idle_time * 1000); - pstick_enter_idle_alarm = - setup_device_alarm(display, pstick_id, XSyncPositiveTransition, - idle_time * 1000); - - if (pstick_leave_idle_alarm == 0 || pstick_enter_idle_alarm == 0) { - fprintf(stderr, "Monitoring of pointing stick requested, but " - "device idletimers could not be initialized.\n"); - exit(5); + if (pstick_leave_idle_alarm == 0 || pstick_enter_idle_alarm == 0) { + pstick_error_msg(fatal_exit, 5, + "Monitoring of pointing stick requested, but " + "device idletimers could not be initialized.\n"); + } + } } } -- 1.8.5.3