diff --git a/.gitignore b/.gitignore index cf9af95..fa31ebb 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ zathura.pc *.gcno *.gcda gcov/ +*.swp diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..d408fa8 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,12 @@ +zathura is written by: + +Moritz Lipp +Sebastian Ramacher + +Other contributors are (in alphabetical order): + +Pavel Borzenkov +Ivan Sichmann Freitas +int3 +karottenreibe +Johannes Meng diff --git a/LICENSE b/LICENSE index 2684cf7..7d84c04 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-2011 pwmt.org +Copyright (c) 2009-2012 pwmt.org This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/Makefile b/Makefile index 48949a2..5755c1e 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,8 @@ ${PROJECT}.pc: ${PROJECT}.pc.in config.mk $(QUIET)echo project=${PROJECT} > ${PROJECT}.pc $(QUIET)echo version=${VERSION} >> ${PROJECT}.pc $(QUIET)echo includedir=${PREFIX}/include >> ${PROJECT}.pc + $(QUIET)echo plugindir=${PLUGINDIR} >> ${PROJECT}.pc + $(QUIET)echo GTK_VERSION=${ZATHURA_GTK_VERSION} >> ${PROJECT}.pc $(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc valgrind: debug @@ -72,19 +74,22 @@ valgrind: debug gdb: debug cgdb ${PROJECT}-debug -tests: ${OBJECTS} - $(QUIET)make -C tests +test: ${OBJECTS} + $(QUIET)make -C tests run dist: clean $(QUIET)mkdir -p ${PROJECT}-${VERSION} - $(QUIET)cp -R LICENSE Makefile config.mk common.mk README Doxyfile \ - ${PROJECT}.1 ${SOURCE} ${HEADER} ${PROJECT}.pc.in tests \ + $(QUIET)mkdir -p ${PROJECT}-${VERSION}/tests + $(QUIET)cp LICENSE Makefile config.mk common.mk README AUTHORS Doxyfile \ + ${PROJECT}.1.rst ${PROJECT}rc.5.rst ${SOURCE} ${HEADER} ${PROJECT}.pc.in \ ${PROJECT}-${VERSION} + $(QUIET)cp Makefile config.mk tests/*.c \ + ${PROJECT}-${VERSION}/tests $(QUIET)tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION} $(QUIET)gzip ${PROJECT}-${VERSION}.tar $(QUIET)rm -rf ${PROJECT}-${VERSION} -doc: clean +doc: $(QUIET)doxygen Doxyfile gcov: clean @@ -103,10 +108,15 @@ install: all ${PROJECT}.pc $(QUIET)cp -f zathura.h ${DESTDIR}${PREFIX}/include/${PROJECT} $(ECHO) installing manual pages $(QUIET)mkdir -p ${DESTDIR}${MANPREFIX}/man1 - $(QUIET)sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 $(QUIET)if which rst2man > /dev/null ; then \ + mkdir -p ${DESTDIR}${MANPREFIX}/man1 ; \ + sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1.rst > ${PROJECT}-v.1.rst ; \ + rst2man ${PROJECT}-v.1.rst > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 ; \ + rm -f ${PROJECT}-v.1.rst ; \ mkdir -p ${DESTDIR}${MANPREFIX}/man5 ; \ - rst2man ${PROJECT}rc.5.rst > ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5 ; \ + sed "s/VERSION/${VERSION}/g" < ${PROJECT}rc.5.rst > ${PROJECT}rc-v.5.rst ; \ + rst2man ${PROJECT}rc-v.5.rst > ${DESTDIR}${MANPREFIX}/man5/${PROJECT}rc.5 ; \ + rm -f ${PROJECT}rc-v.5.rst ; \ fi $(QUIET)mkdir -p ${DESTDIR}${DESKTOPPREFIX} $(ECHO) installing desktop file @@ -131,4 +141,4 @@ uninstall: -include $(wildcard .depend/*.dep) -.PHONY: all options clean doc debug valgrind gdb dist doc install uninstall tests +.PHONY: all options clean doc debug valgrind gdb dist doc install uninstall test diff --git a/bookmarks.c b/bookmarks.c index e0a90ed..5fc94d5 100644 --- a/bookmarks.c +++ b/bookmarks.c @@ -32,8 +32,9 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page) bookmark->id = g_strdup(id); bookmark->page = page; girara_list_append(zathura->bookmarks.bookmarks, bookmark); - if (zathura->database) { - if (!zathura_db_add_bookmark(zathura->database, zathura->document->file_path, bookmark)) { + + if (zathura->database != NULL) { + if (zathura_db_add_bookmark(zathura->database, zathura->document->file_path, bookmark) == false) { girara_warning("Failed to add bookmark to database."); } } @@ -48,15 +49,16 @@ zathura_bookmark_remove(zathura_t* zathura, const gchar* id) g_return_val_if_fail(id, false); zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, id); - if (!bookmark) { + if (bookmark == NULL) { return false; } - if (zathura->database) { - if (!zathura_db_remove_bookmark(zathura->database, zathura->document->file_path, bookmark->id)) { + if (zathura->database != NULL) { + if (zathura_db_remove_bookmark(zathura->database, zathura->document->file_path, bookmark->id) == false) { girara_warning("Failed to remove bookmark from database."); } } + girara_list_remove(zathura->bookmarks.bookmarks, bookmark); return true; @@ -74,7 +76,7 @@ zathura_bookmark_get(zathura_t* zathura, const gchar* id) void zathura_bookmark_free(zathura_bookmark_t* bookmark) { - if (!bookmark) { + if (bookmark == NULL) { return; } @@ -86,17 +88,19 @@ bool zathura_bookmarks_load(zathura_t* zathura, const gchar* file) { g_return_val_if_fail(zathura, false); g_return_val_if_fail(file, false); + if (zathura->database == NULL) { return false; } girara_list_t* bookmarks = zathura_db_load_bookmarks(zathura->database, file); - if (!bookmarks) { + if (bookmarks == NULL) { return false; } girara_list_free(zathura->bookmarks.bookmarks); zathura->bookmarks.bookmarks = bookmarks; + return true; } @@ -106,9 +110,11 @@ zathura_bookmarks_compare(zathura_bookmark_t* lhs, zathura_bookmark_t* rhs) if (lhs == NULL && rhs == NULL) { return 0; } + if (lhs == NULL) { return -1; } + if (rhs == NULL) { return 1; } diff --git a/callbacks.c b/callbacks.c index 1ad6b7c..b0c6d57 100644 --- a/callbacks.c +++ b/callbacks.c @@ -97,18 +97,25 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi } void -cb_pages_per_row_value_changed(girara_session_t* UNUSED(session), const char* UNUSED(name), girara_setting_type_t UNUSED(type), void* value, void* data) +cb_pages_per_row_value_changed(girara_session_t* session, const char* UNUSED(name), girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) { g_return_if_fail(value != NULL); + g_return_if_fail(session != NULL); + g_return_if_fail(session->global.data != NULL); + zathura_t* zathura = session->global.data; int pages_per_row = *(int*) value; - zathura_t* zathura = data; if (pages_per_row < 1) { pages_per_row = 1; } page_widget_set_mode(zathura, pages_per_row); + + if (zathura->document != NULL) { + unsigned int current_page = zathura->document->current_page_number; + page_set_delayed(zathura, current_page); + } } void @@ -214,11 +221,16 @@ cb_file_monitor(GFileMonitor* monitor, GFile* file, GFile* UNUSED(other_file), G g_return_if_fail(file != NULL); g_return_if_fail(session != NULL); - if (event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { - return; + switch (event) { + case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: + case G_FILE_MONITOR_EVENT_CREATED: + gdk_threads_enter(); + sc_reload(session, NULL, NULL, 0); + gdk_threads_leave(); + break; + default: + return; } - - sc_reload(session, NULL, NULL, 0); } static gboolean @@ -256,13 +268,13 @@ cb_password_dialog(GtkEntry* entry, zathura_password_dialog_info_t* dialog) g_free(input); } - g_idle_add(password_dialog, dialog); + gdk_threads_add_idle(password_dialog, dialog); return false; } /* try to open document again */ if (document_open(dialog->zathura, dialog->path, input) == false) { - g_idle_add(password_dialog, dialog); + gdk_threads_add_idle(password_dialog, dialog); } else { g_free(dialog->path); free(dialog); @@ -283,14 +295,22 @@ error_ret: } bool -cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* UNUSED(allocation), zathura_t* zathura) +cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* allocation, zathura_t* zathura) { if (zathura == NULL || zathura->document == NULL) { return false; } - girara_argument_t argument = { zathura->document->adjust_mode, NULL }; - sc_adjust_window(zathura->ui.session, &argument, NULL, 0); + static int height = -1; + static int width = -1; - return true; + /* adjust only if the allocation changed */ + if (width != allocation->width || height != allocation->height) { + girara_argument_t argument = { zathura->document->adjust_mode, NULL }; + sc_adjust_window(zathura->ui.session, &argument, NULL, 0); + width = allocation->width; + height = allocation->height; + } + + return false; } diff --git a/commands.c b/commands.c index 7455326..c68ce7e 100644 --- a/commands.c +++ b/commands.c @@ -116,7 +116,7 @@ cmd_close(girara_session_t* session, girara_list_t* UNUSED(argument_list)) return true; } - document_close(zathura); + document_close(zathura, false); return true; } @@ -157,11 +157,6 @@ cmd_info(girara_session_t* session, girara_list_t* UNUSED(argument_list)) char* tmp = zathura_document_meta_get(zathura->document, meta_fields[i].field, NULL); if (tmp != NULL) { char* text = g_strdup_printf("%s: %s\n", meta_fields[i].name, tmp); - if (text == NULL) { - g_free(tmp); - return true; - } - g_string_append(string, text); g_free(text); @@ -198,8 +193,8 @@ cmd_open(girara_session_t* session, girara_list_t* argument_list) girara_notify(session, GIRARA_ERROR, "Too many arguments."); return false; } else if (argc >= 1) { - if (zathura->document) { - document_close(zathura); + if (zathura->document != NULL) { + document_close(zathura, false); } document_open(zathura, girara_list_nth(argument_list, 0), (argc == 2) ? girara_list_nth(argument_list, 1) : NULL); @@ -286,6 +281,8 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu } bool firsthit = true; + zathura_plugin_error_t error = ZATHURA_PLUGIN_ERROR_OK; + for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; ++page_id) { zathura_page_t* page = zathura->document->pages[(page_id + zathura->document->current_page_number) % zathura->document->number_of_pages]; if (page == NULL) { @@ -294,11 +291,16 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu g_object_set(page->drawing_area, "draw-links", FALSE, NULL); - girara_list_t* result = zathura_page_search_text(page, input, NULL); + girara_list_t* result = zathura_page_search_text(page, input, &error); if (result == NULL || girara_list_size(result) == 0) { girara_list_free(result); g_object_set(page->drawing_area, "search-results", NULL, NULL); - continue; + + if (error == ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED) { + break; + } else { + continue; + } } g_object_set(page->drawing_area, "search-results", result, NULL); @@ -332,14 +334,20 @@ cmd_export(girara_session_t* session, girara_list_t* argument_list) } const char* attachment_name = girara_list_nth(argument_list, 0); - const char* file_name = girara_list_nth(argument_list, 1); + const char* file_name = girara_list_nth(argument_list, 1); + + if (file_name == NULL || attachment_name == NULL) { + return false; + } char* file_name2 = girara_fix_path(file_name); - if (!zathura_document_attachment_save(zathura->document, attachment_name, file_name)) { + + if (zathura_document_attachment_save(zathura->document, attachment_name, file_name) == false) { girara_notify(session, GIRARA_ERROR, "Couldn't write attachment '%s' to '%s'.", attachment_name, file_name); } else { girara_notify(session, GIRARA_INFO, "Wrote attachment '%s' to '%s'.", attachment_name, file_name2); } g_free(file_name2); + return true; } diff --git a/completion.c b/completion.c index cfcbd92..0f837a9 100644 --- a/completion.c +++ b/completion.c @@ -11,6 +11,7 @@ #include "utils.h" #include +#include #include #include #include @@ -29,6 +30,10 @@ compare_case_insensitive(const char* str1, const char* str2) static girara_list_t* list_files(zathura_t* zathura, const char* current_path, const char* current_file, int current_file_length, bool is_dir) { + if (zathura == NULL || zathura->ui.session == NULL || current_path == NULL) { + return NULL; + } + /* read directory */ GDir* dir = g_dir_open(current_path, 0, NULL); if (dir == NULL) { @@ -38,6 +43,9 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil girara_list_t* res = girara_sorted_list_new2((girara_compare_function_t)compare_case_insensitive, (girara_free_function_t)g_free); + bool show_hidden = false; + girara_setting_get(zathura->ui.session, "show-hidden", &show_hidden); + /* read files */ char* name = NULL; while ((name = (char*) g_dir_read_name(dir)) != NULL) { @@ -45,20 +53,26 @@ list_files(zathura_t* zathura, const char* current_path, const char* current_fil if (e_name == NULL) { goto error_free; } - int e_length = strlen(e_name); - if ((current_file_length > e_length) || strncmp(current_file, e_name, - current_file_length)) { + int e_length = strlen(e_name); + + if (show_hidden == false && e_name[0] == '.') { g_free(e_name); continue; } - char* full_path = g_strdup_printf("%s%s%s", current_path, is_dir ? "" : "/", e_name); - if (full_path == NULL) { + if ((current_file_length > e_length) || strncmp(current_file, e_name, current_file_length)) { g_free(e_name); - goto error_free; + continue; } + char* tmp = "/"; + if (is_dir == true || g_strcmp0(current_path, "/") == 0) { + tmp = ""; + }; + + char* full_path = g_strdup_printf("%s%s%s", current_path, tmp, e_name); + if (g_file_test(full_path, G_FILE_TEST_IS_DIR) == true) { char* tmp_path = full_path; full_path = g_strdup_printf("%s/", full_path); @@ -120,9 +134,6 @@ cc_open(girara_session_t* session, const char* input) } char* tmp_path = g_strdup_printf("%s/%s", cwd, path); - if (tmp_path == NULL) { - goto error_free; - } g_free(path); path = tmp_path; @@ -132,10 +143,6 @@ cc_open(girara_session_t* session, const char* input) bool is_dir = (path[strlen(path) - 1] == '/') ? true : false; if ((g_file_test(path, G_FILE_TEST_IS_DIR) == TRUE) && !is_dir) { char* tmp_path = g_strdup_printf("%s/", path); - if (tmp_path == NULL) { - goto error_free; - } - g_free(path); path = tmp_path; is_dir = true; diff --git a/config.c b/config.c index 3a3e3d6..343e22d 100644 --- a/config.c +++ b/config.c @@ -12,6 +12,31 @@ #include #include #include +#include + +static void +cb_color_change(girara_session_t* session, const char* name, girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) +{ + g_return_if_fail(value != NULL); + g_return_if_fail(session != NULL); + g_return_if_fail(session->global.data != NULL); + g_return_if_fail(name != NULL); + zathura_t* zathura = session->global.data; + + char* string_value = (char*) value; + if (g_strcmp0(name, "highlight-color") == 0) { + gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color)); + } else if (g_strcmp0(name, "highlight-active-active") == 0) { + gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color_active)); + } else if (g_strcmp0(name, "recolor-darkcolor") == 0) { + gdk_color_parse(string_value, &(zathura->ui.colors.recolor_dark_color)); + } else if (g_strcmp0(name, "recolor-lightcolor") == 0) { + gdk_color_parse(string_value, &(zathura->ui.colors.recolor_light_color)); + } + + /* TODO: cause a redraw here? */ +} + void config_load_default(zathura_t* zathura) @@ -45,106 +70,144 @@ config_load_default(zathura_t* zathura) int_value = 1; girara_setting_add(gsession, "page-padding", &int_value, INT, true, "Padding between pages", NULL, NULL); int_value = 1; - girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", cb_pages_per_row_value_changed, zathura); + girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", cb_pages_per_row_value_changed, NULL); float_value = 40; girara_setting_add(gsession, "scroll-step", &float_value, FLOAT, false, "Scroll step", NULL, NULL); + int_value = 10; + girara_setting_add(gsession, "zoom-min", &int_value, INT, false, "Zoom minimum", NULL, NULL); + int_value = 1000; + girara_setting_add(gsession, "zoom-max", &int_value, INT, false, "Zoom maximum", NULL, NULL); - string_value = "#FFFFFF"; - girara_setting_add(gsession, "recolor-darkcolor", string_value, STRING, false, "Recoloring (dark color)", NULL, NULL); - string_value = "#000000"; - girara_setting_add(gsession, "recolor-lightcolor", string_value, STRING, false, "Recoloring (light color)", NULL, NULL); + girara_setting_add(gsession, "recolor-darkcolor", NULL, STRING, false, "Recoloring (dark color)", cb_color_change, NULL); + girara_setting_set(gsession, "recolor-darkcolor", "#FFFFFF"); + girara_setting_add(gsession, "recolor-lightcolor", NULL, STRING, false, "Recoloring (light color)", cb_color_change, NULL); + girara_setting_set(gsession, "recolor-lightcolor", "#000000"); + girara_setting_add(gsession, "highlight-color", NULL, STRING, false, "Color for highlighting", cb_color_change, NULL); + girara_setting_set(gsession, "highlight-color", "#9FBC00"); + girara_setting_add(gsession, "highlight-active-color", NULL, STRING, false, "Color for highlighting (active)", cb_color_change, NULL); + girara_setting_set(gsession, "highlight-active-color", "#00BC00"); - string_value = "#9FBC00"; - girara_setting_add(gsession, "highlight-color", string_value, STRING, false, "Color for highlighting", NULL, NULL); float_value = 0.5; girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, "Transparency for highlighting", NULL, NULL); bool_value = true; girara_setting_add(gsession, "render-loading", &bool_value, BOOLEAN, false, "Render 'Loading ...'", NULL, NULL); - int_value = ADJUST_BESTFIT; - girara_setting_add(gsession, "adjust-open", &int_value, INT, false, "Adjust to when opening file", NULL, NULL); + string_value = "best-fit"; + girara_setting_add(gsession, "adjust-open", string_value, STRING, false, "Adjust to when opening file", NULL, NULL); + bool_value = false; + girara_setting_add(gsession, "show-hidden", &bool_value, BOOLEAN, false, "Show hidden files and directories", NULL, NULL); /* define default shortcuts */ - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); - girara_shortcut_add(gsession, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); - girara_shortcut_add(gsession, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL); - girara_shortcut_add(gsession, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); - girara_shortcut_add(gsession, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); - girara_shortcut_add(gsession, 0, GDK_slash, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_slash, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(gsession, 0, GDK_question, NULL, girara_sc_focus_inputbar, NORMAL, 0, &("?")); - girara_shortcut_add(gsession, 0, GDK_colon, NULL, girara_sc_focus_inputbar, NORMAL, 0, &(":")); - girara_shortcut_add(gsession, 0, GDK_o, NULL, girara_sc_focus_inputbar, NORMAL, 0, &(":open ")); - girara_shortcut_add(gsession, 0, GDK_O, NULL, girara_sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); - girara_shortcut_add(gsession, 0, GDK_f, NULL, sc_follow, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, 0, "gg", sc_goto, NORMAL, TOP, NULL); - girara_shortcut_add(gsession, 0, 0, "gg", sc_goto, FULLSCREEN, TOP, NULL); - girara_shortcut_add(gsession, 0, 0, "G", sc_goto, NORMAL, BOTTOM, NULL); - girara_shortcut_add(gsession, 0, 0, "G", sc_goto, FULLSCREEN, BOTTOM, NULL); - girara_shortcut_add(gsession, 0, GDK_J, NULL, sc_navigate, NORMAL, NEXT, NULL); - girara_shortcut_add(gsession, 0, GDK_K, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); - girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_Right, NULL, sc_navigate, NORMAL, NEXT, NULL); - girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_Left, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); - girara_shortcut_add(gsession, 0, GDK_Left, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); - girara_shortcut_add(gsession, 0, GDK_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); - girara_shortcut_add(gsession, 0, GDK_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); - girara_shortcut_add(gsession, 0, GDK_Right, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); - girara_shortcut_add(gsession, 0, GDK_k, NULL, sc_navigate_index, INDEX, UP, NULL); - girara_shortcut_add(gsession, 0, GDK_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); - girara_shortcut_add(gsession, 0, GDK_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); - girara_shortcut_add(gsession, 0, GDK_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL); - girara_shortcut_add(gsession, 0, GDK_space, NULL, sc_navigate_index, INDEX, SELECT, NULL); - girara_shortcut_add(gsession, 0, GDK_Return, NULL, sc_navigate_index, INDEX, SELECT, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_i, NULL, sc_recolor, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_R, NULL, sc_reload, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_r, NULL, sc_rotate, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_h, NULL, sc_scroll, NORMAL, LEFT, NULL); - girara_shortcut_add(gsession, 0, GDK_j, NULL, sc_scroll, NORMAL, DOWN, NULL); - girara_shortcut_add(gsession, 0, GDK_k, NULL, sc_scroll, NORMAL, UP, NULL); - girara_shortcut_add(gsession, 0, GDK_l, NULL, sc_scroll, NORMAL, RIGHT, NULL); - girara_shortcut_add(gsession, 0, GDK_Left, NULL, sc_scroll, NORMAL, LEFT, NULL); - girara_shortcut_add(gsession, 0, GDK_Up, NULL, sc_scroll, NORMAL, UP, NULL); - girara_shortcut_add(gsession, 0, GDK_Down, NULL, sc_scroll, NORMAL, DOWN, NULL); - girara_shortcut_add(gsession, 0, GDK_Right, NULL, sc_scroll, NORMAL, RIGHT, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_d, NULL, sc_scroll, NORMAL, HALF_DOWN, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_u, NULL, sc_scroll, NORMAL, HALF_UP, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_f, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); - girara_shortcut_add(gsession, 0, GDK_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); - girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_space, NULL, sc_scroll, NORMAL, FULL_UP, NULL); - girara_shortcut_add(gsession, 0, GDK_n, NULL, sc_search, NORMAL, FORWARD, NULL); - girara_shortcut_add(gsession, 0, GDK_N, NULL, sc_search, NORMAL, BACKWARD, NULL); - girara_shortcut_add(gsession, 0, GDK_Tab, NULL, sc_toggle_index, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_Tab, NULL, sc_toggle_index, INDEX, 0, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_m, NULL, girara_sc_toggle_inputbar, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_F5, NULL, sc_toggle_fullscreen, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_F5, NULL, sc_toggle_fullscreen, FULLSCREEN, 0, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_n, NULL, girara_sc_toggle_statusbar, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_q, NULL, sc_quit, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_plus, NULL, sc_zoom, NORMAL, ZOOM_IN, NULL); - girara_shortcut_add(gsession, 0, GDK_plus, NULL, sc_zoom, FULLSCREEN, ZOOM_IN, NULL); - girara_shortcut_add(gsession, 0, GDK_minus, NULL, sc_zoom, NORMAL, ZOOM_OUT, NULL); - girara_shortcut_add(gsession, 0, GDK_minus, NULL, sc_zoom, FULLSCREEN, ZOOM_OUT, NULL); - girara_shortcut_add(gsession, 0, GDK_equal, NULL, sc_zoom, NORMAL, ZOOM_ORIGINAL, NULL); - girara_shortcut_add(gsession, 0, GDK_equal, NULL, sc_zoom, FULLSCREEN, ZOOM_ORIGINAL, NULL); - girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, NORMAL, ZOOM_IN, NULL); - girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, FULLSCREEN, ZOOM_IN, NULL); - girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, NORMAL, ZOOM_OUT, NULL); - girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, FULLSCREEN, ZOOM_OUT, NULL); - girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, NORMAL, ZOOM_ORIGINAL, NULL); - girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, FULLSCREEN, ZOOM_ORIGINAL, NULL); - girara_shortcut_add(gsession, 0, GDK_equal, NULL, sc_zoom, NORMAL, ZOOM_SPECIFIC, NULL); - girara_shortcut_add(gsession, 0, GDK_equal, NULL, sc_zoom, FULLSCREEN, ZOOM_SPECIFIC, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_c, NULL, sc_abort, 0, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Escape, NULL, sc_abort, 0, 0, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, 0, GDK_KEY_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); + girara_shortcut_add(gsession, 0, GDK_KEY_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); + girara_shortcut_add(gsession, 0, GDK_KEY_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); + girara_shortcut_add(gsession, 0, GDK_KEY_O, NULL, sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); + + girara_shortcut_add(gsession, 0, GDK_KEY_f, NULL, sc_follow, NORMAL, 0, NULL); + + girara_shortcut_add(gsession, 0, 0, "gg", sc_goto, NORMAL, TOP, NULL); + girara_shortcut_add(gsession, 0, 0, "gg", sc_goto, FULLSCREEN, TOP, NULL); + girara_shortcut_add(gsession, 0, 0, "G", sc_goto, NORMAL, BOTTOM, NULL); + girara_shortcut_add(gsession, 0, 0, "G", sc_goto, FULLSCREEN, BOTTOM, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_J, NULL, sc_navigate, NORMAL, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_K, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_KEY_Right, NULL, sc_navigate, NORMAL, NEXT, NULL); + girara_shortcut_add(gsession, GDK_MOD1_MASK, GDK_KEY_Left, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, NORMAL, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_J, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_K, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Page_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_navigate_index, INDEX, UP, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_L, NULL, sc_navigate_index, INDEX, EXPAND_ALL, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_H, NULL, sc_navigate_index, INDEX, COLLAPSE_ALL, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_navigate_index, INDEX, UP, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_navigate_index, INDEX, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_navigate_index, INDEX, EXPAND, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_space, NULL, sc_navigate_index, INDEX, SELECT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Return, NULL, sc_navigate_index, INDEX, SELECT, NULL); + + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_i, NULL, sc_recolor, NORMAL, 0, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_R, NULL, sc_reload, NORMAL, 0, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_r, NULL, sc_rotate, NORMAL, 0, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_h, NULL, sc_scroll, NORMAL, LEFT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_j, NULL, sc_scroll, NORMAL, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_k, NULL, sc_scroll, NORMAL, UP, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_l, NULL, sc_scroll, NORMAL, RIGHT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Left, NULL, sc_scroll, NORMAL, LEFT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Up, NULL, sc_scroll, NORMAL, UP, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Down, NULL, sc_scroll, NORMAL, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Right, NULL, sc_scroll, NORMAL, RIGHT, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_d, NULL, sc_scroll, NORMAL, HALF_DOWN, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_u, NULL, sc_scroll, NORMAL, HALF_UP, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_f, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); + girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_KEY_space, NULL, sc_scroll, NORMAL, FULL_UP, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_n, NULL, sc_search, NORMAL, FORWARD, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_N, NULL, sc_search, NORMAL, BACKWARD, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_Tab, NULL, sc_toggle_index, INDEX, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_F5, NULL, sc_toggle_fullscreen, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_F5, NULL, sc_toggle_fullscreen, FULLSCREEN, 0, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_n, NULL, girara_sc_toggle_statusbar, NORMAL, 0, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_KEY_m, NULL, girara_sc_toggle_inputbar, NORMAL, 0, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_q, NULL, sc_quit, NORMAL, 0, NULL); + + girara_shortcut_add(gsession, 0, GDK_KEY_plus, NULL, sc_zoom, NORMAL, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_plus, NULL, sc_zoom, FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_minus, NULL, sc_zoom, NORMAL, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_minus, NULL, sc_zoom, FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_equal, NULL, sc_zoom, NORMAL, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_equal, NULL, sc_zoom, FULLSCREEN, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, NORMAL, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, NORMAL, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, NORMAL, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, FULLSCREEN, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_equal, NULL, sc_zoom, NORMAL, ZOOM_SPECIFIC, NULL); + girara_shortcut_add(gsession, 0, GDK_KEY_equal, NULL, sc_zoom, FULLSCREEN, ZOOM_SPECIFIC, NULL); /* mouse events */ - girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_SCROLL, 0, NULL); - girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL, 0, NULL); - girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, NORMAL, GIRARA_EVENT_SCROLL, 0, NULL); - girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, FULLSCREEN, GIRARA_EVENT_SCROLL, 0, NULL); - girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL, GIRARA_EVENT_BUTTON_PRESS, 0, NULL); - girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL, GIRARA_EVENT_BUTTON_RELEASE, 0, NULL); - girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_MOTION_NOTIFY, 0, NULL); + girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_SCROLL_UP, UP, NULL); + girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_UP, UP, NULL); + girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL); + girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL); + girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, NORMAL, GIRARA_EVENT_SCROLL_UP, UP, NULL); + girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, FULLSCREEN, GIRARA_EVENT_SCROLL_UP, UP, NULL); + girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, NORMAL, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL); + girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL); + girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL, GIRARA_EVENT_BUTTON_PRESS, 0, NULL); + girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL, GIRARA_EVENT_BUTTON_RELEASE, 0, NULL); + girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_MOTION_NOTIFY, 0, NULL); /* define default inputbar commands */ girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark"); @@ -168,7 +231,7 @@ config_load_default(zathura_t* zathura) girara_shortcut_mapping_add(gsession, "change_mode", sc_change_mode); girara_shortcut_mapping_add(gsession, "follow", sc_follow); girara_shortcut_mapping_add(gsession, "goto", sc_goto); - girara_shortcut_mapping_add(gsession, "index_navigate", sc_navigate_index); + girara_shortcut_mapping_add(gsession, "navigate_index", sc_navigate_index); girara_shortcut_mapping_add(gsession, "navigate", sc_navigate); girara_shortcut_mapping_add(gsession, "quit", sc_quit); girara_shortcut_mapping_add(gsession, "recolor", sc_recolor); @@ -183,30 +246,34 @@ config_load_default(zathura_t* zathura) girara_shortcut_mapping_add(gsession, "zoom", sc_zoom); /* add argument mappings */ - girara_argument_mapping_add(gsession, "bottom", BOTTOM); - girara_argument_mapping_add(gsession, "default", DEFAULT); - girara_argument_mapping_add(gsession, "down", DOWN); - girara_argument_mapping_add(gsession, "full-down", FULL_DOWN); - girara_argument_mapping_add(gsession, "full-up", FULL_UP); - girara_argument_mapping_add(gsession, "half-down", HALF_DOWN); - girara_argument_mapping_add(gsession, "half-up", HALF_UP); - girara_argument_mapping_add(gsession, "in", ZOOM_IN); - girara_argument_mapping_add(gsession, "left", LEFT); - girara_argument_mapping_add(gsession, "next", NEXT); - girara_argument_mapping_add(gsession, "out", ZOOM_OUT); - girara_argument_mapping_add(gsession, "previous", PREVIOUS); - girara_argument_mapping_add(gsession, "right", RIGHT); - girara_argument_mapping_add(gsession, "specific", ZOOM_SPECIFIC); - girara_argument_mapping_add(gsession, "top", TOP); - girara_argument_mapping_add(gsession, "up", UP); - girara_argument_mapping_add(gsession, "best-fit", ADJUST_BESTFIT); - girara_argument_mapping_add(gsession, "width", ADJUST_WIDTH); + girara_argument_mapping_add(gsession, "bottom", BOTTOM); + girara_argument_mapping_add(gsession, "default", DEFAULT); + girara_argument_mapping_add(gsession, "collapse", COLLAPSE); + girara_argument_mapping_add(gsession, "collapse-all", COLLAPSE_ALL); + girara_argument_mapping_add(gsession, "down", DOWN); + girara_argument_mapping_add(gsession, "expand", EXPAND); + girara_argument_mapping_add(gsession, "expand-all", EXPAND_ALL); + girara_argument_mapping_add(gsession, "full-down", FULL_DOWN); + girara_argument_mapping_add(gsession, "full-up", FULL_UP); + girara_argument_mapping_add(gsession, "half-down", HALF_DOWN); + girara_argument_mapping_add(gsession, "half-up", HALF_UP); + girara_argument_mapping_add(gsession, "in", ZOOM_IN); + girara_argument_mapping_add(gsession, "left", LEFT); + girara_argument_mapping_add(gsession, "next", NEXT); + girara_argument_mapping_add(gsession, "out", ZOOM_OUT); + girara_argument_mapping_add(gsession, "previous", PREVIOUS); + girara_argument_mapping_add(gsession, "right", RIGHT); + girara_argument_mapping_add(gsession, "specific", ZOOM_SPECIFIC); + girara_argument_mapping_add(gsession, "top", TOP); + girara_argument_mapping_add(gsession, "up", UP); + girara_argument_mapping_add(gsession, "best-fit", ADJUST_BESTFIT); + girara_argument_mapping_add(gsession, "width", ADJUST_WIDTH); } void config_load_file(zathura_t* zathura, char* path) { - if (zathura == NULL) { + if (zathura == NULL || path == NULL) { return; } diff --git a/config.mk b/config.mk index da58c87..254b5df 100644 --- a/config.mk +++ b/config.mk @@ -3,6 +3,9 @@ VERSION = 0.0.8.1 +# the GTK version to use +ZATHURA_GTK_VERSION ?= 2 + # paths PREFIX ?= /usr MANPREFIX ?= ${PREFIX}/share/man @@ -13,11 +16,11 @@ PLUGINDIR ?= ${PREFIX}/lib/zathura # libs # set this to 0 if you don't need to link against dl -GTK_INC ?= $(shell pkg-config --cflags gtk+-2.0) -GTK_LIB ?= $(shell pkg-config --libs gtk+-2.0 gthread-2.0) +GTK_INC ?= $(shell pkg-config --cflags gtk+-${ZATHURA_GTK_VERSION}.0) +GTK_LIB ?= $(shell pkg-config --libs gtk+-${ZATHURA_GTK_VERSION}.0 gthread-2.0) -GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk2) -GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk2) +GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk${ZATHURA_GTK_VERSION}) +GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk${ZATHURA_GTK_VERSION}) SQLITE_INC ?= $(shell pkg-config --cflags sqlite3) SQLITE_LIB ?= $(shell pkg-config --libs sqlite3) diff --git a/database-plain.c b/database-plain.c index 804d626..1099117 100644 --- a/database-plain.c +++ b/database-plain.c @@ -234,9 +234,6 @@ zathura_db_set_fileinfo(zathura_database_t* db, const char* file, unsigned int } char* tmp = g_strdup_printf("%f", scale); - if (tmp == NULL) { - return false; - } g_key_file_set_integer(db->history, file, KEY_PAGE, page); g_key_file_set_integer(db->history, file, KEY_OFFSET, offset); diff --git a/document.c b/document.c index dcab1a5..fbaef7c 100644 --- a/document.c +++ b/document.c @@ -216,8 +216,6 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password return NULL; } - char* file_uri = NULL; - /* determine real path */ long path_max; #ifdef PATH_MAX @@ -328,39 +326,24 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password document->pages[page_id] = page; } - /* install file monitor */ - file_uri = g_filename_to_uri(real_path, NULL, NULL); - if (file_uri == NULL) { - goto error_free; - } - - document->file_monitor.file = g_file_new_for_uri(file_uri); - if (document->file_monitor.file == NULL) { - goto error_free; - } - - document->file_monitor.monitor = g_file_monitor_file(document->file_monitor.file, G_FILE_MONITOR_NONE, NULL, NULL); - if (document->file_monitor.monitor == NULL) { - goto error_free; - } - - g_signal_connect(G_OBJECT(document->file_monitor.monitor), "changed", G_CALLBACK(cb_file_monitor), zathura->ui.session); - - /* apply open adjustment */ - int adjust_open = ADJUST_BESTFIT; - girara_setting_get(zathura->ui.session, "adjust-open", &adjust_open); - - g_free(file_uri); + char* adjust_open = "best-fit"; + document->adjust_mode = ADJUST_BESTFIT; + if (girara_setting_get(zathura->ui.session, "adjust-open", &(adjust_open)) == true) { + if (g_strcmp0(adjust_open, "best-fit") == 0) { + document->adjust_mode = ADJUST_BESTFIT; + } else if (g_strcmp0(adjust_open, "width") == 0) { + document->adjust_mode = ADJUST_WIDTH; + } else { + document->adjust_mode = ADJUST_NONE; + } + g_free(adjust_open); + } return document; error_free: - if (file_uri != NULL) { - g_free(file_uri); - } - free(real_path); if (document != NULL && document->pages != NULL) { @@ -378,7 +361,7 @@ error_free: zathura_plugin_error_t zathura_document_free(zathura_document_t* document) { - if (document == NULL) { + if (document == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) { return false; } @@ -393,6 +376,7 @@ zathura_document_free(zathura_document_t* document) /* free document */ bool r = true; if (document->functions.document_free == NULL) { + girara_notify(document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); } else { r = document->functions.document_free(document); @@ -410,11 +394,12 @@ zathura_document_free(zathura_document_t* document) zathura_plugin_error_t zathura_document_save_as(zathura_document_t* document, const char* path) { - if (document == NULL || path == NULL) { + if (document == NULL || path == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) { return false; } if (document->functions.document_save_as == NULL) { + girara_notify(document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); return false; } @@ -425,11 +410,12 @@ zathura_document_save_as(zathura_document_t* document, const char* path) girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document, zathura_plugin_error_t* error) { - if (document == NULL) { + if (document == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) { return NULL; } if (document->functions.document_index_generate == NULL) { + girara_notify(document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -440,11 +426,12 @@ zathura_document_index_generate(zathura_document_t* document, zathura_plugin_err girara_list_t* zathura_document_attachments_get(zathura_document_t* document, zathura_plugin_error_t* error) { - if (document == NULL) { + if (document == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) { return NULL; } if (document->functions.document_attachments_get == NULL) { + girara_notify(document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -455,11 +442,13 @@ zathura_document_attachments_get(zathura_document_t* document, zathura_plugin_er zathura_plugin_error_t zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file) { - if (document == NULL) { + if (document == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) { return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; } if (document->functions.document_attachment_save == NULL) { + girara_notify(document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; } @@ -469,9 +458,9 @@ zathura_document_attachment_save(zathura_document_t* document, const char* attac char* zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t meta, zathura_plugin_error_t* error) { - if (document == NULL) { + if (document == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) { if (error != NULL) { - *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + *error = ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; } return NULL; } @@ -480,6 +469,8 @@ zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t if (error != NULL) { *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; } + girara_notify(document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -489,12 +480,19 @@ zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id, zathura_plugin_error_t* error) { - if (document == NULL) { + if (document == NULL || document->zathura == NULL || document->zathura->ui.session == NULL) { + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; + } return NULL; } if (document->functions.page_get == NULL) { + girara_notify(document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + } return NULL; } @@ -504,6 +502,12 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id, zathura_plu page->number = page_id; page->visible = false; page->drawing_area = zathura_page_widget_new(page); + if (page->drawing_area == NULL) { + girara_error("couldn't create page widget"); + zathura_page_free(page); + return NULL; + } + page->document = document; unsigned int page_height = 0; @@ -519,13 +523,14 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id, zathura_plu zathura_plugin_error_t zathura_page_free(zathura_page_t* page) { - if (page == NULL || page->document == NULL) { - return false; + if (page == NULL || page->document == NULL || page->document->zathura == NULL || page->document->zathura->ui.session == NULL) { + return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; } if (page->document->functions.page_free == NULL) { + girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); - return false; + return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; } return page->document->functions.page_free(page); @@ -534,12 +539,20 @@ zathura_page_free(zathura_page_t* page) girara_list_t* zathura_page_search_text(zathura_page_t* page, const char* text, zathura_plugin_error_t* error) { - if (page == NULL || page->document == NULL || text == NULL) { + if (page == NULL || page->document == NULL || text == NULL || + page->document->zathura == NULL || page->document->zathura->ui.session == NULL) { + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; + } return NULL; } if (page->document->functions.page_search_text == NULL) { + girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + } return NULL; } @@ -549,12 +562,20 @@ zathura_page_search_text(zathura_page_t* page, const char* text, zathura_plugin_ girara_list_t* zathura_page_links_get(zathura_page_t* page, zathura_plugin_error_t* error) { - if (page == NULL || page->document == NULL) { + if (page == NULL || page->document == NULL || page->document->zathura == NULL + || page->document->zathura->ui.session == NULL) { + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; + } return NULL; } if (page->document->functions.page_links_get == NULL) { + girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + } return NULL; } @@ -570,12 +591,20 @@ zathura_page_links_free(girara_list_t* UNUSED(list)) girara_list_t* zathura_page_form_fields_get(zathura_page_t* page, zathura_plugin_error_t* error) { - if (page == NULL || page->document == NULL) { + if (page == NULL || page->document == NULL || page->document->zathura == NULL + || page->document->zathura->ui.session == NULL) { + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; + } return NULL; } if (page->document->functions.page_form_fields_get == NULL) { + girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + } return NULL; } @@ -585,42 +614,59 @@ zathura_page_form_fields_get(zathura_page_t* page, zathura_plugin_error_t* error zathura_plugin_error_t zathura_page_form_fields_free(girara_list_t* UNUSED(list)) { - return false; + return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; } girara_list_t* zathura_page_images_get(zathura_page_t* page, zathura_plugin_error_t* error) { - if (page == NULL || page->document == NULL) { + if (page == NULL || page->document == NULL || page->document->zathura == NULL + || page->document->zathura->ui.session == NULL) { + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; + } return NULL; } if (page->document->functions.page_images_get == NULL) { + girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); - return false; + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + } + return NULL; } return page->document->functions.page_images_get(page, error); } -zathura_plugin_error_t -zathura_page_image_save(zathura_page_t* page, zathura_image_t* image, const char* file) +cairo_surface_t* +zathura_page_image_get_cairo(zathura_page_t* page, zathura_image_t* image, zathura_plugin_error_t* error) { - if (page == NULL || page->document == NULL || image == NULL || file == NULL) { - return false; + if (page == NULL || page->document == NULL || image == NULL || + page->document->zathura == NULL || page->document->zathura->ui.session == + NULL) { + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; + } + return NULL; } - if (page->document->functions.page_image_save == NULL) { + if (page->document->functions.page_image_get_cairo == NULL) { + girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); - return false; + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + } + return NULL; } - return page->document->functions.page_image_save(page, image, file); + return page->document->functions.page_image_get_cairo(page, image, error); } char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle, zathura_plugin_error_t* error) { - if (page == NULL || page->document == NULL) { + if (page == NULL || page->document == NULL || page->document->zathura == NULL || page->document->zathura->ui.session == NULL) { if (error) { *error = ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; } @@ -628,6 +674,7 @@ char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle, } if (page->document->functions.page_get_text == NULL) { + girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); if (error) { *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; @@ -641,11 +688,14 @@ char* zathura_page_get_text(zathura_page_t* page, zathura_rectangle_t rectangle, zathura_plugin_error_t zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing) { - if (page == NULL || page->document == NULL || cairo == NULL) { + if (page == NULL || page->document == NULL || cairo == NULL || + page->document->zathura == NULL || page->document->zathura->ui.session == + NULL) { return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; } if (page->document->functions.page_render_cairo == NULL) { + girara_notify(page->document->zathura->ui.session, GIRARA_WARNING, "%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__); return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; } diff --git a/document.h b/document.h index e0aac6f..d17fa42 100644 --- a/document.h +++ b/document.h @@ -271,9 +271,9 @@ struct zathura_document_s girara_list_t* (*page_images_get)(zathura_page_t* page, zathura_plugin_error_t* error); /** - * Save image to a file + * Get the image */ - zathura_plugin_error_t (*page_image_save)(zathura_page_t* page, zathura_image_t* image, const char* file); + cairo_surface_t* (*page_image_get_cairo)(zathura_page_t* page, zathura_image_t* image, zathura_plugin_error_t* error); /** * Get text for selection @@ -300,14 +300,6 @@ struct zathura_document_s * Document pages */ zathura_page_t** pages; - - /** - * File monitor - */ - struct { - GFileMonitor* monitor; /**< File monitor */ - GFile* file; /**< File for file monitor */ - } file_monitor; }; /** @@ -477,21 +469,21 @@ zathura_plugin_error_t zathura_page_form_fields_free(girara_list_t* list); girara_list_t* zathura_page_images_get(zathura_page_t* page, zathura_plugin_error_t* error); /** - * Save image + * Get image * * @param page Page - * @param image The image - * @param file Path to the file - * @return ZATHURA_PLUGIN_ERROR_OK when no error occured, otherwise see - * zathura_plugin_error_t + * @param image Image identifier + * @param error Set to an error value (see \ref zathura_plugin_error_t) if an + * error occured + * @return The cairo image surface or NULL if an error occured */ -zathura_plugin_error_t zathura_page_image_save(zathura_page_t* page, zathura_image_t* image, const char* file); +cairo_surface_t* zathura_page_image_get_cairo(zathura_page_t* page, zathura_image_t* image, zathura_plugin_error_t* error); /** * Get text for selection * @param page Page * @param rectangle Selection - * @error Set to an error value (see \ref zathura_plugin_error_t) if an error + * @param error Set to an error value (see \ref zathura_plugin_error_t) if an error * occured * @return The selected text (needs to be deallocated with g_free) */ diff --git a/page_widget.c b/page_widget.c index 5c0f368..40cdd0b 100644 --- a/page_widget.c +++ b/page_widget.c @@ -29,7 +29,10 @@ typedef struct zathura_page_widget_private_s { #define ZATHURA_PAGE_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZATHURA_TYPE_PAGE, zathura_page_widget_private_t)) +static gboolean zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo); +#if GTK_MAJOR_VERSION == 2 static gboolean zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event); +#endif static void zathura_page_widget_finalize(GObject* object); static void zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); static void zathura_page_widget_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec); @@ -61,7 +64,11 @@ zathura_page_widget_class_init(ZathuraPageClass* class) /* overwrite methods */ GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(class); +#if GTK_MAJOR_VERSION == 3 + widget_class->draw = zathura_page_widget_draw; +#else widget_class->expose_event = zathura_page_widget_expose; +#endif widget_class->size_allocate = zathura_page_widget_size_allocate; widget_class->button_press_event = cb_zathura_page_widget_button_press_event; widget_class->button_release_event = cb_zathura_page_widget_button_release_event; @@ -219,6 +226,7 @@ zathura_page_widget_get_property(GObject* object, guint prop_id, GValue* value, } } +#if GTK_MAJOR_VERSION == 2 static gboolean zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event) { @@ -232,14 +240,29 @@ zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event) cairo_rectangle(cairo, event->area.x, event->area.y, event->area.width, event->area.height); cairo_clip(cairo); + const gboolean ret = zathura_page_widget_draw(widget, cairo); + cairo_destroy(cairo); + return ret; +} +#endif + +static gboolean +zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo) +{ zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget); g_static_mutex_lock(&(priv->lock)); + +#if GTK_MAJOR_VERSION == 2 + const unsigned int page_height = widget->allocation.height; + const unsigned int page_width = widget->allocation.width; +#else + const unsigned int page_height = gtk_widget_get_allocated_height(widget); + const unsigned int page_width = gtk_widget_get_allocated_width(widget); +#endif + if (priv->surface != NULL) { cairo_save(cairo); - unsigned int page_height = widget->allocation.height; - unsigned int page_width = widget->allocation.width; - switch (priv->page->document->rotate) { case 90: cairo_translate(cairo, page_width, 0); @@ -302,10 +325,11 @@ zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event) zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect); /* draw position */ - GdkColor color = priv->zathura->ui.colors.highlight_color; if (idx == priv->search_current) { - cairo_set_source_rgba(cairo, 0, color.green, color.blue, transparency); + GdkColor color = priv->zathura->ui.colors.highlight_color_active; + cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency); } else { + GdkColor color = priv->zathura->ui.colors.highlight_color; cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency); } cairo_rectangle(cairo, rectangle.x1, rectangle.y1, @@ -325,7 +349,7 @@ zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event) } else { /* set background color */ cairo_set_source_rgb(cairo, 255, 255, 255); - cairo_rectangle(cairo, 0, 0, widget->allocation.width, widget->allocation.height); + cairo_rectangle(cairo, 0, 0, page_width, page_height); cairo_fill(cairo); bool render_loading = true; @@ -339,8 +363,8 @@ zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event) cairo_set_font_size(cairo, 16.0); cairo_text_extents_t extents; cairo_text_extents(cairo, text, &extents); - double x = widget->allocation.width * 0.5 - (extents.width * 0.5 + extents.x_bearing); - double y = widget->allocation.height * 0.5 - (extents.height * 0.5 + extents.y_bearing); + double x = page_width * 0.5 - (extents.width * 0.5 + extents.x_bearing); + double y = page_height * 0.5 - (extents.height * 0.5 + extents.y_bearing); cairo_move_to(cairo, x, y); cairo_show_text(cairo, text); } @@ -348,8 +372,6 @@ zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event) /* render real page */ render_page(priv->zathura->sync.render_thread, priv->page); } - cairo_destroy(cairo); - g_static_mutex_unlock(&(priv->lock)); return FALSE; } @@ -391,7 +413,11 @@ redraw_rect(ZathuraPage* widget, zathura_rectangle_t* rectangle) grect.y = rectangle->y1; grect.width = rectangle->x2 - rectangle->x1; grect.height = rectangle->y2 - rectangle->y1; +#if (GTK_MAJOR_VERSION == 3) + gtk_widget_queue_draw_area(GTK_WIDGET(widget), grect.x, grect.y, grect.width, grect.height); +#else gdk_window_invalidate_rect(GTK_WIDGET(widget)->window, &grect, TRUE); +#endif } static void diff --git a/render.c b/render.c index 2311398..cfe9abd 100644 --- a/render.c +++ b/render.c @@ -112,7 +112,7 @@ render_free(render_thread_t* render_thread) } if (render_thread->list) { - girara_list_free(render_thread->list); + girara_list_clear(render_thread->list); } if (render_thread->cond) { @@ -121,6 +121,10 @@ render_free(render_thread_t* render_thread) g_cond_free(render_thread->cond); } + if (render_thread->list) { + girara_list_free(render_thread->list); + } + if (render_thread->lock) { g_mutex_free(render_thread->lock); } diff --git a/shortcuts.c b/shortcuts.c index c5d8a0a..e1cd346 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "callbacks.h" #include "shortcuts.h" @@ -57,6 +58,10 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument, } zathura->document->adjust_mode = argument->n; + if (argument->n == ADJUST_NONE) { + /* there is nothing todo */ + goto error_ret; + } /* get window size */ GtkAllocation allocation; @@ -112,6 +117,63 @@ sc_change_mode(girara_session_t* session, girara_argument_t* argument, return false; } +bool +sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) +{ + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->gtk.inputbar_entry != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(argument != NULL, false); + + if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == false) { + gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); + } + + if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.notification_area)) == true) { + gtk_widget_hide(GTK_WIDGET(session->gtk.notification_area)); + } + + gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar_entry)); + + if (argument->data != NULL) { + gtk_entry_set_text(session->gtk.inputbar_entry, (char*) argument->data); + + /* append filepath */ + if (argument->n == APPEND_FILEPATH && zathura->document != NULL) { + char* file_path = g_strdup(zathura->document->file_path); + if (file_path == NULL) { + return false; + } + + char* path = dirname(file_path); + char* tmp = g_strdup_printf("%s%s/", (char*) argument->data, (g_strcmp0(path, "/") == 0) ? "" : path); + + if (tmp == NULL) { + g_free(file_path); + return false; + } + + gtk_entry_set_text(session->gtk.inputbar_entry, tmp); + g_free(tmp); + g_free(file_path); + } + + /* we save the X clipboard that will be clear by "grab_focus" */ + gchar* x_clipboard_text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY)); + + gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar_entry), -1); + + if (x_clipboard_text != NULL) { + /* we reset the X clipboard with saved text */ + gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), x_clipboard_text, -1); + g_free(x_clipboard_text); + } + } + + return true; +} + bool sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t)) @@ -120,7 +182,7 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; - if (zathura->document == NULL) { + if (zathura->document == NULL || zathura->ui.session == NULL) { return false; } @@ -151,7 +213,7 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), /* ask for input */ if (show_links == true) { - girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_follow, NULL); + girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_follow, zathura->ui.session); } return false; @@ -188,52 +250,51 @@ sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_e g_return_val_if_fail(argument != NULL, false); g_return_val_if_fail(event != NULL, false); - static int x = 0; - static int y = 0; - if (zathura->document == NULL) { return false; } - /* scroll event */ - if (event->type == GIRARA_EVENT_SCROLL) { - switch (event->direction) { - case GIRARA_SCROLL_UP: - argument->n = UP; - break; - case GIRARA_SCROLL_DOWN: - argument->n = DOWN; - break; - case GIRARA_SCROLL_LEFT: - argument->n = LEFT; - break; - case GIRARA_SCROLL_RIGHT: - argument->n = RIGHT; - break; - } + static int x = 0; + static int y = 0; - return sc_scroll(session, argument, NULL, t); - } else if (event->type == GIRARA_EVENT_BUTTON_PRESS) { - x = event->x; - y = event->y; - } else if (event->type == GIRARA_EVENT_BUTTON_RELEASE) { - x = 0; - y = 0; - } else if (event->type == GIRARA_EVENT_MOTION_NOTIFY) { - GtkAdjustment* x_adj = - gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); - GtkAdjustment* y_adj = - gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); + GtkAdjustment* x_adj = NULL; + GtkAdjustment* y_adj = NULL; - if (x_adj == NULL || y_adj == NULL) { - return false; - } + switch (event->type) { + /* scroll */ + case GIRARA_EVENT_SCROLL_UP: + case GIRARA_EVENT_SCROLL_DOWN: + case GIRARA_EVENT_SCROLL_LEFT: + case GIRARA_EVENT_SCROLL_RIGHT: + return sc_scroll(session, argument, NULL, t); - set_adjustment(x_adj, gtk_adjustment_get_value(x_adj) - (event->x - x)); - set_adjustment(y_adj, gtk_adjustment_get_value(y_adj) - (event->y - y)); + /* drag */ + case GIRARA_EVENT_BUTTON_PRESS: + x = event->x; + y = event->y; + break; + case GIRARA_EVENT_BUTTON_RELEASE: + x = 0; + y = 0; + break; + case GIRARA_EVENT_MOTION_NOTIFY: + x_adj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); + y_adj =gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); - x = event->x; - y = event->y; + if (x_adj == NULL || y_adj == NULL) { + return false; + } + + set_adjustment(x_adj, gtk_adjustment_get_value(x_adj) - (event->x - x)); + set_adjustment(y_adj, gtk_adjustment_get_value(y_adj) - (event->y - y)); + + x = event->x; + y = event->y; + break; + + /* unhandled events */ + default: + break; } return false; @@ -253,22 +314,18 @@ sc_mouse_zoom(girara_session_t* session, girara_argument_t* argument, girara_eve } /* scroll event */ - if (event->type == GIRARA_EVENT_SCROLL) { - switch (event->direction) { - case GIRARA_SCROLL_UP: - argument->n = ZOOM_IN; - break; - case GIRARA_SCROLL_DOWN: - argument->n = ZOOM_OUT; - break; - default: - return false; - } - - return sc_zoom(session, argument, NULL, t); + switch (event->type) { + case GIRARA_EVENT_SCROLL_UP: + argument->n = ZOOM_IN; + break; + case GIRARA_EVENT_SCROLL_DOWN: + argument->n = ZOOM_OUT; + break; + default: + return false; } - return false; + return sc_zoom(session, argument, NULL, t); } bool @@ -318,23 +375,15 @@ sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument), g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; - if (zathura->document == NULL || zathura->document->file_path == NULL) { + if (zathura->file_monitor.file_path == NULL) { return false; } - /* save current document path and password */ - char* path = g_strdup(zathura->document->file_path); - char* password = zathura->document->password ? g_strdup(zathura->document->password) : NULL; - /* close current document */ - document_close(zathura); + document_close(zathura, true); /* reopen document */ - document_open(zathura, path, password); - - /* clean up */ - g_free(path); - g_free(password); + document_open(zathura, zathura->file_monitor.file_path, zathura->file_monitor.password); return false; } @@ -380,25 +429,27 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); } - gdouble view_size = gtk_adjustment_get_page_size(adjustment); - gdouble value = gtk_adjustment_get_value(adjustment); - gdouble max = gtk_adjustment_get_upper(adjustment) - view_size; + gdouble view_size = gtk_adjustment_get_page_size(adjustment); + gdouble value = gtk_adjustment_get_value(adjustment); + gdouble max = gtk_adjustment_get_upper(adjustment) - view_size; + unsigned int padding = zathura->global.page_padding; + float scroll_step = 40; girara_setting_get(session, "scroll-step", &scroll_step); gdouble new_value; switch(argument->n) { case FULL_UP: - new_value = value - view_size; + new_value = value - view_size - padding; break; case FULL_DOWN: - new_value = value + view_size; + new_value = value + view_size + padding; break; case HALF_UP: - new_value = value - (view_size / 2); + new_value = value - ((view_size + padding) / 2); break; case HALF_DOWN: - new_value = value + (view_size / 2); + new_value = value + ((view_size + padding) / 2); break; case LEFT: case UP: @@ -533,7 +584,7 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument, switch(argument->n) { case UP: - if(gtk_tree_path_prev(path) == FALSE) { + if (gtk_tree_path_prev(path) == FALSE) { is_valid_path = gtk_tree_path_up(path); } else { /* row above */ while(gtk_tree_view_row_expanded(tree_view, path)) { @@ -547,14 +598,14 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument, } break; case COLLAPSE: - if(!gtk_tree_view_collapse_row(tree_view, path) + if (gtk_tree_view_collapse_row(tree_view, path) == FALSE && gtk_tree_path_get_depth(path) > 1) { gtk_tree_path_up(path); gtk_tree_view_collapse_row(tree_view, path); } break; case DOWN: - if(gtk_tree_view_row_expanded(tree_view, path)) { + if (gtk_tree_view_row_expanded(tree_view, path) == TRUE) { gtk_tree_path_down(path); } else { do { @@ -568,10 +619,19 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument, } break; case EXPAND: - if(gtk_tree_view_expand_row(tree_view, path, FALSE)) { + if (gtk_tree_view_expand_row(tree_view, path, FALSE)) { gtk_tree_path_down(path); } break; + case EXPAND_ALL: + gtk_tree_view_expand_all(tree_view); + break; + case COLLAPSE_ALL: + gtk_tree_view_collapse_all(tree_view); + gtk_tree_path_free(path); + path = gtk_tree_path_new_first(); + gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE); + break; case SELECT: cb_index_row_activated(tree_view, path, NULL, zathura); return false; @@ -787,10 +847,18 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* } /* zoom limitations */ - if (zathura->document->scale < 0.1f) { - zathura->document->scale = 0.1f; - } else if (zathura->document->scale > 10.0f) { - zathura->document->scale = 10.0f; + int zoom_min_int = 10; + int zoom_max_int = 1000; + girara_setting_get(session, "zoom-min", &zoom_min_int); + girara_setting_get(session, "zoom-max", &zoom_max_int); + + float zoom_min = zoom_min_int * 0.01f; + float zoom_max = zoom_max_int * 0.01f; + + if (zathura->document->scale < zoom_min) { + zathura->document->scale = zoom_min; + } else if (zathura->document->scale > zoom_max) { + zathura->document->scale = zoom_max; } /* keep position */ @@ -805,4 +873,3 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* return false; } - diff --git a/shortcuts.h b/shortcuts.h index 1629d74..56bed86 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -38,6 +38,18 @@ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, gi */ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); +/** + * Shortcut function to focus the inputbar + * + * @param session The used girara session + * @param argument The argument + * @param event Girara event + * @param t Number of executions + * @return true No error occured + * @return false An error occured (abort execution) + */ +bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t); + /** * Follow a link * diff --git a/tests/Makefile b/tests/Makefile index 272a112..589bfef 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,7 +21,7 @@ ZSOURCE += ../database-plain.c endif endif -all: ${PROJECT} run +all: ${PROJECT} run: ${PROJECT} $(QUIET)./${PROJECT} @@ -46,8 +46,8 @@ ${PROJECT}: options ${OBJECTS} ${OBJECTS}: ../config.mk clean: - $(QUIET)rm -rf ${OBJECTS} ${PROJECT} + $(QUIET)rm -rf ${OBJECTS} ${PROJECT} *.gcno *.gcda -.PHONY: all options clean debug +.PHONY: all options clean debug run -include $(wildcard .depend/*.dep) diff --git a/utils.c b/utils.c index 36c9cc1..afc88fa 100644 --- a/utils.c +++ b/utils.c @@ -7,7 +7,7 @@ #include #include #include -#include "math.h" +#include #include "utils.h" #include "zathura.h" @@ -263,7 +263,8 @@ recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle) void set_adjustment(GtkAdjustment* adjustment, gdouble value) { - gtk_adjustment_set_value(adjustment, MAX(adjustment->lower, MIN(adjustment->upper - adjustment->page_size, value))); + gtk_adjustment_set_value(adjustment, MAX(gtk_adjustment_get_lower(adjustment), + MIN(gtk_adjustment_get_upper(adjustment) - gtk_adjustment_get_page_size(adjustment), value))); } void diff --git a/utils.h b/utils.h index 38124ca..331ef77 100644 --- a/utils.h +++ b/utils.h @@ -74,7 +74,8 @@ void page_calculate_offset(zathura_page_t* page, page_offset_t* offset); /** * Rotate a rectangle by 0, 90, 180 or 270 degree - * @param rect the rectangle to rotate + * + * @param rectangle the rectangle to rotate * @param degree rotation degree * @param height the height of the enclosing rectangle * @param width the width of the enclosing rectangle diff --git a/zathura.1 b/zathura.1 deleted file mode 100644 index a38bb6a..0000000 --- a/zathura.1 +++ /dev/null @@ -1,27 +0,0 @@ -.TH ZATHURA 1 zathura\-VERSION - -.SH NAME -zathura \- a document viewer - -.SH SYNOPSIS -.B zathura -.RB [options] -.RB [file] -.RB [password] - -.SH DESCRIPTION -zathura is a highly customizable and functional document viewer. - -.SH OPTIONS -.TP -.B "-e xid" -Reparents to window specified by xid. -.TP -.B "-c path" -Path to the config directory. -.TP -.B "-d path" -Path to the data directory. -.TP -.B "-p path" -Path to the plugin directory. diff --git a/zathura.1.rst b/zathura.1.rst new file mode 100644 index 0000000..989431e --- /dev/null +++ b/zathura.1.rst @@ -0,0 +1,153 @@ +======= +zathura +======= + +----------------- +a document viewer +----------------- + +:Author: pwmt.org +:Date: VERSION +:Manual section: 1 + +SYNOPOSIS +========= +| zathura [OPTION]... +| zathura [OPTION]... FILE +| zathura [OPTION]... FILE PASSWORD + +DESCRIPTION +=========== +zathura is a highly customizable and functional document viewer. It provides a +minimalistic and space saving interface as well as an easy usage that mainly +focuses on keyboard interaction. + +OPTIONS +======= + +-e [xid], --reparent [xid] + Reparents to window specified by xid + +-c [path], --config-dir [path] + Path to the config directory + +-d [path], --data-dir [path] + Path to the data directory + +-p [path], --plugins-dir [path] + Path to the directory containing plugins + +--fork + Fork into the background + +MOUSE AND KEY BINDINGS +====================== + +J, K + Go to the next or previous page +h, k, j, l + Scroll to the left, down, up or right direction +Left, Down, Up, Right + Scroll to the left, down, up or right direction +^d, ^u + Scroll a half page down or up +^f, ^b, space, + Scroll a full page down or up +gg, G, nG + Goto to the first, the last or to the nth page +^c, Escape + Abort +a, s + Adjust window in best-fit or width mode +/, ? + Search for text +n, N + Search for the next or previous result +o, O + Open document +f + Follow links +\: + Enter command +r + Rotate by 90 degrees +^i + Recolor +R + Reload document +Tab + Show index and switch to **Index mode** +F5 + Switch to fullscreen mode +^m + Toggle inputbar +^n + Toggle statusbar ++, -, = + Zoom in, out or to the original size +zI, zO, z0 + Zoom in, out or to the original size +n= + Zoom to size n +mX + Set a quickmark to a letter or number X +'X + Goto quickmark saved at letter or number X +q + Quit + +Index mode +---------- + +k, j + Move to upper or lower entry +l + Expand entry +L + Expand all entries +h + Collapse entry +H + Collapse all entries +space, Return + Select and open entry + +Mouse bindings +-------------- +Scroll + Scroll up or down +^Scroll + Zoom in or out +Hold Button2 + Pan the document +Button1 + Follow link + +COMMANDS +======== +bmark + Save a bookmark +bdelete + Delete a bookmark +blist + List bookmarks +close + Close document +info + Show document information +help + Show help page +open, o + Open a document +print + Print document +write, write! + Save document (and force overwriting) +export + Export attachments + +CONFIGURATION +============= +The default appearance and behaviour of zathura can be overwritten by modifying +the *zathurarc* file (default path: ~/.config/zathura/zathurarc). For a detailed +description please visit http://pwmt.org/projects/zathura/configuration diff --git a/zathura.c b/zathura.c index a90177f..a31e7f7 100644 --- a/zathura.c +++ b/zathura.c @@ -38,7 +38,12 @@ zathura_t* zathura_init(int argc, char* argv[]) { /* parse command line options */ +#if (GTK_MAJOR_VERSION == 2) GdkNativeWindow embed = 0; +#else + Window embed = 0; +#endif + gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; bool forkback = false; GOptionEntry entries[] = @@ -55,7 +60,7 @@ zathura_init(int argc, char* argv[]) g_option_context_add_main_entries(context, entries, NULL); GError* error = NULL; - if (!g_option_context_parse(context, &argc, &argv, &error)) + if (g_option_context_parse(context, &argc, &argv, &error) == false) { printf("Error parsing command line arguments: %s\n", error->message); g_option_context_free(context); @@ -86,7 +91,7 @@ zathura_init(int argc, char* argv[]) zathura->plugins.type_plugin_mapping = girara_list_new2( (girara_free_function_t)zathura_type_plugin_mapping_free); - if (config_dir) { + if (config_dir != NULL) { zathura->config.config_dir = g_strdup(config_dir); } else { gchar* path = girara_get_xdg_path(XDG_CONFIG); @@ -94,7 +99,7 @@ zathura_init(int argc, char* argv[]) g_free(path); } - if (data_dir) { + if (data_dir != NULL) { zathura->config.data_dir = g_strdup(config_dir); } else { gchar* path = girara_get_xdg_path(XDG_DATA); @@ -106,7 +111,7 @@ zathura_init(int argc, char* argv[]) g_mkdir_with_parents(zathura->config.config_dir, 0771); g_mkdir_with_parents(zathura->config.data_dir, 0771); - if (plugin_path) { + if (plugin_path != NULL) { girara_list_t* paths = girara_split_path_array(plugin_path); girara_list_merge(zathura->plugins.path, paths); girara_list_free(paths); @@ -163,6 +168,7 @@ zathura_init(int argc, char* argv[]) /* initialize girara */ zathura->ui.session->gtk.embed = embed; + if (girara_session_init(zathura->ui.session, "zathura") == false) { goto error_out; } @@ -172,11 +178,11 @@ zathura_init(int argc, char* argv[]) /* page view */ zathura->ui.page_widget = gtk_table_new(0, 0, TRUE); - if (!zathura->ui.page_widget) { + if (zathura->ui.page_widget == NULL) { goto error_free; } - g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "size-allocate", G_CALLBACK(cb_view_resized), zathura); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "size-allocate", G_CALLBACK(cb_view_resized), zathura); /* callbacks */ GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); @@ -186,7 +192,7 @@ zathura_init(int argc, char* argv[]) /* page view alignment */ zathura->ui.page_widget_alignment = gtk_alignment_new(0.5, 0.5, 0, 0); - if (!zathura->ui.page_widget_alignment) { + if (zathura->ui.page_widget_alignment == NULL) { goto error_free; } gtk_container_add(GTK_CONTAINER(zathura->ui.page_widget_alignment), zathura->ui.page_widget); @@ -205,7 +211,7 @@ zathura_init(int argc, char* argv[]) } zathura->ui.statusbar.page_number = girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); - if (!zathura->ui.statusbar.page_number) { + if (zathura->ui.statusbar.page_number == NULL) { goto error_free; } @@ -221,28 +227,6 @@ zathura_init(int argc, char* argv[]) gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_widget), zathura->global.page_padding); gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_widget), zathura->global.page_padding); - /* parse colors */ - char* string_value = NULL; - girara_setting_get(zathura->ui.session, "recolor-darkcolor", &string_value); - if (string_value != NULL) { - gdk_color_parse(string_value, &(zathura->ui.colors.recolor_dark_color)); - g_free(string_value); - } - - string_value = NULL; - girara_setting_get(zathura->ui.session, "recolor-lightcolor", &string_value); - if (string_value != NULL) { - gdk_color_parse(string_value, &(zathura->ui.colors.recolor_light_color)); - g_free(string_value); - } - - string_value = NULL; - girara_setting_get(zathura->ui.session, "highlight-color", &string_value); - if (string_value != NULL) { - gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color)); - g_free(string_value); - } - /* database */ zathura->database = zathura_db_init(zathura->config.data_dir); if (zathura->database == NULL) { @@ -260,18 +244,18 @@ zathura_init(int argc, char* argv[]) document_info->zathura = zathura; document_info->path = argv[1]; document_info->password = (argc >= 2) ? argv[2] : NULL; - g_idle_add(document_info_open, document_info); + gdk_threads_add_idle(document_info_open, document_info); } return zathura; error_free: - if (zathura->ui.page_widget) { + if (zathura->ui.page_widget != NULL) { g_object_unref(zathura->ui.page_widget); } - if (zathura->ui.page_widget_alignment) { + if (zathura->ui.page_widget_alignment != NULL) { g_object_unref(zathura->ui.page_widget_alignment); } @@ -289,7 +273,7 @@ zathura_free(zathura_t* zathura) return; } - document_close(zathura); + document_close(zathura, false); if (zathura->ui.session != NULL) { girara_session_destroy(zathura->ui.session); @@ -308,7 +292,7 @@ zathura_free(zathura_t* zathura) zathura_db_free(zathura->database); /* free print settings */ - if(zathura->print.settings != NULL) { + if (zathura->print.settings != NULL) { g_object_unref(zathura->print.settings); } @@ -414,16 +398,46 @@ document_info_open(gpointer data) bool document_open(zathura_t* zathura, const char* path, const char* password) { - if (!path) { + if (path == NULL) { goto error_out; } zathura_document_t* document = zathura_document_open(zathura, path, password); - if (!document) { + if (document == NULL) { goto error_out; } + /* install file monitor */ + gchar* file_uri = g_filename_to_uri(document->file_path, NULL, NULL); + if (file_uri == NULL) { + goto error_free; + } + + zathura->file_monitor.file = g_file_new_for_uri(file_uri); + if (zathura->file_monitor.file == NULL) { + goto error_free; + } + + zathura->file_monitor.monitor = g_file_monitor_file(zathura->file_monitor.file, G_FILE_MONITOR_NONE, NULL, NULL); + if (zathura->file_monitor.monitor == NULL) { + goto error_free; + } + + g_signal_connect(G_OBJECT(zathura->file_monitor.monitor), "changed", G_CALLBACK(cb_file_monitor), zathura->ui.session); + + zathura->file_monitor.file_path = g_strdup(document->file_path); + if (zathura->file_monitor.file_path == NULL) { + goto error_free; + } + + if (document->password != NULL) { + zathura->file_monitor.password = g_strdup(document->password); + if (zathura->file_monitor.password == NULL) { + goto error_free; + } + } + zathura->document = document; /* view mode */ @@ -436,7 +450,7 @@ document_open(zathura_t* zathura, const char* path, const char* password) /* threads */ zathura->sync.render_thread = render_init(zathura); - if (!zathura->sync.render_thread) { + if (zathura->sync.render_thread == NULL) { goto error_free; } @@ -447,17 +461,21 @@ document_open(zathura_t* zathura, const char* path, const char* password) } /* bookmarks */ - if (!zathura_bookmarks_load(zathura, zathura->document->file_path)) { - girara_warning("Failed to load bookmarks for %s.\n", zathura->document->file_path); - } + zathura_bookmarks_load(zathura, zathura->document->file_path); - page_set_delayed(zathura, document->current_page_number - 1); + page_set_delayed(zathura, document->current_page_number); cb_view_vadjustment_value_changed(NULL, zathura); + free(file_uri); + return true; error_free: + if (file_uri != NULL) { + g_free(file_uri); + } + zathura_document_free(document); error_out: @@ -473,7 +491,7 @@ document_save(zathura_t* zathura, const char* path, bool overwrite) g_return_val_if_fail(path, false); gchar* file_path = girara_fix_path(path); - if (!overwrite && g_file_test(file_path, G_FILE_TEST_EXISTS)) + if ((overwrite == false) && g_file_test(file_path, G_FILE_TEST_EXISTS)) { girara_error("File already exists: %s. Use :write! to overwrite it.", file_path); g_free(file_path); @@ -488,20 +506,44 @@ document_save(zathura_t* zathura, const char* path, bool overwrite) static void remove_page_from_table(GtkWidget* page, gpointer permanent) { - if (!permanent) { + if (permanent == false) { g_object_ref(G_OBJECT(page)); } - gtk_container_remove(GTK_CONTAINER(page->parent), page); + gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(page)), page); } bool -document_close(zathura_t* zathura) +document_close(zathura_t* zathura, bool keep_monitor) { - if (!zathura->document) { + if (zathura == NULL || zathura->document == NULL) { return false; } + /* remove monitor */ + if (keep_monitor == false) { + if (zathura->file_monitor.monitor != NULL) { + g_file_monitor_cancel(zathura->file_monitor.monitor); + g_object_unref(zathura->file_monitor.monitor); + zathura->file_monitor.monitor = NULL; + } + + if (zathura->file_monitor.file != NULL) { + g_object_unref(zathura->file_monitor.file); + zathura->file_monitor.file = NULL; + } + + if (zathura->file_monitor.file_path != NULL) { + g_free(zathura->file_monitor.file_path); + zathura->file_monitor.file_path = NULL; + } + + if (zathura->file_monitor.password != NULL) { + g_free(zathura->file_monitor.password); + zathura->file_monitor.password = NULL; + } + } + /* store last seen page */ zathura_db_set_fileinfo(zathura->database, zathura->document->file_path, zathura->document->current_page_number, /* zathura->document->offset TODO */ 0, zathura->document->scale, @@ -553,7 +595,7 @@ page_set_delayed(zathura_t* zathura, unsigned int page_id) page_set_delayed_t* p = g_malloc(sizeof(page_set_delayed_t)); p->zathura = zathura; p->page = page_id; - g_idle_add(page_set_delayed_impl, p); + gdk_threads_add_idle(page_set_delayed_impl, p); return true; } @@ -571,10 +613,12 @@ page_set(zathura_t* zathura, unsigned int page_id) /* render page */ zathura_page_t* page = zathura->document->pages[page_id]; - if (!page) { + if (page == NULL) { goto error_out; } + zathura->document->current_page_number = page_id; + page_offset_t offset; page_calculate_offset(page, &offset); diff --git a/zathura.desktop b/zathura.desktop index b2b7807..57fe73e 100644 --- a/zathura.desktop +++ b/zathura.desktop @@ -7,4 +7,4 @@ Comment[de]=Ein minimalistischer Dokumenten-Betrachter Exec=zathura %f Terminal=false Categories=Office;Viewer; -MimeType=application/pdf;application/postscript;image/vnd.djvu; +MimeType=application/pdf;application/postscript;application/eps;application/x-eps;image/eps;image/x-eps;image/vnd.djvu; diff --git a/zathura.h b/zathura.h index c769474..c2d767d 100644 --- a/zathura.h +++ b/zathura.h @@ -14,9 +14,9 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, DELETE_LAST_WORD, DELETE_LAST_CHAR, DEFAULT, ERROR, WARNING, NEXT_GROUP, PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD, BACKWARD, ADJUST_BESTFIT, ADJUST_WIDTH, ADJUST_NONE, CONTINUOUS, DELETE_LAST, - ADD_MARKER, EVAL_MARKER, EXPAND, COLLAPSE, SELECT, GOTO_DEFAULT, GOTO_LABELS, - GOTO_OFFSET, HALF_UP, HALF_DOWN, FULL_UP, FULL_DOWN, NEXT_CHAR, PREVIOUS_CHAR, - DELETE_TO_LINE_START, APPEND_FILEPATH }; + ADD_MARKER, EVAL_MARKER, EXPAND, EXPAND_ALL, COLLAPSE_ALL, COLLAPSE, SELECT, + GOTO_DEFAULT, GOTO_LABELS, GOTO_OFFSET, HALF_UP, HALF_DOWN, FULL_UP, + FULL_DOWN, NEXT_CHAR, PREVIOUS_CHAR, DELETE_TO_LINE_START, APPEND_FILEPATH }; /* forward declaration for types from document.h */ struct zathura_document_s; @@ -50,6 +50,7 @@ typedef struct zathura_s GdkColor recolor_dark_color; /**< Dark color for recoloring */ GdkColor recolor_light_color; /**< Light color for recoloring */ GdkColor highlight_color; /**< Color for highlighting */ + GdkColor highlight_color_active; /** Color for highlighting */ } colors; GtkWidget *page_widget_alignment; @@ -108,6 +109,16 @@ typedef struct zathura_s zathura_document_t* document; /**< The current document */ zathura_database_t* database; /**< The database */ + + /** + * File monitor + */ + struct { + GFileMonitor* monitor; /**< File monitor */ + GFile* file; /**< File for file monitor */ + gchar* file_path; /**< Save file path */ + gchar* password; /**< Save password */ + } file_monitor; } zathura_t; /** @@ -152,9 +163,10 @@ bool document_save(zathura_t* zathura, const char* path, bool overwrite); * Closes the current opened document * * @param zathura The zathura session + * @param keep_monitor Set to true if monitor should be kept (sc_reload) * @return If no error occured true, otherwise false, is returned. */ -bool document_close(zathura_t* zathura); +bool document_close(zathura_t* zathura, bool keep_monitor); /** * Opens the page with the given number diff --git a/zathura.pc.in b/zathura.pc.in index 6e36e4f..659ca85 100644 --- a/zathura.pc.in +++ b/zathura.pc.in @@ -6,4 +6,4 @@ Description: document viewer Version: ${version} URL: http://pwmt.org/projects/zathura Cflags: ${INC_PATH} -Libs: +Requires.private: girara-gtk${GTK_VERSION} gtk+-${GTK_VERSION}-0 diff --git a/zathurarc.5.rst b/zathurarc.5.rst index 7449e73..977269d 100644 --- a/zathurarc.5.rst +++ b/zathurarc.5.rst @@ -1,272 +1,28 @@ -=========== - zathurarc -=========== +========= +zathurarc +========= -------------------------- zathura configuration file -------------------------- :Author: pwmt.org -:Date: 02.02.2012 +:Date: VERSION :Manual section: 5 -SYNOPOSIS -========= +SYNOPSIS +======== /etc/zathurarc, $XDG_CONFIG_HOME/zathura/zathurarc DESCRIPTION =========== -The zathurarc file is a simple plain text file that can be populated with -various commands to change the behaviour and the look of zathura which we are -going to describe in the following subsections. Each line (besides empty lines -and comments (which start with a prepended #)) is evaluated on its own, so it is -not possible to write multiple commands in one single line. +The *zathurarc* file is a simple plain text file that can be populated with +various commands to change the behaviour and the look of zathura. -The following commands can be used: - -set - Changing the options --------------------------- - -In addition to the build-in :set command zathura offers more options to be -changed and makes those changes permanent. To overwrite an option you just have -to add a line structured like the following: - -:: - set