SHOW:
|
|
- or go back to the newest paste.
1 | - | #include <X11/Xlib.h> |
1 | + | |
2 | - | #include <stdio.h> |
2 | + | |
3 | - | #include <stdlib.h> |
3 | + | #include <X11/Xlib.h> |
4 | - | #include <string.h> |
4 | + | #include <stdio.h> |
5 | #include <stdlib.h> | |
6 | - | int main(void) { |
6 | + | #include <string.h> |
7 | - | Display *d; |
7 | + | |
8 | - | Window w, ww; |
8 | + | int main(void) { |
9 | - | XEvent e; |
9 | + | Display *d; |
10 | - | int s; |
10 | + | Window w, ww; |
11 | XEvent e; | |
12 | - | int width = 100, height = 100; |
12 | + | int s; |
13 | int i; | |
14 | - | d = XOpenDisplay(NULL); |
14 | + | |
15 | - | if (d == NULL) { |
15 | + | int width = 100, height = 100; |
16 | - | fprintf(stderr, "Cannot open display\n"); |
16 | + | |
17 | - | exit(1); |
17 | + | d = XOpenDisplay(NULL); |
18 | - | } |
18 | + | if (d == NULL) { |
19 | fprintf(stderr, "Cannot open display\n"); | |
20 | - | s = DefaultScreen(d); |
20 | + | exit(1); |
21 | - | w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 120, 120, 1, |
21 | + | } |
22 | - | WhitePixel(d, s), BlackPixel(d, s)); |
22 | + | |
23 | s = DefaultScreen(d); | |
24 | - | ww = XCreateSimpleWindow(d, w, 10, 10, width, height, 1, BlackPixel(d, s), WhitePixel(d, s)); |
24 | + | w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 120, 120, 1, |
25 | WhitePixel(d, s), BlackPixel(d, s)); | |
26 | - | XSelectInput(d, w, ExposureMask | KeyPressMask | StructureNotifyMask ); |
26 | + | |
27 | - | XSelectInput(d, ww, ExposureMask | KeyPressMask); |
27 | + | ww = XCreateSimpleWindow(d, w, 10, 10, width, height, 1, BlackPixel(d, s), WhitePixel(d, s)); |
28 | - | XMapWindow(d, w); |
28 | + | |
29 | - | XMapWindow(d, ww); |
29 | + | XSelectInput(d, w, ExposureMask | KeyPressMask | StructureNotifyMask ); |
30 | XSelectInput(d, ww, ExposureMask | KeyPressMask); | |
31 | - | while (1) { |
31 | + | XMapWindow(d, w); |
32 | - | XNextEvent(d, &e); |
32 | + | XMapWindow(d, ww); |
33 | - | if (e.type == Expose) { |
33 | + | |
34 | - | XFillRectangle(d, ww, DefaultGC(d, s), 20, 20, 10, 10); |
34 | + | while (1) { |
35 | - | XFillRectangle(d, ww, DefaultGC(d, s), width-30, height-30, 10, 10); |
35 | + | XNextEvent(d, &e); |
36 | - | XFillRectangle(d, ww, DefaultGC(d, s), 20, height-30, 10, 10); |
36 | + | if (e.type == Expose) { |
37 | - | XFillRectangle(d, ww, DefaultGC(d, s), width-30, 20, 10, 10); |
37 | + | for (i=0;i<1000;i++) { |
38 | - | } |
38 | + | XFillRectangle(d, ww, DefaultGC(d, s), 20, 20, 10, 10); |
39 | - | if (e.type == KeyPress) |
39 | + | XFillRectangle(d, ww, DefaultGC(d, s), width-30, height-30, 10, 10); |
40 | - | break; |
40 | + | XFillRectangle(d, ww, DefaultGC(d, s), 20, height-30, 10, 10); |
41 | XFillRectangle(d, ww, DefaultGC(d, s), width-30, 20, 10, 10); | |
42 | - | if (e.type == ConfigureNotify) { |
42 | + | } |
43 | - | width = e.xconfigure.width - 20; |
43 | + | } |
44 | - | if (width < 100) width = 100; |
44 | + | if (e.type == KeyPress) |
45 | - | height = e.xconfigure.height - 20; |
45 | + | break; |
46 | - | if (height < 100) height = 100; |
46 | + | |
47 | - | XMoveResizeWindow (d, ww, 10, 10, width, height); |
47 | + | if (e.type == ConfigureNotify) { |
48 | - | } |
48 | + | width = e.xconfigure.width - 20; |
49 | - | } |
49 | + | if (width < 100) width = 100; |
50 | height = e.xconfigure.height - 20; | |
51 | - | XCloseDisplay(d); |
51 | + | if (height < 100) height = 100; |
52 | - | return 0; |
52 | + | XMoveResizeWindow (d, ww, 10, 10, width, height); |
53 | - | } |
53 | + | } |
54 | } | |
55 | ||
56 | XCloseDisplay(d); | |
57 | return 0; | |
58 | } |