PageRenderTime 75ms CodeModel.GetById 23ms RepoModel.GetById 0ms 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

Large files files are truncated, but you can click here to view the full 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 : xCo

Large files files are truncated, but you can click here to view the full file