From 7c9f5e01fd3250cfe1c9bcb83f1d87038fe867b5 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 28 Jun 2016 23:34:07 +0200 Subject: [PATCH] Fix tests and crash. --- doc/test_xr.txt | 2 ++ source/dialogs/dmenu.c | 40 +++++++++++++++++++++++++++++++++++++++- source/dialogs/window.c | 3 ++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/doc/test_xr.txt b/doc/test_xr.txt index c2576518..0d5928ec 100644 --- a/doc/test_xr.txt +++ b/doc/test_xr.txt @@ -94,6 +94,8 @@ rofi.scrollbar-width: 8 rofi.scroll-method: 0 ! Background to use for fake transparency. (background or screenshot) rofi.fake-background: screenshot +! Window Format. w (desktop name), t (title), n (name), r (role), c (class) +rofi.window-format: w c t ! Pidfile location rofi.pid: /tmp/1000-runtime-dir/rofi.pid ! Paste primary selection diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index ebb0b9cd..6fe27791 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -87,6 +87,9 @@ typedef struct unsigned int cmd_list_length; unsigned int only_selected; unsigned int selected_count; + + gchar **columns; + gchar *column_separator; } DmenuModePrivateData; static char **get_dmenu ( DmenuModePrivateData *pd, FILE *fd, unsigned int *length ) @@ -173,6 +176,34 @@ static void parse_ranges ( char *input, struct range_pair **list, unsigned int * } } +static gchar * dmenu_format_output_string ( const DmenuModePrivateData *pd, const char *input ) +{ + if ( pd->columns == NULL ) { + return g_strdup ( input ); + } + char *retv = NULL; + char ** splitted = g_regex_split_simple ( pd->column_separator, input, G_REGEX_CASELESS, 00 ); + uint32_t ns = 0; + for (; splitted && splitted[ns]; ns++ ) { + ; + } + for ( uint32_t i = 0; pd->columns && pd->columns[i]; i++ ) { + unsigned int index = (unsigned int ) g_ascii_strtoull ( pd->columns[i], NULL, 10 ); + if ( index < ns && index > 0 ) { + if ( retv == NULL ) { + retv = g_strdup ( splitted[index - 1] ); + } + else { + gchar *t = g_strjoin ( "\t", retv, splitted[index - 1], NULL ); + g_free ( retv ); + retv = t; + } + } + } + g_strfreev ( splitted ); + return retv ? retv : g_strdup ( "" ); +} + static char *get_display_data ( const Mode *data, unsigned int index, int *state, int get_entry ) { Mode *sw = (Mode *) data; @@ -194,7 +225,7 @@ static char *get_display_data ( const Mode *data, unsigned int index, int *state if ( pd->do_markup ) { *state |= MARKUP; } - return get_entry ? g_strdup ( retv[index] ) : NULL; + return get_entry ? dmenu_format_output_string ( pd, retv[index] ) : NULL; } /** @@ -341,6 +372,13 @@ static int dmenu_mode_init ( Mode *sw ) if ( fd != NULL ) { fclose ( fd ); } + + gchar *columns = NULL; + if ( find_arg_str ( "-display-columns", &columns ) ) { + pd->columns = g_strsplit ( columns, ",", 0 ); + pd->column_separator = "\t"; + find_arg_str ( "-display-column-separator", &pd->column_separator ); + } return TRUE; } diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 08cb090c..5fda3561 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -365,7 +365,8 @@ static int window_match ( const Mode *sw, GRegex **tokens, unsigned int index ) static unsigned int window_mode_get_num_entries ( const Mode *sw ) { const ModeModePrivateData *pd = (const ModeModePrivateData *) mode_get_private_data ( sw ); - return pd->ids->len; + + return pd->ids?pd->ids->len:0; } /** * Small helper function to find the right entry in the ewmh reply.