From 354ccdd94d2c08dd1399496a96102433c409e9e9 Mon Sep 17 00:00:00 2001 From: QC Date: Sat, 16 May 2015 13:58:09 +0200 Subject: [PATCH] Fix Issue #164 --- doc/rofi-manpage.markdown | 5 +++-- doc/rofi.1 | 22 +++++++++++++++------- include/helper.h | 1 + source/dialogs/dmenu.c | 25 ++++++++++++++++--------- source/helper.c | 13 +++++++++++++ 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 87472554..1f09270a 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -520,8 +520,9 @@ The following options are further explained in the theming section: * 'i' index (0 - (N-1)). * 'd' index (1 - N). * 'q' quote string. - * 'e' escape string. - + * 'f' filter string (user input). + * 'F' quoted filter string (user input). + Default: 's' ### Message dialog diff --git a/doc/rofi.1 b/doc/rofi.1 index 4d7c8f8d..1d2f9e0b 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -87,7 +87,8 @@ Keybindings can also be specified in the \fB\fCXresources\fR file. \fBrofi\fP can emulate \fB\fCdmenu\fR (a dynamic menu for X) when launched with the \fB\fC\-dmenu\fR flag. .PP The official website for \fB\fCdmenu\fR can be found here -\[la]http://tools.suckless.org/dmenu/\[ra]\&. +.UR http://tools.suckless.org/dmenu/ +.UE \&. .SH OPTIONS .PP There are currently three methods of setting configuration options: @@ -97,7 +98,9 @@ Compile time: edit config.c. This method is strongly discouraged. .IP \(bu 2 Xresources: A method of storing key values in the Xserver. See here -\[la]https://en.wikipedia.org/wiki/X_resources\[ra] for more information. +.UR https://en.wikipedia.org/wiki/X_resources +.UE +for more information. .IP \(bu 2 Command\-line options: Arguments passed to \fBrofi\fP\&. .RE @@ -679,7 +682,8 @@ Allows the output of dmenu to be customized (N is total number of input entries) * 'i' index (0 \- (N\-1)). * 'd' index (1 \- N). * 'q' quote string. - * 'e' escape string. + * 'f' filter string (user input). + * 'F' quoted filter string (user input). Default: 's' .fi .RE @@ -921,18 +925,22 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .SH WEBSITE .PP \fBrofi\fP website can be found at here -\[la]https://davedavenport.github.io/rofi/\[ra] +.UR https://davedavenport.github.io/rofi/ +.UE .PP \fBrofi\fP bugtracker can be found here -\[la]https://github.com/DaveDavenport/rofi/issues\[ra] +.UR https://github.com/DaveDavenport/rofi/issues +.UE .SH AUTHOR .PP Qball Cow -\[la]qball@gmpclient.org\[ra] +.MT qball@gmpclient.org +.ME .PP Rasmus Steinke .PP Original code based on work by: Sean Pringle -\[la]sean.pringle@gmail.com\[ra] +.MT sean.pringle@gmail.com +.ME .PP For a full list of authors, check the AUTHORS file. diff --git a/include/helper.h b/include/helper.h index 80230a32..99b1bf7d 100644 --- a/include/helper.h +++ b/include/helper.h @@ -81,6 +81,7 @@ int find_arg_int ( const char * const key, int *val ); * @returns TRUE if key was found and val was set. */ int find_arg_str ( const char * const key, char** val ); +int find_arg_str_alloc ( const char * const key, char** val ); /** * @param key The key to search for diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 9c72eb83..fffa4f61 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -131,18 +131,21 @@ static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNU * @param format The format string used. See below for possible syntax. * @param string The selected entry. * @param selected_line The selected line index. + * @param filter The entered filter. * * Function that outputs the selected line in the user-specified format. * Currently the following formats are supported: * * i: Print the index (0-(N-1)) * * d: Print the index (1-N) * * s: Print input string. - * * e: Print input string shell quoted. + * * q: Print quoted input string. + * * f: Print the entered filter. + * * F: Print the entered filter, quoted * * This functions outputs the formatted string to stdout, appends a newline (\n) character and * calls flush on the file descriptor. */ -static void dmenu_output_formatted_line ( const char *format, const char *string, int selected_line ) +static void dmenu_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter ) { for ( int i = 0; format && format[i]; i++ ) { if ( format[i] == 'i' ) { @@ -159,8 +162,11 @@ static void dmenu_output_formatted_line ( const char *format, const char *string fputs ( quote, stdout ); g_free ( quote ); } - else if ( format[i] == 'e' ) { - char *quote = g_strescape ( string, "" ); + else if ( format[i] == 'f' ) { + fputs ( filter, stdout ); + } + else if ( format[i] == 'F' ) { + char *quote = g_shell_quote ( filter ); fputs ( quote, stdout ); g_free ( quote ); } @@ -213,6 +219,7 @@ int dmenu_switcher_dialog ( char **input ) return TRUE; } } + find_arg_str_alloc ( "-filter", input ); do { int next_pos = selected_line; @@ -225,7 +232,7 @@ int dmenu_switcher_dialog ( char **input ) */ restart = TRUE; if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) { - dmenu_output_formatted_line ( format, list[selected_line], selected_line ); + dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); retv = TRUE; if ( ( mretv & MENU_QUICK_SWITCH ) ) { retv = 10 + ( mretv & MENU_LOWER_MASK ); @@ -239,10 +246,10 @@ int dmenu_switcher_dialog ( char **input ) restart = FALSE; if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && list[selected_line] != NULL ) { if ( ( mretv & MENU_CUSTOM_INPUT ) ) { - dmenu_output_formatted_line ( format, *input, -1 ); + dmenu_output_formatted_line ( format, *input, -1, *input ); } else{ - dmenu_output_formatted_line ( format, list[selected_line], selected_line ); + dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); } if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; @@ -256,10 +263,10 @@ int dmenu_switcher_dialog ( char **input ) } else if ( ( mretv & MENU_QUICK_SWITCH ) ) { if ( ( mretv & MENU_CUSTOM_INPUT ) ) { - dmenu_output_formatted_line ( format, *input, -1 ); + dmenu_output_formatted_line ( format, *input, -1, *input ); } else{ - dmenu_output_formatted_line ( format, list[selected_line], selected_line ); + dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); } restart = FALSE; diff --git a/source/helper.c b/source/helper.c index 02262268..47127866 100644 --- a/source/helper.c +++ b/source/helper.c @@ -226,6 +226,19 @@ int find_arg_str ( const char * const key, char** val ) } return FALSE; } +int find_arg_str_alloc ( const char * const key, char** val ) +{ + int i = find_arg ( key ); + + if ( val != NULL && i > 0 && i < stored_argc - 1 ) { + if ( *val != NULL ) { + g_free ( *val ); + } + *val = g_strdup ( stored_argv[i + 1] ); + return TRUE; + } + return FALSE; +} int find_arg_int ( const char * const key, int *val ) {