dummy_rustwlc/
types.rs

1//! Contains struct and enum declarations for
2//! structs defined by wlc.
3
4use std::fmt;
5use std::cmp;
6
7/// Log level to pass into wlc logging
8#[repr(C)]
9#[derive(Debug, Copy, Clone, PartialEq, Eq)]
10pub enum LogType {
11    /// Info log type
12    Info,
13    /// Warn log type
14    Warn,
15    /// Error log type
16    Error,
17    /// Wayland logs
18    Wayland
19}
20
21/// Type of backend that a window is being composited in
22#[repr(C)]
23#[derive(Debug, Copy, Clone, PartialEq, Eq)]
24pub enum BackendType {
25    /// Backend type is unknown
26    None,
27    /// Standard wayland client
28    DRM,
29    /// wayland-x11 client
30    X11
31}
32
33bitflags! {
34    /// Flags describing wayland events
35    #[repr(C)]
36    pub flags EventBit: u32 {
37        /// Event can be read
38        const EVENT_READABLE = 1,
39        /// Event can be written
40        const EVENT_WRITEABLE = 2,
41        /// Event is hung up (?)
42        const EVENT_HANGUP = 4,
43        /// Event is in error
44        const EVENT_ERROR = 8
45    }
46}
47
48bitflags! {
49    /// How window is being viewed
50    #[repr(C)]
51    pub flags ViewState: u32 {
52        /// Window maximized
53        const VIEW_MAXIMIZED = 1,
54        /// Window fullscreen
55        const VIEW_FULLSCREEN = 2,
56        /// Window resizing
57        const VIEW_RESIZING = 4,
58        /// Window moving
59        const VIEW_MOVING = 8,
60        /// Window activated
61        const VIEW_ACTIVATED = 16
62    }
63}
64
65bitflags! {
66    /// Viewtype - like x11 flags
67    #[repr(C)]
68    pub flags ViewType: u32 {
69        /// Override redirect (X11)
70        const VIEW_BIT_OVERRIDE_REDIRECT = 1,
71        /// Tooltips (X11)
72        const VIEW_BIT_UNMANAGED = 2,
73        /// Splash Screens (X11)
74        const VIEW_BIT_SPLASH = 4,
75        /// Modal Windows (X11)
76        const VIEW_BIT_MODAL = 8,
77        /// xdg-shell, wl-shell popups
78        const VIEW_BIT_POPUP = 16
79    }
80}
81
82bitflags! {
83    /// Which edge is being used to resize a window.
84    #[repr(C)]
85    pub flags ResizeEdge: u32 {
86        /// No edge
87        const EDGE_NONE = 0,
88        /// Top edge
89        const RESIZE_TOP = 1,
90        /// Bottom edge
91        const RESIZE_BOTTOM = 2,
92        /// Left edge
93        const RESIZE_LEFT = 4,
94        /// Top left edge
95        const RESIZE_TOPLEFT = 5,
96        /// Bottom left edge
97        const RESIZE_BOTTOMLEFT = 6,
98        /// Right edge
99        const RESIZE_RIGHT = 8,
100        /// Top right edge
101        const RESIZE_TOPRIGHT = 9,
102        /// Bottom right edge
103        const RESIZE_BOTTOMRIGHT = 10
104    }
105}
106
107bitflags! {
108    /// Which view property is being updated
109    #[repr(C)]
110    pub flags ViewPropertyType: u32 {
111        /// View title is being updated
112        const PROPERTY_TITLE = 0,
113        /// View class is being updated
114        const PROPRETY_CLASS = 1,
115        /// View app id is being updated
116        const PROPERTY_APP_ID = 2,
117        /// PID of the view is being updated
118        const PROPERTY_PID = 4
119    }
120}
121
122bitflags! {
123    /// Represents which keyboard meta keys are being pressed.
124    #[repr(C)]
125    pub flags KeyMod: u32 {
126        /// No modifiers
127        const MOD_NONE = 0,
128        /// Shift
129        const MOD_SHIFT = 1,
130        /// Caps lock
131        const MOD_CAPS = 2,
132        /// Control
133        const MOD_CTRL = 4,
134        /// Alt
135        const MOD_ALT = 8,
136        /// Mod2
137        const MOD_MOD2 = 16,
138        /// Mod3
139        const MOD_MOD3 = 32,
140        /// Mod4/logo
141        const MOD_MOD4 = 64,
142        /// 5Mod5Me
143        const MOD_MOD5 = 128
144    }
145}
146
147bitflags! {
148    /// "LEDs" or active key-locks.
149    /// i.e. caps lock, scroll lock
150    #[repr(C)]
151    pub flags KeyboardLed: u32 {
152        /// Num lock is pressed
153        const NUM_LOCK = 1,
154        /// Caps lock is pressed
155        const CAPS_LOCK = 2,
156        /// Original typo of SCROLL_LOCK
157        ///
158        /// # Deprecated
159        /// Please use SCROLL_LOCK instead.
160        const SCROL_LLOCK = 4,
161        /// Scroll lock key is being pressed.
162        const SCROLL_LOCK = 4
163    }
164}
165
166bitflags! {
167    #[repr(C)]
168    pub flags PositionerAnchorBit: u32 {
169        const WLC_BIT_ANCHOR_NONE = 0,
170        const WLC_BIT_ANCHOR_TOP = 1<<0,
171        const WLC_BIT_ANCHOR_BOTTOM = 1<<1,
172        const WLC_BIT_ANCHOR_LEFT = 1<<2,
173        const WLC_BIT_ANCHOR_RIGHT = 1<<3
174    }
175}
176
177bitflags! {
178    #[repr(C)]
179    pub flags PositionerGravityBit: u32 {
180        const WLC_BIT_GRAVITY_NONE = 0,
181        const WLC_BIT_GRAVITY_TOP = 1<<0,
182        const WLC_BIT_GRAVITY_BOTTOM = 1<<1,
183        const WLC_BIT_GRAVITY_LEFT = 1<<2,
184        const WLC_BIT_GRAVITY_RIGHT = 1<<3
185
186    }
187}
188
189bitflags! {
190    #[repr(C)]
191    pub flags PositionerConstraintAdjustmentBits: u32 {
192        const WLC_BIT_CONSTRAINT_ADJUSTMENT_NONE = 0,
193        const WLC_BIT_CONSTRAINT_ADJUSTMENT_SLIDE_X = 1<<0,
194        const WLC_BIT_CONSTRAINT_ADJUSTMENT_SLIDE_Y = 1<<1,
195        const WLC_BIT_CONSTRAINT_ADJUSTMENT_FLIP_X = 1<<2,
196        const WLC_BIT_CONSTRAINT_ADJUSTMENT_FLIP_Y = 1<<3,
197        const WLC_BIT_CONSTRAINT_ADJUSTMENT_RESIZE_X = 1<<4,
198        const WLC_BIT_CONSTRAINT_ADJUSTMENT_RESIZE_Y = 1<<5
199    }
200}
201
202/// Represents a key state in key events
203#[repr(C)]
204#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
205pub enum KeyState {
206    /// Key is being pressed
207    Released = 0,
208    /// Key is being released
209    Pressed = 1
210}
211
212/// Represents a button state in button events
213#[repr(C)]
214#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
215pub enum ButtonState {
216    /// Button is being pressed
217    Released = 0,
218    /// Button is being released
219    Pressed = 1
220}
221
222/// Which axis of the scroll wheel is being used
223#[repr(C)]
224#[derive(Debug, Copy, Clone, PartialEq, Eq)]
225pub enum ScrollAxis {
226    /// No axes
227    None = 0,
228    /// Vertical scroll
229    Vertical = 1,
230    /// Horizontal scroll
231    Horizontal = 2,
232    /// Both scrolls
233    Both = 3
234}
235
236/// Touch type in touch interface handler
237#[repr(C)]
238#[derive(Debug, Copy, Clone, PartialEq, Eq)]
239pub enum TouchType {
240    /// Touch down
241    Down,
242    /// Touch up
243    Up,
244    /// Touch motion
245    Motion,
246    /// Touch frame
247    Frame,
248    /// Touch cancelled
249    Cancel
250}
251
252/// State of keyoard modifiers.
253/// i.e. control key, caps lock on
254#[repr(C)]
255#[derive(Debug, Copy, Clone, PartialEq, Eq)]
256pub struct KeyboardModifiers {
257    /// Which "lock" keys are being pressed
258    pub leds: KeyboardLed,
259    /// Which control/meta keys are being pressed
260    pub mods: KeyMod
261}
262
263/// Represents the location of a view.
264#[repr(C)]
265#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
266pub struct Point {
267    /// x coordinate
268    pub x: i32,
269    /// y coordinate
270    pub y: i32
271}
272
273impl Point {
274    /// The point defined as (0, 0).
275    pub fn origin() -> Point {
276        Point { x: 0, y: 0 }
277    }
278
279    /// Create a new point from the given x and y coordinates.
280    pub fn new(x: i32, y: i32) -> Point {
281        Point { x: x, y: y }
282    }
283
284    /// Creates a new point with an x and y which are the smallest of the two
285    /// points.
286    ///
287    /// # Examples:
288    /// ```rust
289    /// # use rustwlc::Point;
290    /// let a = Point::new(0i32, 12i32);
291    /// let b = Point::new(12i32, 0i32);
292    ///
293    /// assert_eq!(Point::from_min_coords(a, b), Point::new(0, 0));
294    /// ```
295    pub fn from_min_coords(a: Point, b: Point) -> Point {
296        Point::new(cmp::min(a.x, b.x), cmp::min(a.y, b.y))
297    }
298
299    /// Creates a new point with an x and y which are the largest of the two
300    /// points.
301    ///
302    /// # Examples:
303    /// ```rust
304    /// # use rustwlc::Point;
305    /// let a = Point::new(0i32, 12i32);
306    /// let b = Point::new(12i32, 0i32);
307    ///
308    /// assert_eq!(Point::from_max_coords(a, b), Point::new(12i32, 12i32));
309    /// ```
310    pub fn from_max_coords(a: Point, b: Point) -> Point {
311        Point::new(cmp::max(a.x, b.x), cmp::max(a.y, b.y))
312    }
313}
314
315impl fmt::Display for Point {
316    fn fmt(&self, format: &mut fmt::Formatter) -> fmt::Result {
317        write!(format, "({}, {})", self.x, self.y)
318    }
319}
320
321/// Represents the height and width of a view.
322#[repr(C)]
323#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
324pub struct Size {
325    /// Width
326    pub w: u32,
327    /// Height
328    pub h: u32
329}
330
331impl Size {
332    /// A size with zero width and height.
333    pub fn zero() -> Size {
334        Size { w: 0, h: 0 }
335    }
336
337    /// Create a new Size from the given height and width.
338    pub fn new(w: u32, h: u32) -> Size {
339        Size { w: w, h: h }
340    }
341
342    /// Creates a new size with a height and width of the smallest of the two
343    /// sizes.
344    ///
345    /// # Examples:
346    /// ```rust
347    /// # use rustwlc::Size;
348    /// let a = Size::new(0u32, 12u32);
349    /// let b = Size::new(12u32, 0u32);
350    ///
351    /// assert_eq!(Size::from_min_dimensions(a, b), Size::new(0u32, 0u32));
352    /// ```
353    pub fn from_min_dimensions(a: Size, b: Size) -> Size {
354        Size::new(cmp::min(a.h, b.h), cmp::min(a.w, b.w))
355    }
356
357    /// Creates a new size with a height and width of the smallest of the two
358    /// sizes.
359    ///
360    /// # Examples:
361    /// ```rust
362    /// # use rustwlc::Size;
363    /// let a = Size::new(0u32, 12u32);
364    /// let b = Size::new(12u32, 0u32);
365    ///
366    /// assert_eq!(Size::from_max_dimensions(a, b), Size::new(12u32, 12u32));
367    /// ```
368    pub fn from_max_dimensions(a: Size, b: Size) -> Size {
369        Size::new(cmp::max(a.h, b.h), cmp::max(a.w, b.w))
370    }
371}
372
373impl fmt::Display for Size {
374    fn fmt(&self, format: &mut fmt::Formatter) -> fmt::Result {
375        write!(format, "{} x {}", self.w, self.h)
376    }
377}
378
379/// Represents the location and size of a view
380#[repr(C)]
381#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
382pub struct Geometry {
383    /// The location of the object
384    pub origin: Point,
385    /// The size of the object
386    pub size: Size
387}
388
389impl Geometry {
390    /// Creates a geometry with zero size at the origin.
391    pub fn zero() -> Geometry {
392        Geometry { origin: Point::origin(), size: Size::zero() }
393    }
394
395    /// Creates a new geometry with the given size and location.
396    pub fn new(origin: Point, size: Size) -> Geometry {
397        Geometry { origin: origin, size: size }
398    }
399
400    /// Determines if this geometry contains a point.
401    ///
402    /// If the point's coordinates are less than or equal to this geometry's
403    /// dimensions plus its size.
404    pub fn contains_point(self, point: Point) -> bool {
405        point.x <= self.origin.x + self.size.w as i32 &&
406            point.y <= self.origin.y + self.size.h as i32
407    }
408
409    /// Determines if this geometry contains another.
410    ///
411    /// If the other geometry's borders could be fully contained (less than
412    /// or equal to) within self.
413    pub fn contains_geometry(self, other: Geometry) -> bool {
414        self.origin.x <= other.origin.x
415            && self.origin.y <= other.origin.y
416            && self.origin.x + self.size.w as i32
417                >= other.origin.x + other.size.w as i32
418            && self.origin.y + self.size.h as i32
419                >= other.origin.y + other.size.h as i32
420    }
421}
422
423impl fmt::Display for Geometry {
424    fn fmt(&self, format: &mut fmt::Formatter) -> fmt::Result {
425        write!(format, "[{} at {}]", self.size, self.origin)
426    }
427}
428
429/// Not currently supporting libinput
430#[repr(C)]
431pub struct LibinputDevice;