diff --git a/doc/man/zathurarc.5.rst b/doc/man/zathurarc.5.rst index 0b7d3a4c22cdf518fbe6a557efa1e200068b0c90..3b20b2717ecc38e06f6903edbde8617f339132d1 100644 --- a/doc/man/zathurarc.5.rst +++ b/doc/man/zathurarc.5.rst @@ -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 ======== diff --git a/zathura/callbacks.c b/zathura/callbacks.c index 04cd268ddc32b955f8c7c0c421f3ce814e87184d..2e814f68af00da7dd05ae4a0aa9089b75ae8ddbd 100644 --- a/zathura/callbacks.c +++ b/zathura/callbacks.c @@ -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); +} diff --git a/zathura/config.c b/zathura/config.c index dc17b3ee463e6bbe97df59acd91758a0ff5423f7..db5f39b33d15c512ff46b906e3a081e11003df19 100644 --- a/zathura/config.c +++ b/zathura/config.c @@ -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); diff --git a/zathura/zathura.c b/zathura/zathura.c index bba38f33a927d7db0a0f2314cd26df9e5d52b304..1d3b38bb541f118b1bc14d056c2c3464e86a8b8b 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -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); diff --git a/zathura/zathura.h b/zathura/zathura.h index 014e7554cd23607cd77c7ef147bfd4e186755cf5..6d8fc505c845b9ad08d48370dced0f2eb1b145e0 100644 --- a/zathura/zathura.h +++ b/zathura/zathura.h @@ -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