Sample X Window Application

xsample 
screen capture

Source code for xsample.

Compiling xsample

  gcc -o xsample xsample.c -L/usr/X11R6/lib -lXaw -lXmu -lXt -lXext -lX11

C-Shell alias I use to compile small X applications

  alias cxt '/usr/bin/gcc -Wall -ansi -pedantic -o \
  `/bin/basename \!* .c` \!* -L/usr/X11R6/lib      \
  -lXaw -lXmu -lXt -lXext -lX11'

 

Customizing xsample

Use /usr/X11R6/bin/editres to find customizable resources.

 

Widget Tree

widget tree 
screen capture

 

Resources

resources 
screen capture

 

X Application Customization Methods

X applications can be customized by the following listed in order of precedence. All source code examples are taken from the xsample application shown above.

  1. Hardcoded in the X application
      Arg arglist[] = { XtNwidth, 180,
                        XtNbackground, (XtArgVal)"red",
                        XtNlabel, (XtArgVal)"HardCoded Resource" };
    
      XtSetValues( (Widget)client_data, arglist, XtNumber( arglist ) );
    
      /* Create widget */
      quitButton = XtVaCreateManagedWidget(
        "quitButton",
        commandWidgetClass,
        container,
        XtNwidth, 180,                      /* hard coded X resource	*/
        NULL );
    
  2. Passed in from the command line.
      /home/matthew> xterm -bg yellow -fg "blue"
      /home/matthew> xsample -xrm ".xsample.*font: fixed"
    
  3. Taken from the X server resource database
    (if any values exist in this database the entire ~/.Xdefaults file is ignored)
      /home/matthew> echo "xsample.*font: fixed" | xrdb -merge
    
                                - or -
    
      /home/matthew> xrdb -merge < xsampleResourceFile
      /home/matthew> xsample
    
  4. Taken from the ~/.Xdefaults file
      /home/matthew> cat ~/.Xdefaults
      #ifdef COLOR
      *customization: -color
      #endif
      .xsample.*font: lucidasans-italic-24
      /home/matthew> xsample
    
  5. Taken from the system wide application defaults file
      /home/matthew> cat /usr/X11R6/lib/X11/app-defaults/XSample
      .xsample.container.quitButton.label: Quit
      .xsample.*font: lucidasans-italic-24
      /home/matthew> xsample
    
  6. From the applications fallback resources
      static String fallbackResources[] = {
        ".xsample.*font: lucidasans-bold-12",
        NULL };
    
      /* Initialize the toolkit */
      topwidget = XtVaAppInitialize(
        &appcontext,                        /* application context          */
        "XSample",                          /* application class            */
        NULL, 0,                            /* command line option list     */
        &argc, argv,                        /* command line arguments       */
        fallbackResources,                  /* fallback resource settings   */
        NULL );                             /* terminate varags list        */
    

 


Last Modified: 14 June 1997

St. Louis Unix Users Group - Linux SIG