From d8dbbf8a25578c8ff8b6f3648f9e10b30d77ee26 Mon Sep 17 00:00:00 2001 From: Rouven Spreckels Date: Mon, 3 Jul 2017 20:58:26 +0200 Subject: [PATCH] Add '-f' flag (implied by '-d' flag). --- README.md | 8 ++++++-- xcape.1 | 8 ++++++-- xcape.c | 13 +++++++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fffcd58..4ab4971 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,15 @@ Then run: Usage ----- - $ xcape [-d] [-t ] [-e ] + $ xcape [-d] [-f] [-t ] [-e ] ### `-d` -Debug mode. Does not fork into the background. +Debug mode. Does not fork into the background. Prints debug information. + +### `-f` + +Foreground mode. Does not fork into the background. ### `-t ` diff --git a/xcape.1 b/xcape.1 index 255ea84..7b2efc8 100644 --- a/xcape.1 +++ b/xcape.1 @@ -1,4 +1,4 @@ -.TH XCAPE 1 2014-02-13 "John Hill" "xcape Manual" +.TH XCAPE 1 2017-07-03 "John Hill" "xcape Manual" .SH NAME xcape \- use a modifier key as another key @@ -6,6 +6,7 @@ xcape \- use a modifier key as another key .SH SYNOPSIS .B xcape [\fB-d\fR] +[\fB-f\fR] [\fB-t\fR \fItimeout\fR] [\fB-e\fR \fImap-expression\fR] @@ -17,7 +18,10 @@ key in place of \fIControl_L\fR (Left Control). .SH OPTIONS .TP .BR \-d -Debug mode. Will run as a foreground process. +Debug mode. Will run as a foreground process and print debug information. +.TP +.BR \-f +Foreground mode. Will run as a foreground process. .TP .BR \-t " " \fItimeout\fR Give a \fItimeout\fR in milliseconds. If you hold a key longer than diff --git a/xcape.c b/xcape.c index 7c067eb..1bdf2b8 100644 --- a/xcape.c +++ b/xcape.c @@ -62,6 +62,7 @@ typedef struct _XCape_t XRecordContext record_ctx; pthread_t sigwait_thread; sigset_t sigset; + Bool foreground; Bool debug; KeyMap_t *map; Key_t *generated; @@ -100,6 +101,7 @@ int main (int argc, char **argv) XRecordRange *rec_range = XRecordAllocRange(); XRecordClientSpec client_spec = XRecordAllClients; + self->foreground = False; self->debug = False; self->timeout.tv_sec = 0; self->timeout.tv_usec = 500000; @@ -108,12 +110,15 @@ int main (int argc, char **argv) rec_range->device_events.first = KeyPress; rec_range->device_events.last = ButtonRelease; - while ((ch = getopt (argc, argv, "de:t:")) != -1) + while ((ch = getopt (argc, argv, "dfe:t:")) != -1) { switch (ch) { case 'd': self->debug = True; + /* imply -f (no break) */ + case 'f': + self->foreground = True; break; case 'e': mapping = optarg; @@ -187,7 +192,7 @@ int main (int argc, char **argv) exit (EXIT_FAILURE); } - if (self->debug != True) + if (self->foreground != True) daemon (0, 0); sigemptyset (&self->sigset); @@ -565,6 +570,6 @@ void delete_keys (Key_t *keys) void print_usage (const char *program_name) { - fprintf (stdout, "Usage: %s [-d] [-t timeout_ms] [-e ]\n", program_name); - fprintf (stdout, "Runs as a daemon unless -d flag is set\n"); + fprintf (stdout, "Usage: %s [-d] [-f] [-t timeout_ms] [-e ]\n", program_name); + fprintf (stdout, "Runs as a daemon unless -d or -f flag is set\n"); }