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
|
/*
* rofi
*
* MIT/X11 License
* Copyright © 2013-2023 Qball Cow <qball@gmpclient.org>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef ROFI_MODE_H
#define ROFI_MODE_H
#include "rofi-types.h"
#include <cairo.h>
#include <gmodule.h>
G_BEGIN_DECLS
/** ABI version to check if loaded plugin is compatible. */
#define ABI_VERSION 7u
/**
* @defgroup MODE Mode
*
* The 'object' that makes a mode in rofi.
* @{
*/
/**
* Type of a mode.
* Access should be done via mode_* functions.
*/
typedef struct rofi_mode Mode;
/**
* Enum used to sum the possible states of ROFI.
*/
typedef enum {
/** Exit. */
MODE_EXIT = 1000,
/** Skip to the next cycle-able dialog. */
NEXT_DIALOG = 1001,
/** Reload current DIALOG */
RELOAD_DIALOG = 1002,
/** Previous dialog */
PREVIOUS_DIALOG = 1003,
/** Reloads the dialog and unset user input */
RESET_DIALOG = 1004,
} ModeMode;
/**
* State returned by the rofi window.
*/
typedef enum {
/** Entry is selected. */
MENU_OK = 0x00010000,
/** User canceled the operation. (e.g. pressed escape) */
MENU_CANCEL = 0x00020000,
/** User requested a mode switch */
MENU_NEXT = 0x00040000,
/** Custom (non-matched) input was entered. */
MENU_CUSTOM_INPUT = 0x00080000,
/** User wanted to delete entry from history. */
MENU_ENTRY_DELETE = 0x00100000,
/** User wants to jump to another switcher. */
MENU_QUICK_SWITCH = 0x00200000,
/** User wants to jump to custom command. */
MENU_CUSTOM_COMMAND = 0x00800000,
/** Go to the previous menu. */
MENU_PREVIOUS = 0x00400000,
/** Go to the complete. */
MENU_COMPLETE = 0x01000000,
/** Bindings specifics */
MENU_CUSTOM_ACTION = 0x10000000,
/** Mask */
MENU_LOWER_MASK = 0x0000FFFF
} MenuReturn;
/**
* @param mode The mode to initialize
*
* Initialize mode
*
* @returns FALSE if there was a failure, TRUE if successful
*/
int mode_init(Mode *mode);
/**
* @param mode The mode to destroy
*
* Destroy the mode
*/
void mode_destroy(Mode *mode);
/**
* @param mode The mode to query
*
* Get the number of entries in the mode.
*
* @returns an unsigned int with the number of entries.
*/
unsigned int mode_get_num_entries(const Mode *mode);
/**
* @param mode The mode to query
* @param selected_line The entry to query
* @param state The state of the entry [out]
* @param attribute_list List of extra (pango) attribute to apply when
* displaying. [out][null]
* @param get_entry If the should be returned.
*
* Returns the string as it should be displayed for the entry and the state of
* how it should be displayed.
*
* @returns allocated new string and state when get_entry is TRUE otherwise just
* the state.
*/
char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
int *state, GList **attribute_list, int get_entry);
/**
* @param mode The mode to query
* @param selected_line The entry to query
* @param height The desired height of the icon.
*
* Returns the icon for the selected_line
*
* @returns allocated new cairo_surface_t if applicable
*/
cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line,
unsigned int height);
/**
* @param mode The mode to query
* @param selected_line The entry to query
*
* Return a string that can be used for completion. It has should have no
* markup.
*
* @returns allocated string.
*/
char *mode_get_completion(const Mode *mode, unsigned int selected_line);
/**
* @param mode The mode to query
* @param menu_retv The menu return value.
* @param input Pointer to the user input string. [in][out]
* @param selected_line the line selected by the user.
*
* Acts on the user interaction.
*
* @returns the next #ModeMode.
*/
ModeMode mode_result(Mode *mode, int menu_retv, char **input,
unsigned int selected_line);
/**
* @param mode The mode to query
* @param tokens The set of tokens to match against
* @param selected_line The index of the entry to match
*
* Match entry against the set of tokens.
*
* @returns TRUE if matches
*/
int mode_token_match(const Mode *mode, rofi_int_matcher **tokens,
unsigned int selected_line);
/**
* @param mode The mode to query
*
* Get the name of the mode.
*
* @returns the name of the mode.
*/
const char *mode_get_name(const Mode *mode);
/**
* @param mode The mode to query
*
* Free the resources allocated for this mode.
*/
void mode_free(Mode **mode);
/**
* @param mode The mode to query
*
* Helper functions for mode.
* Get the private data object.
*/
void *mode_get_private_data(const Mode *mode);
/**
* @param mode The mode to query
* @param pd Pointer to private data to attach to the mode.
*
* Helper functions for mode.
* Set the private data object.
*/
void mode_set_private_data(Mode *mode, void *pd);
/**
* @param mode The mode to query
*
* Get the name of the mode as it should be presented to the user.
*
* @return the user visible name of the mode
*/
const char *mode_get_display_name(const Mode *mode);
/**
* @param mode The mode to query
*
* Should be called once for each mode. This adds the display-name configuration
* option for the mode.
*/
void mode_set_config(Mode *mode);
/**
* @param mode The mode to query
* @param input The input to process
*
* This processes the input so it can be used for matching and sorting.
* This includes removing pango markup.
*
* @returns a newly allocated string
*/
char *mode_preprocess_input(Mode *mode, const char *input);
/**
* @param mode The mode to query
*
* Query the mode for a user display.
*
* @return a new allocated (valid pango markup) message to display (user should
* free).
*/
char *mode_get_message(const Mode *mode);
/**
* @param mode The mode to create an instance off.
*
* @returns a new instance of the mode.
*/
Mode *mode_create(const Mode *mode);
/**
* @param sw The mode to query
* @param menu_retv The menu return value.
* @param input Pointer to the user input string. [in][out]
* @param selected_line the line selected by the user.
* @param path get the path to the selected file. [out]
*
* Acts on the user interaction.
*
* @returns the next #ModeMode.
*/
ModeMode mode_completer_result(Mode *sw, int menu_retv, char **input,
unsigned int selected_line, char **path);
/**
* @param sw The mode to query.
*
* Check if mode is a valid completer.
*
* @returns TRUE if mode can be used as completer.
*/
gboolean mode_is_completer(const Mode *sw);
/**
* @param mode The mode to query
*
* @returns the modes ABI version.
*/
int mode_get_abi_version(Mode *const mode);
/**
* @param mode The mode to query
* @param mod The GModule used to load the mode
*
* Set GModule used to load this plugin, this is used to
* unload it on shutdown.
*/
void mode_plugin_set_module(Mode *mode, GModule *mod);
/**
* @param mode The mode to query
*
* @returns the GModule used to load this plugin. NULL if not a plugin.
*/
GModule *mode_plugin_get_module(Mode *mode);
/**@}*/
G_END_DECLS
#endif
|