Skip to content

Commit a5a92a0

Browse files
committed
[WIP] bitwise_enums: Use Bitwise.Enum modules instead of functions
1 parent a0568b0 commit a5a92a0

File tree

10 files changed

+97
-106
lines changed

10 files changed

+97
-106
lines changed

common/utils.ml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,6 @@ let ptr_hash : 'a ptr -> int = fun p ->
1313
to_voidp p |> raw_address_of_ptr |> Hashtbl.hash
1414

1515
let mk_equal compare x y = compare x y = 0
16-
17-
let bitwise_enum desc =
18-
let open Unsigned.UInt64 in
19-
let open Infix in
20-
let read i =
21-
List.filter_map (fun (x, cst) ->
22-
if (i land cst) <> zero then
23-
Some x
24-
else None
25-
) desc
26-
in
27-
let write items =
28-
List.fold_left (fun i item ->
29-
(List.assoc item desc) lor i
30-
) zero items
31-
in
32-
view ~read ~write uint64_t
33-
34-
let bitwise_enum32 desc =
35-
let open Unsigned.UInt32 in
36-
let open Infix in
37-
let read i =
38-
List.filter_map (fun (x, cst) ->
39-
if (i land cst) <> zero then
40-
Some x
41-
else None
42-
) desc
43-
in
44-
let write items =
45-
List.fold_left (fun i item ->
46-
(List.assoc item desc) lor i
47-
) zero items
48-
in
49-
view ~read ~write uint32_t
50-
5116
module Ptr = struct
5217
let compare = ptr_compare
5318
let hash = ptr_hash

lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
event_pointer_motion
2828
event_pointer_motion_absolute
2929
event_pointer_axis
30-
edges
30+
edges_elems
3131
touch
3232
tablet_tool
3333
tablet_pad

lib/edges.ml

Lines changed: 0 additions & 18 deletions
This file was deleted.

lib/edges_elems.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
open Ctypes
2+
module Types = Wlroots_ffi_f.Ffi.Types
3+
4+
type t = None | Top | Bottom | Left | Right
5+
module Size = Unsigned.UInt32
6+
let size = uint32_t
7+
open Types.Edges
8+
let desc = [
9+
None, _WLR_EDGE_NONE;
10+
Top, _WLR_EDGE_TOP;
11+
Bottom, _WLR_EDGE_BOTTOM;
12+
Right, _WLR_EDGE_RIGHT;
13+
Left, _WLR_EDGE_LEFT;
14+
]

lib/keyboard.ml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
open Ctypes
22
open Wlroots_common.Utils
3+
open Wlroots_common
34

45
module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
56
module Types = Wlroots_ffi_f.Ffi.Types
@@ -19,6 +20,35 @@ module Event_key = struct
1920
let state = getfield Types.Event_keyboard_key.state
2021
end
2122

23+
module Modifiers = struct
24+
type t = Types.Keyboard_modifiers.t ptr
25+
let t = ptr Types.Keyboard_modifiers.t
26+
include Ptr
27+
end
28+
29+
module Modifier_elems : Bitwise.Elems = struct
30+
open Types.Keyboard_modifier
31+
type t =
32+
Shift | Caps | Ctrl | Alt | Mod2 | Mod3 | Logo | Mod5
33+
module Size = Unsigned.UInt32
34+
let size = uint32_t
35+
let desc = [
36+
Shift, _WLR_MODIFIER_SHIFT;
37+
Caps, _WLR_MODIFIER_CAPS;
38+
Ctrl, _WLR_MODIFIER_CTRL;
39+
Alt, _WLR_MODIFIER_ALT;
40+
Mod2, _WLR_MODIFIER_MOD2;
41+
Mod3, _WLR_MODIFIER_MOD3;
42+
Logo, _WLR_MODIFIER_LOGO;
43+
Mod5, _WLR_MODIFIER_MOD5;
44+
]
45+
end
46+
47+
module Modifier = struct
48+
include Bitwise.Make(Modifier_elems)
49+
include Poly
50+
end
51+
2252
let xkb_state = getfield Types.Keyboard.xkb_state
2353

2454
let modifiers = getfield Types.Keyboard.modifiers

lib/seat.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ let signal_request_set_cursor (seat: t) : _ Wl.Signal.t = {
6363
typ = Pointer_request_set_cursor_event.t
6464
}
6565

