diff options
authorJakob Kaivo <>2015-04-18 00:38:56 -0400
committerJakob Kaivo <>2015-04-18 00:38:56 -0400
commitaac2afbf514abc27a4c3b2af9c46ee9e2adf7940 (patch)
parentac0708c3af77d0e28c704248b5f361b369504666 (diff)
added command line optionspenxortouch
updated README to reflect said options
2 files changed, 48 insertions, 13 deletions
diff --git a/README b/README
index f05e560..8db1870 100644
--- a/README
+++ b/README
@@ -4,16 +4,17 @@ digitizer is near.
It requires the XInput extension and its accompanying library. On Debian, this
is available in the package libxi-dev.
-It's been developed and tested on a ThinkPad Yoga (first generation), which
-is what the input device names are configured for.
+The default pen and touch devices are specified by the PENDEVICE and
+TOUCHDEVICE symbolic constants #defined near the top of the code,
+respectively. These are the devices on a ThinkPad Yoga (first generation),
+on which this program was originally developed. Command line options are
+available to override either or both. The options are -t for the touch
+device and -p for the pen device. Check the output of xinput(1) for the names
+of the devices on your system. Note that if the names of your devices contain
+spaces, which is likely, you'll need to quote them in your shell.
-A future revision will support naming devices via command line options, but
-for the time being they are compiled in. If you are using a different tablet,
-you may need to edit the values of PENDEVICE and/or TOUCHDEVICE in
-penxortouch.c. Hopefully these names are self-explanatory. The command
-xinput(1) will give you a list of the input devices available on your system.
+A future revision will include an actual man page. As it is, the command is
+very simple and provides a basic usage synopsis with the -h option.
-A future revision will also include a genuine man page. As it is, there are
-no run-time options. Simply run the program, penxortouch, and it will disable
-the touchscreen device whenever the pen device comes in proximity to the
-screen, and reenable the touchscreen when the pen leaves proximity.
+A possibility for the future is some sort of intelligent default search
diff --git a/penxortouch.c b/penxortouch.c
index 902f6a5..362ff72 100644
--- a/penxortouch.c
+++ b/penxortouch.c
@@ -23,6 +23,7 @@ SOFTWARE.
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/extensions/XInput.h>
#include <X11/Xatom.h>
@@ -32,6 +33,8 @@ SOFTWARE.
#define DEVPROP "Device Enabled"
+#define USAGE "Usage: %s [-h] [-p pen-device] [-t touch-device]\n"
XDevice *
open_dev(Display *dpy, const char *devname)
@@ -113,10 +116,41 @@ main(int argc, char **argv)
XDevice *pen = NULL, *touch = NULL;
Display *dpy = NULL;
+ char *pendev = PENDEVICE, *touchdev = TOUCHDEVICE;
+ int opt;
+ while ((opt = getopt(argc, argv, "?hp:t:")) != -1) {
+ switch (opt) {
+ case 'p':
+ pendev = optarg;
+ break;
+ case 't':
+ touchdev = optarg;
+ break;
+ case 'h':
+ printf(USAGE, argv[0]);
+ printf("\n");
+ printf(" This command monitors a pen device for proxmity to the screen.\n");
+ printf(" When the pen device comes near, the touch device will be disabled.\n");
+ printf(" The touch device will be reenabled when the pen leaves the screen.\n");
+ printf(" The following options are available:\n");
+ printf("\n");
+ printf(" -h Prints out this usage information and exits\n");
+ printf(" -p pen-device Specifies the device to take precedence\n");
+ printf(" (default: %s)\n", PENDEVICE);
+ printf(" -t touch-device Specifies the device to be disabled\n");
+ printf(" (default: %s)\n", TOUCHDEVICE);
+ printf("\n");
+ return 0;
+ default:
+ fprintf(stderr, USAGE, argv[0]);
+ return 1;
+ }
+ }
if ((dpy = open_display()) == NULL) goto error;
- if ((pen = open_dev(dpy, PENDEVICE)) == NULL) goto error;
- if ((touch = open_dev(dpy, TOUCHDEVICE)) == NULL) goto error;
+ if ((pen = open_dev(dpy, pendev)) == NULL) goto error;
+ if ((touch = open_dev(dpy, touchdev)) == NULL) goto error;
watch(dpy, pen, touch);
/* Only get here on error conditions */