1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Remove the is_ascii mess.

This commit is contained in:
Dave Davenport 2016-05-22 17:47:34 +02:00
parent 8091558ed8
commit 498fadc735
14 changed files with 59 additions and 223 deletions

View file

@ -32,8 +32,8 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... );
*
* @returns a newly allocated 2 dimensional array of strings.
*/
char **tokenize ( const char *input, int case_sensitive );
void tokenize_free ( char ** tokens );
GRegex **tokenize ( const char *input, int case_sensitive );
void tokenize_free ( GRegex ** tokens );
/**
* @param key The key to search for
@ -97,7 +97,7 @@ int find_arg ( const char * const key );
*
* @returns 1 when matches, 0 otherwise
*/
int token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive );
int token_match ( GRegex **tokens, const char *input);
/**
* @param cmd The command to execute.
*
@ -160,6 +160,6 @@ unsigned int levenshtein ( const char *needle, const char *haystack );
*/
char * rofi_force_utf8 ( gchar *data );
char * rofi_latin_to_utf8_strdup ( const char *input, gssize length );
PangoAttrList *token_match_get_pango_attr ( char **tokens, const char *input, PangoAttrList *retv );
PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input, PangoAttrList *retv );
/*@}*/
#endif // ROFI_HELPER_H

View file

@ -17,7 +17,7 @@ typedef char * ( *_mode_get_completion )( const Mode *sw, unsigned int selected_
*
* @returns 1 when it matches, 0 if not.
*/
typedef int ( *_mode_token_match )( const Mode *data, char **tokens, int not_ascii, int case_sensitive, unsigned int index );
typedef int ( *_mode_token_match )( const Mode *data, GRegex **tokens, unsigned int index );
typedef int ( *__mode_init )( Mode *sw );
@ -27,8 +27,6 @@ typedef void ( *__mode_destroy )( Mode *sw );
typedef ModeMode ( *_mode_result )( Mode *sw, int menu_retv, char **input, unsigned int selected_line );
typedef int ( *_mode_is_not_ascii )( const Mode *sw, unsigned int index );
/**
* Structure defining a switcher.
* It consists of a name, callback and if enabled
@ -50,8 +48,6 @@ struct rofi_mode
__mode_destroy _destroy;
/** Get number of entries to display. (unfiltered). */
__mode_get_num_entries _get_num_entries;
/** Check if the element is ascii. */
_mode_is_not_ascii _is_not_ascii;
/** Process the result of the user selection. */
_mode_result _result;
/** Token match. */

View file

@ -96,16 +96,6 @@ char * mode_get_display_value ( const Mode *mode, unsigned int selected_line, in
*/
char * mode_get_completion ( const Mode *mode, unsigned int selected_line );
/**
* @param mode The mode to query
* @param selected_line The entry to query
*
* Check if the entry has non-ascii characters.
*
* @returns TRUE when selected line has non-ascii characters.
*/
int mode_is_not_ascii ( const Mode *mode, unsigned int selected_line );
/**
* @param mode The mode to query
* @param mretv The menu return value.
@ -121,15 +111,13 @@ ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int sel
/**
* @param mode The mode to query
* @param tokens The set of tokens to match against
* @param not_ascii If the entry is pure-ascii
* @param case_sensitive If the entry should be matched case sensitive
* @param selected_line The index of the entry to match
*
* Match entry against the set of tokens.
*
* @returns TRUE if matches
*/
int mode_token_match ( const Mode *mode, char **tokens, int not_ascii, int case_sensitive, unsigned int selected_line );
int mode_token_match ( const Mode *mode, GRegex **tokens, unsigned int selected_line );
/**
* @param mode The mode to query

View file

@ -56,7 +56,6 @@ struct RofiViewState
// Return state
unsigned int selected_line;
MenuReturn retv;
int *lines_not_ascii;
int line_height;
unsigned int border;
workarea mon;

View file

@ -175,18 +175,17 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned
}
return MODE_EXIT;
}
static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii,
int case_sensitive, unsigned int index )
static int combi_mode_match ( const Mode *sw, GRegex **tokens, unsigned int index )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
if ( config.regex || config.glob ) {
// if ( config.regex || config.glob ) {
// Bang support only works in text mode.
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
return mode_token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
index - pd->starts[i] );
return mode_token_match ( pd->switchers[i], tokens, index - pd->starts[i] );
}
}
/* @TODO fix this
}
else{
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
@ -205,6 +204,7 @@ static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii,
}
}
}
*/
abort ();
return 0;
}
@ -231,16 +231,6 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat
return NULL;
}
static int combi_is_not_ascii ( const Mode *sw, unsigned int index )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
return mode_is_not_ascii ( pd->switchers[i], index - pd->starts[i] );
}
}
return FALSE;
}
static char * combi_get_completion ( const Mode *sw, unsigned int index )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
@ -269,7 +259,6 @@ Mode combi_mode =
._token_match = combi_mode_match,
._get_completion = combi_get_completion,
._get_display_value = combi_mgrv,
._is_not_ascii = combi_is_not_ascii,
.private_data = NULL,
.free = NULL
};

View file

@ -332,16 +332,10 @@ static int dmenu_mode_init ( Mode *sw )
return TRUE;
}
static int dmenu_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
static int dmenu_token_match ( const Mode *sw, GRegex **tokens, unsigned int index )
{
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw );
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
}
static int dmenu_is_not_ascii ( const Mode *sw, unsigned int index )
{
DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw );
return !g_str_is_ascii ( rmpd->cmd_list[index] );
return token_match ( tokens, rmpd->cmd_list[index] );
}
#include "mode-private.h"
@ -356,7 +350,6 @@ Mode dmenu_mode =
._token_match = dmenu_token_match,
._get_display_value = get_display_data,
._get_completion = NULL,
._is_not_ascii = dmenu_is_not_ascii,
.private_data = NULL,
.free = NULL
};
@ -516,25 +509,25 @@ int dmenu_switcher_dialog ( void )
char *select = NULL;
find_arg_str ( "-select", &select );
if ( select != NULL ) {
char **tokens = tokenize ( select, config.case_sensitive );
GRegex **tokens = tokenize ( select, config.case_sensitive );
unsigned int i = 0;
for ( i = 0; i < cmd_list_length; i++ ) {
if ( token_match ( tokens, cmd_list[i], !g_str_is_ascii ( cmd_list[i] ), config.case_sensitive ) ) {
if ( token_match ( tokens, cmd_list[i] ) ) {
pd->selected_line = i;
break;
}
}
g_strfreev ( tokens );
tokenize_free ( tokens );
}
if ( find_arg ( "-dump" ) >= 0 ) {
char **tokens = tokenize ( config.filter ? config.filter : "", config.case_sensitive );
GRegex **tokens = tokenize ( config.filter ? config.filter : "", config.case_sensitive );
unsigned int i = 0;
for ( i = 0; i < cmd_list_length; i++ ) {
if ( token_match ( tokens, cmd_list[i], !g_str_is_ascii ( cmd_list[i] ), config.case_sensitive ) ) {
if ( token_match ( tokens, cmd_list[i] ) ) {
dmenu_output_formatted_line ( pd->format, cmd_list[i], i, config.filter );
}
}
g_strfreev ( tokens );
tokenize_free ( tokens );
return TRUE;
}
// TODO remove

View file

@ -378,29 +378,24 @@ static char *drun_get_completion ( const Mode *sw, unsigned int index )
}
}
static int drun_token_match ( const Mode *data,
char **tokens,
int not_ascii,
int case_sensitive,
unsigned int index
)
static int drun_token_match ( const Mode *data, GRegex **tokens, unsigned int index)
{
DRunModePrivateData *rmpd = (DRunModePrivateData *) mode_get_private_data ( data );
int match = 1;
if ( tokens ) {
for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) {
int test = 0;
char *ftokens[2] = { tokens[j], NULL };
GRegex *ftokens[2] = { tokens[j], NULL };
if ( !test && rmpd->entry_list[index].name &&
token_match ( ftokens, rmpd->entry_list[index].name, not_ascii, case_sensitive ) ) {
token_match ( ftokens, rmpd->entry_list[index].name ) ) {
test = 1;
}
if ( !test && rmpd->entry_list[index].generic_name &&
token_match ( ftokens, rmpd->entry_list[index].generic_name, not_ascii, case_sensitive ) ) {
token_match ( ftokens, rmpd->entry_list[index].generic_name) ) {
test = 1;
}
if ( !test && token_match ( ftokens, rmpd->entry_list[index].exec, not_ascii, case_sensitive ) ) {
if ( !test && token_match ( ftokens, rmpd->entry_list[index].exec) ) {
test = 1;
}
if ( test == 0 ) {
@ -416,15 +411,6 @@ static unsigned int drun_mode_get_num_entries ( const Mode *sw )
const DRunModePrivateData *pd = (const DRunModePrivateData *) mode_get_private_data ( sw );
return pd->cmd_list_length;
}
static int drun_is_not_ascii ( const Mode *sw, unsigned int index )
{
DRunModePrivateData *pd = (DRunModePrivateData *) mode_get_private_data ( sw );
if ( pd->entry_list[index].generic_name ) {
return !g_str_is_ascii ( pd->entry_list[index].name ) || !g_str_is_ascii ( pd->entry_list[index].generic_name );
}
return !g_str_is_ascii ( pd->entry_list[index].name );
}
#include "mode-private.h"
Mode drun_mode =
{
@ -437,7 +423,6 @@ Mode drun_mode =
._token_match = drun_token_match,
._get_completion = drun_get_completion,
._get_display_value = _get_display_value,
._is_not_ascii = drun_is_not_ascii,
.private_data = NULL,
.free = NULL
};

View file

@ -418,16 +418,10 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
}
static int run_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
static int run_token_match ( const Mode *sw, GRegex **tokens, unsigned int index )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
}
static int run_is_not_ascii ( const Mode *sw, unsigned int index )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
return !g_str_is_ascii ( rmpd->cmd_list[index] );
return token_match ( tokens, rmpd->cmd_list[index]);
}
#include "mode-private.h"
@ -442,7 +436,6 @@ Mode run_mode =
._token_match = run_token_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._is_not_ascii = run_is_not_ascii,
.private_data = NULL,
.free = NULL
};

