1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Fix tests and crash.

This commit is contained in:
Dave Davenport 2016-06-28 23:34:07 +02:00
parent 9f25a975ae
commit 7c9f5e01fd
3 changed files with 43 additions and 2 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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.