Continue cleanup

This commit is contained in:
Dave Davenport 2016-02-07 12:31:17 +01:00
parent 730ee1ad4e
commit 69b3a360fc
4 changed files with 51 additions and 51 deletions

View File

@ -17,7 +17,6 @@
* Pointer to xdg cache directory. * Pointer to xdg cache directory.
*/ */
extern const char *cache_dir; extern const char *cache_dir;
typedef struct RofiViewState RofiViewState;
/** /**
* @param msg The error message to show. * @param msg The error message to show.
@ -27,34 +26,6 @@ typedef struct RofiViewState RofiViewState;
*/ */
void error_dialog ( const char *msg, int markup ); 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 */ /** Reset terminal */
#define color_reset "\033[0m" #define color_reset "\033[0m"
/** Set terminal text bold */ /** Set terminal text bold */

View File

@ -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 * @param state The Menu Handle
* *

View File

@ -63,6 +63,9 @@
#include "xrmoptions.h" #include "xrmoptions.h"
#include "dialogs/dialogs.h" #include "dialogs/dialogs.h"
#include "view.h"
#include "view-internal.h"
gboolean daemon_mode = FALSE; gboolean daemon_mode = FALSE;
// Pidfile. // Pidfile.
char *pidfile = NULL; char *pidfile = NULL;
@ -105,9 +108,6 @@ static int switcher_get ( const char *name )
return -1; return -1;
} }
#include "view.h"
#include "view-internal.h"
/** /**
* @param key the Key to match * @param key the Key to match
* @param modstate the modifier state to match * @param modstate the modifier state to match
@ -180,6 +180,16 @@ static int run_dmenu ()
} }
static int pfd = -1; 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 ) static void run_switcher ( ModeMode mode )
{ {
pfd = setup (); pfd = setup ();
@ -194,13 +204,9 @@ static void run_switcher ( ModeMode mode )
return; return;
} }
} }
char *input = g_strdup ( config.filter ); char *input = g_strdup ( config.filter );
char *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode] ) ); __run_switcher_internal ( mode, input );
curr_switcher = mode; g_free ( input );
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 process_result ( RofiViewState *state ) static void process_result ( RofiViewState *state )
{ {
@ -234,14 +240,10 @@ static void process_result ( RofiViewState *state )
mode = retv; mode = retv;
} }
if ( mode != MODE_EXIT ) { if ( mode != MODE_EXIT ) {
char *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode] ) ); /**
curr_switcher = mode; * Load in the new mode.
RofiViewState * state = rofi_view_create ( modi[mode], input, prompt, NULL, MENU_NORMAL ); */
state->finalize = process_result; __run_switcher_internal ( mode, input );
g_free ( prompt );
// TODO FIX
//g_return_val_if_fail ( state != NULL, MODE_EXIT );
rofi_view_set_active ( state );
g_free ( input ); g_free ( input );
main_loop_x11_event_handler ( NULL ); main_loop_x11_event_handler ( NULL );
return; return;

View File

@ -64,6 +64,9 @@
#include "dialogs/dialogs.h" #include "dialogs/dialogs.h"
#include "rofi.h" #include "rofi.h"
#include "view.h"
#include "view-internal.h"
extern RofiViewState *current_active_menu; extern RofiViewState *current_active_menu;
extern Display *display; extern Display *display;
extern unsigned int num_modi; extern unsigned int num_modi;
@ -89,9 +92,6 @@ typedef enum _MainLoopEvent
ML_TIMEOUT ML_TIMEOUT
} MainLoopEvent; } MainLoopEvent;
#include "view.h"
#include "view-internal.h"
static char * get_matching_state ( void ) static char * get_matching_state ( void )
{ {
if ( config.case_sensitive ) { if ( config.case_sensitive ) {
@ -1375,7 +1375,7 @@ static void menu_mainloop_iter ( RofiViewState *state, XEvent *ev )
} }
} }
RofiViewState *rofi_view_create ( Mode *sw, RofiViewState *rofi_view_create ( Mode *sw,
char *input, const char *input,
char *prompt, char *prompt,
const char *message, const char *message,
MenuFlags menu_flags ) MenuFlags menu_flags )