From 1222a2a99d9a159db1914bb63407ccf8e6c8fb66 Mon Sep 17 00:00:00 2001 From: Thomas Faughnan Date: Tue, 11 Jan 2022 08:28:58 -0500 Subject: [PATCH] Add option to display page number percent in statusbar --- doc/man/zathurarc.5.rst | 6 ++++++ zathura/config.c | 2 ++ zathura/zathura.c | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/man/zathurarc.5.rst b/doc/man/zathurarc.5.rst index bf519ae..1ee368f 100644 --- a/doc/man/zathurarc.5.rst +++ b/doc/man/zathurarc.5.rst @@ -856,6 +856,12 @@ zathura * Value type: Boolean * Default value: false +*statusbar-page-percent* + Display (current page / total pages) as a percent in the statusbar. + + * Value type: Boolean + * Default value: false + *statusbar-home-tilde* Display a short version of the file path, which replaces $HOME with ~, in the statusbar. diff --git a/zathura/config.c b/zathura/config.c index 08b610a..b3d0c93 100644 --- a/zathura/config.c +++ b/zathura/config.c @@ -283,6 +283,8 @@ config_load_default(zathura_t* zathura) 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); + bool_value = false; + girara_setting_add(gsession, "statusbar-page-percent", &bool_value, BOOLEAN, false, _("Display (current page / total pages) as a percent in the statusbar"), cb_window_statbusbar_changed, NULL); bool_value = true; girara_setting_add(gsession, "synctex", &bool_value, BOOLEAN, false, _("Enable synctex support"), NULL, NULL); girara_setting_add(gsession, "synctex-editor-command", "", STRING, false, _("Synctex editor command"), NULL, NULL); diff --git a/zathura/zathura.c b/zathura/zathura.c index 8f09128..b3222ce 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -1542,17 +1542,29 @@ statusbar_page_number_update(zathura_t* zathura) unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); unsigned int current_page_number = zathura_document_get_current_page_number(zathura->document); + unsigned int page_number_percent = number_of_pages ? 100 * (current_page_number + 1) / number_of_pages : 0; if (zathura->document != NULL) { zathura_page_t* page = zathura_document_get_page(zathura->document, current_page_number); char* page_label = zathura_page_get_label(page, NULL); + bool show_percent = false; + girara_setting_get(zathura->ui.session, "statusbar-page-percent", &show_percent); + char* page_number_text = NULL; if (page_label != NULL) { - page_number_text = g_strdup_printf("[%s (%d/%d)]", page_label, current_page_number + 1, number_of_pages); + if (show_percent) { + page_number_text = g_strdup_printf("[%s (%d/%d) (%d%%)]", page_label, current_page_number + 1, number_of_pages, page_number_percent); + } else { + page_number_text = g_strdup_printf("[%s (%d/%d)]", page_label, current_page_number + 1, number_of_pages); + } g_free(page_label); } else { - page_number_text = g_strdup_printf("[%d/%d]", current_page_number + 1, number_of_pages); + if (show_percent) { + page_number_text = g_strdup_printf("[%d/%d (%d%%)]", current_page_number + 1, number_of_pages, page_number_percent); + } else { + page_number_text = g_strdup_printf("[%d/%d]", current_page_number + 1, number_of_pages); + } } girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, page_number_text);