Merge branch 'page-percent' into 'develop'

Add option to display page number percent in statusbar

See merge request pwmt/zathura!48
This commit is contained in:
Sebastian Ramacher 2022-01-11 17:38:01 +00:00
commit 35e41f94aa
3 changed files with 22 additions and 2 deletions

View File

@ -856,6 +856,12 @@ zathura
* Value type: Boolean * Value type: Boolean
* Default value: false * 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* *statusbar-home-tilde*
Display a short version of the file path, which replaces $HOME with ~, in the statusbar. Display a short version of the file path, which replaces $HOME with ~, in the statusbar.

View File

@ -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); 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; 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); 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; bool_value = true;
girara_setting_add(gsession, "synctex", &bool_value, BOOLEAN, false, _("Enable synctex support"), NULL, NULL); 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); girara_setting_add(gsession, "synctex-editor-command", "", STRING, false, _("Synctex editor command"), NULL, NULL);

View File

@ -1542,18 +1542,30 @@ statusbar_page_number_update(zathura_t* zathura)
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); 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 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) { if (zathura->document != NULL) {
zathura_page_t* page = zathura_document_get_page(zathura->document, current_page_number); zathura_page_t* page = zathura_document_get_page(zathura->document, current_page_number);
char* page_label = zathura_page_get_label(page, NULL); 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; char* page_number_text = NULL;
if (page_label != NULL) { if (page_label != NULL) {
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); page_number_text = g_strdup_printf("[%s (%d/%d)]", page_label, current_page_number + 1, number_of_pages);
}
g_free(page_label); g_free(page_label);
} else {
if (show_percent) {
page_number_text = g_strdup_printf("[%d/%d (%d%%)]", current_page_number + 1, number_of_pages, page_number_percent);
} else { } else {
page_number_text = g_strdup_printf("[%d/%d]", current_page_number + 1, number_of_pages); 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); girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, page_number_text);
bool page_number_in_window_title = false; bool page_number_in_window_title = false;