From 72dfe2ad4c37d98b789019bb0f2b2bd3fc9e8971 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 5 Mar 2016 11:08:32 +0100 Subject: [PATCH] Propagate error down, show dialog. Fix positioning dialog. --- Makefile.am | 2 +- include/keyb.h | 2 +- include/textbox.h | 18 +++++++++--------- include/x11-helper.h | 3 ++- source/keyb.c | 8 ++++++-- source/rofi.c | 5 ++--- source/view.c | 9 ++++++--- source/x11-helper.c | 5 +++-- source/xrmoptions.c | 4 ++-- 9 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Makefile.am b/Makefile.am index a9905a92..a98704e0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -304,7 +304,7 @@ indent: $(rofi_SOURCES) $(top_srcdir)/config/config.def.c $(helper_test_SOURCES) .PHONY: cppcheck cppcheck: $(rofi_SOURCES) - cppcheck --std=c99 --platform=unix64 --enable=all -Uerror_dialog -I $(top_srcdir)/include/ $^ + cppcheck --std=c99 --platform=unix64 --enable=all -Uerror_dialog --inconclusive -I $(top_srcdir)/include/ $^ .PHONY: ohcount diff --git a/include/keyb.h b/include/keyb.h index 37d67884..9c986db9 100644 --- a/include/keyb.h +++ b/include/keyb.h @@ -82,7 +82,7 @@ typedef enum _KeyBindingAction * Parse the keybindings. * This should be called after the setting system is initialized. */ -void parse_keys_abe ( void ); +gboolean parse_keys_abe ( void ); /** * Setup the keybindings diff --git a/include/textbox.h b/include/textbox.h index e1d608e1..3d3b8d09 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -38,15 +38,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 diff --git a/include/x11-helper.h b/include/x11-helper.h index b0aa1eb3..a1435c3f 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -1,5 +1,6 @@ #ifndef X11_ROFI_HELPER_H #define X11_ROFI_HELPER_H +#include #include #include @@ -83,7 +84,7 @@ unsigned int x11_canonalize_mask ( unsigned int mask ); * * Parse key from user input string. */ -void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key ); +gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key ); /** * @param display The connection to the X server. diff --git a/source/keyb.c b/source/keyb.c index db4fc515..9916a276 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -100,7 +100,7 @@ void setup_abe ( void ) } } -void parse_keys_abe ( void ) +gboolean parse_keys_abe ( void ) { for ( int iter = 0; iter < NUM_ABE; iter++ ) { char *keystr = g_strdup ( abe[iter].keystr ); @@ -114,12 +114,16 @@ void parse_keys_abe ( void ) for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL; entry = strtok_r ( NULL, ",", &sp ) ) { abe[iter].kb = g_realloc ( abe[iter].kb, ( abe[iter].num_bindings + 1 ) * sizeof ( KeyBinding ) ); KeyBinding *kb = &( abe[iter].kb[abe[iter].num_bindings] ); - x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ) ); + if ( !x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ) ) ) { + g_free ( keystr ); + return FALSE; + } abe[iter].num_bindings++; } g_free ( keystr ); } + return TRUE; } void cleanup_abe ( void ) diff --git a/source/rofi.c b/source/rofi.c index 4055316d..967f7a80 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -534,9 +534,8 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data ) } TICK_N ( "Config sanity check" ); // Parse the keybindings. - parse_keys_abe (); - // Check if there is error dialog. - if ( rofi_view_get_active ( ) != NULL ) { + if ( !parse_keys_abe () ) { + // Error dialog return G_SOURCE_REMOVE; } TICK_N ( "Parse ABE" ); diff --git a/source/view.c b/source/view.c index 814d6a98..21c5ce7c 100644 --- a/source/view.c +++ b/source/view.c @@ -37,8 +37,6 @@ #include #include #include -#include -#include #include #include @@ -471,7 +469,7 @@ static xcb_window_t __create_window ( MenuFlags menu_flags ) { 0, 0, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_KEY_PRESS | - XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_1_MOTION,map }; + XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_1_MOTION, map }; xcb_window_t box = xcb_generate_id ( xcb->connection ); xcb_create_window ( xcb->connection, @@ -1720,6 +1718,9 @@ int rofi_view_error_dialog ( const char *msg, int markup ) // resize window vertically to suit state->h = state->line_height + ( state->border ) * 2; + // Calculte window position. + calculate_window_position ( state ); + // Move the window to the correct x,y position. uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; uint32_t vals[] = { state->x, state->y, state->w, state->h }; @@ -1733,6 +1734,8 @@ int rofi_view_error_dialog ( const char *msg, int markup ) if ( xcb->sncontext != NULL ) { sn_launchee_context_complete ( xcb->sncontext ); } + + // Set it has current window. rofi_view_set_active ( state ); return TRUE; } diff --git a/source/x11-helper.c b/source/x11-helper.c index c0fc3b8b..76991586 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -379,7 +379,7 @@ unsigned int x11_canonalize_mask ( unsigned int mask ) } // convert a Mod+key arg to mod mask and keysym -void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key ) +gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key ) { GString *str = g_string_new ( "" ); unsigned int modmask = 0; @@ -464,10 +464,11 @@ void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key ) if ( str->len > 0 ) { show_error_message ( str->str, TRUE ); g_string_free ( str, TRUE ); - return; + return FALSE; } g_string_free ( str, TRUE ); *key = sym; + return TRUE; } void x11_set_window_opacity ( xcb_window_t box, unsigned int opacity ) diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 3fb83fce..6fff1015 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -332,9 +332,9 @@ static void __config_parse_xresource_options_dynamic ( XrmDatabase xDB ) void config_parse_xresource_options_dynamic ( xcb_stuff *xcb ) { - char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER ); + char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER ); if ( name ) { - XrmDatabase xDB = XrmGetStringDatabase ( name ); + XrmDatabase xDB = XrmGetStringDatabase ( name ); __config_parse_xresource_options_dynamic ( xDB ); XrmDestroyDatabase ( xDB ); g_free ( name );