Skip to content

Commit

Permalink
Merge pull request alols#89 from qu1x/add-foreground-flag
Browse files Browse the repository at this point in the history
Add '-f' flag (implied by '-d' flag).
  • Loading branch information
alols authored Aug 7, 2017
2 parents 99dda44 + d8dbbf8 commit 6ded5b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ Then run:

Usage
-----
$ xcape [-d] [-t <timeout ms>] [-e <map-expression>]
$ xcape [-d] [-f] [-t <timeout ms>] [-e <map-expression>]

### `-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 <timeout ms>`

Expand Down
8 changes: 6 additions & 2 deletions xcape.1
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.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

.SH SYNOPSIS
.B xcape
[\fB-d\fR]
[\fB-f\fR]
[\fB-t\fR \fItimeout\fR]
[\fB-e\fR \fImap-expression\fR]

Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions xcape.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 <mapping>]\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 <mapping>]\n", program_name);
fprintf (stdout, "Runs as a daemon unless -d or -f flag is set\n");
}

0 comments on commit 6ded5b4

Please sign in to comment.