summaryrefslogtreecommitdiffstats
path: root/include/rofi.h
blob: 86c37acc1fd1964e571bc326af511bde1254af5c (plain)
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
#ifndef ROFI_MAIN_H
#define ROFI_MAIN_H
#include <X11/X.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
#include "textbox.h"
#include <cairo.h>
#include <cairo-xlib.h>
#include "timings.h"
#include "keyb.h"

/**
 * @defgroup Widgets Widgets
 */

/**
 * @defgroup Main Main
 * @{
 */
/**
 * Pointer to xdg cache directory.
 */
extern const char *cache_dir;

typedef struct _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
} 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,
    /** Go to the previous menu. */
    MENU_PREVIOUS     = 0x00400000,
    /** Modifiers */
    MENU_SHIFT        = 0x10000000,
    /** Mask */
    MENU_LOWER_MASK   = 0x0000FFFF
} MenuReturn;

/**
 * @param sig  The caught signal
 *
 * Catch the exit signal generated by X.
 */
void catch_exit ( __attribute__( ( unused ) ) int sig );

/**
 * @param sw the Mode to show.
 * @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 )
__attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );

/**
 * @param msg The error message to show.
 * @param markup The error message uses pango markup.
 *
 * The error message to show.
 */
void error_dialog ( const char *msg, int markup  );

typedef void ( *switcher_free )( Mode *data );

typedef char * ( *switcher_get_display_value )( const Mode *sw, unsigned int selected_line, int *state, int get_entry );

typedef char * ( *switcher_get_completion )( const Mode *sw, unsigned int selected_line );
/**
 * @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 );

typedef void ( *switcher_init )( Mode *sw );

typedef unsigned int ( *switcher_get_num_entries )( const Mode *sw );

typedef void ( *switcher_destroy )( Mode *sw );

typedef ModeMode ( *switcher_result )( Mode *sw, int menu_retv, char **input, unsigned int selected_line );

typedef int ( *switcher_is_not_ascii )( const Mode *sw, unsigned int index );

/**
 * Structure defining a switcher.
 * It consists of a name, callback and if enabled
 * a textbox for the sidebar-mode.
 */
struct _Mode
{
    /** Name (max 31 char long) */
    char         name[32];
    /** Keybindings (keysym and modmask) */
    char         * keycfg;
    char         * keystr;
    KeySym       keysym;
    unsigned int modmask;

    /**
     * A switcher normally consists of the following parts:
     */
    /** Initialize the Mode */
    switcher_init              init;
    /** Destroy the switcher, e.g. free all its memory. */
    switcher_destroy           destroy;
    /** Get number of entries to display. (unfiltered). */
    switcher_get_num_entries   get_num_entries;
    /** Check if the element is ascii. */
    switcher_is_not_ascii      is_not_ascii;
    /** Process the result of the user selection. */
    switcher_result            result;
    /** Token match. */
    switcher_token_match       token_match;
    /** Get the string to display for the entry. */
    switcher_get_display_value mgrv;
    /** Get the 'completed' entry. */
    switcher_get_completion    get_completion;

    /** Pointer to private data. */
    void                       *private_data;

    /**
     * Free SWitcher
     * Only to be used when the switcher object itself is dynamic.
     * And has data in `ed`
     */
    switcher_free free;
    /** Extra fields for script */
    void          *ed;
};

/** 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 );
/*@}*/
#endif