gpm.tex 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. \chapter{The GPM unit}
  2. \section{Introduction}
  3. The \file{GPM} unit implements an interface to file{libgpm}, the console
  4. program for mouse handling. This unit was created by Peter Vreman, and
  5. is only available on \linux.
  6. When this unit is used, your program is linked to the C libraries, so
  7. you must take care of the C library version. Also, it will only work with
  8. version 1.17 or higher of the \file{libgpm} library.
  9. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10. % Constants, types and variables
  11. \section{Constants, types and variables}
  12. \subsection{constants}
  13. The following constants are used to denote filenames used by the library:
  14. \begin{verbatim}
  15. _PATH_VARRUN = '/var/run/';
  16. _PATH_DEV = '/dev/';
  17. GPM_NODE_DIR = _PATH_VARRUN;
  18. GPM_NODE_DIR_MODE = 0775;
  19. GPM_NODE_PID = '/var/run/gpm.pid';
  20. GPM_NODE_DEV = '/dev/gpmctl';
  21. GPM_NODE_CTL = GPM_NODE_DEV;
  22. GPM_NODE_FIFO = '/dev/gpmdata';
  23. \end{verbatim}
  24. The following constants denote the buttons on the mouse:
  25. \begin{verbatim}
  26. GPM_B_LEFT = 4;
  27. GPM_B_MIDDLE = 2;
  28. GPM_B_RIGHT = 1;
  29. \end{verbatim}
  30. The following constants define events:
  31. \begin{verbatim}
  32. GPM_MOVE = 1;
  33. GPM_DRAG = 2;
  34. GPM_DOWN = 4;
  35. GPM_UP = 8;
  36. GPM_SINGLE = 16;
  37. GPM_DOUBLE = 32;
  38. GPM_TRIPLE = 64;
  39. GPM_MFLAG = 128;
  40. GPM_HARD = 256;
  41. GPM_ENTER = 512;
  42. GPM_LEAVE = 1024;
  43. \end{verbatim}
  44. The following constants are used in defining margins:
  45. \begin{verbatim}
  46. GPM_TOP = 1;
  47. GPM_BOT = 2;
  48. GPM_LFT = 4;
  49. GPM_RGT = 8;
  50. \end{verbatim}
  51. % Types
  52. \subsection{Types}
  53. The following general types are defined:
  54. \begin{verbatim}
  55. TGpmEtype = longint;
  56. TGpmMargin = longint;
  57. \end{verbatim}
  58. The following type describes an event; it is passed in many of the gpm
  59. functions.
  60. \begin{verbatim}
  61. PGpmEvent = ^TGpmEvent;
  62. TGpmEvent = record
  63. buttons : byte;
  64. modifiers : byte;
  65. vc : word;
  66. dx : integer;
  67. dy : integer;
  68. x : integer;
  69. y : integer;
  70. wdx : integer;
  71. wdy : integer;
  72. EventType : TGpmEType;
  73. clicks : longint;
  74. margin : TGpmMargin;
  75. end;
  76. TGpmHandler=function(var event:TGpmEvent;clientdata:pointer):longint;cdecl;
  77. \end{verbatim}
  78. The following types are used in connecting to the \file{gpm} server:
  79. \begin{verbatim}
  80. PGpmConnect = ^TGpmConnect;
  81. TGpmConnect = record
  82. eventMask : word;
  83. defaultMask : word;
  84. minMod : word;
  85. maxMod : word;
  86. pid : longint;
  87. vc : longint;
  88. end;
  89. \end{verbatim}
  90. The following type is used to define {\em regions of interest}
  91. \begin{verbatim}
  92. PGpmRoi = ^TGpmRoi;
  93. TGpmRoi = record
  94. xMin : integer;
  95. xMax : integer;
  96. yMin : integer;
  97. yMax : integer;
  98. minMod : word;
  99. maxMod : word;
  100. eventMask : word;
  101. owned : word;
  102. handler : TGpmHandler;
  103. clientdata : pointer;
  104. prev : PGpmRoi;
  105. next : PGpmRoi;
  106. end;
  107. \end{verbatim}
  108. % Variables
  109. \subsection{Variables}
  110. The following variables are imported from the \var{gpm} library
  111. \begin{verbatim}
  112. gpm_flag : longint;cvar;external;
  113. gpm_fd : longint;cvar;external;
  114. gpm_hflag : longint;cvar;external;
  115. gpm_morekeys : Longbool;cvar;external;
  116. gpm_zerobased : Longbool;cvar;external;
  117. gpm_visiblepointer : Longbool;cvar;external;
  118. gpm_mx : longint;cvar;external;
  119. gpm_my : longint;cvar;external;
  120. gpm_timeout : TTimeVal;cvar;external;
  121. _gpm_buf : array[0..0] of char;cvar;external;
  122. _gpm_arg : ^word;cvar;external;
  123. gpm_handler : TGpmHandler;cvar;external;
  124. gpm_data : pointer;cvar;external;
  125. gpm_roi_handler : TGpmHandler;cvar;external;
  126. gpm_roi_data : pointer;cvar;external;
  127. gpm_roi : PGpmRoi;cvar;external;
  128. gpm_current_roi : PGpmRoi;cvar;external;
  129. gpm_consolefd : longint;cvar;external;
  130. Gpm_HandleRoi : TGpmHandler;cvar;external;
  131. \end{verbatim}
  132. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  133. % Functions and procedures
  134. \section{Functions and procedures}
  135. \begin{functionl}{Gpm\_AnyDouble}{GpmAnyDouble}
  136. \Declaration
  137. function Gpm\_AnyDouble(EventType : longint) : boolean;
  138. \Description
  139. \var{Gpm\_AnyDouble} returns \var{True} if \var{EventType} contains
  140. the \var{GPM\_DOUBLE} flag, \var{False} otherwise.
  141. \Errors
  142. None.
  143. \SeeAlso
  144. \seefl{Gpm\_StrictSingle}{GpmStrictSingle},
  145. \seefl{Gpm\_AnySingle}{GpmAnySingle},
  146. \seefl{Gpm\_StrictDouble}{GpmStrictDouble},
  147. \seefl{Gpm\_StrictTriple{GpmStrictTriple},
  148. \seefl{Gpm\_AnyTriple}{GpmAnyTriple}
  149. \end{functionl}
  150. \begin{functionl}{Gpm\_AnySingle}{GpmAnySingle}
  151. \Declaration
  152. function Gpm\_AnySingle(EventType : longint) : boolean;
  153. \Description
  154. \var{Gpm\_AnySingle} returns \var{True} if \var{EventType} contains
  155. the \var{GPM\_SINGLE} flag, \var{False} otherwise.
  156. \Errors
  157. \SeeAlso
  158. \seefl{Gpm\_StrictSingle}{GpmStrictSingle},
  159. \seefl{Gpm\_AnyDoubmle}{GpmAnyDouble},
  160. \seefl{Gpm\_StrictDouble}{GpmStrictDouble},
  161. \seefl{Gpm\_StrictTriple{GpmStrictTriple},
  162. \seefl{Gpm\_AnyTriple}{GpmAnyTriple}
  163. \end{functionl}
  164. \begin{functionl}{Gpm_AnyTriple}{GpmAnyTriple}
  165. \Declaration
  166. function Gpm\_AnyTriple(EventType : longint) : boolean;
  167. \Description
  168. \Errors
  169. \SeeAlso
  170. \seefl{Gpm\_StrictSingle}{GpmStrictSingle},
  171. \seefl{Gpm\_AnyDoubmle}{GpmAnyDouble},
  172. \seefl{Gpm\_StrictDouble}{GpmStrictDouble},
  173. \seefl{Gpm\_StrictTriple{GpmStrictTriple},
  174. \seefl{Gpm\_AnySingle}{GpmAnySingle}
  175. \end{functionl}
  176. \begin{functionl}{Gpm_Close}{GpmClose}
  177. \Declaration
  178. function Gpm\_Close:longint;cdecl;external;
  179. \Description
  180. \var{Gpm\_Close} closes the current connection, and pops the connection
  181. stack; this means that the previous connection becomes active again.
  182. The function returns -1 if the current connection is not the last one,
  183. and it returns 0 if the current connection is the last one.
  184. \Errors
  185. None.
  186. \SeeAlso
  187. \seefl{Gpm\_Open}{GpmOpen}
  188. \end{functionl}
  189. \begin{functionl}{Gpm\_FitValues}{GpmFitValues}
  190. \Declaration
  191. function Gpm\_FitValues(var x,y:longint):longint;cdecl;external;
  192. \Description
  193. \var{Gpm_fitValues} changes \var{x} and \var{y} so they fit in the visible
  194. screen. The actual mouse pointer is not affected by this function.
  195. \Errors
  196. None.
  197. \SeeAlso
  198. \seefl{Gpm\_FitValuesM}{Gpm\_FitValuesM},
  199. \end{functionl}
  200. \begin{functionl}{Gpm\_FitValuesM}{GpmFitValuesM}
  201. \Declaration
  202. function Gpm\_FitValuesM(var x,y:longint; margin:longint):longint;cdecl;external;
  203. \Description
  204. \var{Gpm\_FitValuesM} chnages \var{x} and \var{y} so they fit in the margin
  205. indicated by \var{margin}. If \var{margin} is -1, then the values are fitted
  206. to the screen. The actual mouse pointer is not affected by this function.
  207. \Errors
  208. None.
  209. \SeeAlso
  210. \seefl{Gpm\_FitValues}{GpmFitValues},
  211. \end{functionl}
  212. \begin{functionl}{Gpm_GetEvent}{GpmGetEvent}
  213. \Declaration
  214. function Gpm\_GetEvent(var Event:TGpmEvent):longint;cdecl;external;
  215. \Description
  216. \var{Gpm\_GetEvent} Reads an event from the file descriptor \var{gpm_fd}.
  217. This file is only for internal use and should never be called by a client
  218. application.
  219. It returns 1 on succes, and -1 on failue.
  220. \Errors
  221. On error, -1 is returned.
  222. \SeeAlso
  223. seefl{Gpm\_GetSnapshot}{GpmGetSnapshot}
  224. \end{functionl}
  225. \begin{functionl}{Gpm\_GetLibVersion}{GpmGetLibVersion}
  226. \Declaration
  227. function Gpm\_GetLibVersion(var where:longint):pchar;cdecl;external;
  228. \Description
  229. \var{Gpm\_GetLibVersion} returns a pointer to a version string, and returns
  230. in \var{where} an integer representing the version. The version string
  231. represents the version of the gpm library.
  232. The return value is a pchar, which should not be dealloacted, i.e. it is not
  233. on the heap.
  234. \Errors
  235. None.
  236. \SeeAlso
  237. \seefl{Gpm\_GetServerVersion}{GpmGetServerVersion}
  238. \end{functionl}
  239. \begin{functionl}{Gpm\_GetServerVersion}{GpmGetServerVersion}
  240. \Declaration
  241. function Gpm\_GetServerVersion(var where:longint):pchar;cdecl;external;
  242. \Description
  243. \var{Gpm\_GetServerVersion} returns a pointer to a version string, and
  244. returns in \var{where} an integer representing the version. The version string
  245. represents the version of the gpm server program.
  246. The return value is a pchar, which should not be dealloacted, i.e. it is not
  247. on the heap.
  248. \Errors
  249. If the gpm program is not present, then the function returns \var{Nil}
  250. \SeeAlso
  251. \seefl{Gpm\_GetLibVersion}{GpmGetLibVersion}
  252. \end{functionl}
  253. \begin{functionl}{Gpm\_GetSnapshot}{GpmGetSnapshot}
  254. \Declaration
  255. function Gpm\_GetSnapshot(var Event:TGpmEvent):longint;cdecl;external;
  256. \Description
  257. \var{Gpm\_GetSnapshot} returns the picture that the server has of the
  258. current situation in \var{Event}.
  259. This call will not read the current situation from the mouse file
  260. descriptor, but returns a buffered version.
  261. The meaning of the fields is as follows:
  262. \begin{description}
  263. \item[x,y] current position of the cursor.
  264. \item[dx,dy] size of the window.
  265. \item[vc] number of te virtual console.
  266. \item[modifiers] keyboard shift state.
  267. \item[buttons] buttons which are currently pressed.
  268. \item[clicks] number of clicks (0,1 or 2).
  269. \end{description}
  270. The function returns the number of mouse buttons, or -1 if this information
  271. is not available.
  272. \Errors
  273. None.
  274. \SeeAlso
  275. \seefl{Gpm\_GetEvent}{GpmGetEvent}
  276. \end{functionl}
  277. \begin{functionl}{Gpm\_LowerRoi}{GpmLowerRoi}
  278. \Declaration
  279. function Gpm\_LowerRoi(which:PGpmRoi; after:PGpmRoi):PGpmRoi;cdecl;external;
  280. \Description
  281. \var{Gpm\_LowerRoi} lowers the region of interest \var{which} after
  282. \var{after}. If \var{after} is \var{Nil}, the region of interest is moved to
  283. the bottom of the stack.
  284. The return value is the new top of the region-of-interest stack.
  285. \Errors
  286. None.
  287. \SeeAlso
  288. \seefl{Gpm\_RaiseRoi}{GpmRaiseRoi},
  289. \seefl{Gpm\_PopRoi}{GpmPopRoi},
  290. \seefl{Gpm\_PushRoi}{GpmPopRoi}
  291. \end{functionl}
  292. \begin{functionl}{Gpm\_Open}{GpmOpen}
  293. \Declaration
  294. function Gpm\_Open(var Conn:TGpmConnect; Flag:longint):longint;cdecl;external;
  295. \Description
  296. \var{Gpm\_Open} opens a new connection to the mouse server. The connection
  297. is described by the fields of the \var{conn} record:
  298. \begin{description}
  299. \item[EventMask] A bitmask of the events the program wants to receive.
  300. \item[DefaultMask] A bitmask to tell the library which events get their
  301. default treatment (text selection).
  302. \item[minMod] the minimum amount of modifiers needed by the program.
  303. \item[maxMod] the maximum amount of modifiers needed by the program.
  304. \end{description}
  305. if \var{Flag} is 0, then the application only receives events that come from
  306. its own terminal device. If it is negative it will receive all events. If
  307. the value is positive then it is considered a console number to which to
  308. connect.
  309. The return value is -1 on error, or the file descriptor used to communicate
  310. with the client. Under an X-Term the return value is -2.
  311. \Errors
  312. On Error, the return value is -1.
  313. \SeeAlso
  314. \seefl{Gpm\_Open}{GpmOpen}
  315. \end{functionl}
  316. \begin{functionl}{Gpm\_PopRoi}{GpmPopRoi}
  317. \Declaration
  318. function Gpm\_PopRoi(which:PGpmRoi):PGpmRoi;cdecl;external;
  319. \Description
  320. \var{Gpm\_PopRoi} pops the topmost region of interest from the stack.
  321. It returns the next element on the stack, or \var{Nil} if the current
  322. element was the last one.
  323. \Errors
  324. None.
  325. \SeeAlso
  326. \seefl{Gpm\_RaiseRoi}{GpmRaiseRoi},
  327. \seefl{Gpm\_LowerRoi}{GpmLowerRoi},
  328. \seefl{Gpm\_PushRoi}{GpmPopRoi}
  329. \end{functionl}
  330. \begin{functionl}{Gpm\_PushRoi}{GpmPushRoi}
  331. \Declaration
  332. function Gpm\_PushRoi(x1:longint; y1:longint; X2:longint; Y2:longint; mask:longint; fun:TGpmHandler; xtradata:pointer):PGpmRoi;cdecl;external;
  333. \Description
  334. \var{Gpm\_PushRoi} puts a new {\em region of interest} on the stack.
  335. The region of interest is defined by a rectangle described by the corners
  336. \var{(X1,Y1)} and \var{(X2,Y2)}.
  337. The \var{mask} describes which events the handler {fun} will handle;
  338. \var{ExtraData} will be put in the \var{xtradata} field of the {TGPM\_Roi}
  339. record passed to the \var{fun} handler.
  340. \Errors
  341. None.
  342. \SeeAlso
  343. \seefl{Gpm\_RaiseRoi}{GpmRaiseRoi},
  344. \seefl{Gpm\_PopRoi}{GpmPopRoi},
  345. \seefl{Gpm\_LowerRoi}{GpmLowerRoi}
  346. \end{functionl}
  347. \begin{functionl}{Gpm\_RaiseRoi}{GpmRaiseRoi}
  348. \Declaration
  349. function Gpm\_RaiseRoi(which:PGpmRoi; before:PGpmRoi):PGpmRoi;cdecl;external;
  350. \Description
  351. \var{Gpm\_RaiseRoi} raises the {\em region of interest} \var{which}
  352. \Errors
  353. \SeeAlso
  354. \end{functionl}
  355. \begin{functionl}
  356. \Declaration
  357. function Gpm_Repeat(millisec:longint):longint;cdecl;external;
  358. \Description
  359. \Errors
  360. \SeeAlso
  361. \end{functionl}
  362. \begin{functionl}
  363. \Declaration
  364. function Gpm_StrictDouble(EventType : longint) : boolean;
  365. \Description
  366. \Errors
  367. \SeeAlso
  368. \end{functionl}
  369. \begin{functionl}
  370. \Declaration
  371. function Gpm_StrictSingle(EventType : longint) : boolean;
  372. \Description
  373. \Errors
  374. \SeeAlso
  375. \end{functionl}
  376. \begin{functionl}
  377. \Declaration
  378. function Gpm_StrictTriple(EventType : longint) : boolean;
  379. \Description
  380. \Errors
  381. \SeeAlso
  382. \end{functionl}