66-
let set_capabilities seat caps =
66+
let set_capabilities =
6767
Bindings.wlr_seat_set_capabilities
68-
seat (coerce Wl.Seat_capability.t uint64_t caps)
6968

7069
let set_keyboard =
7170
Bindings.wlr_seat_set_keyboard

lib/wl.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Ctypes
2+
open Wlroots_common
23
open Wlroots_common.Utils
34

45
module Bindings = Wlroots_ffi_f.Ffi.Make (Generated_ffi)
@@ -115,15 +116,19 @@ module Resource = struct
115116
include Ptr
116117
end
117118

118-
module Seat_capability = struct
119-
type cap = Pointer | Keyboard | Touch
120-
type t = cap list
121-
include Poly
122-
123-
let t : cap list typ =
124-
bitwise_enum Types.Wl_seat_capability.([
119+
module Seat_capability_elems : Bitwise.Elems = struct
120+
type t = Pointer | Keyboard | Touch
121+
module Size = Signed.Int64
122+
let size = int64_t
123+
open Types.Wl_seat_capability
124+
let desc = [
125125
Pointer, _WL_SEAT_CAPABILITY_POINTER;
126126
Keyboard, _WL_SEAT_CAPABILITY_KEYBOARD;
127127
Touch, _WL_SEAT_CAPABILITY_TOUCH;
128-
])
128+
]
129+
end
130+
131+
module Seat_capability = struct
132+
include Bitwise.Make(Seat_capability_elems)
133+
include Poly
129134
end

lib/wlroots.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include Event
2+
open Wlroots_common
23

34
module Output_layout = Output_layout
45
module Seat = Seat
@@ -19,7 +20,11 @@ module Event_pointer_motion = Event_pointer_motion
1920
module Event_pointer_motion_absolute = Event_pointer_motion_absolute
2021
module Event_pointer_button = Event_pointer_button
2122
module Event_pointer_axis = Event_pointer_axis
22-
module Edges = Edges
23+
module Edges_elems = Edges_elems
24+
module Edges = struct
25+
include Bitwise.Make(Edges_elems)
26+
include Utils.Poly
27+
end
2328
module Touch = Touch
2429
module Tablet_tool = Tablet_tool
2530
module Tablet_pad = Tablet_pad

lib/wlroots.mli

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Wlroots_common.Sigs
2+
open Wlroots_common
23

34
module Wl : sig
45
module Event_loop : sig
@@ -37,8 +38,8 @@ module Wl : sig
3738
end
3839

3940
module Seat_capability : sig
40-
type cap = Pointer | Keyboard | Touch
41-
include Comparable0 with type t = cap list
41+
include Bitwise.Enum
42+
include Comparable0 with type t := t
4243
end
4344
end
4445

@@ -164,9 +165,11 @@ module Pointer : sig
164165
type axis_orientation = Vertical | Horizontal
165166
end
166167

168+
module Edges_elems : Bitwise.Elems
169+
167170
module Edges : sig
168-
type edges = None | Top | Bottom | Left | Right
169-
include Comparable0 with type t = edges list
171+
include Bitwise.Enum
172+
include Comparable0 with type t := t
170173
end
171174

172175
module Touch : sig
@@ -331,7 +334,7 @@ and Xdg_shell : sig
331334
val signal_new_surface : t -> Xdg_surface.t Wl.Signal.t
332335
end
333336

334-
module Cursor : sig
337+
and Cursor : sig
335338
include Comparable0
336339

337340
val x : t -> float
@@ -351,15 +354,7 @@ module Cursor : sig
351354
val warp_absolute : t -> Input_device.t -> float -> float -> unit
352355
end
353356

354-
module Xcursor_manager : sig
355-
include Comparable0
356-
357-
val create : string option -> int -> t
358-
val load : t -> float -> int
359-
val set_cursor_image : t -> string -> Cursor.t -> unit
360-
end
361-
362-
module Seat : sig
357+
and Seat : sig
363358
include Comparable0
364359

365360
module Client : sig
@@ -415,6 +410,13 @@ module Seat : sig
415410
val pointer_notify_frame :
416411
t -> unit
417412
end
413+
module Xcursor_manager : sig
414+
include Comparable0
415+
416+
val create : string option -> int -> t
417+
val load : t -> float -> int
418+
val set_cursor_image : t -> string -> Cursor.t -> unit
419+
end
418420

