Skip to main content

rofi_plugin_sys/
mode.rs

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