diff options
-rw-r--r-- | Changelog | 3 | ||||
-rw-r--r-- | doc/rofi-manpage.markdown | 8 | ||||
-rw-r--r-- | doc/rofi.1 | 8 | ||||
-rw-r--r-- | source/dialogs/dmenu.c | 75 | ||||
-rw-r--r-- | source/textbox.c | 14 |
5 files changed, 94 insertions, 14 deletions
@@ -3,8 +3,11 @@ - Number mode for dmenu. allows user to get index back instead of content. - Combi mode. Combine multiple views into one. - Highlight current window. + - Highlight urgent and active row in window view. + - DMenu allow rows to be highlighted. Bug fixes: - On a single item in list disable auto-select. + - Fix cursor position (#140) Improvements: - Add Ctrl(Shift)Tab to switch modi's. - Auto size number of columns based on available columns. diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index c1077a8e..39d1fb7e 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -400,10 +400,18 @@ daemon listening to specific key-combinations. `-a` *X* Active row, mark row X as active. (starting at 0) + You can specify single element: -a 3 + A range: -a 3-8 + or a set of rows: -a 0,2 + Or any combination: -a 0,2-3,9 `-u` *X* Urgent row, mark row X as urgent. (starting at 0) + You can specify single element: -u 3 + A range: -u 3-8 + or a set of rows: -u 0,2 + Or any combination: -u 0,2-3,9 ### Message dialog @@ -503,6 +503,10 @@ Number mode, return the index of the selected row. (starting at 0) .RS .nf Active row, mark row X as active. (starting at 0) +You can specify single element: \-a 3 +A range: \-a 3\-8 +or a set of rows: \-a 0,2 +Or any combination: \-a 0,2\-3,9 .fi .RE .PP @@ -511,6 +515,10 @@ Active row, mark row X as active. (starting at 0) .RS .nf Urgent row, mark row X as urgent. (starting at 0) +You can specify single element: \-u 3 +A range: \-u 3\-8 +or a set of rows: \-u 0,2 +Or any combination: \-u 0,2\-3,9 .fi .RE .SS Message dialog diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index b9e94564..5f72ebc3 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -64,18 +64,65 @@ static char **get_dmenu ( int *length ) return retv; } +struct range_pair +{ + unsigned int start; + unsigned int stop; +}; + +struct range_pair * urgent_list = NULL; +unsigned int num_urgent_list = 0; +struct range_pair * active_list = NULL; +unsigned int num_active_list = 0; -static unsigned int row_urgent = 0xFFFFFFFF; -static unsigned int row_active = 0xFFFFFFFF; +static void parse_pair ( char *input, struct range_pair *item ) +{ + int index = 0; + for ( char *token = strsep ( &input, "-" ); + token != NULL; + token = strsep ( &input, "-" ) ) { + if ( index == 0 ) { + item->start = item->stop = (unsigned int) strtoul ( token, NULL, 10 ); + index++; + } + else { + if ( token[0] == '\0' ) { + item->stop = 0xFFFFFFFF; + } + else{ + item->stop = (unsigned int) strtoul ( token, NULL, 10 ); + } + } + } +} + +static void parse_ranges ( char *input, struct range_pair **list, unsigned int *length ) +{ + char *endp; + for ( char *token = strtok_r ( input, ",", &endp ); + token != NULL; + token = strtok_r ( NULL, ",", &endp ) ) { + // Make space. + *list = g_realloc ( ( *list ), ( ( *length ) + 1 ) * sizeof ( struct range_pair ) ); + // Parse a single pair. + parse_pair ( token, &( ( *list )[*length] ) ); + + ( *length )++; + } +} static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNUSED int *state ) { char **retv = (char * *) data; - if ( index == row_urgent ) { - *state |= URGENT; + for ( unsigned int i = 0; i < num_active_list; i++ ) { + if ( index >= active_list[i].start && index <= active_list[i].stop ) { + *state |= ACTIVE; + } } - if ( index == row_active ) { - *state |= ACTIVE; + for ( unsigned int i = 0; i < num_urgent_list; i++ ) { + if ( index >= urgent_list[i].start && index <= urgent_list[i].stop ) { + *state |= URGENT; + } } return retv[index]; } @@ -97,8 +144,18 @@ int dmenu_switcher_dialog ( char **input ) // Check prompt find_arg_str ( "-p", &dmenu_prompt ); find_arg_int ( "-l", &selected_line ); - find_arg_uint ( "-u", &row_urgent ); - find_arg_uint ( "-a", &row_active ); + // Urgent. + char *str = NULL; + find_arg_str ( "-u", &str ); + if ( str != NULL ) { + parse_ranges ( str, &urgent_list, &num_urgent_list ); + } + // Active + str = NULL; + find_arg_str ( "-a", &str ); + if ( str != NULL ) { + parse_ranges ( str, &active_list, &num_active_list ); + } do { int mretv = menu ( list, length, input, dmenu_prompt, @@ -138,6 +195,8 @@ int dmenu_switcher_dialog ( char **input ) } while ( restart ); g_strfreev ( list ); + g_free ( urgent_list ); + g_free ( active_list ); return retv; } diff --git a/source/textbox.c b/source/textbox.c index 8a352104..5ca23533 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -147,18 +147,20 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft ) } if ( ( tbft & FMOD_MASK ) ) { if ( ( tbft & ACTIVE ) ) { - if(tbft&HIGHLIGHT) { + if ( tbft & HIGHLIGHT ) { tb->color_fg = color_hlfg; tb->color_bg = color_fg_active; - }else { + } + else { tb->color_fg = color_fg_active; } } else if ( ( tbft & URGENT ) ) { - if(tbft&HIGHLIGHT) { + if ( tbft & HIGHLIGHT ) { tb->color_fg = color_hlfg; tb->color_bg = color_fg_urgent; - }else { + } + else { tb->color_fg = color_fg_urgent; } } @@ -318,8 +320,8 @@ void textbox_draw ( textbox *tb ) // draw the cursor if ( tb->flags & TB_EDITABLE ) { XftDrawRect ( draw, &tb->color_fg, - x / PANGO_SCALE + cursor_x, y/PANGO_SCALE, // Align with font - cursor_width, font_height ); + x / PANGO_SCALE + cursor_x, y / PANGO_SCALE, // Align with font + cursor_width, font_height ); } // flip canvas to window |