This commit is contained in:
Dave Davenport 2016-02-08 09:03:11 +01:00
parent ad932c8fd0
commit 5a86ae5c99
12 changed files with 35 additions and 31 deletions

View File

@ -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
*
* The error message to show.
* 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
*/
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" \
" <i>https://github.com/DaveDavenport/rofi/</i>"
#define ERROR_MSG_MARKUP TRUE
int locate_switcher ( KeySym key, unsigned int modstate );
/*@}*/
#endif

View File

@ -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

View File

@ -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: <b>%s</b>:\n\t<i>%s</i>", estr, strerror ( errno ) );
error_dialog ( msg, TRUE );
rofi_view_error_dialog ( msg, TRUE );
g_free ( msg );
g_free ( estr );
return TRUE;

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -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 );

View File

@ -41,6 +41,7 @@
#include "rofi.h"
#include "x11-helper.h"
#include "i3-support.h"
#include "view.h"
#ifdef HAVE_I3_IPC_H
#include <i3/ipc.h>
@ -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;

View File

@ -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 );

View File

@ -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.

View File

@ -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 <x11-helper.h>

View File

@ -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;
}