summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/helper.h2
-rw-r--r--include/textbox.h4
-rw-r--r--source/helper.c23
-rw-r--r--source/textbox.c12
-rw-r--r--source/view.c10
5 files changed, 51 insertions, 0 deletions
diff --git a/include/helper.h b/include/helper.h
index de6f1097..93bbc022 100644
--- a/include/helper.h
+++ b/include/helper.h
@@ -2,6 +2,7 @@
#define ROFI_HELPER_H
#include "rofi.h"
+#include <pango/pango.h>
/**
* @defgroup HELPERS Helpers
*/
@@ -171,5 +172,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 *regex_token_match_get_pango_attr ( char **tokens, const char *input, PangoAttrList *retv );
/*@}*/
#endif // ROFI_HELPER_H
diff --git a/include/textbox.h b/include/textbox.h
index afadd9e4..c315f08a 100644
--- a/include/textbox.h
+++ b/include/textbox.h
@@ -225,6 +225,10 @@ void textbox_delete ( textbox *tb, int pos, int dlen );
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
int textbox_get_estimated_char_height ( void );
void textbox_set_pango_context ( PangoContext *p );
+void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list );
+PangoAttrList *textbox_get_pango_attributes ( textbox *tb );
+
+const char *textbox_get_visible_text ( textbox *tb );
/*@}*/
#endif //ROFI_TEXTBOX_H
diff --git a/source/helper.c b/source/helper.c
index a6767c0d..179a99ff 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -410,6 +410,29 @@ static int regex_token_match ( char **tokens, const char *input, G_GNUC_UNUSED i
return match;
}
+PangoAttrList *regex_token_match_get_pango_attr ( char **tokens, const char *input, PangoAttrList *retv )
+{
+ if ( config.regex == FALSE ) return retv;
+ // Do a tokenized match.
+ if ( tokens ) {
+ for ( int j = 0; tokens[j]; j++ ) {
+ GMatchInfo *gmi = NULL;
+ g_regex_match ( (GRegex *) tokens[j], input, G_REGEX_MATCH_PARTIAL, &gmi );
+ while ( g_match_info_matches ( gmi ) ) {
+ int start, end;
+ g_match_info_fetch_pos ( gmi, 0, &start, &end );
+ PangoAttribute *pa = pango_attr_underline_new ( PANGO_UNDERLINE_SINGLE );
+ pa->start_index = start;
+ pa->end_index = end;
+ pango_attr_list_insert ( retv, pa );
+ g_match_info_next ( gmi, NULL );
+ }
+ g_match_info_free ( gmi );
+ }
+ }
+ return retv;
+}
+
static int glob_token_match ( char **tokens, const char *input, int not_ascii, int case_sensitive )
{
int match = 1;
diff --git a/source/textbox.c b/source/textbox.c
index 3a27bf93..e58230ea 100644
--- a/source/textbox.c
+++ b/source/textbox.c
@@ -162,6 +162,18 @@ static void __textbox_update_pango_text ( textbox *tb )
pango_layout_set_text ( tb->layout, tb->text, -1 );
}
}
+const char *textbox_get_visible_text ( textbox *tb )
+{
+ return pango_layout_get_text ( tb->layout );
+}
+PangoAttrList *textbox_get_pango_attributes ( textbox *tb )
+{
+ return pango_layout_get_attributes ( tb->layout );
+}
+void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list )
+{
+ pango_layout_set_attributes ( tb->layout, list );
+}
// set the default text to display
void textbox_text ( textbox *tb, const char *text )
diff --git a/source/view.c b/source/view.c
index 320a5db2..de9b00cf 100644
--- a/source/view.c
+++ b/source/view.c
@@ -933,6 +933,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 );
// 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 );
@@ -946,10 +947,19 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d )
TextBoxFontType tbft = fstate | ( ( i + offset ) == state->selected ? HIGHLIGHT : type );
textbox_font ( state->boxes[i], tbft );
textbox_text ( state->boxes[i], text );
+
+ PangoAttrList *list = textbox_get_pango_attributes ( state->boxes[i] );
+ if ( list != NULL )
+ pango_attr_list_ref ( list );
+ else list = pango_attr_list_new ();
+ regex_token_match_get_pango_attr ( tokens, textbox_get_visible_text ( state->boxes[i] ), list );
+ textbox_set_pango_attributes ( state->boxes[i], list );
+ pango_attr_list_unref ( list );
g_free ( text );
}
textbox_draw ( state->boxes[i], d );
}
+ tokenize_free ( tokens );
state->rchanged = FALSE;
}
else{