next up previous contents
Next: MappingMoving & Uncovering Up: Starting Up Previous: Finding out about the

Creating & Destroying Windows

Before drawing or writing on the screen each program which is using the server creates one or more windows. The windows exist in a tree structure growing down from the RootWindow which covers the whole display.

Many applications only use windows which have root as the parent. If you create a grandchild window you will find that the baby window behaves as if its parent constituted the whole physical display; all output to the baby window is clipped at the boundaries of its parent.

No window appears on the display until it is mapped, all its ancestors are mapped and an expose event has been received. Furthermore the mapping command must reach the server before anything will happen. When you map a window you must either deliberately flush all buffers (see the section on Events for details of XFlush) or draw something on the display to push your mapping command across the network. The subroutines for mapping windows are given later in this section. Creating a window alone is not sufficient to enable you to actually see anything on the display.

If you don't want to bother setting up too many things, you can create windows that inherit their attributes from their parent.

Window XCreateSimpleWindow
(display,parent, x, y, width, height, borderwidth, border,background)
    Display *display            /* The value returned by XOpenDisplay     */
    Window parent;              /* parent window i.d. probably RootWindow */
    int x, y;                   /* specify top LH corner of border        */
    unsigned int width, height; /* specify internal dimensions   */
    unsigned int border;        /* border pixel */
    unsigned long background;   /* background pixel */
For more sophisticated windows use,
Window XCreateWindow
(display,parent,x,y,width,height,border_width,depth,class,visual,valuemask,attributes)
    Window parent;                /* parent window i.d. probably RootWindow */
    int x, y;                     /* specify top LH corner of border */
    unsigned int width, height;   /* specify internal dimensions */
    unsigned int borderwidth;     /* border width */
    int depth;
    unsigned int class;           /*InputOutput,InputOnly,CopyFromParent*/
                                  /*(InputOnly windows are transparent)*/
    Visual *visual;               /*CopyFromParent, etc */
    unsigned long valuemask;      /* selects attribute fields */
    XSetWindowAttributes *attributes; /* contains the attributes */
The following structure is used when initialising windows.
typedef struct {
                                /* DEFAULT           MASK               */
Pixmap background_pixmap;       /* None              CWBackPixmap       */
unsigned long background_pixel; /* -                 CWBackPixel        */
Pixmap border_pixmap;           /* CopyFromParent    CWBorderPixmap     */
unsigned long border_pixel;     /* -                 CWBorderPixel      */
int bit_gravity;                /* ForgetGravity     CWBitGravity       */
int win_gravity;                /* NorthWestGravity  CWWinGravity       */
int backing_store;              /* NotUseful         CWBackingStore     */
unsigned long backing_planes;   /* ~0                CWBackingPlanes    */
unsigned long backing_pixel;    /* 0                 CWBackingPixel     */
Bool save_under;                /* False             CWSaveUnder        */
long event_mask;                /* 0                 CWEventMask        */
long do_not_propagate_mask;     /* 0                 CWDontPropagate    */
Bool override_redirect;         /* False             CWOverrideRedirect */
Colormap colormap;              /* CopyFromParent    CWColormap         */
Cursor cursor;                  /* None              CWCursor           */
} XSetWindowAttributes;
background_pixmap:- This lets you have a patterned background. It must have the same root and depth as the window. If None then there's no background. If ParentRelative, the parent's background is used but the parent and child must have the same depth.

border_pixmap:- This and the window must have the same root and depth (else a BadMatch error). If CopyFromParent the parent's pixmap is copied

bit_gravity:- Defines which region is retained should the window be resized.

win_gravity:- Defines how the window is re-positioned should its parent be resized.

backing_store:- WhenMapped advises the server to save the contents of the window if it's unmapped or obscured. Always advises the server that saving the contents even when unmapped would be useful. Not all servers support backing store. Use DoesBackingStore() to find out.

backing_planes:- Defines which planes will be saved.

backing_pixel:- Defines what value to put in planes not saved.

save_under:- True advises the server to save regions obscured by the window.

do_not_propagate_mask:- Defines which events should not be propagated to ancestors.

override_redirect:- If True then the window manager won't know about the window.

colormap:- This must have the same visual type as the window. If CopyFromParent the parent's colormap is copied

There are a couple of calls which can be used to destroy windows. Windows are unmapped automatically before they are destroyed.

XDestroyWindow(display,w)  /* destroy the window with the given i.d. */|

XDestroySubwindows(display,w)
    Window w;  /* destroys all the subwindows of the specified window */
               /* the window itself is not destroyed                  */
Attributes of a window are returned using the following call and structure :-
Status XGetWindowAttributes(display,w,window_attributes) 
   XWindowAttributes *window_attributes;  /* RETURN completed structure*/

typedef struct {
    int x, y;                   /* location of window */
    int width, height;          /* width and height of window */
    int border_width;           /* border width of window */
    int depth;                  /* depth of window */
    Visual *visual;             /* the associated visual structure */
    Window root;                /* root of screen containing window */
    int class;                  /* InputOutput, InputOnly*/
    int bit_gravity;            /* one of bit gravity values */
    int win_gravity;            /* one of the window gravity values */
    int backing_store;          /* NotUseful, WhenMapped, Always */
    unsigned long backing_planes;/* planes to be preserved if possible */
    unsigned long backing_pixel;/* value to be used when restoring planes */
    Bool save_under;            /* should bits under be saved? */
    Colormap colormap;          /* color map associated with window */
    Bool map_installed;         /* is color map currently installed*/
    int map_state;              /* IsUnmapped, IsUnviewable, IsViewable */
    long all_event_masks;       /* events that interest all people */   
    long your_event_mask;       /* my event mask */                    
    long do_not_propagate_mask; /* events that should not propagate */
    Bool override_redirect;     /* boolean value for override-redirect */
} XWindowAttributes;

next up previous contents
Next: MappingMoving & Uncovering Up: Starting Up Previous: Finding out about the

Tim Love
Mon Mar 11 17:03:18 GMT 1996