Department of Engineering

IT Services

Working with other clients and Window Managers

X11 release 4 included routines to implement The Inter-Client Communications Conventions which allow clients to cooperate in the areas of selections, cut buffers, window management, session management, and resources. See the online XR5demo.c program for details. This chapter covers enough for most needs.

You can suggest to the window manager how it should display and handle your application. The window manager is at liberty to ignore the suggestions. These properties can be set individually or en masse.

Naming windows and defining icons

XStoreName(display,w, name) /* assign a name to a window */
    char *name;          /* name: a null-terminated string      */

Status XFetchName(display,w, name) /* find a window's name */
    char **name;         /* RETURN a pointer to the name array  */

XSetIconName(display,w,icon_name) /* set name used on icon */
    icon_name *char;

Status XGetIconName(display,w,icon_name) /* get name used on icon */
    icon_name **char;   /*RETURN*/

To set groups of properties there are 2 structures:-

typedef struct{
long flags; /*InputHint,StateHint,IconPixmapHint,IconWindowHint,
            IconPositionHint,IconMaskHint, WindowGroupHint, AllHints */
Bool input;           /* does this application rely on the window manager
                         to get keyboard input ? */
int initial_state; /*NormalState,ZoomState,IconicState,InactiveState,DontCareState*/
Pixmap icon_pixmap;
Window icon_window;   /* window to be used as icon */
int icon_x, icon_y;   /*initial icon position*/
Pixmap icon_mask;
XID window_group;     /* windows can be grouped so that, for example,
                         they could all be de-iconified at once */
} XWMHints;

typedef struct {
  long flags;    /* which fields are defined. Possibilities are
                 USPosition, USSize, PPosition, Psize, PMinSize
                 PMaxSize, PResizeInc, PAspect, PAllHints */
  int x,y;
  int width, height;
  int min_width, max_width;
  int min_height, max_height;
  int width_inc, height_inc;
  struct {
         int x; /* numerator   */
         int y; /* demoninator */
  } min_aspect, max_aspect;
} XSizeHints;

Control over the step size of the increment is useful if, say, you want to allow change of a text window by units of a character cell.

These structures are used in these routines:-

void XSetNormalHints(display, w, hints)
     Display *display;
     Window  w;
     XSizeHints *hints;

void XGetNormalHints(display, w, hints)
     Display *display;
     Window  w;
     XSizeHints *hints;  /* RETURNED*/

XSetStandardProperties(display,w,window_name,icon_name,
                icon_pixmap,argv,argc,hints)
char *window_name, *icon_name;
Pixmap icon_pixmap;
char **argv;             /* the command line to start the application*/   
int  argc;               
XSizeHints *hints;

XSetWMHints(display,w,wmhints)
XWMHints *wmhints;

XWMHints *XGetWMHints(display,w,wmhints)
XWMHints *wmhints;

If you set maximum size, minimum size and original size to be all the same, and the window manager takes your hints, then your window will be of fixed size.

Property Lists

Extra information can be associated with windows. This information can be accessed by all clients using the server. Each property has a name and a unique ID called an Atom. Properties have types which are also indicated using Atoms (eg XA_STRING, XA_PIXMAP). The Atoms for some common properties are predefined in <X11/Xatom.h>. To create an Atom with a name, use

Atom XInternAtom(display,atom_name,only_if_exists)
   char *atom_name;
   int only_if_exists;/*If False then a new atom will be created if necessary;
                        if True, and there is no corresponding atom then None 
                        is returned */

The inverse of this is,

char *XGetAtomName(display,atom)

To obtain the atom type and property format, use

int GetWindowProperty(display,w,property,long_offset,long_length,delete,
            req_type,actual_type,actual_format,nitems,bytes_after,prop);
   Atom property;
   long long_offset,long_length; /* the length and offset of data to be   
                                 received, in 32-bit quantities     */ 
   Bool delete;            /*if True then the property is deleted   */      
   Atom req_type;          /*AnyPropertyType, etc */               
   Atom *actual_type;      /*RETURN*/                              
   int *actual_format;     /*RETURN data type of returned data*/   
   unsigned long *nitems;  /*RETURN*/                              
   long *bytes_after;      /*RETURN number of bytes left unread */ 
   unsigned char **prop;   /*RETURN*/                              
Possible return values are None, Success, BadWindow, BadMatch

Atom *XListProperties(display,w,num_prop)
   int *num_prop;  /*RETURN*/

XChangeProperty(display,w,property,type,format,mode,data,nelements)
   Atom property,type;         
   int format;   /*8,16 or 32*/
   int mode;     /* PropModeReplace, PropModePrePend, PropModeAppend*/ 
   unsigned char *data;        
   int nelements;              

XRotateWindowProperties(display,w,properties,num_props,npositions)
Atom properties[];         

XDeleteProperty(display,w,property)