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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
#![allow(non_camel_case_types, non_upper_case_globals, missing_docs)]
use ffi;

use std::cmp::Ordering;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct Point {
    pub x: i32,
    pub y: i32,
}


#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
impl PartialOrd for Point {
    fn partial_cmp(&self, other: &Point) -> Option<Ordering> {
        if self.x < other.x && self.y <= other.y {
            Some(Ordering::Less)
        } else if self.y < other.y && self.x <= other.x {
            Some(Ordering::Less)
        } else if self.x > other.x && self.y >= other.y {
            Some(Ordering::Greater)
        } else if self.y > other.y && self.x >= other.x {
            Some(Ordering::Greater)
        } else if self.x == other.x && self.y == other.y {
            Some(Ordering::Equal)
        } else {
            None
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct Size {
    pub w: u32,
    pub h: u32,
}

#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
impl PartialOrd for Size {
    fn partial_cmp(&self, other: &Size) -> Option<Ordering> {
        if self.w < other.w && self.h <= other.h {
            Some(Ordering::Less)
        } else if self.h < other.h && self.w <= other.w {
            Some(Ordering::Less)
        } else if self.w > other.w && self.h >= other.h {
            Some(Ordering::Greater)
        } else if self.h > other.h && self.w >= other.w {
            Some(Ordering::Greater)
        } else if self.w == other.w && self.h == other.h {
            Some(Ordering::Equal)
        } else {
            None
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct Geometry {
    pub origin: Point,
    pub size: Size,
}

#[cfg_attr(feature = "cargo-clippy", allow(if_same_then_else))]
impl PartialOrd for Geometry {
    fn partial_cmp(&self, other: &Geometry) -> Option<Ordering> {
        if self.origin < other.origin && self.size <= other.size {
            Some(Ordering::Less)
        } else if self.size < other.size && self.origin <= other.origin {
            Some(Ordering::Less)
        } else if self.origin > other.origin && self.size >= other.size {
            Some(Ordering::Greater)
        } else if self.size > other.size && self.origin >= other.origin {
            Some(Ordering::Greater)
        } else if self.origin == other.origin && self.size == other.size {
            Some(Ordering::Equal)
        } else {
            None
        }
    }
}

impl Point {
    #[doc(hidden)]
    pub fn into_ffi(self) -> ffi::wlc_point {
        ffi::wlc_point {
            x: self.x,
            y: self.y,
        }
    }

    #[doc(hidden)]
    pub fn from_ffi(point: &ffi::wlc_point) -> Point {
        Point {
            x: point.x,
            y: point.y,
        }
    }
}

impl Size {
    #[doc(hidden)]
    pub fn into_ffi(self) -> ffi::wlc_size {
        ffi::wlc_size {
            w: self.w,
            h: self.h,
        }
    }

    #[doc(hidden)]
    pub fn from_ffi(size: &ffi::wlc_size) -> Size {
        Size {
            w: size.w,
            h: size.h,
        }
    }
}

impl Geometry {
    #[doc(hidden)]
    pub fn into_ffi(self) -> ffi::wlc_geometry {
        ffi::wlc_geometry {
            origin: self.origin.into_ffi(),
            size: self.size.into_ffi(),
        }
    }

    #[doc(hidden)]
    pub fn from_ffi(geo: &ffi::wlc_geometry) -> Geometry {
        Geometry {
            origin: Point::from_ffi(&geo.origin),
            size: Size::from_ffi(&geo.size),
        }
    }
}

enum_from_primitive! {
    #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
    #[repr(u32)]
    /// Backend used by wlc
    pub enum BackendType
    {
        Null = ffi::wlc_backend_type_WLC_BACKEND_NONE,
        DRM  = ffi::wlc_backend_type_WLC_BACKEND_DRM,
        X11  = ffi::wlc_backend_type_WLC_BACKEND_X11,
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
enum_serde!(BackendType {
    Null,
    DRM,
    X11,
});

/// States a View may hold
#[allow(non_snake_case)]
pub mod ViewState {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple states
        pub flags Flags: u32 {
            /// view is maximized
            const Maximized     = ffi::wlc_view_state_bit_WLC_BIT_MAXIMIZED,
            /// view is shown in fullscreen
            const Fullscreen    = ffi::wlc_view_state_bit_WLC_BIT_FULLSCREEN,
            /// view is resizing
            const Resizing      = ffi::wlc_view_state_bit_WLC_BIT_RESIZING,
            /// view is moving
            const Moving        = ffi::wlc_view_state_bit_WLC_BIT_MOVING,
            /// view is active
            const Activated     = ffi::wlc_view_state_bit_WLC_BIT_ACTIVATED,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(ViewState {
    Maximized,
    Fullscreen,
    Resizing,
    Moving,
    Activated,
});

/// Typical view categories
#[allow(non_snake_case)]
pub mod ViewType {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple types
        pub flags Flags: u32 {
            /// Override redirect (x11)
            const OverrideRedirect  = ffi::wlc_view_type_bit_WLC_BIT_OVERRIDE_REDIRECT,
            /// Tooltips, DnD's, menus (x11)
            const Unmanaged         = ffi::wlc_view_type_bit_WLC_BIT_UNMANAGED,
            /// Splash screens (x11)
            const Splash            = ffi::wlc_view_type_bit_WLC_BIT_SPLASH,
            /// Modal windows (x11)
            const Modal             = ffi::wlc_view_type_bit_WLC_BIT_MODAL,
            /// xdg-shell, wl-shell popups
            const Popup             = ffi::wlc_view_type_bit_WLC_BIT_POPUP,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(ViewType {
    OverrideRedirect,
    Unmanaged,
    Splash,
    Modal,
    Popup,
});

/// Updated properties of a view
#[allow(non_snake_case)]
pub mod ViewPropertyUpdate {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple updated properties
        pub flags Flags: u32 {
            /// Title changed. Receive with `view.title()`
            const Title     = ffi::wlc_view_property_update_bit_WLC_BIT_PROPERTY_TITLE,
            /// Class changed. Receive with `view.class()`
            const Class     = ffi::wlc_view_property_update_bit_WLC_BIT_PROPERTY_CLASS,
            /// AppID changed. Receive with `view.app_id()`
            const AppID     = ffi::wlc_view_property_update_bit_WLC_BIT_PROPERTY_APP_ID,
            /// PID of belonging process changed. Receive with `view.pid()`
            const PID       = ffi::wlc_view_property_update_bit_WLC_BIT_PROPERTY_PID,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(ViewPropertyUpdate {
    Title,
    Class,
    AppID,
    PID,
});

/// Edges for interactive resizing
#[allow(non_snake_case)]
pub mod ResizeEdge {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple edges
        pub flags Flags: u32 {
            const Null         = ffi::wlc_resize_edge_WLC_RESIZE_EDGE_NONE,
            const Top          = ffi::wlc_resize_edge_WLC_RESIZE_EDGE_TOP,
            const Bottom       = ffi::wlc_resize_edge_WLC_RESIZE_EDGE_BOTTOM,
            const Left         = ffi::wlc_resize_edge_WLC_RESIZE_EDGE_LEFT,
            const Right        = ffi::wlc_resize_edge_WLC_RESIZE_EDGE_RIGHT,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(ResizeEdge {
    Null,
    Top,
    Bottom,
    Left,
    Right,
});

/// Set of modifiers on a keyboard
#[allow(non_snake_case)]
pub mod Modifier {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple modifiers
        pub flags Flags: u32 {
            /// Shift Key
            const Shift     = ffi::wlc_modifier_bit_WLC_BIT_MOD_SHIFT,
            /// Caps Key
            const Caps      = ffi::wlc_modifier_bit_WLC_BIT_MOD_CAPS,
            /// Control Key
            const Ctrl      = ffi::wlc_modifier_bit_WLC_BIT_MOD_CTRL,
            /// Alternative Function Key
            const Alt       = ffi::wlc_modifier_bit_WLC_BIT_MOD_ALT,
            /// Second Modifier
            const Mod2      = ffi::wlc_modifier_bit_WLC_BIT_MOD_MOD2,
            /// Third Modifier
            const Mod3      = ffi::wlc_modifier_bit_WLC_BIT_MOD_MOD3,
            /// Logo (Forth) Modifier (Windows/Command Key)
            const Logo      = ffi::wlc_modifier_bit_WLC_BIT_MOD_LOGO,
            /// Fifth Modifier
            const Mod5      = ffi::wlc_modifier_bit_WLC_BIT_MOD_MOD5,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(Modifier {
    Shift,
    Caps,
    Ctrl,
    Alt,
    Mod2,
    Mod3,
    Logo,
    Mod5,
});

/// Keyboard LEDs
#[allow(non_snake_case)]
pub mod Led {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple leds
        pub flags Flags: u32 {
            const Num       = ffi::wlc_led_bit_WLC_BIT_LED_NUM,
            const Caps      = ffi::wlc_led_bit_WLC_BIT_LED_CAPS,
            const Scroll    = ffi::wlc_led_bit_WLC_BIT_LED_SCROLL,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(Led {
    Num,
    Caps,
    Scroll,
});

enum_from_primitive! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    #[repr(u32)]
    /// States of a key
    pub enum KeyState {
        Released = ffi::wlc_key_state_WLC_KEY_STATE_RELEASED,
        Pressed  = ffi::wlc_key_state_WLC_KEY_STATE_PRESSED,
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
enum_serde!(KeyState {
    Released,
    Pressed,
});

enum_from_primitive! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    #[repr(u32)]
    /// States of a button
    pub enum ButtonState {
        Released = ffi::wlc_button_state_WLC_BUTTON_STATE_RELEASED,
        Pressed  = ffi::wlc_button_state_WLC_BUTTON_STATE_PRESSED,
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
enum_serde!(ButtonState {
    Released,
    Pressed,
});

/// Scroll Axes
#[allow(non_snake_case)]
pub mod ScrollAxis {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple axis
        pub flags Flags: u8 {
            /// Vertical Scroll Axis
            const Vertical      = ffi::wlc_scroll_axis_bit_WLC_SCROLL_AXIS_VERTICAL as u8,
            /// Horizontal Scroll Axis
            const Horizontal    = ffi::wlc_scroll_axis_bit_WLC_SCROLL_AXIS_HORIZONTAL as u8,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(ScrollAxis {
    Vertical,
    Horizontal,
});

enum_from_primitive! {
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    #[repr(u32)]
    /// Touch events
    pub enum TouchType {
        Down    = ffi::wlc_touch_type_WLC_TOUCH_DOWN,
        Up      = ffi::wlc_touch_type_WLC_TOUCH_UP,
        Motion  = ffi::wlc_touch_type_WLC_TOUCH_MOTION,
        Frame   = ffi::wlc_touch_type_WLC_TOUCH_FRAME,
        Cancel  = ffi::wlc_touch_type_WLC_TOUCH_CANCEL,
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
enum_serde!(TouchType {
    Down,
    Up,
    Motion,
    Frame,
    Cancel,
});

/// Combined keyboard Modifiers and LEDs
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct Modifiers {
    pub leds: Led::Flags,
    pub mods: Modifier::Flags,
}

impl Modifiers {
    #[doc(hidden)]
    pub fn into_ffi(self) -> ffi::wlc_modifiers {
        ffi::wlc_modifiers {
            leds: self.leds.bits(),
            mods: self.mods.bits(),
        }
    }

    #[doc(hidden)]
    pub fn from_ffi(mods: &ffi::wlc_modifiers) -> Modifiers {
        Modifiers {
            leds: Led::Flags::from_bits_truncate(mods.leds),
            mods: Modifier::Flags::from_bits_truncate(mods.mods),
        }
    }

    pub fn empty() -> Modifiers {
        Modifiers {
            leds: Led::Flags::empty(),
            mods: Modifier::Flags::empty(),
        }
    }
}

/// Visibility Flags
/// Useful to implement workspace functionality or simply hiding views
#[allow(non_snake_case)]
pub mod Visibility {
    bitflags! {
        /// Bitmap that may represent multiple Slots for Visibility
        pub flags Flags: u32 {
            const Null   = 0b00000000000000000000000000000000,
            const Slot1  = 0b00000000000000000000000000000001,
            const Slot2  = 0b00000000000000000000000000000010,
            const Slot3  = 0b00000000000000000000000000000100,
            const Slot4  = 0b00000000000000000000000000001000,
            const Slot5  = 0b00000000000000000000000000010000,
            const Slot6  = 0b00000000000000000000000000100000,
            const Slot7  = 0b00000000000000000000000001000000,
            const Slot8  = 0b00000000000000000000000010000000,
            const Slot9  = 0b00000000000000000000000100000000,
            const Slot10 = 0b00000000000000000000001000000000,
            const Slot11 = 0b00000000000000000000010000000000,
            const Slot12 = 0b00000000000000000000100000000000,
            const Slot13 = 0b00000000000000000001000000000000,
            const Slot14 = 0b00000000000000000010000000000000,
            const Slot15 = 0b00000000000000000100000000000000,
            const Slot16 = 0b00000000000000001000000000000000,
            const Slot17 = 0b00000000000000010000000000000000,
            const Slot18 = 0b00000000000000100000000000000000,
            const Slot19 = 0b00000000000001000000000000000000,
            const Slot20 = 0b00000000000010000000000000000000,
            const Slot21 = 0b00000000000100000000000000000000,
            const Slot22 = 0b00000000001000000000000000000000,
            const Slot23 = 0b00000000010000000000000000000000,
            const Slot24 = 0b00000000100000000000000000000000,
            const Slot25 = 0b00000001000000000000000000000000,
            const Slot26 = 0b00000010000000000000000000000000,
            const Slot27 = 0b00000100000000000000000000000000,
            const Slot28 = 0b00001000000000000000000000000000,
            const Slot29 = 0b00010000000000000000000000000000,
            const Slot30 = 0b00100000000000000000000000000000,
            const Slot31 = 0b01000000000000000000000000000000,
            const Slot32 = 0b10000000000000000000000000000000,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(Visibility {
    Null,
    Slot1,
    Slot2,
    Slot3,
    Slot4,
    Slot5,
    Slot6,
    Slot7,
    Slot8,
    Slot9,
    Slot10,
    Slot11,
    Slot12,
    Slot13,
    Slot14,
    Slot15,
    Slot16,
    Slot17,
    Slot18,
    Slot19,
    Slot20,
    Slot21,
    Slot22,
    Slot23,
    Slot24,
    Slot25,
    Slot26,
    Slot27,
    Slot28,
    Slot29,
    Slot30,
    Slot31,
    Slot32,
});

#[allow(non_snake_case)]
/// View Positioner Anchor
pub mod Anchor {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple Anchors of a `View` by it's `Positioner`
        pub flags Flags: u32 {
            const Null   = ffi::wlc_positioner_anchor_bit_WLC_BIT_ANCHOR_NONE,
            const Top    = ffi::wlc_positioner_anchor_bit_WLC_BIT_ANCHOR_TOP,
            const Bottom = ffi::wlc_positioner_anchor_bit_WLC_BIT_ANCHOR_BOTTOM,
            const Left   = ffi::wlc_positioner_anchor_bit_WLC_BIT_ANCHOR_LEFT,
            const Right  = ffi::wlc_positioner_anchor_bit_WLC_BIT_ANCHOR_RIGHT,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(Anchor {
    Null,
    Top,
    Bottom,
    Left,
    Right,
});

#[allow(non_snake_case)]
/// View Positioner Gravity
pub mod Gravity {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple Gravity Values for a `View` by it's `Positioner`
        pub flags Flags: u32 {
            const Null   = ffi::wlc_positioner_gravity_bit_WLC_BIT_GRAVITY_NONE,
            const Top    = ffi::wlc_positioner_gravity_bit_WLC_BIT_GRAVITY_TOP,
            const Bottom = ffi::wlc_positioner_gravity_bit_WLC_BIT_GRAVITY_BOTTOM,
            const Left   = ffi::wlc_positioner_gravity_bit_WLC_BIT_GRAVITY_LEFT,
            const Right  = ffi::wlc_positioner_gravity_bit_WLC_BIT_GRAVITY_RIGHT,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(Gravity {
    Null,
    Top,
    Bottom,
    Left,
    Right,
});

#[allow(non_snake_case)]
/// View Positioner Adjustments when View is constraint
pub mod ConstraintAdjustment {
    use ffi;
    bitflags! {
        /// Bitmap that may represent multiple Constraints to adjust a `View` by it's `Positioner`
        pub flags Flags: u32 {
            /// Don't alter the surface position even if it is
            /// constrained on some axis, for example partially outside
            /// the edge of a monitor.
            const Null =
                ffi::wlc_positioner_constraint_adjustment_bit_WLC_BIT_CONSTRAINT_ADJUSTMENT_NONE,
            /// Invert the anchor and gravity on the x axis if the
            /// surface is constrained on the x axis. For example, if the
            /// left edge of the surface is constrained, the gravity is
            /// 'left' and the anchor is 'left', change the gravity to
            /// 'right' and the anchor to 'right'.
            ///
	        /// If the adjusted position also ends up being constrained,
            /// the resulting position of the flip_x adjustment will be
            /// the one before the adjustment.
            const FlipX =
                ffi::wlc_positioner_constraint_adjustment_bit_WLC_BIT_CONSTRAINT_ADJUSTMENT_FLIP_X,
            /// Invert the anchor and gravity on the y axis if the
            /// surface is constrained on the y axis. For example, if the
            /// bottom edge of the surface is constrained, the gravity is
            /// 'bottom' and the anchor is 'bottom', change the gravity
            /// to 'top' and the anchor to 'top'.
            ///
	        /// If the adjusted position also ends up being constrained,
            /// the resulting position of the flip_y adjustment will be
            /// the one before the adjustment.
            const FlipY =
                ffi::wlc_positioner_constraint_adjustment_bit_WLC_BIT_CONSTRAINT_ADJUSTMENT_FLIP_Y,
            /// Resize the surface horizontally so that it is completely
            /// unconstrained.
            const ResizeX =
                ffi::wlc_positioner_constraint_adjustment_bit_WLC_BIT_CONSTRAINT_ADJUSTMENT_RESIZE_X,
            /// Resize the surface vertically so that it is completely
            /// unconstrained.
            const ResizeY =
                ffi::wlc_positioner_constraint_adjustment_bit_WLC_BIT_CONSTRAINT_ADJUSTMENT_RESIZE_Y,
            /// Slide the surface along the x axis until it is no longer
            /// constrained.
            ///
	        /// First try to slide towards the direction of the gravity
            /// on the x axis until either the edge in the opposite
            /// direction of the gravity is unconstrained or the edge in
            /// the direction of the gravity is constrained.
            ///
	        /// Then try to slide towards the opposite direction of the
            /// gravity on the x axis until either the edge in the
            /// direction of the gravity is unconstrained or the edge in
            /// the opposite direction of the gravity is constrained.
            const SlideX =
                ffi::wlc_positioner_constraint_adjustment_bit_WLC_BIT_CONSTRAINT_ADJUSTMENT_SLIDE_X,
            /// Slide the surface along the y axis until it is no longer
            /// constrained.
            ///
	        /// First try to slide towards the direction of the gravity
            /// on the y axis until either the edge in the opposite
            /// direction of the gravity is unconstrained or the edge in
            /// the direction of the gravity is constrained.
            ///
	        /// Then try to slide towards the opposite direction of the
            /// gravity on the y axis until either the edge in the
            /// direction of the gravity is unconstrained or the edge in
            /// the opposite direction of the gravity is constrained.
            const SlideY =
                ffi::wlc_positioner_constraint_adjustment_bit_WLC_BIT_CONSTRAINT_ADJUSTMENT_SLIDE_Y,
        }
    }
}

#[cfg_attr(rustfmt, rustfmt_skip)]
bitflags_serde!(ConstraintAdjustment {
    Null,
    FlipX,
    FlipY,
    ResizeX,
    ResizeY,
    SlideX,
    SlideY,
});

#[test]
fn test_ord_point() {
    {
        let p1 = Point { x: 100, y: 200 };
        let p2 = Point { x: 100, y: 300 };
        assert!(p1 < p2);
    }

    {
        let p1 = Point { x: 100, y: 200 };
        let p2 = Point { x: 200, y: 300 };
        assert!(p1 < p2);
    }

    {
        let p1 = Point { x: 100, y: 200 };
        let p2 = Point { x: 200, y: 200 };
        assert!(p1 < p2);
    }

    {
        let p1 = Point { x: 200, y: 300 };
        let p2 = Point { x: 100, y: 300 };
        assert!(p1 > p2);
    }

    {
        let p1 = Point { x: 200, y: 400 };
        let p2 = Point { x: 100, y: 300 };
        assert!(p1 > p2);
    }

    {
        let p1 = Point { x: 200, y: 300 };
        let p2 = Point { x: 200, y: 200 };
        assert!(p1 > p2);
    }

    {
        let p1 = Point { x: 100, y: 300 };
        let p2 = Point { x: 300, y: 100 };
        assert_eq!(p1.partial_cmp(&p2), None);
    }

    {
        let p1 = Point { x: 300, y: 100 };
        let p2 = Point { x: 100, y: 300 };
        assert_eq!(p1.partial_cmp(&p2), None);
    }
}

#[test]
fn test_ord_size() {
    {
        let s1 = Size { w: 100, h: 200 };
        let s2 = Size { w: 100, h: 300 };
        assert!(s1 < s2);
    }

    {
        let s1 = Size { w: 100, h: 200 };
        let s2 = Size { w: 200, h: 300 };
        assert!(s1 < s2);
    }

    {
        let s1 = Size { w: 100, h: 200 };
        let s2 = Size { w: 200, h: 200 };
        assert!(s1 < s2);
    }

    {
        let s1 = Size { w: 200, h: 300 };
        let s2 = Size { w: 100, h: 300 };
        assert!(s1 > s2);
    }

    {
        let s1 = Size { w: 200, h: 400 };
        let s2 = Size { w: 100, h: 300 };
        assert!(s1 > s2);
    }

    {
        let s1 = Size { w: 200, h: 300 };
        let s2 = Size { w: 200, h: 200 };
        assert!(s1 > s2);
    }

    {
        let s1 = Size { w: 100, h: 300 };
        let s2 = Size { w: 300, h: 100 };
        assert_eq!(s1.partial_cmp(&s2), None);
    }

    {
        let s1 = Size { w: 300, h: 100 };
        let s2 = Size { w: 100, h: 300 };
        assert_eq!(s1.partial_cmp(&s2), None);
    }
}

#[test]
fn test_ord_geo() {
    {
        let g1 = Geometry {
            origin: Point { x: 0, y: 200 },
            size: Size { w: 100, h: 200 },
        };
        let g2 = Geometry {
            origin: Point { x: 100, y: 200 },
            size: Size { w: 100, h: 200 },
        };
        assert!(g1 < g2);
    }

    {
        let g1 = Geometry {
            origin: Point { x: 0, y: 200 },
            size: Size { w: 100, h: 200 },
        };
        let g2 = Geometry {
            origin: Point { x: 0, y: 200 },
            size: Size { w: 100, h: 300 },
        };
        assert!(g1 < g2);
    }

    {
        let g1 = Geometry {
            origin: Point { x: 100, y: 200 },
            size: Size { w: 100, h: 200 },
        };
        let g2 = Geometry {
            origin: Point { x: 0, y: 200 },
            size: Size { w: 100, h: 200 },
        };
        assert!(g1 > g2);
    }

    {
        let g1 = Geometry {
            origin: Point { x: 100, y: 200 },
            size: Size { w: 100, h: 300 },
        };
        let g2 = Geometry {
            origin: Point { x: 100, y: 200 },
            size: Size { w: 100, h: 200 },
        };
        assert!(g1 > g2);
    }

    {
        let g1 = Geometry {
            origin: Point { x: 200, y: 200 },
            size: Size { w: 100, h: 300 },
        };
        let g2 = Geometry {
            origin: Point { x: 100, y: 200 },
            size: Size { w: 100, h: 400 },
        };
        assert_eq!(g1.partial_cmp(&g2), None);
    }
}