summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-05-22 17:47:34 +0200
committerDave Davenport <qball@gmpclient.org>2016-05-22 17:47:34 +0200
commit498fadc735df509ef0a864db1e93d2120d8eb9ee (patch)
tree8d322b8736c615cc0ba51c9b40ad30d3a9668480 /source
parent8091558ed8234914b398fe288aaccfe9770dac9c (diff)
Remove the is_ascii mess.
Diffstat (limited to 'source')
-rw-r--r--source/dialogs/combi.c21
-rw-r--r--source/dialogs/dmenu.c23
-rw-r--r--source/dialogs/drun.c25
-rw-r--r--source/dialogs/run.c11
-rw-r--r--source/dialogs/script.c11
-rw-r--r--source/dialogs/ssh.c20
-rw-r--r--source/dialogs/window.c35
-rw-r--r--source/helper.c43
-rw-r--r--source/mode.c10
-rw-r--r--source/view.c54
10 files changed, 53 insertions, 200 deletions
diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c
index 5ab58940..89c634b8 100644
--- a/source/dialogs/combi.c
+++ b/source/dialogs/combi.c
@@ -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
};
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c
index 56f397bf..4d4cdbbc 100644
--- a/source/dialogs/dmenu.c
+++ b/source/dialogs/dmenu.c
@@ -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
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c
index 5f063701..39fee13f 100644
--- a/source/dialogs/drun.c
+++ b/source/dialogs/drun.c
@@ -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
};
diff --git a/source/dialogs/run.c b/source/dialogs/run.c
index 00dae3fe..51db25d9 100644
--- a/source/dialogs/run.c
+++ b/source/dialogs/run.c
@@ -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
};
diff --git a/source/dialogs/script.c b/source/dialogs/script.c
index 92f9129b..3abb2aba 100644
--- a/source/dialogs/script.c
+++ b/source/dialogs/script.c
@@ -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;
}
diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c
index 95bcd080..3bf38f8e 100644
--- a/source/dialogs/ssh.c
+++ b/source/dialogs/ssh.c
@@ -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
};
diff --git a/source/dialogs/window.c b/source/dialogs/window.c
index f228cbf7..a2918bb7 100644
--- a/source/dialogs/window.c
+++ b/source/dialogs/window.c
@@ -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
};
diff --git a/source/helper.c b/source/helper.c
index 3d36b538..1897516f 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -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 )
diff --git a/source/mode.c b/source/mode.c
index 2e5b1969..216e0148 100644
--- a/source/mode.c
+++ b/source/mode.c
@@ -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 )
diff --git a/source/view.c b/source/view.c
index 2c98b972..1114c923 100644
--- a/source/view.c
+++ b/source/view.c
@@ -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.