Index: trunk/Ohana/src/kapa2/Makefile
===================================================================
--- trunk/Ohana/src/kapa2/Makefile	(revision 13332)
+++ trunk/Ohana/src/kapa2/Makefile	(revision 13333)
@@ -52,5 +52,4 @@
 $(SRC)/SetSection.$(ARCH).o		  $(SRC)/DefineSection.$(ARCH).o      \
 $(SRC)/SetLimits.$(ARCH).o                $(SRC)/SetFont.$(ARCH).o            \
-$(SRC)/cursor.$(ARCH).o                   $(SRC)/Stop.$(ARCH).o               \
 $(SRC)/Center.$(ARCH).o                   $(SRC)/Remap.$(ARCH).o              \
 $(SRC)/Remap8.$(ARCH).o                   $(SRC)/Remap16.$(ARCH).o            \
@@ -76,5 +75,5 @@
 $(SRC)/UpdatePointer.$(ARCH).o            $(SRC)/JPEGit24.$(ARCH).o           \
 $(SRC)/bDrawOverlay.$(ARCH).o             $(SRC)/ButtonFunctions.$(ARCH).o    \
-$(SRC)/PSimage.$(ARCH).o                  $(SRC)/PSPixmap.$(ARCH).o    \
+$(SRC)/PSimage.$(ARCH).o                  $(SRC)/PSPixmap.$(ARCH).o           \
 $(SRC)/PSOverlay.$(ARCH).o
 
Index: trunk/Ohana/src/kapa2/include/globals.h
===================================================================
--- trunk/Ohana/src/kapa2/include/globals.h	(revision 13332)
+++ trunk/Ohana/src/kapa2/include/globals.h	(revision 13333)
@@ -1,8 +1,9 @@
 
-int HAVE_BACKING;
-int DEBUG;
-int USE_XWINDOW;
-int MAP_WINDOW;
-int FOREGROUND;
+int   ACTIVE_CURSOR;
+int   HAVE_BACKING;
+int   DEBUG;
+int   USE_XWINDOW;
+int   MAP_WINDOW;
+int   FOREGROUND;
 char *NAME_WINDOW;
 
Index: trunk/Ohana/src/kapa2/include/prototypes.h
===================================================================
--- trunk/Ohana/src/kapa2/include/prototypes.h	(revision 13332)
+++ trunk/Ohana/src/kapa2/include/prototypes.h	(revision 13333)
@@ -59,5 +59,4 @@
 int           DefineSection       PROTO(());
 int           SetFont             PROTO(());
-int           cursor              PROTO(());
 int           EraseCurrentPlot    PROTO(());
 int           ErasePlots          PROTO(());
Index: trunk/Ohana/src/kapa2/src/CheckPipe.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CheckPipe.c	(revision 13332)
+++ trunk/Ohana/src/kapa2/src/CheckPipe.c	(revision 13333)
@@ -30,5 +30,19 @@
   
   /***** handle different messages ****/
+  if (ACTIVE_CURSOR) {
+    if (strcmp (buffer, "NCUR")) {
+      fprintf (stderr, "wrong end message %s\n", buffer);
+      return (TRUE);
+    }
+    ACTIVE_CURSOR = FALSE;
+    return (TRUE);
+  } 
+
   if (!strcmp (buffer, "QUIT")) return (FALSE);
+  
+  if (!strcmp (buffer, "CURS")) {
+    ACTIVE_CURSOR = TRUE;
+    return (TRUE);
+  }
   
   if (!strcmp (buffer, "PSIT")) {
@@ -105,10 +119,4 @@
   }
   
-  // XXX replace this with the "ActiveCursor" boolean?
-  if (!strcmp (buffer, "CURS")) {
-    cursor ();
-    return (TRUE);
-  }
-  
   /* Erase Section */
   if (!strcmp (buffer, "ERSC")) {
Index: trunk/Ohana/src/kapa2/src/InterpretKeys.c
===================================================================
--- trunk/Ohana/src/kapa2/src/InterpretKeys.c	(revision 13332)
+++ trunk/Ohana/src/kapa2/src/InterpretKeys.c	(revision 13333)
@@ -1,23 +1,62 @@
 # include "Ximage.h"
 
-int InterpretKeys (Graphic *graphic, XEvent *event) {
+int InterpretKeys (Graphic *graphic, XKeyEvent *event) {
 
-  double X, Y, offset;
-  int    modstate;
-  char   string[10];
-  KeySym keysym;
-  XComposeStatus  composestatus;
-  XKeyEvent *keyevent;
-  Section *section;
+  double 	   X, Y, offset;
+  int    	   modstate;
+  char   	  *name, string[16], line[40];
+  KeySym           keysym;
+  XComposeStatus   composestatus;
+  Section         *section;
   KapaImageWidget *image;
+  KapaGraphWidget *graph;
 
   // XXX select the window element which contains the event
   section = GetActiveSection();
   image   = section->image;
+  graph   = section->graph;
 
-  keyevent = (XKeyEvent *) event;
-  XLookupString (keyevent, string, 9, &keysym, &composestatus);
-  modstate = keyevent[0].state;
+  XLookupString (event, string, 9, &keysym, &composestatus);
+  modstate = event[0].state;
 
+  // return graph coords by default, image if graph does not exist
+  // XXX allow user to choose graph or image coords
+  if (ACTIVE_CURSOR) {
+    name = XKeysymToString (keysym);
+
+    // skip the following keys: 
+    if (name == NULL) goto skip_cursor;
+    if (!strcmp (name, "Shift_L")) goto skip_cursor;
+    if (!strcmp (name, "Shift_R")) goto skip_cursor;
+    if (!strcmp (name, "Control_L")) goto skip_cursor;
+    if (!strcmp (name, "Control_R")) goto skip_cursor;
+    if (!strcmp (name, "Alt_L")) goto skip_cursor;
+    if (!strcmp (name, "Alt_R")) goto skip_cursor;
+    if (!strcmp (name, "Super_L")) goto skip_cursor;
+    if (!strcmp (name, "Super_R")) goto skip_cursor;
+    if (!strcmp (name, "Caps_Lock")) goto skip_cursor;
+    if (!strcmp (name, "Pause")) goto skip_cursor;
+    if (!strcmp (name, "Continue")) goto skip_cursor;
+    if (!strcmp (name, "Num_Lock")) goto skip_cursor;
+    if (!strcmp (name, "Scroll_Lock")) goto skip_cursor;
+    if (!strcmp (name, "Print")) goto skip_cursor;
+    if (!strcmp (name, "(null)")) goto skip_cursor;
+
+    if (graph) {
+      X = (event[0].x - graph[0].axis[0].fx)*(graph[0].axis[0].max - graph[0].axis[0].min)/graph[0].axis[0].dfx + graph[0].axis[0].min;
+      Y = (event[0].y - graph[0].axis[1].fy)*(graph[0].axis[1].max - graph[0].axis[1].min)/graph[0].axis[1].dfy + graph[0].axis[1].min;
+    } 
+    if (image && !graph) {
+      if (event[0].x < image[0].picture.x) goto skip_cursor;
+      if (event[0].y < image[0].picture.y) goto skip_cursor;
+      if (event[0].x > image[0].picture.x + image[0].picture.dx) goto skip_cursor;
+      if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
+      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
+    }
+    snprintf (line, 40, "%12s %12.6f %12.6f ", name, X, Y);
+    write (sock, line, 40);
+  }
+
+skip_cursor:
   // offset is in image pixels: 
   // 0.5 image pixels is 1 screen pixel for expand == +2
@@ -42,5 +81,5 @@
     case XK_KP_Begin:
     case XK_Return:
-      Screen_to_Image (&X, &Y, (double)keyevent[0].x, (double)keyevent[0].y, image);
+      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
       X = 0.5*image[0].matrix.Naxis[0] - X;
       Y = 0.5*image[0].matrix.Naxis[1] - Y;
Index: trunk/Ohana/src/kapa2/src/InterpretPresses.c
===================================================================
--- trunk/Ohana/src/kapa2/src/InterpretPresses.c	(revision 13332)
+++ trunk/Ohana/src/kapa2/src/InterpretPresses.c	(revision 13333)
@@ -3,14 +3,39 @@
 int InterpretPresses (Graphic *graphic, XButtonEvent *event) {
 
-  int             status, done, this_button, x, y, old_cursor;
-  KeySym          keysym;
-  Button         *button;
-  Section *section;
+  int              status, done, this_button, old_cursor;
+  char             name[16], line[40];
+  double           X, Y;
+  KeySym           keysym;
+  Button          *button;
+  Section         *section;
   KapaImageWidget *image;
+  KapaGraphWidget *graph;
 
   // XXX select the window element which contains the event
   section = GetActiveSection();
   image   = section->image;
+  graph   = section->graph;
 
+  // return graph coords by default, image if graph does not exist
+  // XXX allow user to choose graph or image coords
+  if (ACTIVE_CURSOR) {
+    sprintf (name, "Button%d", event[0].button);
+    if (graph) {
+      X = (event[0].x - graph[0].axis[0].fx)*(graph[0].axis[0].max - graph[0].axis[0].min)/graph[0].axis[0].dfx + graph[0].axis[0].min;
+      Y = (event[0].y - graph[0].axis[1].fy)*(graph[0].axis[1].max - graph[0].axis[1].min)/graph[0].axis[1].dfy + graph[0].axis[1].min;
+    } 
+    if (image && !graph) {
+      if (event[0].x < image[0].picture.x) goto skip_cursor;
+      if (event[0].y < image[0].picture.y) goto skip_cursor;
+      if (event[0].x > image[0].picture.x + image[0].picture.dx) goto skip_cursor;
+      if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
+	
+      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
+    }
+    snprintf (line, 40, "%12s %12.6f %12.6f ", name, X, Y);
+    write (sock, line, 40);
+  }
+
+skip_cursor:
   status = TRUE;
   this_button = event[0].button;
Index: trunk/Ohana/src/kapa2/src/Layout.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Layout.c	(revision 13332)
+++ trunk/Ohana/src/kapa2/src/Layout.c	(revision 13333)
@@ -21,4 +21,6 @@
     sock = KiiWait (argv[1]);
   }
+
+  ACTIVE_CURSOR = FALSE;
 
   /* get the display colors */
