Continue parsing when keybinding fail, only show errors after all are done.

This commit is contained in:
Dave Davenport 2016-11-14 16:53:01 +01:00
parent d450d02ad6
commit 62879ee739
5 changed files with 38 additions and 43 deletions

View File

@ -161,7 +161,7 @@ Global options:
-kb-remove-char-forward [string] Delete next char
Delete,Control+d (File)
-kb-remove-char-back [string] Delete previous char
BackSpace,Control+h (File)
Backspace,Control+h (File)
-kb-remove-to-eol [string] Delete till the end of line
Control+k (File)
-kb-remove-to-sol [string] Delete till the start of line
@ -199,7 +199,7 @@ Global options:
-kb-row-select [string] Set selected item as input text
Control+space (File)
-kb-screenshot [string] Take a screenshot of the rofi window
Alt+Shift+S (File)
Alt+S (File)
-kb-toggle-case-sensitivity [string] Toggle case sensitivity
grave,dead_grave (File)
-kb-toggle-sort [string] Toggle sort
@ -229,21 +229,21 @@ Global options:
-kb-custom-11 [string] Custom keybinding 11
Alt+Shift+1 (File)
-kb-custom-12 [string] Custom keybinding 12
Alt+Shift+2 (File)
Alt+at (File)
-kb-custom-13 [string] Csutom keybinding 13
Alt+Shift+3 (File)
Alt+numbersign (File)
-kb-custom-14 [string] Custom keybinding 14
Alt+Shift+4 (File)
Alt+dollar (File)
-kb-custom-15 [string] Custom keybinding 15
Alt+Shift+5 (File)
Alt+percent (File)
-kb-custom-16 [string] Custom keybinding 16
Alt+Shift+6 (File)
Alt+dead_circumflex (File)
-kb-custom-17 [string] Custom keybinding 17
Alt+Shift+7 (File)
Alt+ampersand (File)
-kb-custom-18 [string] Custom keybinding 18
Alt+Shift+8 (File)
Alt+asterisk (File)
-kb-custom-19 [string] Custom Keybinding 19
Alt+Shift+9 (File)
Alt+parenleft (File)
-display-ssh [string] The display name of this browser
 (File)
-display-run [string] The display name of this browser

View File

@ -125,7 +125,7 @@ rofi.kb-remove-word-forward: Control+Alt+d
! "Delete next char" Set from: File
rofi.kb-remove-char-forward: Delete,Control+d
! "Delete previous char" Set from: File
rofi.kb-remove-char-back: BackSpace,Control+h
rofi.kb-remove-char-back: Backspace,Control+h
! "Delete till the end of line" Set from: File
rofi.kb-remove-to-eol: Control+k
! "Delete till the start of line" Set from: File
@ -163,7 +163,7 @@ rofi.kb-row-last: End,KP_End
! "Set selected item as input text" Set from: File
rofi.kb-row-select: Control+space
! "Take a screenshot of the rofi window" Set from: File
rofi.kb-screenshot: Alt+Shift+S
rofi.kb-screenshot: Alt+S
! "Toggle case sensitivity" Set from: File
rofi.kb-toggle-case-sensitivity: grave,dead_grave
! "Toggle sort" Set from: File
@ -193,21 +193,21 @@ rofi.kb-custom-10: Alt+0
! "Custom keybinding 11" Set from: File
rofi.kb-custom-11: Alt+Shift+1
! "Custom keybinding 12" Set from: File
rofi.kb-custom-12: Alt+Shift+2
rofi.kb-custom-12: Alt+at
! "Csutom keybinding 13" Set from: File
rofi.kb-custom-13: Alt+Shift+3
rofi.kb-custom-13: Alt+numbersign
! "Custom keybinding 14" Set from: File
rofi.kb-custom-14: Alt+Shift+4
rofi.kb-custom-14: Alt+dollar
! "Custom keybinding 15" Set from: File
rofi.kb-custom-15: Alt+Shift+5
rofi.kb-custom-15: Alt+percent
! "Custom keybinding 16" Set from: File
rofi.kb-custom-16: Alt+Shift+6
rofi.kb-custom-16: Alt+dead_circumflex
! "Custom keybinding 17" Set from: File
rofi.kb-custom-17: Alt+Shift+7
rofi.kb-custom-17: Alt+ampersand
! "Custom keybinding 18" Set from: File
rofi.kb-custom-18: Alt+Shift+8
rofi.kb-custom-18: Alt+asterisk
! "Custom Keybinding 19" Set from: File
rofi.kb-custom-19: Alt+Shift+9
rofi.kb-custom-19: Alt+parenleft
! "The display name of this browser" Set from: File
rofi.display-ssh: 
! "The display name of this browser" Set from: File