419421
module Log : sig
420422
type importance =

types/types.ml

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ module Make (S : Cstubs_structs.TYPE) = struct
6969
end
7070

7171
module Wl_seat_capability = struct
72-
type t = Unsigned.uint64
73-
let t : t typ = uint64_t
74-
let _WL_SEAT_CAPABILITY_POINTER = constant "WL_SEAT_CAPABILITY_POINTER" uint64_t
75-
let _WL_SEAT_CAPABILITY_KEYBOARD = constant "WL_SEAT_CAPABILITY_KEYBOARD" uint64_t
76-
let _WL_SEAT_CAPABILITY_TOUCH = constant "WL_SEAT_CAPABILITY_TOUCH" uint64_t
72+
type t = Signed.Int64.t
73+
let t : t typ = int64_t
74+
let _WL_SEAT_CAPABILITY_POINTER = constant "WL_SEAT_CAPABILITY_POINTER" t
75+
let _WL_SEAT_CAPABILITY_KEYBOARD = constant "WL_SEAT_CAPABILITY_KEYBOARD" t
76+
let _WL_SEAT_CAPABILITY_TOUCH = constant "WL_SEAT_CAPABILITY_TOUCH" t
7777
end
7878

7979
module Renderer = struct
@@ -191,28 +191,17 @@ module Make (S : Cstubs_structs.TYPE) = struct
191191
end
192192

193193
module Keyboard_modifier = struct
194-
type modifier =
195-
Shift | Caps | Ctrl | Alt | Mod2 | Mod3 | Logo | Mod5
196-
197-
let _WLR_MODIFIER_SHIFT = constant "WLR_MODIFIER_SHIFT" int64_t
198-
let _WLR_MODIFIER_CAPS = constant "WLR_MODIFIER_CAPS" int64_t
199-
let _WLR_MODIFIER_CTRL = constant "WLR_MODIFIER_CTRL" int64_t
200-
let _WLR_MODIFIER_ALT = constant "WLR_MODIFIER_ALT" int64_t
201-
let _WLR_MODIFIER_MOD2 = constant "WLR_MODIFIER_MOD2" int64_t
202-
let _WLR_MODIFIER_MOD3 = constant "WLR_MODIFIER_MOD3" int64_t
203-
let _WLR_MODIFIER_LOGO = constant "WLR_MODIFIER_LOGO" int64_t
204-
let _WLR_MODIFIER_MOD5 = constant "WLR_MODIFIER_MOD5" int64_t
205-
206-
let modifier : modifier typ =
207-
enum "wlr_keyboard_modifier" [
208-
Shift, _WLR_MODIFIER_SHIFT;
209-
Ctrl, _WLR_MODIFIER_CTRL;
210-
Alt, _WLR_MODIFIER_ALT;
211-
Mod2, _WLR_MODIFIER_MOD2;
212-
Mod3, _WLR_MODIFIER_MOD3;
213-
Logo, _WLR_MODIFIER_LOGO;
214-
Mod5, _WLR_MODIFIER_MOD5;
215-
]
194+
type t = Unsigned.uint32
195+
let t : t typ = uint32_t
196+
197+
let _WLR_MODIFIER_SHIFT = constant "WLR_MODIFIER_SHIFT" t
198+
let _WLR_MODIFIER_CAPS = constant "WLR_MODIFIER_CAPS" t
199+
let _WLR_MODIFIER_CTRL = constant "WLR_MODIFIER_CTRL" t
200+
let _WLR_MODIFIER_ALT = constant "WLR_MODIFIER_ALT" t
201+
let _WLR_MODIFIER_MOD2 = constant "WLR_MODIFIER_MOD2" t
202+
let _WLR_MODIFIER_MOD3 = constant "WLR_MODIFIER_MOD3" t
203+
let _WLR_MODIFIER_LOGO = constant "WLR_MODIFIER_LOGO" t
204+
let _WLR_MODIFIER_MOD5 = constant "WLR_MODIFIER_MOD5" t
216205
end
217206

218207
module Keyboard_modifiers = struct

0 commit comments

Comments
 (0)