rofi_plugin_sys/
mode.rs

1//! Bindings to mode.h
2
3use {
4    crate::{mode_private::Mode, types::RofiIntMatcher},
5    ::std::{
6        ffi::c_void,
7        os::raw::{c_char, c_int, c_uint},
8    },
9};
10
11/// Mode to exit Rofi.
12pub const EXIT: c_int = 1000;
13
14/// Mode to skip to the next cycle-able dialog.
15pub const NEXT_DIALOG: c_int = 1001;
16
17/// Mode to reload current dialog.
18pub const RELOAD_DIALOG: c_int = 1002;
19
20/// Mode to go to the previous dialog.
21pub const PREVIOUS_DIALOG: c_int = 1003;
22
23/// Mode to reload the dialog and unset user input.
24pub const RESET_DIALOG: c_int = 1004;
25
26/// States returned by the rofi window.
27pub mod menu {
28    use ::std::os::raw::c_int;
29
30    /// Entry is selected.
31    pub const OK: c_int = 0x00010000;
32
33    /// User canceled the operation. (e.g. pressed escape)
34    pub const CANCEL: c_int = 0x00020000;
35
36    /// User requested a mode switch
37    pub const NEXT: c_int = 0x00040000;
38
39    /// Custom (non-matched) input was entered.
40    pub const CUSTOM_INPUT: c_int = 0x00080000;
41
42    /// User wanted to delete entry from history.
43    pub const ENTRY_DELETE: c_int = 0x00100000;
44
45    /// User wants to jump to another switcher.
46    pub const QUICK_SWITCH: c_int = 0x00200000;
47
48    /// User wants to jump to custom command.
49    pub const CUSTOM_COMMAND: c_int = 0x00800000;
50
51    /// Go to the previous menu.
52    pub const PREVIOUS: c_int = 0x00400000;
53
54    /// Go to the complete.
55    pub const COMPLETE: c_int = 0x01000000;
56
57    /// Bindings specifics
58    pub const CUSTOM_ACTION: c_int = 0x10000000;
59
60    /// Mask
61    pub const LOWER_MASK: c_int = 0x0000FFF;
62}
63
64extern "C" {
65    /// Initialize a mode.
66    ///
67    /// Returns FALSE if there was a failure, TRUE if successful.
68    pub fn mode_init(mode: *mut Mode) -> c_int;
69
70    /// Destroy the mode.
71    pub fn mode_destroy(mode: *mut Mode);
72
73    /// Get the number of entries in the mode.
74    pub fn mode_get_num_entries(mode: *const Mode) -> c_uint;
75
76    /// Returns the string as it should be displayed for the entry and the state of how it should
77    /// be displayed.
78    ///
79    /// When `get_entry` is `TRUE` a new string is allocated and returned.
80    ///
81    /// - `selected_line`: The entry to query
82    /// - `state`: The state of the entry \[out\]
83    /// - `attribute_list`: List of extra (pango) attributes to apply when displaying \[out\] \[null\]
84    /// - `get_entry`: If the entry should be returned
85    pub fn mode_get_display_value(
86        mode: *const Mode,
87        selected_line: c_uint,
88        state: *mut c_int,
89        attribute_list: *mut *mut glib_sys::GList,
90        get_entry: c_int,
91    ) -> *mut c_char;
92
93    /// Returns the icon for the selected line.
94    ///
95    /// Returns a newly allocated `cairo_surface_t` if applicable.
96    ///
97    /// - `selected_line`: The entry to query
98    /// - `height`: The desired height of the icon
99    pub fn mode_get_icon(
100        mode: *mut Mode,
101        selected_line: c_uint,
102        height: c_int,
103    ) -> *mut cairo_sys::cairo_surface_t;
104
105    /// Get a string that can be used for completion. It should have no markup.
106    ///
107    /// Returns a newly allocated string.
108    ///
109    /// - `selected_line`: The entry to query
110    pub fn mode_get_completion(mode: *const Mode, selected_line: c_uint) -> *const c_char;
111
112    /// Acts on the user interaction.
113    ///
114    /// Returns the next mode state.
115    ///
116    /// - `menu_retv`: The menu return value.
117    /// - `input`: Pointer to the user input string. \[in\] \[out\]
118    /// - `selected_line`: The line selected by the user.
119    pub fn mode_result(
120        mode: *mut Mode,
121        menu_retv: c_int,
122        input: *mut *mut c_char,
123        selected_line: c_uint,
124    ) -> c_int;
125
126    /// Match entry against the set of tokens.
127    ///
128    /// Returns TRUE if it matches.
129    ///
130    /// - `tokens`: The set of tokens to match against.
131    /// - `selected_line`: The index of the entry to match.
132    pub fn mode_token_match(
133        mode: *const Mode,
134        tokens: *mut *mut RofiIntMatcher,
135        selected_line: c_uint,
136    ) -> c_int;
137
138    /// Get the name of the mode.
139    pub fn mode_get_name(mode: *const Mode) -> *const c_char;
140
141    /// Free the resources allocated for this mode.
142    pub fn mode_free(mode: *mut *mut Mode);
143
144    /// A helper function for modes: get the private data object.
145    pub fn mode_get_private_data(mode: *const Mode) -> *mut c_void;
146
147    /// A helper function for modes: set the private data object.
148    pub fn mode_set_private_data(mode: *mut Mode, pd: *mut c_void);
149
150    /// Get the name of the mode as it should be presented to the user.
151    pub fn mode_get_display_name(mode: *const Mode) -> *const c_char;
152
153    /// Adds the display-name configuration option for the mode.
154    /// Should be called once for each mode.
155    pub fn mode_set_config(mode: *mut Mode);
156
157    /// Process the input so it can be used for matching and sorting.
158    /// This includes removing Pango markup.
159    ///
160    /// Returns a newly allocated string.
161    ///
162    /// - `input`: The input to process.
163    pub fn mode_preprocess_input(mode: *mut Mode, input: *const c_char) -> *const c_char;
164
165    /// Query the mode for a user display.
166    ///
167    /// Returns a newly allocated (valid Pango markup) message to display,
168    /// which the user must free.
169    pub fn mode_get_message(mode: *const Mode) -> *const c_char;
170
171    /// Returns a new instance of the mode.
172    pub fn mode_create(mode: *const Mode) -> *mut Mode;
173
174    /// Acts on the user interaction. Returns the next mode state.
175    ///
176    /// - `mode`: The mode to query
177    /// - `menu_retv`: The menu return value.
178    /// - `input`: Pointer to the user input string. (in, out)
179    /// - `selected_line`: the line selected by the user.
180    /// - `path`: get the path to the selected file. (out)
181    pub fn mode_completer_result(
182        sw: *mut Mode,
183        menu_retv: c_int,
184        input: *mut *mut c_char,
185        selected_line: c_uint,
186        path: *mut *mut c_char,
187    ) -> c_uint;
188
189    /// Check if a mode is a valid completer.
190    ///
191    /// Returns true if the mode can be used as a completer.
192    pub fn mode_is_completer(sw: *const Mode) -> glib_sys::gboolean;
193}