View file

@ -168,16 +168,10 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
}
static int script_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
static int script_token_match ( const Mode *sw, GRegex **tokens, unsigned int index )
{
ScriptModePrivateData *rmpd = sw->private_data;
return token_match ( tokens, rmpd->cmd_list[index], not_ascii, case_sensitive );
}
static int script_is_not_ascii ( const Mode *sw, unsigned int index )
{
ScriptModePrivateData *rmpd = sw->private_data;
return !g_str_is_ascii ( rmpd->cmd_list[index] );
return token_match ( tokens, rmpd->cmd_list[index] );
}
#include "mode-private.h"
@ -207,7 +201,6 @@ Mode *script_switcher_parse_setup ( const char *str )
sw->_token_match = script_token_match;
sw->_get_completion = NULL,
sw->_get_display_value = _get_display_value;
sw->_is_not_ascii = script_is_not_ascii;
return sw;
}

View file

@ -481,26 +481,11 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_
*
* @returns TRUE if matches
*/
static int ssh_token_match ( const Mode *sw, char **tokens, int not_ascii, int case_sensitive, unsigned int index )
static int ssh_token_match ( const Mode *sw, GRegex **tokens, unsigned int index )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
return token_match ( tokens, rmpd->hosts_list[index], not_ascii, case_sensitive );
return token_match ( tokens, rmpd->hosts_list[index] );
}
/**
* @param sw Object handle to the SSH Mode object
* @param index The index of the entry to match
*
* Check if the selected entry contains non-ascii symbols.
*
* @returns TRUE if string contains non-ascii symbols
*/
static int ssh_is_not_ascii ( const Mode *sw, unsigned int index )
{
SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw );
return !g_str_is_ascii ( rmpd->hosts_list[index] );
}
#include "mode-private.h"
Mode ssh_mode =
{
@ -513,7 +498,6 @@ Mode ssh_mode =
._token_match = ssh_token_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._is_not_ascii = ssh_is_not_ascii,
.private_data = NULL,
.free = NULL
};

