home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / test / shapetest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-24  |  2.8 KB  |  103 lines

  1. /************************************************************
  2. Copyright 1989 by the Massachusetts Institute of Technology
  3.  
  4. Permission  to  use,  copy,  modify,  and  distribute   this
  5. software  and  its documentation for any purpose and without
  6. fee is hereby granted, provided that the above copyright no-
  7. tice  appear  in all copies and that both that copyright no-
  8. tice and this permission notice appear in  supporting  docu-
  9. mentation,  and  that  the name of MIT not be used in adver-
  10. tising  or publicity pertaining to distribution of the soft-
  11. ware without specific prior written permission. M.I.T. makes
  12. no representation about the suitability of this software for
  13. any  purpose.  It is provided "as is" without any express or
  14. implied warranty.
  15.  
  16. ********************************************************/
  17.  
  18. /* $XConsortium: shapetest.c,v 1.4 91/01/24 15:14:58 gildea Exp $ */
  19. #include <stdio.h>
  20. #include <X11/Xlib.h>
  21. #include <X11/Xatom.h>
  22. #include <X11/Xproto.h>
  23. #include <X11/Xutil.h>
  24. #include <X11/extensions/shape.h>
  25.  
  26. Display *dpy;
  27.  
  28. StartConnectionToServer(argc, argv)
  29. int     argc;
  30. char    *argv[];
  31. {
  32.     char *display;
  33.  
  34.     display = NULL;
  35.     for(--argc, ++argv; argc; --argc, ++argv)
  36.     {
  37.     if ((*argv)[0] == '-') {
  38.         switch((*argv)[1]) {
  39.         case 'd':
  40.         display = argv[1];
  41.         ++argv; --argc;
  42.         break;
  43.         }
  44.     }
  45.     }
  46.     if (!(dpy = XOpenDisplay(display)))
  47.     {
  48.        perror("Cannot open display\n");
  49.        exit(0);
  50.    }
  51. }
  52.  
  53. XRectangle  rects[] = { 0,0, 100, 100, 10, 10, 100, 100 };
  54.  
  55. main(argc, argv)
  56.     int argc;
  57.     char **argv;
  58.  
  59. {
  60.     Window  w;
  61.     GC gc;
  62.     char *windowName = "Test of Shape Extension";
  63.     XSetWindowAttributes xswa;
  64.     unsigned long    mask;
  65.     XEvent pe;
  66.     XColor screen_def_blue, exact_def_blue;
  67.     XColor screen_def_red, exact_def_red;
  68.  
  69.     /*_Xdebug = 1;*/   /* turn on synchronization */
  70.  
  71.     StartConnectionToServer(argc, argv);
  72.  
  73.     xswa.event_mask = ExposureMask;
  74.     xswa.background_pixel = BlackPixel (dpy, DefaultScreen (dpy));
  75.     mask = CWEventMask | CWBackPixel;
  76.     w = XCreateWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)),
  77.         100, 100, 340, 340, 0, 
  78.         CopyFromParent, CopyFromParent,    CopyFromParent,
  79.         mask, &xswa);
  80.  
  81.     XChangeProperty(dpy,
  82.         w, XA_WM_NAME, XA_STRING, 8, PropModeReplace,
  83.         (unsigned char *)windowName, strlen(windowName));
  84.  
  85.     XShapeCombineRectangles (dpy, w, ShapeBounding, 0, 0, 
  86.                   rects, sizeof (rects) / sizeof (rects[0]),
  87.               ShapeSet, Unsorted);
  88.  
  89.     XMapWindow(dpy, w);
  90.  
  91.     gc = XCreateGC(dpy, w, 0, 0);
  92.     XAllocNamedColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)), "blue",
  93.            &screen_def_blue,  &exact_def_blue);
  94.     XAllocNamedColor(dpy, DefaultColormap(dpy, DefaultScreen(dpy)), "red",
  95.            &screen_def_red,  &exact_def_red);
  96.     XSetForeground(dpy, gc, screen_def_red.pixel);
  97.     XSetBackground(dpy, gc, screen_def_blue.pixel);
  98.  
  99.     while (1) {
  100.         XNextEvent(dpy, &pe);
  101.     }
  102. }
  103.