mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-27 14:16:01 +01:00
Add option to update window icon based on first page of a document (fixes pwmt/zathura#8)
This commit is contained in:
parent
448a7cb57d
commit
3d12dbc51f
5 changed files with 51 additions and 1 deletions
|
@ -1069,6 +1069,14 @@ Some features are disabled when using strict sandbox mode:
|
|||
|
||||
No feature regressions are expected when using normal sandbox mode.
|
||||
|
||||
window-icon-document
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
Defines whether the window document should be updated based on the first page of
|
||||
a dcument.
|
||||
|
||||
* Value type: Boolean
|
||||
* default value: false
|
||||
|
||||
SEE ALSO
|
||||
========
|
||||
|
||||
|
|
|
@ -758,3 +758,18 @@ cb_page_widget_scaled_button_release(ZathuraPage* page_widget, GdkEventButton* e
|
|||
synctex_edit(editor, page, event->x, event->y);
|
||||
g_free(editor);
|
||||
}
|
||||
|
||||
void
|
||||
cb_window_update_icon(ZathuraRenderRequest* GIRARA_UNUSED(request), cairo_surface_t* surface, void* data)
|
||||
{
|
||||
zathura_t* zathura = data;
|
||||
|
||||
girara_debug("updating window icon");
|
||||
GdkPixbuf* pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface));
|
||||
if (pixbuf == NULL) {
|
||||
girara_error("Unable to convert cairo surface to Gdk Pixbuf.");
|
||||
}
|
||||
|
||||
gtk_window_set_icon(GTK_WINDOW(zathura->ui.session->gtk.window), pixbuf);
|
||||
g_object_unref(pixbuf);
|
||||
}
|
||||
|
|
|
@ -273,6 +273,8 @@ config_load_default(zathura_t* zathura)
|
|||
bool_value = false;
|
||||
girara_setting_add(gsession, "window-title-page", &bool_value, BOOLEAN, false, _("Display the page number in the window title"), cb_window_statbusbar_changed, NULL);
|
||||
bool_value = false;
|
||||
girara_setting_add(gsession, "window-icon-document", &bool_value, BOOLEAN, false, _("Use first page of a document as window icon"), NULL, NULL);
|
||||
bool_value = false;
|
||||
girara_setting_add(gsession, "statusbar-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the statusbar"), cb_window_statbusbar_changed, NULL);
|
||||
bool_value = false;
|
||||
girara_setting_add(gsession, "statusbar-home-tilde", &bool_value, BOOLEAN, false, _("Use ~ instead of $HOME in the filename in the statusbar"), cb_window_statbusbar_changed, NULL);
|
||||
|
|
|
@ -650,7 +650,8 @@ zathura_set_argv(zathura_t* zathura, char** argv)
|
|||
}
|
||||
|
||||
static bool
|
||||
setup_renderer(zathura_t* zathura, zathura_document_t* document) {
|
||||
setup_renderer(zathura_t* zathura, zathura_document_t* document)
|
||||
{
|
||||
/* page cache size */
|
||||
int cache_size = 0;
|
||||
girara_setting_get(zathura->ui.session, "page-cache-size", &cache_size);
|
||||
|
@ -660,6 +661,7 @@ setup_renderer(zathura_t* zathura, zathura_document_t* document) {
|
|||
cache_size = ZATHURA_PAGE_CACHE_DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
girara_debug("starting renderer with cache size %d", cache_size);
|
||||
ZathuraRenderer* renderer = zathura_renderer_new(cache_size);
|
||||
if (renderer == NULL) {
|
||||
return false;
|
||||
|
@ -684,6 +686,18 @@ setup_renderer(zathura_t* zathura, zathura_document_t* document) {
|
|||
|
||||
zathura->sync.render_thread = renderer;
|
||||
|
||||
/* create render request to render window icon */
|
||||
bool window_icon = false;
|
||||
girara_setting_get(zathura->ui.session, "window-icon-document", &window_icon);
|
||||
if (window_icon == true) {
|
||||
girara_debug("starting render request for window icon");
|
||||
ZathuraRenderRequest* request = zathura_render_request_new(renderer, zathura_document_get_page(document, 0));
|
||||
g_signal_connect(request, "completed", G_CALLBACK(cb_window_update_icon), zathura);
|
||||
zathura_render_request_set_render_plain(request, true);
|
||||
zathura_render_request(request, 0);
|
||||
zathura->window_icon_render_request = request;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1351,8 +1365,17 @@ document_close(zathura_t* zathura, bool keep_monitor)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* reset window icon */
|
||||
if (zathura->ui.session != NULL && zathura->window_icon_render_request != NULL) {
|
||||
char* window_icon = NULL;
|
||||
girara_setting_get(zathura->ui.session, "window-icon", &window_icon);
|
||||
girara_setting_set(zathura->ui.session, "window-icon", window_icon);
|
||||
g_free(window_icon);
|
||||
}
|
||||
|
||||
/* stop rendering */
|
||||
zathura_renderer_stop(zathura->sync.render_thread);
|
||||
g_clear_object(&zathura->window_icon_render_request);
|
||||
|
||||
/* remove monitor */
|
||||
if (keep_monitor == false) {
|
||||
|
@ -1375,6 +1398,7 @@ document_close(zathura_t* zathura, bool keep_monitor)
|
|||
save_fileinfo_to_db(zathura);
|
||||
}
|
||||
|
||||
/* remove jump list */
|
||||
girara_list_iterator_free(zathura->jumplist.cur);
|
||||
zathura->jumplist.cur = NULL;
|
||||
girara_list_free(zathura->jumplist.list);
|
||||
|
|
|
@ -183,6 +183,7 @@ struct zathura_s
|
|||
GtkWidget** pages; /**< The page widgets */
|
||||
zathura_database_t* database; /**< The database */
|
||||
ZathuraDbus* dbus; /**< D-Bus service */
|
||||
ZathuraRenderRequest* window_icon_render_request; /**< Render request for window icon */
|
||||
|
||||
/**
|
||||
* File monitor
|
||||
|
|
Loading…
Reference in a new issue