diff --git a/config/config.def.c b/config/config.def.c index e8aac238..2a2313b5 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -133,5 +133,6 @@ Settings config = { /** Monitor */ .monitor = -1, .line_margin = 3, + .filter = NULL, }; diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 6cb948c0..e34017d6 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -29,7 +29,8 @@ [ -display *display* ] [ -bc *color* ] [ -bw *width* ] -[ -dmenu [ -p *prompt* ] [ -sep *separator* ] [ -l *selected line* ] [ -mesg ] [ -filter ] [ -select ] ] +[ -dmenu [ -p *prompt* ] [ -sep *separator* ] [ -l *selected line* ] [ -mesg ] [ -select ] ] +[ -filter *filter* ] [ -ssh-client *client* ] [ -ssh-command *command* ] [ -disable-history ] @@ -193,10 +194,14 @@ Below is a list of the most important options: Do not print any message when starting in daemon mode. -`-fuzzy` +`-fuzzy` Enable experimental fuzzy matching. +`-filter` *filter* + + Preset user filter to *filter* in the entry box and pre-filter the list. + ### Theming @@ -560,10 +565,6 @@ The following options are further explained in the theming section: Default: 's' -`-filter` *filter* - - Preset user filter to *filter* in the entry box and pre-filter the list. - `-select` *string* Select first line that matches the given string diff --git a/doc/rofi.1 b/doc/rofi.1 index 0b7de0f9..acdb5b76 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -7,7 +7,7 @@ \fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement . .SH "SYNOPSIS" -\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-fg \fIcolor\fR ] [ \-fg\-urgent \fIcolor\fR ] [ \-fg\-active \fIcolor\fR ] [ \-bg\-urgent \fIcolor\fR ] [ \-bg\-active \fIcolor\fR ] [ \-bg \fIcolor\fR ] [ \-bgalt \fIcolor\fR ] [ \-hlfg \fIcolor\fR ] [ \-hlbg \fIcolor\fR ] [ \-key\-\fBmode\fR \fIcombo\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bc \fIcolor\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-filter ] [ \-select ] ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help] [ \-dump\-xresources ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-quiet ] +\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-fg \fIcolor\fR ] [ \-fg\-urgent \fIcolor\fR ] [ \-fg\-active \fIcolor\fR ] [ \-bg\-urgent \fIcolor\fR ] [ \-bg\-active \fIcolor\fR ] [ \-bg \fIcolor\fR ] [ \-bgalt \fIcolor\fR ] [ \-hlfg \fIcolor\fR ] [ \-hlbg \fIcolor\fR ] [ \-key\-\fBmode\fR \fIcombo\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bc \fIcolor\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help] [ \-dump\-xresources ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-quiet ] . .SH "DESCRIPTION" \fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\. @@ -297,6 +297,19 @@ Enable experimental fuzzy matching\. . .IP "" 0 . +.P +\fB\-filter\fR \fIfilter\fR +. +.IP "" 4 +. +.nf + +Preset user filter to *filter* in the entry box and pre\-filter the list\. +. +.fi +. +.IP "" 0 +. .SS "Theming" \fB\-bg\fR . @@ -741,11 +754,11 @@ When one entry is left, automatically select this\. . .IP "" 4 . -.P -Select (Xinerama) monitor to display **rofi** on\. The special number -1 denotes the currently focused monitor, the number -2 denotes the currently focused window (i.e. rofi will be displayed on top of the focused window). -. -.P -Default: \fI{cmd}\fR +.nf + +Select (Xinerama) monitor to display **rofi** on\. The special number \-1 denotes the currently focused monitor, the number \-2 denotes the currently focused window (i\.e\. rofi will be displayed on top of the focused window)\. + +Default: *\-1* . .fi . @@ -1021,19 +1034,6 @@ Default: \'s\' .IP "" 0 . .P -\fB\-filter\fR \fIfilter\fR -. -.IP "" 4 -. -.nf - -Preset user filter to *filter* in the entry box and pre\-filter the list\. -. -.fi -. -.IP "" 0 -. -.P \fB\-select\fR \fIstring\fR . .IP "" 4 diff --git a/include/dialogs/dmenu.h b/include/dialogs/dmenu.h index da08b44b..7d20b3a7 100644 --- a/include/dialogs/dmenu.h +++ b/include/dialogs/dmenu.h @@ -3,12 +3,10 @@ /** - * @param input Pointer to the user-input string. - * * dmenu dialog. * * @returns TRUE if script was successful. */ -int dmenu_switcher_dialog ( char **input ); +int dmenu_switcher_dialog ( void ); #endif diff --git a/include/rofi.h b/include/rofi.h index 062a8187..1aa5b6b9 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -232,6 +232,8 @@ typedef struct _Settings int monitor; /** Line margin */ unsigned int line_margin; + /** filter */ + char *filter; } Settings; /** Global Settings structure. */ diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index a440f871..cc1f6f33 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -178,8 +178,9 @@ static void dmenu_output_formatted_line ( const char *format, const char *string fflush ( stdout ); } -int dmenu_switcher_dialog ( char **input ) +int dmenu_switcher_dialog ( void ) { + char *input = NULL; char *dmenu_prompt = "dmenu "; int selected_line = -1; int retv = FALSE; @@ -218,7 +219,8 @@ int dmenu_switcher_dialog ( char **input ) return TRUE; } } - find_arg_str_alloc ( "-filter", input ); + /* copy filter string */ + input = g_strdup ( config.filter ); char *select = NULL; find_arg_str ( "-select", &select ); @@ -251,7 +253,7 @@ int dmenu_switcher_dialog ( char **input ) do { int next_pos = selected_line; - int mretv = menu ( list, length, input, dmenu_prompt, + int mretv = menu ( list, length, &input, dmenu_prompt, token_match, NULL, &selected_line, config.levenshtein_sort, get_display_data, list, &next_pos, message ); // Special behavior. // TODO clean this up! @@ -261,7 +263,7 @@ int dmenu_switcher_dialog ( char **input ) */ restart = 1; if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) { - dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); + dmenu_output_formatted_line ( format, list[selected_line], selected_line, input ); retv = TRUE; if ( ( mretv & MENU_QUICK_SWITCH ) ) { retv = 10 + ( mretv & MENU_LOWER_MASK ); @@ -279,7 +281,7 @@ int dmenu_switcher_dialog ( char **input ) restart = FALSE; // Normal mode if ( ( mretv & MENU_OK ) && list[selected_line] != NULL ) { - dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); + dmenu_output_formatted_line ( format, list[selected_line], selected_line, input ); if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; // Move to next line. @@ -289,7 +291,7 @@ int dmenu_switcher_dialog ( char **input ) } // Custom input else if ( ( mretv & ( MENU_CUSTOM_INPUT ) ) ) { - dmenu_output_formatted_line ( format, *input, -1, *input ); + dmenu_output_formatted_line ( format, input, -1, input ); if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; // Move to next line. @@ -300,14 +302,14 @@ int dmenu_switcher_dialog ( char **input ) } // Quick switch with entry selected. else if ( ( mretv & MENU_QUICK_SWITCH ) && selected_line >= 0 ) { - dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); + dmenu_output_formatted_line ( format, list[selected_line], selected_line, input ); restart = FALSE; retv = 10 + ( mretv & MENU_LOWER_MASK ); } // Quick switch without entry selected. else if ( ( mretv & MENU_QUICK_SWITCH ) && selected_line == -1 ) { - dmenu_output_formatted_line ( format, *input, -1, *input ); + dmenu_output_formatted_line ( format, input, -1, input ); restart = FALSE; retv = 10 + ( mretv & MENU_LOWER_MASK ); @@ -318,6 +320,8 @@ int dmenu_switcher_dialog ( char **input ) g_free ( urgent_list ); g_free ( active_list ); + g_free ( input ); + return retv; } diff --git a/source/rofi.c b/source/rofi.c index c472fa3f..8981bb05 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1502,17 +1502,15 @@ static void teardown ( int pfd ) */ static int run_dmenu () { - char *input = NULL; - int ret_state = EXIT_FAILURE; - int pfd = setup (); + int ret_state = EXIT_FAILURE; + int pfd = setup (); if ( pfd < 0 ) { return ret_state; } // Dmenu modi has a return state. - ret_state = dmenu_switcher_dialog ( &input ); + ret_state = dmenu_switcher_dialog (); - g_free ( input ); teardown ( pfd ); return ret_state; } @@ -1524,7 +1522,7 @@ static void run_switcher ( SwitcherMode mode ) return; } // Otherwise check if requested mode is enabled. - char *input = NULL; + char *input = g_strdup ( config.filter ); for ( unsigned int i = 0; i < num_switchers; i++ ) { switchers[i]->init ( switchers[i] ); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 1a931def..a35cf849 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -127,7 +127,8 @@ static XrmOption xrmOptions[] = { { xrm_Number, "monitor", { .snum = &config.monitor }, NULL }, /* Alias for dmenu compatibility. */ { xrm_SNumber, "m", { .snum = &config.monitor }, NULL }, - { xrm_Number, "line-margin", { .num = &config.line_margin }, NULL } + { xrm_Number, "line-margin", { .num = &config.line_margin }, NULL }, + { xrm_String, "filter", { .str = &config.filter }, NULL } }; // Dynamic options.