Source file input_rule.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
open! Ppx_yojson_conv_lib.Yojson_conv
module Send_events = struct
type t =
| Enabled [@name "enabled"]
| Disabled [@name "disabled"]
| Disabled_on_external_mouse [@name "disabled_on_external_mouse"]
[@@deriving yojson]
let to_string = function
| Enabled -> "enabled"
| Disabled -> "disabled"
| Disabled_on_external_mouse -> "disabled-on-external-mouse"
;;
end
module Button_map = struct
type t =
| Lrm [@name "lrm"]
| Lmr [@name "lmr"]
[@@deriving yojson]
let to_string = function
| Lrm -> "left-right-middle"
| Lmr -> "left-middle-right"
;;
end
module Accel_profile = struct
type t =
| None [@name "none"]
| Flat [@name "flat"]
| Adaptive [@name "adaptive"]
| Custom [@name "custom"]
[@@deriving yojson]
let to_string = function
| None -> "none"
| Flat -> "flat"
| Adaptive -> "adaptive"
| Custom -> "custom"
;;
end
module Click_method = struct
type t =
| None [@name "none"]
| Button_areas [@name "button_areas"]
| Clickfinger [@name "clickfinger"]
[@@deriving yojson]
let to_string = function
| None -> "none"
| Button_areas -> "button-areas"
| Clickfinger -> "clickfinger"
;;
end
module Scroll_method = struct
type t =
| No_scroll [@name "no_scroll"]
| Two_finger [@name "two_finger"]
| Edge [@name "edge"]
| On_button_down [@name "on_button_down"]
[@@deriving yojson]
let to_string = function
| No_scroll -> "no-scroll"
| Two_finger -> "two-finger"
| Edge -> "edge"
| On_button_down -> "on-button-down"
;;
end
module Drag_lock = struct
type t =
| Disabled [@name "disabled"]
| Enabled_timeout [@name "enabled_timeout"]
| Enabled_sticky [@name "enabled_sticky"]
[@@deriving yojson]
let to_string = function
| Disabled -> "disabled"
| Enabled_timeout -> "enabled-timeout"
| Enabled_sticky -> "enabled-sticky"
;;
end
module Three_finger_drag = struct
type t =
| Disabled [@name "disabled"]
| Enabled_3fg [@name "enabled_3fg"]
| Enabled_4fg [@name "enabled_4fg"]
[@@deriving yojson]
let to_string = function
| Disabled -> "disabled"
| Enabled_3fg -> "enabled-3fg"
| Enabled_4fg -> "enabled-4fg"
;;
end
module Touchpad = struct
type t =
{ tap : bool option [@yojson.option]
; tap_button_map : Button_map.t option [@yojson.option]
; drag : bool option [@yojson.option]
; drag_lock : Drag_lock.t option [@yojson.option]
; three_finger_drag : Three_finger_drag.t option [@yojson.option]
; dwt : bool option [@yojson.option]
; dwtp : bool option [@yojson.option]
; click_method : Click_method.t option [@yojson.option]
; clickfinger_button_map : Button_map.t option [@yojson.option]
; accel_profile : Accel_profile.t option [@yojson.option]
; accel_speed : float option [@yojson.option]
; natural_scroll : bool option [@yojson.option]
; left_handed : bool option [@yojson.option]
; middle_emulation : bool option [@yojson.option]
; scroll_method : Scroll_method.t option [@yojson.option]
; send_events : Send_events.t option [@yojson.option]
; scroll_factor : float option [@yojson.option]
}
[@@deriving yojson]
let empty = Json_slots.empty t_of_yojson
let merge = Json_slots.merge yojson_of_t t_of_yojson
end
module Mouse = struct
type t =
{ accel_profile : Accel_profile.t option [@yojson.option]
; accel_speed : float option [@yojson.option]
; natural_scroll : bool option [@yojson.option]
; left_handed : bool option [@yojson.option]
; middle_emulation : bool option [@yojson.option]
; scroll_method : Scroll_method.t option [@yojson.option]
; scroll_button : Pointer_button.t option [@yojson.option]
; scroll_button_lock : bool option [@yojson.option]
; send_events : Send_events.t option [@yojson.option]
; scroll_factor : float option [@yojson.option]
}
[@@deriving yojson]
let empty = Json_slots.empty t_of_yojson
let merge = Json_slots.merge yojson_of_t t_of_yojson
end
type 'a rule =
{ pattern : string option [@yojson.option]
; case : Pattern.Case.t
; settings : 'a
}
[@@deriving yojson]
type t =
| Touchpad of Touchpad.t rule [@name "touchpad"]
| Mouse of Mouse.t rule [@name "mouse"]
[@@deriving yojson]
let name_matches rule ~name = Pattern.matches ~case:rule.case ~pattern:rule.pattern name
let equal (a : t) (b : t) =
match a, b with
| Touchpad a', Touchpad b' -> a'.pattern = b'.pattern && a'.case = b'.case
| Mouse a', Mouse b' -> a'.pattern = b'.pattern && a'.case = b'.case
| _ -> false
;;