rofi_plugin_sys/
types.rs

1//! Bindings to rofi-types.h
2
3use ::{
4    bitflags::bitflags,
5    std::{
6        ffi::c_void,
7        mem,
8        os::raw::{c_char, c_double, c_int, c_uint},
9    },
10};
11
12/// The type of a property.
13#[allow(clippy::manual_non_exhaustive)] // count variant is not for that
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15#[repr(C)]
16pub enum PropertyType {
17    Integer,
18    Double,
19    String,
20    Char,
21    Boolean,
22    Color,
23    Image,
24    Padding,
25    Link,
26    Position,
27    Highlight,
28    List,
29    Orientation,
30    Cursor,
31    Inherit,
32    #[doc(hidden)]
33    #[non_exhaustive]
34    __Count,
35}
36
37extern "C" {
38    /// This array maps [`PropertyType`] to a user-readable name.
39    pub static ProtypeTypeName: [*const c_char; PropertyType::__Count as usize];
40}
41
42bitflags! {
43    /// Style of text highlight.
44    #[repr(transparent)]
45    #[derive(Clone, Copy, Debug, PartialEq)]
46    pub struct RofiHighlightStyle: c_uint {
47        const BOLD = 1;
48        const UNDERLINE = 2;
49        const STRIKETHROUGH = 16;
50        const ITALIC = 4;
51        const COLOR = 8;
52        const UPPERCASE = 32;
53        const LOWERCASE = 64;
54        const CAPITALIZE = 128;
55    }
56}
57
58// Make sure the enum's sizes match
59const _: [(); mem::size_of::<RofiHighlightStyle>()] = [(); mem::size_of::<PropertyType>()];
60
61/// Style of line.
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
63#[repr(C)]
64pub enum RofiLineStyle {
65    /// Solid line
66    Solid,
67    /// Dashed line
68    Dash,
69}
70
71/// Distance unit type.
72#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
73#[repr(C)]
74pub enum RofiPixelUnit {
75    /// PixelWidth in pixels.
76    Px,
77    /// PixelWidth in millimetres.
78    Mm,
79    /// PixelWidth in EM.
80    Em,
81    /// PixelWidth in percentage.
82    Percent,
83    /// PixelWidth in CH.
84    Ch,
85}
86
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
88#[repr(C)]
89pub enum RofiDistanceModifier {
90    None,
91    Add,
92    Subtract,
93    Divide,
94    Multiply,
95    Modulo,
96    Group,
97    Min,
98    Max,
99    Round,
100    Floor,
101    Ceil,
102}
103
104#[derive(Debug, Clone, Copy, PartialEq)]
105#[repr(C)]
106pub struct RofiDistanceUnit {
107    /// Distance
108    pub distance: c_double,
109    /// Unit type of the distance
110    pub unit_type: RofiPixelUnit,
111
112    /// Type
113    pub mod_type: RofiDistanceModifier,
114
115    /// Modifier
116    pub left: *mut RofiDistanceUnit,
117
118    /// Modifier
119    pub right: *mut RofiDistanceUnit,
120}
121
122#[derive(Debug, Clone, Copy, PartialEq)]
123#[repr(C)]
124pub struct RofiDistance {
125    /// Base
126    pub base: RofiDistanceUnit,
127    /// Style of the line (optional)
128    pub style: RofiLineStyle,
129}
130
131/// Type of orientation.
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
133#[repr(C)]
134pub enum RofiOrientation {
135    Vertical,
136    Horizontal,
137}
138
139/// Cursor type.
140#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
141#[repr(C)]
142pub enum RofiCursorType {
143    Default,
144    Pointer,
145    Text,
146}
147
148impl Default for RofiCursorType {
149    fn default() -> Self {
150        Self::Default
151    }
152}
153
154/// Represents the color in a theme.
155#[derive(Debug, Clone, Copy, PartialEq)]
156#[repr(C)]
157pub struct ThemeColor {
158    /// Red channel
159    pub red: f64,
160    /// Green channel
161    pub green: f64,
162    /// Blue channel
163    pub blue: f64,
164    /// Alpha channel
165    pub alpha: f64,
166}
167
168/// Theme image
169#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
170#[repr(C)]
171pub enum RofiImageType {
172    Url,
173    LinearGradient,
174}
175
176#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
177#[repr(C)]
178pub enum RofiDirection {
179    Left,
180    Right,
181    Top,
182    Bottom,
183    Angle,
184}
185
186#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
187#[repr(C)]
188pub enum RofiScaleType {
189    None,
190    Both,
191    Height,
192    Width,
193}
194
195#[derive(Debug, Clone, Copy, PartialEq)]
196#[repr(C)]
197pub struct RofiImage {
198    pub image_type: RofiImageType,
199    pub url: *const c_char,
200    pub scaling: RofiScaleType,
201    pub wsize: c_int,
202    pub hsize: c_int,
203
204    pub dir: RofiDirection,
205    pub angle: f64,
206    /// Colors
207    pub colors: *const glib_sys::GList,
208
209    /// Cached image
210    pub surface_id: u32,
211}
212
213#[derive(Debug, Clone, Copy, PartialEq)]
214#[repr(C)]
215pub struct RofiPadding {
216    pub top: RofiDistance,
217    pub right: RofiDistance,
218    pub bottom: RofiDistance,
219    pub left: RofiDistance,
220}
221
222/// Theme highlight.
223#[derive(Debug, Clone, Copy, PartialEq)]
224#[repr(C)]
225pub struct RofiHighlightColorStyle {
226    /// Style to display
227    pub style: RofiHighlightStyle,
228    pub color: ThemeColor,
229}
230
231bitflags! {
232    /// Bitflags indicating location or gravity of window.
233    ///
234    /// ```text
235    /// NORTH_WEST      NORTH      NORTH_EAST
236    /// EAST            CENTER     EAST
237    /// SOUTH_WEST      SOUTH      SOUTH_EAST
238    /// ```
239    #[repr(transparent)]
240    pub struct WindowLocation: c_uint {
241        const CENTER = 0;
242        /// Top middle
243        const NORTH = 1;
244        /// Middle right
245        const EAST = 2;
246        /// Bottom middle
247        const SOUTH = 4;
248        /// Middle left
249        const WEST = 8;
250        /// Top left corner.
251        const NORTH_WEST = Self::NORTH.bits() | Self::WEST.bits();
252        /// Top right corner.
253        const NORTH_EAST = Self::NORTH.bits() | Self::EAST.bits();
254        /// Bottom right.
255        const SOUTH_EAST = Self::SOUTH.bits() | Self::EAST.bits();
256        /// Bottom left.
257        const SOUTH_WEST = Self::SOUTH.bits() | Self::WEST.bits();
258    }
259}
260
261#[derive(Debug, Clone, Copy, PartialEq, Eq)]
262#[repr(C)]
263pub struct PropertyLink {
264    /// Name
265    pub name: *mut c_char,
266    /// Cached looked up ref
267    pub property_ref: *mut Property,
268    /// Property default
269    pub def_value: *mut Property,
270}
271
272#[derive(Clone, Copy)]
273#[repr(C)]
274pub union PropertyValue {
275    /// [`PropertyType::Integer`]
276    pub i: i32,
277    /// [`PropertyType::Double`]
278    pub f: f64,
279    /// [`PropertyType::String`]
280    pub s: *mut c_char,
281    /// [`PropertyType::Char`]
282    pub c: c_char,
283    /// [`PropertyType::Boolean`]
284    pub b: glib_sys::gboolean,
285    /// [`PropertyType::Color`]
286    pub color: ThemeColor,
287    /// [`PropertyType::Padding`]
288    pub padding: RofiPadding,
289    /// Reference - [`PropertyType::Link`]
290    pub link: PropertyLink,
291    /// Highlight style - [`PropertyType::Highlight`]
292    pub highlight: RofiHighlightColorStyle,
293    /// [`PropertyType::Image`]
294    pub image: RofiImage,
295    /// [`PropertyType::List`]
296    pub list: *mut glib_sys::GList,
297}
298
299/// Property structure.
300#[derive(Clone, Copy)]
301#[repr(C)]
302pub struct Property {
303    /// Name of property
304    pub name: *const c_char,
305    /// Type of property
306    pub ty: PropertyType,
307    /// Value
308    pub value: PropertyValue,
309}
310
311/// Describes the media constraint type.
312#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
313#[repr(C)]
314pub enum ThemeMediaType {
315    /// Minimum width constraint.
316    MinWidth,
317    /// Maximum width constraint.
318    MaxWidth,
319    /// Minimum height constraint.
320    MinHeight,
321    /// Maximum height constraint.
322    MaxHeight,
323    /// Monitor id constraint.
324    MonId,
325    /// Minimum aspect ratio constraint.
326    MinAspectRatio,
327    /// Maximum aspect ratio constraint.
328    MaxAspectRatio,
329    /// Boolean option for use with env.
330    Boolean,
331    /// Invalid entry.
332    Invalid,
333}
334
335/// Theme media description.
336#[derive(Debug, Clone, Copy, PartialEq)]
337#[repr(C)]
338pub struct ThemeMedia {
339    pub r#type: ThemeMediaType,
340    pub value: f64,
341    pub boolv: glib_sys::gboolean,
342}
343
344/// Theme widget.
345#[derive(Debug, Clone, Copy, PartialEq, Eq)]
346#[repr(C)]
347pub struct ThemeWidget {
348    pub set: c_int,
349    pub name: *mut c_char,
350    pub num_widgets: c_uint,
351    pub widgets: *mut *mut ThemeWidget,
352    pub media: *mut ThemeMedia,
353    pub properties: *mut glib_sys::GHashTable,
354    pub parent: *mut ThemeWidget,
355}
356
357pub type ConfigEntry = ThemeWidget;
358
359/// Structure to hold a range.
360#[derive(Debug, Clone, Copy, PartialEq, Eq)]
361#[repr(C)]
362pub struct RofiRangePair {
363    pub start: c_int,
364    pub stop: c_int,
365}
366
367/// Internal structure for matching.
368#[derive(Debug, Clone, Copy, PartialEq, Eq)]
369#[repr(C)]
370pub struct RofiIntMatcher {
371    pub regex: *mut glib_sys::GRegex,
372    pub invert: glib_sys::gboolean,
373}
374
375/// Structure with data to process by each worker thread.
376#[derive(Debug, Clone, Copy, PartialEq, Eq)]
377#[repr(C)]
378pub struct ThreadState {
379    pub callback: Option<unsafe extern "C" fn(t: *mut ThreadState, data: *mut c_void)>,
380    pub free: unsafe extern "C" fn(*mut c_void),
381    pub priority: c_int,
382}
383
384extern "C" {
385    pub static mut tpool: *mut glib_sys::GThreadPool;
386}