1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00
rofi/include/mode.h

283 lines
7.3 KiB
C
Raw Normal View History

/*
* rofi
*
* MIT/X11 License
2023-01-14 07:02:35 -05:00
* 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.
*
*/
2016-01-07 13:47:37 -05:00
#ifndef ROFI_MODE_H
#define ROFI_MODE_H
#include "rofi-types.h"
#include <cairo.h>
G_BEGIN_DECLS
2016-01-07 13:47:37 -05:00
/**
* @defgroup MODE Mode
*
* The 'object' that makes a mode in rofi.
* @{
*/
2016-11-15 02:24:06 -05:00
/**
* Type of a mode.
2016-11-15 02:24:27 -05:00
* Access should be done via mode_* functions.
2016-11-15 02:24:06 -05:00
*/
typedef struct rofi_mode Mode;
2016-01-07 13:47:37 -05:00
/**
* 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,
2016-01-07 13:47:37 -05:00
} 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
2016-01-07 13:47:37 -05:00
} MenuReturn;
/**
* @param mode The mode to initialize
*
* Initialize mode
*
* @returns FALSE if there was a failure, TRUE if successful
2016-01-07 13:47:37 -05:00
*/
int mode_init(Mode *mode);
2016-01-07 13:47:37 -05:00
/**
* @param mode The mode to destroy
*
* Destroy the mode
*/
void mode_destroy(Mode *mode);
2016-01-07 13:47:37 -05:00
/**
2017-04-23 09:17:15 -04:00
* @param mode The mode to query
2016-01-07 13:47:37 -05:00
*
* Get the number of entries in the mode.
*
2018-05-14 09:46:34 -04:00
* @returns an unsigned int with the number of entries.
2016-01-07 13:47:37 -05:00
*/
unsigned int mode_get_num_entries(const Mode *mode);
2016-01-07 13:47:37 -05:00
/**
* @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]
2016-01-07 13:47:37 -05:00
* @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.
2016-01-07 13:47:37 -05:00
*
* @returns allocated new string and state when get_entry is TRUE otherwise just
* the state.
2016-01-07 13:47:37 -05:00
*/
char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
int *state, GList **attribute_list, int get_entry);
2016-01-07 15:27:20 -05:00
2017-04-12 11:58:32 -04:00
/**
* @param mode The mode to query
* @param selected_line The entry to query
2017-06-03 10:27:11 -04:00
* @param height The desired height of the icon.
2017-04-12 11:58:32 -04:00
*
* 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,
2022-07-22 18:28:55 -04:00
unsigned int height);
2017-04-12 11:58:32 -04:00
2016-01-07 15:27:20 -05:00
/**
* @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.
2016-01-07 15:27:20 -05:00
*
* @returns allocated string.
*/
char *mode_get_completion(const Mode *mode, unsigned int selected_line);
2016-01-07 15:27:20 -05:00
/**
2016-01-08 03:29:15 -05:00
* @param mode The mode to query
2016-07-29 02:32:34 -04:00
* @param menu_retv The menu return value.
* @param input Pointer to the user input string. [in][out]
2016-01-07 15:27:20 -05:00
* @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);
2016-01-07 15:27:20 -05:00
/**
2016-01-08 03:29:15 -05:00
* @param mode The mode to query
2016-01-07 15:27:20 -05:00
* @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);
2016-01-07 15:27:20 -05:00
/**
2016-01-08 03:29:15 -05:00
* @param mode The mode to query
2016-01-07 15:27:20 -05:00
*
* Get the name of the mode.
*
* @returns the name of the mode.
*/
const char *mode_get_name(const Mode *mode);
2016-01-07 15:27:20 -05:00
/**
2016-01-08 03:29:15 -05:00
* @param mode The mode to query
2016-01-07 15:27:20 -05:00
*
* Free the resources allocated for this mode.
*/
void mode_free(Mode **mode);
2016-01-07 15:27:20 -05:00
2016-01-08 03:29:15 -05:00
/**
* @param mode The mode to query
*
* Helper functions for mode.
* Get the private data object.
*/
void *mode_get_private_data(const Mode *mode);
2016-01-08 03:29:15 -05:00
/**
* @param mode The mode to query
2016-07-29 02:32:34 -04:00
* @param pd Pointer to private data to attach to the mode.
2016-01-08 03:29:15 -05:00
*
* Helper functions for mode.
* Set the private data object.
*/
void mode_set_private_data(Mode *mode, void *pd);
2016-11-15 02:24:06 -05:00
/**
* @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);
2016-11-15 02:24:06 -05:00
/**
* @param mode The mode to query
*
* Should be called once for each mode. This adds the display-name configuration
* option for the mode.
2016-11-15 02:24:06 -05:00
*/
void mode_set_config(Mode *mode);
2016-11-15 02:24:06 -05:00
/**
* @param mode The mode to query
2016-11-15 15:54:31 -05:00
* @param input The input to process
2016-11-15 02:24:06 -05:00
*
* 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);
Merging in the Recursive file browser. Squashed commit of the following: commit 92e730076d461622dc81e44e87ec456317514904 Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 18:17:12 2023 +0200 [Doc] Add regex filtering to recursivebrowser. commit ee80c8487f9765b1e6e8ab8219a6baea089cf5af Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 17:49:29 2023 +0200 [recursivebrowser] Update manpage. commit a24b68f52362aaf1461935c2340e3bf5e31da59d Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 17:37:56 2023 +0200 [Mode] Add some extra validating of the mode selected to complete. commit cf497e8685e806521c0f61922827687adce268c9 Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 4 15:12:31 2023 +0200 [Recursive browser] Make completer selectable. commit 722f07a803c28a406d8a610f31a24b3f7247b9ba Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 4 14:36:14 2023 +0200 Add methods for completer to modes. commit 7972420c30275514751802d1ed517a45bbd83da1 Author: Qball Cow <qball@blame.services> Date: Thu Jun 1 21:56:06 2023 +0200 Prepare updates for new APIs. commit dd3035a1a61f8196d394f6867701a0e1b3af30ac Author: Dave Davenport <qball@gmpclient.org> Date: Wed May 10 19:24:48 2023 +0200 [RB] Fix regex and cleanups commit 4d2941caf32dfb946aee54c467c1319c7a89804a Author: Dave Davenport <qball@blame.services> Date: Wed May 10 18:09:54 2023 +0200 [RB] Add (unfinished regex test) commit 848277001fc8cf9afc538067f2afa24a174f8c7f Author: Dave Davenport <qball@blame.services> Date: Wed May 10 17:49:16 2023 +0200 [RB] Pull the scanning into a separate thread. commit f369a7f63f618bbcad10c18e73f7e2b117c515f1 Author: Dave Davenport <qball@gmpclient.org> Date: Wed May 3 18:35:15 2023 +0200 [Recursive File Browser] First test version.
2023-06-12 13:07:00 -04:00
/**
* @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
Merging in the Recursive file browser. Squashed commit of the following: commit 92e730076d461622dc81e44e87ec456317514904 Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 18:17:12 2023 +0200 [Doc] Add regex filtering to recursivebrowser. commit ee80c8487f9765b1e6e8ab8219a6baea089cf5af Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 17:49:29 2023 +0200 [recursivebrowser] Update manpage. commit a24b68f52362aaf1461935c2340e3bf5e31da59d Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 17:37:56 2023 +0200 [Mode] Add some extra validating of the mode selected to complete. commit cf497e8685e806521c0f61922827687adce268c9 Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 4 15:12:31 2023 +0200 [Recursive browser] Make completer selectable. commit 722f07a803c28a406d8a610f31a24b3f7247b9ba Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 4 14:36:14 2023 +0200 Add methods for completer to modes. commit 7972420c30275514751802d1ed517a45bbd83da1 Author: Qball Cow <qball@blame.services> Date: Thu Jun 1 21:56:06 2023 +0200 Prepare updates for new APIs. commit dd3035a1a61f8196d394f6867701a0e1b3af30ac Author: Dave Davenport <qball@gmpclient.org> Date: Wed May 10 19:24:48 2023 +0200 [RB] Fix regex and cleanups commit 4d2941caf32dfb946aee54c467c1319c7a89804a Author: Dave Davenport <qball@blame.services> Date: Wed May 10 18:09:54 2023 +0200 [RB] Add (unfinished regex test) commit 848277001fc8cf9afc538067f2afa24a174f8c7f Author: Dave Davenport <qball@blame.services> Date: Wed May 10 17:49:16 2023 +0200 [RB] Pull the scanning into a separate thread. commit f369a7f63f618bbcad10c18e73f7e2b117c515f1 Author: Dave Davenport <qball@gmpclient.org> Date: Wed May 3 18:35:15 2023 +0200 [Recursive File Browser] First test version.
2023-06-12 13:07:00 -04:00
* @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.
Merging in the Recursive file browser. Squashed commit of the following: commit 92e730076d461622dc81e44e87ec456317514904 Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 18:17:12 2023 +0200 [Doc] Add regex filtering to recursivebrowser. commit ee80c8487f9765b1e6e8ab8219a6baea089cf5af Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 17:49:29 2023 +0200 [recursivebrowser] Update manpage. commit a24b68f52362aaf1461935c2340e3bf5e31da59d Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 11 17:37:56 2023 +0200 [Mode] Add some extra validating of the mode selected to complete. commit cf497e8685e806521c0f61922827687adce268c9 Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 4 15:12:31 2023 +0200 [Recursive browser] Make completer selectable. commit 722f07a803c28a406d8a610f31a24b3f7247b9ba Author: Dave Davenport <qball@gmpclient.org> Date: Sun Jun 4 14:36:14 2023 +0200 Add methods for completer to modes. commit 7972420c30275514751802d1ed517a45bbd83da1 Author: Qball Cow <qball@blame.services> Date: Thu Jun 1 21:56:06 2023 +0200 Prepare updates for new APIs. commit dd3035a1a61f8196d394f6867701a0e1b3af30ac Author: Dave Davenport <qball@gmpclient.org> Date: Wed May 10 19:24:48 2023 +0200 [RB] Fix regex and cleanups commit 4d2941caf32dfb946aee54c467c1319c7a89804a Author: Dave Davenport <qball@blame.services> Date: Wed May 10 18:09:54 2023 +0200 [RB] Add (unfinished regex test) commit 848277001fc8cf9afc538067f2afa24a174f8c7f Author: Dave Davenport <qball@blame.services> Date: Wed May 10 17:49:16 2023 +0200 [RB] Pull the scanning into a separate thread. commit f369a7f63f618bbcad10c18e73f7e2b117c515f1 Author: Dave Davenport <qball@gmpclient.org> Date: Wed May 3 18:35:15 2023 +0200 [Recursive File Browser] First test version.
2023-06-12 13:07:00 -04:00
*
* Check if mode is a valid completer.
*
* @returns TRUE if mode can be used as completer.
*/
gboolean mode_is_completer(const Mode *sw);
2020-10-12 15:39:36 -04:00
/**@}*/
G_END_DECLS
2016-01-07 13:47:37 -05:00
#endif