IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

cursor now returns a string for key

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.