home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / gpm.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-31  |  8.3 KB  |  270 lines

  1. /* -*-mode:C;tab-width:3-*-
  2.  * gpm.h - public include file for gpm
  3.  *
  4.  * Copyright 1994,1995   rubini@linux.it (Alessandro Rubini)
  5.  * Copyright (C) 1998 Ian Zimmerman <itz@rahul.net>
  6.  * Copyright (C) 2002 Nico Schottelius <nico@schottelius.org>
  7.  *
  8.  *   This program is free software; you can redistribute it and/or modify
  9.  *   it under the terms of the GNU General Public License as published by
  10.  *   the Free Software Foundation; either version 2 of the License, or
  11.  *   (at your option) any later version.
  12.  *
  13.  *   This program is distributed in the hope that it will be useful,
  14.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *   GNU General Public License for more details.
  17.  *
  18.  *   You should have received a copy of the GNU General Public License
  19.  *   along with this program; if not, write to the Free Software
  20.  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  21.  ********/
  22.  
  23. #ifndef _GPM_H_
  24. #define _GPM_H_
  25.  
  26. /* $Id: gpm.h,v 1.5 2002/11/30 13:20:10 nico Exp $ */
  27.  
  28. #include <paths.h>              /* _PATH_VARRUN etc. */
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. /*....................................... Xtermish stuff */
  35.  
  36. #define GPM_XTERM_ON \
  37.   printf("%c[?1001s",27), fflush(stdout), /* save old hilit tracking */ \
  38.   printf("%c[?1000h",27), fflush(stdout) /* enable mouse tracking */
  39.  
  40. #define GPM_XTERM_OFF \
  41.   printf("%c[?1000l",27), fflush(stdout), /* disable mouse tracking */ \
  42.   printf("%c[?1001r",27), fflush(stdout) /* restore old hilittracking */
  43.  
  44. /*....................................... Cfg pathnames */
  45.  
  46. /* Provide trailing slash, since mostly used for building pathnames. */
  47.  
  48. #ifndef _PATH_VARRUN
  49. #define _PATH_VARRUN    "/var/run/"
  50. #endif
  51.  
  52. #ifndef _PATH_DEV
  53. #define _PATH_DEV    "/dev/"
  54. #endif
  55.  
  56. #define GPM_NODE_DIR      _PATH_VARRUN
  57.  
  58. /* itz Wed Jul  1 11:56:46 PDT 1998 this definitely ought not to be
  59.    world-writable; umask doesn't apply either, as gpm is most often
  60.    run from init */
  61.  
  62. #define GPM_NODE_DIR_MODE 0775
  63.  
  64. #define GPM_NODE_PID      GPM_NODE_DIR    "gpm.pid"
  65. #define GPM_NODE_DEV      _PATH_DEV    "gpmctl"
  66.  
  67. /* itz Wed Jul 1 12:09:29 PDT 1998 let's simplify this by placing the
  68.    file always in /dev whether it's a device or socket.  It doesn't
  69.    really belong to /var/run anyway. */
  70.  
  71. #define GPM_NODE_CTL      GPM_NODE_DEV
  72. #define GPM_NODE_FIFO     _PATH_DEV    "gpmdata"
  73.  
  74. /*....................................... Cfg buttons */
  75.  
  76. #define GPM_B_DOWN      32
  77. #define GPM_B_UP        16
  78. #define GPM_B_FOURTH    8
  79. #define GPM_B_LEFT      4
  80. #define GPM_B_MIDDLE    2
  81. #define GPM_B_RIGHT     1
  82. #define GPM_B_NONE      0
  83.  
  84. /*....................................... The event types */
  85.  
  86. enum Gpm_Etype {
  87.   GPM_MOVE=1,
  88.   GPM_DRAG=2,   /* exactly one of the bare ones is active at a time */
  89.   GPM_DOWN=4,
  90.   GPM_UP=  8,
  91.  
  92. #define GPM_BARE_EVENTS(type) ((type)&(0x0f|GPM_ENTER|GPM_LEAVE))
  93.  
  94.   GPM_SINGLE=16,            /* at most one in three is set */
  95.   GPM_DOUBLE=32,
  96.   GPM_TRIPLE=64,            /* WARNING: I depend on the values */
  97.  
  98.   GPM_MFLAG=128,            /* motion during click? */
  99.   GPM_HARD=256,             /* if set in the defaultMask, force an already
  100.                    used event to pass over to another handler */
  101.  
  102.   GPM_ENTER=512,            /* enter event, user in Roi's */
  103.   GPM_LEAVE=1024            /* leave event, used in Roi's */
  104. };
  105.  
  106. #define Gpm_StrictSingle(type) (((type)&GPM_SINGLE) && !((type)&GPM_MFLAG))
  107. #define Gpm_AnySingle(type)     ((type)&GPM_SINGLE)
  108. #define Gpm_StrictDouble(type) (((type)&GPM_DOUBLE) && !((type)&GPM_MFLAG))
  109. #define Gpm_AnyDouble(type)     ((type)&GPM_DOUBLE)
  110. #define Gpm_StrictTriple(type) (((type)&GPM_TRIPLE) && !((type)&GPM_MFLAG))
  111. #define Gpm_AnyTriple(type)     ((type)&GPM_TRIPLE)
  112.  
  113. /*....................................... The event data structure */
  114.  
  115. enum Gpm_Margin {GPM_TOP=1, GPM_BOT=2, GPM_LFT=4, GPM_RGT=8};
  116.  
  117. /*....................................... The reported event */
  118.  
  119. typedef struct Gpm_Event {
  120.   unsigned char buttons, modifiers;  /* try to be a multiple of 4 */
  121.   unsigned short vc;
  122.   short dx, dy, x, y;
  123.   enum Gpm_Etype type;
  124.   int clicks;
  125.   enum Gpm_Margin margin;
  126.   short wdx, wdy;
  127. }              Gpm_Event;
  128.  
  129. /*....................................... The handling function */
  130.  
  131. typedef int Gpm_Handler(Gpm_Event *event, void *clientdata);
  132.  
  133. /*....................................... The connection data structure */
  134.  
  135. #define GPM_MAGIC 0x47706D4C /* "GpmL" */
  136. typedef struct Gpm_Connect {
  137.   unsigned short eventMask, defaultMask;
  138.   unsigned short minMod, maxMod;
  139.   int pid;
  140.   int vc;
  141. }              Gpm_Connect;
  142.  
  143. /*....................................... The region of Interest */
  144.  
  145. typedef struct Gpm_Roi {
  146.   short xMin,xMax;
  147.   short yMin,yMax;
  148.   unsigned short minMod, maxMod;
  149.   unsigned short eventMask;
  150.   unsigned short owned;
  151.   Gpm_Handler *handler;
  152.   void *clientdata;
  153.   struct Gpm_Roi *prev;
  154.   struct Gpm_Roi *next;
  155. }              Gpm_Roi;
  156.   
  157.  
  158. /*....................................... Global variables for the client */
  159.  
  160. extern int gpm_flag, gpm_ctlfd, gpm_fd, gpm_hflag, gpm_morekeys;
  161.  
  162. extern int gpm_zerobased;
  163. extern int gpm_visiblepointer;
  164. extern int gpm_mx, gpm_my; /* max x and y to fit margins */
  165. extern struct timeval gpm_timeout;
  166.  
  167. extern unsigned char    _gpm_buf[];
  168. extern unsigned short * _gpm_arg;
  169.  
  170. extern Gpm_Handler *gpm_handler;
  171. extern void *gpm_data;
  172.  
  173. extern Gpm_Handler *gpm_roi_handler;
  174. extern void *gpm_roi_data;
  175.  
  176. extern Gpm_Roi *gpm_roi;
  177. extern Gpm_Roi *gpm_current_roi;
  178.  
  179.  
  180. /*....................................... Prototypes for the client       */
  181. /*                                          all of them return 0 or errno */
  182.  
  183. #include <stdio.h>      /* needed to get FILE */
  184. #include <sys/ioctl.h>  /* to get the prototype for ioctl() */
  185.  
  186. /* liblow.c */
  187. extern int Gpm_Open(Gpm_Connect *, int);
  188. extern int Gpm_Close(void);
  189. extern int Gpm_GetEvent(Gpm_Event *);
  190. extern int Gpm_CharsQueued(void);
  191. extern int Gpm_Getc(FILE *);
  192. #define    Gpm_Getchar() Gpm_Getc(stdin)
  193. extern int Gpm_Repeat(int millisec);
  194. extern int Gpm_FitValuesM(int *x, int *y, int margin);
  195. #define    Gpm_FitValues(x,y) Gpm_FitValuesM((x),(y),-1);
  196. #define    Gpm_FitEvent(ePtr)   \
  197.    do {                         \
  198.       int _x, _y;               \
  199.       if ((ePtr)->margin && ((ePtr)->type&(GPM_DRAG | GPM_UP)))  \
  200.         {                       \
  201.         _x = (ePtr)->x;         \
  202.         _y = (ePtr)->y;         \
  203.         Gpm_FitValuesM(&_x, &_y, (ePtr)->margin); \
  204.         (ePtr)->x = _x;         \
  205.         (ePtr)->y = _y;         \
  206.     }                       \
  207.     } while(0)                  \
  208.  
  209.  
  210. /* the following is a (progn ...) form */
  211.  
  212. #define Gpm_DrawPointer(x, y, fd) \
  213.                        (_gpm_buf[sizeof(short)-1] = 2, \
  214.                         _gpm_arg[0] = _gpm_arg[2] = \
  215.                                 (unsigned short)(x)+gpm_zerobased, \
  216.                         _gpm_arg[1] = _gpm_arg[3] = \
  217.                                 (unsigned short)(y)+gpm_zerobased, \
  218.                         _gpm_arg[4] = (unsigned short)3, \
  219.                         ioctl(fd, TIOCLINUX, _gpm_buf+sizeof(short)-1))
  220.  
  221. /* the following is a heavy thing ... */
  222. extern int gpm_consolefd; /* liblow.c */
  223.  
  224. /* #define GPM_DRAWPOINTER(event) \
  225.  *                      ((gpm_consolefd=open("/dev/console",O_RDWR))>=0 && \
  226.  *                      Gpm_DrawPointer((event)->x,(event)->y,gpm_consolefd), \
  227.  *                      close(gpm_consolefd))
  228.  */
  229.  
  230. #define GPM_DRAWPOINTER(ePtr) \
  231.                          (Gpm_DrawPointer((ePtr)->x,(ePtr)->y,gpm_consolefd))
  232.  
  233.  
  234.  
  235. /* libhigh.c */
  236.  
  237. Gpm_Handler Gpm_HandleRoi;
  238. Gpm_Roi *Gpm_PushRoi(int x, int y, int X, int Y, int mask,
  239.                      Gpm_Handler *fun, void *xtradata);
  240. Gpm_Roi * Gpm_PopRoi(Gpm_Roi *which);
  241. Gpm_Roi * Gpm_RaiseRoi(Gpm_Roi *which, Gpm_Roi *before);
  242. Gpm_Roi * Gpm_LowerRoi(Gpm_Roi *which, Gpm_Roi *after);
  243.  
  244.  
  245. /* libcurses.c */
  246. /* #include <curses.h>  Hmm... seems risky */
  247.  
  248. extern int Gpm_Wgetch();
  249. #define Gpm_Getch() (Gpm_Wgetch(NULL))
  250.  
  251. /* libxtra.c */
  252. char *Gpm_GetLibVersion(int *where);
  253. char *Gpm_GetServerVersion(int *where);
  254. int   Gpm_GetSnapshot(Gpm_Event *ePtr);
  255.  
  256. /* tools.c: do they really need to be exported? Can't we keep them in gpmInt.h ? */
  257. char *Gpm_get_console( void );
  258. int Gpm_x_high_y(int base, int pot_y);
  259. int Gpm_cnt_digits(int number);
  260. void gpm_oops(int line, char *file, char *text, ... );
  261.  
  262. /* report.c / report-lib.c */
  263. void gpm_report(int line, char *file, int stat, char *text, ... );
  264.  
  265. #ifdef __cplusplus
  266.   };
  267. #endif
  268.  
  269. #endif /* _GPM_H_ */
  270.