home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / auto_box / init_win.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-14  |  2.8 KB  |  89 lines

  1. /* $XConsortium: init_win.c,v 5.2 91/04/14 11:14:21 rws Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Sun Microsystems,
  13. the X Consortium, and MIT not be used in advertising or publicity 
  14. pertaining to distribution of the software without specific, written 
  15. prior permission.  
  16.  
  17. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  19. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  20. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. #include <stdio.h>
  28. #include <errno.h>
  29. #include <X11/Xlib.h>
  30. #include <X11/Xatom.h>
  31.  
  32. #define    WIN_X    200
  33. #define    WIN_Y      200
  34. #define    WIN_W      400
  35. #define    WIN_H      400
  36.  
  37. #define    CONNECT_TO_DISPLAY(name) \
  38.     if (!(appl_display = XOpenDisplay(name))) { \
  39.         perror( "Cannot open display\n"); \
  40.         exit(-1); \
  41.     } 
  42.  
  43. Display *appl_display;
  44. Window appl_window;
  45.  
  46. void init_window();
  47.  
  48. void
  49. init_window()
  50. {
  51.     XSetWindowAttributes xswa;
  52.     Colormap map;
  53.     unsigned int bw = 1;
  54.     char *display_name = NULL;
  55.     int bg_pix, bd_pix;
  56.     Visual visual;
  57.     XEvent exposureEvent;
  58.  
  59.     CONNECT_TO_DISPLAY(display_name);
  60.  
  61.     map = XDefaultColormap(appl_display, DefaultScreen(appl_display));
  62.              
  63.     bg_pix = BlackPixel(appl_display, DefaultScreen(appl_display));
  64.     bd_pix = WhitePixel(appl_display, DefaultScreen(appl_display));
  65.                           
  66.     xswa.backing_store = NotUseful;
  67.     xswa.event_mask = ExposureMask | StructureNotifyMask;
  68.     xswa.background_pixel = bg_pix;
  69.     xswa.border_pixel = bd_pix;
  70.     visual.visualid = CopyFromParent;
  71.     appl_window = XCreateWindow(appl_display,
  72.         RootWindow(appl_display, DefaultScreen(appl_display)),
  73.         WIN_X, WIN_Y, WIN_W, WIN_H, bw,
  74.         DefaultDepth(appl_display, DefaultScreen(appl_display)),
  75.         InputOutput, &visual,
  76.         CWEventMask | CWBackingStore | CWBorderPixel | CWBackPixel,
  77.         &xswa);
  78.  
  79.     XChangeProperty(appl_display,
  80.         appl_window, XA_WM_NAME, XA_STRING, 8,
  81.         PropModeReplace, (unsigned char *)"AutoBox", 5);
  82.     XMapWindow(appl_display, appl_window);
  83.                          
  84.     /** sync and wait for exposure event **/
  85.     XSync(appl_display, 0);
  86.     XWindowEvent(appl_display,
  87.         appl_window, ExposureMask, &exposureEvent);
  88. }
  89.