summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2015-12-03 18:21:23 +0100
committerDave Davenport <qball@gmpclient.org>2015-12-03 18:22:13 +0100
commit697abdfdfc5a3aee299827d8c883f54f26f5a994 (patch)
tree4dceaae50e9545763d65ae4c9132614259bb327d
parent2195efd3bf6c0dc14a222347821189924790c0c4 (diff)
[DMenu] Add option to read from file instead of stdin.
-rw-r--r--Changelog1
-rw-r--r--doc/rofi-manpage.markdown6
-rw-r--r--source/dialogs/dmenu.c22
3 files changed, 25 insertions, 4 deletions
diff --git a/Changelog b/Changelog
index 21a04531..213c7223 100644
--- a/Changelog
+++ b/Changelog
@@ -7,6 +7,7 @@
- Autodetect number of HW-threads.
- Disabled by default.
- Highlight multiple selected rows (#287)
+ - Dmenu can read from file instead of stdin.
Improvements:
- Improve speed of reading stdin in dmenu mode.
- Correctly handle modifier keys now. Should now support most weird keyboard layouts and switching between them.
diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown
index 409a57fc..2cd83d69 100644
--- a/doc/rofi-manpage.markdown
+++ b/doc/rofi-manpage.markdown
@@ -29,7 +29,7 @@
[ -display *display* ]
[ -bc *color* ]
[ -bw *width* ]
-[ -dmenu [ -p *prompt* ] [ -sep *separator* ] [ -l *selected line* ] [ -mesg ] [ -select ] ]
+[ -dmenu [ -p *prompt* ] [ -sep *separator* ] [ -l *selected line* ] [ -mesg ] [ -select ] [ -input *input* ] ]
[ -filter *filter* ]
[ -ssh-client *client* ]
[ -ssh-command *command* ]
@@ -632,6 +632,10 @@ Dump the filtered list to stdout and quit.
This can be used to get the list as **rofi** would filter it.
Use together with `-filter` command.
+`-input` *file*
+
+Reads from *file* instead of stdin.
+
### Message dialog
`-e` *message*
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c
index 781e6564..3c888a8c 100644
--- a/source/dialogs/dmenu.c
+++ b/source/dialogs/dmenu.c
@@ -33,6 +33,7 @@
#include <string.h>
#include <ctype.h>
#include <stdint.h>
+#include <errno.h>
#include "rofi.h"
#include "dialogs/dmenu.h"
#include "helper.h"
@@ -63,7 +64,7 @@ typedef struct _DmenuModePrivateData
unsigned int cmd_list_length;
} DmenuModePrivateData;
-static char **get_dmenu ( unsigned int *length )
+static char **get_dmenu ( FILE *fd, unsigned int *length )
{
TICK_N ( "Read stdin START" );
char **retv = NULL;
@@ -73,7 +74,7 @@ static char **get_dmenu ( unsigned int *length )
gchar *data = NULL;
size_t data_l = 0;
ssize_t l = 0;
- while ( ( l = getdelim ( &data, &data_l, config.separator, stdin ) ) > 0 ) {
+ while ( ( l = getdelim ( &data, &data_l, config.separator, fd ) ) > 0 ) {
if ( rvlength < ( *length + 2 ) ) {
rvlength *= 2;
retv = g_realloc ( retv, ( rvlength ) * sizeof ( char* ) );
@@ -286,7 +287,22 @@ static void dmenu_mode_init ( Mode *sw )
if ( find_arg ( "-i" ) >= 0 ) {
config.case_sensitive = FALSE;
}
- pd->cmd_list = get_dmenu ( &( pd->cmd_list_length ) );
+ FILE *fd = NULL;
+ str = NULL;
+ if ( find_arg_str ("-input", &str)) {
+ char *estr = rofi_expand_path(str);
+ fd = fopen(str, "r");
+ if(fd == NULL ){
+ char *msg = g_markup_printf_escaped("Failed to open file: <b>%s</b>:\n\t<i>%s</i>", estr, strerror(errno));
+ error_dialog (msg,TRUE);
+ g_free(msg);
+ g_free(estr);
+ return;
+ }
+ g_free(estr);
+ }
+ pd->cmd_list = get_dmenu ( fd == NULL?stdin:fd , &( pd->cmd_list_length ) );
+ if(fd != NULL ) fclose(fd);
}
static int dmenu_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )