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