PageRenderTime 58ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 1ms

/Xlib.ml

http://github.com/dmsh/ocaml-xlib
OCaml | 2967 lines | 1948 code | 509 blank | 510 comment | 39 complexity | e56e2e6cd5c234ea9a86c1f447be9a37 MD5 | raw file
  1. (** OCaml bindings for the Xlib library. *)
  2. (* Copyright (C) 2008, 2009, 2010 by Florent Monnier
  3. * Contact: <fmonnier@linux-nantes.org>
  4. *
  5. * OCaml-Xlib is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published
  7. * by the Free Software Foundation, either version 3 of the License,
  8. * or (at your option) any later version.
  9. *
  10. * OCaml-Xlib is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with OCaml-Xlib. If not, see:
  17. * <http://www.gnu.org/licenses/>
  18. *)
  19. (**
  20. {ul
  21. {- {{:http://www.x.org/docs/X11/xlib.pdf}Xlib manual (pdf)}}
  22. {- {{:http://tronche.com/gui/x/xlib/}Xlib manual (html)}}
  23. }
  24. *)
  25. (** {3 Types} *)
  26. type event_mask =
  27. | KeyPressMask
  28. | KeyReleaseMask
  29. | ButtonPressMask
  30. | ButtonReleaseMask
  31. | EnterWindowMask
  32. | LeaveWindowMask
  33. | PointerMotionMask
  34. | PointerMotionHintMask
  35. | Button1MotionMask
  36. | Button2MotionMask
  37. | Button3MotionMask
  38. | Button4MotionMask
  39. | Button5MotionMask
  40. | ButtonMotionMask
  41. | KeymapStateMask
  42. | ExposureMask
  43. | VisibilityChangeMask
  44. | StructureNotifyMask
  45. | ResizeRedirectMask
  46. | SubstructureNotifyMask
  47. | SubstructureRedirectMask
  48. | FocusChangeMask
  49. | PropertyChangeMask
  50. | ColormapChangeMask
  51. | OwnerGrabButtonMask
  52. (* just in case a futur ocaml implementation would handle uint *)
  53. type uint = int
  54. type 'a drawable
  55. type _window type window = _window drawable
  56. type _pixmap type pixmap = _pixmap drawable
  57. (** both windows and pixmaps can be used as drawable *)
  58. type gc
  59. type colormap
  60. type atom
  61. type time = int64
  62. (* exposed *)
  63. type keysym = int
  64. type keycode = int
  65. (*
  66. (* abstract *)
  67. type keysym
  68. type keycode
  69. external keysym_of_int: int -> keysym = "%identity"
  70. external int_of_keysym: keysym -> int = "%identity"
  71. external keycode_of_int: int -> keycode = "%identity"
  72. external int_of_keycode: keycode -> int = "%identity"
  73. *)
  74. (** {3 Display} *)
  75. (** {{:http://tronche.com/gui/x/xlib/display/}Display Functions} *)
  76. type display
  77. external xOpenDisplay: name:string -> display = "ml_XOpenDisplay"
  78. (** {{:http://tronche.com/gui/x/xlib/display/opening.html}man} *)
  79. #if defined(MLI)
  80. val open_display: ?name:string -> unit -> display
  81. #else
  82. let open_display ?name () =
  83. let name = match name with Some id -> id
  84. | None -> try Sys.getenv "DISPLAY" with Not_found -> ":0"
  85. in
  86. xOpenDisplay ~name
  87. ;;
  88. #endif
  89. external xCloseDisplay: dpy:display -> unit = "ml_XCloseDisplay"
  90. (** {{:http://tronche.com/gui/x/xlib/display/XCloseDisplay.html}man} *)
  91. external xFlush: dpy:display -> unit = "ml_XFlush"
  92. (** {{:http://tronche.com/gui/x/xlib/event-handling/XFlush.html}man} *)
  93. external xBell: dpy:display -> percent:int -> unit = "ml_XBell"
  94. (** {{:http://tronche.com/gui/x/xlib/input/XBell.html}man} *)
  95. (* WIP *)
  96. external xChangeKeyboardControl_bell_percent: dpy:display -> bell_percent:int -> unit
  97. = "ml_XChangeKeyboardControl_bell_percent"
  98. external xChangeKeyboardControl_bell_pitch: dpy:display -> bell_pitch:int -> unit
  99. = "ml_XChangeKeyboardControl_bell_pitch"
  100. external xChangeKeyboardControl_bell_duration: dpy:display -> bell_duration:int -> unit
  101. = "ml_XChangeKeyboardControl_bell_duration"
  102. external xChangeKeyboardControl_bell: dpy:display ->
  103. bell_percent:int ->
  104. bell_pitch:int ->
  105. bell_duration:int -> unit
  106. = "ml_XChangeKeyboardControl_bell"
  107. (** [bell_percent] sets the base volume for the bell between 0 (off) and 100
  108. (loud) inclusive, if possible. A setting of -1 restores the default. Other
  109. negative values generate a BadValue error.
  110. [bell_pitch] member sets the pitch (specified in Hz) of the bell, if possible.
  111. A setting of -1 restores the default. Other negative values generate a BadValue error.
  112. [bell_duration] member sets the duration of the bell specified in milliseconds,
  113. if possible. A setting of -1 restores the default. Other negative values generate
  114. a BadValue error. *)
  115. external xChangeKeyboardControl_key_click_percent: dpy:display -> key_click_percent:int -> unit
  116. = "ml_XChangeKeyboardControl_key_click_percent"
  117. (* /WIP *)
  118. type close_mode =
  119. | DestroyAll
  120. | RetainPermanent
  121. | RetainTemporary
  122. external xSetCloseDownMode: dpy:display -> close_mode:close_mode -> unit = "ml_XSetCloseDownMode"
  123. (** {{:http://tronche.com/gui/x/xlib/display/XSetCloseDownMode.html}man} *)
  124. external xSync: dpy:display -> discard:bool -> unit = "ml_XSync"
  125. (** {{:http://tronche.com/gui/x/xlib/event-handling/XSync.html}man} *)
  126. external xConnectionNumber: dpy:display -> int = "ml_XConnectionNumber"
  127. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#ConnectionNumber}man} *)
  128. external xProtocolVersion: dpy:display -> int = "ml_XProtocolVersion"
  129. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#ProtocolVersion}man} *)
  130. external xProtocolRevision: dpy:display -> int = "ml_XProtocolRevision"
  131. external xVendorRelease: dpy:display -> int = "ml_XVendorRelease"
  132. external xServerVendor: dpy:display -> string = "ml_XServerVendor"
  133. external xlibSpecificationRelease: unit -> int = "ml_XlibSpecificationRelease"
  134. (** Server Grabbing *)
  135. external xGrabServer: dpy:display -> unit = "ml_XGrabServer"
  136. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XGrabServer.html}man} *)
  137. external xUngrabServer: dpy:display -> unit = "ml_XUngrabServer"
  138. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XUngrabServer.html}man} *)
  139. external xUngrabPointer: dpy:display -> time:time -> unit = "ml_XUngrabPointer"
  140. (** {{:http://tronche.com/gui/x/xlib/input/XUngrabPointer.html}man} *)
  141. external xUngrabKeyboard: dpy:display -> time:time -> unit = "ml_XUngrabKeyboard"
  142. (** {{:http://tronche.com/gui/x/xlib/input/XUngrabKeyboard.html}man} *)
  143. (** {3 Screen number} *)
  144. type screen_number = private int
  145. external xDefaultScreen: dpy:display -> screen_number = "ml_XDefaultScreen"
  146. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#DefaultScreen}man} *)
  147. external xDisplayWidth: dpy:display -> scr:screen_number -> int = "ml_XDisplayWidth"
  148. external xDisplayHeight: dpy:display -> scr:screen_number -> int = "ml_XDisplayHeight"
  149. external xDefaultDepth: dpy:display -> scr:screen_number -> int = "ml_XDefaultDepth"
  150. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#DefaultDepth}man} *)
  151. external xListDepths: dpy:display -> scr:screen_number -> int array = "ml_XListDepths"
  152. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#XListDepths}man} *)
  153. external xDisplayPlanes: dpy:display -> scr:screen_number -> int = "ml_XDisplayPlanes"
  154. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#DisplayPlanes}man} *)
  155. external xScreenCount: dpy:display -> int = "ml_XScreenCount"
  156. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#ScreenCount}man} *)
  157. #if defined(MLI)
  158. val xScreenNumbers : dpy:display -> screen_number array
  159. (** returns an array of all the screen numbers *)
  160. #else
  161. let xScreenNumbers ~dpy =
  162. let n = xScreenCount ~dpy in
  163. Array.init n (fun i -> (Obj.magic i : screen_number))
  164. ;;
  165. #endif
  166. (** {3 Pixel Colors} *)
  167. type pixel_color
  168. external xBlackPixel: dpy:display -> scr:screen_number -> pixel_color = "ml_XBlackPixel"
  169. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#BlackPixel}man} *)
  170. external xWhitePixel: dpy:display -> scr:screen_number -> pixel_color = "ml_XWhitePixel"
  171. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#WhitePixel}man} *)
  172. (** {3 XColor} *)
  173. (** {{:http://tronche.com/gui/x/xlib/color/}Color Management Functions} *)
  174. type xColor
  175. external new_xColor: unit -> xColor = "ml_alloc_XColor"
  176. (** this type is garbage collected *)
  177. external xAllocNamedColor: dpy:display -> colormap:colormap -> color_name:string -> xColor * xColor = "ml_XAllocNamedColor"
  178. (** the returned values are garbage collected,
  179. {{:http://tronche.com/gui/x/xlib/color/XAllocNamedColor.html}man} *)
  180. external xColor_set_red: xColor -> int -> unit = "ml_XColor_set_red"
  181. external xColor_set_green: xColor -> int -> unit = "ml_XColor_set_green"
  182. external xColor_set_blue: xColor -> int -> unit = "ml_XColor_set_blue"
  183. external xColor_set_rgb: xColor -> r:int -> g:int -> b:int -> unit = "ml_XColor_set_rgb"
  184. type color_flags =
  185. | DoRed
  186. | DoGreen
  187. | DoBlue
  188. external xColor_set_flags: xColor -> color_flags list -> unit = "ml_XColor_set_flags"
  189. #if defined(ML)
  190. type x_color =
  191. { xcolor : xColor;
  192. set_red : int -> unit;
  193. set_green : int -> unit;
  194. set_blue : int -> unit;
  195. }
  196. let new_x_color () =
  197. let xcolor = new_xColor() in
  198. xColor_set_flags xcolor [DoRed; DoGreen; DoBlue];
  199. { xcolor = xcolor;
  200. set_red = xColor_set_red xcolor;
  201. set_green = xColor_set_green xcolor;
  202. set_blue = xColor_set_blue xcolor;
  203. }
  204. #endif
  205. external xAllocColor: dpy:display -> colormap:colormap -> xColor -> unit = "ml_XAllocColor"
  206. (** {{:http://tronche.com/gui/x/xlib/color/XAllocColor.html}man} *)
  207. external xAllocColorCells: dpy:display -> colormap:colormap ->
  208. contig:bool -> nplanes:uint -> npixels:uint -> uint array * uint array = "ml_XAllocColorCells"
  209. (** {{:http://tronche.com/gui/x/xlib/color/XAllocColorCells.html}man},
  210. returns [(plane_masks, pixels)] *)
  211. external xAllocColorCellsPixels: dpy:display -> colormap:colormap ->
  212. contig:bool -> npixels:uint -> uint array = "ml_XAllocColorCellsPixels"
  213. (** same than [xAllocColorCells] but only requests for the pixels *)
  214. external xColor_pixel: xColor -> pixel_color = "ml_XColor_pixel"
  215. external xColor_set_pixel: xColor -> pixel_color -> unit = "ml_XColor_set_pixel"
  216. external xQueryColor: dpy:display -> colormap:colormap -> xColor -> unit = "ml_XQueryColor"
  217. (** {{:http://tronche.com/gui/x/xlib/color/XQueryColor.html}man} *)
  218. external xColor_get_red: xColor -> int = "ml_XColor_get_red"
  219. external xColor_get_green: xColor -> int = "ml_XColor_get_green"
  220. external xColor_get_blue: xColor -> int = "ml_XColor_get_blue"
  221. external xColor_get_rgb: xColor -> int * int * int = "ml_XColor_get_rgb"
  222. (** {3 Visual} *)
  223. type visual
  224. type visualID
  225. external xDefaultVisual: dpy:display -> scr:screen_number -> visual = "ml_XDefaultVisual"
  226. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#DefaultVisual}man} *)
  227. external visual_red_mask: visual:visual -> int = "ml_Visual_red_mask"
  228. external visual_green_mask: visual:visual -> int = "ml_Visual_green_mask"
  229. external visual_blue_mask: visual:visual -> int = "ml_Visual_blue_mask"
  230. external visual_bits_per_rgb: visual:visual -> int = "ml_Visual_bits_per_rgb"
  231. external visual_visualid: visual:visual -> visualID = "ml_Visual_visualid"
  232. external visual_map_entries: visual:visual -> int = "ml_Visual_map_entries"
  233. (** color map entries *)
  234. (** {3 xVisualInfo} *)
  235. (** {{:http://tronche.com/gui/x/xlib/utilities/visual.html}man} *)
  236. type xVisualInfo (* pointer to a structure *)
  237. type xVisualInfo_contents = (* contents of this structure *)
  238. { visual: visual;
  239. visual_id: visualID;
  240. screen_number: screen_number;
  241. depth: int;
  242. red_mask: uint;
  243. green_mask: uint;
  244. blue_mask: uint;
  245. colormap_size: int;
  246. bits_per_rgb: int;
  247. }
  248. external xVisualInfo_datas: visual_info:xVisualInfo -> xVisualInfo_contents = "ml_XVisualInfo_contents"
  249. external xFree_xVisualInfo: xVisualInfo -> unit = "ml_XFree_XVisualInfo"
  250. type color_class =
  251. | StaticGray
  252. | GrayScale
  253. | StaticColor
  254. | PseudoColor
  255. | TrueColor
  256. | DirectColor
  257. external new_xVisualInfo: unit -> xVisualInfo = "ml_alloc_XVisualInfo"
  258. (** do not call {!xFree_xVisualInfo} with this [xVisualInfo] *)
  259. external xVisualInfo_set_visual: visual -> unit = "ml_XVisualInfo_set_visual"
  260. external xVisualInfo_set_visualid: visualID -> unit = "ml_XVisualInfo_set_visualid"
  261. external xVisualInfo_set_screen: screen_number -> unit = "ml_XVisualInfo_set_screen"
  262. external xVisualInfo_set_depth: uint -> unit = "ml_XVisualInfo_set_depth"
  263. external xVisualInfo_set_class: color_class -> unit = "ml_XVisualInfo_set_class"
  264. external xVisualInfo_set_red_mask: uint -> unit = "ml_XVisualInfo_set_red_mask"
  265. external xVisualInfo_set_green_mask: uint -> unit = "ml_XVisualInfo_set_green_mask"
  266. external xVisualInfo_set_blue_mask: uint -> unit = "ml_XVisualInfo_set_blue_mask"
  267. external xVisualInfo_set_colormap_size: int -> unit = "ml_XVisualInfo_set_colormap_size"
  268. external xVisualInfo_set_bits_per_rgb: int -> unit = "ml_XVisualInfo_set_bits_per_rgb"
  269. type visual_info_mask =
  270. | VisualNoMask
  271. | VisualIDMask
  272. | VisualScreenMask
  273. | VisualDepthMask
  274. | VisualClassMask
  275. | VisualRedMaskMask
  276. | VisualGreenMaskMask
  277. | VisualBlueMaskMask
  278. | VisualColormapSizeMask
  279. | VisualBitsPerRGBMask
  280. | VisualAllMask
  281. external xGetVisualInfo: dpy:display -> visual_info_mask list -> template:xVisualInfo -> xVisualInfo array
  282. = "ml_XGetVisualInfo"
  283. (** {{:http://tronche.com/gui/x/xlib/utilities/XGetVisualInfo.html}man} *)
  284. external xMatchVisualInfo: dpy:display -> scr:screen_number -> depth:int -> color_class:color_class -> xVisualInfo
  285. = "ml_XMatchVisualInfo"
  286. (** {{:http://tronche.com/gui/x/xlib/utilities/XMatchVisualInfo.html}man}
  287. no need to call {!xFree_xVisualInfo} on the returned value *)
  288. (** {3 Colormap} *)
  289. external xDefaultColormap: dpy:display -> scr:screen_number -> colormap = "ml_XDefaultColormap"
  290. (** do not free the default colormap,
  291. {{:http://tronche.com/gui/x/xlib/display/display-macros.html#DefaultColormap}man} *)
  292. external xDisplayCells: dpy:display -> scr:screen_number -> int = "ml_XDisplayCells"
  293. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#DisplayCells}man} *)
  294. type colormap_alloc =
  295. | AllocNone
  296. | AllocAll
  297. external xCreateColormap: dpy:display -> win:window -> visual:visual -> alloc:colormap_alloc -> colormap = "ml_XCreateColormap"
  298. (** {{:http://tronche.com/gui/x/xlib/color/XCreateColormap.html}man} *)
  299. external xFreeColormap: dpy:display -> colormap:colormap -> unit = "ml_XFreeColormap"
  300. (** {{:http://tronche.com/gui/x/xlib/color/XFreeColormap.html}man} *)
  301. external xCopyColormapAndFree: dpy:display -> colormap:colormap -> colormap = "ml_XCopyColormapAndFree"
  302. (** {{:http://tronche.com/gui/x/xlib/color/XCopyColormapAndFree.html}man} *)
  303. external xSetWindowColormap: dpy:display -> win:window -> colormap:colormap -> unit = "ml_XSetWindowColormap"
  304. (** {{:http://tronche.com/gui/x/xlib/window/XSetWindowColormap.html}man} *)
  305. (*
  306. XChangeWindowAttributes
  307. *)
  308. (** {4 Managing Installed Colormaps} *)
  309. external xInstallColormap: dpy:display -> colormap:colormap -> unit = "ml_XInstallColormap"
  310. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XInstallColormap.html}man} *)
  311. external xUninstallColormap: dpy:display -> colormap:colormap -> unit = "ml_XUninstallColormap"
  312. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XUninstallColormap.html}man} *)
  313. external xListInstalledColormaps: dpy:display -> win:window -> colormap array = "ml_XListInstalledColormaps"
  314. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XListInstalledColormaps.html}man} *)
  315. (** {4 xSetWindowAttributes} *)
  316. type xSetWindowAttributes
  317. external new_xSetWindowAttributes: unit -> xSetWindowAttributes = "ml_XSetWindowAttributes_alloc"
  318. (** the returned [xSetWindowAttributes] is garbage collected *)
  319. type event_mask_list = event_mask list
  320. type cursor
  321. (* {{{ setting xSetWindowAttributes fields *)
  322. external winAttr_set_background_pixmap: xSetWindowAttributes -> background_pixmap:pixmap -> unit = "ml_xSetWindowAttributes_set_background_pixmap"
  323. external winAttr_set_background_pixel: xSetWindowAttributes -> background_pixel:pixel_color -> unit = "ml_xSetWindowAttributes_set_background_pixel"
  324. external winAttr_set_border_pixmap: xSetWindowAttributes -> border_pixmap:pixmap -> unit = "ml_xSetWindowAttributes_set_border_pixmap"
  325. external winAttr_set_border_pixel: xSetWindowAttributes -> border_pixel:pixel_color -> unit = "ml_xSetWindowAttributes_set_border_pixel"
  326. external winAttr_set_bit_gravity: xSetWindowAttributes -> bit_gravity:int -> unit = "ml_xSetWindowAttributes_set_bit_gravity"
  327. external winAttr_set_win_gravity: xSetWindowAttributes -> win_gravity:int -> unit = "ml_xSetWindowAttributes_set_win_gravity"
  328. external winAttr_set_backing_store: xSetWindowAttributes -> backing_store:int -> unit = "ml_xSetWindowAttributes_set_backing_store"
  329. external winAttr_set_backing_planes: xSetWindowAttributes -> backing_planes:uint -> unit = "ml_xSetWindowAttributes_set_backing_planes"
  330. external winAttr_set_backing_pixel: xSetWindowAttributes -> backing_pixel:uint -> unit = "ml_xSetWindowAttributes_set_backing_pixel"
  331. external winAttr_set_save_under: xSetWindowAttributes -> save_under:bool -> unit = "ml_xSetWindowAttributes_set_save_under"
  332. external winAttr_set_event_mask: xSetWindowAttributes -> event_mask:event_mask_list -> unit = "ml_xSetWindowAttributes_set_event_mask"
  333. external winAttr_set_do_not_propagate_mask: xSetWindowAttributes -> do_not_propagate_mask:int -> unit = "ml_xSetWindowAttributes_set_do_not_propagate_mask"
  334. external winAttr_set_override_redirect: xSetWindowAttributes -> override_redirect:bool -> unit = "ml_xSetWindowAttributes_set_override_redirect"
  335. external winAttr_set_colormap: xSetWindowAttributes -> colormap:colormap -> unit = "ml_xSetWindowAttributes_set_colormap"
  336. external winAttr_set_cursor: xSetWindowAttributes -> cursor:cursor -> unit = "ml_xSetWindowAttributes_set_cursor"
  337. (* }}} *)
  338. type set_win_attr = {
  339. attr : xSetWindowAttributes;
  340. set_background_pixmap: background_pixmap:pixmap -> unit;
  341. set_background_pixel: background_pixel:pixel_color -> unit;
  342. set_border_pixmap: border_pixmap:pixmap -> unit;
  343. set_border_pixel: border_pixel:pixel_color -> unit;
  344. set_bit_gravity: bit_gravity:int -> unit;
  345. set_win_gravity: win_gravity:int -> unit;
  346. set_backing_store: backing_store:int -> unit;
  347. set_backing_planes: backing_planes:uint -> unit;
  348. set_backing_pixel: backing_pixel:uint -> unit;
  349. set_save_under: save_under:bool -> unit;
  350. set_event_mask: event_mask:event_mask_list -> unit;
  351. set_do_not_propagate_mask: do_not_propagate_mask:int -> unit;
  352. set_override_redirect: override_redirect:bool -> unit;
  353. set_colormap: colormap:colormap -> unit;
  354. set_cursor: cursor:cursor -> unit;
  355. }
  356. (** a record to replace all the [winAttr_set_*] functions *)
  357. #if defined(ML)
  358. let new_win_attr () =
  359. let wa = new_xSetWindowAttributes() in
  360. { attr = wa;
  361. set_background_pixmap = winAttr_set_background_pixmap wa;
  362. set_background_pixel = winAttr_set_background_pixel wa;
  363. set_border_pixmap = winAttr_set_border_pixmap wa;
  364. set_border_pixel = winAttr_set_border_pixel wa;
  365. set_bit_gravity = winAttr_set_bit_gravity wa;
  366. set_win_gravity = winAttr_set_win_gravity wa;
  367. set_backing_store = winAttr_set_backing_store wa;
  368. set_backing_planes = winAttr_set_backing_planes wa;
  369. set_backing_pixel = winAttr_set_backing_pixel wa;
  370. set_save_under = winAttr_set_save_under wa;
  371. set_event_mask = winAttr_set_event_mask wa;
  372. set_do_not_propagate_mask = winAttr_set_do_not_propagate_mask wa;
  373. set_override_redirect = winAttr_set_override_redirect wa;
  374. set_colormap = winAttr_set_colormap wa;
  375. set_cursor = winAttr_set_cursor wa;
  376. }
  377. #else
  378. val new_win_attr: unit -> set_win_attr
  379. (** replaces [new_xSetWindowAttributes],
  380. this one is supposed to produce more concise code *)
  381. #endif
  382. (** {3 Windows} *)
  383. external xRootWindow: dpy:display -> scr:screen_number -> window = "ml_XRootWindow"
  384. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#RootWindow}man} *)
  385. external xDefaultRootWindow: dpy:display -> window = "ml_XDefaultRootWindow"
  386. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#DefaultRootWindow}man} *)
  387. #if defined(ML)
  388. let root_win ~dpy ?scr () =
  389. let scr =
  390. match scr with Some scr -> scr
  391. | None -> xDefaultScreen ~dpy
  392. in
  393. let win = xRootWindow ~dpy ~scr in
  394. (win)
  395. ;;
  396. #else
  397. val root_win: dpy:display -> ?scr:screen_number -> unit -> window
  398. (** alternative for [xRootWindow] and [xDefaultRootWindow] *)
  399. #endif
  400. external xCreateSimpleWindow: dpy:display -> parent:window -> x:int -> y:int ->
  401. width:uint -> height:uint -> border_width:uint ->
  402. border_color:pixel_color -> background:pixel_color -> window
  403. = "ml_XCreateSimpleWindow_bytecode"
  404. "ml_XCreateSimpleWindow"
  405. (** {{:http://tronche.com/gui/x/xlib/window/XCreateWindow.html}man} *)
  406. #if defined(ML)
  407. let simple_window ~dpy
  408. ?(parent) ?(x=0) ?(y=0)
  409. ?(width=0xFF) ?(height=0xFF) ?(border_width=0x01)
  410. ?(border_color) ?(background) ()
  411. =
  412. let d, s = dpy, xDefaultScreen dpy in
  413. let parent =
  414. match parent with Some v -> v | None -> xRootWindow d s
  415. and border_color =
  416. match border_color with Some v -> v | None -> xBlackPixel d s
  417. and background =
  418. match background with Some v -> v | None -> xWhitePixel d s
  419. in
  420. xCreateSimpleWindow
  421. ~dpy ~parent
  422. ~x ~y ~width ~height
  423. ~border_width ~border_color
  424. ~background
  425. ;;
  426. (** returns a window with eventually defaut parameters (wip) *)
  427. #else
  428. val simple_window: dpy:display -> ?parent:window -> ?x:int -> ?y:int ->
  429. ?width:uint -> ?height:uint -> ?border_width:uint ->
  430. ?border_color:pixel_color -> ?background:pixel_color -> unit -> window
  431. (** returns a window with eventually defaut parameters (wip) *)
  432. #endif
  433. external xDestroyWindow: dpy:display -> win:window -> unit = "ml_XDestroyWindow"
  434. (** {{:http://tronche.com/gui/x/xlib/window/XDestroyWindow.html}man} *)
  435. external xid: int -> 'a = "caml_get_xid"
  436. (** some magic *)
  437. external xStoreName: dpy:display -> win:window -> name:string -> unit = "ml_XStoreName"
  438. (** {{:http://tronche.com/gui/x/xlib/ICC/client-to-window-manager/XStoreName.html}man} *)
  439. (* TODO test this function XXX *)
  440. external xFetchName: dpy:display -> win:window -> string = "ml_XFetchName"
  441. (** {{:http://tronche.com/gui/x/xlib/ICC/client-to-window-manager/XFetchName.html}man} *)
  442. external xSelectInput: dpy:display -> win:window -> event_mask:event_mask list -> unit = "ml_XSelectInput"
  443. external xMapWindow: dpy:display -> win:window -> unit = "ml_XMapWindow"
  444. (** {{:http://tronche.com/gui/x/xlib/window/XMapWindow.html}man} *)
  445. external xMapSubwindows: dpy:display -> win:window -> unit = "ml_XMapSubwindows"
  446. (** {{:http://tronche.com/gui/x/xlib/window/XMapSubwindows.html}man} *)
  447. external xMapRaised: dpy:display -> win:window -> unit = "ml_XMapRaised"
  448. (** {{:http://tronche.com/gui/x/xlib/window/XMapRaised.html}man} *)
  449. external xUnmapWindow: dpy:display -> win:window -> unit = "ml_XUnmapWindow"
  450. (** {{:http://tronche.com/gui/x/xlib/window/XUnmapWindow.html}man} *)
  451. (*
  452. typedef struct {
  453. int x, y;
  454. int width, height;
  455. int border_width;
  456. Window sibling;
  457. int stack_mode; // Above, Below, TopIf, BottomIf, Opposite (* xconfreq_detail *)
  458. } XWindowChanges;
  459. /* Configure window value mask bits */
  460. #define CWX (1<<0)
  461. #define CWY (1<<1)
  462. #define CWWidth (1<<2)
  463. #define CWHeight (1<<3)
  464. #define CWBorderWidth (1<<4)
  465. #define CWSibling (1<<5)
  466. #define CWStackMode (1<<6)
  467. int XConfigureWindow(
  468. Display* /* display */,
  469. Window /* w */,
  470. unsigned int /* value_mask */,
  471. XWindowChanges* /* values */
  472. );
  473. (** {{:http://tronche.com/gui/x/xlib/window/XConfigureWindow.html}man} *)
  474. Status XReconfigureWMWindow(
  475. Display* /* display */,
  476. Window /* w */,
  477. int /* screen_number */,
  478. unsigned int /* mask */,
  479. XWindowChanges* /* changes */
  480. );
  481. *)
  482. type window_class =
  483. | CopyFromParent
  484. | InputOutput
  485. | InputOnly
  486. type winattr_valuemask =
  487. | CWBackPixmap
  488. | CWBackPixel
  489. | CWBorderPixmap
  490. | CWBorderPixel
  491. | CWBitGravity
  492. | CWWinGravity
  493. | CWBackingStore
  494. | CWBackingPlanes
  495. | CWBackingPixel
  496. | CWOverrideRedirect
  497. | CWSaveUnder
  498. | CWEventMask
  499. | CWDontPropagate
  500. | CWColormap
  501. | CWCursor
  502. external xCreateWindow:
  503. dpy:display -> parent:window -> x:int -> y:int ->
  504. width:uint -> height:uint ->
  505. border_width:uint ->
  506. depth:int -> win_class:window_class -> visual:visual ->
  507. valuemask:winattr_valuemask list ->
  508. attributes:xSetWindowAttributes -> window
  509. = "ml_XCreateWindow_bytecode" "ml_XCreateWindow"
  510. (** {{:http://tronche.com/gui/x/xlib/window/XCreateWindow.html}man} *)
  511. (* {{{ create_window *)
  512. type winattr =
  513. | BackPixmap of pixmap
  514. | BackPixel of pixel_color
  515. | BorderPixmap of pixmap
  516. | BorderPixel of pixel_color
  517. | BitGravity of int
  518. | WinGravity of int
  519. | BackingStore of int
  520. | BackingPlanes of uint
  521. | BackingPixel of uint
  522. | OverrideRedirect of bool
  523. | SaveUnder of bool
  524. | EventMask of event_mask_list
  525. | DontPropagate of int
  526. | Colormap of colormap
  527. | Cursor of cursor
  528. #if defined(ML)
  529. let create_window ~dpy ~parent ~x ~y ~width ~height
  530. ~border_width ~depth ~win_class ~visual
  531. ~win_attrs =
  532. let wa = new_xSetWindowAttributes() in
  533. let valuemask =
  534. List.map (function
  535. | BackPixmap pixmap -> winAttr_set_background_pixmap wa pixmap ; CWBackPixmap
  536. | BackPixel background_pixel -> winAttr_set_background_pixel wa background_pixel ; CWBackPixel
  537. | BorderPixmap border_pixmap -> winAttr_set_border_pixmap wa border_pixmap ; CWBorderPixmap
  538. | BorderPixel border_pixel -> winAttr_set_border_pixel wa border_pixel ; CWBorderPixel
  539. | BitGravity bit_gravity -> winAttr_set_bit_gravity wa bit_gravity ; CWBitGravity
  540. | WinGravity win_gravity -> winAttr_set_win_gravity wa win_gravity ; CWWinGravity
  541. | BackingStore backing_store -> winAttr_set_backing_store wa backing_store ; CWBackingStore
  542. | BackingPlanes backing_planes -> winAttr_set_backing_planes wa backing_planes ; CWBackingPlanes
  543. | BackingPixel backing_pixel -> winAttr_set_backing_pixel wa backing_pixel ; CWBackingPixel
  544. | OverrideRedirect override_redirect -> winAttr_set_override_redirect wa override_redirect ; CWOverrideRedirect
  545. | SaveUnder save_under -> winAttr_set_save_under wa save_under ; CWSaveUnder
  546. | EventMask event_mask -> winAttr_set_event_mask wa event_mask ; CWEventMask
  547. | DontPropagate dont_propagate -> winAttr_set_do_not_propagate_mask wa dont_propagate; CWDontPropagate
  548. | Colormap colormap -> winAttr_set_colormap wa colormap ; CWColormap
  549. | Cursor cursor -> winAttr_set_cursor wa cursor ; CWCursor
  550. ) win_attrs
  551. in
  552. xCreateWindow
  553. ~dpy ~parent ~x ~y ~width ~height ~border_width
  554. ~depth ~win_class ~visual
  555. ~valuemask
  556. ~attributes:wa ;;
  557. #else
  558. val create_window:
  559. dpy:display -> parent:window -> x:int -> y:int ->
  560. width:uint -> height:uint ->
  561. border_width:uint ->
  562. depth:int -> win_class:window_class -> visual:visual ->
  563. win_attrs:winattr list -> window
  564. (** equivalent of [xCreateWindow] *)
  565. #endif
  566. (* }}} *)
  567. external xResizeWindow: dpy:display -> win:window -> width:uint -> height:uint -> unit = "ml_XResizeWindow"
  568. (** {{:http://tronche.com/gui/x/xlib/window/XResizeWindow.html}man} *)
  569. external xMoveWindow: dpy:display -> win:window -> x:int -> y:int -> unit = "ml_XMoveWindow"
  570. (** {{:http://tronche.com/gui/x/xlib/window/XMoveWindow.html}man} *)
  571. external xMoveResizeWindow: dpy:display -> win:window -> x:int -> y:int -> width:uint -> height:uint -> unit
  572. = "ml_XMoveResizeWindow_bytecode" "ml_XMoveResizeWindow"
  573. (** {{:http://tronche.com/gui/x/xlib/window/XMoveResizeWindow.html}man} *)
  574. external xLowerWindow: dpy:display -> win:window -> unit = "ml_XLowerWindow"
  575. (** {{:http://tronche.com/gui/x/xlib/window/XLowerWindow.html}man} *)
  576. external xRaiseWindow: dpy:display -> win:window -> unit = "ml_XRaiseWindow"
  577. (** {{:http://tronche.com/gui/x/xlib/window/XRaiseWindow.html}man} *)
  578. external xQueryTree: dpy:display -> win:window -> window * window * window array = "ml_XQueryTree"
  579. (** {{:http://tronche.com/gui/x/xlib/window-information/XQueryTree.html}man},
  580. returns [(root_window, parent_window, children_windows)] *)
  581. external xRestackWindows: dpy:display -> win:window array -> unit = "ml_XRestackWindows"
  582. (** {{:http://tronche.com/gui/x/xlib/window/XRestackWindows.html}man} *)
  583. external xCirculateSubwindowsDown: dpy:display -> win:window -> unit = "ml_XCirculateSubwindowsDown"
  584. external xCirculateSubwindowsUp: dpy:display -> win:window -> unit = "ml_XCirculateSubwindowsUp"
  585. type circulate_subwindows_direction = RaiseLowest | LowerHighest
  586. external xCirculateSubwindows: dpy:display -> win:window -> dir:circulate_subwindows_direction -> unit
  587. = "ml_XCirculateSubwindows"
  588. type req_type = Atom of atom | AnyPropertyType
  589. external xGetWindowProperty_string:
  590. dpy:display ->
  591. win:window ->
  592. property:atom ->
  593. long_offset:int ->
  594. long_length:int ->
  595. delete:bool ->
  596. req_type:req_type ->
  597. atom * (* actual_type *)
  598. int * (* actual_format *)
  599. int * (* nitems *)
  600. int * (* bytes_after *)
  601. string (* prop_return *)
  602. = "ml_XGetWindowProperty_string_bytecode"
  603. "ml_XGetWindowProperty_string"
  604. external xGetWindowProperty_window:
  605. dpy:display ->
  606. win:window ->
  607. property:atom ->
  608. long_offset:int ->
  609. long_length:int ->
  610. delete:bool ->
  611. req_type:req_type ->
  612. atom * (* actual_type *)
  613. int * (* actual_format *)
  614. int * (* nitems *)
  615. int * (* bytes_after *)
  616. window (* prop_return *)
  617. = "ml_XGetWindowProperty_window_bytecode"
  618. "ml_XGetWindowProperty_window"
  619. (** {{:http://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html}man} *)
  620. (** {3 XScreen} *)
  621. type xScreen
  622. (** this type wraps the scruture Screen from the Xlib, but is here renamed with
  623. an additionnal x as a way of disambiguation with the type [screen_number] *)
  624. external xDefaultScreenOfDisplay: dpy:display -> xScreen = "ml_XDefaultScreenOfDisplay"
  625. (** the result points to a member of the input structure *)
  626. external xScreenOfDisplay: dpy:display -> scr:screen_number -> xScreen = "ml_XScreenOfDisplay"
  627. external xDefaultVisualOfScreen: xScreen -> visual = "ml_XDefaultVisualOfScreen"
  628. (** the result points to a member of the input structure *)
  629. external xRootWindowOfScreen: xScreen -> window = "ml_XRootWindowOfScreen"
  630. external xBlackPixelOfScreen: xScreen -> pixel_color = "ml_XBlackPixelOfScreen"
  631. external xWhitePixelOfScreen: xScreen -> pixel_color = "ml_XWhitePixelOfScreen"
  632. external xDefaultColormapOfScreen: xScreen -> colormap = "ml_XDefaultColormapOfScreen"
  633. external xDefaultDepthOfScreen: xScreen -> int = "ml_XDefaultDepthOfScreen"
  634. external xDefaultGCOfScreen: xScreen -> gc = "ml_XDefaultGCOfScreen"
  635. external xDisplayOfScreen: xScreen -> display = "ml_XDisplayOfScreen"
  636. external xWidthOfScreen: xScreen -> int = "ml_XWidthOfScreen"
  637. external xHeightOfScreen: xScreen -> int = "ml_XHeightOfScreen"
  638. external xScreenNumberOfScreen: xScreen -> screen_number = "ml_XScreenNumberOfScreen"
  639. (** {3 xWindowAttributes} *)
  640. type xWindowAttributes
  641. (** xWindowAttributes is garbage collected *)
  642. external xGetWindowAttributes: dpy:display -> win:window -> xWindowAttributes = "ml_XGetWindowAttributes"
  643. (** {{:http://tronche.com/gui/x/xlib/window-information/XGetWindowAttributes.html}man} *)
  644. external xWindowAttributes_x: xWindowAttributes -> int = "ml_XWindowAttributes_x"
  645. external xWindowAttributes_y: xWindowAttributes -> int = "ml_XWindowAttributes_y"
  646. external xWindowAttributes_width: xWindowAttributes -> int = "ml_XWindowAttributes_width"
  647. external xWindowAttributes_height: xWindowAttributes -> int = "ml_XWindowAttributes_height"
  648. external xWindowAttributes_depth: xWindowAttributes -> int = "ml_XWindowAttributes_depth"
  649. external xWindowAttributes_screen: xWindowAttributes -> xScreen = "ml_XWindowAttributes_screen"
  650. external xWindowAttributes_border_width: xWindowAttributes -> int = "ml_XWindowAttributes_border_width"
  651. external xWindowAttributes_colormap: xWindowAttributes -> colormap = "ml_XWindowAttributes_colormap"
  652. external xWindowAttributes_map_installed: xWindowAttributes -> bool = "ml_XWindowAttributes_map_installed"
  653. type wattr = {
  654. wattr_x: int;
  655. wattr_y: int;
  656. wattr_width: int;
  657. wattr_height: int;
  658. wattr_depth: int;
  659. }
  660. (** a record to replace all the [xWindowAttributes_*] functions *)
  661. #if defined(ML)
  662. external xGetWindowAttributesAll: dpy:display -> win:window -> wattr = "ml_XWindowAttributes_all"
  663. let get_win_attrs = xGetWindowAttributesAll
  664. #else
  665. val get_win_attrs : dpy:display -> win:window -> wattr
  666. (** replaces [xGetWindowAttributes],
  667. this one is supposed to produce more concise code *)
  668. #endif
  669. type wattrs = {
  670. winat_x: unit -> int;
  671. winat_y: unit -> int;
  672. winat_width: unit -> int;
  673. winat_height: unit -> int;
  674. winat_depth: unit -> int;
  675. winat_screen: unit -> xScreen;
  676. winat_border_width: unit -> int;
  677. winat_colormap: unit -> colormap;
  678. winat_map_installed: unit -> bool;
  679. }
  680. (** another record to replace all the [xWindowAttributes_*] functions *)
  681. #if defined(ML)
  682. let win_attrs ~dpy ~win =
  683. let xwa = xGetWindowAttributes ~dpy ~win in
  684. {
  685. winat_x = (fun () -> xWindowAttributes_x xwa);
  686. winat_y = (fun () -> xWindowAttributes_y xwa);
  687. winat_width = (fun () -> xWindowAttributes_width xwa);
  688. winat_height = (fun () -> xWindowAttributes_height xwa);
  689. winat_depth = (fun () -> xWindowAttributes_depth xwa);
  690. winat_screen = (fun () -> xWindowAttributes_screen xwa);
  691. winat_border_width = (fun () -> xWindowAttributes_border_width xwa);
  692. winat_colormap = (fun () -> xWindowAttributes_colormap xwa);
  693. winat_map_installed = (fun () -> xWindowAttributes_map_installed xwa);
  694. }
  695. #else
  696. val win_attrs : dpy:display -> win:window -> wattrs
  697. (** another replacement for [xWindowAttributes] functions *)
  698. #endif
  699. (** {3 XSizeHints} *)
  700. type xSizeHints
  701. external new_xSizeHints: unit -> xSizeHints = "ml_alloc_XSizeHints"
  702. (** this type is garbage collected *)
  703. external xSizeHints_set_USPosition: xSizeHints -> x:int -> y:int -> unit = "ml_XSizeHints_set_USPosition"
  704. external xSizeHints_set_USSize: xSizeHints -> width:int -> height:int -> unit = "ml_XSizeHints_set_USSize"
  705. external xSizeHints_set_PPosition: xSizeHints -> x:int -> y:int -> unit = "ml_XSizeHints_set_PPosition"
  706. external xSizeHints_set_PSize: xSizeHints -> width:int -> height:int -> unit = "ml_XSizeHints_set_PSize"
  707. external xSizeHints_set_PMinSize: xSizeHints -> width:int -> height:int -> unit = "ml_XSizeHints_set_PMinSize"
  708. external xSizeHints_set_PMaxSize: xSizeHints -> width:int -> height:int -> unit = "ml_XSizeHints_set_PMaxSize"
  709. external xSizeHints_set_PResizeInc: xSizeHints -> width_inc:int -> height_inc:int -> unit = "ml_XSizeHints_set_PResizeInc"
  710. external xSizeHints_set_PBaseSize: xSizeHints -> base_width:int -> base_height:int -> unit = "ml_XSizeHints_set_PBaseSize"
  711. external xSizeHints_set_PAspect: xSizeHints -> min_aspect:int * int -> max_aspect:int * int -> unit = "ml_XSizeHints_set_PAspect"
  712. external xSizeHints_set_PWinGravity: xSizeHints -> win_gravity:int -> unit = "ml_XSizeHints_set_PWinGravity"
  713. external xSetNormalHints: dpy:display -> win:window -> hints:xSizeHints -> unit = "ml_XSetNormalHints"
  714. external xSetStandardProperties: dpy:display -> win:window -> window_name:string -> icon_name:string ->
  715. icon_pixmap:pixmap option -> argv:string array -> hints:xSizeHints -> unit
  716. = "ml_XSetStandardProperties_bytecode"
  717. "ml_XSetStandardProperties"
  718. type set_size_hints = {
  719. hints: xSizeHints;
  720. set_USPosition: x:int -> y:int -> unit;
  721. set_USSize: width:int -> height:int -> unit;
  722. set_PPosition: x:int -> y:int -> unit;
  723. set_PSize: width:int -> height:int -> unit;
  724. set_PMinSize: width:int -> height:int -> unit;
  725. set_PMaxSize: width:int -> height:int -> unit;
  726. set_PResizeInc: width_inc:int -> height_inc:int -> unit;
  727. set_PBaseSize: base_width:int -> base_height:int -> unit;
  728. set_PAspect: min_aspect:int * int -> max_aspect:int * int -> unit;
  729. set_PWinGravity: win_gravity:int -> unit;
  730. }
  731. (** a record to replace all the [xSizeHints_set_*] functions *)
  732. #if defined(ML)
  733. let new_size_hints () =
  734. let sh = new_xSizeHints() in
  735. { hints = sh;
  736. set_USPosition = xSizeHints_set_USPosition sh;
  737. set_USSize = xSizeHints_set_USSize sh;
  738. set_PPosition = xSizeHints_set_PPosition sh;
  739. set_PSize = xSizeHints_set_PSize sh;
  740. set_PMinSize = xSizeHints_set_PMinSize sh;
  741. set_PMaxSize = xSizeHints_set_PMaxSize sh;
  742. set_PResizeInc = xSizeHints_set_PResizeInc sh;
  743. set_PBaseSize = xSizeHints_set_PBaseSize sh;
  744. set_PAspect = xSizeHints_set_PAspect sh;
  745. set_PWinGravity = xSizeHints_set_PWinGravity sh;
  746. }
  747. #else
  748. val new_size_hints : unit -> set_size_hints
  749. (** replaces [new_xSizeHints] *)
  750. #endif
  751. (** a variant to replace all the [xSizeHints_set_*] functions *)
  752. type size_hints =
  753. | USPosition of int * int
  754. | USSize of int * int (** (width, height) *)
  755. | PPosition of int * int
  756. | PSize of int * int
  757. | PMinSize of int * int
  758. | PMaxSize of int * int
  759. | PResizeInc of int * int
  760. | PBaseSize of int * int
  761. | PAspect of (int * int) * (int * int)
  762. | PWinGravity of int
  763. #if defined(ML)
  764. let set_normal_hints ~dpy ~win ~hints =
  765. let sh = new_xSizeHints() in
  766. List.iter (function
  767. | USPosition(x, y) -> xSizeHints_set_USPosition sh x y;
  768. | USSize(width, height) -> xSizeHints_set_USSize sh width height;
  769. | PPosition(x, y) -> xSizeHints_set_PPosition sh x y;
  770. | PSize(width, height) -> xSizeHints_set_PSize sh width height;
  771. | PMinSize(width, height) -> xSizeHints_set_PMinSize sh width height;
  772. | PMaxSize(width, height) -> xSizeHints_set_PMaxSize sh width height;
  773. | PResizeInc(width_inc, height_inc) -> xSizeHints_set_PResizeInc sh width_inc height_inc;
  774. | PBaseSize(base_width, base_height) -> xSizeHints_set_PBaseSize sh base_width base_height;
  775. | PAspect(min_aspect, max_aspect) -> xSizeHints_set_PAspect sh min_aspect max_aspect;
  776. | PWinGravity(win_gravity) -> xSizeHints_set_PWinGravity sh win_gravity;
  777. ) hints;
  778. xSetNormalHints ~dpy ~win ~hints:sh ;;
  779. #else
  780. val set_normal_hints: dpy:display -> win:window -> hints:size_hints list -> unit
  781. (** replaces [xSetNormalHints] *)
  782. #endif
  783. #if defined(ML)
  784. let set_standard_properties ~dpy ~win ~window_name ~icon_name
  785. ~icon_pixmap ~argv ~hints =
  786. let sh = new_xSizeHints() in
  787. List.iter (function
  788. | USPosition(x, y) -> xSizeHints_set_USPosition sh x y;
  789. | USSize(width, height) -> xSizeHints_set_USSize sh width height;
  790. | PPosition(x, y) -> xSizeHints_set_PPosition sh x y;
  791. | PSize(width, height) -> xSizeHints_set_PSize sh width height;
  792. | PMinSize(width, height) -> xSizeHints_set_PMinSize sh width height;
  793. | PMaxSize(width, height) -> xSizeHints_set_PMaxSize sh width height;
  794. | PResizeInc(width_inc, height_inc) -> xSizeHints_set_PResizeInc sh width_inc height_inc;
  795. | PBaseSize(base_width, base_height) -> xSizeHints_set_PBaseSize sh base_width base_height;
  796. | PAspect(min_aspect, max_aspect) -> xSizeHints_set_PAspect sh min_aspect max_aspect;
  797. | PWinGravity(win_gravity) -> xSizeHints_set_PWinGravity sh win_gravity;
  798. ) hints;
  799. xSetStandardProperties ~dpy ~win ~window_name ~icon_name
  800. ~icon_pixmap ~argv ~hints:sh ;;
  801. #else
  802. val set_standard_properties: dpy:display -> win:window -> window_name:string -> icon_name:string ->
  803. icon_pixmap:pixmap option -> argv:string array -> hints:size_hints list -> unit
  804. (** replaces [xSetStandardProperties] *)
  805. #endif
  806. (** {3 XEvents} *)
  807. type 'a xEvent
  808. type event_type =
  809. | KeyPress
  810. | KeyRelease
  811. | ButtonPress
  812. | ButtonRelease
  813. | MotionNotify
  814. | EnterNotify
  815. | LeaveNotify
  816. | FocusIn
  817. | FocusOut
  818. | KeymapNotify
  819. | Expose
  820. | GraphicsExpose
  821. | NoExpose
  822. | VisibilityNotify
  823. | CreateNotify
  824. | DestroyNotify
  825. | UnmapNotify
  826. | MapNotify
  827. | MapRequest
  828. | ReparentNotify
  829. | ConfigureNotify
  830. | ConfigureRequest
  831. | GravityNotify
  832. | ResizeRequest
  833. | CirculateNotify
  834. | CirculateRequest
  835. | PropertyNotify
  836. | SelectionClear
  837. | SelectionRequest
  838. | SelectionNotify
  839. | ColormapNotify
  840. | ClientMessage
  841. | MappingNotify
  842. type any
  843. type xKeyEvent
  844. type xButtonEvent
  845. type xMotionEvent
  846. type xCrossingEvent
  847. type xFocusChangeEvent
  848. type xExposeEvent
  849. type xGraphicsExposeEvent
  850. type xNoExposeEvent
  851. type xVisibilityEvent
  852. type xCreateWindowEvent
  853. type xDestroyWindowEvent
  854. type xUnmapEvent
  855. type xMapEvent
  856. type xMapRequestEvent
  857. type xReparentEvent
  858. type xConfigureEvent
  859. type xGravityEvent
  860. type xResizeRequestEvent
  861. type xConfigureRequestEvent
  862. type xCirculateEvent
  863. type xCirculateRequestEvent
  864. type xPropertyEvent
  865. type xSelectionClearEvent
  866. type xSelectionRequestEvent
  867. type xSelectionEvent
  868. type xColormapEvent
  869. type xClientMessageEvent
  870. type xMappingEvent
  871. type xErrorEvent
  872. type xKeymapEvent
  873. type xKeyPressedEvent = xKeyEvent
  874. type xKeyReleasedEvent = xKeyEvent
  875. type xButtonPressedEvent = xButtonEvent
  876. type xButtonReleasedEvent = xButtonEvent
  877. type xEnterWindowEvent = xCrossingEvent
  878. type xLeaveWindowEvent = xCrossingEvent
  879. type xFocusInEvent = xFocusChangeEvent
  880. type xFocusOutEvent = xFocusChangeEvent
  881. type event_kind =
  882. | XKeyPressedEvent of xKeyPressedEvent xEvent
  883. | XKeyReleasedEvent of xKeyReleasedEvent xEvent
  884. | XButtonPressedEvent of xButtonPressedEvent xEvent
  885. | XButtonReleasedEvent of xButtonReleasedEvent xEvent
  886. | XMotionEvent of xMotionEvent xEvent
  887. | XCrossingEvent of xCrossingEvent xEvent
  888. | XFocusChangeEvent of xFocusChangeEvent xEvent
  889. | XExposeEvent of xExposeEvent xEvent
  890. | XGraphicsExposeEvent of xGraphicsExposeEvent xEvent
  891. | XNoExposeEvent of xNoExposeEvent xEvent
  892. | XVisibilityEvent of xVisibilityEvent xEvent
  893. | XCreateWindowEvent of xCreateWindowEvent xEvent
  894. | XDestroyWindowEvent of xDestroyWindowEvent xEvent
  895. | XUnmapEvent of xUnmapEvent xEvent
  896. | XMapEvent of xMapEvent xEvent
  897. | XMapRequestEvent of xMapRequestEvent xEvent
  898. | XReparentEvent of xReparentEvent xEvent
  899. | XConfigureEvent of xConfigureEvent xEvent
  900. | XGravityEvent of xGravityEvent xEvent
  901. | XResizeRequestEvent of xResizeRequestEvent xEvent
  902. | XConfigureRequestEvent of xConfigureRequestEvent xEvent
  903. | XCirculateEvent of xCirculateEvent xEvent
  904. | XCirculateRequestEvent of xCirculateRequestEvent xEvent
  905. | XPropertyEvent of xPropertyEvent xEvent
  906. | XSelectionClearEvent of xSelectionClearEvent xEvent
  907. | XSelectionRequestEvent of xSelectionRequestEvent xEvent
  908. | XSelectionEvent of xSelectionEvent xEvent
  909. | XColormapEvent of xColormapEvent xEvent
  910. | XClientMessageEvent of xClientMessageEvent xEvent
  911. | XMappingEvent of xMappingEvent xEvent
  912. | XErrorEvent of xErrorEvent xEvent
  913. | XKeymapEvent of xKeymapEvent xEvent
  914. external new_xEvent: unit -> any xEvent = "ml_alloc_XEvent"
  915. (** the return value is garbage collected *)
  916. external xNextEvent: dpy:display -> event:any xEvent -> unit = "ml_XNextEvent"
  917. (** {{:http://tronche.com/gui/x/xlib/event-handling/manipulating-event-queue/XNextEvent.html}man}
  918. this function modifies the [event] parameter, which is supposed to come from
  919. the function [new_xEvent]. *)
  920. external xNextEventFun: dpy:display -> any xEvent = "ml_XNextEvent_fun"
  921. (** This function is supposed to replace the functions [new_xEvent] and [xNextEvent],
  922. in order to produce more functional code. The tradeoff is that there is a
  923. new allocation of the xEvent structure at each call. *)
  924. external xPeekEvent: dpy:display -> event:any xEvent -> unit = "ml_XPeekEvent"
  925. (** {{:http://tronche.com/gui/x/xlib/event-handling/manipulating-event-queue/XPeekEvent.html}man} *)
  926. external xMaskEvent: dpy:display -> event_mask list -> any xEvent -> unit = "ml_XMaskEvent"
  927. (** {{:http://tronche.com/gui/x/xlib/event-handling/manipulating-event-queue/XMaskEvent.html}man} *)
  928. (* TODO s/'a/any/ ??? *)
  929. (* TODO s/xWindowEvent/xWindowEventFun/ ??? *)
  930. external xWindowEvent: dpy:display -> win:window -> event_mask list -> 'a xEvent = "ml_XWindowEvent"
  931. (** {{:http://tronche.com/gui/x/xlib/event-handling/manipulating-event-queue/XWindowEvent.html}man} *)
  932. external xPending: dpy:display -> int = "ml_XPending"
  933. (** {{:http://tronche.com/gui/x/xlib/event-handling/XPending.html}man} *)
  934. type event_mode =
  935. | AsyncPointer
  936. | SyncPointer
  937. | AsyncKeyboard
  938. | SyncKeyboard
  939. | ReplayPointer
  940. | ReplayKeyboard
  941. | AsyncBoth
  942. | SyncBoth
  943. external xAllowEvents: dpy:display -> event_mode:event_mode -> time:time -> unit = "ml_XAllowEvents"
  944. (** {{:http://tronche.com/gui/x/xlib/input/XAllowEvents.html}man} *)
  945. (*
  946. extern int XIfEvent(
  947. Display* /* display */,
  948. XEvent* /* event_return */,
  949. Bool ( * ) (
  950. Display* /* display */,
  951. XEvent* /* event */,
  952. XPointer /* arg */
  953. ) /* predicate */,
  954. XPointer /* arg */
  955. );
  956. (** {{:http://tronche.com/gui/x/xlib/event-handling/manipulating-event-queue/XIfEvent.html}man},
  957. {{:http://tronche.com/gui/x/xlib/event-handling/manipulating-event-queue/selecting-using-predicate.html}man}
  958. *)
  959. *)
  960. external xPutBackEvent: dpy:display -> event:'a xEvent -> unit = "ml_XPutBackEvent"
  961. (** {{:http://tronche.com/gui/x/xlib/event-handling/XPutBackEvent.html}man} *)
  962. (*
  963. Status XSendEvent(
  964. Display* /* display */,
  965. Window /* w */,
  966. Bool /* propagate */,
  967. long /* event_mask */,
  968. XEvent* /* event_send */
  969. );
  970. (** {{:http://tronche.com/gui/x/xlib/event-handling/XSendEvent.html}man} *)
  971. *)
  972. type queued_mode =
  973. | QueuedAlready
  974. | QueuedAfterFlush
  975. | QueuedAfterReading
  976. external xEventsQueued: dpy:display -> mode:queued_mode -> int = "ml_XEventsQueued"
  977. (** {{:http://tronche.com/gui/x/xlib/event-handling/XEventsQueued.html}man} *)
  978. external xCheckTypedEvent: dpy:display -> event_type -> any xEvent -> bool = "ml_XCheckTypedEvent"
  979. (** {{:http://tronche.com/gui/x/xlib/event-handling/manipulating-event-queue/XCheckTypedEvent.html}man},
  980. this function is imperative: the xEvent provided is modified, so is a returned value too *)
  981. #if defined(MLI)
  982. val xCheckTypedEvent_option: dpy:display -> event_type -> any xEvent option
  983. (** replaces [xCheckTypedEvent] *)
  984. #else
  985. let xCheckTypedEvent_option ~dpy event_type =
  986. let ev = new_xEvent() in
  987. if (xCheckTypedEvent ~dpy event_type ev)
  988. then Some ev
  989. else None
  990. #endif
  991. external xEventType: event:'a xEvent -> event_type = "ml_XEvent_type"
  992. #if defined(MLI)
  993. val xEventKind : event:any xEvent -> event_kind
  994. (** selects the right type of the event *)
  995. #else
  996. let xEventKind ~event =
  997. match xEventType ~event with
  998. | MotionNotify -> XMotionEvent (Obj.magic event : xMotionEvent xEvent)
  999. | KeyPress -> XKeyPressedEvent (Obj.magic event : xKeyPressedEvent xEvent) (* xKeyEvent *)
  1000. | KeyRelease -> XKeyReleasedEvent (Obj.magic event : xKeyReleasedEvent xEvent) (* xKeyEvent *)
  1001. | ButtonPress -> XButtonPressedEvent (Obj.magic event : xButtonPressedEvent xEvent) (* xButtonEvent *)
  1002. | ButtonRelease -> XButtonReleasedEvent (Obj.magic event : xButtonReleasedEvent xEvent) (* xButtonEvent *)
  1003. | EnterNotify -> XCrossingEvent (Obj.magic event : xEnterWindowEvent xEvent) (* xCrossingEvent *)
  1004. | LeaveNotify -> XCrossingEvent (Obj.magic event : xLeaveWindowEvent xEvent) (* xCrossingEvent *)
  1005. | FocusIn -> XFocusChangeEvent (Obj.magic event : xFocusInEvent xEvent) (* xFocusChangeEvent *)
  1006. | FocusOut -> XFocusChangeEvent (Obj.magic event : xFocusOutEvent xEvent) (* xFocusChangeEvent *)
  1007. | KeymapNotify -> XKeymapEvent (Obj.magic event : xKeymapEvent xEvent)
  1008. | Expose -> XExposeEvent (Obj.magic event : xExposeEvent xEvent)
  1009. | GraphicsExpose -> XGraphicsExposeEvent (Obj.magic event : xGraphicsExposeEvent xEvent)
  1010. | NoExpose -> XNoExposeEvent (Obj.magic event : xNoExposeEvent xEvent)
  1011. | VisibilityNotify -> XVisibilityEvent (Obj.magic event : xVisibilityEvent xEvent)
  1012. | CreateNotify -> XCreateWindowEvent (Obj.magic event : xCreateWindowEvent xEvent)
  1013. | DestroyNotify -> XDestroyWindowEvent (Obj.magic event : xDestroyWindowEvent xEvent)
  1014. | UnmapNotify -> XUnmapEvent (Obj.magic event : xUnmapEvent xEvent)
  1015. | MapNotify -> XMapEvent (Obj.magic event : xMapEvent xEvent)
  1016. | MapRequest -> XMapRequestEvent (Obj.magic event : xMapRequestEvent xEvent)
  1017. | ReparentNotify -> XReparentEvent (Obj.magic event : xReparentEvent xEvent)
  1018. | ConfigureNotify -> XConfigureEvent (Obj.magic event : xConfigureEvent xEvent)
  1019. | ConfigureRequest -> XConfigureRequestEvent (Obj.magic event : xConfigureRequestEvent xEvent)
  1020. | GravityNotify -> XGravityEvent (Obj.magic event : xGravityEvent xEvent)
  1021. | ResizeRequest -> XResizeRequestEvent (Obj.magic event : xResizeRequestEvent xEvent)
  1022. | CirculateNotify -> XCirculateEvent (Obj.magic event : xCirculateEvent xEvent)
  1023. | CirculateRequest -> XCirculateRequestEvent (Obj.magic event : xCirculateRequestEvent xEvent)
  1024. | PropertyNotify -> XPropertyEvent (Obj.magic event : xPropertyEvent xEvent)
  1025. | SelectionClear -> XSelectionClearEvent (Obj.magic event : xSelectionClearEvent xEvent)
  1026. | SelectionRequest -> XSelectionRequestEvent (Obj.magic event : xSelectionRequestEvent xEvent)
  1027. | SelectionNotify -> XSelectionEvent (Obj.magic event : xSelectionEvent xEvent)
  1028. | ColormapNotify -> XColormapEvent (Obj.magic event : xColormapEvent xEvent)
  1029. | ClientMessage -> XClientMessageEvent (Obj.magic event : xClientMessageEvent xEvent)
  1030. | MappingNotify -> XMappingEvent (Obj.magic event : xMappingEvent xEvent)
  1031. ;;
  1032. #endif
  1033. (* {{{ string_of_event_type *)
  1034. #if defined(MLI)
  1035. val string_of_event_type: event_type:event_type -> string
  1036. #else
  1037. let string_of_event_type ~event_type =
  1038. match event_type with
  1039. | MotionNotify -> "MotionNotify"
  1040. | KeyPress -> "KeyPress"
  1041. | KeyRelease -> "KeyRelease"
  1042. | ButtonPress -> "ButtonPress"
  1043. | ButtonRelease -> "ButtonRelease"
  1044. | EnterNotify -> "EnterNotify"
  1045. | LeaveNotify -> "LeaveNotify"
  1046. | FocusIn -> "FocusIn"
  1047. | FocusOut -> "FocusOut"
  1048. | KeymapNotify -> "KeymapNotify"
  1049. | Expose -> "Expose"
  1050. | GraphicsExpose -> "GraphicsExpose"
  1051. | NoExpose -> "NoExpose"
  1052. | VisibilityNotify -> "VisibilityNotify"
  1053. | CreateNotify -> "CreateNotify"
  1054. | DestroyNotify -> "DestroyNotify"
  1055. | UnmapNotify -> "UnmapNotify"
  1056. | MapNotify -> "MapNotify"
  1057. | MapRequest -> "MapRequest"
  1058. | ReparentNotify -> "ReparentNotify"
  1059. | ConfigureNotify -> "ConfigureNotify"
  1060. | ConfigureRequest -> "ConfigureRequest"
  1061. | GravityNotify -> "GravityNotify"
  1062. | ResizeRequest -> "ResizeRequest"
  1063. | CirculateNotify -> "CirculateNotify"
  1064. | CirculateRequest -> "CirculateRequest"
  1065. | PropertyNotify -> "PropertyNotify"
  1066. | SelectionClear -> "SelectionClear"
  1067. | SelectionRequest -> "SelectionRequest"
  1068. | SelectionNotify -> "SelectionNotify"
  1069. | ColormapNotify -> "ColormapNotify"
  1070. | ClientMessage -> "ClientMessage"
  1071. | MappingNotify -> "MappingNotify"
  1072. ;;
  1073. #endif
  1074. (* }}} *)
  1075. (* {{{ XEvent conversion *)
  1076. (** {4 XEvent Conversions} *)
  1077. #if defined(ML)
  1078. let to_xMotionEvent ~(event : any xEvent) =
  1079. if (xEventType ~event) <> MotionNotify then
  1080. invalid_arg "to_xMotionEvent";
  1081. (Obj.magic event : xMotionEvent xEvent)
  1082. ;;
  1083. let to_xKeyEvent ~(event : any xEvent) =
  1084. if (xEventType ~event) <> KeyPress &&
  1085. (xEventType ~event) <> KeyRelease then
  1086. invalid_arg "to_xKeyEvent";
  1087. (Obj.magic event : xKeyEvent xEvent)
  1088. ;;
  1089. let to_xKeyPressedEvent ~(event : any xEvent) =
  1090. if (xEventType ~event) <> KeyPress then
  1091. invalid_arg "to_xKeyPressedEvent";
  1092. (Obj.magic event : xKeyPressedEvent xEvent)
  1093. ;;
  1094. let to_xKeyReleasedEvent ~(event : any xEvent) =
  1095. if (xEventType ~event) <> KeyRelease then
  1096. invalid_arg "to_xKeyReleasedEvent";
  1097. (Obj.magic event : xKeyReleasedEvent xEvent)
  1098. ;;
  1099. let to_xButtonEvent ~(event : any xEvent) =
  1100. if (xEventType ~event) <> ButtonPress &&
  1101. (xEventType ~event) <> ButtonRelease then
  1102. invalid_arg "to_xButtonEvent";
  1103. (Obj.magic event : xButtonEvent xEvent)
  1104. ;;
  1105. let to_xButtonPressedEvent ~(event : any xEvent) =
  1106. if (xEventType ~event) <> ButtonPress then
  1107. invalid_arg "to_xButtonPressedEvent";
  1108. (Obj.magic event : xButtonPressedEvent xEvent)
  1109. ;;
  1110. let to_xButtonReleasedEvent ~(event : any xEvent) =
  1111. if (xEventType ~event) <> ButtonRelease then
  1112. invalid_arg "to_xButtonReleasedEvent";
  1113. (Obj.magic event : xButtonReleasedEvent xEvent)
  1114. ;;
  1115. let to_xCrossingEvent ~(event : any xEvent) =
  1116. if (xEventType ~event) <> EnterNotify &&
  1117. (xEventType ~event) <> LeaveNotify then
  1118. invalid_arg "to_xCrossingEvent";
  1119. (Obj.magic event : xCrossingEvent xEvent)
  1120. ;;
  1121. let to_xEnterWindowEvent ~(event : any xEvent) =
  1122. if (xEventType ~event) <> EnterNotify then
  1123. invalid_arg "to_xEnterWindowEvent";
  1124. (Obj.magic event : xEnterWindowEvent xEvent)
  1125. ;;
  1126. let to_xLeaveWindowEvent ~(event : any xEvent) =
  1127. if (xEventType ~event) <> LeaveNotify then
  1128. invalid_arg "to_xLeaveWindowEvent";
  1129. (Obj.magic event : xLeaveWindowEvent xEvent)
  1130. ;;
  1131. let to_xFocusChangeEvent ~(event : any xEvent) =
  1132. if (xEventType ~event) <> FocusIn &&
  1133. (xEventType ~event) <> FocusOut then
  1134. invalid_arg "to_xFocusChangeEvent";
  1135. (Obj.magic event : xFocusChangeEvent xEvent)
  1136. ;;
  1137. let to_xFocusInEvent ~(event : any xEvent) =
  1138. if (xEventType ~event) <> FocusIn then
  1139. invalid_arg "to_xFocusInEvent";
  1140. (Obj.magic event : xFocusInEvent xEvent)
  1141. ;;
  1142. let to_xFocusOutEvent ~(event : any xEvent) =
  1143. if (xEventType ~event) <> FocusOut then
  1144. invalid_arg "to_xFocusOutEvent";
  1145. (Obj.magic event : xFocusOutEvent xEvent)
  1146. ;;
  1147. let to_xKeymapEvent ~(event : any xEvent) =
  1148. if (xEventType ~event) <> KeymapNotify then
  1149. invalid_arg "to_xKeymapEvent";
  1150. (Obj.magic event : xKeymapEvent xEvent)
  1151. ;;
  1152. let to_xExposeEvent ~(event : any xEvent) =
  1153. if (xEventType ~event) <> Expose then
  1154. invalid_arg "to_xExposeEvent";
  1155. (Obj.magic event : xExposeEvent xEvent)
  1156. ;;
  1157. let to_xGraphicsExposeEvent ~(event : any xEvent) =
  1158. if (xEventType ~event) <> GraphicsExpose then
  1159. invalid_arg "to_xGraphicsExposeEvent";
  1160. (Obj.magic event : xGraphicsExposeEvent xEvent)
  1161. ;;
  1162. let to_xNoExposeEvent ~(event : any xEvent) =
  1163. if (xEventType ~event) <> NoExpose then
  1164. invalid_arg "to_xNoExposeEvent";
  1165. (Obj.magic event : xNoExposeEvent xEvent)
  1166. ;;
  1167. let to_xVisibilityEvent ~(event : any xEvent) =
  1168. if (xEventType ~event) <> VisibilityNotify then
  1169. invalid_arg "to_xVisibilityEvent";
  1170. (Obj.magic event : xVisibilityEvent xEvent)
  1171. ;;
  1172. let to_xCreateWindowEvent ~(event : any xEvent) =
  1173. if (xEventType ~event) <> CreateNotify then
  1174. invalid_arg "to_xCreateWindowEvent";
  1175. (Obj.magic event : xCreateWindowEvent xEvent)
  1176. ;;
  1177. let to_xDestroyWindowEvent ~(event : any xEvent) =
  1178. if (xEventType ~event) <> DestroyNotify then
  1179. invalid_arg "to_xDestroyWindowEvent";
  1180. (Obj.magic event : xDestroyWindowEvent xEvent)
  1181. ;;
  1182. let to_xUnmapEvent ~(event : any xEvent) =
  1183. if (xEventType ~event) <> UnmapNotify then
  1184. invalid_arg "to_xUnmapEvent";
  1185. (Obj.magic event : xUnmapEvent xEvent)
  1186. ;;
  1187. let to_xMapEvent ~(event : any xEvent) =
  1188. if (xEventType ~event) <> MapNotify then
  1189. invalid_arg "to_xMapEvent";
  1190. (Obj.magic event : xMapEvent xEvent)
  1191. ;;
  1192. let to_xMapRequestEvent ~(event : any xEvent) =
  1193. if (xEventType ~event) <> MapRequest then
  1194. invalid_arg "to_xMapRequestEvent";
  1195. (Obj.magic event : xMapRequestEvent xEvent)
  1196. ;;
  1197. let to_xReparentEvent ~(event : any xEvent) =
  1198. if (xEventType ~event) <> ReparentNotify then
  1199. invalid_arg "to_xReparentEvent";
  1200. (Obj.magic event : xReparentEvent xEvent)
  1201. ;;
  1202. let to_xConfigureEvent ~(event : any xEvent) =
  1203. if (xEventType ~event) <> ConfigureNotify then
  1204. invalid_arg "to_xConfigureEvent";
  1205. (Obj.magic event : xConfigureEvent xEvent)
  1206. ;;
  1207. let to_xConfigureRequestEvent ~(event : any xEvent) =
  1208. if (xEventType ~event) <> ConfigureRequest then
  1209. invalid_arg "to_xConfigureRequestEvent";
  1210. (Obj.magic event : xConfigureRequestEvent xEvent)
  1211. ;;
  1212. let to_xGravityEvent ~(event : any xEvent) =
  1213. if (xEventType ~event) <> GravityNotify then
  1214. invalid_arg "to_xGravityEvent";
  1215. (Obj.magic event : xGravityEvent xEvent)
  1216. ;;
  1217. let to_xResizeRequestEvent ~(event : any xEvent) =
  1218. if (xEventType ~event) <> ResizeRequest then
  1219. invalid_arg "to_xResizeRequestEvent";
  1220. (Obj.magic event : xResizeRequestEvent xEvent)
  1221. ;;
  1222. let to_xCirculateEvent ~(event : any xEvent) =
  1223. if (xEventType ~event) <> CirculateNotify then
  1224. invalid_arg "to_xCirculateEvent";
  1225. (Obj.magic event : xCirculateEvent xEvent)
  1226. ;;
  1227. let to_xCirculateRequestEvent ~(event : any xEvent) =
  1228. if (xEventType ~event) <> CirculateRequest then
  1229. invalid_arg "to_xCirculateRequestEvent";
  1230. (Obj.magic event : xCirculateRequestEvent xEvent)
  1231. ;;
  1232. let to_xPropertyEvent ~(event : any xEvent) =
  1233. if (xEventType ~event) <> PropertyNotify then
  1234. invalid_arg "to_xPropertyEvent";
  1235. (Obj.magic event : xPropertyEvent xEvent)
  1236. ;;
  1237. let to_xSelectionClearEvent ~(event : any xEvent) =
  1238. if (xEventType ~event) <> SelectionClear then
  1239. invalid_arg "to_xSelectionClearEvent";
  1240. (Obj.magic event : xSelectionClearEvent xEvent)
  1241. ;;
  1242. let to_xSelectionRequestEvent ~(event : any xEvent) =
  1243. if (xEventType ~event) <> SelectionRequest then
  1244. invalid_arg "to_xSelectionRequestEvent";
  1245. (Obj.magic event : xSelectionRequestEvent xEvent)
  1246. ;;
  1247. let to_xSelectionEvent ~(event : any xEvent) =
  1248. if (xEventType ~event) <> SelectionNotify then
  1249. invalid_arg "to_xSelectionEvent";
  1250. (Obj.magic event : xSelectionEvent xEvent)
  1251. ;;
  1252. let to_xColormapEvent ~(event : any xEvent) =
  1253. if (xEventType ~event) <> ColormapNotify then
  1254. invalid_arg "to_xColormapEvent";
  1255. (Obj.magic event : xColormapEvent xEvent)
  1256. ;;
  1257. let to_xClientMessageEvent ~(event : any xEvent) =
  1258. if (xEventType ~event) <> ClientMessage then
  1259. invalid_arg "to_xClientMessageEvent";
  1260. (Obj.magic event : xClientMessageEvent xEvent)
  1261. ;;
  1262. let to_xMappingEvent ~(event : any xEvent) =
  1263. if (xEventType ~event) <> MappingNotify then
  1264. invalid_arg "to_xMappingEvent";
  1265. (Obj.magic event : xMappingEvent xEvent)
  1266. ;;
  1267. #else
  1268. (** convertions from type [any xEvent] *)
  1269. val to_xMotionEvent : event:any xEvent -> xMotionEvent xEvent
  1270. val to_xKeyEvent : event:any xEvent -> xKeyEvent xEvent
  1271. val to_xKeyPressedEvent : event:any xEvent -> xKeyPressedEvent xEvent
  1272. val to_xKeyReleasedEvent : event:any xEvent -> xKeyReleasedEvent xEvent
  1273. val to_xButtonEvent : event:any xEvent -> xButtonEvent xEvent
  1274. val to_xButtonPressedEvent : event:any xEvent -> xButtonPressedEvent xEvent
  1275. val to_xButtonReleasedEvent : event:any xEvent -> xButtonReleasedEvent xEvent
  1276. val to_xCrossingEvent : event:any xEvent -> xCrossingEvent xEvent
  1277. val to_xEnterWindowEvent : event:any xEvent -> xEnterWindowEvent xEvent
  1278. val to_xLeaveWindowEvent : event:any xEvent -> xLeaveWindowEvent xEvent
  1279. val to_xFocusChangeEvent : event:any xEvent -> xFocusChangeEvent xEvent
  1280. val to_xFocusInEvent : event:any xEvent -> xFocusInEvent xEvent
  1281. val to_xFocusOutEvent : event:any xEvent -> xFocusOutEvent xEvent
  1282. val to_xKeymapEvent : event:any xEvent -> xKeymapEvent xEvent
  1283. val to_xExposeEvent : event:any xEvent -> xExposeEvent xEvent
  1284. val to_xGraphicsExposeEvent : event:any xEvent -> xGraphicsExposeEvent xEvent
  1285. val to_xNoExposeEvent : event:any xEvent -> xNoExposeEvent xEvent
  1286. val to_xVisibilityEvent : event:any xEvent -> xVisibilityEvent xEvent
  1287. val to_xCreateWindowEvent : event:any xEvent -> xCreateWindowEvent xEvent
  1288. val to_xDestroyWindowEvent : event:any xEvent -> xDestroyWindowEvent xEvent
  1289. val to_xUnmapEvent : event:any xEvent -> xUnmapEvent xEvent
  1290. val to_xMapEvent : event:any xEvent -> xMapEvent xEvent
  1291. val to_xMapRequestEvent : event:any xEvent -> xMapRequestEvent xEvent
  1292. val to_xReparentEvent : event:any xEvent -> xReparentEvent xEvent
  1293. val to_xConfigureEvent : event:any xEvent -> xConfigureEvent xEvent
  1294. val to_xConfigureRequestEvent : event:any xEvent -> xConfigureRequestEvent xEvent
  1295. val to_xGravityEvent : event:any xEvent -> xGravityEvent xEvent
  1296. val to_xResizeRequestEvent : event:any xEvent -> xResizeRequestEvent xEvent
  1297. val to_xCirculateEvent : event:any xEvent -> xCirculateEvent xEvent
  1298. val to_xCirculateRequestEvent : event:any xEvent -> xCirculateRequestEvent xEvent
  1299. val to_xPropertyEvent : event:any xEvent -> xPropertyEvent xEvent
  1300. val to_xSelectionClearEvent : event:any xEvent -> xSelectionClearEvent xEvent
  1301. val to_xSelectionRequestEvent : event:any xEvent -> xSelectionRequestEvent xEvent
  1302. val to_xSelectionEvent : event:any xEvent -> xSelectionEvent xEvent
  1303. val to_xColormapEvent : event:any xEvent -> xColormapEvent xEvent
  1304. val to_xClientMessageEvent : event:any xEvent -> xClientMessageEvent xEvent
  1305. val to_xMappingEvent : event:any xEvent -> xMappingEvent xEvent
  1306. #endif
  1307. (* }}} *)
  1308. (* {{{ XEvents datas *)
  1309. (** {4 XEvents Contents} *)
  1310. (** {{:http://tronche.com/gui/x/xlib/events/structures.html}manual about XEvent Structures} *)
  1311. (*
  1312. | KeyPress - Done
  1313. | KeyRelease - Done
  1314. | ButtonPress - Done
  1315. | ButtonRelease - Done
  1316. | MotionNotify - Done
  1317. | EnterNotify - Done
  1318. | LeaveNotify - Done
  1319. | FocusIn - Done
  1320. | FocusOut - Done
  1321. | KeymapNotify - Done
  1322. | Expose - Done
  1323. | GraphicsExpose -
  1324. | NoExpose -
  1325. | VisibilityNotify - Done
  1326. | CreateNotify -
  1327. | DestroyNotify - Done
  1328. | UnmapNotify -
  1329. | MapNotify -
  1330. | MapRequest -
  1331. | ReparentNotify - Done
  1332. | ConfigureNotify - Done
  1333. | ConfigureRequest - Done
  1334. | GravityNotify -
  1335. | ResizeRequest - Done
  1336. | CirculateNotify -
  1337. | CirculateRequest -
  1338. | PropertyNotify -
  1339. | SelectionClear -
  1340. | SelectionRequest -
  1341. | SelectionNotify - Done
  1342. | ColormapNotify -
  1343. | ClientMessage -
  1344. | MappingNotify -
  1345. http://tronche.com/gui/x/xlib/events/structures.html
  1346. *)
  1347. type xAnyEvent_contents = {
  1348. xany_type: event_type;
  1349. xany_serial: uint;
  1350. xany_send_event: bool;
  1351. xany_display: display;
  1352. xany_window: window;
  1353. }
  1354. external xAnyEvent_datas: 'a xEvent -> xAnyEvent_contents = "ml_XAnyEvent_datas"
  1355. type logical_state =
  1356. | AnyModifier
  1357. | Button1Mask
  1358. | Button2Mask
  1359. | Button3Mask
  1360. | Button4Mask
  1361. | Button5Mask
  1362. | ShiftMask
  1363. | LockMask
  1364. | ControlMask
  1365. | Mod1Mask
  1366. | Mod2Mask
  1367. | Mod3Mask
  1368. | Mod4Mask
  1369. | Mod5Mask
  1370. type xKeyEvent_contents = {
  1371. key_serial: uint;
  1372. key_send_event: bool;
  1373. key_display: display;
  1374. key_window: window;
  1375. key_root: window;
  1376. key_subwindow: window;
  1377. key_time: time;
  1378. key_x: int;
  1379. key_y: int;
  1380. key_x_root: int;
  1381. key_y_root: int;
  1382. key_state: logical_state list;
  1383. key_keycode: keycode;
  1384. key_same_screen: bool;
  1385. }
  1386. external xKeyEvent_datas: xKeyEvent xEvent -> xKeyEvent_contents = "ml_XKeyEvent_datas"
  1387. (** {{:http://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html#XKeyEvent}man} *)
  1388. (*
  1389. type button_mask =
  1390. | Button1Mask
  1391. | Button2Mask
  1392. | Button3Mask
  1393. | Button4Mask
  1394. | Button5Mask
  1395. *)
  1396. type xMotionEvent_contents = {
  1397. motion_serial: uint;
  1398. motion_send_event: bool;
  1399. motion_display: display;
  1400. motion_window: window;
  1401. motion_root: window;
  1402. motion_subwindow: window;
  1403. motion_time: time;
  1404. motion_x: int;
  1405. motion_y: int;
  1406. motion_x_root: int;
  1407. motion_y_root: int;
  1408. motion_state: (* button_mask *) logical_state list; (* TODO check the additionnal Masks *)
  1409. motion_is_hint: char;
  1410. motion_same_screen: bool;
  1411. }
  1412. external xMotionEvent_datas: xMotionEvent xEvent -> xMotionEvent_contents = "ml_XMotionEvent_datas"
  1413. (** {{:http://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html#XMotionEvent}man} *)
  1414. type button =
  1415. | AnyButton
  1416. | Button1
  1417. | Button2
  1418. | Button3
  1419. | Button4
  1420. | Button5
  1421. type xButtonEvent_contents = {
  1422. button_serial: uint;
  1423. button_send_event: bool;
  1424. button_display: display;
  1425. button_window: window;
  1426. button_root: window;
  1427. button_subwindow: window;
  1428. button_time: time;
  1429. button_x: int;
  1430. button_y: int;
  1431. button_x_root: int;
  1432. button_y_root: int;
  1433. button_state: uint;
  1434. button: button;
  1435. button_same_screen: bool;
  1436. }
  1437. external xButtonEvent_datas: xButtonEvent xEvent -> xButtonEvent_contents = "ml_XButtonEvent_datas"
  1438. (** {{:http://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html#XButtonEvent}man} *)
  1439. #if defined(MLI)
  1440. module Cross : sig
  1441. #else
  1442. module Cross = struct
  1443. #endif
  1444. type crossing_mode =
  1445. | NotifyNormal
  1446. | NotifyGrab
  1447. | NotifyUngrab
  1448. type crossing_detail =
  1449. | NotifyAncestor
  1450. | NotifyVirtual
  1451. | NotifyInferior
  1452. | NotifyNonlinear
  1453. | NotifyNonlinearVirtual
  1454. type crossing_state =
  1455. | Button1Mask
  1456. | Button2Mask
  1457. | Button3Mask
  1458. | Button4Mask
  1459. | Button5Mask
  1460. | ShiftMask
  1461. | LockMask
  1462. | ControlMask
  1463. | Mod1Mask
  1464. | Mod2Mask
  1465. | Mod3Mask
  1466. | Mod4Mask
  1467. | Mod5Mask
  1468. end
  1469. type xCrossingEvent_contents = {
  1470. cross_window : window;
  1471. cross_root : window;
  1472. cross_subwindow : window;
  1473. cross_time : time;
  1474. cross_x : int;
  1475. cross_y : int;
  1476. cross_x_root : int;
  1477. cross_y_root : int;
  1478. cross_mode : Cross.crossing_mode;
  1479. cross_detail : Cross.crossing_detail;
  1480. cross_same_screen : bool;
  1481. cross_focus : bool;
  1482. cross_state : Cross.crossing_state;
  1483. }
  1484. external xCrossingEvent_datas: xCrossingEvent xEvent -> xCrossingEvent_contents = "ml_XCrossingEvent_datas"
  1485. (** {{:http://tronche.com/gui/x/xlib/events/window-entry-exit/}man} *)
  1486. type focus_mode =
  1487. | NotifyNormal
  1488. | NotifyGrab
  1489. | NotifyUngrab
  1490. | NotifyWhileGrabbed
  1491. type focus_detail =
  1492. | NotifyAncestor
  1493. | NotifyVirtual
  1494. | NotifyInferior
  1495. | NotifyNonlinear
  1496. | NotifyNonlinearVirtual
  1497. | NotifyPointer
  1498. | NotifyPointerRoot
  1499. | NotifyDetailNone
  1500. type xFocusChangeEvent_contents = {
  1501. focus_mode: focus_mode;
  1502. focus_detail: focus_detail;
  1503. }
  1504. external xFocusChangeEvent_datas: xFocusChangeEvent xEvent -> xFocusChangeEvent_contents = "ml_XFocusChangeEvent_datas"
  1505. (** {{:http://tronche.com/gui/x/xlib/events/input-focus/}man} *)
  1506. type xKeymapEvent_contents = {
  1507. key_vector: string;
  1508. }
  1509. external xKeymapEvent_datas: xKeymapEvent xEvent -> xKeymapEvent_contents = "ml_XKeymapEvent_datas"
  1510. (** {{:http://tronche.com/gui/x/xlib/events/key-map.html}man} *)
  1511. type xExposeEvent_contents = {
  1512. expose_x: int;
  1513. expose_y: int;
  1514. expose_width: int;
  1515. expose_height: int;
  1516. expose_count: int;
  1517. }
  1518. external xExposeEvent_datas: xExposeEvent xEvent -> xExposeEvent_contents = "ml_XExposeEvent_datas"
  1519. (** {{:http://tronche.com/gui/x/xlib/events/exposure/expose.html}man} *)
  1520. type visibility_state =
  1521. | VisibilityUnobscured
  1522. | VisibilityPartiallyObscured
  1523. | VisibilityFullyObscured
  1524. type xVisibilityEvent_contents = {
  1525. visibility_state: visibility_state;
  1526. }
  1527. external xVisibilityEvent_datas: xVisibilityEvent xEvent -> xVisibilityEvent_contents = "ml_XVisibilityEvent_datas"
  1528. (** {{:http://tronche.com/gui/x/xlib/events/window-state-change/visibility.html}man} *)
  1529. type xDestroyWindowEvent_contents = {
  1530. destroy_event: window;
  1531. destroy_window: window;
  1532. }
  1533. external xDestroyWindowEvent_datas: xDestroyWindowEvent xEvent -> xDestroyWindowEvent_contents = "ml_XDestroyWindowEvent_datas"
  1534. (** {{:http://tronche.com/gui/x/xlib/events/window-state-change/destroy.html}man} *)
  1535. type xReparentEvent_contents = {
  1536. reparent_event: window;
  1537. reparent_window: window;
  1538. reparent_parent: window;
  1539. reparent_x: int;
  1540. reparent_y: int;
  1541. reparent_override_redirect: bool;
  1542. }
  1543. external xReparentEvent_datas: xReparentEvent xEvent -> xReparentEvent_contents = "ml_XReparentEvent_datas"
  1544. (** {{:http://tronche.com/gui/x/xlib/events/window-state-change/reparent.html}man} *)
  1545. type xConfigureEvent_contents = {
  1546. conf_x: int;
  1547. conf_y: int;
  1548. conf_width: int;
  1549. conf_height: int;
  1550. conf_border_width: int;
  1551. conf_above: window;
  1552. conf_override_redirect: bool;
  1553. }
  1554. external xConfigureEvent_datas: xConfigureEvent xEvent -> xConfigureEvent_contents = "ml_XConfigureEvent_datas"
  1555. (** {{:http://tronche.com/gui/x/xlib/events/window-state-change/configure.html}man} *)
  1556. type xconfreq_detail =
  1557. | Above
  1558. | Below
  1559. | TopIf
  1560. | BottomIf
  1561. | Opposite
  1562. type xConfigureRequestEvent_contents = {
  1563. confreq_parent: window;
  1564. confreq_window: window;
  1565. confreq_x: int;
  1566. confreq_y: int;
  1567. confreq_width: int;
  1568. confreq_height: int;
  1569. confreq_border_width: int;
  1570. confreq_above: window;
  1571. confreq_detail: xconfreq_detail;
  1572. confreq_value_mask: uint; (* XXX TODO *)
  1573. }
  1574. external xConfigureRequestEvent_datas: xConfigureRequestEvent xEvent -> xConfigureRequestEvent_contents = "ml_XConfigureRequestEvent_datas"
  1575. (** {{:http://tronche.com/gui/x/xlib/events/structure-control/configure.html}man} *)
  1576. type xResizeRequestEvent_contents = {
  1577. resize_width: int;
  1578. resize_height: int;
  1579. }
  1580. external xResizeRequestEvent_datas: xResizeRequestEvent xEvent -> xResizeRequestEvent_contents = "ml_XResizeRequestEvent_datas"
  1581. (** {{:http://tronche.com/gui/x/xlib/events/structure-control/resize.html}man} *)
  1582. type xSelectionEvent_contents = {
  1583. selec_requestor: window;
  1584. selec_selection: atom;
  1585. selec_target: atom;
  1586. selec_property: atom option;
  1587. selec_time: time;
  1588. }
  1589. external xSelectionEvent_datas: xSelectionEvent xEvent -> xSelectionEvent_contents = "ml_XSelectionEvent_datas"
  1590. (** {{:http://tronche.com/gui/x/xlib/events/client-communication/selection.html}man} *)
  1591. (* TODO
  1592. xGraphicsExposeEvent
  1593. xNoExposeEvent
  1594. xCreateWindowEvent
  1595. xUnmapEvent
  1596. xMapEvent
  1597. xMapRequestEvent
  1598. xGravityEvent
  1599. xCirculateEvent
  1600. xCirculateRequestEvent
  1601. xPropertyEvent
  1602. xSelectionClearEvent
  1603. xSelectionRequestEvent
  1604. xColormapEvent
  1605. xClientMessageEvent
  1606. xMappingEvent
  1607. xErrorEvent
  1608. *)
  1609. (* }}} *)
  1610. type todo_contents = {
  1611. todo_field: int;
  1612. }
  1613. type event_content =
  1614. | XMotionEvCnt of xMotionEvent_contents
  1615. | XKeyPressedEvCnt of xKeyEvent_contents
  1616. | XKeyReleasedEvCnt of xKeyEvent_contents
  1617. | XButtonPressedEvCnt of xButtonEvent_contents
  1618. | XButtonReleasedEvCnt of xButtonEvent_contents
  1619. | XCrossingEvCnt of xCrossingEvent_contents
  1620. | XFocusChangeEvCnt of xFocusChangeEvent_contents
  1621. | XKeymapEvCnt of xKeymapEvent_contents
  1622. | XExposeEvCnt of xExposeEvent_contents
  1623. | XGraphicsExposeEvCnt of todo_contents
  1624. | XNoExposeEvCnt of todo_contents
  1625. | XVisibilityEvCnt of xVisibilityEvent_contents
  1626. | XCreateWindowEvCnt of todo_contents
  1627. | XDestroyWindowEvCnt of xDestroyWindowEvent_contents
  1628. | XUnmapEvCnt of todo_contents
  1629. | XMapEvCnt of todo_contents
  1630. | XMapRequestEvCnt of todo_contents
  1631. | XReparentEvCnt of xReparentEvent_contents
  1632. | XConfigureEvCnt of xConfigureEvent_contents
  1633. | XConfigureRequestEvCnt of xConfigureRequestEvent_contents
  1634. | XGravityEvCnt of todo_contents
  1635. | XResizeRequestEvCnt of xResizeRequestEvent_contents
  1636. | XCirculateEvCnt of todo_contents
  1637. | XCirculateRequestEvCnt of todo_contents
  1638. | XPropertyEvCnt of todo_contents
  1639. | XSelectionClearEvCnt of todo_contents
  1640. | XSelectionRequestEvCnt of todo_contents
  1641. | XSelectionEvCnt of xSelectionEvent_contents
  1642. | XColormapEvCnt of todo_contents
  1643. | XClientMessageEvCnt of todo_contents
  1644. | XMappingEvCnt of todo_contents
  1645. external xSendEvent: dpy:display -> win:window -> propagate:bool -> event_mask:event_mask -> event_content -> unit
  1646. = "ml_XSendEvent"
  1647. (** {{:http://tronche.com/gui/x/xlib/event-handling/XSendEvent.html}man} *)
  1648. (** {3 Keysym} *)
  1649. (** {{:http://tronche.com/gui/x/xlib/utilities/keyboard/}
  1650. Keyboard Utility Functions}
  1651. {{:http://tronche.com/gui/x/xlib/utilities/latin-keyboard.html}
  1652. Latin-1 Keyboard Event Functions} *)
  1653. (* external _xLookupString: event:xKeyEvent xEvent -> unit = "_ml_XLookupString" *)
  1654. external xLookupString: event:xKeyEvent xEvent -> buffer:string -> int * keysym = "ml_XLookupString"
  1655. (** {{:http://tronche.com/gui/x/xlib/utilities/XLookupString.html}man},
  1656. {b Warning:} the [buffer] parameter is filled by the function, you can provide
  1657. a string of length 2, or an empty string if you're not interested by it. *)
  1658. external xLookupKeysym: event:xKeyEvent xEvent -> index:int -> keysym = "ml_XLookupKeysym"
  1659. (** {{:http://tronche.com/gui/x/xlib/utilities/keyboard/XLookupKeysym.html}man} *)
  1660. external xKeycodeToKeysym: dpy:display -> keycode:keycode -> index:int -> keysym = "ml_XKeycodeToKeysym"
  1661. (** {{:http://tronche.com/gui/x/xlib/utilities/keyboard/XKeycodeToKeysym.html}man} *)
  1662. (* TODO
  1663. char *XKeysymToString(
  1664. KeySym keysym
  1665. );
  1666. KeySym XStringToKeysym(
  1667. _Xconst char* string
  1668. );
  1669. KeyCode XKeysymToKeycode(
  1670. Display* display,
  1671. KeySym keysym
  1672. );
  1673. int XRebindKeysym(
  1674. Display* /* display */,
  1675. KeySym /* keysym */,
  1676. KeySym* /* list */,
  1677. int /* mod_count */,
  1678. _Xconst unsigned char* /* string */,
  1679. int /* bytes_string */
  1680. );
  1681. *)
  1682. (** {3 Keyboard Mapping} *)
  1683. external xRefreshKeyboardMapping : event:xMappingEvent xEvent -> unit = "ml_XRefreshKeyboardMapping"
  1684. (** {{:http://tronche.com/gui/x/xlib/utilities/keyboard/XRefreshKeyboardMapping.html}man} *)
  1685. external xDisplayKeycodes: dpy:display -> keycode * keycode = "ml_XDisplayKeycodes"
  1686. (** {{:http://tronche.com/gui/x/xlib/input/XDisplayKeycodes.html}man}
  1687. returns (min_keycodes, max_keycodes) *)
  1688. external xGetKeyboardMapping: dpy:display -> first_keycode:keycode -> keycode_count:int -> keysym array array
  1689. = "ml_XGetKeyboardMapping"
  1690. (** {b WIP!} {{:http://tronche.com/gui/x/xlib/input/XGetKeyboardMapping.html}man} *)
  1691. external xChangeKeyboardMapping:
  1692. dpy:display ->
  1693. first_keycode:keycode ->
  1694. keysyms_per_keycode:int ->
  1695. keysyms:keysym array ->
  1696. num_codes:int -> unit = "ml_XChangeKeyboardMapping"
  1697. (** {b WIP!} {{:http://tronche.com/gui/x/xlib/input/XChangeKeyboardMapping.html}man} *)
  1698. external xChangeKeyboardMapping_single:
  1699. dpy:display ->
  1700. keycode:keycode ->
  1701. keysym:int -> unit = "ml_XChangeKeyboardMapping_single" "noalloc"
  1702. (** same as [xChangeKeyboardMapping] but requests for only one item *)
  1703. (*
  1704. if (!(map = XGetModifierMapping(display))) {
  1705. return;
  1706. }
  1707. *)
  1708. (** {3 Atoms} *)
  1709. external xSetWMProtocols: dpy:display -> win:window -> protocols:atom -> count:int -> unit = "ml_XSetWMProtocols"
  1710. (** {{:http://tronche.com/gui/x/xlib/ICC/client-to-window-manager/XSetWMProtocols.html}man} *)
  1711. external xInternAtom: dpy:display -> atom_name:string -> only_if_exists:bool -> atom = "ml_XInternAtom"
  1712. (** if None is returned, raises [Not_found] *)
  1713. external xInternAtoms: dpy:display -> names:string array -> only_if_exists:bool -> atom array
  1714. = "ml_XInternAtoms"
  1715. external xGetAtomName: dpy:display -> atom:atom -> string = "ml_XGetAtomName"
  1716. (** {{:http://tronche.com/gui/x/xlib/window-information/XGetAtomName.html}man} *)
  1717. external xEvent_xclient_data : xClientMessageEvent xEvent -> atom = "ml_XEvent_xclient_data_l_0"
  1718. (** alpha *)
  1719. (** {3 Font} *)
  1720. (* xlib.pdf page 155 *)
  1721. type font
  1722. type xFontStruct (* pointer to a structure *)
  1723. external xLoadFont: dpy:display -> name:string -> font = "ml_XLoadFont"
  1724. (** {{:http://tronche.com/gui/x/xlib/graphics/font-metrics/XLoadFont.html}man} *)
  1725. external xLoadQueryFont: dpy:display -> name:string -> xFontStruct = "ml_XLoadQueryFont"
  1726. (** {{:http://tronche.com/gui/x/xlib/graphics/font-metrics/XLoadQueryFont.html}man} *)
  1727. external xQueryFont: dpy:display -> font:font -> xFontStruct = "ml_XQueryFont"
  1728. (** {{:http://tronche.com/gui/x/xlib/graphics/font-metrics/XQueryFont.html}man} *)
  1729. external xQueryFontGC: dpy:display -> gc:gc -> xFontStruct = "ml_XQueryFontGC"
  1730. external xSetFont: dpy:display -> gc:gc -> font:font -> unit = "ml_XSetFont"
  1731. (** {{:http://tronche.com/gui/x/xlib/GC/convenience-functions/XSetFont.html}man} *)
  1732. external xFontStruct_font: xFontStruct -> font = "ml_XFontStruct_get_fid"
  1733. external xFontStruct_ascent: xFontStruct -> int = "ml_XFontStruct_get_ascent"
  1734. external xFontStruct_descent: xFontStruct -> int = "ml_XFontStruct_get_descent"
  1735. external xFontStruct_all_chars_exist: xFontStruct -> bool = "ml_XFontStruct_get_all_chars_exist"
  1736. external xFontStruct_get_height: xFontStruct -> int * int = "ml_XFontStruct_get_height"
  1737. (** returns the [(ascent, descent)] pair *)
  1738. external xTextWidth: xFontStruct -> string -> int = "ml_XTextWidth"
  1739. type xCharStruct = {
  1740. lbearing: int;
  1741. rbearing: int;
  1742. width: int;
  1743. ascent: int;
  1744. descent: int;
  1745. }
  1746. external xFontStruct_min_bounds: xFontStruct -> xCharStruct = "ml_xFontStruct_min_bounds"
  1747. external xFontStruct_max_bounds: xFontStruct -> xCharStruct = "ml_xFontStruct_max_bounds"
  1748. (* {{{ font_struct / load_font *)
  1749. type font_struct = {
  1750. _font: font;
  1751. _ascent: int;
  1752. _descent: int;
  1753. all_chars_exist: bool;
  1754. font_height: int * int;
  1755. text_width: string -> int;
  1756. min_bounds: xCharStruct;
  1757. max_bounds: xCharStruct;
  1758. }
  1759. (** replaces the functions [xFontStruct_*] *)
  1760. #if defined(MLI)
  1761. val load_font: dpy:display -> name:string -> font_struct
  1762. (** replaces [xLoadFont] *)
  1763. #else
  1764. let load_font ~dpy ~name =
  1765. let fs = xLoadQueryFont dpy name in
  1766. {
  1767. _font = xFontStruct_font fs;
  1768. _ascent = xFontStruct_ascent fs;
  1769. _descent = xFontStruct_descent fs;
  1770. all_chars_exist = xFontStruct_all_chars_exist fs;
  1771. font_height = xFontStruct_get_height fs;
  1772. text_width = xTextWidth fs;
  1773. min_bounds = xFontStruct_min_bounds fs;
  1774. max_bounds = xFontStruct_max_bounds fs;
  1775. }
  1776. #endif
  1777. (* }}} *)
  1778. (** {3 Setting and Retrieving the Font Search Path} *)
  1779. external xSetFontPath: dpy:display -> directories:string array -> unit = "ml_XSetFontPath"
  1780. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XSetFontPath.html}man} *)
  1781. external xGetFontPath: dpy:display -> string array = "ml_XGetFontPath"
  1782. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XGetFontPath.html}man} *)
  1783. external xListFonts: dpy:display -> pattern:string -> maxnames:int -> string array = "ml_XListFonts"
  1784. (** {{:http://tronche.com/gui/x/xlib/graphics/font-metrics/XListFonts.html}man} *)
  1785. (** {3 Graphics Context} *)
  1786. external xDefaultGC: dpy:display -> scr:screen_number -> gc = "ml_XDefaultGC"
  1787. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html}man} *)
  1788. type xGCValues
  1789. external new_xGCValues: unit -> xGCValues = "ml_alloc_XGCValues"
  1790. (** the return value is garbage collected *)
  1791. type line_style =
  1792. | LineSolid
  1793. | LineOnOffDash
  1794. | LineDoubleDash
  1795. type cap_style =
  1796. | CapNotLast
  1797. | CapButt
  1798. | CapRound
  1799. | CapProjecting
  1800. type join_style =
  1801. | JoinMiter
  1802. | JoinRound
  1803. | JoinBevel
  1804. type fill_style =
  1805. | FillSolid
  1806. | FillTiled
  1807. | FillStippled
  1808. | FillOpaqueStippled
  1809. type fill_rule =
  1810. | EvenOddRule
  1811. | WindingRule
  1812. type logop_func =
  1813. | GXclear
  1814. | GXand
  1815. | GXandReverse
  1816. | GXcopy
  1817. | GXandInverted
  1818. | GXnoop
  1819. | GXxor
  1820. | GXor
  1821. | GXnor
  1822. | GXequiv
  1823. | GXinvert
  1824. | GXorReverse
  1825. | GXcopyInverted
  1826. | GXorInverted
  1827. | GXnand
  1828. | GXset
  1829. type arc_mode =
  1830. | ArcChord
  1831. | ArcPieSlice
  1832. type subwindow_mode =
  1833. | ClipByChildren
  1834. | IncludeInferiors
  1835. external xGCValues_set_foreground: gcv:xGCValues -> fg:pixel_color -> unit = "ml_XGCValues_set_foreground"
  1836. external xGCValues_set_background: gcv:xGCValues -> bg:pixel_color -> unit = "ml_XGCValues_set_background"
  1837. external xGCValues_set_graphics_exposures: gcv:xGCValues -> bool -> unit = "ml_XGCValues_set_graphics_exposures"
  1838. external xGCValues_set_tile: gcv:xGCValues -> pixmap -> unit = "ml_XGCValues_set_tile"
  1839. external xGCValues_set_clip_x_origin: gcv:xGCValues -> int -> unit = "ml_XGCValues_set_clip_x_origin"
  1840. external xGCValues_set_clip_y_origin: gcv:xGCValues -> int -> unit = "ml_XGCValues_set_clip_y_origin"
  1841. external xGCValues_set_ts_x_origin: gcv:xGCValues -> int -> unit = "ml_XGCValues_set_ts_x_origin"
  1842. external xGCValues_set_ts_y_origin: gcv:xGCValues -> int -> unit = "ml_XGCValues_set_ts_y_origin"
  1843. external xGCValues_set_line_style: gcv:xGCValues -> line_style -> unit = "ml_XGCValues_set_line_style"
  1844. external xGCValues_set_cap_style: gcv:xGCValues -> cap_style -> unit = "ml_XGCValues_set_cap_style"
  1845. external xGCValues_set_join_style: gcv:xGCValues -> join_style -> unit = "ml_XGCValues_set_join_style"
  1846. external xGCValues_set_fill_style: gcv:xGCValues -> fill_style -> unit = "ml_XGCValues_set_fill_style"
  1847. external xGCValues_set_fill_rule: gcv:xGCValues -> fill_rule -> unit = "ml_XGCValues_set_fill_rule"
  1848. external xGCValues_set_function: gcv:xGCValues -> logop_func -> unit = "ml_XGCValues_set_function"
  1849. external xGCValues_set_line_width: gcv:xGCValues -> int -> unit = "ml_XGCValues_set_line_width"
  1850. external xGCValues_set_arc_mode: gcv:xGCValues -> arc_mode -> unit = "ml_XGCValues_set_arc_mode"
  1851. external xGCValues_set_font: gcv:xGCValues -> font -> unit = "ml_XGCValues_set_font"
  1852. external xGCValues_set_subwindow_mode: gcv:xGCValues -> subwindow_mode -> unit = "ml_XGCValues_set_subwindow_mode"
  1853. external xGCValues_get_foreground: gcv:xGCValues -> pixel_color = "ml_XGCValues_get_foreground"
  1854. external xGCValues_get_background: gcv:xGCValues -> pixel_color = "ml_XGCValues_get_background"
  1855. external xGCValues_get_graphics_exposures: gcv:xGCValues -> bool = "ml_XGCValues_get_graphics_exposures"
  1856. external xGCValues_get_tile: gcv:xGCValues -> pixmap = "ml_XGCValues_get_tile"
  1857. external xGCValues_get_clip_x_origin: gcv:xGCValues -> int = "ml_XGCValues_get_clip_x_origin"
  1858. external xGCValues_get_clip_y_origin: gcv:xGCValues -> int = "ml_XGCValues_get_clip_y_origin"
  1859. external xGCValues_get_ts_x_origin: gcv:xGCValues -> int = "ml_XGCValues_get_ts_x_origin"
  1860. external xGCValues_get_ts_y_origin: gcv:xGCValues -> int = "ml_XGCValues_get_ts_y_origin"
  1861. external xGCValues_get_line_style: gcv:xGCValues -> line_style = "ml_XGCValues_get_line_style"
  1862. external xGCValues_get_cap_style: gcv:xGCValues -> cap_style = "ml_XGCValues_get_cap_style"
  1863. external xGCValues_get_join_style: gcv:xGCValues -> join_style = "ml_XGCValues_get_join_style"
  1864. external xGCValues_get_fill_style: gcv:xGCValues -> fill_style = "ml_XGCValues_get_fill_style"
  1865. external xGCValues_get_fill_rule: gcv:xGCValues -> fill_rule = "ml_XGCValues_get_fill_rule"
  1866. external xGCValues_get_function: gcv:xGCValues -> logop_func = "ml_XGCValues_get_function"
  1867. external xGCValues_get_line_width: gcv:xGCValues -> int = "ml_XGCValues_get_line_width"
  1868. external xGCValues_get_arc_mode: gcv:xGCValues -> arc_mode = "ml_XGCValues_get_arc_mode"
  1869. external xGCValues_get_font: gcv:xGCValues -> font = "ml_XGCValues_get_font"
  1870. external xGCValues_get_subwindow_mode: gcv:xGCValues -> subwindow_mode = "ml_XGCValues_get_subwindow_mode"
  1871. (* {{{ new_gc_values *)
  1872. type gc_values = {
  1873. gcValues: xGCValues;
  1874. set_foreground: fg:pixel_color -> unit;
  1875. set_background: bg:pixel_color -> unit;
  1876. set_graphics_exposures: bool -> unit;
  1877. set_tile: pixmap -> unit;
  1878. set_clip_x_origin: int -> unit;
  1879. set_clip_y_origin: int -> unit;
  1880. set_ts_x_origin: int -> unit;
  1881. set_ts_y_origin: int -> unit;
  1882. set_line_style: line_style -> unit;
  1883. set_cap_style: cap_style -> unit;
  1884. set_join_style: join_style -> unit;
  1885. set_fill_style: fill_style -> unit;
  1886. set_fill_rule: fill_rule -> unit;
  1887. set_function: logop_func -> unit;
  1888. set_line_width: int -> unit;
  1889. set_arc_mode: arc_mode -> unit;
  1890. set_font: font -> unit;
  1891. set_subwindow_mode: subwindow_mode -> unit;
  1892. foreground: pixel_color;
  1893. background: pixel_color;
  1894. graphics_exposures: bool;
  1895. tile: pixmap;
  1896. clip_x_origin: int;
  1897. clip_y_origin: int;
  1898. ts_x_origin: int;
  1899. ts_y_origin: int;
  1900. line_style: line_style;
  1901. cap_style: cap_style;
  1902. join_style: join_style;
  1903. fill_style: fill_style;
  1904. fill_rule: fill_rule;
  1905. logical_op: logop_func;
  1906. line_width: int;
  1907. arc_mode: arc_mode;
  1908. gc_font: font;
  1909. subwindow_mode: subwindow_mode;
  1910. }
  1911. (** a record to replace all the [xGCValues_set_*] and [xGCValues_get_*] functions *)
  1912. #if defined(MLI)
  1913. val new_gc_values : unit -> gc_values
  1914. (** replaces [new_xGCValues] *)
  1915. #else
  1916. let new_gc_values () =
  1917. let gcv = new_xGCValues() in
  1918. { gcValues = gcv;
  1919. set_foreground = xGCValues_set_foreground ~gcv;
  1920. set_background = xGCValues_set_background ~gcv;
  1921. set_graphics_exposures = xGCValues_set_graphics_exposures ~gcv;
  1922. set_tile = xGCValues_set_tile ~gcv;
  1923. set_clip_x_origin = xGCValues_set_clip_x_origin ~gcv;
  1924. set_clip_y_origin = xGCValues_set_clip_y_origin ~gcv;
  1925. set_ts_x_origin = xGCValues_set_ts_x_origin ~gcv;
  1926. set_ts_y_origin = xGCValues_set_ts_y_origin ~gcv;
  1927. set_line_style = xGCValues_set_line_style ~gcv;
  1928. set_cap_style = xGCValues_set_cap_style ~gcv;
  1929. set_join_style = xGCValues_set_join_style ~gcv;
  1930. set_fill_style = xGCValues_set_fill_style ~gcv;
  1931. set_fill_rule = xGCValues_set_fill_rule ~gcv;
  1932. set_function = xGCValues_set_function ~gcv;
  1933. set_line_width = xGCValues_set_line_width ~gcv;
  1934. set_arc_mode = xGCValues_set_arc_mode ~gcv;
  1935. set_font = xGCValues_set_font ~gcv;
  1936. set_subwindow_mode = xGCValues_set_subwindow_mode ~gcv;
  1937. foreground = xGCValues_get_foreground ~gcv;
  1938. background = xGCValues_get_background ~gcv;
  1939. graphics_exposures = xGCValues_get_graphics_exposures ~gcv;
  1940. tile = xGCValues_get_tile ~gcv;
  1941. clip_x_origin = xGCValues_get_clip_x_origin ~gcv;
  1942. clip_y_origin = xGCValues_get_clip_y_origin ~gcv;
  1943. ts_x_origin = xGCValues_get_ts_x_origin ~gcv;
  1944. ts_y_origin = xGCValues_get_ts_y_origin ~gcv;
  1945. line_style = xGCValues_get_line_style ~gcv;
  1946. cap_style = xGCValues_get_cap_style ~gcv;
  1947. join_style = xGCValues_get_join_style ~gcv;
  1948. fill_style = xGCValues_get_fill_style ~gcv;
  1949. fill_rule = xGCValues_get_fill_rule ~gcv;
  1950. logical_op = xGCValues_get_function ~gcv;
  1951. line_width = xGCValues_get_line_width ~gcv;
  1952. arc_mode = xGCValues_get_arc_mode ~gcv;
  1953. gc_font = xGCValues_get_font ~gcv;
  1954. subwindow_mode = xGCValues_get_subwindow_mode ~gcv;
  1955. }
  1956. #endif
  1957. (* }}} *)
  1958. type gc_valuemask =
  1959. | GCFunction
  1960. | GCPlaneMask
  1961. | GCForeground
  1962. | GCBackground
  1963. | GCLineWidth
  1964. | GCLineStyle
  1965. | GCCapStyle
  1966. | GCJoinStyle
  1967. | GCFillStyle
  1968. | GCFillRule
  1969. | GCTile
  1970. | GCStipple
  1971. | GCTileStipXOrigin
  1972. | GCTileStipYOrigin
  1973. | GCFont
  1974. | GCSubwindowMode
  1975. | GCGraphicsExposures
  1976. | GCClipXOrigin
  1977. | GCClipYOrigin
  1978. | GCClipMask
  1979. | GCDashOffset
  1980. | GCDashList
  1981. | GCArcMode
  1982. #if defined(ML)
  1983. external xCreateGC: dpy:display -> d:'a drawable -> gc_valuemask list -> xGCValues -> gc = "ml_XCreateGC"
  1984. external do_finalize_gc: gc -> unit = "do_finalize_GC"
  1985. let xCreateGC ~dpy ~d mask vals =
  1986. let gc = xCreateGC ~dpy ~d mask vals in
  1987. Gc.finalise do_finalize_gc gc;
  1988. (gc)
  1989. ;;
  1990. #else
  1991. val xCreateGC: dpy:display -> d:'a drawable -> gc_valuemask list -> xGCValues -> gc
  1992. (** {{:http://tronche.com/gui/x/xlib/GC/XCreateGC.html}man} *)
  1993. #endif
  1994. external xChangeGC: dpy:display -> gc:gc -> gc_valuemask list -> xGCValues -> unit = "ml_XChangeGC"
  1995. (** {{:http://tronche.com/gui/x/xlib/GC/XChangeGC.html}man} *)
  1996. external xGetGCValues: dpy:display -> gc:gc -> gc_valuemask list -> xGCValues = "ml_XGetGCValues"
  1997. (** {{:http://tronche.com/gui/x/xlib/GC/XGetGCValues.html}man} *)
  1998. external xSetLineAttributes: dpy:display -> gc:gc -> line_width:uint -> line_style:line_style ->
  1999. cap_style:cap_style -> join_style:join_style -> unit
  2000. = "ml_XSetLineAttributes_bytecode"
  2001. "ml_XSetLineAttributes"
  2002. (** {{:http://tronche.com/gui/x/xlib/GC/convenience-functions/XSetLineAttributes.html}man} *)
  2003. external xSetFillStyle: dpy:display -> gc:gc -> fill_style:fill_style -> unit = "ml_XSetFillStyle"
  2004. (** {{:http://tronche.com/gui/x/xlib/GC/convenience-functions/XSetFillStyle.html}man} *)
  2005. (** {3 Drawing} *)
  2006. external xSetForeground: dpy:display -> gc:gc -> fg:pixel_color -> unit = "ml_XSetForeground"
  2007. (** {{:http://tronche.com/gui/x/xlib/GC/convenience-functions/XSetForeground.html}man} *)
  2008. external xSetBackground: dpy:display -> gc:gc -> bg:pixel_color -> unit = "ml_XSetBackground"
  2009. (** {{:http://tronche.com/gui/x/xlib/GC/convenience-functions/XSetBackground.html}man} *)
  2010. external xClearWindow: dpy:display -> win:window -> unit = "ml_XClearWindow"
  2011. (** {{:http://tronche.com/gui/x/xlib/graphics/XClearWindow.html}man} *)
  2012. external xClearArea: dpy:display -> win:window -> x:int -> y:int ->
  2013. width:uint -> height:uint -> exposures:bool -> unit
  2014. = "ml_XClearArea_bytecode"
  2015. "ml_XClearArea"
  2016. (** {{:http://tronche.com/gui/x/xlib/graphics/XClearArea.html}man} *)
  2017. external xDrawPoint: dpy:display -> d:'a drawable -> gc:gc -> x:int -> y:int -> unit = "ml_XDrawPoint"
  2018. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawPoint.html}man} *)
  2019. type coordinate_mode =
  2020. | CoordModeOrigin
  2021. | CoordModePrevious
  2022. type xPoint = { pnt_x: int; pnt_y: int }
  2023. external xDrawPoints: dpy:display -> d:'a drawable -> gc:gc -> points: xPoint array -> mode:coordinate_mode -> unit
  2024. = "ml_XDrawPoints"
  2025. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawPoints.html}man} *)
  2026. external xDrawLine: dpy:display -> d:'a drawable -> gc:gc -> x1:int -> y1:int -> x2:int -> y2:int -> unit
  2027. = "ml_XDrawLine_bytecode"
  2028. "ml_XDrawLine"
  2029. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawLine.html}man} *)
  2030. external xDrawLines: dpy:display -> d:'a drawable -> gc:gc -> points: xPoint array -> mode:coordinate_mode -> unit
  2031. = "ml_XDrawLines"
  2032. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawLines.html}man} *)
  2033. type segment = {
  2034. x1:int;
  2035. y1:int;
  2036. x2:int;
  2037. y2:int;
  2038. }
  2039. external xDrawSegments: dpy:display -> d:'a drawable -> gc:gc -> segments:segment array -> unit = "ml_XDrawSegments"
  2040. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawSegments.html}man} *)
  2041. external xDrawRectangle: dpy:display -> d:'a drawable -> gc:gc ->
  2042. x:int -> y:int -> width:uint -> height:uint -> unit
  2043. = "ml_XDrawRectangle_bytecode"
  2044. "ml_XDrawRectangle"
  2045. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawRectangle.html}man} *)
  2046. external xFillRectangle: dpy:display -> d:'a drawable -> gc:gc ->
  2047. x:int -> y:int -> width:uint -> height:uint -> unit
  2048. = "ml_XFillRectangle_bytecode"
  2049. "ml_XFillRectangle"
  2050. (** {{:http://tronche.com/gui/x/xlib/graphics/filling-areas/XFillRectangle.html}man} *)
  2051. type x_rectangle = {
  2052. rect_x : int;
  2053. rect_y : int;
  2054. rect_width : uint;
  2055. rect_height : uint;
  2056. }
  2057. external xFillRectangles: dpy:display -> d:'a drawable -> gc:gc -> rectangles: x_rectangle array -> unit
  2058. = "ml_XFillRectangles"
  2059. (** {{:http://tronche.com/gui/x/xlib/graphics/filling-areas/XFillRectangles.html}man} *)
  2060. external xDrawRectangles: dpy:display -> d:'a drawable -> gc:gc -> rectangles: x_rectangle array -> unit
  2061. = "ml_XDrawRectangles"
  2062. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawRectangles.html}man} *)
  2063. external xDrawArc: dpy:display -> d:'a drawable -> gc:gc -> x:int -> y:int ->
  2064. width:uint -> height:uint -> angle1:int -> angle2:int -> unit
  2065. = "ml_XDrawArc_bytecode"
  2066. "ml_XDrawArc"
  2067. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawArc.html}man} *)
  2068. external xFillArc: dpy:display -> d:'a drawable -> gc:gc -> x:int -> y:int ->
  2069. width:uint -> height:uint -> angle1:int -> angle2:int -> unit
  2070. = "ml_XFillArc_bytecode"
  2071. "ml_XFillArc"
  2072. (** {{:http://tronche.com/gui/x/xlib/graphics/filling-areas/XFillArc.html}man} *)
  2073. type x_arc = {
  2074. arc_x : int;
  2075. arc_y : int;
  2076. arc_width : uint;
  2077. arc_height : uint;
  2078. arc_angle1 : int;
  2079. arc_angle2 : int;
  2080. }
  2081. external xDrawArcs: dpy:display -> d:'a drawable -> gc:gc -> arcs: x_arc array -> unit = "ml_XDrawArcs"
  2082. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing/XDrawArcs.html}man} *)
  2083. external xFillArcs: dpy:display -> d:'a drawable -> gc:gc -> arcs: x_arc array -> unit = "ml_XFillArcs"
  2084. (** {{:http://tronche.com/gui/x/xlib/graphics/filling-areas/XFillArcs.html}man} *)
  2085. type shape_kind =
  2086. | Complex
  2087. | Nonconvex
  2088. | Convex
  2089. external xFillPolygon: dpy:display -> d:'a drawable -> gc:gc -> points: xPoint array ->
  2090. shape:shape_kind -> mode:coordinate_mode -> unit
  2091. = "ml_XFillPolygon_bytecode"
  2092. "ml_XFillPolygon"
  2093. (** {{:http://tronche.com/gui/x/xlib/graphics/filling-areas/XFillPolygon.html}man} *)
  2094. external xDrawString: dpy:display -> d:'a drawable -> gc:gc ->
  2095. x:int -> y:int -> str:string -> unit
  2096. = "ml_XDrawString_bytecode"
  2097. "ml_XDrawString"
  2098. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing-text/XDrawString.html}man} *)
  2099. external xDrawImageString: dpy:display -> d:'a drawable -> gc:gc ->
  2100. x:int -> y:int -> str:string -> unit
  2101. = "ml_XDrawImageString_bytecode"
  2102. "ml_XDrawImageString"
  2103. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing-text/XDrawImageString.html}man} *)
  2104. (** {3 16 bit characters} *)
  2105. type xChar2b
  2106. external new_xChar2b: char * char -> xChar2b = "ml_alloc_XChar2b"
  2107. (** normal 16 bit characters are two bytes *)
  2108. type xChar2b_string
  2109. external new_xChar2b_string: (char * char) array -> xChar2b_string = "ml_alloc_XChar2b_string"
  2110. external xDrawImageString16: dpy:display -> d:'a drawable -> gc:gc ->
  2111. x:int -> y:int -> str16:xChar2b_string -> unit
  2112. = "ml_XDrawImageString16_bytecode"
  2113. "ml_XDrawImageString16"
  2114. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing-text/XDrawImageString16.html}man} *)
  2115. external xDrawString16: dpy:display -> d:'a drawable -> gc:gc ->
  2116. x:int -> y:int -> str16:xChar2b_string -> unit
  2117. = "ml_XDrawString16_bytecode"
  2118. "ml_XDrawString16"
  2119. (** {{:http://tronche.com/gui/x/xlib/graphics/drawing-text/XDrawString16.html}man} *)
  2120. (** {3 Drawable} *)
  2121. external xCopyArea: dpy:display ->
  2122. src:'a drawable -> dest:'b drawable -> gc:gc -> src_x:int -> src_y:int ->
  2123. width:uint -> height: uint -> dest_x:int -> dest_y:int -> unit
  2124. = "ml_XCopyArea_bytecode"
  2125. "ml_XCopyArea"
  2126. (** {{:http://tronche.com/gui/x/xlib/graphics/XCopyArea.html}man} *)
  2127. external xCreatePixmap: dpy:display -> d:'a drawable -> width:uint -> height:uint -> depth:uint -> pixmap
  2128. = "ml_XCreatePixmap"
  2129. (** {{:http://tronche.com/gui/x/xlib/pixmap-and-cursor/XCreatePixmap.html}man} *)
  2130. external xCreateBitmapFromData: dpy:display -> d:'a drawable -> data:string -> width:uint -> height:uint -> pixmap
  2131. = "ml_XCreateBitmapFromData"
  2132. (** {{:http://tronche.com/gui/x/xlib/utilities/XCreateBitmapFromData.html}man} *)
  2133. external xCreatePixmapCursor: dpy:display -> source:pixmap -> mask:pixmap ->
  2134. foreground:xColor -> background:xColor -> x:uint -> y:uint -> cursor
  2135. = "ml_XCreatePixmapCursor_bytecode"
  2136. "ml_XCreatePixmapCursor"
  2137. (** {{:http://tronche.com/gui/x/xlib/pixmap-and-cursor/XCreatePixmapCursor.html}man} *)
  2138. external xFreePixmap: dpy:display -> pixmap -> unit = "ml_XFreePixmap"
  2139. (** {{:http://tronche.com/gui/x/xlib/pixmap-and-cursor/XFreePixmap.html}man} *)
  2140. external xQueryBestTile: dpy:display -> d:'a drawable -> width:uint -> height:uint -> uint * uint = "ml_XQueryBestTile"
  2141. (** {{:http://tronche.com/gui/x/xlib/GC/convenience-functions/XQueryBestTile.html}man} *)
  2142. type xPixmapFormatValues = {
  2143. pxm_depth: int;
  2144. bits_per_pixel: int;
  2145. scanline_pad: int;
  2146. }
  2147. external xListPixmapFormats: dpy:display -> xPixmapFormatValues array = "ml_XListPixmapFormats"
  2148. (** {{:http://tronche.com/gui/x/xlib/display/image-format-macros.html#XListPixmapFormats}man} *)
  2149. external xBitmapUnit: dpy:display -> int = "ml_XBitmapUnit"
  2150. (** {{:http://tronche.com/gui/x/xlib/display/image-format-macros.html#BitmapUnit}man} *)
  2151. external xBitmapPad: dpy:display -> int = "ml_XBitmapPad"
  2152. (** {{:http://tronche.com/gui/x/xlib/display/image-format-macros.html#BitmapPad}man} *)
  2153. (** {4 XImage} *)
  2154. (** {{:http://tronche.com/gui/x/xlib/utilities/manipulating-images.html}
  2155. Manipulating Images} *)
  2156. type byte_order = LSBFirst | MSBFirst
  2157. external xImageByteOrder: dpy:display -> byte_order = "ml_XImageByteOrder"
  2158. (** {{:http://tronche.com/gui/x/xlib/display/image-format-macros.html#ImageByteOrder}man} *)
  2159. type ximage_format = XYBitmap | XYPixmap | ZPixmap
  2160. type xImage
  2161. external xCreateImage:
  2162. dpy:display -> visual:visual -> depth:int -> fmt:ximage_format -> offset:int ->
  2163. data:'a -> width:uint -> height:uint -> bitmap_pad:int -> bytes_per_line:int -> xImage
  2164. = "ml_XCreateImage_bytecode"
  2165. "ml_XCreateImage"
  2166. (** [data] can be a string or a bigarray (ala glcaml),
  2167. {{:http://tronche.com/gui/x/xlib/utilities/XCreateImage.html}man} *)
  2168. external xDestroyImage: image:xImage -> unit = "ml_XDestroyImage"
  2169. (** {{:http://tronche.com/gui/x/xlib/utilities/XDestroyImage.html}man} *)
  2170. external xSubImage: image:xImage -> x:int -> y:int -> width:uint -> height:uint -> xImage = "ml_XSubImage"
  2171. (** {{:http://tronche.com/gui/x/xlib/utilities/XSubImage.html}man} *)
  2172. external xAllPlanes: unit -> uint = "ml_XAllPlanes" (* TODO: maybe switch for an ocaml int32 *)
  2173. (** {{:http://tronche.com/gui/x/xlib/display/display-macros.html#XAllPlanes}man} *)
  2174. external xGetImage: dpy:display -> d:'a drawable -> x:int -> y:int ->
  2175. width:uint -> height:uint -> plane_mask:uint -> fmt:ximage_format -> xImage
  2176. = "ml_XGetImage_bytecode"
  2177. "ml_XGetImage"
  2178. (** {{:http://tronche.com/gui/x/xlib/graphics/XGetImage.html}man} *)
  2179. type image_data = (int, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Genarray.t
  2180. external xImage_data_ba: image:xImage -> image_data = "ml_XImage_data_ba" (* XXX : Experimental ; TODO : test me *)
  2181. external xImage_data_str: image:xImage -> string = "ml_XImage_data_str" (* XXX : Experimental ; TODO : test me *)
  2182. (** get the raw data *)
  2183. external xGetPixel: image:xImage -> x:int -> y:int -> pixel_color = "ml_XGetPixel"
  2184. external xPutPixel: image:xImage -> x:int -> y:int -> pixel:pixel_color -> unit = "ml_XPutPixel"
  2185. external xAddPixel: image:xImage -> v:int -> unit = "ml_XAddPixel"
  2186. external xPutImage: dpy:display -> d:'a drawable -> gc:gc -> image:xImage ->
  2187. src_x:int -> src_y:int -> dest_x:int -> dest_y:int -> width:uint -> height:uint -> unit
  2188. = "ml_XPutImage_bytecode"
  2189. "ml_XPutImage"
  2190. (** {4 Keyboard} *)
  2191. external xAutoRepeatOff: dpy:display -> unit = "ml_XAutoRepeatOff"
  2192. external xAutoRepeatOn: dpy:display -> unit = "ml_XAutoRepeatOn"
  2193. external xQueryKeymap: dpy:display -> string = "ml_XQueryKeymap"
  2194. (** {{:http://tronche.com/gui/x/xlib/input/XQueryKeymap.html}man} *)
  2195. external xQueryPointer: dpy:display -> win:window ->
  2196. window * int * int * (window * int * int) option * logical_state list
  2197. = "ml_XQueryPointer"
  2198. (** {{:http://tronche.com/gui/x/xlib/window-information/XQueryPointer.html}man} *)
  2199. #if defined(MLI)
  2200. module Got : sig
  2201. type auto_repeat_mode = AutoRepeatModeOff | AutoRepeatModeOn
  2202. end
  2203. module Set : sig
  2204. type auto_repeat_mode = AutoRepeatModeOff | AutoRepeatModeOn | AutoRepeatModeDefault
  2205. end
  2206. #else
  2207. module Got = struct
  2208. type auto_repeat_mode = AutoRepeatModeOff | AutoRepeatModeOn
  2209. end
  2210. module Set = struct
  2211. type auto_repeat_mode = AutoRepeatModeOff | AutoRepeatModeOn | AutoRepeatModeDefault
  2212. end
  2213. #endif
  2214. type xKeyboardState = {
  2215. key_click_percent: int;
  2216. bell_percent: int;
  2217. bell_pitch: uint;
  2218. bell_duration: uint;
  2219. led_mask: uint;
  2220. global_auto_repeat: Got.auto_repeat_mode;
  2221. auto_repeats: string;
  2222. }
  2223. external xGetKeyboardControl: dpy:display -> xKeyboardState = "ml_XGetKeyboardControl"
  2224. (** {{:http://tronche.com/gui/x/xlib/input/XGetKeyboardControl.html}man} *)
  2225. (** {4 ScreenSaver} *)
  2226. type screensaver_mode =
  2227. | ScreenSaverActive
  2228. | ScreenSaverReset
  2229. external xForceScreenSaver: dpy:display -> mode:screensaver_mode -> unit = "ml_XForceScreenSaver"
  2230. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XForceScreenSaver.html}man} *)
  2231. type prefer_blanking = DontPreferBlanking | PreferBlanking | DefaultBlanking
  2232. type allow_exposures = DontAllowExposures | AllowExposures | DefaultExposures
  2233. type screensaver_values = {
  2234. timeout: int;
  2235. interval: int;
  2236. prefer_blanking: prefer_blanking;
  2237. allow_exposures: allow_exposures;
  2238. }
  2239. external xGetScreenSaver: dpy:display -> screensaver_values = "ml_XGetScreenSaver"
  2240. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XGetScreenSaver.html}man} *)
  2241. external xSetScreenSaver:
  2242. dpy:display -> timeout:int -> interval:int -> prefer_blanking:prefer_blanking ->
  2243. allow_exposures:allow_exposures -> unit = "ml_XSetScreenSaver"
  2244. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XSetScreenSaver.html}man} *)
  2245. external xActivateScreenSaver: dpy:display -> unit = "ml_XActivateScreenSaver"
  2246. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XActivateScreenSaver.html}man} *)
  2247. external xResetScreenSaver: dpy:display -> unit = "ml_XResetScreenSaver"
  2248. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XResetScreenSaver.html}man} *)
  2249. (** {4 Error Handler} *)
  2250. (*
  2251. http://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html
  2252. http://tronche.com/gui/x/xlib/event-handling/XSync.html
  2253. *)
  2254. type xID
  2255. type xErrorEvent_contents = {
  2256. error_display: display;
  2257. error_resourceid: xID; (* resource id *)
  2258. error_serial: uint; (* serial number of failed request *)
  2259. error_error_code: char; (* error code of failed request *)
  2260. error_request_code: char; (* Major op-code of failed request *)
  2261. error_minor_code: char; (* Minor op-code of failed request *)
  2262. }
  2263. external xErrorEvent_datas: xErrorEvent xEvent -> xErrorEvent_contents = "ml_XErrorEvent_datas"
  2264. #if defined(ML)
  2265. external xSetErrorHandler: unit -> unit = "ml_XSetErrorHandler"
  2266. let xSetErrorHandler ~cb =
  2267. Callback.register "Error Handler Callback" cb;
  2268. xSetErrorHandler();
  2269. ;;
  2270. #else
  2271. val xSetErrorHandler: cb:(dpy:display -> event:xErrorEvent xEvent -> unit) -> unit
  2272. (** {{:http://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html}man},
  2273. {{:http://tronche.com/gui/x/xlib/event-handling/protocol-errors/XSetErrorHandler.html}man}
  2274. *)
  2275. #endif
  2276. (** {4 Cursor} *)
  2277. type cursor_shape =
  2278. | XC_X_cursor
  2279. | XC_arrow
  2280. | XC_based_arrow_down
  2281. | XC_based_arrow_up
  2282. | XC_boat
  2283. | XC_bogosity
  2284. | XC_bottom_left_corner
  2285. | XC_bottom_right_corner
  2286. | XC_bottom_side
  2287. | XC_bottom_tee
  2288. | XC_box_spiral
  2289. | XC_center_ptr
  2290. | XC_circle
  2291. | XC_clock
  2292. | XC_coffee_mug
  2293. | XC_cross
  2294. | XC_cross_reverse
  2295. | XC_crosshair
  2296. | XC_diamond_cross
  2297. | XC_dot
  2298. | XC_dotbox
  2299. | XC_double_arrow
  2300. | XC_draft_large
  2301. | XC_draft_small
  2302. | XC_draped_box
  2303. | XC_exchange
  2304. | XC_fleur
  2305. | XC_gobbler
  2306. | XC_gumby
  2307. | XC_hand1
  2308. | XC_hand2
  2309. | XC_heart
  2310. | XC_icon
  2311. | XC_iron_cross
  2312. | XC_left_ptr
  2313. | XC_left_side
  2314. | XC_left_tee
  2315. | XC_leftbutton
  2316. | XC_ll_angle
  2317. | XC_lr_angle
  2318. | XC_man
  2319. | XC_middlebutton
  2320. | XC_mouse
  2321. | XC_pencil
  2322. | XC_pirate
  2323. | XC_plus
  2324. | XC_question_arrow
  2325. | XC_right_ptr
  2326. | XC_right_side
  2327. | XC_right_tee
  2328. | XC_rightbutton
  2329. | XC_rtl_logo
  2330. | XC_sailboat
  2331. | XC_sb_down_arrow
  2332. | XC_sb_h_double_arrow
  2333. | XC_sb_left_arrow
  2334. | XC_sb_right_arrow
  2335. | XC_sb_up_arrow
  2336. | XC_sb_v_double_arrow
  2337. | XC_shuttle
  2338. | XC_sizing
  2339. | XC_spider
  2340. | XC_spraycan
  2341. | XC_star
  2342. | XC_target
  2343. | XC_tcross
  2344. | XC_top_left_arrow
  2345. | XC_top_left_corner
  2346. | XC_top_right_corner
  2347. | XC_top_side
  2348. | XC_top_tee
  2349. | XC_trek
  2350. | XC_ul_angle
  2351. | XC_umbrella
  2352. | XC_ur_angle
  2353. | XC_watch
  2354. | XC_xterm
  2355. external xCreateFontCursor: dpy:display -> shape:cursor_shape -> cursor = "ml_XCreateFontCursor"
  2356. (** {{:http://tronche.com/gui/x/xlib/pixmap-and-cursor/XCreateFontCursor.html}man} *)
  2357. external xDefineCursor: dpy:display -> win:window -> cursor:cursor -> unit = "ml_XDefineCursor"
  2358. (** {{:http://tronche.com/gui/x/xlib/window/XDefineCursor.html}man} *)
  2359. (* TODO test me *)
  2360. external xRecolorCursor: dpy:display -> cursor:cursor -> foreground:xColor -> background:xColor -> unit
  2361. = "ml_XRecolorCursor"
  2362. (** {{:http://tronche.com/gui/x/xlib/pixmap-and-cursor/XRecolorCursor.html}man} *)
  2363. (** {5 Mouse Control} *)
  2364. external xChangePointerControl:
  2365. dpy:display ->
  2366. do_accel:bool ->
  2367. do_threshold:bool ->
  2368. accel_numerator:int ->
  2369. accel_denominator:int ->
  2370. threshold:int -> unit
  2371. = "ml_XChangePointerControl_bytecode"
  2372. "ml_XChangePointerControl"
  2373. (** {{:http://tronche.com/gui/x/xlib/input/XChangePointerControl.html}man} *)
  2374. (* TODO: test this function *)
  2375. external xGetPointerControl: dpy:display -> int * int * int = "ml_XGetPointerControl"
  2376. (** returns (accel_numerator, accel_denominator, threshold) *)
  2377. (** {4 Window Manager} *)
  2378. external xReparentWindow: dpy:display -> win:window -> parent:window -> x:int -> y:int -> unit = "ml_XReparentWindow"
  2379. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XReparentWindow.html}man} *)
  2380. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/controlling-window-lifetime.html}
  2381. Controlling the Lifetime of a Window} *)
  2382. type change_mode =
  2383. | SetModeInsert
  2384. | SetModeDelete
  2385. external xChangeSaveSet: dpy:display -> win:window -> mode:change_mode -> unit = "ml_XChangeSaveSet"
  2386. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XChangeSaveSet.html}man} *)
  2387. external xAddToSaveSet: dpy:display -> win:window -> unit = "ml_XAddToSaveSet"
  2388. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XAddToSaveSet.html}man} *)
  2389. external xRemoveFromSaveSet: dpy:display -> win:window -> unit = "ml_XRemoveFromSaveSet"
  2390. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XRemoveFromSaveSet.html}man} *)
  2391. external xKillClient: dpy:display -> resource:window -> unit = "ml_XKillClient"
  2392. (** {{:http://tronche.com/gui/x/xlib/window-and-session-manager/XKillClient.html}man} *)
  2393. (** {5 Threads} *)
  2394. external xInitThreads: unit -> unit = "ml_XInitThreads"
  2395. external xLockDisplay: dpy:display -> unit = "ml_XLockDisplay"
  2396. external xUnlockDisplay: dpy:display -> unit = "ml_XUnlockDisplay"
  2397. (** {3 ICCCM routines} *)
  2398. (*
  2399. Status XReconfigureWMWindow(
  2400. Display* /* display */,
  2401. Window /* w */,
  2402. int /* screen_number */,
  2403. unsigned int /* mask */,
  2404. XWindowChanges* /* changes */
  2405. );
  2406. Status XGetWMProtocols(
  2407. Display* /* display */,
  2408. Window /* w */,
  2409. Atom** /* protocols_return */,
  2410. int* /* count_return */
  2411. );
  2412. Status XSetWMProtocols(
  2413. Display* /* display */,
  2414. Window /* w */,
  2415. Atom* /* protocols */,
  2416. int /* count */
  2417. );
  2418. *)
  2419. external xIconifyWindow: dpy:display -> win:window -> scr:screen_number -> unit = "ml_XIconifyWindow"
  2420. (** {{:http://tronche.com/gui/x/xlib/ICC/client-to-window-manager/XIconifyWindow.html}man} *)
  2421. external xWithdrawWindow: dpy:display -> win:window -> scr:screen_number -> unit = "ml_XWithdrawWindow"
  2422. (** {{:http://tronche.com/gui/x/xlib/ICC/client-to-window-manager/XWithdrawWindow.html}man} *)
  2423. external xGetCommand: dpy:display -> win:window -> string array = "ml_XGetCommand"
  2424. (** {{:http://tronche.com/gui/x/xlib/ICC/client-to-session-manager/XGetCommand.html}man} *)
  2425. (*
  2426. Status XGetWMColormapWindows(
  2427. Display* /* display */,
  2428. Window /* w */,
  2429. Window** /* windows_return */,
  2430. int* /* count_return */
  2431. );
  2432. Status XSetWMColormapWindows(
  2433. Display* /* display */,
  2434. Window /* w */,
  2435. Window* /* colormap_windows */,
  2436. int /* count */
  2437. );
  2438. void XFreeStringList(
  2439. char** /* list */
  2440. );
  2441. int XSetTransientForHint(
  2442. Display* /* display */,
  2443. Window /* w */,
  2444. Window /* prop_window */
  2445. );
  2446. *)
  2447. (* vim: sw=2 sts=2 ts=2 et fdm=marker
  2448. *)