home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / A / GPM / _GPM.TAR / usr / include / gpm.h
Encoding:
C/C++ Source or Header  |  1994-10-31  |  5.7 KB  |  177 lines

  1. /*
  2.  * gpm.h - public include file for gpm-Linux
  3.  *
  4.  * Copyright 1994   rubini@ipvvis.unipv.it (Alessandro Rubini)
  5.  *
  6.  *   This program is free software; you can redistribute it and/or modify
  7.  *   it under the terms of the GNU General Public License as published by
  8.  *   the Free Software Foundation; either version 2 of the License, or
  9.  *   (at your option) any later version.
  10.  *
  11.  *   This program is distributed in the hope that it will be useful,
  12.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *   GNU General Public License for more details.
  15.  *
  16.  *   You should have received a copy of the GNU General Public License
  17.  *   along with this program; if not, write to the Free Software
  18.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  ********/
  20.  
  21. #ifndef _GPM_H_
  22. #define _GPM_H_
  23.  
  24. /*....................................... Xtermish stuff */
  25. #define GPM_XTERM_ON \
  26.   printf("%c[?1001s",27), fflush(stdout), /* save old hilit tracking */ \
  27.   printf("%c[?1000h",27), fflush(stdout) /* enable mouse tracking */
  28.  
  29. #define GPM_XTERM_OFF \
  30.   printf("%c[?10001",27), fflush(stdout), /* disable mouse tracking */ \
  31.   printf("%c[?1001r",27), fflush(stdout) /* restore old hilittracking */
  32.  
  33. /*....................................... Cfg pathnames */
  34.  
  35. #define GPM_NODE_DIR      "/tmp"
  36. #define GPM_NODE_DIR_MODE 0777
  37. #define GPM_NODE_PID      GPM_NODE_DIR "/gpmpid"
  38. #define GPM_NODE_LOG      GPM_NODE_DIR "/gpmlog"
  39. #define GPM_NODE_CTL      GPM_NODE_DIR "/gpmctl"
  40.  
  41. /*....................................... Cfg buttons */
  42.  
  43. #define GPM_B_LEFT      4
  44. #define GPM_B_MIDDLE    2
  45. #define GPM_B_RIGHT     1
  46.  
  47. /*....................................... The event types */
  48.  
  49. enum Gpm_Etype {
  50.   GPM_MOVE=1,
  51.   GPM_DRAG=2,   /* exactly one in four is active at a time */
  52.   GPM_DOWN=4,
  53.   GPM_UP=  8,
  54.  
  55. #define GPM_BARE_EVENTS(ev) ((ev)&0xF)
  56.  
  57.   GPM_SINGLE=16,            /* at most one in three is set */
  58.   GPM_DOUBLE=32,
  59.   GPM_TRIPLE=64,            /* WARNING: I depend on the values */
  60.  
  61.   GPM_MFLAG=128,            /* motion during click? */
  62.   GPM_HARD=256             /* if set in the defaultMask, force an already
  63.                    used event to pass over to another handler */
  64. };
  65.  
  66. #define Gpm_StrictSingle(type) (((type)&GPM_SINGLE) && !((type)&GPM_MFLAG))
  67. #define Gpm_AnySingle(type)     ((type)&GPM_SINGLE)
  68. #define Gpm_StrictDouble(type) (((type)&GPM_DOUBLE) && !((type)&GPM_MFLAG))
  69. #define Gpm_AnyDouble(type)     ((type)&GPM_DOUBLE)
  70. #define Gpm_StrictTriple(type) (((type)&GPM_TRIPLE) && !((type)&GPM_MFLAG))
  71. #define Gpm_AnyTriple(type)     ((type)&GPM_TRIPLE)
  72.  
  73. /*....................................... The event data structure */
  74.  
  75. enum Gpm_Margin {GPM_TOP=1, GPM_BOT=2, GPM_LFT=4, GPM_RGT=8};
  76.  
  77.  
  78. typedef struct Gpm_Event {
  79.   unsigned char buttons, modifiers;  /* try to be a multiple of 4 */
  80.   unsigned short vc;
  81.   short dx, dy, x, y;
  82.   enum Gpm_Etype type;
  83.   int clicks;
  84.   enum Gpm_Margin margin;
  85. }              Gpm_Event;
  86.  
  87. /*....................................... The connection data structure */
  88.  
  89. #define GPM_MAGIC 0x47706D4C /* "GpmL" */
  90. typedef struct Gpm_Connect {
  91.   unsigned short eventMask, defaultMask;
  92.   unsigned short minMod, maxMod;
  93.   int pid;
  94.   int vc;
  95. }              Gpm_Connect;
  96.  
  97.  
  98. /*....................................... Global variables for the client */
  99.  
  100. extern int gpm_flag, gpm_ctlfd, gpm_fd, gpm_hflag, gpm_morekeys;
  101.  
  102. typedef int Gpm_Handler(Gpm_Event *event, void *clientdata);
  103.  
  104. extern Gpm_Handler *gpm_handler;
  105. extern void *gpm_data;
  106.  
  107. extern int gpm_zerobased;
  108. extern int gpm_visiblepointer;
  109. extern int gpm_mx, gpm_my; /* max x and y to fit margins */
  110. extern struct timeval gpm_timeout;
  111.  
  112. extern unsigned char    _gpm_buf[];
  113. extern unsigned short * _gpm_arg;
  114.  
  115.  
  116. /*....................................... Prototypes for the client       */
  117. /*                                          all of them return 0 or errno */
  118.  
  119. #include <stdio.h>      /* needed to get FILE */
  120. #include <sys/ioctl.h>  /* to get the prototype for ioctl() */
  121.  
  122. /* liblow.c */
  123. extern int Gpm_Open(Gpm_Connect *, int);
  124. extern int Gpm_Close(void);
  125. extern int Gpm_GetEvent(Gpm_Event *);
  126. extern int Gpm_Getc(FILE *);
  127. #define    Gpm_Getchar() Gpm_Getc(stdin)
  128. extern int Gpm_Repeat(int millisec);
  129. extern int Gpm_FitValuesM(int *x, int *y, int margin);
  130. #define    Gpm_FitValues(x,y) Gpm_FitValuesM((int *)(x),(int *)(y),-1);
  131. #define    Gpm_FitEvent(ePtr) \
  132.                         ((ePtr)->margin \
  133.                          ? Gpm_FitValuesM((int *)(&((ePtr)->x)), \
  134.                       (int *)(&((ePtr)->y)), \
  135.                                 (ePtr)->margin) \
  136.                          : 0)
  137.  
  138. /* the following is a (progn ...) form */
  139.  
  140. #define Gpm_DrawPointer(x, y, fd) \
  141.                        (_gpm_buf[sizeof(short)-1] = 2, \
  142.                         _gpm_arg[0] = _gpm_arg[2] = \
  143.                                 (unsigned short)(x)+gpm_zerobased, \
  144.                         _gpm_arg[1] = _gpm_arg[3] = \
  145.                                 (unsigned short)(y)+gpm_zerobased, \
  146.                         _gpm_arg[4] = (unsigned short)3, \
  147.                         ioctl(fd, TIOCLINUX, _gpm_buf+sizeof(short)-1))
  148.  
  149. /* the following is a heavy thing ... */
  150. extern int gpm_consolefd; /* liblow.c */
  151.  
  152. /* #define GPM_DRAWPOINTER(event) \
  153.  *                      ((gpm_consolefd=open("/dev/console",O_RDWR))>=0 && \
  154.  *                      Gpm_DrawPointer((event)->x,(event)->y,gpm_consolefd), \
  155.  *                      close(gpm_consolefd))
  156.  */
  157.  
  158. #define GPM_DRAWPOINTER(ePtr) \
  159.                          (Gpm_DrawPointer((ePtr)->x,(ePtr)->y,gpm_consolefd))
  160.  
  161.  
  162.  
  163. /* libhigh.c */
  164. extern int Gpm_Callback(int eventmask, int (*fun)(Gpm_Event *));
  165.  
  166.  
  167. /* libcurses.c */
  168. /* #include <curses.h>  Hmm... seems risky */
  169.  
  170. extern int Gpm_Wgetch();
  171. #define Gpm_Getch() (Gpm_Wgetch(NULL))
  172.  
  173. #endif /* _GPM_H_ */
  174.  
  175.  
  176.  
  177.