View file

@ -319,9 +319,7 @@ typedef struct
char *cache;
} ModeModePrivateData;
static int window_match ( const Mode *sw, char **tokens,
__attribute__( ( unused ) ) int not_ascii,
int case_sensitive, unsigned int index )
static int window_match ( const Mode *sw, GRegex **tokens, unsigned int index )
{
ModeModePrivateData *rmpd = (ModeModePrivateData *) mode_get_private_data ( sw );
int match = 1;
@ -338,21 +336,21 @@ static int window_match ( const Mode *sw, char **tokens,
// Now we want it to match only one item at the time.
// If hack not in place it would not match queries spanning multiple fields.
// e.g. when searching 'title element' and 'class element'
char *ftokens[2] = { tokens[j], NULL };
GRegex *ftokens[2] = { tokens[j], NULL };
if ( !test && c->title != NULL && c->title[0] != '\0' ) {
test = token_match ( ftokens, c->title, not_ascii, case_sensitive );
test = token_match ( ftokens, c->title);
}
if ( !test && c->class != NULL && c->class[0] != '\0' ) {
test = token_match ( ftokens, c->class, not_ascii, case_sensitive );
test = token_match ( ftokens, c->class);
}
if ( !test && c->role != NULL && c->role[0] != '\0' ) {
test = token_match ( ftokens, c->role, not_ascii, case_sensitive );
test = token_match ( ftokens, c->role);
}
if ( !test && c->name != NULL && c->name[0] != '\0' ) {
test = token_match ( ftokens, c->name, not_ascii, case_sensitive );
test = token_match ( ftokens, c->name);
}
if ( test == 0 ) {
@ -655,25 +653,6 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
}
static int window_is_not_ascii ( const Mode *sw, unsigned int index )
{
const ModeModePrivateData *rmpd = mode_get_private_data ( sw );
const winlist *ids = ( winlist * ) rmpd->ids;
// Want to pull directly out of cache, X calls are not thread safe.
int idx = winlist_find ( cache_client, ids->array[index] );
g_assert ( idx >= 0 );
client *c = cache_client->data[idx];
if ( c->role && !g_str_is_ascii ( c->role ) ) {
return TRUE;
}
if ( c->class && !g_str_is_ascii ( c->class ) ) {
return TRUE;
}
if ( c->title && !g_str_is_ascii ( c->title ) ) {
return TRUE;
}
return FALSE;
}
#include "mode-private.h"
Mode window_mode =
@ -687,7 +666,6 @@ Mode window_mode =
._token_match = window_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._is_not_ascii = window_is_not_ascii,
.private_data = NULL,
.free = NULL
};
@ -702,7 +680,6 @@ Mode window_mode_cd =
._token_match = window_match,
._get_display_value = _get_display_value,
._get_completion = NULL,
._is_not_ascii = window_is_not_ascii,
.private_data = NULL,
.free = NULL
};

View file

