diff --git a/README.md b/README.md index 8a423e0..7109eb1 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Part 1: uinput driver On your PC, either download one of these binaries (don't forget to `chmod a+x` it): -* [uinput-networktablet 64-bit, dynamically linked, tested with Fedora 18 and Ubuntu 12.10](https://github.com/rfc2822/GfxTablet/blob/binaries/uinput-networktablet-x86_64?raw=true) +* [networktablet 64-bit, dynamically linked, tested with Fedora 18 and Ubuntu 12.10](https://github.com/rfc2822/GfxTablet/blob/binaries/networktablet-x86_64?raw=true) or compile it yourself (don't be afraid, it's only one file) @@ -90,12 +90,13 @@ uinput access, you'll need to do it yourself or just run the driver as root: `sudo ./networktablet` -Then, `xinput list` should show a "Network Tablet" device. +Then you should see a status message saying the driver is ready. If you do `xinput list` in a separate +terminal, should show a "Network Tablet" device. You can start and stop (Ctrl+C) the Network Tablet at any time, but please be aware that applications which use the device may be confused by that and could crash. -`networktablet` will display a dot for every touch/motion event it receives. +`networktablet` will display a status line for every touch/motion event it receives. Part 2: App diff --git a/driver-uinput/networktablet.c b/driver-uinput/networktablet.c index 946f4b3..e7cde9c 100644 --- a/driver-uinput/networktablet.c +++ b/driver-uinput/networktablet.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,9 @@ } +int udp_socket; + + void init_device(int fd) { struct uinput_user_dev uidev; @@ -85,19 +89,29 @@ void send_event(int device, int type, int code, int value) error("error: write()"); } +void quit(int signal) { + close(udp_socket); +} + int main(void) { - int device, socket; + int device; struct event_packet ev_pkt; if ((device = open("/dev/uinput", O_WRONLY | O_NONBLOCK)) < 0) die("error: open"); init_device(device); - socket = prepare_socket(); + udp_socket = prepare_socket(); - while (recv(socket, &ev_pkt, sizeof(ev_pkt), 0) >= 9) { // every packet has at least 9 bytes + printf("GfxTablet driver (protocol version %u) is ready and listening on 0.0.0.0:%u (UDP)\n" + "Hint: Make sure that this port is not blocked by your firewall.\n", PROTOCOL_VERSION, GFXTABLET_PORT); + + signal(SIGINT, quit); + signal(SIGTERM, quit); + + while (recv(udp_socket, &ev_pkt, sizeof(ev_pkt), 0) >= 9) { // every packet has at least 9 bytes printf("."); fflush(0); if (memcmp(ev_pkt.signature, "GfxTablet", 9) != 0) { @@ -132,10 +146,12 @@ int main(void) } } + close(udp_socket); - close(socket); - + printf("Removing network tablet from device list\n"); ioctl(device, UI_DEV_DESTROY); close(device); + + printf("GfxTablet driver shut down gracefully\n"); return 0; }