summaryrefslogtreecommitdiff
path: root/lib/Wayland/Protocols/RiverLibinputConfigV1/Header.lean
blob: 3f62b69d6ef4bde29ef46d492a2be66e435cfab5 (plain)
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
import Wayland.Display

namespace Wayland.Protocols

abbrev RiverLibinputConfigV1.name : InterfaceName := "river_libinput_config_v1"
abbrev RiverLibinputDeviceV1.name : InterfaceName := "river_libinput_device_v1"
abbrev RiverLibinputAccelConfigV1.name : InterfaceName := "river_libinput_accel_config_v1"
abbrev RiverLibinputResultV1.name : InterfaceName := "river_libinput_result_v1"

abbrev RiverLibinputConfigV1 : Type := Object RiverLibinputConfigV1.name
abbrev RiverLibinputDeviceV1 : Type := Object RiverLibinputDeviceV1.name
abbrev RiverLibinputAccelConfigV1 : Type := Object RiverLibinputAccelConfigV1.name
abbrev RiverLibinputResultV1 : Type := Object RiverLibinputResultV1.name

inductive RiverLibinputConfigV1.Error where
  | invalidArg
  | invalidDestroy

inductive RiverLibinputDeviceV1.Error where
  | invalidArg

structure RiverLibinputDeviceV1.SendEventsModes where
  enabled : Bool
  disabled : Bool
  disabledOnExternalMouse : Bool

inductive RiverLibinputDeviceV1.TapState where
  | disabled
  | enabled

inductive RiverLibinputDeviceV1.TapButtonMap where
  | lrm
  | lmr

inductive RiverLibinputDeviceV1.DragState where
  | disabled
  | enabled

inductive RiverLibinputDeviceV1.DragLockState where
  | disabled
  | enabledTimeout
  | enabledSticky

inductive RiverLibinputDeviceV1.ThreeFingerDragState where
  | disabled
  | enabled3fg
  | enabled4fg

inductive RiverLibinputDeviceV1.AccelProfile where
  | none
  | flat
  | adaptive
  | custom

structure RiverLibinputDeviceV1.AccelProfiles where
  none : Bool
  flat : Bool
  adaptive : Bool
  custom : Bool

inductive RiverLibinputDeviceV1.NaturalScrollState where
  | disabled
  | enabled

inductive RiverLibinputDeviceV1.LeftHandedState where
  | disabled
  | enabled

inductive RiverLibinputDeviceV1.ClickMethod where
  | none
  | buttonAreas
  | clickfinger

structure RiverLibinputDeviceV1.ClickMethods where
  none : Bool
  buttonAreas : Bool
  clickfinger : Bool

inductive RiverLibinputDeviceV1.ClickfingerButtonMap where
  | lrm
  | lmr

inductive RiverLibinputDeviceV1.MiddleEmulationState where
  | disabled
  | enabled

inductive RiverLibinputDeviceV1.ScrollMethod where
  | noScroll
  | twoFinger
  | edge
  | onButtonDown

structure RiverLibinputDeviceV1.ScrollMethods where
  noScroll : Bool
  twoFinger : Bool
  edge : Bool
  onButtonDown : Bool

inductive RiverLibinputDeviceV1.ScrollButtonLockState where
  | disabled
  | enabled

inductive RiverLibinputDeviceV1.DwtState where
  | disabled
  | enabled

inductive RiverLibinputDeviceV1.DwtpState where
  | disabled
  | enabled

inductive RiverLibinputAccelConfigV1.Error where
  | invalidArg

inductive RiverLibinputAccelConfigV1.AccelType where
  | fallback
  | motion
  | scroll

namespace RiverLibinputConfigV1.Error

instance : Marshallable RiverLibinputConfigV1.Error where
  marshal
    | .int,  .invalidArg => ArgumentMarshaller.marshalInt 0
    | .uint, .invalidArg => ArgumentMarshaller.marshalUInt 0
    | .int,  .invalidDestroy => ArgumentMarshaller.marshalInt 1
    | .uint, .invalidDestroy => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .invalidArg
        | 1 => pure .invalidDestroy
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .invalidArg
        | 1 => pure .invalidDestroy
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputConfigV1.Error

