From 2060059c46af52097974aff76ec2ad8885c1587a Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 17 Jul 2017 15:01:02 +0200 Subject: [DMenu] If input is stdin and from a tty, do not read data. - This stops rofi from blocking the whole desktop. --- source/dialogs/dmenu.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'source/dialogs') diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index ab9e9f7c..87b4aaad 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -451,11 +451,13 @@ static int dmenu_mode_init ( Mode *sw ) } g_free ( estr ); } - pd->cancel = g_cancellable_new (); - pd->cancel_source = g_cancellable_connect ( pd->cancel, G_CALLBACK ( async_read_cancel ), pd, NULL ); - pd->input_stream = g_unix_input_stream_new ( fd, fd != STDIN_FILENO ); - pd->data_input_stream = g_data_input_stream_new ( pd->input_stream ); - + // If input is stdin, and a tty, do not read as rofi grabs input and therefor blocks. + if ( ! ( fd == STDIN_FILENO && isatty ( fd ) == 1 ) ) { + pd->cancel = g_cancellable_new (); + pd->cancel_source = g_cancellable_connect ( pd->cancel, G_CALLBACK ( async_read_cancel ), pd, NULL ); + pd->input_stream = g_unix_input_stream_new ( fd, fd != STDIN_FILENO ); + pd->data_input_stream = g_data_input_stream_new ( pd->input_stream ); + } gchar *columns = NULL; if ( find_arg_str ( "-display-columns", &columns ) ) { pd->columns = g_strsplit ( columns, ",", 0 ); @@ -663,13 +665,16 @@ int dmenu_switcher_dialog ( void ) find_arg ( "-selected-row" ) >= 0 ) { async = FALSE; } - if ( async ) { - unsigned int pre_read = 25; - find_arg_uint ( "-async-pre-read", &pre_read ); - async = get_dmenu_async ( pd, pre_read ); - } - else { - get_dmenu_sync ( pd ); + // Check if the subsystem is setup for reading, otherwise do not read. + if ( pd->cancel != NULL ) { + if ( async ) { + unsigned int pre_read = 25; + find_arg_uint ( "-async-pre-read", &pre_read ); + async = get_dmenu_async ( pd, pre_read ); + } + else { + get_dmenu_sync ( pd ); + } } char *input = NULL; unsigned int cmd_list_length = pd->cmd_list_length; -- cgit v1.2.3