@ -136,7 +136,7 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... )
return FALSE;
}
void tokenize_free ( char ** tokens )
void tokenize_free ( GRegex ** tokens )
{
for ( size_t i = 0; tokens && tokens[i]; i++ ) {
g_regex_unref ( (GRegex *) tokens[i] );
@ -194,17 +194,17 @@ static GRegex * create_regex ( const char *input, int case_sensitive )
}
return retv;
}
char **tokenize ( const char *input, int case_sensitive )
GRegex **tokenize ( const char *input, int case_sensitive )
{
if ( input == NULL || strlen(input) == 0 ) {
return NULL;
}
char *saveptr = NULL, *token;
char **retv = NULL;
GRegex **retv = NULL;
if ( !config.tokenize ) {
retv = g_malloc0 ( sizeof ( char* ) * 2 );
retv[0] = (char *) create_regex ( input, case_sensitive );
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
retv[0] = (GRegex *) create_regex ( input, case_sensitive );
return retv;
}
@ -218,8 +218,8 @@ char **tokenize ( const char *input, int case_sensitive )
// strtok should still be valid for utf8.
const char * const sep = " ";
for ( token = strtok_r ( str, sep, &saveptr ); token != NULL; token = strtok_r ( NULL, sep, &saveptr ) ) {
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
retv[num_tokens] = (char *) create_regex ( token, case_sensitive );
retv = g_realloc ( retv, sizeof ( GRegex* ) * ( num_tokens + 2 ) );
retv[num_tokens] = (GRegex*) create_regex ( token, case_sensitive );
retv[num_tokens + 1] = NULL;
num_tokens++;
}
@ -335,20 +335,8 @@ int find_arg_char ( const char * const key, char *val )
return FALSE;
}
static int regex_token_match ( char **tokens, const char *input, G_GNUC_UNUSED int not_ascii, G_GNUC_UNUSED int case_sensitive )
{
int match = 1;
// Do a tokenized match.
if ( tokens ) {
for ( int j = 0; match && tokens[j]; j++ ) {
match = g_regex_match ( (GRegex *) tokens[j], input, G_REGEX_MATCH_PARTIAL, NULL );
}
}
return match;
}
static PangoAttrList *regex_token_match_get_pango_attr ( char **tokens, const char *input, PangoAttrList *retv )
PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input, PangoAttrList *retv )
{
// Do a tokenized match.
if ( tokens ) {
@ -369,14 +357,17 @@ static PangoAttrList *regex_token_match_get_pango_attr ( char **tokens, const ch
}
return retv;
}
PangoAttrList *token_match_get_pango_attr ( char **tokens, const char *input, PangoAttrList *retv )
{
return regex_token_match_get_pango_attr ( tokens, input, retv );
}
int token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive )
int token_match ( GRegex **tokens, const char *input)
{
return regex_token_match ( tokens, input, not_ascii, case_sensitive );
int match = 1;
// Do a tokenized match.
if ( tokens ) {
for ( int j = 0; match && tokens[j]; j++ ) {
match = g_regex_match ( (GRegex *) tokens[j], input, G_REGEX_MATCH_PARTIAL, NULL );
}
}
return match;
}
int execute_generator ( const char * cmd )

View file

