mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-03 04:23:42 -05:00
Refactor menu function into three parts, setup, itterrate and finalize.
This commit is contained in:
parent
94cbe3a005
commit
d0716efe12
6 changed files with 462 additions and 435 deletions
|
@ -121,8 +121,6 @@ Settings config = {
|
|||
.element_height = 1,
|
||||
/** Sidebar mode, show the modi */
|
||||
.sidebar_mode = FALSE,
|
||||
/** Lazy mode setting */
|
||||
.lazy_filter_limit = 15000,
|
||||
/** auto select */
|
||||
.auto_select = FALSE,
|
||||
/** Parse /etc/hosts file in ssh view. */
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* Pointer to xdg cache directory.
|
||||
*/
|
||||
extern const char *cache_dir;
|
||||
typedef struct MenuState MenuState;
|
||||
|
||||
/**
|
||||
* @param msg The error message to show.
|
||||
|
@ -49,12 +50,11 @@ typedef enum
|
|||
*
|
||||
* @returns The command issued (see MenuReturn)
|
||||
*/
|
||||
MenuReturn menu ( Mode *sw,
|
||||
char **input, char *prompt,
|
||||
unsigned int *selected_line,
|
||||
unsigned int *next_pos,
|
||||
MenuState *menu ( Mode *sw,
|
||||
char *input, char *prompt,
|
||||
unsigned int selected_line,
|
||||
const char *message, MenuFlags flags )
|
||||
__attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
|
||||
__attribute__ ( ( nonnull ( 1, 2, 3 ) ) );
|
||||
|
||||
/** Reset terminal */
|
||||
#define color_reset "\033[0m"
|
||||
|
@ -84,5 +84,13 @@ int show_error_message ( const char *msg, int markup );
|
|||
" * The version of rofi you are running\n\n" \
|
||||
" <i>https://github.com/DaveDavenport/rofi/</i>"
|
||||
#define ERROR_MSG_MARKUP TRUE
|
||||
|
||||
MenuReturn menu_state_get_return_value ( const MenuState *state );
|
||||
unsigned int menu_state_get_selected_line ( const MenuState *state );
|
||||
unsigned int menu_state_get_next_position ( const MenuState *state );
|
||||
void menu_state_itterrate ( MenuState *state, XEvent *event );
|
||||
unsigned int menu_state_get_completed ( const MenuState *state );
|
||||
const char * menu_state_get_user_input ( const MenuState *state );
|
||||
void menu_state_free ( MenuState *state );
|
||||
/*@}*/
|
||||
#endif
|
||||
|
|
|
@ -40,15 +40,15 @@ typedef struct
|
|||
|
||||
typedef enum
|
||||
{
|
||||
TB_AUTOHEIGHT = 1 << 0,
|
||||
TB_AUTOWIDTH = 1 << 1,
|
||||
TB_LEFT = 1 << 16,
|
||||
TB_RIGHT = 1 << 17,
|
||||
TB_CENTER = 1 << 18,
|
||||
TB_EDITABLE = 1 << 19,
|
||||
TB_MARKUP = 1 << 20,
|
||||
TB_WRAP = 1 << 21,
|
||||
TB_PASSWORD = 1 << 22,
|
||||
TB_AUTOHEIGHT = 1 << 0,
|
||||
TB_AUTOWIDTH = 1 << 1,
|
||||
TB_LEFT = 1 << 16,
|
||||
TB_RIGHT = 1 << 17,
|
||||
TB_CENTER = 1 << 18,
|
||||
TB_EDITABLE = 1 << 19,
|
||||
TB_MARKUP = 1 << 20,
|
||||
TB_WRAP = 1 << 21,
|
||||
TB_PASSWORD = 1 << 22,
|
||||
} TextboxFlags;
|
||||
|
||||
typedef enum
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
// We limit at 1000000 rows for now.
|
||||
#define DMENU_MAX_ROWS 1000000
|
||||
|
||||
// TODO HACK TO BE REMOVED
|
||||
extern Display *display;
|
||||
|
||||
struct range_pair
|
||||
{
|
||||
unsigned int start;
|
||||
|
@ -397,8 +400,24 @@ int dmenu_switcher_dialog ( void )
|
|||
|
||||
do {
|
||||
retv = FALSE;
|
||||
unsigned int next_pos = pd->selected_line;
|
||||
int mretv = menu ( &dmenu_mode, &input, pd->prompt, &( pd->selected_line ), &next_pos, pd->message, menu_flags );
|
||||
MenuState *state = menu ( &dmenu_mode, input, pd->prompt, ( pd->selected_line ), pd->message, menu_flags );
|
||||
|
||||
// Enter main loop.
|
||||
while ( !menu_state_get_completed ( state ) ) {
|
||||
// Wait for event.
|
||||
XEvent ev;
|
||||
// Get next event. (might block)
|
||||
XNextEvent ( display, &ev );
|
||||
TICK_N ( "X Event" );
|
||||
menu_state_itterrate ( state, &ev );
|
||||
}
|
||||
g_free ( input );
|
||||
input = g_strdup ( menu_state_get_user_input ( state ) );
|
||||
pd->selected_line = menu_state_get_selected_line ( state );;
|
||||
MenuReturn mretv = menu_state_get_return_value ( state );
|
||||
unsigned int next_pos = menu_state_get_next_position ( state );
|
||||
menu_state_free ( state );
|
||||
|
||||
// Special behavior.
|
||||
// TODO clean this up!
|
||||
if ( only_selected ) {
|
||||
|
|
835
source/rofi.c
835
source/rofi.c
File diff suppressed because it is too large
Load diff
|
@ -118,7 +118,6 @@ static XrmOption xrmOptions[] = {
|
|||
{ xrm_Boolean, "levenshtein-sort", { .num = &config.levenshtein_sort }, NULL, "Use levenshtein sorting" },
|
||||
{ xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL, "Set case-sensitivity" },
|
||||
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL, "Enable sidebar-mode" },
|
||||
{ xrm_Number, "lazy-filter-limit", { .num = &config.lazy_filter_limit }, NULL, "Set lazy filter limit" },
|
||||
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL, "Row height (in chars)" },
|
||||
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL, "Enable auto select mode" },
|
||||
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL, "Parse hosts file for ssh mode" },
|
||||
|
|
Loading…
Reference in a new issue