Source file function_description.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
open Ctypes

(* This Types_generated module is an instantiation of the Types
   functor defined in the type_description.ml file. It's generated by
   a C program that Dune creates and runs behind the scenes. *)
module T = Types_generated

module Functions (F : FOREIGN) = struct
  open F

  let returning_ignored x = returning (view ~read:(Fun.const ()) ~write:(fun _ -> assert false) x)

  let int_uint = view ~read:Unsigned.UInt.to_int ~write:Unsigned.UInt.of_int uint
  let int_uint32 = view ~read:Unsigned.UInt32.to_int ~write:Unsigned.UInt32.of_int uint32_t
  let int_int32 = view ~read:Int32.to_int ~write:Int32.of_int int32_t

  let keycode = view uint32_t ~read:Keycode.of_uint32 ~write:Keycode.to_uint32
  let time_usec = view ~read:Unsigned.UInt64.to_int64 ~write:Unsigned.UInt64.of_int64 uint64_t

  let bool_int = view ~read:((<>) 0) ~write:Bool.to_int int
  let bool_uint32 = view ~read:((<>) Unsigned.UInt32.zero) ~write:(fun t -> Unsigned.UInt32.of_int (Bool.to_int t)) uint32_t

  let foreign_opt ~requires name typ = if Config.version >= requires then Some (foreign name typ) else None

  (* Supporing libraries *)

  let major = foreign "major" @@ PosixTypes.dev_t @-> returning uint
  let minor = foreign "minor" @@ PosixTypes.dev_t @-> returning uint

  module Udev = struct
    let create = foreign "udev_new" @@ void @-> returning (ptr_opt T.Udev.t)
    let unref = foreign "udev_unref" @@ ptr T.Udev.t @-> returning_ignored (ptr_opt T.Udev.t)
  end

  (* libinput functions *)

  let udev_create_context = foreign "libinput_udev_create_context" @@
    ptr T.Interface.t @->
    ptr void @->
    ptr T.Udev.t @->
    returning (ptr_opt T.Libinput.t)

  let udev_assign_seat = foreign "libinput_udev_assign_seat" @@
    ptr T.Libinput.t @->
    string @->
    returning int

  let unref = foreign "libinput_unref" @@
    ptr T.Libinput.t @->
    returning (ptr_opt T.Libinput.t)

  let dispatch = foreign "libinput_dispatch" @@
    ptr T.Libinput.t @->
    returning int

  let path_create_context = foreign "libinput_path_create_context" @@
    ptr T.Interface.t @->
    ptr void @->
    returning (ptr_opt T.Libinput.t)

  let path_add_device = foreign "libinput_path_add_device" @@
    ptr T.Libinput.t @->
    string @->
    returning (ptr_opt T.Device.t)

  let path_remove_device = foreign "libinput_path_remove_device" @@
    ptr T.Device.t @->
    returning void

  module Log = struct
    let set_priority = foreign "libinput_log_set_priority" @@
      ptr T.Libinput.t @->
      T.Log_priority.t @->
      returning void

    let get_priority = foreign "libinput_log_get_priority" @@
      ptr T.Libinput.t @->
      returning T.Log_priority.t

    let set_handler = foreign "caml_libinput_log_set_handler_simple" @@
      ptr T.Libinput.t @->
      T.log_handler_simple @->
      returning void
  end

  module Device_group = struct
    type t = T.Device_group.t ptr
    let t = ptr T.Device_group.t

    let ref = foreign "libinput_device_group_ref" @@ t @-> returning_ignored t
    let unref = foreign "libinput_device_group_unref" @@ t @-> returning_ignored (ptr_opt T.Device_group.t)
  end

  module Device = struct
    type t = T.Device.t ptr

    let t = ptr T.Device.t
    let get_sysname = foreign "libinput_device_get_sysname" @@ t @-> returning string
    let get_name = foreign "libinput_device_get_name" @@ t @-> returning string
    let has_capability = foreign "libinput_device_has_capability" @@ t @-> T.Device_capability.t @-> returning bool_int
    let get_seat = foreign "libinput_device_get_seat" @@ t @-> returning (ptr T.Seat.t)
    let get_device_group = foreign "libinput_device_get_device_group" @@ t @-> returning Device_group.t
    let get_id_bustype = foreign_opt ~requires:(1, 26) "libinput_device_get_id_bustype" @@ (t @-> returning int_uint)
    let get_id_product = foreign "libinput_device_get_id_product" @@ t @-> returning int_uint
    let get_id_vendor = foreign "libinput_device_get_id_vendor" @@ t @-> returning int_uint
    let get_output_name = foreign "libinput_device_get_output_name" @@ t @-> returning (ptr_opt (const char))
    let set_seat_logical_name = foreign "libinput_device_set_seat_logical_name" @@ t @-> string @-> returning int
    let get_size = foreign "libinput_device_get_size" @@ t @-> ptr double @-> ptr double @-> returning int
    let keyboard_has_key = foreign "libinput_device_keyboard_has_key" @@ t @-> keycode @-> returning int
    let pointer_has_button = foreign "libinput_device_pointer_has_button" @@ t @-> keycode @-> returning int
    let touch_get_touch_count = foreign "libinput_device_touch_get_touch_count" @@ t @-> returning int
    let switch_has_switch = foreign "libinput_device_switch_has_switch" @@ t @-> T.Switch.t @-> returning int

    let led_update = foreign "libinput_device_led_update" @@ t @-> T.Led.t @-> returning void

    module Tablet_pad = struct
      let get_num_mode_groups = foreign "libinput_device_tablet_pad_get_num_mode_groups" @@ t @-> returning int
      let get_mode_group = foreign "libinput_device_tablet_pad_get_mode_group" @@ t @-> int_uint @-> returning (ptr_opt T.Mode_group.t)
      let get_num_buttons = foreign "libinput_device_tablet_pad_get_num_buttons" @@ t @-> returning int
      let get_num_dials = foreign_opt ~requires:(1, 26) "libinput_device_tablet_pad_get_num_dials" @@ t @-> returning int
      let get_num_rings = foreign "libinput_device_tablet_pad_get_num_rings" @@ t @-> returning int
      let get_num_strips = foreign "libinput_device_tablet_pad_get_num_strips" @@ t @-> returning int
      let has_key = foreign "libinput_device_tablet_pad_has_key" @@ t @-> keycode @-> returning int
    end

    let ref = foreign "libinput_device_ref" @@ t @-> returning_ignored t
    let unref = foreign "libinput_device_unref" @@ t @-> returning_ignored (ptr_opt T.Device.t)

    module Config = struct
      module Setting = struct
        type nonrec 'a t =
          | Unsupported of 'a
          | Setting of {
              set : (t -> 'a -> T.Config.status return) F.result;
              get : (t -> 'a return) F.result;
              get_default : (t -> 'a return) F.result;
            }

        let make ?unless pattern ty =
          match unless with
          | Some (false, default) -> Unsupported default
          | _ ->
            let name x = Printf.sprintf pattern x in
            let set = foreign (name "set") @@ t @-> ty @-> returning T.Config.status in
            let get = foreign (name "get") @@ t @-> returning ty in
            let get_default = foreign (name "get_default") @@ t @-> returning ty in
            Setting { set; get; get_default }
      end

      module Tap = struct
        let enabled = Setting.make "libinput_device_config_tap_%s_enabled" T.Config.tap_state
        let get_finger_count = foreign "libinput_device_config_tap_get_finger_count" @@ t @-> returning int
        let button_map = Setting.make "libinput_device_config_tap_%s_button_map" T.Config.tap_button_map
        let drag_enabled = Setting.make "libinput_device_config_tap_%s_drag_enabled" T.Config.drag_state
        let drag_lock_enabled = Setting.make "libinput_device_config_tap_%s_drag_lock_enabled" T.Config.drag_lock_state
      end

      module Three_finger_drag = struct
        let supported = Config.version >= (1, 28)

        let get_finger_count =
          if supported then Some (foreign "libinput_device_config_3fg_drag_get_finger_count" @@ t @-> returning int)
          else None

        let enabled = Setting.make "libinput_device_config_3fg_drag_%s_enabled" T.Config.three_finger_drag_state
            ~unless:(supported, `Disabled)
      end

      module Calibration_matrix = struct
        type matrix = (float * float * float) * (float * float * float)

        let c_matrix = ptr float

        let matrix : matrix typ =
          view c_matrix
            ~read:(fun x ->
                let get i = !@ (x +@ i) in
                (get 0, get 1, get 2),
                (get 3, get 4, get 5)
              )
            ~write:(fun ((a, b, c), (d, e, f)) ->
                (CArray.of_list float [a; b; c; d; e; f]).astart
              )

        let create_matrix () = allocate_n float ~count:6
        let matrix_of_ptr x = Ctypes.(coerce (ptr float)) matrix x

        let is_supported = foreign "libinput_device_config_calibration_has_matrix" @@ t @-> returning bool_int
        let set = foreign "libinput_device_config_calibration_set_matrix" @@ t @-> matrix @-> returning T.Config.status
        let get = foreign "libinput_device_config_calibration_get_matrix" @@ t @-> c_matrix @-> returning bool_int
        let get_default = foreign "libinput_device_config_calibration_get_default_matrix" @@ t @-> c_matrix @-> returning bool_int
      end

      module Area = struct
        module A = T.Config.Area_rectangle

        let name = Printf.sprintf "libinput_device_config_area_%s_rectangle"
        let has_rectangle = foreign_opt ~requires:(1, 26) (name "has") @@ t @-> returning bool_int
        let set_rectangle = foreign_opt ~requires:(1, 26) (name "set") @@ t @-> ptr A.t @-> returning T.Config.status
        let get_rectangle = foreign_opt ~requires:(1, 26) (name "get") @@ t @-> returning A.t
        let get_default_rectangle = foreign_opt ~requires:(1, 26) (name "get_default") @@ t @-> returning A.t
      end

      module Send_events = struct
        let get_modes = foreign "libinput_device_config_send_events_get_modes" @@ t @-> returning T.Config.Send_events_mode.t
        let mode = Setting.make "libinput_device_config_send_events_%s_mode" T.Config.Send_events_mode.t
      end

      module Accel = struct
        let is_available = foreign "libinput_device_config_accel_is_available" @@ t @-> returning bool_int
        let speed = Setting.make "libinput_device_config_accel_%s_speed" double

        type custom = {
          accel_create : (Unsigned.uint32 -> T.Config.Accel.t Ctypes.ptr option return) F.result;
          accel_destroy : (T.Config.Accel.t Ctypes.ptr -> unit return) F.result;
          accel_apply : (t -> T.Config.Accel.t Ctypes.ptr -> T.Config.status return) F.result;
          accel_set_points :
            (T.Config.Accel.t Ctypes.ptr ->
             T.Config.accel_type ->
             float ->
             PosixTypes.size_t -> float Ctypes.ptr -> T.Config.status return) F.result;
        }

        let custom =
          T.Config.Accel.t |> Option.map (fun accel -> {
                accel_create = foreign "libinput_config_accel_create" @@ T.Config.Accel_profile.t @-> returning (ptr_opt accel);
                accel_destroy = foreign "libinput_config_accel_destroy" @@ ptr accel @-> returning void;
                accel_apply = foreign "libinput_device_config_accel_apply" @@ t @-> ptr accel @-> returning T.Config.status;
                accel_set_points = foreign "libinput_config_accel_set_points" @@
                  ptr accel @->
                  T.Config.accel_type @->
                  double @->
                  size_t @->
                  ptr double @->
                  returning T.Config.status;
              }
            )

        let accel_get_profiles = foreign "libinput_device_config_accel_get_profiles" @@ t @-> returning T.Config.Accel_profile.t
        let profile = Setting.make "libinput_device_config_accel_%s_profile" T.Config.Accel_profile.t
      end

      module Scoll = struct
        let has_natural_scroll = foreign "libinput_device_config_scroll_has_natural_scroll" @@ t @-> returning bool_int
        let scroll_enabled = Setting.make "libinput_device_config_scroll_%s_natural_scroll_enabled" bool_int
      end

      module Left_handled = struct
        let is_available = foreign "libinput_device_config_left_handed_is_available" @@ t @-> returning bool_int
        let enabled = Setting.make "libinput_device_config_left_handed_%s" bool_int
      end

      module Click = struct
        let get_methods = foreign "libinput_device_config_click_get_methods" @@ t @-> returning T.Config.Click_method.t
        let meth = Setting.make "libinput_device_config_click_%s_method" T.Config.Click_method.t
        let clickfinger_button_map = Setting.make "libinput_device_config_click_%s_clickfinger_button_map" T.Config.clickfinger_button_map
            ~unless:(Config.version >= (1, 26), `LRM)
      end

      module Middle_emulation = struct
        let is_available = foreign "libinput_device_config_middle_emulation_is_available" @@ t @-> returning bool_int
        let enabled = Setting.make "libinput_device_config_middle_emulation_%s_enabled" bool_int
      end

      module Scroll = struct
        let get_methods = foreign "libinput_device_config_scroll_get_methods" @@ t @-> returning T.Config.Scroll_method.t
        let meth = Setting.make "libinput_device_config_scroll_%s_method" T.Config.Scroll_method.t
        let button = Setting.make "libinput_device_config_scroll_%s_button" keycode
        let button_lock = Setting.make "libinput_device_config_scroll_%s_button_lock" T.Config.scroll_button_lock_state
      end

      module Dwt = struct
        let is_available = foreign "libinput_device_config_dwt_is_available" @@ t @-> returning bool_int
        let enabled = Setting.make "libinput_device_config_dwt_%s_enabled" T.Config.dwt_state
      end

      module Dwtp = struct
        let is_available = foreign_opt ~requires:(1, 21) "libinput_device_config_dwtp_is_available" @@ t @-> returning bool_int
        let enabled =
          match T.Config.dwtp_state with
          | Some t -> Setting.make "libinput_device_config_dwtp_%s_enabled" t
          | None -> Unsupported `Disabled
      end

      module Rotation = struct
        let is_available = foreign "libinput_device_config_rotation_is_available" @@ t @-> returning bool_int
        let angle = Setting.make "libinput_device_config_rotation_%s_angle" int
      end
    end
  end

  module Seat = struct
    type t = T.Seat.t Ctypes.ptr
    let t = ptr T.Seat.t

    let ref = foreign "libinput_seat_ref" @@ t @-> returning_ignored t
    let unref = foreign "libinput_seat_unref" @@ t @-> returning_ignored (ptr_opt T.Seat.t)

    let get_physical_name = foreign "libinput_seat_get_physical_name" @@ t @-> returning string
    let get_logical_name = foreign "libinput_seat_get_logical_name" @@ t @-> returning string
  end

  module Tool = struct
    type t = T.Tool.t ptr
    let t = ptr T.Tool.t

    let ref = foreign "libinput_tablet_tool_ref" @@ t @-> returning_ignored t
    let unref = foreign "libinput_tablet_tool_unref" @@ t @-> returning_ignored (ptr_opt T.Tool.t)

    let get_type = foreign "libinput_tablet_tool_get_type" @@ t @-> returning T.Tool_type.t
    let get_tool_id = foreign "libinput_tablet_tool_get_tool_id" @@ t @-> returning uint64_t
    let has_pressure = foreign "libinput_tablet_tool_has_pressure" @@ t @-> returning bool_int
    let has_distance = foreign "libinput_tablet_tool_has_distance" @@ t @-> returning bool_int
    let has_tilt = foreign "libinput_tablet_tool_has_tilt" @@ t @-> returning bool_int
    let has_rotation = foreign "libinput_tablet_tool_has_rotation" @@ t @-> returning bool_int
    let has_slider = foreign "libinput_tablet_tool_has_slider" @@ t @-> returning bool_int
    let has_size = foreign "libinput_tablet_tool_has_size" @@ t @-> returning bool_int
    let has_wheel = foreign "libinput_tablet_tool_has_wheel" @@ t @-> returning bool_int
    let has_button = foreign "libinput_tablet_tool_has_button" @@ t @-> int_uint32 @-> returning bool_int
    let is_unique = foreign "libinput_tablet_tool_is_unique" @@ t @-> returning bool_int
    let get_serial = foreign "libinput_tablet_tool_get_serial" @@ t @-> returning uint64_t

    module Config = struct
      module Setting = struct
        type nonrec 'a t = 
          | Unsupported of 'a
          | Setting of {
              set : (t -> 'a -> T.Config.status return) F.result;
              get : (t -> 'a return) F.result;
              get_default : (t -> 'a return) F.result;
            }

        let make ?unless pattern ty =
          match unless with
          | Some (false, default) -> Unsupported default
          | _ ->
            let name x = Printf.sprintf pattern x in
            let set = foreign (name "set") @@ t @-> ty @-> returning T.Config.status in
            let get = foreign (name "get") @@ t @-> returning ty in
            let get_default = foreign (name "get_default") @@ t @-> returning ty in
            Setting { set; get; get_default }
      end

      module Pressure_range = struct
        let is_available = foreign_opt ~requires:(1, 26) "libinput_tablet_tool_config_pressure_range_is_available" @@ t @-> returning bool_int
        let set = foreign_opt ~requires:(1, 26) "libinput_tablet_tool_config_pressure_range_set" @@ t @-> double @-> double @-> returning T.Config.status
        let get_minimum = foreign_opt ~requires:(1, 26) "libinput_tablet_tool_config_pressure_range_get_minimum" @@ t @-> returning double
        let get_maximum = foreign_opt ~requires:(1, 26) "libinput_tablet_tool_config_pressure_range_get_maximum" @@ t @-> returning double
        let get_default_minimum = foreign_opt ~requires:(1, 26) "libinput_tablet_tool_config_pressure_range_get_default_minimum" @@ t @-> returning double
        let get_default_maximum = foreign_opt ~requires:(1, 26) "libinput_tablet_tool_config_pressure_range_get_default_maximum" @@ t @-> returning double
      end

      module Eraser_button = struct
        let supported = T.Eraser_button_mode.supported

        let get_modes =
          if supported then Some (foreign "libinput_tablet_tool_config_eraser_button_get_modes" @@ t @-> returning bool_uint32)
          else None

        let mode = Setting.make "libinput_tablet_tool_config_eraser_button_%s_mode" T.Eraser_button_mode.t
            ~unless:(supported, T.Eraser_button_mode.Default)

        let button = Setting.make "libinput_tablet_tool_config_eraser_button_%s_button" int_uint32
            ~unless:(supported, 0)
      end
    end
  end

  module Mode_group = struct
    type t = T.Mode_group.t ptr
    let t = ptr T.Mode_group.t

    let ref = foreign "libinput_tablet_pad_mode_group_ref" @@ t @-> returning_ignored t
    let unref = foreign "libinput_tablet_pad_mode_group_unref" @@ t @-> returning_ignored (ptr_opt T.Mode_group.t)

    let get_index = foreign "libinput_tablet_pad_mode_group_get_index" @@ t @-> returning int_uint
    let get_num_modes = foreign "libinput_tablet_pad_mode_group_get_num_modes" @@ t @-> returning int_uint
    let get_mode = foreign "libinput_tablet_pad_mode_group_get_mode" @@ t @-> returning int_uint
    let has_button = foreign "libinput_tablet_pad_mode_group_has_button" @@ t @-> int_uint @-> returning bool_int
    let has_dial = foreign_opt ~requires:(1, 26) "libinput_tablet_pad_mode_group_has_dial" @@ t @-> int_uint @-> returning bool_int
    let has_ring = foreign "libinput_tablet_pad_mode_group_has_ring" @@ t @-> int_uint @-> returning bool_int
    let has_strip = foreign "libinput_tablet_pad_mode_group_has_strip" @@ t @-> int_uint @-> returning bool_int
    let button_is_toggle = foreign "libinput_tablet_pad_mode_group_button_is_toggle" @@ t @-> int_uint @-> returning bool_int
  end

  module Event = struct
    type t = T.Event.t ptr
    let t = ptr T.Event.t

    let get_type = foreign "libinput_event_get_type" @@ t @-> returning T.Event.Type.t
    let get_context = foreign "libinput_event_get_context" @@ t @-> returning (ptr T.Libinput.t)
    let get_device = foreign "libinput_event_get_device" @@ t @-> returning (ptr T.Device.t)
    let destroy = foreign "libinput_event_destroy" @@ t @-> returning void

    module Keyboard = struct
      let get_event = foreign "libinput_event_get_keyboard_event" @@ t @-> returning (ptr_opt T.Event.Keyboard.t)

      let t = ptr T.Event.Keyboard.t

      let get_time_usec = foreign "libinput_event_keyboard_get_time_usec" @@ t @-> returning time_usec
      let get_key = foreign "libinput_event_keyboard_get_key" @@ t @-> returning keycode
      let get_key_state = foreign "libinput_event_keyboard_get_key_state" @@ t @-> returning T.key_state
      let get_seat_key_count = foreign "libinput_event_keyboard_get_seat_key_count" @@ t @-> returning int_uint32
    end

    module Pointer = struct
      let get_event = foreign "libinput_event_get_pointer_event" @@ t @-> returning (ptr_opt T.Event.Pointer.t)

      let t = ptr T.Event.Pointer.t

      let get_time_usec = foreign "libinput_event_pointer_get_time_usec" @@ t @-> returning time_usec

      let get_dx = foreign "libinput_event_pointer_get_dx" @@ t @-> returning double
      let get_dy = foreign "libinput_event_pointer_get_dy" @@ t @-> returning double

      let get_dx_unaccelerated = foreign "libinput_event_pointer_get_dx_unaccelerated" @@ t @-> returning double
      let get_dy_unaccelerated = foreign "libinput_event_pointer_get_dy_unaccelerated" @@ t @-> returning double

      let get_absolute_x = foreign "libinput_event_pointer_get_absolute_x" @@ t @-> returning double
      let get_absolute_y = foreign "libinput_event_pointer_get_absolute_y" @@ t @-> returning double

      let get_absolute_x_transformed = foreign "libinput_event_pointer_get_absolute_x_transformed" @@ t @-> int_uint32 @-> returning double
      let get_absolute_y_transformed = foreign "libinput_event_pointer_get_absolute_y_transformed" @@ t @-> int_uint32 @-> returning double

      let get_button = foreign "libinput_event_pointer_get_button" @@ t @-> returning keycode
      let get_button_state = foreign "libinput_event_pointer_get_button_state" @@ t @-> returning T.button_state

      let get_seat_button_count = foreign "libinput_event_pointer_get_seat_button_count" @@ t @-> returning int_uint32

      let has_axis = foreign "libinput_event_pointer_has_axis" @@ t @-> T.axis @-> returning int
      let get_scroll_value = foreign "libinput_event_pointer_get_scroll_value" @@ t @-> T.axis @-> returning double
      let get_scroll_value_v120 = foreign "libinput_event_pointer_get_scroll_value_v120" @@ t @-> T.axis @-> returning double
    end

    module Touch = struct
      let get_event = foreign "libinput_event_get_touch_event" @@ t @-> returning (ptr_opt T.Event.Touch.t)

      let t = ptr T.Event.Touch.t

      let get_time_usec = foreign "libinput_event_touch_get_time_usec" @@ t @-> returning time_usec

      let get_slot = foreign "libinput_event_touch_get_slot" @@ t @-> returning int_int32
      let get_seat_slot = foreign "libinput_event_touch_get_seat_slot" @@ t @-> returning int_int32

      let get_x = foreign "libinput_event_touch_get_x" @@ t @-> returning double
      let get_y = foreign "libinput_event_touch_get_y" @@ t @-> returning double

      let get_x_transformed = foreign "libinput_event_touch_get_x_transformed" @@ t @-> int_uint32 @-> returning double
      let get_y_transformed = foreign "libinput_event_touch_get_y_transformed" @@ t @-> int_uint32 @-> returning double
    end

    module Tablet_tool = struct
      let get_event = foreign "libinput_event_get_tablet_tool_event" @@ t @-> returning (ptr_opt T.Event.Tablet_tool.t)

      let t = ptr T.Event.Tablet_tool.t

      let get_time_usec = foreign "libinput_event_tablet_tool_get_time_usec" @@ t @-> returning time_usec

      let x_has_changed = foreign "libinput_event_tablet_tool_x_has_changed" @@ t @-> returning bool_int
      let y_has_changed = foreign "libinput_event_tablet_tool_y_has_changed" @@ t @-> returning bool_int
      let pressure_has_changed = foreign "libinput_event_tablet_tool_pressure_has_changed" @@ t @-> returning bool_int
      let distance_has_changed = foreign "libinput_event_tablet_tool_distance_has_changed" @@ t @-> returning bool_int
      let tilt_x_has_changed = foreign "libinput_event_tablet_tool_tilt_x_has_changed" @@ t @-> returning bool_int
      let tilt_y_has_changed = foreign "libinput_event_tablet_tool_tilt_y_has_changed" @@ t @-> returning bool_int
      let rotation_has_changed = foreign "libinput_event_tablet_tool_rotation_has_changed" @@ t @-> returning bool_int
      let slider_has_changed = foreign "libinput_event_tablet_tool_slider_has_changed" @@ t @-> returning bool_int
      let size_major_has_changed = foreign "libinput_event_tablet_tool_size_major_has_changed" @@ t @-> returning bool_int
      let size_minor_has_changed = foreign "libinput_event_tablet_tool_size_minor_has_changed" @@ t @-> returning bool_int
      let wheel_has_changed = foreign "libinput_event_tablet_tool_wheel_has_changed" @@ t @-> returning bool_int

      let get_x = foreign "libinput_event_tablet_tool_get_x" @@ t @-> returning double
      let get_y = foreign "libinput_event_tablet_tool_get_y" @@ t @-> returning double
      let get_dx = foreign "libinput_event_tablet_tool_get_dx" @@ t @-> returning double
      let get_dy = foreign "libinput_event_tablet_tool_get_dy" @@ t @-> returning double
      let get_pressure = foreign "libinput_event_tablet_tool_get_pressure" @@ t @-> returning double
      let get_distance = foreign "libinput_event_tablet_tool_get_distance" @@ t @-> returning double
      let get_tilt_x = foreign "libinput_event_tablet_tool_get_tilt_x" @@ t @-> returning double
      let get_tilt_y = foreign "libinput_event_tablet_tool_get_tilt_y" @@ t @-> returning double
      let get_rotation = foreign "libinput_event_tablet_tool_get_rotation" @@ t @-> returning double
      let get_slider_position = foreign "libinput_event_tablet_tool_get_slider_position" @@ t @-> returning double
      let get_size_major = foreign "libinput_event_tablet_tool_get_size_major" @@ t @-> returning double
      let get_size_minor = foreign "libinput_event_tablet_tool_get_size_minor" @@ t @-> returning double
      let get_wheel_delta = foreign "libinput_event_tablet_tool_get_wheel_delta" @@ t @-> returning double
      let get_wheel_delta_discrete = foreign "libinput_event_tablet_tool_get_wheel_delta_discrete" @@ t @-> returning int
      let get_x_transformed = foreign "libinput_event_tablet_tool_get_x_transformed" @@ t @-> int_uint32 @-> returning double
      let get_y_transformed = foreign "libinput_event_tablet_tool_get_y_transformed" @@ t @-> int_uint32 @-> returning double
      let get_tool = foreign "libinput_event_tablet_tool_get_tool" @@ t @-> returning (ptr T.Tool.t)
      let get_proximity_state = foreign "libinput_event_tablet_tool_get_proximity_state" @@ t @-> returning T.proximity_state
      let get_tip_state = foreign "libinput_event_tablet_tool_get_tip_state" @@ t @-> returning T.tip_state
      let get_button = foreign "libinput_event_tablet_tool_get_button" @@ t @-> returning int_uint32
      let get_button_state = foreign "libinput_event_tablet_tool_get_button_state" @@ t @-> returning T.button_state
      let get_seat_button_count = foreign "libinput_event_tablet_tool_get_seat_button_count" @@ t @-> returning int_uint32
    end

    module Tablet_pad = struct
      let get_event = foreign "libinput_event_get_tablet_pad_event" @@ t @-> returning (ptr_opt T.Event.Tablet_pad.t)

      let t = ptr T.Event.Tablet_pad.t

      let get_time_usec = foreign "libinput_event_tablet_pad_get_time_usec" @@ t @-> returning time_usec

      let get_ring_position = foreign "libinput_event_tablet_pad_get_ring_position" @@ t @-> returning double
      let get_ring_number = foreign "libinput_event_tablet_pad_get_ring_number" @@ t @-> returning int_uint
      let get_ring_source = foreign "libinput_event_tablet_pad_get_ring_source" @@ t @-> returning T.ring_axis_source
      let get_strip_position = foreign "libinput_event_tablet_pad_get_strip_position" @@ t @-> returning double
      let get_strip_number = foreign "libinput_event_tablet_pad_get_strip_number" @@ t @-> returning int_uint
      let get_strip_source = foreign "libinput_event_tablet_pad_get_strip_source" @@ t @-> returning T.strip_axis_source
      let get_button_number = foreign "libinput_event_tablet_pad_get_button_number" @@ t @-> returning int_uint32
      let get_button_state = foreign "libinput_event_tablet_pad_get_button_state" @@ t @-> returning T.button_state
      let get_key = foreign "libinput_event_tablet_pad_get_key" @@ t @-> returning keycode
      let get_key_state = foreign "libinput_event_tablet_pad_get_key_state" @@ t @-> returning T.key_state
      let get_dial_delta_v120 = foreign_opt ~requires:(1, 26) "libinput_event_tablet_pad_get_dial_delta_v120" @@ t @-> returning double
      let get_dial_number = foreign_opt ~requires:(1, 26) "libinput_event_tablet_pad_get_dial_number" @@ t @-> returning int_uint
      let get_mode = foreign "libinput_event_tablet_pad_get_mode" @@ t @-> returning int_uint
      let get_mode_group = foreign "libinput_event_tablet_pad_get_mode_group" @@ t @-> returning (ptr T.Mode_group.t)
    end

    module Gesture = struct
      let get_event = foreign "libinput_event_get_gesture_event" @@ t @-> returning (ptr_opt T.Event.Gesture.t)

      let t = ptr T.Event.Gesture.t

      let get_time_usec = foreign "libinput_event_gesture_get_time_usec" @@ t @-> returning time_usec
      let get_finger_count = foreign "libinput_event_gesture_get_finger_count" @@ t @-> returning int
      let get_cancelled = foreign "libinput_event_gesture_get_cancelled" @@ t @-> returning bool_int
      let get_dx = foreign "libinput_event_gesture_get_dx" @@ t @-> returning double
      let get_dy = foreign "libinput_event_gesture_get_dy" @@ t @-> returning double
      let get_dx_unaccelerated = foreign "libinput_event_gesture_get_dx_unaccelerated" @@ t @-> returning double
      let get_dy_unaccelerated = foreign "libinput_event_gesture_get_dy_unaccelerated" @@ t @-> returning double
      let get_scale = foreign "libinput_event_gesture_get_scale" @@ t @-> returning double
      let get_angle_delta = foreign "libinput_event_gesture_get_angle_delta" @@ t @-> returning double
    end

    module Switch = struct
      let get_event = foreign "libinput_event_get_switch_event" @@ t @-> returning (ptr_opt T.Event.Switch.t)

      let t = ptr T.Event.Switch.t

      let get_time_usec = foreign "libinput_event_switch_get_time_usec" @@ t @-> returning time_usec
      let get_switch = foreign "libinput_event_switch_get_switch" @@ t @-> returning T.Switch.t
      let get_switch_state = foreign "libinput_event_switch_get_switch_state" @@ t @-> returning T.switch_state
    end
  end

  let get_event = foreign "libinput_get_event" @@
    ptr T.Libinput.t @->
    returning (ptr_opt T.Event.t)

  let get_fd = foreign "libinput_get_fd" @@
    ptr T.Libinput.t @->
    returning T.fd

  let suspend = foreign "libinput_suspend" @@
    ptr T.Libinput.t @->
    returning void

  let resume = foreign "libinput_resume" @@
    ptr T.Libinput.t @->
    returning bool_int

  module Config = struct
    let status_to_str = foreign "libinput_config_status_to_str" @@ T.Config.status @-> returning string
  end
end