mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-08 14:35:59 +01:00
Specify configuration directory
With this commit it is possible to pass the path to an configuration directory. Thanks to Sebastinas Other changes: * Updated Makefile * Update Manpage
This commit is contained in:
parent
98bf13102c
commit
b541f617ae
4 changed files with 46 additions and 17 deletions
3
Makefile
3
Makefile
|
@ -44,6 +44,9 @@ clean:
|
||||||
@rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
|
@rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
|
||||||
${DOBJECTS} ${PROJECT}-debug
|
${DOBJECTS} ${PROJECT}-debug
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
@rm -rf config.h
|
||||||
|
|
||||||
${PROJECT}-debug: ${DOBJECTS}
|
${PROJECT}-debug: ${DOBJECTS}
|
||||||
@echo CC -o ${PROJECT}-debug
|
@echo CC -o ${PROJECT}-debug
|
||||||
@${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS}
|
@${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS}
|
||||||
|
|
|
@ -14,10 +14,10 @@ static const char FORMAT_COMMAND[] = "<b>%s</b>";
|
||||||
static const char FORMAT_DESCRIPTION[] = "<i>%s</i>";
|
static const char FORMAT_DESCRIPTION[] = "<i>%s</i>";
|
||||||
|
|
||||||
/* directories and files */
|
/* directories and files */
|
||||||
static const char ZATHURA_DIR[] = ".config/zathura";
|
|
||||||
static const char BOOKMARK_FILE[] = "bookmarks";
|
static const char BOOKMARK_FILE[] = "bookmarks";
|
||||||
static const char ZATHURA_RC[] = "zathurarc";
|
static const char ZATHURA_RC[] = "zathurarc";
|
||||||
static const char GLOBAL_RC[] = "/etc/zathurarc";
|
static const char GLOBAL_RC[] = "/etc/zathurarc";
|
||||||
|
char* zathura_dir = "~/.config/zathura";
|
||||||
|
|
||||||
/* bookmarks */
|
/* bookmarks */
|
||||||
static const char BM_PAGE_ENTRY[] = "page";
|
static const char BM_PAGE_ENTRY[] = "page";
|
||||||
|
|
|
@ -4,6 +4,7 @@ zathura \- a PDF viewer
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B zathura
|
.B zathura
|
||||||
.RB [-e\ xid]
|
.RB [-e\ xid]
|
||||||
|
.RB [-c\ path]
|
||||||
.RB [file]
|
.RB [file]
|
||||||
.RB [password]
|
.RB [password]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
|
@ -14,6 +15,8 @@ space saving interface, with a focus on keyboard interaction.
|
||||||
.TP
|
.TP
|
||||||
.B -e xid
|
.B -e xid
|
||||||
Reparents to window specified by xid.
|
Reparents to window specified by xid.
|
||||||
|
.B -c path
|
||||||
|
Path to the config directory
|
||||||
.SH DEFAULT SETTINGS
|
.SH DEFAULT SETTINGS
|
||||||
.SS Shortcuts
|
.SS Shortcuts
|
||||||
.TP
|
.TP
|
||||||
|
|
55
zathura.c
55
zathura.c
|
@ -351,12 +351,14 @@ gboolean open_file(char*, char*);
|
||||||
void open_uri(char*);
|
void open_uri(char*);
|
||||||
void out_of_memory();
|
void out_of_memory();
|
||||||
void update_status();
|
void update_status();
|
||||||
|
void read_configuration_file(const char*);
|
||||||
void read_configuration();
|
void read_configuration();
|
||||||
void recalcRectangle(int, PopplerRectangle*);
|
void recalcRectangle(int, PopplerRectangle*);
|
||||||
void setCompletionRowColor(GtkBox*, int, int);
|
void setCompletionRowColor(GtkBox*, int, int);
|
||||||
void set_page(int);
|
void set_page(int);
|
||||||
void switch_view(GtkWidget*);
|
void switch_view(GtkWidget*);
|
||||||
GtkEventBox* createCompletionRow(GtkBox*, char*, char*, gboolean);
|
GtkEventBox* createCompletionRow(GtkBox*, char*, char*, gboolean);
|
||||||
|
char* fix_path(const char*);
|
||||||
|
|
||||||
Completion* completion_init();
|
Completion* completion_init();
|
||||||
CompletionGroup* completion_group_create(char*);
|
CompletionGroup* completion_group_create(char*);
|
||||||
|
@ -512,17 +514,28 @@ init_look()
|
||||||
gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar));
|
gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
fix_path(const char* path)
|
||||||
|
{
|
||||||
|
if (!path)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (path[0] == '~')
|
||||||
|
return g_build_filename(g_get_home_dir(), path + 1, NULL);
|
||||||
|
else
|
||||||
|
return g_strdup(path);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_directories()
|
init_directories()
|
||||||
{
|
{
|
||||||
/* create zathura directory */
|
/* create zathura directory */
|
||||||
gchar *base_directory = g_build_filename(g_get_home_dir(), ZATHURA_DIR, NULL);
|
gchar *base_directory = fix_path(zathura_dir);
|
||||||
g_mkdir_with_parents(base_directory, 0771);
|
g_mkdir_with_parents(base_directory, 0771);
|
||||||
g_free(base_directory);
|
|
||||||
|
|
||||||
/* create or open existing bookmark file */
|
/* create or open existing bookmark file */
|
||||||
Zathura.Bookmarks.data = g_key_file_new();
|
Zathura.Bookmarks.data = g_key_file_new();
|
||||||
char* bookmarks = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, BOOKMARK_FILE);
|
char* bookmarks = g_build_filename(base_directory, BOOKMARK_FILE, NULL);
|
||||||
|
|
||||||
if(!g_file_test(bookmarks, G_FILE_TEST_IS_REGULAR))
|
if(!g_file_test(bookmarks, G_FILE_TEST_IS_REGULAR))
|
||||||
{
|
{
|
||||||
|
@ -541,6 +554,7 @@ init_directories()
|
||||||
|
|
||||||
Zathura.Bookmarks.file = g_strdup(bookmarks);
|
Zathura.Bookmarks.file = g_strdup(bookmarks);
|
||||||
g_free(bookmarks);
|
g_free(bookmarks);
|
||||||
|
g_free(base_directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1405,10 +1419,12 @@ read_configuration_file(const char* rcfile)
|
||||||
void
|
void
|
||||||
read_configuration()
|
read_configuration()
|
||||||
{
|
{
|
||||||
char* zathurarc = g_strdup_printf("%s/%s/%s", g_get_home_dir(), ZATHURA_DIR, ZATHURA_RC);
|
char* configpath = fix_path(zathura_dir);
|
||||||
|
char* zathurarc = g_build_filename(configpath, ZATHURA_RC, NULL);
|
||||||
read_configuration_file(GLOBAL_RC);
|
read_configuration_file(GLOBAL_RC);
|
||||||
read_configuration_file(zathurarc);
|
read_configuration_file(zathurarc);
|
||||||
g_free(zathurarc);
|
g_free(zathurarc);
|
||||||
|
g_free(configpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -4288,18 +4304,25 @@ int main(int argc, char* argv[])
|
||||||
/* embed */
|
/* embed */
|
||||||
Zathura.UI.embed = 0;
|
Zathura.UI.embed = 0;
|
||||||
|
|
||||||
/* parse arguments */
|
static GOptionEntry entries[] =
|
||||||
int i;
|
|
||||||
for(i = 1; i < argc && argv[i][0] == '-' && argv[i][1] != '\0'; i++)
|
|
||||||
{
|
{
|
||||||
switch(argv[i][1])
|
{ "reparent", 'e', 0 , G_OPTION_ARG_INT, &Zathura.UI.embed, "Reparents to window specified by xid", "xid" },
|
||||||
{
|
{ "config-dir", 'c', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_STRING, &zathura_dir, "Path to the config directory", "path " },
|
||||||
case 'e':
|
{ NULL }
|
||||||
if(++i < argc)
|
};
|
||||||
Zathura.UI.embed = atoi(argv[i]);
|
|
||||||
break;
|
GOptionContext* context = g_option_context_new(" [file] [password]");
|
||||||
}
|
g_option_context_add_main_entries(context, entries, NULL);
|
||||||
|
|
||||||
|
GError* error = NULL;
|
||||||
|
if(!g_option_context_parse(context, &argc, &argv, &error))
|
||||||
|
{
|
||||||
|
printf("Error parsing command line arguments: %s\n", error->message);
|
||||||
|
g_option_context_free(context);
|
||||||
|
g_error_free(error);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
g_option_context_free(context);
|
||||||
|
|
||||||
g_thread_init(NULL);
|
g_thread_init(NULL);
|
||||||
gdk_threads_init();
|
gdk_threads_init();
|
||||||
|
@ -4313,8 +4336,8 @@ int main(int argc, char* argv[])
|
||||||
init_look();
|
init_look();
|
||||||
init_directories();
|
init_directories();
|
||||||
|
|
||||||
if(argc >= i+1)
|
if(argc > 1)
|
||||||
open_file(argv[i], (argc == i+2) ? argv[i+1] : NULL);
|
open_file(argv[1], (argc == 3) ? argv[2] : NULL);
|
||||||
|
|
||||||
switch_view(Zathura.UI.document);
|
switch_view(Zathura.UI.document);
|
||||||
update_status();
|
update_status();
|
||||||
|
|
Loading…
Reference in a new issue