diff --git a/include/widgets/listview.h b/include/widgets/listview.h index 292118383..1b22dbf48 100644 --- a/include/widgets/listview.h +++ b/include/widgets/listview.h @@ -84,6 +84,13 @@ typedef void (*listview_selection_changed_callback)(listview *lv, */ typedef void (*listview_mouse_activated_cb)(listview *, gboolean, void *); + +/** + * Callback when current page is changed. + */ +typedef void (*listview_page_changed_cb)(void); + + /** * @param parent The widget's parent. * @param name The name of the to be created widget. @@ -95,7 +102,8 @@ typedef void (*listview_mouse_activated_cb)(listview *, gboolean, void *); * @returns a new listview */ listview *listview_create(widget *parent, const char *name, - listview_update_callback cb, void *udata, + listview_update_callback cb, + listview_page_changed_cb page_cb, void *udata, unsigned int eh, gboolean reverse); /** diff --git a/source/view.c b/source/view.c index a8039bf2d..5851f3661 100644 --- a/source/view.c +++ b/source/view.c @@ -1353,6 +1353,11 @@ static void update_callback(textbox *t, icon *ico, unsigned int index, textbox_font(t, *type); } } +static void page_changed_callback() +{ + rofi_view_workers_finalize(); + rofi_view_workers_initialize(); +} void rofi_view_update(RofiViewState *state, gboolean qr) { if (!widget_need_redraw(WIDGET(state->main_window))) { @@ -2354,7 +2359,8 @@ static void rofi_view_add_widget(RofiViewState *state, widget *parent_widget, return; } state->list_view = listview_create(parent_widget, name, update_callback, - state, config.element_height, 0); + page_changed_callback, state, + config.element_height, 0); listview_set_selection_changed_callback( state->list_view, selection_changed_callback, (void *)state); box_add((box *)parent_widget, WIDGET(state->list_view), TRUE); diff --git a/source/widgets/listview.c b/source/widgets/listview.c index f304f2382..957b9ce8f 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -120,6 +120,8 @@ struct _listview { xcb_timestamp_t last_click; listview_mouse_activated_cb mouse_activated; void *mouse_activated_data; + + listview_page_changed_cb page_callback; char *listview_name; @@ -285,8 +287,8 @@ static unsigned int scroll_per_page(listview *lv) { offset = page * lv->max_elements; if (page != lv->cur_page) { - rofi_view_workers_finalize(); - rofi_view_workers_initialize(); + if (lv->page_callback) + lv->page_callback(); lv->cur_page = page; lv->rchanged = TRUE; @@ -749,7 +751,8 @@ static gboolean listview_element_motion_notify(widget *wid, } listview *listview_create(widget *parent, const char *name, - listview_update_callback cb, void *udata, + listview_update_callback cb, + listview_page_changed_cb page_cb, void *udata, unsigned int eh, gboolean reverse) { listview *lv = g_malloc0(sizeof(listview)); widget_init(WIDGET(lv), parent, WIDGET_TYPE_LISTVIEW, name); @@ -786,6 +789,8 @@ listview *listview_create(widget *parent, const char *name, lv->callback = cb; lv->udata = udata; + lv->page_callback = page_cb; + // Some settings. lv->spacing = rofi_theme_get_distance(WIDGET(lv), "spacing", DEFAULT_SPACING); lv->menu_columns =