View File

@ -162,7 +162,7 @@ unsigned int x11_get_current_mask ( xkb_stuff *xkb );
*
* Parse key from user input string.
*/
gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key, gboolean *release );
gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key, gboolean *release, GString * );
/**
* Setup several items required.

View File

@ -109,6 +109,7 @@ void setup_abe ( void )
gboolean parse_keys_abe ( void )
{
GString *error_msg = g_string_new ( "" );
for ( int iter = 0; iter < NUM_ABE; iter++ ) {
char *keystr = g_strdup ( abe[iter].keystr );
char *sp = NULL;
@ -123,15 +124,19 @@ gboolean parse_keys_abe ( void )
abe[iter].kb = g_realloc ( abe[iter].kb, ( abe[iter].num_bindings + 1 ) * sizeof ( KeyBinding ) );
KeyBinding *kb = &( abe[iter].kb[abe[iter].num_bindings] );
memset ( kb, 0, sizeof ( KeyBinding ) );
if ( !x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ), &( kb->release ) ) ) {
g_free ( keystr );
return FALSE;
if ( x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ), &( kb->release ), error_msg ) ) {
abe[iter].num_bindings++;
}
abe[iter].num_bindings++;
}
g_free ( keystr );
}
if ( error_msg->len > 0 ) {
rofi_view_error_dialog ( error_msg->str, TRUE );
g_string_free ( error_msg, TRUE );
return FALSE;
}
g_string_free ( error_msg, TRUE );
return TRUE;
}

View File

@ -612,16 +612,15 @@ unsigned int x11_get_current_mask ( xkb_stuff *xkb )
}
// convert a Mod+key arg to mod mask and keysym
gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key, gboolean *release )
gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key, gboolean *release, GString *str )
{
GString *str = g_string_new ( "" );
unsigned int modmask = 0;
if ( g_str_has_prefix ( combo, "!" ) ) {
++combo;
*release = TRUE;
}
// TODO split this into tokonized parsing, so propper error can be generated.
if ( strcasestr ( combo, "shift" ) ) {
modmask |= x11_mod_masks[X11MOD_SHIFT];
if ( x11_mod_masks[X11MOD_SHIFT] == 0 ) {
@ -658,10 +657,6 @@ gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key, gboo
g_string_append_printf ( str, "X11 configured keyboard has no <b>Hyper</b> key.\n" );
}
}
int seen_mod = FALSE;
if ( strcasestr ( combo, "Mod" ) ) {
seen_mod = TRUE;
}
// Find location of modifier (if it exists)
char i = strlen ( combo );
@ -678,26 +673,21 @@ gboolean x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key, gboo
*mod = modmask;
}
// Parse key
xkb_keysym_t sym = XKB_KEY_NoSymbol;
sym = xkb_keysym_from_name ( combo + i, XKB_KEYSYM_NO_FLAGS );
if ( sym == XKB_KEY_NoSymbol || ( !modmask && ( strchr ( combo, '-' ) || strchr ( combo, '+' ) ) ) ) {
g_string_append_printf ( str, "Sorry, rofi cannot understand the key combination: <i>%s</i>\n", combo );
g_string_append ( str, "\nRofi supports the following modifiers:\n\t" );
g_string_append ( str, "<i>Shift,Control,Alt,Super,Meta,Hyper</i>" );
if ( seen_mod ) {
g_string_append ( str, "\n\n<b>Mod1,Mod2,Mod3,Mod4,Mod5 are no longer supported, use one of the above.</b>" );
if ( sym == XKB_KEY_NoSymbol ) {
g_string_append_printf ( str, "∙ Key <i>%s</i> is not understood\n", combo + i );
}
}
if ( str->len > 0 ) {
rofi_view_error_dialog ( str->str, TRUE );
g_string_free ( str, TRUE );
if ( ( !modmask && ( strchr ( combo, '-' ) || strchr ( combo, '+' ) ) ) ) {
g_string_append ( str, "∙ Rofi supports the following modifiers: <i>Shift,Control,Alt,Super,Meta,Hyper</i>\n" );
}
g_string_append_c ( str, '\n' );
return FALSE;
}
g_string_free ( str, TRUE );
*key = sym;
return TRUE;
}