rofi/include/rofi.h

188 lines
5.3 KiB
C
Raw Normal View History

2015-07-27 08:17:12 +00:00
#ifndef ROFI_MAIN_H
#define ROFI_MAIN_H
#include <X11/X.h>
#include <glib.h>
2015-09-26 18:34:34 +00:00
#include <string.h>
#include <stdlib.h>
2016-01-07 12:32:33 +00:00
#include "textbox.h"
2015-09-27 10:57:54 +00:00
#include <cairo.h>
#include <cairo-xlib.h>
#include "timings.h"
#include "keyb.h"
2016-01-07 07:54:24 +00:00
/**
* @defgroup Widgets Widgets
*/
2016-01-07 15:01:56 +00:00
/**
* @defgroup Main Main
* @{
*/
2014-11-25 07:27:08 +00:00
/**
* Pointer to xdg cache directory.
*/
2014-01-25 22:37:37 +00:00
extern const char *cache_dir;
typedef struct _Mode Mode;
2014-06-02 10:54:35 +00:00
/**
* Enum used to sum the possible states of ROFI.
*/
2014-03-22 20:04:19 +00:00
typedef enum
{
2014-06-02 10:54:35 +00:00
/** Exit. */
2014-11-11 20:50:16 +00:00
MODE_EXIT = 1000,
2014-06-02 10:54:35 +00:00
/** Skip to the next cycle-able dialog. */
2014-11-11 20:50:16 +00:00
NEXT_DIALOG = 1001,
/** Reload current DIALOG */
2014-11-11 20:50:16 +00:00
RELOAD_DIALOG = 1002,
/** Previous dialog */
PREVIOUS_DIALOG = 1003
} ModeMode;
2014-06-02 10:54:35 +00:00
/**
* State returned by the rofi window.
*/
2014-03-22 20:04:19 +00:00
typedef enum
{
2014-06-02 10:54:35 +00:00
/** Entry is selected. */
2015-05-10 10:08:08 +00:00
MENU_OK = 0x00010000,
2014-06-02 10:54:35 +00:00
/** User canceled the operation. (e.g. pressed escape) */
2015-05-10 10:08:08 +00:00
MENU_CANCEL = 0x00020000,
2014-06-02 10:54:35 +00:00
/** User requested a mode switch */
2015-05-10 10:08:08 +00:00
MENU_NEXT = 0x00040000,
2014-06-02 10:54:35 +00:00
/** Custom (non-matched) input was entered. */
2015-05-10 10:08:08 +00:00
MENU_CUSTOM_INPUT = 0x00080000,
2014-06-02 10:54:35 +00:00
/** User wanted to delete entry from history. */
MENU_ENTRY_DELETE = 0x00100000,
2014-11-25 07:27:08 +00:00
/** User wants to jump to another switcher. */
MENU_QUICK_SWITCH = 0x00200000,
2014-11-25 07:27:08 +00:00
/** Go to the previous menu. */
MENU_PREVIOUS = 0x00400000,
2015-03-27 19:28:53 +00:00
/** Modifiers */
MENU_SHIFT = 0x10000000,
/** Mask */
MENU_LOWER_MASK = 0x0000FFFF
} MenuReturn;
2014-11-25 07:27:08 +00:00
/**
* @param sig The caught signal
*
* Catch the exit signal generated by X.
*/
2014-03-22 20:04:19 +00:00
void catch_exit ( __attribute__( ( unused ) ) int sig );
2015-11-24 21:02:30 +00:00
/**
* @param sw the Mode to show.
2015-11-24 21:02:30 +00:00
* @param lines An array of strings to display.
* @param num_lines Length of the array with strings to display.
* @param input A pointer to a string where the inputted data is placed.
* @param prompt The prompt to show.
* @param shift pointer to integer that is set to the state of the shift key.
* @param mmc Menu menu match callback, used for matching user input.
* @param mmc_data data to pass to mmc.
* @param selected_line pointer to integer holding the selected line.
* @param message Extra message to display.
*
* Main menu callback.
*
* @returns The command issued (see MenuReturn)
*/
MenuReturn menu ( Mode *sw, char **input, char *prompt, unsigned int *selected_line, unsigned int *next_pos, const char *message )
2015-11-24 21:02:30 +00:00
__attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
2014-02-03 21:49:07 +00:00
2014-11-25 07:27:08 +00:00
/**
* @param msg The error message to show.
2015-06-08 21:22:35 +00:00
* @param markup The error message uses pango markup.
2014-11-25 07:27:08 +00:00
*
* The error message to show.
*/
2015-06-08 21:22:35 +00:00
void error_dialog ( const char *msg, int markup );
2014-11-25 07:27:08 +00:00
typedef void ( *switcher_free )( Mode *data );
2015-11-24 21:02:30 +00:00
typedef char * ( *switcher_get_display_value )( const Mode *sw, unsigned int selected_line, int *state, int get_entry );
2015-11-24 21:02:30 +00:00
typedef char * ( *switcher_get_completion )( const Mode *sw, unsigned int selected_line );
2015-11-24 21:02:30 +00:00
/**
* @param tokens List of (input) tokens to match.
* @param input The entry to match against.
* @param case_sensitive Whether case is significant.
* @param index The current selected index.
* @param data User data.
*
* Function prototype for the matching algorithm.
*
* @returns 1 when it matches, 0 if not.
*/
typedef int ( *switcher_token_match )( const Mode *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index );
2015-11-24 21:02:30 +00:00
typedef void ( *switcher_init )( Mode *sw );
2015-11-24 21:02:30 +00:00
typedef unsigned int ( *switcher_get_num_entries )( const Mode *sw );
2015-11-24 21:02:30 +00:00
typedef void ( *switcher_destroy )( Mode *sw );
2015-11-24 21:02:30 +00:00
typedef ModeMode ( *switcher_result )( Mode *sw, int menu_retv, char **input, unsigned int selected_line );
2015-11-24 21:02:30 +00:00
typedef int ( *switcher_is_not_ascii )( const Mode *sw, unsigned int index );
2015-11-24 21:02:30 +00:00
2015-03-27 19:28:53 +00:00
/**
* Structure defining a switcher.
* It consists of a name, callback and if enabled
* a textbox for the sidebar-mode.
*/
struct _Mode
2015-03-27 19:28:53 +00:00
{
2016-01-07 15:01:56 +00:00
/** Name (max 31 char long) */
2015-03-27 19:28:53 +00:00
char name[32];
2016-01-07 15:01:56 +00:00
/** Keybindings (keysym and modmask) */
2015-03-27 19:28:53 +00:00
char * keycfg;
char * keystr;
KeySym keysym;
unsigned int modmask;
/**
* A switcher normally consists of the following parts:
*/
2016-01-07 15:01:56 +00:00
/** Initialize the Mode */
switcher_init init;
2016-01-07 15:01:56 +00:00
/** Destroy the switcher, e.g. free all its memory. */
switcher_destroy destroy;
2016-01-07 15:01:56 +00:00
/** Get number of entries to display. (unfiltered). */
switcher_get_num_entries get_num_entries;
2016-01-07 15:01:56 +00:00
/** Check if the element is ascii. */
switcher_is_not_ascii is_not_ascii;
2016-01-07 15:01:56 +00:00
/** Process the result of the user selection. */
switcher_result result;
2016-01-07 15:01:56 +00:00
/** Token match. */
switcher_token_match token_match;
2016-01-07 15:01:56 +00:00
/** Get the string to display for the entry. */
2015-11-24 21:02:30 +00:00
switcher_get_display_value mgrv;
2016-01-07 15:01:56 +00:00
/** Get the 'completed' entry. */
switcher_get_completion get_completion;
2016-01-07 15:01:56 +00:00
/** Pointer to private data. */
void *private_data;
2015-03-27 19:28:53 +00:00
2016-01-07 15:01:56 +00:00
/**
* Free SWitcher
* Only to be used when the switcher object itself is dynamic.
* And has data in `ed`
*/
switcher_free free;
2016-01-07 15:01:56 +00:00
/** Extra fields for script */
void *ed;
2015-03-27 19:28:53 +00:00
};
2016-01-07 15:01:56 +00:00
/** Reset terminal */
#define color_reset "\033[0m"
/** Set terminal text bold */
#define color_bold "\033[1m"
/** Set terminal text italic */
#define color_italic "\033[2m"
/** Set terminal foreground text green */
#define color_green "\033[0;32m"
int show_error_message ( const char *msg, int markup );
2016-01-07 15:01:56 +00:00
/*@}*/
#endif