Skip to content

Commit

Permalink
added listview page_changed_callback; rebuild icon fetcher threadpool…
Browse files Browse the repository at this point in the history
… in page_changed_callback
  • Loading branch information
giomatfois62 committed Mar 9, 2024
1 parent b179ff0 commit 58ff766
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 9 additions & 1 deletion include/widgets/listview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);

/**
Expand Down
8 changes: 7 additions & 1 deletion source/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions source/widgets/listview.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 58ff766

Please sign in to comment.