author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:57:56 +0100 | |
changeset 4 | 236f8f747073 |
parent 0 | af501b0c1716 |
child 8 | 96d16dfe787a |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* $Id: xdemo.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $ |
|
3 |
* $Source: /development/c/demos/xdemo.c,v $ |
|
4 |
* |
|
5 |
*/ |
|
6 |
||
7 |
#include <stdio.h> |
|
8 |
#include <stdlib.h> |
|
9 |
#include <X11/Xlib.h> |
|
10 |
||
11 |
int main (int argc, char **argv) |
|
12 |
{ |
|
13 |
Window w = 0; |
|
14 |
Display *dpy = XOpenDisplay (NULL); |
|
15 |
XEvent xev; |
|
16 |
int active; |
|
17 |
||
18 |
if (dpy == NULL) { |
|
19 |
printf ("Error opening localhost:0\n"); |
|
20 |
return EXIT_SUCCESS; |
|
21 |
} |
|
22 |
||
23 |
XSynchronize (dpy, 1); |
|
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
24 |
w = XCreateSimpleWindow (dpy, DefaultRootWindow (dpy), 0, 0, 240, 60, 1, 1, 1); |
0 | 25 |
|
26 |
if (w < 0) |
|
27 |
return EXIT_SUCCESS; |
|
28 |
||
29 |
printf ("WINDOW-ID: %ld\n", w); |
|
30 |
||
31 |
XRaiseWindow (dpy, w); |
|
32 |
XMapWindow (dpy, w); |
|
33 |
||
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
34 |
printf ("Press ESC to quit\n"); |
0 | 35 |
|
36 |
active = 1; |
|
37 |
XSelectInput (dpy, w, KeyPressMask); |
|
38 |
||
39 |
while (active) { |
|
40 |
XNextEvent (dpy, &xev); |
|
41 |
switch (xev.type) { |
|
42 |
case KeyPress: |
|
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
43 |
if(xev.xkey.keycode == 9) |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
44 |
active = 0; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
45 |
printf("Keycode = %2u\n", xev.xkey.keycode); |
0 | 46 |
break; |
47 |
default: |
|
48 |
printf ("Unknown Event: %d\n", xev.type); |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
XDestroyWindow (dpy, w); |
|
53 |
XCloseDisplay (dpy); |
|
54 |
return 0; |
|
55 |
} |