[comp.windows.x.motif] Simple routine to toggle cursor between watch and arrow

amc@wlv.imsd.contel.com (Allen M. Cohen) (06/19/91)

Here's a simple rountine to toggle between a watch cursor and an arrow
cursor.

/*
 *  Change cursor to either a watch or an arrow.
 *  Allen M. Cohen
 *  06/18/91
 */
#include <X11/Intrinsic.h>
#include <X11/cursorfont.h>
extern Widget toplevel;

void
  ToggleCursor(w)
Widget w;
{
  static Display     *Dsp;	/* Main display */
  static Cursor       WaitCursor; /* Watch cursor for "in-work" */
  static Cursor       ArrowCursor; /* Arrow cursor for normal mode */
  static Bool Tog = 1;
  
  
  if (Dsp == NULL)
    {
      /*
       *  Get main display
       */
      Dsp = XtDisplay(toplevel);
      
      /*
       *  Create cursors
       */
      WaitCursor = XCreateFontCursor (Dsp, XC_watch);
      ArrowCursor = XCreateFontCursor (Dsp, XC_arrow);
    }
  
  if ((Tog++) % 2)
    {
      /*
       *  Change to "watch" cursor
       */
      XDefineCursor (Dsp,
		     XtWindow(w),
		     WaitCursor);
      /*
       *  Force expose event before callbacks
       */
      XmUpdateDisplay(toplevel);
    }
  else
    {
      /*
       *  Revert to "arrow" cursor
       */
      XDefineCursor (Dsp,
		     XtWindow(w),
		     ArrowCursor);
    }
}

<> Allen M. Cohen                  Internet:  amc@wlv.imsd.contel.com       <>
<> 1853 Stonesgate St.             UUCP:      elroy.Jpl.Nasa.Gov!agi0!allen <>
<> Westlake Village, Ca. 91361     Telephone: (805) 498-9611 ext. 195       <>
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>