namespace RiverLibinputDeviceV1.Error

instance : Marshallable RiverLibinputDeviceV1.Error where
  marshal
    | .int,  .invalidArg => ArgumentMarshaller.marshalInt 0
    | .uint, .invalidArg => ArgumentMarshaller.marshalUInt 0
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .invalidArg
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .invalidArg
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.Error

namespace RiverLibinputDeviceV1.SendEventsModes

instance : Marshallable RiverLibinputDeviceV1.SendEventsModes where
  marshal
    | .uint, μ => ArgumentMarshaller.marshalUInt <|
        0
        ||| (if μ.enabled then 0 else 0)
        ||| (if μ.disabled then 1 else 0)
        ||| (if μ.disabledOnExternalMouse then 2 else 0)
    | _, _ => throw "Marshalling unexpected type, expected uint."
  demarshal
    | .uint => do
        let μ ← ArgumentDemarshaller.demarshalUInt
        return {
          enabled := (μ &&& 0) == 0
          disabled := (μ &&& 1) == 1
          disabledOnExternalMouse := (μ &&& 2) == 2
        }
    | _ => throw "Demarshalling unexpected type, expected uint."

end RiverLibinputDeviceV1.SendEventsModes

namespace RiverLibinputDeviceV1.TapState

instance : Marshallable RiverLibinputDeviceV1.TapState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.TapState

namespace RiverLibinputDeviceV1.TapButtonMap

instance : Marshallable RiverLibinputDeviceV1.TapButtonMap where
  marshal
    | .int,  .lrm => ArgumentMarshaller.marshalInt 0
    | .uint, .lrm => ArgumentMarshaller.marshalUInt 0
    | .int,  .lmr => ArgumentMarshaller.marshalInt 1
    | .uint, .lmr => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .lrm
        | 1 => pure .lmr
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .lrm
        | 1 => pure .lmr
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.TapButtonMap

namespace RiverLibinputDeviceV1.DragState

instance : Marshallable RiverLibinputDeviceV1.DragState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.DragState

namespace RiverLibinputDeviceV1.DragLockState

instance : Marshallable RiverLibinputDeviceV1.DragLockState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabledTimeout => ArgumentMarshaller.marshalInt 1
    | .uint, .enabledTimeout => ArgumentMarshaller.marshalUInt 1
    | .int,  .enabledSticky => ArgumentMarshaller.marshalInt 2
    | .uint, .enabledSticky => ArgumentMarshaller.marshalUInt 2
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabledTimeout
        | 2 => pure .enabledSticky
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabledTimeout
        | 2 => pure .enabledSticky
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.DragLockState

namespace RiverLibinputDeviceV1.ThreeFingerDragState

instance : Marshallable RiverLibinputDeviceV1.ThreeFingerDragState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled3fg => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled3fg => ArgumentMarshaller.marshalUInt 1
    | .int,  .enabled4fg => ArgumentMarshaller.marshalInt 2
    | .uint, .enabled4fg => ArgumentMarshaller.marshalUInt 2
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled3fg
        | 2 => pure .enabled4fg
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled3fg
        | 2 => pure .enabled4fg
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.ThreeFingerDragState

namespace RiverLibinputDeviceV1.AccelProfile

instance : Marshallable RiverLibinputDeviceV1.AccelProfile where
  marshal
    | .int,  .none => ArgumentMarshaller.marshalInt 0
    | .uint, .none => ArgumentMarshaller.marshalUInt 0
    | .int,  .flat => ArgumentMarshaller.marshalInt 1
    | .uint, .flat => ArgumentMarshaller.marshalUInt 1
    | .int,  .adaptive => ArgumentMarshaller.marshalInt 2
    | .uint, .adaptive => ArgumentMarshaller.marshalUInt 2
    | .int,  .custom => ArgumentMarshaller.marshalInt 4
    | .uint, .custom => ArgumentMarshaller.marshalUInt 4
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .none
        | 1 => pure .flat
        | 2 => pure .adaptive
        | 4 => pure .custom
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .none
        | 1 => pure .flat
        | 2 => pure .adaptive
        | 4 => pure .custom
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.AccelProfile

