Commit 122ea70e authored by Moritz Lipp's avatar Moritz Lipp

Render last-viewed pages with a higher priority

parent 3986cbc0
......@@ -83,7 +83,8 @@ enum properties_e
PROP_SEARCH_RESULTS,
PROP_SEARCH_RESULTS_LENGTH,
PROP_SEARCH_RESULTS_CURRENT,
PROP_DRAW_SEACH_RESULTS
PROP_DRAW_SEACH_RESULTS,
PROP_LAST_VIEW,
};
static void
......@@ -129,6 +130,8 @@ zathura_page_widget_class_init(ZathuraPageClass* class)
g_param_spec_int("search-length", "search-length", "The number of search results", -1, INT_MAX, 0, G_PARAM_READABLE));
g_object_class_install_property(object_class, PROP_DRAW_SEACH_RESULTS,
g_param_spec_boolean("draw-search-results", "draw-search-results", "Set to true if search results should be drawn", FALSE, G_PARAM_WRITABLE));
g_object_class_install_property(object_class, PROP_LAST_VIEW,
g_param_spec_int("last-view", "last-view", "Last time the page has been viewed", -1, INT_MAX, 0, G_PARAM_READABLE));
}
static void
......@@ -289,6 +292,9 @@ zathura_page_widget_get_property(GObject* object, guint prop_id, GValue* value,
case PROP_SEARCH_RESULTS:
g_value_set_pointer(value, priv->search.list);
break;
case PROP_LAST_VIEW:
g_value_set_int(value, priv->last_view);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
......
......@@ -15,6 +15,7 @@
static void render_job(void* data, void* user_data);
static bool render(zathura_t* zathura, zathura_page_t* page);
static gint render_thread_sort(gconstpointer a, gconstpointer b, gpointer data);
struct render_thread_s
{
......@@ -46,6 +47,8 @@ render_init(zathura_t* zathura)
goto error_free;
}
g_thread_pool_set_sort_function(render_thread->pool, render_thread_sort, zathura);
return render_thread;
error_free:
......@@ -189,3 +192,32 @@ render_all(zathura_t* zathura)
gtk_widget_queue_resize(widget);
}
}
static gint
render_thread_sort(gconstpointer a, gconstpointer b, gpointer data)
{
if (a == NULL || b == NULL || data == NULL) {
return 0;
}
zathura_page_t* page_a = (zathura_page_t*) a;
zathura_page_t* page_b = (zathura_page_t*) b;
zathura_t* zathura = (zathura_t*) data;
unsigned int page_a_index = zathura_page_get_index(page_a);
unsigned int page_b_index = zathura_page_get_index(page_b);
unsigned int last_view_a = 0;
unsigned int last_view_b = 0;
g_object_get(zathura->pages[page_a_index], "last-view", &last_view_a, NULL);
g_object_get(zathura->pages[page_b_index], "last-view", &last_view_b, NULL);
if (last_view_a > last_view_b) {
return -1;
} else if (last_view_b > last_view_a) {
return 1;
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment