IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5349


Ignore:
Timestamp:
Oct 15, 2005, 2:41:53 PM (21 years ago)
Author:
eugene
Message:

cursor now returns a string for key

Location:
trunk/Ohana/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa/graph/cursor.c

    r4769 r5349  
    11# include "Ximage.h"
    2 # define EventMask (long) (KeyPressMask | ExposureMask | StructureNotifyMask)
     2# define EventMask (long) (KeyPressMask | ExposureMask | StructureNotifyMask | ButtonPressMask)
    33
    44int cursor () {
     
    88  int             status, value;
    99  XComposeStatus  composestatus;
    10   char            string[10], line[35];
     10  char            string[10], line[40], *name;
    1111  double          x, y;
    1212  char            buffer[10];
    1313  Layout         *layout;
    14  
     14  XButtonEvent   *mouse_event;
     15
    1516  layout = &section[TheSection];
    1617
     
    2223   
    2324    switch (status) {
    24     case -1:
    25       /* no input from pipe: continue */
    26       break;
     25      case -1:
     26        /* no input from pipe: continue */
     27        break;
    2728     
    28     case 0:
    29       fprintf (stderr, "pipe has died!\n");
    30       return (FALSE);
    31       break;
     29      case 0:
     30        fprintf (stderr, "pipe has died!\n");
     31        return (FALSE);
     32        break;
    3233
    33     case 4:
    34       if (!strcmp (buffer, "NCUR")) {  /* stop reading cursor */
     34      case 4:
     35        if (!strcmp (buffer, "NCUR")) {  /* stop reading cursor */
     36          return (TRUE);
     37        }
     38        break;
     39
     40      default:
     41        fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
    3542        return (TRUE);
    36       }
    37       break;
    38 
    39     default:
    40       fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
    41       return (TRUE);
    42       break;
     43        break;
    4344    }
    4445
     
    5354      switch (event.type)  {
    5455
    55       case MotionNotify:
    56         break;
     56        case MotionNotify:
     57          break;
    5758
    58       case Expose:
    59         if (HAVE_BACKING) {
    60           continue;
    61         }
    62         if (XEventsQueued (graphic.display, QueuedAlready) < 2) {
    63           Refresh (1);
    64         }
    65         break;
     59        case Expose:
     60          if (HAVE_BACKING) {
     61            continue;
     62          }
     63          if (XEventsQueued (graphic.display, QueuedAlready) < 2) {
     64            Refresh (1);
     65          }
     66          break;
    6667       
    67       case ConfigureNotify:
    68         status = Reconfig (&event);
    69         break;
     68        case ConfigureNotify:
     69          status = Reconfig (&event);
     70          break;
    7071       
    71       case MappingNotify:
    72         XRefreshKeyboardMapping ((XMappingEvent *) &event);
    73         break;
     72        case MappingNotify:
     73          XRefreshKeyboardMapping ((XMappingEvent *) &event);
     74          break;
    7475       
    75       case KeyPress:
    76         string[0] = 0;
    77         value = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
    78         x = (event.xkey.x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
    79         y = (event.xkey.y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
    80         if ((value > 0) && (isdigit(string[0]) || isalpha(string[0]))) {
    81           sprintf (line, "%c %12.6f %12.6f ", string[0], x, y);
    82           write (sock, line, 32);
    83         }
    84         break;
     76        case ButtonPress:
     77          mouse_event = (XButtonEvent *) &event;
     78          sprintf (string, "Button%d", mouse_event[0].button);
     79          x = (mouse_event[0].x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
     80          y = (mouse_event[0].y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
     81          snprintf (line, 40, "%12s %12.6f %12.6f ", string, x, y);
     82          write (sock, line, 40);
     83          break;
     84
     85        case KeyPress:
     86          value = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
     87          name = XKeysymToString (keysym);
     88
     89          x = (event.xkey.x - layout[0].axis[0].fx)*(layout[0].axis[0].max - layout[0].axis[0].min)/layout[0].axis[0].dfx + layout[0].axis[0].min;
     90          y = (event.xkey.y - layout[0].axis[1].fy)*(layout[0].axis[1].max - layout[0].axis[1].min)/layout[0].axis[1].dfy + layout[0].axis[1].min;
     91
     92          // skip the following keys:
     93          if (!strcmp (name, "Shift_L")) break;
     94          if (!strcmp (name, "Shift_R")) break;
     95          if (!strcmp (name, "Control_L")) break;
     96          if (!strcmp (name, "Control_R")) break;
     97          if (!strcmp (name, "Alt_L")) break;
     98          if (!strcmp (name, "Alt_R")) break;
     99          if (!strcmp (name, "Super_L")) break;
     100          if (!strcmp (name, "Super_R")) break;
     101          if (!strcmp (name, "Caps_Lock")) break;
     102          if (!strcmp (name, "Pause")) break;
     103          if (!strcmp (name, "Break")) break;
     104          if (!strcmp (name, "Num_Lock")) break;
     105          if (!strcmp (name, "Scroll_Lock")) break;
     106          if (!strcmp (name, "Print")) break;
     107          if (!strcmp (name, "(null)")) break;
     108
     109          snprintf (line, 40, "%12s %12.6f %12.6f ", name, x, y);
     110          write (sock, line, 40);
     111          break;
    85112      }
    86113    }
  • trunk/Ohana/src/kii/picture/cursor.c

    r3464 r5349  
    1010  int             status;
    1111  XComposeStatus  composestatus;
    12   char            string[10], line[500];
     12  char            string[10], line[40], *name;
    1313  double          x, y;
    1414 
     
    3535    if (LastEvent (display, MotionNotify,    &event)) UpdatePointer (graphic, layout, (XMotionEvent *) &event);
    3636    if (LastEvent (display, ButtonPress,     &event)) InterpretPresses (graphic, layout, (XButtonEvent *) &event);
    37 
    3837    if (LastEvent (display, KeyPress,        &event)) {
    3938      status = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
    4039
    41       if (!status) continue;
    4240      if (event.xkey.x < layout[0].picture.x) continue;
    4341      if (event.xkey.x > layout[0].picture.x + layout[0].picture.dx) continue;
     
    4644       
    4745      Screen_to_Image (&x, &y, (double)event.xkey.x, (double)event.xkey.y, layout);
     46      name = XKeysymToString (keysym);
    4847
    49       if (isprint(string[0]))
    50         sprintf (line, "%c %6.1f %6.1f ", string[0], x, y);
    51       else {
    52         sprintf (line, "X %6.1f %6.1f ", x, y);
    53       }
    54       write (layout[0].Ximage, line, 16);
     48      // skip the following keys:
     49      if (!strcmp (name, "Shift_L")) continue;
     50      if (!strcmp (name, "Shift_R")) continue;
     51      if (!strcmp (name, "Control_L")) continue;
     52      if (!strcmp (name, "Control_R")) continue;
     53      if (!strcmp (name, "Alt_L")) continue;
     54      if (!strcmp (name, "Alt_R")) continue;
     55      if (!strcmp (name, "Super_L")) continue;
     56      if (!strcmp (name, "Super_R")) continue;
     57      if (!strcmp (name, "Caps_Lock")) continue;
     58      if (!strcmp (name, "Pause")) continue;
     59      if (!strcmp (name, "Continue")) continue;
     60      if (!strcmp (name, "Num_Lock")) continue;
     61      if (!strcmp (name, "Scroll_Lock")) continue;
     62      if (!strcmp (name, "Print")) continue;
     63      if (!strcmp (name, "(null)")) continue;
     64
     65      snprintf (line, 40, "%12s %12.6f %12.6f ", name, x, y);
     66      write (layout[0].Ximage, line, 40);
    5567    }
    5668  }
  • trunk/Ohana/src/opihi/cmd.data/cursor.c

    r2843 r5349  
    33int cursor (int argc, char **argv) {
    44
    5   char buffer[40], string[20], key;
     5  char buffer[40], string[20], key[20], keyname[20];
    66  int i, N, Nsource, Source, IsImage;
    77  double X, Y, R, D, Z;
     
    4949  Z = -1.0;
    5050  for (i = 0; ((i < N) || (N == 0)) && !interrupt; i++) {
    51     bzero (buffer, 20);
    52     read (Source, buffer, 32);
    53     buffer[32] = 0;
    54     sscanf (buffer, "%c %lf %lf", &key, &X, &Y);
    55 
    56     sprintf (string, "X%1c", key);
     51    bzero (buffer, 40);
     52    read (Source, buffer, 40);
     53    buffer[39] = 0;
     54    sscanf (buffer, "%s %lf %lf", key, &X, &Y);
     55    if (ispunct(key[0])) {
     56      strcpy (keyname, "_");
     57    } else {
     58      strcpy (keyname, key);
     59    }
     60    sprintf (string, "X%s", keyname);
    5761    set_variable (string, X);
    58     sprintf (string, "Y%1c", key);
     62    sprintf (string, "Y%s", keyname);
    5963    set_variable (string, Y);
    60     sprintf (string, "%c", key);
    61     set_str_variable ("KEY", string);
     64    set_str_variable ("KEY", key);
    6265   
    6366    if (IsImage && (buf != NULL))
     
    6669    if (!IsImage) {
    6770      XY_to_RD (&R, &D, X, Y, &graphmode.coords);
    68       sprintf (string, "R%1c", key);
     71      sprintf (string, "R%s", keyname);
    6972      set_variable (string, R);
    70       sprintf (string, "D%1c", key);
     73      sprintf (string, "D%s", keyname);
    7174      set_variable (string, D);
    7275    }
     
    7477    /* I still don't like this, but I have to decide which to print... */
    7578    if (IsImage) {
    76       fprintf (GetOutfile(), "%c %f %f  %f\n", key, X, Y, Z);
     79      fprintf (GetOutfile(), "%s %f %f  %f\n", key, X, Y, Z);
    7780    } else {
    78       fprintf (GetOutfile(), "%c %f %f\n", key, X, Y);
     81      fprintf (GetOutfile(), "%s %f %f\n", key, X, Y);
    7982    }
    8083
    81     if ((key == 'q') || (key == 'Q')) {
     84    if (!strcasecmp (key, "Q")) {
    8285      signal (SIGINT, (void *) oldsignal);
    8386      write (Source, "NCUR", 4); /* ask Source to stop looking for the keystrokes */
Note: See TracChangeset for help on using the changeset viewer.