namespace RiverLibinputDeviceV1.AccelProfiles

instance : Marshallable RiverLibinputDeviceV1.AccelProfiles where
  marshal
    | .uint, μ => ArgumentMarshaller.marshalUInt <|
        0
        ||| (if μ.none then 0 else 0)
        ||| (if μ.flat then 1 else 0)
        ||| (if μ.adaptive then 2 else 0)
        ||| (if μ.custom then 4 else 0)
    | _, _ => throw "Marshalling unexpected type, expected uint."
  demarshal
    | .uint => do
        let μ ← ArgumentDemarshaller.demarshalUInt
        return {
          none := (μ &&& 0) == 0
          flat := (μ &&& 1) == 1
          adaptive := (μ &&& 2) == 2
          custom := (μ &&& 4) == 4
        }
    | _ => throw "Demarshalling unexpected type, expected uint."

end RiverLibinputDeviceV1.AccelProfiles

namespace RiverLibinputDeviceV1.NaturalScrollState

instance : Marshallable RiverLibinputDeviceV1.NaturalScrollState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.NaturalScrollState

namespace RiverLibinputDeviceV1.LeftHandedState

instance : Marshallable RiverLibinputDeviceV1.LeftHandedState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.LeftHandedState

namespace RiverLibinputDeviceV1.ClickMethod

instance : Marshallable RiverLibinputDeviceV1.ClickMethod where
  marshal
    | .int,  .none => ArgumentMarshaller.marshalInt 0
    | .uint, .none => ArgumentMarshaller.marshalUInt 0
    | .int,  .buttonAreas => ArgumentMarshaller.marshalInt 1
    | .uint, .buttonAreas => ArgumentMarshaller.marshalUInt 1
    | .int,  .clickfinger => ArgumentMarshaller.marshalInt 2
    | .uint, .clickfinger => ArgumentMarshaller.marshalUInt 2
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .none
        | 1 => pure .buttonAreas
        | 2 => pure .clickfinger
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .none
        | 1 => pure .buttonAreas
        | 2 => pure .clickfinger
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.ClickMethod

namespace RiverLibinputDeviceV1.ClickMethods

instance : Marshallable RiverLibinputDeviceV1.ClickMethods where
  marshal
    | .uint, μ => ArgumentMarshaller.marshalUInt <|
        0
        ||| (if μ.none then 0 else 0)
        ||| (if μ.buttonAreas then 1 else 0)
        ||| (if μ.clickfinger then 2 else 0)
    | _, _ => throw "Marshalling unexpected type, expected uint."
  demarshal
    | .uint => do
        let μ ← ArgumentDemarshaller.demarshalUInt
        return {
          none := (μ &&& 0) == 0
          buttonAreas := (μ &&& 1) == 1
          clickfinger := (μ &&& 2) == 2
        }
    | _ => throw "Demarshalling unexpected type, expected uint."

end RiverLibinputDeviceV1.ClickMethods

namespace RiverLibinputDeviceV1.ClickfingerButtonMap

instance : Marshallable RiverLibinputDeviceV1.ClickfingerButtonMap where
  marshal
    | .int,  .lrm => ArgumentMarshaller.marshalInt 0
    | .uint, .lrm => ArgumentMarshaller.marshalUInt 0
    | .int,  .lmr => ArgumentMarshaller.marshalInt 1
    | .uint, .lmr => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .lrm
        | 1 => pure .lmr
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .lrm
        | 1 => pure .lmr
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.ClickfingerButtonMap

namespace RiverLibinputDeviceV1.MiddleEmulationState

instance : Marshallable RiverLibinputDeviceV1.MiddleEmulationState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.MiddleEmulationState

namespace RiverLibinputDeviceV1.ScrollMethod

