mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-02-06 10:34:55 +01:00
Add feature to show ~ instead of $HOME in title
This commit is contained in:
parent
d9e74bb152
commit
f1f65664da
3 changed files with 37 additions and 7 deletions
|
@ -224,6 +224,8 @@ config_load_default(zathura_t* zathura)
|
|||
bool_value = false;
|
||||
girara_setting_add(gsession, "window-title-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the window title"), NULL, NULL);
|
||||
bool_value = false;
|
||||
girara_setting_add(gsession, "window-title-home-tilde", &bool_value, BOOLEAN, false, _("Use ~ instead of $HOME in the filename in the window title"), NULL, NULL);
|
||||
bool_value = false;
|
||||
girara_setting_add(gsession, "window-title-page", &bool_value, BOOLEAN, false, _("Display the page number in the window title"), NULL, NULL);
|
||||
bool_value = false;
|
||||
girara_setting_add(gsession, "statusbar-basename", &bool_value, BOOLEAN, false, _("Use basename of the file in the statusbar"), NULL, NULL);
|
||||
|
|
|
@ -546,6 +546,38 @@ document_info_open(gpointer data)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
const char*
|
||||
get_window_title_filename(zathura_t* zathura, const char* file_path)
|
||||
{
|
||||
bool basename_only = false;
|
||||
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only);
|
||||
if (basename_only == false) {
|
||||
bool home_tilde = false;
|
||||
girara_setting_get(zathura->ui.session, "window-title-home-tilde", &home_tilde);
|
||||
if (home_tilde) {
|
||||
char *home = getenv("HOME");
|
||||
int home_len = home ? strlen(home) : 0;
|
||||
int file_path_len = file_path ? strlen(file_path) : 0;
|
||||
|
||||
if (home_len > 1 && strncmp(home, file_path, home_len) == 0 && (!file_path[home_len] || file_path[home_len] == '/')) {
|
||||
// Length should be total length of path - length of $HOME + 1 for '~' + 1 for '\0'
|
||||
int tlen = file_path_len - home_len + 2;
|
||||
char *tdir = malloc(sizeof(char) * tlen);
|
||||
strncpy(tdir + 1, file_path + home_len, tlen);
|
||||
tdir[0] = '~';
|
||||
tdir[tlen - 1] = '\0';
|
||||
return tdir;
|
||||
} else {
|
||||
return file_path;
|
||||
}
|
||||
} else {
|
||||
return file_path;
|
||||
}
|
||||
} else {
|
||||
return zathura_document_get_basename(zathura->document);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
document_open(zathura_t* zathura, const char* path, const char* password,
|
||||
int page_number)
|
||||
|
@ -838,13 +870,7 @@ document_open(zathura_t* zathura, const char* path, const char* password,
|
|||
}
|
||||
|
||||
/* update title */
|
||||
basename_only = false;
|
||||
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only);
|
||||
if (basename_only == false) {
|
||||
girara_set_window_title(zathura->ui.session, file_path);
|
||||
} else {
|
||||
girara_set_window_title(zathura->ui.session, zathura_document_get_basename(document));
|
||||
}
|
||||
girara_set_window_title(zathura->ui.session, get_window_title_filename(zathura, file_path));
|
||||
|
||||
g_free(file_uri);
|
||||
|
||||
|
|
|
@ -278,6 +278,8 @@ void zathura_set_plugin_dir(zathura_t* zathura, const char* dir);
|
|||
*/
|
||||
void zathura_set_argv(zathura_t* zathura, char** argv);
|
||||
|
||||
const char* get_window_title_filename(zathura_t* zathura, const char* file_path);
|
||||
|
||||
/**
|
||||
* Opens a file
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue