wmail: skip leading white-space in From: headers.
[dockapps.git] / wmfu / extra / xhooktst.c
blob5914b6df9cecddbd7a4a34fbe35bc30f7d33abad
1 /*
2 * Copyright (c) 2007 Daniel Borca All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <stdio.h>
21 #include <signal.h>
22 #include <stdlib.h>
23 #include <X11/Xlib.h>
25 #include "xhookey.h"
28 static void
29 test_keys (Display *dpy, int num, KTUPLE keys[])
31 int quit = 0;
33 #if XHK_SIGFORK
34 void (*old_sig_handler) (int) = signal(SIGCHLD, xhk_sig_handler);
35 #endif
36 #if XHK_XERROR
37 XErrorHandler old_eks_handler = XSetErrorHandler(xhk_eks_handler);
38 #endif
39 while (!quit) {
40 XEvent evt;
41 XNextEvent(dpy, &evt);
42 xhk_run(dpy, &evt, num, keys);
44 #if XHK_XERROR
45 XSetErrorHandler(old_eks_handler);
46 #endif
47 #if XHK_SIGFORK
48 signal(SIGCHLD, old_sig_handler);
49 #endif
53 int
54 main (int argc, char **argv)
56 int rv;
58 int n;
59 KTUPLE *keys;
61 Display *display;
63 display = XOpenDisplay(NULL);
64 if (display == NULL) {
65 fprintf(stderr, "cannot open display\n");
66 goto err_0;
69 n = xhk_parse(argc, argv, &keys);
70 if (n <= 0) {
71 fprintf(stderr, "no keys\n");
72 goto err_1;
75 rv = xhk_grab(display, n, keys);
76 if (rv < 0) {
77 printf("cannot grab keys\n");
78 goto err_2;
81 test_keys(display, n, keys);
83 xhk_ungrab(display);
85 free(keys);
87 XCloseDisplay(display);
89 return 0;
91 err_2:
92 free(keys);
93 err_1:
94 XCloseDisplay(display);
95 err_0:
96 return -1;