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
//! Bindings to rofi-types.h

use ::{
    bitflags::bitflags,
    std::{
        ffi::c_void,
        mem,
        os::raw::{c_char, c_double, c_int, c_uint},
    },
};

/// The type of a property.
#[allow(clippy::manual_non_exhaustive)] // count variant is not for that
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum PropertyType {
    Integer,
    Double,
    String,
    Char,
    Boolean,
    Color,
    Image,
    Padding,
    Link,
    Position,
    Highlight,
    List,
    Orientation,
    Cursor,
    Inherit,
    #[doc(hidden)]
    #[non_exhaustive]
    __Count,
}

extern "C" {
    /// This array maps [`PropertyType`] to a user-readable name.
    pub static ProtypeTypeName: [*const c_char; PropertyType::__Count as usize];
}

bitflags! {
    /// Style of text highlight.
    #[repr(transparent)]
    #[derive(Clone, Copy, Debug, PartialEq)]
    pub struct RofiHighlightStyle: c_uint {
        const BOLD = 1;
        const UNDERLINE = 2;
        const STRIKETHROUGH = 16;
        const SMALL_CAPS = 32;
        const ITALIC = 4;
        const COLOR = 8;
    }
}

// Make sure the enum's sizes match
const _: [(); mem::size_of::<RofiHighlightStyle>()] = [(); mem::size_of::<PropertyType>()];

/// Style of line.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum RofiLineStyle {
    /// Solid line
    Solid,
    /// Dashed line
    Dash,
}

/// Distance unit type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum RofiPixelUnit {
    /// PixelWidth in pixels.
    Px,
    /// PixelWidth in millimetres.
    Mm,
    /// PixelWidth in EM.
    Em,
    /// PixelWidth in percentage.
    Percent,
    /// PixelWidth in CH.
    Ch,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum RofiDistanceModifier {
    None,
    Add,
    Subtract,
    Divide,
    Multiply,
    Modulo,
    Group,
    Min,
    Max,
    Round,
    Floor,
    Ceil,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub struct RofiDistanceUnit {
    /// Distance
    pub distance: c_double,
    /// Unit type of the distance
    pub unit_type: RofiPixelUnit,

    /// Type
    pub mod_type: RofiDistanceModifier,

    /// Modifier
    pub left: *mut RofiDistanceUnit,

    /// Modifier
    pub right: *mut RofiDistanceUnit,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub struct RofiDistance {
    /// Base
    pub base: RofiDistanceUnit,
    /// Style of the line (optional)
    pub style: RofiLineStyle,
}

/// Type of orientation.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum RofiOrientation {
    Vertical,
    Horizontal,
}

/// Cursor type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum RofiCursorType {
    Default,
    Pointer,
    Text,
}

impl Default for RofiCursorType {
    fn default() -> Self {
        Self::Default
    }
}

/// Represents the color in a theme.
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub struct ThemeColor {
    /// Red channel
    pub red: f64,
    /// Green channel
    pub green: f64,
    /// Blue channel
    pub blue: f64,
    /// Alpha channel
    pub alpha: f64,
}

/// Theme image
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum RofiImageType {
    Url,
    LinearGradient,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum RofiDirection {
    Left,
    Right,
    Top,
    Bottom,
    Angle,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub enum RofiScaleType {
    None,
    Both,
    Height,
    Width,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub struct RofiImage {
    pub image_type: RofiImageType,
    pub url: *const c_char,
    pub scaling: RofiScaleType,
    pub wsize: c_int,
    pub hsize: c_int,

    pub dir: RofiDirection,
    pub angle: f64,
    /// Colors
    pub colors: *const glib_sys::GList,

    /// Cached image
    pub surface_id: u32,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub struct RofiPadding {
    pub top: RofiDistance,
    pub right: RofiDistance,
    pub bottom: RofiDistance,
    pub left: RofiDistance,
}

/// Theme highlight.
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub struct RofiHighlightColorStyle {
    /// Style to display
    pub style: RofiHighlightStyle,
    pub color: ThemeColor,
}

bitflags! {
    /// Bitflags indicating location or gravity of window.
    ///
    /// ```text
    /// NORTH_WEST      NORTH      NORTH_EAST
    /// EAST            CENTER     EAST
    /// SOUTH_WEST      SOUTH      SOUTH_EAST
    /// ```
    #[repr(transparent)]
    pub struct WindowLocation: c_uint {
        const CENTER = 0;
        /// Top middle
        const NORTH = 1;
        /// Middle right
        const EAST = 2;
        /// Bottom middle
        const SOUTH = 4;
        /// Middle left
        const WEST = 8;
        /// Top left corner.
        const NORTH_WEST = Self::NORTH.bits() | Self::WEST.bits();
        /// Top right corner.
        const NORTH_EAST = Self::NORTH.bits() | Self::EAST.bits();
        /// Bottom right.
        const SOUTH_EAST = Self::SOUTH.bits() | Self::EAST.bits();
        /// Bottom left.
        const SOUTH_WEST = Self::SOUTH.bits() | Self::WEST.bits();
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct PropertyLink {
    /// Name
    pub name: *mut c_char,
    /// Cached looked up ref
    pub property_ref: *mut Property,
    /// Property default
    pub def_value: *mut Property,
}

#[derive(Clone, Copy)]
#[repr(C)]
pub union PropertyValue {
    /// [`PropertyType::Integer`]
    pub i: i32,
    /// [`PropertyType::Double`]
    pub f: f64,
    /// [`PropertyType::String`]
    pub s: *mut c_char,
    /// [`PropertyType::Char`]
    pub c: c_char,
    /// [`PropertyType::Boolean`]
    pub b: glib_sys::gboolean,
    /// [`PropertyType::Color`]
    pub color: ThemeColor,
    /// [`PropertyType::Padding`]
    pub padding: RofiPadding,
    /// Reference - [`PropertyType::Link`]
    pub link: PropertyLink,
    /// Highlight style - [`PropertyType::Highlight`]
    pub highlight: RofiHighlightColorStyle,
    /// [`PropertyType::Image`]
    pub image: RofiImage,
    /// [`PropertyType::List`]
    pub list: *mut glib_sys::GList,
}

/// Property structure.
#[derive(Clone, Copy)]
#[repr(C)]
pub struct Property {
    /// Name of property
    pub name: *const c_char,
    /// Type of property
    pub ty: PropertyType,
    /// Value
    pub value: PropertyValue,
}

/// Structure to hold a range.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct RofiRangePair {
    pub start: c_int,
    pub stop: c_int,
}

/// Internal structure for matching.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct RofiIntMatcher {
    pub regex: *mut glib_sys::GRegex,
    pub invert: glib_sys::gboolean,
}

/// Structure with data to process by each worker thread.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct ThreadState {
    pub callback: Option<unsafe extern "C" fn(t: *mut ThreadState, data: *mut c_void)>,
}

extern "C" {
    pub static mut tpool: *mut glib_sys::GThreadPool;
}