home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / sco-mouse.shar / emacsmouse.c next >
Encoding:
C/C++ Source or Header  |  1990-07-22  |  2.0 KB  |  109 lines

  1. /*
  2.  * emacsmouse.c - emacs mouse driver
  3.  * copyright 1990 Ronald Florence (ron@mlfarm, 5.7.90)
  4.  */
  5.  
  6. #include <fcntl.h>
  7. #include <sys/termio.h>
  8. #include <stdio.h>
  9. #include <signal.h>
  10. #include <sys/machdep.h>
  11. #include <sys/types.h>
  12. #include <sys/param.h>
  13. #include <sys/sysmacros.h>
  14. #include <sys/page.h>
  15. #include <sys/event.h>
  16. #include <mouse.h>
  17.  
  18. #define BUTTONS    0x7
  19. #define RATIO    0x40        /* You may need to change this if your */
  20.                 /* mouse is overactive or lazy. */
  21.  
  22. main(argc, argv)
  23. int argc;
  24. char **argv;
  25. {
  26.   int quit(), sensitivity, ratio = RATIO;
  27.   EVENT *evp;
  28.   dmask_t dmask = D_REL | D_BUTTON;
  29.  
  30.   if (argc <= 1 || (sensitivity = atoi(*++argv)) < 1 || sensitivity > 9)
  31.     sensitivity = 5;
  32.   ratio <<= sensitivity;
  33.  
  34.   signal(SIGINT, quit);
  35.    
  36.   if (ev_init() < 0)
  37.     quit();
  38.   if (ev_open(&dmask) < 0)
  39.     {
  40. #ifdef DEBUG
  41.       printf("cannot open event queue\n");
  42. #endif
  43.       quit();
  44.     }
  45.   if (dmask != (D_REL | D_BUTTON)) 
  46.     {
  47. #ifdef DEBUG
  48.       printf("cannot attach mouse\n");
  49. #endif
  50.       quit();
  51.     }
  52.  
  53.   while (!ev_block()) 
  54.     if ( (evp = ev_read()) != (EVENT *) NULL ) 
  55.       {
  56.     char button;
  57.  
  58.     switch (EV_BUTTONS(*evp) & BUTTONS)
  59.       {
  60.       case LT_BUTTON: 
  61.         button = 'l'; 
  62.         break;
  63.       case MD_BUTTON:
  64.         button = 'c';
  65.         break;
  66.       case RT_BUTTON: 
  67.         button = 'r'; 
  68.         break;
  69.       case (LT_BUTTON | RT_BUTTON): 
  70.         button = 'b'; 
  71.         break;
  72.       case (LT_BUTTON | RT_BUTTON | MD_BUTTON):
  73.         button = 'a';
  74.         break;
  75.       case (LT_BUTTON | MD_BUTTON):
  76.         button = 'L';
  77.         break;
  78.       case (RT_BUTTON | MD_BUTTON):
  79.         button = 'R';
  80.         break;
  81.       default: 
  82.         button = 'n'; 
  83.         break;
  84.       }
  85.     if (button != 'n' || EV_DX(*evp) || EV_DY(*evp))
  86.       {
  87.         EV_DX(*evp) *= ratio;
  88.         EV_DY(*evp) *= ratio;
  89.         EV_DX(*evp) >>= LOC_RSHIFT;
  90.         EV_DY(*evp) >>= LOC_RSHIFT;
  91. #ifdef DEBUG
  92.         printf("%c %+.2d %+.2d\n", button, EV_DX(*evp), EV_DY(*evp));
  93. #else
  94.         printf("%c%+.2d%+.2d", button, EV_DX(*evp), EV_DY(*evp));
  95.         fflush(stdout);
  96. #endif
  97.       }
  98.     ev_pop();
  99.       }
  100.   return 0;
  101. }
  102.  
  103.  
  104. quit()
  105. {
  106.   ev_close();
  107.   exit(0);
  108. }
  109.