@ -57,12 +57,6 @@ char * mode_get_completion ( const Mode *mode, unsigned int selected_line )
}
}
int mode_is_not_ascii ( const Mode *mode, unsigned int selected_line )
{
g_assert ( mode != NULL );
g_assert ( mode->_is_not_ascii != NULL );
return mode->_is_not_ascii ( mode, selected_line );
}
ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int selected_line )
{
g_assert ( mode != NULL );
@ -71,11 +65,11 @@ ModeMode mode_result ( Mode *mode, int menu_retv, char **input, unsigned int sel
return mode->_result ( mode, menu_retv, input, selected_line );
}
int mode_token_match ( const Mode *mode, char **tokens, int not_ascii, int case_sensitive, unsigned int selected_line )
int mode_token_match ( const Mode *mode, GRegex **tokens, unsigned int selected_line )
{
g_assert ( mode != NULL );
g_assert ( mode->_token_match != NULL );
return mode->_token_match ( mode, tokens, not_ascii, case_sensitive, selected_line );
return mode->_token_match ( mode, tokens, selected_line );
}
const char *mode_get_name ( const Mode *mode )

View file

@ -301,7 +301,6 @@ void rofi_view_free ( RofiViewState *state )
g_free ( state->boxes );
g_free ( state->line_map );
g_free ( state->distance );
g_free ( state->lines_not_ascii );
// Free the switcher boxes.
// When state is free'ed we should no longer need these.
if ( config.sidebar_mode == TRUE ) {
@ -465,7 +464,7 @@ static RofiViewState * __rofi_view_state_create ( void )
typedef struct _thread_state
{
RofiViewState *state;
char **tokens;
GRegex **tokens;
unsigned int start;
unsigned int stop;
unsigned int count;
@ -494,8 +493,7 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data
{
// input changed
for ( unsigned int i = t->start; i < t->stop; i++ ) {
int match = mode_token_match ( t->state->sw, t->tokens, t->state->lines_not_ascii[i],
config.case_sensitive, i );
int match = mode_token_match ( t->state->sw, t->tokens, i );
// If each token was matched, add it to list.
if ( match ) {
t->state->line_map[t->start + t->count] = i;
@ -509,12 +507,6 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data
}
}
}
static void check_is_ascii ( thread_state *t, G_GNUC_UNUSED gpointer user_data )
{
for ( unsigned int i = t->start; i < t->stop; i++ ) {
t->state->lines_not_ascii[i] = mode_is_not_ascii ( t->state->sw, i );
}
}
static void rofi_view_setup_fake_transparency ( void )
{
@ -933,7 +925,7 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d )
int x_offset = state->border;
if ( state->rchanged ) {
char **tokens = tokenize ( state->text->text, config.case_sensitive );
GRegex **tokens = tokenize ( state->text->text, config.case_sensitive );
// Move, resize visible boxes and show them.
for ( i = 0; i < max_elements && ( i + offset ) < state->filtered_lines; i++ ) {
unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin );
@ -1256,7 +1248,7 @@ static void rofi_view_refilter ( RofiViewState *state )
TICK_N ( "Filter start" );
if ( strlen ( state->text->text ) > 0 ) {
unsigned int j = 0;
char **tokens = tokenize ( state->text->text, config.case_sensitive );
GRegex **tokens = tokenize ( state->text->text, config.case_sensitive );
/**
* On long lists it can be beneficial to parallelize.
* If number of threads is 1, no thread is spawn.
@ -1641,45 +1633,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
// Request the lines to show.
state->num_lines = mode_get_num_entries ( sw );
state->lines_not_ascii = g_malloc0_n ( state->num_lines, sizeof ( int ) );
// find out which lines contain non-ascii codepoints, so we can be faster in some cases.
if ( state->num_lines > 0 ) {
TICK_N ( "Is ASCII start" );
unsigned int nt = MAX ( 1, state->num_lines / 5000 );
thread_state states[nt];
unsigned int steps = ( state->num_lines + nt ) / nt;
unsigned int count = nt;
GCond cond;
GMutex mutex;
g_mutex_init ( &mutex );
g_cond_init ( &cond );
for ( unsigned int i = 0; i < nt; i++ ) {
states[i].state = state;
states[i].start = i * steps;
states[i].stop = MIN ( ( i + 1 ) * steps, state->num_lines );
states[i].acount = &count;
states[i].mutex = &mutex;
states[i].cond = &cond;
states[i].callback = check_is_ascii;
if ( i > 0 ) {
g_thread_pool_push ( tpool, &( states[i] ), NULL );
}
}
// Run one in this thread.
rofi_view_call_thread ( &( states[0] ), NULL );
// No need to do this with only one thread.
if ( nt > 1 ) {
g_mutex_lock ( &mutex );
while ( count > 0 ) {
g_cond_wait ( &cond, &mutex );
}
g_mutex_unlock ( &mutex );
}
g_cond_clear ( &cond );
g_mutex_clear ( &mutex );
TICK_N ( "Is ASCII stop" );
}
TICK_N ( "Startup notification" );
// Try to grab the keyboard as early as possible.