| 1 | #include "xdemo.h"
|
|---|
| 2 |
|
|---|
| 3 | void init_x () {
|
|---|
| 4 |
|
|---|
| 5 | dis = XOpenDisplay ( NULL );
|
|---|
| 6 | if ( dis == NULL)
|
|---|
| 7 | {
|
|---|
| 8 | fprintf ( stderr , "Display: connection impossible\n");
|
|---|
| 9 | exit (1);
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | screen = DefaultScreen ( dis );
|
|---|
| 13 | depth = DefaultDepth ( dis , screen );
|
|---|
| 14 | width = DisplayWidth ( dis , screen );
|
|---|
| 15 | height = DisplayHeight ( dis , screen );
|
|---|
| 16 |
|
|---|
| 17 | if ( depth != 24 )
|
|---|
| 18 | {
|
|---|
| 19 | fprintf ( stderr , "This code works only in 24 bpp..\n" );
|
|---|
| 20 | XCloseDisplay ( dis );
|
|---|
| 21 | exit (1);
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | winRoot = DefaultRootWindow ( dis );
|
|---|
| 25 | winAttr.border_pixel = BlackPixel ( dis , screen );
|
|---|
| 26 | winAttr.background_pixel = BlackPixel ( dis , screen );
|
|---|
| 27 | winMask = CWBackPixel | CWBorderPixel;
|
|---|
| 28 |
|
|---|
| 29 | win = XCreateWindow ( dis , winRoot , X , Y , W , H , BORDER , depth ,
|
|---|
| 30 | InputOutput , CopyFromParent , winMask , &winAttr );
|
|---|
| 31 |
|
|---|
| 32 | XStoreName ( dis , win , NAME );
|
|---|
| 33 |
|
|---|
| 34 | XSelectInput ( dis , win , KeyPressMask );
|
|---|
| 35 |
|
|---|
| 36 | winHint.flags = PPosition | PMinSize | PMaxSize ;
|
|---|
| 37 | winHint.x = X;
|
|---|
| 38 | winHint.y = Y;
|
|---|
| 39 | winHint.max_width = winHint.min_width = W;
|
|---|
| 40 | winHint.max_height = winHint.min_height = H;
|
|---|
| 41 | XSetWMNormalHints ( dis , win , &winHint );
|
|---|
| 42 |
|
|---|
| 43 | XClearWindow ( dis , win );
|
|---|
| 44 | XMapRaised ( dis , win );
|
|---|
| 45 | XFlush ( dis );
|
|---|
| 46 |
|
|---|
| 47 | buffer = ( char * ) malloc ( 4*W*H );
|
|---|
| 48 | xim = XCreateImage ( dis , CopyFromParent , depth , ZPixmap , 0 ,
|
|---|
| 49 | buffer , W , H , 32 , W*4 );
|
|---|
| 50 |
|
|---|
| 51 | gcVal.foreground = 0;
|
|---|
| 52 | gcVal.background = 0;
|
|---|
| 53 | gcMask = GCForeground | GCBackground;
|
|---|
| 54 |
|
|---|
| 55 | gc = XCreateGC ( dis , win , gcMask , &gcVal );
|
|---|
| 56 |
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | int event_x () {
|
|---|
| 61 |
|
|---|
| 62 | XEvent XEv;
|
|---|
| 63 |
|
|---|
| 64 | return ( ! XCheckWindowEvent ( dis , win , KeyPressMask , &XEv ) );
|
|---|
| 65 |
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | void close_x () {
|
|---|
| 70 |
|
|---|
| 71 | XFreeGC ( dis , gc );
|
|---|
| 72 | XDestroyImage ( xim );
|
|---|
| 73 | XDestroyWindow ( dis , win );
|
|---|
| 74 | XCloseDisplay ( dis );
|
|---|
| 75 |
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|