home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slackwar / a / util / util-lin.10 / util-lin / util-linux-1.10 / selection / test-mouse.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-17  |  1.5 KB  |  68 lines

  1. /*
  2.  * test-mouse: exercise rodent to test compatibility.
  3.  * Any button to draw asterisks of different
  4.  * colour. Left and right buttons (while mouse is stationary) to quit.
  5.  * Andrew Haylett, 17th June 1993
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <termios.h>
  11. #include <errno.h>
  12. #include <sys/ioctl.h>
  13.  
  14. #include "mouse.h"
  15.  
  16. #define SCALE    10
  17.  
  18. int
  19. main(int argc, char *argv[])
  20. {
  21.     struct ms_event ev;
  22.     struct winsize win;
  23.  
  24.     ms_params(argc, argv);
  25.     ioctl(fileno(stdout), TIOCGWINSZ, &win);
  26.     if (! win.ws_col || ! win.ws_row)
  27.     {
  28.         fprintf(stderr, "selection: zero screen dimension: assuming 80x25.\n");
  29.         win.ws_col = 80;
  30.         win.ws_row = 25;
  31.     }
  32.  
  33.     printf("\033[2J\033[%d;%dH", win.ws_row / 2, win.ws_col / 2);
  34.     fflush(stdout);
  35.     if (ms_init((win.ws_col + 1) * SCALE - 1, (win.ws_row + 1) * SCALE - 1))
  36.     {
  37.         perror("ms_init");
  38.         exit(1);
  39.     }
  40.     while (1)
  41.     {
  42.         if (get_ms_event(&ev))
  43.         {
  44.         perror("get_ms_event");
  45.             exit(1);
  46.     }
  47.     if (ev.ev_code == MS_BUTDOWN && ev.ev_butstate == (MS_BUTLEFT | MS_BUTRIGHT))
  48.     {
  49.         printf("\033[;H\033[2J\033[m");
  50.         exit(0);
  51.     }
  52.     else if (ev.ev_code == MS_MOVE || ev.ev_code == MS_DRAG)
  53.     {
  54.         printf("\033[%d;%dH", ev.ev_y / SCALE, ev.ev_x / SCALE);
  55.         if (ev.ev_code == MS_DRAG)
  56.         {
  57.             if (ev.ev_butstate == MS_BUTLEFT)
  58.             printf("\033[31m*\033[D");    /* red */
  59.         else if (ev.ev_butstate == MS_BUTRIGHT)
  60.             printf("\033[35m*\033[D");    /* purple */
  61.         else
  62.             printf("\033[34m*\033[D");    /* blue */
  63.         }
  64.     }
  65.     fflush(stdout);
  66.     }
  67. }
  68.