diff --git a/include/rofi.h b/include/rofi.h index 46b674bb..4f74757d 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -17,7 +17,6 @@ * Pointer to xdg cache directory. */ extern const char *cache_dir; -typedef struct RofiViewState RofiViewState; /** * @param msg The error message to show. @@ -27,34 +26,6 @@ typedef struct RofiViewState RofiViewState; */ void error_dialog ( const char *msg, int markup ); -typedef enum -{ - MENU_NORMAL = 0, - MENU_PASSWORD = 1 -} MenuFlags; - -/** - * @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. - * @param flags Flags indicating state of the menu. - * - * Main menu callback. - * - * @returns The command issued (see MenuReturn) - */ -RofiViewState *rofi_view_create ( Mode *sw, - char *input, char *prompt, - const char *message, MenuFlags flags ) -__attribute__ ( ( nonnull ( 1, 2, 3 ) ) ); - /** Reset terminal */ #define color_reset "\033[0m" /** Set terminal text bold */ diff --git a/include/view.h b/include/view.h index 8e94c77f..e997c8c4 100644 --- a/include/view.h +++ b/include/view.h @@ -8,7 +8,34 @@ * * @{ */ +typedef struct RofiViewState RofiViewState; +typedef enum +{ + MENU_NORMAL = 0, + MENU_PASSWORD = 1 +} MenuFlags; +/** + * @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. + * @param flags Flags indicating state of the menu. + * + * Main menu callback. + * + * @returns The command issued (see MenuReturn) + */ +RofiViewState *rofi_view_create ( Mode *sw, + const char *input, char *prompt, + const char *message, MenuFlags flags ) +__attribute__ ( ( nonnull ( 1, 2, 3 ) ) ); /** * @param state The Menu Handle * diff --git a/source/rofi.c b/source/rofi.c index 45e6db5f..72f5592d 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -63,6 +63,9 @@ #include "xrmoptions.h" #include "dialogs/dialogs.h" +#include "view.h" +#include "view-internal.h" + gboolean daemon_mode = FALSE; // Pidfile. char *pidfile = NULL; @@ -105,9 +108,6 @@ static int switcher_get ( const char *name ) return -1; } -#include "view.h" -#include "view-internal.h" - /** * @param key the Key to match * @param modstate the modifier state to match @@ -180,6 +180,16 @@ static int run_dmenu () } static int pfd = -1; + +static void __run_switcher_internal ( ModeMode mode, char *input ) +{ + char *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode] ) ); + curr_switcher = mode; + RofiViewState * state = rofi_view_create ( modi[mode], input, prompt, NULL, MENU_NORMAL ); + state->finalize = process_result; + rofi_view_set_active ( state ); + g_free ( prompt ); +} static void run_switcher ( ModeMode mode ) { pfd = setup (); @@ -194,13 +204,9 @@ static void run_switcher ( ModeMode mode ) return; } } - char *input = g_strdup ( config.filter ); - char *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode] ) ); - curr_switcher = mode; - RofiViewState * state = rofi_view_create ( modi[mode], input, prompt, NULL, MENU_NORMAL ); - state->finalize = process_result; - rofi_view_set_active ( state ); - g_free ( prompt ); + char *input = g_strdup ( config.filter ); + __run_switcher_internal ( mode, input ); + g_free ( input ); } static void process_result ( RofiViewState *state ) { @@ -234,14 +240,10 @@ static void process_result ( RofiViewState *state ) mode = retv; } if ( mode != MODE_EXIT ) { - char *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode] ) ); - curr_switcher = mode; - RofiViewState * state = rofi_view_create ( modi[mode], input, prompt, NULL, MENU_NORMAL ); - state->finalize = process_result; - g_free ( prompt ); - // TODO FIX - //g_return_val_if_fail ( state != NULL, MODE_EXIT ); - rofi_view_set_active ( state ); + /** + * Load in the new mode. + */ + __run_switcher_internal ( mode, input ); g_free ( input ); main_loop_x11_event_handler ( NULL ); return; diff --git a/source/view.c b/source/view.c index a7a16468..379fb3c0 100644 --- a/source/view.c +++ b/source/view.c @@ -64,6 +64,9 @@ #include "dialogs/dialogs.h" #include "rofi.h" +#include "view.h" +#include "view-internal.h" + extern RofiViewState *current_active_menu; extern Display *display; extern unsigned int num_modi; @@ -89,9 +92,6 @@ typedef enum _MainLoopEvent ML_TIMEOUT } MainLoopEvent; -#include "view.h" -#include "view-internal.h" - static char * get_matching_state ( void ) { if ( config.case_sensitive ) { @@ -1375,7 +1375,7 @@ static void menu_mainloop_iter ( RofiViewState *state, XEvent *ev ) } } RofiViewState *rofi_view_create ( Mode *sw, - char *input, + const char *input, char *prompt, const char *message, MenuFlags menu_flags )