2
0

gpm.tex 15 KB

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