From 9c18aaef22adda614c213e1ad18a4f2c96cb63cd Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 27 Jun 2022 17:09:21 +0200 Subject: [PATCH] [View] Add icon-current-entry widget. --- doc/rofi-theme.5 | 2 ++ doc/rofi-theme.5.markdown | 1 + include/view-internal.h | 1 + source/view.c | 37 ++++++++++++++++++++++++++----------- themes/sidebar-v2.rasi | 14 +++++++++++--- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index 360a74dd..cc7b18d5 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -1246,6 +1246,8 @@ The current widgets available in \fBrofi\fP: \fB\fCnum-filtered-rows\fR: Shows the total number of rows after filtering. .IP \(bu 2 \fB\fCtextbox-current-entry\fR: Shows the text of the currently selected entry. +.IP \(bu 2 +\fB\fCicon-current-entry\fR: Shows the icon of the currently selected entry. .RE diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index 48125bf5..3e6b8899 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -774,6 +774,7 @@ The current widgets available in **rofi**: * `num-rows`: Shows the total number of rows. * `num-filtered-rows`: Shows the total number of rows after filtering. * `textbox-current-entry`: Shows the text of the currently selected entry. + * `icon-current-entry`: Shows the icon of the currently selected entry. * `listview`: The listview. * `scrollbar`: the listview scrollbar * `element`: a box in the listview holding the entries diff --git a/include/view-internal.h b/include/view-internal.h index b942e4e1..28ab47f3 100644 --- a/include/view-internal.h +++ b/include/view-internal.h @@ -108,6 +108,7 @@ struct RofiViewState { textbox *tb_filtered_rows; textbox *tb_current_entry; + icon *icon_current_entry; /** Settings of the menu */ MenuFlags menu_flags; diff --git a/source/view.c b/source/view.c index 122010b6..18b8175d 100644 --- a/source/view.c +++ b/source/view.c @@ -1010,18 +1010,29 @@ inline static void rofi_view_nav_last(RofiViewState *state) { static void selection_changed_callback(listview *lv, unsigned int index, void *udata) { RofiViewState *state = (RofiViewState *)udata; - if (state->tb_current_entry == NULL) { - return; - } - if (index < state->filtered_lines) { - int fstate = 0; - char *text = mode_get_display_value(state->sw, state->line_map[index], - &fstate, NULL, TRUE); - textbox_text(state->tb_current_entry, text); - g_free(text); + if (state->tb_current_entry) { + if (index < state->filtered_lines) { + int fstate = 0; + char *text = mode_get_display_value(state->sw, state->line_map[index], + &fstate, NULL, TRUE); + textbox_text(state->tb_current_entry, text); + g_free(text); - } else { - textbox_text(state->tb_current_entry, ""); + } else { + textbox_text(state->tb_current_entry, ""); + } + } + if (state->icon_current_entry) { + if (index < state->filtered_lines) { + int icon_height = + widget_get_desired_height(WIDGET(state->icon_current_entry), + WIDGET(state->icon_current_entry)->w); + cairo_surface_t *icon = + mode_get_icon(state->sw, state->line_map[index], icon_height); + icon_set_surface(state->icon_current_entry, icon); + } else { + icon_set_surface(state->icon_current_entry, NULL); + } } } static void update_callback(textbox *t, icon *ico, unsigned int index, @@ -1898,6 +1909,10 @@ static void rofi_view_add_widget(RofiViewState *state, widget *parent_widget, TB_MARKUP | TB_AUTOHEIGHT, NORMAL, "", 0, 0); box_add((box *)parent_widget, WIDGET(state->tb_current_entry), FALSE); defaults = NULL; + } else if (strcmp(name, "icon-current-entry") == 0) { + state->icon_current_entry = icon_create(parent_widget, name); + box_add((box *)parent_widget, WIDGET(state->icon_current_entry), FALSE); + defaults = NULL; } /** * CASE INDICATOR diff --git a/themes/sidebar-v2.rasi b/themes/sidebar-v2.rasi index 05894d26..e0ee824a 100644 --- a/themes/sidebar-v2.rasi +++ b/themes/sidebar-v2.rasi @@ -63,7 +63,7 @@ textbox-current-entry { } element-icon { expand: true; - size: 20mm; + size: 10mm; vertial-align: 0.5; horizontal-align: 0.5; padding: 2mm; @@ -74,13 +74,21 @@ mainbox { expand: true; background-color: transparent; spacing: 5mm; - children: [ inputbar,textbox-current-entry, listview ]; + children: [ + inputbar, + listview, + icon-current-entry, + textbox-current-entry + ]; } +icon-current-entry { + size: 100mm; + } listview { padding: 0em; dynamic: false; lines: 0; - columns: 5; + columns: 8; flow: horizontal; } element selected normal {