diff --git a/config/config.c b/config/config.c index 7b4b3265..bb5f4555 100644 --- a/config/config.c +++ b/config/config.c @@ -78,6 +78,7 @@ Settings config = { .x_offset = 0, .fixed_num_lines = FALSE, .disable_history = FALSE, - .levenshtein_sort = FALSE + .levenshtein_sort = FALSE, + .separator = '\n' }; diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index e585fc08..60d824f3 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -12,7 +12,7 @@ rofi - A window switcher, run dialog and dmenu replacement [ -opacity *opacity%* ] [ -display *display* ] [ -bc *color* ] [ -bw *width* ] [ -dmenu [ -p *prompt* ] ] [ -ssh-client *client* ] [ -ssh-command *command* ] [ -now ] [ -rnow ] [ -snow ] [ -version ] [ -help] [ -dump-xresources ] [ -disable-history ] [ -levenshtein-sort ] [ -show *mode* ] [ -switcher -*mode1,mode2* ] [ -e *message*] +*mode1,mode2* ] [ -e *message*] [ -sep *separator* ] ## DESCRIPTION @@ -281,6 +281,10 @@ The default key combinations are: Popup a message dialog (used internally for showing errors) with *message*. +`-sep` *separator* + + Separator for dmenu. + ## Pattern To launch commands (e.g. when using the ssh dialog) the user can enter the used commandline, diff --git a/doc/rofi.1 b/doc/rofi.1 index 6b88401f..5b816a16 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -10,7 +10,7 @@ rofi \- A window switcher, run dialog and dmenu replacement [ \-opacity \fIopacity%\fP ] [ \-display \fIdisplay\fP ] [ \-bc \fIcolor\fP ] [ \-bw \fIwidth\fP ] [ \-dmenu [ \-p \fIprompt\fP ] ] [ \-ssh\-client \fIclient\fP ] [ \-ssh\-command \fIcommand\fP ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help] [ \-dump\-xresources ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-show \fImode\fP ] [ \-switcher -\fImode1,mode2\fP ] [ \-e \fImessage\fP] +\fImode1,mode2\fP ] [ \-e \fImessage\fP] [ \-sep \fIseparator\fP ] .SH DESCRIPTION .PP \fBrofi\fP is an X11 popup window switcher. A list is displayed center\-screen showing open window titles, WM_CLASS, and desktop number. @@ -362,6 +362,14 @@ So to have a mode 'Workspaces' using the \fB\fCi3_switch_workspace.sh\fR script Popup a message dialog (used internally for showing errors) with *message*. .fi .RE +.PP +\fB\fC\-sep\fR \fIseparator\fP +.PP +.RS +.nf +Separator for dmenu. +.fi +.RE .SH Pattern .PP To launch commands (e.g. when using the ssh dialog) the user can enter the used commandline, diff --git a/include/helper.h b/include/helper.h index dda0f1b7..9ba64dc3 100644 --- a/include/helper.h +++ b/include/helper.h @@ -3,4 +3,6 @@ int helper_parse_setup ( char * string, char ***output, int *lenght, ... ); +char* fgets_s ( char* s, int n, FILE *iop, char sep ); + #endif // __HELPER_H__ diff --git a/include/rofi.h b/include/rofi.h index 2dee8113..de95cb8e 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -129,6 +129,7 @@ typedef struct _Settings unsigned int disable_history; unsigned int levenshtein_sort; + char separator; } Settings; extern Settings config; diff --git a/source/dmenu-dialog.c b/source/dmenu-dialog.c index a4ec3fe2..89b22036 100644 --- a/source/dmenu-dialog.c +++ b/source/dmenu-dialog.c @@ -34,6 +34,7 @@ #include #include "rofi.h" #include "dmenu-dialog.h" +#include "helper.h" char *dmenu_prompt = "dmenu "; @@ -44,7 +45,7 @@ static char **get_dmenu ( int *length ) *length = 0; - while ( fgets ( buffer, 1024, stdin ) != NULL ) { + while ( fgets_s ( buffer, 1024, stdin, (char) config.separator ) != NULL ) { retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) ); retv[( *length )] = g_strdup ( buffer ); retv[( *length ) + 1] = NULL; diff --git a/source/helper.c b/source/helper.c index 4b1194d3..ac42384b 100644 --- a/source/helper.c +++ b/source/helper.c @@ -4,6 +4,27 @@ #include #include + +char* fgets_s ( char* s, int n, FILE *iop, char sep ) +{ + register int c; + register char* cs; + cs = s; + + while ( --n > 0 && ( c = getc ( iop ) ) != EOF ) { + // put the input char into the current pointer position, then increment it + // if a newline entered, break + if ( ( *cs++ = c ) == sep ) { + // Whipe separator + cs[-1] = '\0'; + break; + } + } + + *cs = '\0'; + return ( c == EOF && cs == s ) ? NULL : s; +} + /** * Replace the entries */ diff --git a/source/rofi.c b/source/rofi.c index d16de748..2d515f09 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -263,6 +263,53 @@ static int find_arg_uint ( const int argc, char * const argv[], const char * con } return FALSE; } +static int find_arg_char ( const int argc, char * const argv[], const char * const key, char *val ) +{ + int i = find_arg ( argc, argv, key ); + + if ( val != NULL && i > 0 && i < ( argc - 1 ) ) { + int len = strlen ( argv[i + 1] ); + if ( len == 1 ) { + *val = argv[i + 1][0]; + } + else if ( len == 2 && argv[i + 1][0] == '\\' ) { + if ( argv[i + 1][1] == 'n' ) { + *val = '\n'; + } + else if ( argv[i + 1][1] == 'a' ) { + *val = '\a'; + } + else if ( argv[i + 1][1] == 'b' ) { + *val = '\b'; + } + else if ( argv[i + 1][1] == 't' ) { + *val = '\t'; + } + else if ( argv[i + 1][1] == 'v' ) { + *val = '\v'; + } + else if ( argv[i + 1][1] == 'f' ) { + *val = '\f'; + } + else if ( argv[i + 1][1] == 'r' ) { + *val = '\r'; + } + else if ( argv[i + 1][1] == '\\' ) { + *val = '\\'; + } + else { + fprintf ( stderr, "Failed to parse command-line argument." ); + exit ( 1 ); + } + } + else{ + fprintf ( stderr, "Failed to parse command-line argument." ); + exit ( 1 ); + } + return TRUE; + } + return FALSE; +} static int ( *xerror )( Display *, XErrorEvent * ); @@ -2198,6 +2245,8 @@ static void parse_cmd_options ( int argc, char ** argv ) find_arg_str ( argc, argv, "-skey", &( config.ssh_key ) ); + + find_arg_char ( argc, argv, "-sep", &( config.separator ) ); // Dump. if ( find_arg ( argc, argv, "-dump-xresources" ) >= 0 ) { xresource_dump (); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 6fbb9b36..a0f04693 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -109,6 +109,7 @@ static XrmOption xrmOptions[] = { { xrm_String, "key", { .str = &config.window_key }, NULL }, { xrm_String, "rkey", { .str = &config.run_key }, NULL }, { xrm_String, "skey", { .str = &config.ssh_key }, NULL }, + { xrm_Number, "separator", { .num = &config.separator }, NULL }, };