From 5a86ae5c99d988511e31d20f08839a47a2141cc5 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 8 Feb 2016 09:03:11 +0100 Subject: Cleanups --- include/rofi.h | 13 ++++++++----- include/view.h | 8 ++++++++ source/dialogs/dmenu.c | 2 +- source/dialogs/drun.c | 2 +- source/dialogs/run.c | 2 +- source/dialogs/ssh.c | 2 +- source/helper.c | 5 +++-- source/i3-support.c | 5 +++-- source/rofi.c | 13 ++----------- source/view.c | 6 +++--- test/helper-test.c | 4 ++-- test/textbox-test.c | 4 ++-- 12 files changed, 35 insertions(+), 31 deletions(-) diff --git a/include/rofi.h b/include/rofi.h index 4f74757d..75713df7 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -8,6 +8,7 @@ #include "timings.h" #include "keyb.h" #include "mode.h" +#include "view.h" /** * @defgroup Main Main @@ -19,12 +20,15 @@ extern const char *cache_dir; /** - * @param msg The error message to show. - * @param markup The error message uses pango markup. + * @param key the Key to match + * @param modstate the modifier state to match + * + * Match key and modifier state against modi. * - * The error message to show. + * @return the index of the switcher that matches the key combination + * specified by key and modstate. Returns -1 if none was found */ -void error_dialog ( const char *msg, int markup ); +int locate_switcher ( KeySym key, unsigned int modstate ); /** Reset terminal */ #define color_reset "\033[0m" @@ -54,6 +58,5 @@ int show_error_message ( const char *msg, int markup ); " * The version of rofi you are running\n\n" \ " https://github.com/DaveDavenport/rofi/" #define ERROR_MSG_MARKUP TRUE -int locate_switcher ( KeySym key, unsigned int modstate ); /*@}*/ #endif diff --git a/include/view.h b/include/view.h index 9c4eb125..329102e5 100644 --- a/include/view.h +++ b/include/view.h @@ -56,5 +56,13 @@ void rofi_view_update ( RofiViewState *state ); void rofi_view_setup_fake_transparency ( Display *display, RofiViewState *state ); void rofi_view_cleanup ( void ); + +/** + * @param msg The error message to show. + * @param markup The error message uses pango markup. + * + * The error message to show. + */ +void rofi_view_error_dialog ( const char *msg, int markup ); /** @} */ #endif diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index cd76ff7b..9eb8455e 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -303,7 +303,7 @@ static int dmenu_mode_init ( Mode *sw ) fd = fopen ( str, "r" ); if ( fd == NULL ) { char *msg = g_markup_printf_escaped ( "Failed to open file: %s:\n\t%s", estr, strerror ( errno ) ); - error_dialog ( msg, TRUE ); + rofi_view_error_dialog ( msg, TRUE ); g_free ( msg ); g_free ( estr ); return TRUE; diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index b136da80..50df40d3 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -61,7 +61,7 @@ static inline int execsh ( const char *cmd, int run_in_term ) g_spawn_async ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error ); if ( error != NULL ) { char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message ); - error_dialog ( msg, FALSE ); + rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. g_error_free ( error ); diff --git a/source/dialogs/run.c b/source/dialogs/run.c index 5f075cd9..a7fb9884 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -89,7 +89,7 @@ static inline int execsh ( const char *cmd, int run_in_term ) g_spawn_async ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error ); if ( error != NULL ) { char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message ); - error_dialog ( msg, FALSE ); + rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. g_error_free ( error ); diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index d503d0e3..94ea4d29 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -77,7 +77,7 @@ static inline int execshssh ( const char *host ) if ( error != NULL ) { char *msg = g_strdup_printf ( "Failed to execute: 'ssh %s'\nError: '%s'", host, error->message ); - error_dialog ( msg, FALSE ); + rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. g_error_free ( error ); diff --git a/source/helper.c b/source/helper.c index 60fe2899..96eb92e2 100644 --- a/source/helper.c +++ b/source/helper.c @@ -43,6 +43,7 @@ #include "settings.h" #include "x11-helper.h" #include "rofi.h" +#include "view.h" static int stored_argc = 0; static char **stored_argv = NULL; @@ -121,7 +122,7 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... ) // Throw error if shell parsing fails. if ( error ) { char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string, error->message ); - error_dialog ( msg, FALSE ); + rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. g_error_free ( error ); @@ -443,7 +444,7 @@ int execute_generator ( const char * cmd ) if ( error != NULL ) { char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message ); - error_dialog ( msg, FALSE ); + rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. g_error_free ( error ); diff --git a/source/i3-support.c b/source/i3-support.c index 278d5f72..84396cfd 100644 --- a/source/i3-support.c +++ b/source/i3-support.c @@ -41,6 +41,7 @@ #include "rofi.h" #include "x11-helper.h" #include "i3-support.h" +#include "view.h" #ifdef HAVE_I3_IPC_H #include @@ -85,7 +86,7 @@ void i3_support_focus_window ( Window id ) t = send ( s, &head, sizeof ( i3_ipc_header_t ), 0 ); if ( t == -1 ) { char *msg = g_strdup_printf ( "Failed to send message header to i3: %s\n", strerror ( errno ) ); - error_dialog ( msg, FALSE ); + rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); close ( s ); return; @@ -94,7 +95,7 @@ void i3_support_focus_window ( Window id ) t = send ( s, command, strlen ( command ), 0 ); if ( t == -1 ) { char *msg = g_strdup_printf ( "Failed to send message body to i3: %s\n", strerror ( errno ) ); - error_dialog ( msg, FALSE ); + rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); close ( s ); return; diff --git a/source/rofi.c b/source/rofi.c index 008bce7e..5b2e966e 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -105,15 +105,6 @@ static int switcher_get ( const char *name ) return -1; } -/** - * @param key the Key to match - * @param modstate the modifier state to match - * - * Match key and modifier state against modi. - * - * @return the index of the switcher that matches the key combination - * specified by key and modstate. Returns -1 if none was found - */ extern unsigned int NumlockMask; int locate_switcher ( KeySym key, unsigned int modstate ) { @@ -196,7 +187,7 @@ static void run_switcher ( ModeMode mode ) // Otherwise check if requested mode is enabled. for ( unsigned int i = 0; i < num_modi; i++ ) { if ( !mode_init ( modi[i] ) ) { - error_dialog ( ERROR_MSG ( "Failed to initialize all the modi." ), ERROR_MSG_MARKUP ); + rofi_view_error_dialog ( ERROR_MSG ( "Failed to initialize all the modi." ), ERROR_MSG_MARKUP ); teardown ( pfd ); return; } @@ -263,7 +254,7 @@ int show_error_message ( const char *msg, int markup ) if ( pfd < 0 ) { return EXIT_FAILURE; } - error_dialog ( msg, markup ); + rofi_view_error_dialog ( msg, markup ); teardown ( pfd ); // TODO this looks incorrect. g_main_loop_quit ( main_loop ); diff --git a/source/view.c b/source/view.c index fc5efb64..c72daa4a 100644 --- a/source/view.c +++ b/source/view.c @@ -1592,7 +1592,7 @@ RofiViewState *rofi_view_create ( Mode *sw, } return state; } -static void error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) +static void __error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) { // Wait for event. if ( sndisplay != NULL ) { @@ -1614,13 +1614,13 @@ static void error_dialog_event_loop ( RofiViewState *state, XEvent *ev ) } rofi_view_update ( state ); } -void error_dialog ( const char *msg, int markup ) +void rofi_view_error_dialog ( const char *msg, int markup ) { RofiViewState *state = rofi_view_state_create (); state->retv = MENU_CANCEL; state->update = TRUE; state->border = config.padding + config.menu_bw; - state->x11_event_loop = error_dialog_event_loop; + state->x11_event_loop = __error_dialog_event_loop; state->finalize = NULL; // Try to grab the keyboard as early as possible. diff --git a/test/helper-test.c b/test/helper-test.c index 1e9db324..fe575034 100644 --- a/test/helper-test.c +++ b/test/helper-test.c @@ -21,14 +21,14 @@ static int test = 0; } \ } -void error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) +void rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) { fputs ( msg, stderr ); } int show_error_message ( const char *msg, int markup ) { - error_dialog ( msg, markup ); + rofi_view_error_dialog ( msg, markup ); return 0; } #include diff --git a/test/textbox-test.c b/test/textbox-test.c index 4622015c..72e2e98a 100644 --- a/test/textbox-test.c +++ b/test/textbox-test.c @@ -30,14 +30,14 @@ void rofi_view_queue_redraw () { } -void error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) +void rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) { fputs ( msg, stderr ); } int show_error_message ( const char *msg, int markup ) { - error_dialog ( msg, markup ); + rofi_view_error_dialog ( msg, markup ); return 0; } -- cgit v1.2.3