instance : Marshallable RiverLibinputDeviceV1.ScrollMethod where
  marshal
    | .int,  .noScroll => ArgumentMarshaller.marshalInt 0
    | .uint, .noScroll => ArgumentMarshaller.marshalUInt 0
    | .int,  .twoFinger => ArgumentMarshaller.marshalInt 1
    | .uint, .twoFinger => ArgumentMarshaller.marshalUInt 1
    | .int,  .edge => ArgumentMarshaller.marshalInt 2
    | .uint, .edge => ArgumentMarshaller.marshalUInt 2
    | .int,  .onButtonDown => ArgumentMarshaller.marshalInt 4
    | .uint, .onButtonDown => ArgumentMarshaller.marshalUInt 4
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .noScroll
        | 1 => pure .twoFinger
        | 2 => pure .edge
        | 4 => pure .onButtonDown
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .noScroll
        | 1 => pure .twoFinger
        | 2 => pure .edge
        | 4 => pure .onButtonDown
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.ScrollMethod

namespace RiverLibinputDeviceV1.ScrollMethods

instance : Marshallable RiverLibinputDeviceV1.ScrollMethods where
  marshal
    | .uint, μ => ArgumentMarshaller.marshalUInt <|
        0
        ||| (if μ.noScroll then 0 else 0)
        ||| (if μ.twoFinger then 1 else 0)
        ||| (if μ.edge then 2 else 0)
        ||| (if μ.onButtonDown then 4 else 0)
    | _, _ => throw "Marshalling unexpected type, expected uint."
  demarshal
    | .uint => do
        let μ ← ArgumentDemarshaller.demarshalUInt
        return {
          noScroll := (μ &&& 0) == 0
          twoFinger := (μ &&& 1) == 1
          edge := (μ &&& 2) == 2
          onButtonDown := (μ &&& 4) == 4
        }
    | _ => throw "Demarshalling unexpected type, expected uint."

end RiverLibinputDeviceV1.ScrollMethods

namespace RiverLibinputDeviceV1.ScrollButtonLockState

instance : Marshallable RiverLibinputDeviceV1.ScrollButtonLockState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.ScrollButtonLockState

namespace RiverLibinputDeviceV1.DwtState

instance : Marshallable RiverLibinputDeviceV1.DwtState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.DwtState

namespace RiverLibinputDeviceV1.DwtpState

instance : Marshallable RiverLibinputDeviceV1.DwtpState where
  marshal
    | .int,  .disabled => ArgumentMarshaller.marshalInt 0
    | .uint, .disabled => ArgumentMarshaller.marshalUInt 0
    | .int,  .enabled => ArgumentMarshaller.marshalInt 1
    | .uint, .enabled => ArgumentMarshaller.marshalUInt 1
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .disabled
        | 1 => pure .enabled
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputDeviceV1.DwtpState

namespace RiverLibinputAccelConfigV1.Error

instance : Marshallable RiverLibinputAccelConfigV1.Error where
  marshal
    | .int,  .invalidArg => ArgumentMarshaller.marshalInt 0
    | .uint, .invalidArg => ArgumentMarshaller.marshalUInt 0
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .invalidArg
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .invalidArg
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputAccelConfigV1.Error

namespace RiverLibinputAccelConfigV1.AccelType

instance : Marshallable RiverLibinputAccelConfigV1.AccelType where
  marshal
    | .int,  .fallback => ArgumentMarshaller.marshalInt 0
    | .uint, .fallback => ArgumentMarshaller.marshalUInt 0
    | .int,  .motion => ArgumentMarshaller.marshalInt 1
    | .uint, .motion => ArgumentMarshaller.marshalUInt 1
    | .int,  .scroll => ArgumentMarshaller.marshalInt 2
    | .uint, .scroll => ArgumentMarshaller.marshalUInt 2
    | _, _ => throw "Marshalling unexpected type, expected int or uint."
  demarshal
    | .int => do
      match (← ArgumentDemarshaller.demarshalInt) with
        | 0 => pure .fallback
        | 1 => pure .motion
        | 2 => pure .scroll
        | _ => throw "Invalid enum value."
    | .uint => do
      match (← ArgumentDemarshaller.demarshalUInt) with
        | 0 => pure .fallback
        | 1 => pure .motion
        | 2 => pure .scroll
        | _ => throw "Invalid enum value."
    | _ => throw "Demarshalling unexpected type, expected int or uint."

end RiverLibinputAccelConfigV1.AccelType

end Wayland.Protocols