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

use {
    crate::{mode_private::Mode, types::RofiIntMatcher},
    ::std::{
        ffi::c_void,
        os::raw::{c_char, c_int, c_uint},
    },
};

/// Mode to exit Rofi.
pub const EXIT: c_int = 1000;

/// Mode to skip to the next cycle-able dialog.
pub const NEXT_DIALOG: c_int = 1001;

/// Mode to reload current dialog.
pub const RELOAD_DIALOG: c_int = 1002;

/// Mode to go to the previous dialog.
pub const PREVIOUS_DIALOG: c_int = 1003;

/// Mode to reload the dialog and unset user input.
pub const RESET_DIALOG: c_int = 1004;

/// States returned by the rofi window.
pub mod menu {
    use ::std::os::raw::c_int;

    /// Entry is selected.
    pub const OK: c_int = 0x00010000;

    /// User canceled the operation. (e.g. pressed escape)
    pub const CANCEL: c_int = 0x00020000;

    /// User requested a mode switch
    pub const NEXT: c_int = 0x00040000;

    /// Custom (non-matched) input was entered.
    pub const CUSTOM_INPUT: c_int = 0x00080000;

    /// User wanted to delete entry from history.
    pub const ENTRY_DELETE: c_int = 0x00100000;

    /// User wants to jump to another switcher.
    pub const QUICK_SWITCH: c_int = 0x00200000;

    /// User wants to jump to custom command.
    pub const CUSTOM_COMMAND: c_int = 0x00800000;

    /// Go to the previous menu.
    pub const PREVIOUS: c_int = 0x00400000;

    /// Go to the complete.
    pub const COMPLETE: c_int = 0x01000000;

    /// Bindings specifics
    pub const CUSTOM_ACTION: c_int = 0x10000000;

    /// Mask
    pub const LOWER_MASK: c_int = 0x0000FFF;
}

extern "C" {
    /// Initialize a mode.
    ///
    /// Returns FALSE if there was a failure, TRUE if successful.
    pub fn mode_init(mode: *mut Mode) -> c_int;

    /// Destroy the mode.
    pub fn mode_destroy(mode: *mut Mode);

    /// Get the number of entries in the mode.
    pub fn mode_get_num_entries(mode: *const Mode) -> c_uint;

    /// Returns the string as it should be displayed for the entry and the state of how it should
    /// be displayed.
    ///
    /// When `get_entry` is `TRUE` a new string is allocated and returned.
    ///
    /// - `selected_line`: The entry to query
    /// - `state`: The state of the entry \[out\]
    /// - `attribute_list`: List of extra (pango) attributes to apply when displaying \[out\] \[null\]
    /// - `get_entry`: If the entry should be returned
    pub fn mode_get_display_value(
        mode: *const Mode,
        selected_line: c_uint,
        state: *mut c_int,
        attribute_list: *mut *mut glib_sys::GList,
        get_entry: c_int,
    ) -> *mut c_char;

    /// Returns the icon for the selected line.
    ///
    /// Returns a newly allocated `cairo_surface_t` if applicable.
    ///
    /// - `selected_line`: The entry to query
    /// - `height`: The desired height of the icon
    pub fn mode_get_icon(
        mode: *mut Mode,
        selected_line: c_uint,
        height: c_int,
    ) -> *mut cairo_sys::cairo_surface_t;

    /// Get a string that can be used for completion. It should have no markup.
    ///
    /// Returns a newly allocated string.
    ///
    /// - `selected_line`: The entry to query
    pub fn mode_get_completion(mode: *const Mode, selected_line: c_uint) -> *const c_char;

    /// Acts on the user interaction.
    ///
    /// Returns the next mode state.
    ///
    /// - `menu_retv`: The menu return value.
    /// - `input`: Pointer to the user input string. \[in\] \[out\]
    /// - `selected_line`: The line selected by the user.
    pub fn mode_result(
        mode: *mut Mode,
        menu_retv: c_int,
        input: *mut *mut c_char,
        selected_line: c_uint,
    ) -> c_int;

    /// Match entry against the set of tokens.
    ///
    /// Returns TRUE if it matches.
    ///
    /// - `tokens`: The set of tokens to match against.
    /// - `selected_line`: The index of the entry to match.
    pub fn mode_token_match(
        mode: *const Mode,
        tokens: *mut *mut RofiIntMatcher,
        selected_line: c_uint,
    ) -> c_int;

    /// Get the name of the mode.
    pub fn mode_get_name(mode: *const Mode) -> *const c_char;

    /// Free the resources allocated for this mode.
    pub fn mode_free(mode: *mut *mut Mode);

    /// A helper function for modes: get the private data object.
    pub fn mode_get_private_data(mode: *const Mode) -> *mut c_void;

    /// A helper function for modes: set the private data object.
    pub fn mode_set_private_data(mode: *mut Mode, pd: *mut c_void);

    /// Get the name of the mode as it should be presented to the user.
    pub fn mode_get_display_name(mode: *const Mode) -> *const c_char;

    /// Adds the display-name configuration option for the mode.
    /// Should be called once for each mode.
    pub fn mode_set_config(mode: *mut Mode);

    /// Process the input so it can be used for matching and sorting.
    /// This includes removing Pango markup.
    ///
    /// Returns a newly allocated string.
    ///
    /// - `input`: The input to process.
    pub fn mode_preprocess_input(mode: *mut Mode, input: *const c_char) -> *const c_char;

    /// Query the mode for a user display.
    ///
    /// Returns a newly allocated (valid Pango markup) message to display,
    /// which the user must free.
    pub fn mode_get_message(mode: *const Mode) -> *const c_char;
}