author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:00 +0100 | |
changeset 8 | 96d16dfe787a |
parent 4 | 236f8f747073 |
child 9 | c3fecc82ade6 |
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: |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
4
diff
changeset
|
43 |
if (xev.xkey.keycode == 9) |
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
4
diff
changeset
|
44 |
active = 0; |
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
4
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); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
4
diff
changeset
|
54 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
4
diff
changeset
|
55 |
return EXIT_SUCCESS; |
0 | 56 |
} |