From e6bed0e5d3b6585e9e19cf6dcf4b685981ff0b84 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 29 Dec 2019 19:04:29 +0100 Subject: [PATCH] [Listview] Add support for showing the (keybindable) index. fixes: #1050 --- doc/rofi-theme.5 | 2 ++ doc/rofi-theme.5.markdown | 1 + source/widgets/listview.c | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index 0a9229dc2..1cc74c94e 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -848,6 +848,8 @@ The current widgets available in \fBrofi\fP: .IP \(bu 2 \fB\fCelement\-icon\fR: the widget in the listview's entry showing the (optional) icon .IP \(bu 2 +\fB\fCelement\-index\fR: the widget in the listview's entry keybindable index (1,2,3..0) +.IP \(bu 2 \fB\fCelement\-text\fR: the widget in the listview's entry showing the text. .RE diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index 7512c11ae..86086824c 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -518,6 +518,7 @@ The current widgets available in **rofi**: * `scrollbar`: the listview scrollbar * `element`: a box in the listview holding the entries * `element-icon`: the widget in the listview's entry showing the (optional) icon + * `element-index`: the widget in the listview's entry keybindable index (1,2,3..0) * `element-text`: the widget in the listview's entry showing the text. * `mode-switcher`: the main horizontal @box packing the buttons. * `button`: the buttons @textbox for each mode diff --git a/source/widgets/listview.c b/source/widgets/listview.c index f71a284d6..ced5d8f24 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -63,6 +63,7 @@ typedef enum typedef struct { box *box; textbox *textbox; + textbox *index; icon *icon; } _listview_row; @@ -173,6 +174,7 @@ static void listview_create_row ( listview *lv, _listview_row *row ) row->textbox = NULL; row->icon = NULL; + row->index = NULL; for ( GList *iter = g_list_first(list); iter != NULL;iter = g_list_next(iter)){ if ( strcasecmp((char *)iter->data, "element-icon") == 0 ) { @@ -183,6 +185,9 @@ static void listview_create_row ( listview *lv, _listview_row *row ) } else if ( strcasecmp ((char *)iter->data, "element-text") == 0 ){ row->textbox= textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT|flags, NORMAL, "DDD", 0, 0 ); box_add ( row->box, WIDGET ( row->textbox ), TRUE); + } else if ( strcasecmp ( (char*)iter->data, "element-index" ) == 0 ){ + row->index= textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT|flags, NORMAL, " ", 0, 0 ); + box_add ( row->box, WIDGET ( row->index ), FALSE); } } g_list_free_full ( list, g_free ); @@ -192,7 +197,12 @@ static void listview_create_row ( listview *lv, _listview_row *row ) static void listview_set_state ( _listview_row r, TextBoxFontType type ) { listview_set_style ( WIDGET(r.box), type); - listview_set_style ( WIDGET(r.textbox), type); + if ( r.textbox ) { + listview_set_style ( WIDGET(r.textbox), type); + } + if ( r.index ) { + listview_set_style ( WIDGET(r.index), type); + } if ( r.icon ) { listview_set_style ( WIDGET(r.icon), type); } @@ -278,6 +288,15 @@ static void update_element ( listview *lv, unsigned int tb, unsigned int index, TextBoxFontType type = ( index & 1 ) == 0 ? NORMAL : ALT; type = ( index ) == lv->selected ? HIGHLIGHT : type; + if ( lv->boxes[tb].index ) { + if ( index < 10 ) { + char str[2] = "0"; + str[0] = ((index+1)%10)+'0'; + textbox_text( lv->boxes[tb].index, str ); + } else { + textbox_text( lv->boxes[tb].index, " " ); + } + } if ( lv->callback ) { lv->callback ( lv->boxes[tb].textbox, lv->boxes[tb].icon, index, lv->udata, &type, full ); listview_set_state ( lv->boxes[tb], type);