From 38ec3eea666cae72c606517e982e897039f0afc4 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 10 Nov 2010 19:18:01 +0100 Subject: [PATCH 001/197] New file structure --- .gitignore | 4 + LICENSE | 2 +- Makefile | 17 +- callbacks.c | 0 callbacks.h | 0 commands.c | 0 commands.h | 0 config.c | 0 config.def.h | 349 ---- config.mk | 2 +- ft/document.h | 0 ft/pdf/pdf.c | 0 ft/pdf/pdf.h | 0 shortcuts.c | 0 shortcuts.h | 0 utils.c | 0 utils.h | 0 zathura.c | 4590 +------------------------------------------------ zathura.h | 25 + 19 files changed, 45 insertions(+), 4944 deletions(-) create mode 100644 .gitignore create mode 100644 callbacks.c create mode 100644 callbacks.h create mode 100644 commands.c create mode 100644 commands.h create mode 100644 config.c delete mode 100644 config.def.h create mode 100644 ft/document.h create mode 100644 ft/pdf/pdf.c create mode 100644 ft/pdf/pdf.h create mode 100644 shortcuts.c create mode 100644 shortcuts.h create mode 100644 utils.c create mode 100644 utils.h create mode 100644 zathura.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e3120a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +*~ +*.rej +*.swp diff --git a/LICENSE b/LICENSE index 05b00df..8e5bef0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 ML, JY - pwmt.org +Copyright (c) 2010 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 f4c5503..9623fbb 100644 --- a/Makefile +++ b/Makefile @@ -25,16 +25,8 @@ options: @echo CC $< @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -${OBJECTS}: config.h config.mk -${DOBJECTS}: config.h config.mk - -config.h: config.def.h - @if [ -f $@ ] ; then \ - echo "config.h exists, but config.def.h is newer. Please check your" \ - "config.h or ${PROJECT} might fail to build." ; \ - else \ - cp $< $@ ; \ - fi +${OBJECTS}: config.mk +${DOBJECTS}: config.mk ${PROJECT}: ${OBJECTS} @echo CC -o $@ @@ -44,9 +36,6 @@ clean: @rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ ${DOBJECTS} ${PROJECT}-debug -distclean: clean - @rm -rf config.h - ${PROJECT}-debug: ${DOBJECTS} @echo CC -o ${PROJECT}-debug @${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS} @@ -62,7 +51,7 @@ gdb: debug dist: clean @mkdir -p ${PROJECT}-${VERSION} - @cp -R LICENSE Makefile config.mk config.def.h README \ + @cp -R LICENSE Makefile config.mk README \ ${PROJECT}.1 ${SOURCE} ${PROJECT}-${VERSION} @tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION} @gzip ${PROJECT}-${VERSION}.tar diff --git a/callbacks.c b/callbacks.c new file mode 100644 index 0000000..e69de29 diff --git a/callbacks.h b/callbacks.h new file mode 100644 index 0000000..e69de29 diff --git a/commands.c b/commands.c new file mode 100644 index 0000000..e69de29 diff --git a/commands.h b/commands.h new file mode 100644 index 0000000..e69de29 diff --git a/config.c b/config.c new file mode 100644 index 0000000..e69de29 diff --git a/config.def.h b/config.def.h deleted file mode 100644 index e18e409..0000000 --- a/config.def.h +++ /dev/null @@ -1,349 +0,0 @@ -/* settings */ -int default_width = 800; -int default_height = 600; -float zoom_step = 10; -float zoom_min = 10; -float zoom_max = 400; -float scroll_step = 40; -float transparency = 0.4; -float smooth_scrolling = 0.0; -int n_completion_items = 15; - -/* completion */ -static const char FORMAT_COMMAND[] = "%s"; -static const char FORMAT_DESCRIPTION[] = "%s"; - -/* Use XDG directory specification if no config and data directory are given on - * the command line. Uncomment the next line if you just want to use CONFIG_DIR - * and DATA_DIR instead (these will be the default locations if the XDG_* - * environment variebles are not set anyway) */ -/* #define ZATHURA_NO_XDG */ - -/* directories and files */ -static const char BOOKMARK_FILE[] = "bookmarks"; -static const char ZATHURA_RC[] = "zathurarc"; -static const char GLOBAL_RC[] = "/etc/zathurarc"; -static const char CONFIG_DIR[] = "~/.config/zathura"; -static const char DATA_DIR[] = "~/.local/share/zathura"; - -/* bookmarks */ -static const char BM_PAGE_ENTRY[] = "page"; -static const char BM_PAGE_OFFSET[] = "offset"; - -/* look */ -char* font = "monospace normal 9"; -char* default_bgcolor = "#000000"; -char* default_fgcolor = "#DDDDDD"; -char* inputbar_bgcolor = "#141414"; -char* inputbar_fgcolor = "#9FBC00"; -char* statusbar_bgcolor = "#000000"; -char* statusbar_fgcolor = "#FFFFFF"; -char* completion_fgcolor = "#DDDDDD"; -char* completion_bgcolor = "#232323"; -char* completion_g_fgcolor = "#DEDEDE"; -char* completion_g_bgcolor = "#FF00FF"; -char* completion_hl_fgcolor = "#232323"; -char* completion_hl_bgcolor = "#9FBC00"; -char* notification_e_bgcolor = "#FF1212"; -char* notification_e_fgcolor = "#FFFFFF"; -char* notification_w_bgcolor = "#FFF712"; -char* notification_w_fgcolor = "#000000"; -char* recolor_darkcolor = "#353535"; -char* recolor_lightcolor = "#DBDBDB"; - -char* search_highlight = "#9FBC00"; -char* select_text = "#000000"; - -/* statusbar */ -char* default_text = "[No Name]"; - -/* printing */ -char* list_printer_command = "lpstat -v | sed -n '/^.*device for \\(.*\\): .*$/s//\\1/p'"; -char* print_command = "lp -d '%s' -P %s %s %s"; /* printer / pages / file */ - -/* open uri */ -char* uri_command = "firefox %s"; /* uri */ - -/* additional settings */ -gboolean show_scrollbars = FALSE; -gboolean scroll_wrap = FALSE; -int adjust_open = ADJUST_BESTFIT; -#define SELECTION_STYLE POPPLER_SELECTION_GLYPH -#define GOTO_MODE GOTO_LABELS /* GOTO_DEFAULT, GOTO_LABELS, GOTO_OFFSET */ - -/* define additional modes */ -#define INSERT (1 << 4) -#define VISUAL (1 << 5) -#define EMACS_CX (1 << 6) - -/* mode names */ -ModeName mode_names[] = { - /* default mode names */ - {"all", ALL, ""}, - {"fullscreen", FULLSCREEN, ""}, - {"index", INDEX, ""}, - {"normal", NORMAL, ""}, - /* additional mode names */ - {"insert", INSERT, "-- INSERT --"}, - {"visual", VISUAL, "-- VISUAL --"} -}; - -/* shortcuts */ -Shortcut shortcuts[] = { - /* mask, key, function, mode, argument */ - {GDK_CONTROL_MASK, GDK_c, sc_abort, ALL, {0} }, - {0, GDK_a, sc_adjust_window, NORMAL, { ADJUST_BESTFIT } }, - {0, GDK_s, sc_adjust_window, NORMAL, { ADJUST_WIDTH } }, - {0, GDK_Escape, sc_abort, ALL, {0} }, - {0, GDK_BackSpace, sc_change_buffer, ALL, { DELETE_LAST } }, - {0, GDK_i, sc_change_mode, NORMAL, { INSERT } }, - {0, GDK_v, sc_change_mode, NORMAL, { VISUAL } }, - {0, GDK_m, sc_change_mode, NORMAL, { ADD_MARKER } }, - {0, GDK_apostrophe, sc_change_mode, NORMAL, { EVAL_MARKER } }, - {0, GDK_slash, sc_focus_inputbar, NORMAL, { .data = "/" } }, - {GDK_SHIFT_MASK, GDK_slash, sc_focus_inputbar, NORMAL, { .data = "/" } }, - {GDK_SHIFT_MASK, GDK_question, sc_focus_inputbar, NORMAL, { .data = "?" } }, - {0, GDK_colon, sc_focus_inputbar, NORMAL, { .data = ":" } }, - {0, GDK_o, sc_focus_inputbar, NORMAL, { .data = ":open " } }, - {0, GDK_O, sc_focus_inputbar, NORMAL, { APPEND_FILEPATH, .data = ":open " } }, - {0, GDK_f, sc_follow, NORMAL, {0} }, - {0, GDK_J, sc_navigate, NORMAL, { NEXT } }, - {0, GDK_K, sc_navigate, NORMAL, { PREVIOUS } }, - {GDK_MOD1_MASK, GDK_Right, sc_navigate, NORMAL, { NEXT } }, - {GDK_MOD1_MASK, GDK_Left, sc_navigate, NORMAL, { PREVIOUS } }, - {0, GDK_Left, sc_navigate, FULLSCREEN, { PREVIOUS } }, - {0, GDK_Up, sc_navigate, FULLSCREEN, { PREVIOUS } }, - {0, GDK_Down, sc_navigate, FULLSCREEN, { NEXT } }, - {0, GDK_Right, sc_navigate, FULLSCREEN, { NEXT } }, - {0, GDK_space, sc_navigate, FULLSCREEN, { NEXT } }, - {0, GDK_k, sc_navigate_index, INDEX, { UP } }, - {0, GDK_j, sc_navigate_index, INDEX, { DOWN } }, - {0, GDK_h, sc_navigate_index, INDEX, { COLLAPSE } }, - {0, GDK_l, sc_navigate_index, INDEX, { EXPAND } }, - {0, GDK_space, sc_navigate_index, INDEX, { SELECT } }, - {0, GDK_Return, sc_navigate_index, INDEX, { SELECT } }, - {GDK_CONTROL_MASK, GDK_i, sc_recolor, NORMAL, {0} }, - {0, GDK_R, sc_reload, NORMAL, {0} }, - {0, GDK_r, sc_rotate, NORMAL, {0} }, - {0, GDK_n, sc_search, NORMAL, { FORWARD } }, - {0, GDK_N, sc_search, NORMAL, { BACKWARD } }, - {0, GDK_h, sc_scroll, NORMAL, { LEFT } }, - {0, GDK_j, sc_scroll, NORMAL, { DOWN } }, - {0, GDK_k, sc_scroll, NORMAL, { UP } }, - {0, GDK_l, sc_scroll, NORMAL, { RIGHT } }, - {0, GDK_Left, sc_scroll, NORMAL, { LEFT } }, - {0, GDK_Up, sc_scroll, NORMAL, { UP } }, - {0, GDK_Down, sc_scroll, NORMAL, { DOWN } }, - {0, GDK_Right, sc_scroll, NORMAL, { RIGHT } }, - {GDK_CONTROL_MASK, GDK_d, sc_scroll, NORMAL, { HALF_DOWN } }, - {GDK_CONTROL_MASK, GDK_u, sc_scroll, NORMAL, { HALF_UP } }, - {GDK_CONTROL_MASK, GDK_f, sc_scroll, NORMAL, { FULL_DOWN } }, - {GDK_CONTROL_MASK, GDK_b, sc_scroll, NORMAL, { FULL_UP } }, - {0, GDK_space, sc_scroll, NORMAL, { FULL_DOWN } }, - {0, GDK_0, sc_switch_goto_mode, NORMAL, {0} }, - {0, GDK_F5, sc_toggle_fullscreen, NORMAL | FULLSCREEN, {0} }, - {0, GDK_Tab, sc_toggle_index, NORMAL | INDEX, {0} }, - {GDK_CONTROL_MASK, GDK_m, sc_toggle_inputbar, NORMAL, {0} }, - {GDK_CONTROL_MASK, GDK_n, sc_toggle_statusbar, NORMAL, {0} }, - {GDK_CONTROL_MASK, GDK_q, sc_quit, ALL, {0} }, - {0, GDK_plus, sc_zoom, NORMAL | FULLSCREEN, { ZOOM_IN } }, - {0, GDK_minus, sc_zoom, NORMAL | FULLSCREEN, { ZOOM_OUT } }, - {0, GDK_equal, sc_zoom, NORMAL | FULLSCREEN, { ZOOM_ORIGINAL } }, -}; - -/* inputbar shortcuts */ -InputbarShortcut inputbar_shortcuts[] = { - /* mask, key, function, argument */ - {0, GDK_Escape, isc_abort, {0} }, - {GDK_CONTROL_MASK, GDK_c, isc_abort, {0} }, - {0, GDK_Up, isc_command_history, {0} }, - {0, GDK_Down, isc_command_history, {0} }, - {0, GDK_Tab, isc_completion, { NEXT } }, - {GDK_CONTROL_MASK, GDK_Tab, isc_completion, { NEXT_GROUP } }, - {0, GDK_ISO_Left_Tab, isc_completion, { PREVIOUS } }, - {GDK_CONTROL_MASK, GDK_ISO_Left_Tab, isc_completion, { PREVIOUS_GROUP } }, - {0, GDK_BackSpace, isc_string_manipulation, { DELETE_LAST_CHAR } }, - {GDK_CONTROL_MASK, GDK_h, isc_string_manipulation, { DELETE_LAST_CHAR } }, - {GDK_CONTROL_MASK, GDK_u, isc_string_manipulation, { DELETE_TO_LINE_START } }, - {GDK_CONTROL_MASK, GDK_w, isc_string_manipulation, { DELETE_LAST_WORD } }, - {GDK_CONTROL_MASK, GDK_f, isc_string_manipulation, { NEXT_CHAR } }, - {GDK_CONTROL_MASK, GDK_b, isc_string_manipulation, { PREVIOUS_CHAR } }, -}; - -/* mouse settings */ -MouseScrollEvent mouse_scroll_events[] = { - /* direction, function, argument */ - {GDK_SCROLL_LEFT, sc_scroll, { LEFT } }, - {GDK_SCROLL_UP, sc_scroll, { UP } }, - {GDK_SCROLL_DOWN, sc_scroll, { DOWN } }, - {GDK_SCROLL_RIGHT, sc_scroll, { RIGHT } }, -}; - -/* commands */ -Command commands[] = { - /* command, abbreviation, function, completion, description */ - {"blist", 0, cmd_open_bookmark, cc_bookmark, "List and open bookmark" }, - {"bmark", "b", cmd_bookmark, 0, "Bookmark current page" }, - {"close", "c", cmd_close, 0, "Close current file" }, - {"coffset", 0, cmd_correct_offset, 0, "Correct page offset" }, - {"delbmark", 0, cmd_delete_bookmark, cc_bookmark, "Bookmark current page" }, - {"export", "e", cmd_export, cc_export, "Export images or attached files" }, - {"info", "i", cmd_info, 0, "Show information about the document" }, - {"map", "m", cmd_map, 0, "Map keybinding to a function" }, - {"open", "o", cmd_open, cc_open, "Open a file" }, - {"print", "p", cmd_print, cc_print, "Print the document" }, - {"quit", "q", cmd_quit, 0, "Quit zathura" }, - {"rotate", "r", cmd_rotate, 0, "Rotate the page" }, - {"set", "s", cmd_set, cc_set, "Set an option" }, - {"write", "w", cmd_save, 0, "Save the document" }, -}; - -/* buffer commands */ -BufferCommand buffer_commands[] = { - /* regex, function, argument */ - {"^gg$", bcmd_goto, { TOP } }, - {"^G$", bcmd_goto, { BOTTOM } }, - {"^[0-9]+G$", bcmd_goto, {0} }, - {"^zI$", bcmd_zoom, { ZOOM_IN } }, - {"^zO$", bcmd_zoom, { ZOOM_OUT } }, - {"^z0$", bcmd_zoom, { ZOOM_ORIGINAL } }, - {"^[0-9]+Z$", bcmd_zoom, { ZOOM_SPECIFIC } }, - {"^[0-9]+%$", bcmd_scroll, {0} }, -}; - -/* special commands */ -SpecialCommand special_commands[] = { - /* identifier, function, a, argument */ - {'/', scmd_search, 1, { DOWN } }, - {'?', scmd_search, 1, { UP } }, -}; - -/* settings */ -Setting settings[] = { - /* name, variable, type, render, re-init, description */ - {"adjust_open", &(adjust_open), 'i', FALSE, FALSE, "Adjust mode"}, - {"browser", &(uri_command), 's', FALSE, FALSE, "Command to open URIs"}, - {"completion_bgcolor", &(completion_bgcolor), 's', FALSE, TRUE, "Completion background color"}, - {"completion_fgcolor", &(completion_fgcolor), 's', FALSE, TRUE, "Completion foreground color"}, - {"completion_g_bgcolor", &(completion_g_bgcolor), 's', FALSE, TRUE, "Completion (group) background color"}, - {"completion_g_fgcolor", &(completion_g_fgcolor), 's', FALSE, TRUE, "Completion (group) foreground color"}, - {"completion_hl_bgcolor", &(completion_hl_bgcolor), 's', FALSE, TRUE, "Completion (highlight) background color"}, - {"completion_hl_fgcolor", &(completion_hl_fgcolor), 's', FALSE, TRUE, "Completion (highlight) foreground color"}, - {"default_bgcolor", &(default_bgcolor), 's', FALSE, TRUE, "Default background color"}, - {"default_fgcolor", &(default_fgcolor), 's', FALSE, TRUE, "Default foreground color"}, - {"default_text", &(default_text), 's', FALSE, FALSE, "Default text"}, - {"font", &(font), 's', FALSE, TRUE, "The used font" }, - {"height", &(default_height), 'i', FALSE, FALSE, "Default window height"}, - {"inputbar_bgcolor", &(inputbar_bgcolor), 's', FALSE, TRUE, "Inputbar background color"}, - {"inputbar_fgcolor", &(inputbar_fgcolor), 's', FALSE, TRUE, "Inputbar foreground color"}, - {"labels", &(Zathura.Global.enable_labelmode), 'b', FALSE, TRUE, "Allow label mode"}, - {"list_printer_command", &(list_printer_command), 's', FALSE, FALSE, "Command to list printers"}, - {"n_completion_items", &(n_completion_items), 'i', FALSE, FALSE, "Number of completion items"}, - {"notification_e_bgcolor", &(notification_e_bgcolor), 's', FALSE, TRUE, "Notification (error) background color"}, - {"notification_e_fgcolor", &(notification_e_fgcolor), 's', FALSE, TRUE, "Notification (error) foreground color"}, - {"notification_w_bgcolor", &(notification_w_bgcolor), 's', FALSE, TRUE, "Notification (warning) background color"}, - {"notification_w_fgcolor", &(notification_w_fgcolor), 's', FALSE, TRUE, "Notification (warning) foreground color"}, - {"offset", &(Zathura.PDF.page_offset), 'i', FALSE, FALSE, "Optional page offset" }, - {"print_command", &(print_command), 's', FALSE, FALSE, "Command to print"}, - {"recolor", &(Zathura.Global.recolor), 'b', TRUE, FALSE, "Invert the image" }, - {"recolor_darkcolor", &(recolor_darkcolor), 's', FALSE, TRUE, "Recoloring (dark color)"}, - {"recolor_lightcolor", &(recolor_lightcolor), 's', FALSE, TRUE, "Recoloring (light color)"}, - {"scroll_step", &(scroll_step), 'f', FALSE, FALSE, "Scroll step"}, - {"scroll_wrap", &(scroll_wrap), 'b', FALSE, FALSE, "Wrap scolling at last page"}, - {"scrollbars", &(show_scrollbars), 'b', FALSE, TRUE, "Show scrollbars"}, - {"show_statusbar", &(Zathura.Global.show_statusbar), 'b', FALSE, TRUE, "Show statusbar"}, - {"show_inputbar", &(Zathura.Global.show_inputbar), 'b', FALSE, TRUE, "Show inputbar"}, - {"search_highlight", &(search_highlight), 's', FALSE, TRUE, "Highlighted results"}, - {"select_text", &(select_text), 's', FALSE, TRUE, "Rectangle of the selected text"}, - {"smooth_scrolling", &(smooth_scrolling), 'f', FALSE, TRUE, "Smooth scrolling"}, - {"statusbar_bgcolor", &(statusbar_bgcolor), 's', FALSE, TRUE, "Statusbar background color"}, - {"statusbar_fgcolor", &(statusbar_fgcolor), 's', FALSE, TRUE, "Statusbar foreground color"}, - {"transparency", &(transparency), 'f', FALSE, FALSE, "Transparency of rectangles"}, - {"uri_command", &(uri_command), 's', FALSE, FALSE, "Command for opening URIs"}, - {"width", &(default_width), 'i', FALSE, FALSE, "Default window width"}, - {"zoom_max", &(zoom_max), 'f', FALSE, FALSE, "Zoom maximum"}, - {"zoom_min", &(zoom_min), 'f', FALSE, FALSE, "Zoom minimum"}, - {"zoom_step", &(zoom_step), 'f', FALSE, FALSE, "Zoom step"}, -}; - -/* shortcut names */ -ShortcutName shortcut_names[] = { - {"abort", sc_abort}, - {"adjust_window", sc_adjust_window}, - {"change_buffer", sc_change_buffer}, - {"change_mode", sc_change_mode}, - {"focus_inputbar", sc_focus_inputbar}, - {"follow", sc_follow}, - {"navigate", sc_navigate}, - {"navigate_index", sc_navigate_index}, - {"quit", sc_quit}, - {"recolor", sc_recolor}, - {"reload", sc_reload}, - {"rotate", sc_rotate}, - {"scroll", sc_scroll}, - {"search", sc_search}, - {"switch_goto_mode", sc_switch_goto_mode}, - {"toggle_fullscreen", sc_toggle_fullscreen}, - {"toggle_index", sc_toggle_index}, - {"toggle_inputbar", sc_toggle_inputbar}, - {"toggle_statusbar", sc_toggle_statusbar}, - {"zoom", sc_zoom}, -}; - -/* argument names */ -ArgumentName argument_names[] = { - {"add_marker", ADD_MARKER}, - {"backward", BACKWARD}, - {"bestfit", ADJUST_BESTFIT}, - {"collapse", COLLAPSE}, - {"delete_last", DELETE_LAST}, - {"down", DOWN}, - {"eval_marker", EVAL_MARKER}, - {"expand", EXPAND}, - {"forward", FORWARD}, - {"full_down", FULL_DOWN}, - {"full_up", FULL_UP}, - {"half_down", HALF_DOWN}, - {"half_up", HALF_UP}, - {"in", ZOOM_IN}, - {"insert", INSERT}, - {"left", LEFT}, - {"next", NEXT}, - {"original", ZOOM_ORIGINAL}, - {"out", ZOOM_OUT}, - {"previous", PREVIOUS}, - {"right", RIGHT}, - {"select", SELECT}, - {"up", UP}, - {"visual", VISUAL}, - {"width", ADJUST_WIDTH}, -}; - -/* special keys */ -GDKKey gdk_keys[] = { - {"", GDK_BackSpace}, - {"", GDK_Caps_Lock}, - {"", GDK_Down}, - {"", GDK_Escape}, - {"", GDK_F10}, - {"", GDK_F11}, - {"", GDK_F12}, - {"", GDK_F1}, - {"", GDK_F2}, - {"", GDK_F3}, - {"", GDK_F4}, - {"", GDK_F5}, - {"", GDK_F6}, - {"", GDK_F7}, - {"", GDK_F8}, - {"", GDK_F9}, - {"", GDK_Left}, - {"", GDK_Page_Down}, - {"", GDK_Page_Up}, - {"", GDK_Return}, - {"", GDK_Right}, - {"", GDK_space}, - {"", GDK_Super_L}, - {"", GDK_Tab}, - {"", GDK_Up}, -}; diff --git a/config.mk b/config.mk index a370180..c9a7738 100644 --- a/config.mk +++ b/config.mk @@ -12,7 +12,7 @@ GTK_INC = $(shell pkg-config --cflags gtk+-2.0 poppler-glib) GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0 poppler-glib) INCS = -I. -I/usr/include ${GTK_INC} -LIBS = -lc ${GTK_LIB} -lpthread -lm +LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara # flags CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) diff --git a/ft/document.h b/ft/document.h new file mode 100644 index 0000000..e69de29 diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c new file mode 100644 index 0000000..e69de29 diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h new file mode 100644 index 0000000..e69de29 diff --git a/shortcuts.c b/shortcuts.c new file mode 100644 index 0000000..e69de29 diff --git a/shortcuts.h b/shortcuts.h new file mode 100644 index 0000000..e69de29 diff --git a/utils.c b/utils.c new file mode 100644 index 0000000..e69de29 diff --git a/utils.h b/utils.h new file mode 100644 index 0000000..e69de29 diff --git a/zathura.c b/zathura.c index 2369a5d..cd40790 100644 --- a/zathura.c +++ b/zathura.c @@ -1,4600 +1,32 @@ /* See LICENSE file for license and copyright information */ -#define _BSD_SOURCE -#define _XOPEN_SOURCE 500 - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -/* macros */ -#define LENGTH(x) (sizeof(x)/sizeof((x)[0])) -#define CLEAN(m) (m & ~(GDK_MOD2_MASK) & ~(GDK_BUTTON1_MASK) & ~(GDK_BUTTON2_MASK) & ~(GDK_BUTTON3_MASK) & ~(GDK_BUTTON4_MASK) & ~(GDK_BUTTON5_MASK) & ~(GDK_LEAVE_NOTIFY_MASK)) -#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC) || defined(__clang__) -/* only gcc, clang and Intel's cc seem support this */ -#define NORETURN __attribute__((noreturn)) -#else -#define NORETURN -#endif - -/* enums */ -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 }; - -/* define modes */ -#define ALL (1 << 0) -#define FULLSCREEN (1 << 1) -#define INDEX (1 << 2) -#define NORMAL (1 << 3) - -/* typedefs */ -struct CElement -{ - char *value; - char *description; - struct CElement *next; -}; - -typedef struct CElement CompletionElement; - -struct CGroup -{ - char *value; - CompletionElement *elements; - struct CGroup *next; -}; - -typedef struct CGroup CompletionGroup; - -typedef struct -{ - CompletionGroup* groups; -} Completion; - -typedef struct -{ - char* command; - char* description; - int command_id; - gboolean is_group; - GtkWidget* row; -} CompletionRow; - -typedef struct -{ - int n; - void *data; -} Argument; - -typedef struct -{ - char* name; - int argument; -} ArgumentName; - -typedef struct -{ - int mask; - int key; - void (*function)(Argument*); - int mode; - Argument argument; -} Shortcut; - -typedef struct -{ - char* name; - int mode; - char* display; -} ModeName; - -typedef struct -{ - char* name; - void (*function)(Argument*); -} ShortcutName; - -typedef struct -{ - int mask; - int key; - void (*function)(Argument*); - Argument argument; -} InputbarShortcut; - -typedef struct -{ - int direction; - void (*function)(Argument*); - Argument argument; -} MouseScrollEvent; - -typedef struct -{ - char* command; - char* abbr; - gboolean (*function)(int, char**); - Completion* (*completion)(char*); - char* description; -} Command; - -typedef struct -{ - char* regex; - void (*function)(char*, Argument*); - Argument argument; -} BufferCommand; - -typedef struct -{ - char identifier; - gboolean (*function)(char*, Argument*); - int always; - Argument argument; -} SpecialCommand; - -struct SCList -{ - Shortcut element; - struct SCList *next; -}; - -typedef struct SCList ShortcutList; - -typedef struct -{ - char* identifier; - int key; -} GDKKey; - -typedef struct -{ - PopplerPage *page; - int id; - char *label; -} Page; - -typedef struct -{ - char* name; - void* variable; - char type; - gboolean render; - gboolean reinit; - char* description; -} Setting; - -typedef struct -{ - int id; - int page; -} Marker; - -typedef struct -{ - char* id; - int page; -} Bookmark; - -/* zathura */ -struct -{ - struct - { - GtkWidget *window; - GtkBox *box; - GtkBox *continuous; - GtkScrolledWindow *view; - GtkViewport *viewport; - GtkWidget *statusbar; - GtkBox *statusbar_entries; - GtkEntry *inputbar; - GtkWidget *index; - GtkWidget *information; - GtkWidget *drawing_area; - GtkWidget *document; - GdkNativeWindow embed; - } UI; - - struct - { - GdkColor default_fg; - GdkColor default_bg; - GdkColor inputbar_fg; - GdkColor inputbar_bg; - GdkColor statusbar_fg; - GdkColor statusbar_bg; - GdkColor completion_fg; - GdkColor completion_bg; - GdkColor completion_g_bg; - GdkColor completion_g_fg; - GdkColor completion_hl_fg; - GdkColor completion_hl_bg; - GdkColor notification_e_fg; - GdkColor notification_e_bg; - GdkColor notification_w_fg; - GdkColor notification_w_bg; - GdkColor recolor_darkcolor; - GdkColor recolor_lightcolor; - GdkColor search_highlight; - GdkColor select_text; - PangoFontDescription *font; - } Style; - - struct - { - GtkLabel *status_text; - GtkLabel *status_buffer; - GtkLabel *status_state; - GString *buffer; - GList *history; - int mode; - int viewing_mode; - gboolean recolor; - gboolean enable_labelmode; - int goto_mode; - int adjust_mode; - gboolean show_index; - gboolean show_statusbar; - gboolean show_inputbar; - } Global; - - struct - { - ShortcutList *sclist; - } Bindings; - - struct - { - gdouble x; - gdouble y; - } SelectPoint; - - struct - { - char* filename; - char* pages; - int scroll_percentage; - } State; - - struct - { - Marker* markers; - int number_of_markers; - int last; - } Marker; - - struct - { - GFileMonitor* monitor; - GFile* file; - } FileMonitor; - - struct - { - GKeyFile *data; - char *file; - Bookmark *bookmarks; - int number_of_bookmarks; - } Bookmarks; - - struct - { - PopplerDocument *document; - char *file; - char *password; - Page **pages; - int page_number; - int page_offset; - int number_of_pages; - int scale; - int rotate; - cairo_surface_t *surface; - } PDF; - - struct - { - GStaticMutex pdflib_lock; - GStaticMutex pdf_obj_lock; - GStaticMutex search_lock; - GStaticMutex select_lock; - } Lock; - - struct - { - GList* results; - int page; - gboolean draw; - } Search; - - struct - { - GThread* search_thread; - gboolean search_thread_running; - GThread* inotify_thread; - } Thread; - - struct - { - guint inputbar_activate; - guint inputbar_key_press_event; - } Handler; - - struct - { - gchar* config_dir; - gchar* data_dir; - } Config; - - struct - { - gchar* file; - } StdinSupport; -} Zathura; - - -/* function declarations */ -void init_look(void); -void init_directories(void); -void init_bookmarks(void); -void init_keylist(void); -void init_settings(void); -void init_zathura(void); -void add_marker(int); -void build_index(GtkTreeModel*, GtkTreeIter*, PopplerIndexIter*); -void change_mode(int); -void calculate_offset(GtkWidget*, double*, double*); -void close_file(gboolean); -void enter_password(void); -void highlight_result(int, PopplerRectangle*); -void draw(int); -void eval_marker(int); -void notify(int, const char*); -gboolean open_file(char*, char*); -gboolean open_stdin(gchar*); -void open_uri(char*); -void out_of_memory(void) NORETURN; -void update_status(void); -void read_configuration_file(const char*); -void read_configuration(void); -void recalcRectangle(int, PopplerRectangle*); -void setCompletionRowColor(GtkBox*, int, int); -void set_page(int); -void switch_view(GtkWidget*); -GtkEventBox* createCompletionRow(GtkBox*, char*, char*, gboolean); -gchar* fix_path(const gchar*); -gchar* path_from_env(const gchar*); -gchar* get_home_dir(void); - -Completion* completion_init(void); -CompletionGroup* completion_group_create(char*); -void completion_add_group(Completion*, CompletionGroup*); -void completion_free(Completion*); -void completion_group_add_element(CompletionGroup*, char*, char*); - -/* thread declaration */ -void* search(void*); - -/* shortcut declarations */ -void sc_abort(Argument*); -void sc_adjust_window(Argument*); -void sc_change_buffer(Argument*); -void sc_change_mode(Argument*); -void sc_focus_inputbar(Argument*); -void sc_follow(Argument*); -void sc_navigate(Argument*); -void sc_recolor(Argument*); -void sc_reload(Argument*); -void sc_rotate(Argument*); -void sc_scroll(Argument*); -void sc_search(Argument*); -void sc_switch_goto_mode(Argument*); -void sc_navigate_index(Argument*); -void sc_toggle_index(Argument*); -void sc_toggle_inputbar(Argument*); -void sc_toggle_fullscreen(Argument*); -void sc_toggle_statusbar(Argument*); -void sc_quit(Argument*); -void sc_zoom(Argument*); - -/* inputbar shortcut declarations */ -void isc_abort(Argument*); -void isc_command_history(Argument*); -void isc_completion(Argument*); -void isc_string_manipulation(Argument*); - -/* command declarations */ -gboolean cmd_bookmark(int, char**); -gboolean cmd_open_bookmark(int, char**); -gboolean cmd_close(int, char**); -gboolean cmd_correct_offset(int, char**); -gboolean cmd_delete_bookmark(int, char**); -gboolean cmd_export(int, char**); -gboolean cmd_info(int, char**); -gboolean cmd_map(int, char**); -gboolean cmd_open(int, char**); -gboolean cmd_print(int, char**); -gboolean cmd_rotate(int, char**); -gboolean cmd_set(int, char**); -gboolean cmd_quit(int, char**); -gboolean cmd_save(int, char**); - -/* completion commands */ -Completion* cc_bookmark(char*); -Completion* cc_export(char*); -Completion* cc_open(char*); -Completion* cc_print(char*); -Completion* cc_set(char*); - -/* buffer command declarations */ -void bcmd_evalmarker(char*, Argument*); -void bcmd_goto(char*, Argument*); -void bcmd_scroll(char*, Argument*); -void bcmd_setmarker(char*, Argument*); -void bcmd_zoom(char*, Argument*); - -/* special command delcarations */ -gboolean scmd_search(char*, Argument*); - -/* callback declarations */ -gboolean cb_destroy(GtkWidget*, gpointer); -gboolean cb_draw(GtkWidget*, GdkEventExpose*, gpointer); -gboolean cb_index_row_activated(GtkTreeView*, GtkTreePath*, GtkTreeViewColumn*, gpointer); -gboolean cb_inputbar_kb_pressed(GtkWidget*, GdkEventKey*, gpointer); -gboolean cb_inputbar_activate(GtkEntry*, gpointer); -gboolean cb_inputbar_form_activate(GtkEntry*, gpointer); -gboolean cb_inputbar_password_activate(GtkEntry*, gpointer); -gboolean cb_view_kb_pressed(GtkWidget*, GdkEventKey*, gpointer); -gboolean cb_view_resized(GtkWidget*, GtkAllocation*, gpointer); -gboolean cb_view_button_pressed(GtkWidget*, GdkEventButton*, gpointer); -gboolean cb_view_button_release(GtkWidget*, GdkEventButton*, gpointer); -gboolean cb_view_motion_notify(GtkWidget*, GdkEventMotion*, gpointer); -gboolean cb_view_scrolled(GtkWidget*, GdkEventScroll*, gpointer); -gboolean cb_watch_file(GFileMonitor*, GFile*, GFile*, GFileMonitorEvent, gpointer); - -/* configuration */ -#include "config.h" +#include "zathura.h" /* function implementation */ -void -init_look(void) +bool +init_zathura() { - /* parse */ - gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg)); - gdk_color_parse(default_bgcolor, &(Zathura.Style.default_bg)); - gdk_color_parse(inputbar_fgcolor, &(Zathura.Style.inputbar_fg)); - gdk_color_parse(inputbar_bgcolor, &(Zathura.Style.inputbar_bg)); - gdk_color_parse(statusbar_fgcolor, &(Zathura.Style.statusbar_fg)); - gdk_color_parse(statusbar_bgcolor, &(Zathura.Style.statusbar_bg)); - gdk_color_parse(completion_fgcolor, &(Zathura.Style.completion_fg)); - gdk_color_parse(completion_bgcolor, &(Zathura.Style.completion_bg)); - gdk_color_parse(completion_g_fgcolor, &(Zathura.Style.completion_g_fg)); - gdk_color_parse(completion_g_fgcolor, &(Zathura.Style.completion_g_fg)); - gdk_color_parse(completion_hl_fgcolor, &(Zathura.Style.completion_hl_fg)); - gdk_color_parse(completion_hl_bgcolor, &(Zathura.Style.completion_hl_bg)); - gdk_color_parse(notification_e_fgcolor, &(Zathura.Style.notification_e_fg)); - gdk_color_parse(notification_e_bgcolor, &(Zathura.Style.notification_e_bg)); - gdk_color_parse(notification_w_fgcolor, &(Zathura.Style.notification_w_fg)); - gdk_color_parse(notification_w_bgcolor, &(Zathura.Style.notification_w_bg)); - gdk_color_parse(recolor_darkcolor, &(Zathura.Style.recolor_darkcolor)); - gdk_color_parse(recolor_lightcolor, &(Zathura.Style.recolor_lightcolor)); - gdk_color_parse(search_highlight, &(Zathura.Style.search_highlight)); - gdk_color_parse(select_text, &(Zathura.Style.select_text)); + if(!(Zathura.UI.session = girara_session_create())) + return false; - Zathura.Style.font = pango_font_description_from_string(font); + if(!girara_session_init(Zathura.UI.session)) + return false; - /* window and viewport */ - gtk_widget_modify_bg(GTK_WIDGET(Zathura.UI.window), GTK_STATE_NORMAL, &(Zathura.Style.default_bg)); - gtk_widget_modify_bg(GTK_WIDGET(Zathura.UI.viewport), GTK_STATE_NORMAL, &(Zathura.Style.default_bg)); - - /* drawing area */ - gtk_widget_modify_bg(GTK_WIDGET(Zathura.UI.drawing_area), GTK_STATE_NORMAL, &(Zathura.Style.default_bg)); - - /* statusbar */ - gtk_widget_modify_bg(GTK_WIDGET(Zathura.UI.statusbar), GTK_STATE_NORMAL, &(Zathura.Style.statusbar_bg)); - - gtk_widget_modify_fg(GTK_WIDGET(Zathura.Global.status_text), GTK_STATE_NORMAL, &(Zathura.Style.statusbar_fg)); - gtk_widget_modify_fg(GTK_WIDGET(Zathura.Global.status_state), GTK_STATE_NORMAL, &(Zathura.Style.statusbar_fg)); - gtk_widget_modify_fg(GTK_WIDGET(Zathura.Global.status_buffer), GTK_STATE_NORMAL, &(Zathura.Style.statusbar_fg)); - - gtk_widget_modify_font(GTK_WIDGET(Zathura.Global.status_text), Zathura.Style.font); - gtk_widget_modify_font(GTK_WIDGET(Zathura.Global.status_state), Zathura.Style.font); - gtk_widget_modify_font(GTK_WIDGET(Zathura.Global.status_buffer), Zathura.Style.font); - - /* inputbar */ - gtk_widget_modify_base(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_bg)); - gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_fg)); - gtk_widget_modify_font(GTK_WIDGET(Zathura.UI.inputbar), Zathura.Style.font); - - /* scrollbars */ - if(show_scrollbars) - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.view), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - else - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.view), GTK_POLICY_NEVER, GTK_POLICY_NEVER); - - /* inputbar */ - if(Zathura.Global.show_inputbar) - gtk_widget_show(GTK_WIDGET(Zathura.UI.inputbar)); - else - gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar)); - - /* statusbar */ - if(Zathura.Global.show_statusbar) - gtk_widget_show(GTK_WIDGET(Zathura.UI.statusbar)); - else - gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar)); -} - -gchar* -fix_path(const gchar* path) -{ - if (!path) - return NULL; - - if (path[0] == '~') - { - gchar* home_path = get_home_dir(); - gchar* res = g_build_filename(home_path, path + 1, NULL); - g_free(home_path); - return res; - } - else - return g_strdup(path); -} - -gchar* path_from_env(const gchar* var) -{ - gchar* env = fix_path(g_getenv(var)); - if (!env) - return NULL; - - gchar* res = g_build_filename(env, "zathura", NULL); - g_free(env); - return res; -} - -gchar* get_home_dir(void) -{ - const gchar* homedir = g_getenv("HOME"); - return g_strdup(homedir ? homedir : g_get_home_dir()); -} - -void -init_directories(void) -{ - /* setup directories */ - if (!Zathura.Config.config_dir) - { -#ifndef ZATHURA_NO_XDG - gchar* env = path_from_env("XDG_CONFIG_HOME"); - if (env) - Zathura.Config.config_dir = env; - else -#endif - Zathura.Config.config_dir = fix_path(CONFIG_DIR); - } - if (!Zathura.Config.data_dir) - { -#ifndef ZATHURA_NO_XDG - gchar* env = path_from_env("XDG_DATA_HOME"); - if (env) - Zathura.Config.data_dir = env; - else -#endif - Zathura.Config.data_dir = fix_path(DATA_DIR); - } - - /* create zathura (config/data) directory */ - g_mkdir_with_parents(Zathura.Config.config_dir, 0771); - g_mkdir_with_parents(Zathura.Config.data_dir, 0771); -} - -void -init_bookmarks(void) -{ - /* create or open existing bookmark file */ - Zathura.Bookmarks.data = g_key_file_new(); - gchar* bookmarks = g_build_filename(Zathura.Config.data_dir, BOOKMARK_FILE, NULL); - - if(!g_file_test(bookmarks, G_FILE_TEST_IS_REGULAR)) - { - /* file does not exist */ - g_file_set_contents(bookmarks, "# Zathura bookmarks\n", -1, NULL); - } - - GError* error = NULL; - if(!g_key_file_load_from_file(Zathura.Bookmarks.data, bookmarks, - G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) - { - gchar* message = g_strdup_printf("Could not load bookmark file: %s", error->message); - notify(ERROR, message); - g_free(message); - } - - Zathura.Bookmarks.file = bookmarks; -} - -void -init_keylist(void) -{ - ShortcutList* e = NULL; - ShortcutList* p = NULL; - - int i; - for(i = 0; i < LENGTH(shortcuts); i++) - { - e = malloc(sizeof(ShortcutList)); - if(!e) - out_of_memory(); - - e->element = shortcuts[i]; - e->next = NULL; - - if(!Zathura.Bindings.sclist) - Zathura.Bindings.sclist = e; - if(p) - p->next = e; - - p = e; - } -} - -void -init_settings(void) -{ - Zathura.State.filename = g_strdup((char*) default_text); - Zathura.Global.adjust_mode = adjust_open; - - gtk_window_set_default_size(GTK_WINDOW(Zathura.UI.window), default_width, default_height); -} - -void -init_zathura(void) -{ - /* init mutexes */ - g_static_mutex_init(&(Zathura.Lock.pdflib_lock)); - g_static_mutex_init(&(Zathura.Lock.search_lock)); - g_static_mutex_init(&(Zathura.Lock.pdf_obj_lock)); - g_static_mutex_init(&(Zathura.Lock.select_lock)); - g_static_mutex_init(&(Zathura.Lock.select_lock)); - - /* other */ - Zathura.Global.mode = NORMAL; - Zathura.Global.viewing_mode = NORMAL; - Zathura.Global.recolor = 0; - Zathura.Global.goto_mode = GOTO_MODE; - Zathura.Global.show_index = FALSE; - Zathura.Global.show_inputbar = TRUE; - Zathura.Global.show_statusbar = TRUE; - - Zathura.State.pages = g_strdup_printf(""); - Zathura.State.scroll_percentage = 0; - - Zathura.Marker.markers = NULL; - Zathura.Marker.number_of_markers = 0; - Zathura.Marker.last = -1; - - Zathura.Search.results = NULL; - Zathura.Search.page = 0; - Zathura.Search.draw = FALSE; - - Zathura.FileMonitor.monitor = NULL; - Zathura.FileMonitor.file = NULL; - - Zathura.StdinSupport.file = NULL; - - /* window */ - if(Zathura.UI.embed) - Zathura.UI.window = gtk_plug_new(Zathura.UI.embed); - else - Zathura.UI.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - /* UI */ - Zathura.UI.box = GTK_BOX(gtk_vbox_new(FALSE, 0)); - Zathura.UI.continuous = GTK_BOX(gtk_vbox_new(FALSE, 0)); - Zathura.UI.view = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); - Zathura.UI.viewport = GTK_VIEWPORT(gtk_viewport_new(NULL, NULL)); - Zathura.UI.drawing_area = gtk_drawing_area_new(); - Zathura.UI.statusbar = gtk_event_box_new(); - Zathura.UI.statusbar_entries = GTK_BOX(gtk_hbox_new(FALSE, 0)); - Zathura.UI.inputbar = GTK_ENTRY(gtk_entry_new()); - Zathura.UI.document = gtk_event_box_new(); - - /* window */ - gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), "zathura"); - GdkGeometry hints = { 1, 1 }; - gtk_window_set_geometry_hints(GTK_WINDOW(Zathura.UI.window), NULL, &hints, GDK_HINT_MIN_SIZE); - g_signal_connect(G_OBJECT(Zathura.UI.window), "destroy", G_CALLBACK(cb_destroy), NULL); - - /* box */ - gtk_box_set_spacing(Zathura.UI.box, 0); - gtk_container_add(GTK_CONTAINER(Zathura.UI.window), GTK_WIDGET(Zathura.UI.box)); - - /* continuous */ - gtk_box_set_spacing(Zathura.UI.continuous, 5); - - /* events */ - gtk_container_add(GTK_CONTAINER(Zathura.UI.document), GTK_WIDGET(Zathura.UI.drawing_area)); - gtk_widget_add_events(GTK_WIDGET(Zathura.UI.document), GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); - - g_signal_connect(G_OBJECT(Zathura.UI.document), "button-press-event", G_CALLBACK(cb_view_button_pressed), NULL); - g_signal_connect(G_OBJECT(Zathura.UI.document), "button-release-event", G_CALLBACK(cb_view_button_release), NULL); - g_signal_connect(G_OBJECT(Zathura.UI.document), "motion-notify-event", G_CALLBACK(cb_view_motion_notify), NULL); - gtk_widget_show(Zathura.UI.document); - - /* view */ - g_signal_connect(G_OBJECT(Zathura.UI.view), "key-press-event", G_CALLBACK(cb_view_kb_pressed), NULL); - g_signal_connect(G_OBJECT(Zathura.UI.view), "size-allocate", G_CALLBACK(cb_view_resized), NULL); - g_signal_connect(G_OBJECT(Zathura.UI.view), "scroll-event", G_CALLBACK(cb_view_scrolled), NULL); - gtk_container_add(GTK_CONTAINER(Zathura.UI.view), GTK_WIDGET(Zathura.UI.viewport)); - gtk_viewport_set_shadow_type(Zathura.UI.viewport, GTK_SHADOW_NONE); - - /* drawing area */ - gtk_widget_show(Zathura.UI.drawing_area); - g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL); - - /* statusbar */ - Zathura.Global.status_text = GTK_LABEL(gtk_label_new(NULL)); - Zathura.Global.status_state = GTK_LABEL(gtk_label_new(NULL)); - Zathura.Global.status_buffer = GTK_LABEL(gtk_label_new(NULL)); - - gtk_misc_set_alignment(GTK_MISC(Zathura.Global.status_text), 0.0, 0.0); - gtk_misc_set_alignment(GTK_MISC(Zathura.Global.status_state), 1.0, 0.0); - gtk_misc_set_alignment(GTK_MISC(Zathura.Global.status_buffer), 1.0, 0.0); - - gtk_misc_set_padding(GTK_MISC(Zathura.Global.status_text), 2.0, 4.0); - gtk_misc_set_padding(GTK_MISC(Zathura.Global.status_state), 2.0, 4.0); - gtk_misc_set_padding(GTK_MISC(Zathura.Global.status_buffer), 2.0, 4.0); - - gtk_label_set_use_markup(Zathura.Global.status_text, TRUE); - gtk_label_set_use_markup(Zathura.Global.status_state, TRUE); - gtk_label_set_use_markup(Zathura.Global.status_buffer, TRUE); - - gtk_box_pack_start(Zathura.UI.statusbar_entries, GTK_WIDGET(Zathura.Global.status_text), TRUE, TRUE, 2); - gtk_box_pack_start(Zathura.UI.statusbar_entries, GTK_WIDGET(Zathura.Global.status_buffer), FALSE, FALSE, 2); - gtk_box_pack_start(Zathura.UI.statusbar_entries, GTK_WIDGET(Zathura.Global.status_state), FALSE, FALSE, 2); - - gtk_container_add(GTK_CONTAINER(Zathura.UI.statusbar), GTK_WIDGET(Zathura.UI.statusbar_entries)); - - /* inputbar */ - gtk_entry_set_inner_border(Zathura.UI.inputbar, NULL); - gtk_entry_set_has_frame( Zathura.UI.inputbar, FALSE); - gtk_editable_set_editable( GTK_EDITABLE(Zathura.UI.inputbar), TRUE); - - Zathura.Handler.inputbar_key_press_event = - g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "key-press-event", G_CALLBACK(cb_inputbar_kb_pressed), NULL); - Zathura.Handler.inputbar_activate = - g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_activate), NULL); - - /* packing */ - gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(Zathura.UI.view), TRUE, TRUE, 0); - gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(Zathura.UI.statusbar), FALSE, FALSE, 0); - gtk_box_pack_end( Zathura.UI.box, GTK_WIDGET(Zathura.UI.inputbar), FALSE, FALSE, 0); -} - -void -add_marker(int id) -{ - if( (id < 0x30) || (id > 0x7A)) - return; - - /* current information */ - int page_number = Zathura.PDF.page_number; - - /* search if entry already exists */ - int i; - for(i = 0; i < Zathura.Marker.number_of_markers; i++) - { - if(Zathura.Marker.markers[i].id == id) - { - Zathura.Marker.markers[i].page = page_number; - Zathura.Marker.last = page_number; - return; - } - } - - /* add new marker */ - int marker_index = Zathura.Marker.number_of_markers++; - Zathura.Marker.markers = realloc(Zathura.Marker.markers, sizeof(Marker) * - (Zathura.Marker.number_of_markers)); - - Zathura.Marker.markers[marker_index].id = id; - Zathura.Marker.markers[marker_index].page = page_number; - Zathura.Marker.last = page_number; -} - -void -build_index(GtkTreeModel* model, GtkTreeIter* parent, PopplerIndexIter* index_iter) -{ - do - { - GtkTreeIter tree_iter; - PopplerIndexIter *child; - PopplerAction *action; - gchar *markup; - - action = poppler_index_iter_get_action(index_iter); - if(!action) - continue; - - markup = g_markup_escape_text (action->any.title, -1); - - gtk_tree_store_append(GTK_TREE_STORE(model), &tree_iter, parent); - gtk_tree_store_set(GTK_TREE_STORE(model), &tree_iter, 0, markup, 1, action, -1); - g_object_weak_ref(G_OBJECT(model), (GWeakNotify) poppler_action_free, action); - g_free(markup); - - child = poppler_index_iter_get_child(index_iter); - if(child) - build_index(model, &tree_iter, child); - poppler_index_iter_free(child); - } while(poppler_index_iter_next(index_iter)); -} - -void -draw(int page_id) -{ - if(!Zathura.PDF.document || page_id < 0 || page_id >= Zathura.PDF.number_of_pages) - return; - - double page_width, page_height; - double width, height; - - double scale = ((double) Zathura.PDF.scale / 100.0); - - int rotate = Zathura.PDF.rotate; - - Page *current_page = Zathura.PDF.pages[page_id]; - - if(Zathura.PDF.surface) - cairo_surface_destroy(Zathura.PDF.surface); - Zathura.PDF.surface = NULL; - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_page_get_size(current_page->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - if(rotate == 0 || rotate == 180) - { - width = page_width * scale; - height = page_height * scale; - } - else - { - width = page_height * scale; - height = page_width * scale; - } - - cairo_t *cairo; - Zathura.PDF.surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height); - cairo = cairo_create(Zathura.PDF.surface); - - cairo_save(cairo); - cairo_set_source_rgb(cairo, 1, 1, 1); - cairo_rectangle(cairo, 0, 0, width, height); - cairo_fill(cairo); - cairo_restore(cairo); - cairo_save(cairo); - - switch(rotate) - { - case 90: - cairo_translate(cairo, width, 0); - break; - case 180: - cairo_translate(cairo, width, height); - break; - case 270: - cairo_translate(cairo, 0, height); - break; - default: - cairo_translate(cairo, 0, 0); - } - - if(scale != 1.0) - cairo_scale(cairo, scale, scale); - - if(rotate != 0) - cairo_rotate(cairo, rotate * G_PI / 180.0); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_page_render(current_page->page, cairo); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - cairo_restore(cairo); - cairo_destroy(cairo); - - if(Zathura.Global.recolor) - { - unsigned char* image = cairo_image_surface_get_data(Zathura.PDF.surface); - int x, y; - - int width = cairo_image_surface_get_width(Zathura.PDF.surface); - int height = cairo_image_surface_get_height(Zathura.PDF.surface); - int rowstride = cairo_image_surface_get_stride(Zathura.PDF.surface); - - /* recolor code based on qimageblitz library flatten() function - (http://sourceforge.net/projects/qimageblitz/) */ - - int r1 = Zathura.Style.recolor_darkcolor.red / 257; - int g1 = Zathura.Style.recolor_darkcolor.green / 257; - int b1 = Zathura.Style.recolor_darkcolor.blue / 257; - int r2 = Zathura.Style.recolor_lightcolor.red / 257; - int g2 = Zathura.Style.recolor_lightcolor.green / 257; - int b2 = Zathura.Style.recolor_lightcolor.blue / 257; - - int min = 0x00; - int max = 0xFF; - int mean; - - float sr = ((float) r2 - r1) / (max - min); - float sg = ((float) g2 - g1) / (max - min); - float sb = ((float) b2 - b1) / (max - min); - - for (y = 0; y < height; y++) - { - unsigned char* data = image + y * rowstride; - - for (x = 0; x < width; x++) - { - mean = (data[0] + data[1] + data[2]) / 3; - data[2] = sr * (mean - min) + r1 + 0.5; - data[1] = sg * (mean - min) + g1 + 0.5; - data[0] = sb * (mean - min) + b1 + 0.5; - data += 4; - } - } - } - - gtk_widget_set_size_request(Zathura.UI.drawing_area, width, height); - gtk_widget_queue_draw(Zathura.UI.drawing_area); -} - -void -change_mode(int mode) -{ - char* mode_text = 0; - for(unsigned int i = 0; i != LENGTH(mode_names); ++i) - if(mode_names[i].mode == mode) - { - mode_text = mode_names[i].display; - break; - } - - if(!mode_text) - { - switch(mode) - { - case ADD_MARKER: - mode_text = ""; - break; - case EVAL_MARKER: - mode_text = ""; - break; - default: - mode_text = ""; - mode = NORMAL; - break; - } - } - - Zathura.Global.mode = mode; - notify(DEFAULT, mode_text); -} - -void -calculate_offset(GtkWidget* widget, double* offset_x, double* offset_y) -{ - double page_width, page_height, width, height; - double scale = ((double) Zathura.PDF.scale / 100.0); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - if(Zathura.PDF.rotate == 0 || Zathura.PDF.rotate == 180) - { - width = page_width * scale; - height = page_height * scale; - } - else - { - width = page_height * scale; - height = page_width * scale; - } - - int window_x, window_y; - gdk_drawable_get_size(widget->window, &window_x, &window_y); - - if (window_x > width) - *offset_x = (window_x - width) / 2; - else - *offset_x = 0; - - if (window_y > height) - *offset_y = (window_y - height) / 2; - else - *offset_y = 0; -} - -void -close_file(gboolean keep_monitor) -{ - if(!Zathura.PDF.document) - return; - - /* clean up pages */ - int i; - for(i = 0; i < Zathura.PDF.number_of_pages; i++) - { - Page* current_page = Zathura.PDF.pages[i]; - g_object_unref(current_page->page); - if(current_page->label) - g_free(current_page->label); - free(current_page); - } - - /* save bookmarks */ - if(Zathura.Bookmarks.data) - { - /* set current page */ - g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file, - BM_PAGE_ENTRY, Zathura.PDF.page_number); - - /* set page offset */ - g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file, - BM_PAGE_OFFSET, Zathura.PDF.page_offset); - - /* save bookmarks */ - int i; - for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++) - g_key_file_set_integer(Zathura.Bookmarks.data, Zathura.PDF.file, - Zathura.Bookmarks.bookmarks[i].id, Zathura.Bookmarks.bookmarks[i].page); - - /* convert file and save it */ - gchar* bookmarks = g_key_file_to_data(Zathura.Bookmarks.data, NULL, NULL); - g_file_set_contents(Zathura.Bookmarks.file, bookmarks, -1, NULL); - g_free(bookmarks); - } - - /* inotify */ - if(!keep_monitor) - { - g_object_unref(Zathura.FileMonitor.monitor); - Zathura.FileMonitor.monitor = NULL; - - if(Zathura.FileMonitor.file) - { - g_object_unref(Zathura.FileMonitor.file); - Zathura.FileMonitor.file = NULL; - } - } - - /* reset values */ - g_free(Zathura.PDF.pages); - g_object_unref(Zathura.PDF.document); - g_free(Zathura.State.pages); - gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), "zathura"); - - Zathura.State.pages = g_strdup_printf(""); - g_free(Zathura.State.filename); - Zathura.State.filename = g_strdup((char*) default_text); - - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - Zathura.PDF.document = NULL; - - if(!keep_monitor) - { - g_free(Zathura.PDF.file); - g_free(Zathura.PDF.password); - Zathura.PDF.file = NULL; - Zathura.PDF.password = NULL; - Zathura.PDF.page_number = 0; - Zathura.PDF.scale = 0; - Zathura.PDF.rotate = 0; - } - Zathura.PDF.number_of_pages = 0; - Zathura.PDF.page_offset = 0; - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - - /* destroy index */ - if(Zathura.UI.index) - { - gtk_widget_destroy(Zathura.UI.index); - Zathura.UI.index = NULL; - } - - /* destroy information */ - if(Zathura.UI.information) - { - gtk_widget_destroy(Zathura.UI.information); - Zathura.UI.information = NULL; - } - - /* free markers */ - if(Zathura.Marker.markers) - free(Zathura.Marker.markers); - Zathura.Marker.number_of_markers = 0; - Zathura.Marker.last = -1; - - update_status(); -} - -void -enter_password(void) -{ - /* replace default inputbar handler */ - g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate); - Zathura.Handler.inputbar_activate = g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_password_activate), NULL); - - Argument argument; - argument.data = "Enter password: "; - sc_focus_inputbar(&argument); -} - -void -eval_marker(int id) -{ - /* go to last marker */ - if(id == 0x27) - { - int current_page = Zathura.PDF.page_number; - set_page(Zathura.Marker.last); - Zathura.Marker.last = current_page; - return; - } - - /* search markers */ - int i; - for(i = 0; i < Zathura.Marker.number_of_markers; i++) - { - if(Zathura.Marker.markers[i].id == id) - { - set_page(Zathura.Marker.markers[i].page); - return; - } - } -} - -void -highlight_result(int page_id, PopplerRectangle* rectangle) -{ - PopplerRectangle* trect = poppler_rectangle_copy(rectangle); - cairo_t *cairo = cairo_create(Zathura.PDF.surface); - cairo_set_source_rgba(cairo, Zathura.Style.search_highlight.red, Zathura.Style.search_highlight.green, - Zathura.Style.search_highlight.blue, transparency); - - recalcRectangle(page_id, trect); - cairo_rectangle(cairo, trect->x1, trect->y1, (trect->x2 - trect->x1), (trect->y2 - trect->y1)); - poppler_rectangle_free(trect); - cairo_fill(cairo); - cairo_destroy(cairo); -} - -void -notify(int level, const char* message) -{ - switch(level) - { - case ERROR: - gtk_widget_modify_base(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.notification_e_bg)); - gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.notification_e_fg)); - break; - case WARNING: - gtk_widget_modify_base(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.notification_w_bg)); - gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.notification_w_fg)); - break; - default: - gtk_widget_modify_base(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_bg)); - gtk_widget_modify_text(GTK_WIDGET(Zathura.UI.inputbar), GTK_STATE_NORMAL, &(Zathura.Style.inputbar_fg)); - break; - } - - if(message) - gtk_entry_set_text(Zathura.UI.inputbar, message); -} - -gboolean -open_file(char* path, char* password) -{ - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - - /* specify path max */ - size_t pm; -#ifdef PATH_MAX - pm = PATH_MAX; -#else - pm = pathconf(path,_PC_PATH_MAX); - if(pm <= 0) - pm = 4096; -#endif - - /* get filename */ - char* file = (char*) g_malloc0(sizeof(char) * pm); - if(!file || !realpath(path, file)) - { - notify(ERROR, "File does not exist"); - if(file) - free(file); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - return FALSE; - } - - if(path[0] == '~') - { - gchar* home_path = get_home_dir(); - g_free(file); - file = g_build_filename(home_path, path + 1, NULL); - g_free(home_path); - } - - /* check if file exists */ - if(!g_file_test(file, G_FILE_TEST_IS_REGULAR)) - { - notify(ERROR, "File does not exist"); - g_free(file); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - return FALSE; - } - - /* close old file */ - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - close_file(FALSE); - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - - /* format path */ - GError* error = NULL; - char* file_uri = g_filename_to_uri(file, NULL, &error); - if (!file_uri) - { - if(file) - g_free(file); - char* message = g_strdup_printf("Can not open file: %s", error->message); - notify(ERROR, message); - g_free(message); - g_error_free(error); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - return FALSE; - } - - /* open file */ - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - Zathura.PDF.document = poppler_document_new_from_file(file_uri, password, &error); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - if(!Zathura.PDF.document) - { - if(error->code == 1) - { - g_free(file_uri); - g_error_free(error); - Zathura.PDF.file = file; - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - enter_password(); - return FALSE; - } - else - { - char* message = g_strdup_printf("Can not open file: %s", error->message); - notify(ERROR, message); - g_free(file_uri); - g_free(message); - g_error_free(error); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - return FALSE; - } - } - - /* save password */ - g_free(Zathura.PDF.password); - Zathura.PDF.password = password ? g_strdup(password) : NULL; - - /* inotify */ - if(!Zathura.FileMonitor.monitor) - { - GFile* file = g_file_new_for_uri(file_uri); - - if(file) - { - Zathura.FileMonitor.monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, NULL, NULL); - if(Zathura.FileMonitor.monitor) - g_signal_connect(G_OBJECT(Zathura.FileMonitor.monitor), "changed", G_CALLBACK(cb_watch_file), NULL); - Zathura.FileMonitor.file = file; - } - } - - g_free(file_uri); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - Zathura.PDF.number_of_pages = poppler_document_get_n_pages(Zathura.PDF.document); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - g_free(Zathura.PDF.file); - Zathura.PDF.file = file; - Zathura.PDF.scale = 100; - Zathura.PDF.rotate = 0; - if(Zathura.State.filename) - g_free(Zathura.State.filename); - Zathura.State.filename = g_markup_escape_text(file, -1); - Zathura.PDF.pages = g_malloc(Zathura.PDF.number_of_pages * sizeof(Page*)); - - if(!Zathura.PDF.pages) - out_of_memory(); - - /* get pages and check label mode */ - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - Zathura.Global.enable_labelmode = FALSE; - - int i; - for(i = 0; i < Zathura.PDF.number_of_pages; i++) - { - Zathura.PDF.pages[i] = malloc(sizeof(Page)); - if(!Zathura.PDF.pages[i]) - out_of_memory(); - - Zathura.PDF.pages[i]->id = i + 1; - Zathura.PDF.pages[i]->page = poppler_document_get_page(Zathura.PDF.document, i); - g_object_get(G_OBJECT(Zathura.PDF.pages[i]->page), "label", &(Zathura.PDF.pages[i]->label), NULL); - - /* check if it is necessary to use the label mode */ - int label_int = atoi(Zathura.PDF.pages[i]->label); - if(label_int == 0 || label_int != (i+1)) - Zathura.Global.enable_labelmode = TRUE; - } - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - /* set correct goto mode */ - if(!Zathura.Global.enable_labelmode && GOTO_MODE == GOTO_LABELS) - Zathura.Global.goto_mode = GOTO_DEFAULT; - - /* start page */ - int start_page = 0; - Zathura.PDF.page_offset = 0; - - /* bookmarks */ - if(Zathura.Bookmarks.data && g_key_file_has_group(Zathura.Bookmarks.data, file)) - { - /* get last opened page */ - if(g_key_file_has_key(Zathura.Bookmarks.data, file, BM_PAGE_ENTRY, NULL)) - start_page = g_key_file_get_integer(Zathura.Bookmarks.data, file, BM_PAGE_ENTRY, NULL); - - /* get page offset */ - if(g_key_file_has_key(Zathura.Bookmarks.data, file, BM_PAGE_OFFSET, NULL)) - Zathura.PDF.page_offset = g_key_file_get_integer(Zathura.Bookmarks.data, file, BM_PAGE_OFFSET, NULL); - if((Zathura.PDF.page_offset != 0) && (Zathura.PDF.page_offset != GOTO_OFFSET)) - Zathura.PDF.page_offset = GOTO_OFFSET; - - /* open and read bookmark file */ - gsize i = 0; - gsize number_of_keys = 0; - char** keys = g_key_file_get_keys(Zathura.Bookmarks.data, file, &number_of_keys, NULL); - - for(i = 0; i < number_of_keys; i++) - { - if(strcmp(keys[i], BM_PAGE_ENTRY) && strcmp(keys[i], BM_PAGE_OFFSET)) - { - Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks, - (Zathura.Bookmarks.number_of_bookmarks + 1) * sizeof(Bookmark)); - - Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].id = keys[i]; - Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].page = - g_key_file_get_integer(Zathura.Bookmarks.data, file, keys[i], NULL); - - Zathura.Bookmarks.number_of_bookmarks++; - } - } - - g_strfreev(keys); - } - - /* set window title */ - gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), basename(file)); - - /* show document */ - set_page(start_page); - update_status(); - - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - isc_abort(NULL); - return TRUE; -} - -gboolean -open_stdin(gchar* password) -{ - GError* error = NULL; - gchar* file = NULL; - gint handle = g_file_open_tmp("zathura.stdin.XXXXXX.pdf", &file, &error); - if (handle == -1) - { - gchar* message = g_strdup_printf("Can not create temporary file: %s", error->message); - notify(ERROR, message); - g_free(message); - g_error_free(error); - return FALSE; - } - - // read from stdin and dump to temporary file - int stdinfno = fileno(stdin); - if (stdinfno == -1) - { - gchar* message = g_strdup_printf("Can not read from stdin."); - notify(ERROR, message); - g_free(message); - close(handle); - g_unlink(file); - g_free(file); - return FALSE; - - } - - char buffer[BUFSIZ]; - ssize_t count = 0; - while ((count = read(stdinfno, buffer, BUFSIZ)) > 0) - { - if (write(handle, buffer, count) != count) - { - gchar* message = g_strdup_printf("Can not write to temporary file: %s", file); - notify(ERROR, message); - g_free(message); - close(handle); - g_unlink(file); - g_free(file); - return FALSE; - } - } - - if (count != 0) - { - gchar* message = g_strdup_printf("Can not read from stdin."); - notify(ERROR, message); - g_free(message); - close(handle); - g_unlink(file); - g_free(file); - return FALSE; - } - - /* update data */ - if (Zathura.StdinSupport.file) - g_unlink(Zathura.StdinSupport.file); - g_free(Zathura.StdinSupport.file); - Zathura.StdinSupport.file = file; - - return open_file(Zathura.StdinSupport.file, password); -} - -void open_uri(char* uri) -{ - char* escaped_uri = g_shell_quote(uri); - char* uri_cmd = g_strdup_printf(uri_command, escaped_uri); - system(uri_cmd); - g_free(uri_cmd); - g_free(escaped_uri); -} - -void out_of_memory(void) -{ - printf("error: out of memory\n"); - exit(-1); -} - -void -update_status(void) -{ - /* update text */ - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename); - - /* update pages */ - if( Zathura.PDF.document && Zathura.PDF.pages ) - { - int page = Zathura.PDF.page_number; - g_free(Zathura.State.pages); - - Zathura.State.pages = g_strdup_printf("[%i/%i]", page + 1, Zathura.PDF.number_of_pages); - } - - /* update state */ - char* zoom_level = (Zathura.PDF.scale != 0) ? g_strdup_printf("%d%%", Zathura.PDF.scale) : g_strdup(""); - char* goto_mode = (Zathura.Global.goto_mode == GOTO_LABELS) ? "L" : - (Zathura.Global.goto_mode == GOTO_OFFSET) ? "O" : "D"; - char* status_text = g_strdup_printf("%s [%s] %s (%d%%)", zoom_level, goto_mode, Zathura.State.pages, Zathura.State.scroll_percentage); - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_state, status_text); - g_free(status_text); - g_free(zoom_level); -} - -void -read_configuration_file(const char* rcfile) -{ - if(!rcfile) - return; - - if(!g_file_test(rcfile, G_FILE_TEST_IS_REGULAR)) - return; - - char* content = NULL; - if(g_file_get_contents(rcfile, &content, NULL, NULL)) - { - gchar **lines = g_strsplit(content, "\n", -1); - int n = g_strv_length(lines) - 1; - - int i; - for(i = 0; i <= n; i++) - { - if(!strlen(lines[i])) - continue; - - gchar **tokens = g_strsplit(lines[i], " ", -1); - int length = g_strv_length(tokens); - - if(!strcmp(tokens[0], "set")) - cmd_set(length - 1, tokens + 1); - else if(!strcmp(tokens[0], "map")) - cmd_map(length - 1, tokens + 1); - } - - g_strfreev(lines); - g_free(content); - } -} - -void -read_configuration(void) -{ - char* zathurarc = g_build_filename(Zathura.Config.config_dir, ZATHURA_RC, NULL); - read_configuration_file(GLOBAL_RC); - read_configuration_file(zathurarc); - g_free(zathurarc); -} - -void -recalcRectangle(int page_id, PopplerRectangle* rectangle) -{ - double page_width, page_height; - double x1 = rectangle->x1; - double x2 = rectangle->x2; - double y1 = rectangle->y1; - double y2 = rectangle->y2; - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_page_get_size(Zathura.PDF.pages[page_id]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - double scale = ((double) Zathura.PDF.scale / 100.0); - - int rotate = Zathura.PDF.rotate; - - switch(rotate) - { - case 90: - rectangle->x1 = y2 * scale; - rectangle->y1 = x1 * scale; - rectangle->x2 = y1 * scale; - rectangle->y2 = x2 * scale; - break; - case 180: - rectangle->x1 = (page_width - x2) * scale; - rectangle->y1 = y2 * scale; - rectangle->x2 = (page_width - x1) * scale; - rectangle->y2 = y1 * scale; - break; - case 270: - rectangle->x1 = (page_height - y1) * scale; - rectangle->y1 = (page_width - x2) * scale; - rectangle->x2 = (page_height - y2) * scale; - rectangle->y2 = (page_width - x1) * scale; - break; - default: - rectangle->x1 = x1 * scale; - rectangle->y1 = (page_height - y1) * scale; - rectangle->x2 = x2 * scale; - rectangle->y2 = (page_height - y2) * scale; - } -} - -GtkEventBox* -createCompletionRow(GtkBox* results, char* command, char* description, gboolean group) -{ - GtkBox *col = GTK_BOX(gtk_hbox_new(FALSE, 0)); - GtkEventBox *row = GTK_EVENT_BOX(gtk_event_box_new()); - - GtkLabel *show_command = GTK_LABEL(gtk_label_new(NULL)); - GtkLabel *show_description = GTK_LABEL(gtk_label_new(NULL)); - - gtk_misc_set_alignment(GTK_MISC(show_command), 0.0, 0.0); - gtk_misc_set_alignment(GTK_MISC(show_description), 0.0, 0.0); - - if(group) - { - gtk_misc_set_padding(GTK_MISC(show_command), 2.0, 4.0); - gtk_misc_set_padding(GTK_MISC(show_description), 2.0, 4.0); - } - else - { - gtk_misc_set_padding(GTK_MISC(show_command), 1.0, 1.0); - gtk_misc_set_padding(GTK_MISC(show_description), 1.0, 1.0); - } - - gtk_label_set_use_markup(show_command, TRUE); - gtk_label_set_use_markup(show_description, TRUE); - - gchar* c = g_markup_printf_escaped(FORMAT_COMMAND, command ? command : ""); - gchar* d = g_markup_printf_escaped(FORMAT_DESCRIPTION, description ? description : ""); - gtk_label_set_markup(show_command, c); - gtk_label_set_markup(show_description, d); - g_free(c); - g_free(d); - - if(group) - { - gtk_widget_modify_fg(GTK_WIDGET(show_command), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_fg)); - gtk_widget_modify_fg(GTK_WIDGET(show_description), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_fg)); - gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_g_bg)); - } - else - { - gtk_widget_modify_fg(GTK_WIDGET(show_command), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); - gtk_widget_modify_fg(GTK_WIDGET(show_description), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); - gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_bg)); - } - - gtk_widget_modify_font(GTK_WIDGET(show_command), Zathura.Style.font); - gtk_widget_modify_font(GTK_WIDGET(show_description), Zathura.Style.font); - - gtk_box_pack_start(GTK_BOX(col), GTK_WIDGET(show_command), TRUE, TRUE, 2); - gtk_box_pack_start(GTK_BOX(col), GTK_WIDGET(show_description), FALSE, FALSE, 2); - - gtk_container_add(GTK_CONTAINER(row), GTK_WIDGET(col)); - - gtk_box_pack_start(results, GTK_WIDGET(row), FALSE, FALSE, 0); - - return row; -} - -void -setCompletionRowColor(GtkBox* results, int mode, int id) -{ - GtkEventBox *row = (GtkEventBox*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(results)), id); - - if(row) - { - GtkBox *col = (GtkBox*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(row)), 0); - GtkLabel *cmd = (GtkLabel*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(col)), 0); - GtkLabel *cdesc = (GtkLabel*) g_list_nth_data(gtk_container_get_children(GTK_CONTAINER(col)), 1); - - if(mode == NORMAL) - { - gtk_widget_modify_fg(GTK_WIDGET(cmd), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); - gtk_widget_modify_fg(GTK_WIDGET(cdesc), GTK_STATE_NORMAL, &(Zathura.Style.completion_fg)); - gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_bg)); - } - else - { - gtk_widget_modify_fg(GTK_WIDGET(cmd), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_fg)); - gtk_widget_modify_fg(GTK_WIDGET(cdesc), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_fg)); - gtk_widget_modify_bg(GTK_WIDGET(row), GTK_STATE_NORMAL, &(Zathura.Style.completion_hl_bg)); - } - } -} - -void -set_page(int page) -{ - if(page >= Zathura.PDF.number_of_pages || page < 0) - { - notify(WARNING, "Could not open page"); - return; - } - - Zathura.PDF.page_number = page; - Zathura.Search.draw = FALSE; - - Argument argument; - argument.n = TOP; - - switch_view(Zathura.UI.document); - draw(page); - sc_scroll(&argument); -} - -void -switch_view(GtkWidget* widget) -{ - GtkWidget* child = gtk_bin_get_child(GTK_BIN(Zathura.UI.viewport)); - if(child) - { - g_object_ref(child); - gtk_container_remove(GTK_CONTAINER(Zathura.UI.viewport), child); - } - - gtk_container_add(GTK_CONTAINER(Zathura.UI.viewport), GTK_WIDGET(widget)); -} - -Completion* -completion_init(void) -{ - Completion *completion = malloc(sizeof(Completion)); - if(!completion) - out_of_memory(); - - completion->groups = NULL; - - return completion; -} - -CompletionGroup* -completion_group_create(char* name) -{ - CompletionGroup* group = malloc(sizeof(CompletionGroup)); - if(!group) - out_of_memory(); - - group->value = name ? g_strdup(name) : NULL; - group->elements = NULL; - group->next = NULL; - - return group; -} - -void -completion_add_group(Completion* completion, CompletionGroup* group) -{ - CompletionGroup* cg = completion->groups; - - while(cg && cg->next) - cg = cg->next; - - if(cg) - cg->next = group; - else - completion->groups = group; -} - -void completion_free(Completion* completion) -{ - CompletionGroup* group = completion->groups; - CompletionElement *element; - - while(group) - { - element = group->elements; - while(element) - { - CompletionElement* ne = element->next; - g_free(element->value); - g_free(element->description); - free(element); - element = ne; - } - - CompletionGroup *ng = group->next; - g_free(group->value); - free(group); - group = ng; - } - free(completion); -} - -void completion_group_add_element(CompletionGroup* group, char* name, char* description) -{ - CompletionElement* el = group->elements; - - while(el && el->next) - el = el->next; - - CompletionElement* new_element = malloc(sizeof(CompletionElement)); - if(!new_element) - out_of_memory(); - - new_element->value = name ? g_strdup(name) : NULL; - new_element->description = description ? g_strdup(description) : NULL; - new_element->next = NULL; - - if(el) - el->next = new_element; - else - group->elements = new_element; -} - - -/* thread implementation */ -void* -search(void* parameter) -{ - Argument* argument = (Argument*) parameter; - - static char* search_item; - static int direction; - static int next_page = 0; - int page_counter; - GList* results = NULL; - - if(argument->data) - { - if(search_item) - g_free(search_item); - - search_item = g_strdup((char*) argument->data); - } - - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - if(!Zathura.PDF.document || !search_item || !strlen(search_item)) - { - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - g_static_mutex_lock(&(Zathura.Lock.search_lock)); - Zathura.Thread.search_thread_running = FALSE; - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); - g_thread_exit(NULL); - } - - /* delete old results */ - if(Zathura.Search.results) - { - g_list_free(Zathura.Search.results); - Zathura.Search.results = NULL; - } - - /* search document */ - if(argument->n) - direction = (argument->n == BACKWARD) ? -1 : 1; - - int number_of_pages = Zathura.PDF.number_of_pages; - int page_number = Zathura.PDF.page_number; - - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - - for(page_counter = 1; page_counter <= number_of_pages; page_counter++) - { - g_static_mutex_lock(&(Zathura.Lock.search_lock)); - if(Zathura.Thread.search_thread_running == FALSE) - { - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); - g_thread_exit(NULL); - } - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); - - next_page = (number_of_pages + page_number + - page_counter * direction) % number_of_pages; - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - PopplerPage* page = poppler_document_get_page(Zathura.PDF.document, next_page); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - if(!page) - g_thread_exit(NULL); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - results = poppler_page_find_text(page, search_item); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - g_object_unref(page); - - if(results) - break; - } - - /* draw results */ - if(results) - { - gdk_threads_enter(); - - set_page(next_page); - - if(Zathura.Search.results) - g_list_free(Zathura.Search.results); - - Zathura.Search.results = results; - Zathura.Search.page = next_page; - Zathura.Search.draw = TRUE; - - gdk_threads_leave(); - } - - g_static_mutex_lock(&(Zathura.Lock.search_lock)); - Zathura.Thread.search_thread_running = FALSE; - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); - - g_thread_exit(NULL); - return NULL; -} - -/* shortcut implementation */ -void -sc_abort(Argument* argument) -{ - /* Clear buffer */ - if(Zathura.Global.buffer) - { - g_string_free(Zathura.Global.buffer, TRUE); - Zathura.Global.buffer = NULL; - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, ""); - } - - /* Set back to normal mode */ - change_mode(NORMAL); - switch_view(Zathura.UI.document); -} - -void -sc_adjust_window(Argument* argument) -{ - if(!Zathura.PDF.document) - return; - - Zathura.Global.adjust_mode = argument->n; - - GtkAdjustment* adjustment; - double view_size; - double page_width; - double page_height; - - if(argument->n == ADJUST_BESTFIT) - adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view); - else if(argument->n == ADJUST_WIDTH) - adjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view); - else - return; - - view_size = gtk_adjustment_get_page_size(adjustment); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - if ((Zathura.PDF.rotate == 90) || (Zathura.PDF.rotate == 270)) - { - double swap = page_width; - page_width = page_height; - page_height = swap; - } - - if(argument->n == ADJUST_BESTFIT) - Zathura.PDF.scale = (view_size / page_height) * 100; - else - Zathura.PDF.scale = (view_size / page_width) * 100; - - draw(Zathura.PDF.page_number); - update_status(); -} - -void -sc_change_buffer(Argument* argument) -{ - if(!Zathura.Global.buffer) - return; - - int buffer_length = Zathura.Global.buffer->len; - - if(argument->n == DELETE_LAST) - { - if((buffer_length - 1) == 0) - { - g_string_free(Zathura.Global.buffer, TRUE); - Zathura.Global.buffer = NULL; - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, ""); - } - else - { - GString* temp = g_string_new_len(Zathura.Global.buffer->str, buffer_length - 1); - g_string_free(Zathura.Global.buffer, TRUE); - Zathura.Global.buffer = temp; - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, Zathura.Global.buffer->str); - } - } -} - -void -sc_change_mode(Argument* argument) -{ - if(argument) - change_mode(argument->n); -} - -void -sc_focus_inputbar(Argument* argument) -{ - if(!(GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.inputbar)))) - gtk_widget_show(GTK_WIDGET(Zathura.UI.inputbar)); - - if(argument->data) - { - char* data = argument->data; - - if(argument->n == APPEND_FILEPATH) - data = g_strdup_printf("%s%s", data, Zathura.PDF.file); - else - data = g_strdup(data); - - notify(DEFAULT, data); - g_free(data); - gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.inputbar)); - gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1); - } -} - -void -sc_follow(Argument* argument) -{ - if(!Zathura.PDF.document) - return; - - Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number]; - int link_id = 1; - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - GList *link_list = poppler_page_get_link_mapping(current_page->page); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - link_list = g_list_reverse(link_list); - - if(g_list_length(link_list) <= 0) - return; - - GList *links; - for(links = link_list; links; links = g_list_next(links)) - { - PopplerLinkMapping *link_mapping = (PopplerLinkMapping*) links->data; - PopplerRectangle* link_rectangle = &link_mapping->area; - PopplerAction *action = link_mapping->action; - - /* only handle URI and internal links */ - if(action->type == POPPLER_ACTION_URI || action->type == POPPLER_ACTION_GOTO_DEST) - { - highlight_result(Zathura.PDF.page_number, link_rectangle); - - /* draw text */ - recalcRectangle(Zathura.PDF.page_number, link_rectangle); - cairo_t *cairo = cairo_create(Zathura.PDF.surface); - cairo_select_font_face(cairo, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size(cairo, 10); - cairo_move_to(cairo, link_rectangle->x1 + 1, link_rectangle->y1 - 1); - char* link_number = g_strdup_printf("%i", link_id++); - cairo_show_text(cairo, link_number); - cairo_destroy(cairo); - g_free(link_number); - } - } - - gtk_widget_queue_draw(Zathura.UI.drawing_area); - poppler_page_free_link_mapping(link_list); - - /* replace default inputbar handler */ - g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate); - Zathura.Handler.inputbar_activate = g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_form_activate), NULL); - - argument->data = "Follow hint: "; - sc_focus_inputbar(argument); -} - -void -sc_navigate(Argument* argument) -{ - if(!Zathura.PDF.document) - return; - - int number_of_pages = Zathura.PDF.number_of_pages; - int new_page = Zathura.PDF.page_number; - - if(argument->n == NEXT) - new_page = scroll_wrap ? (new_page + 1) : ((new_page + 1) % number_of_pages); - else if(argument->n == PREVIOUS) - new_page = scroll_wrap ? (new_page - 1) : ((new_page + number_of_pages - 1) % number_of_pages); - - if (scroll_wrap && (new_page < 0 || new_page >= number_of_pages)) - return; - - set_page(new_page); - update_status(); -} - -void -sc_recolor(Argument* argument) -{ - Zathura.Global.recolor = !Zathura.Global.recolor; - draw(Zathura.PDF.page_number); -} - -void -sc_reload(Argument* argument) -{ - draw(Zathura.PDF.page_number); - - GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view); - GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view); - - /* save old information */ - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - char* path = Zathura.PDF.file ? strdup(Zathura.PDF.file) : NULL; - char* password = Zathura.PDF.password ? strdup(Zathura.PDF.password) : NULL; - int scale = Zathura.PDF.scale; - int page = Zathura.PDF.page_number; - int rotate = Zathura.PDF.rotate; - gdouble va = gtk_adjustment_get_value(vadjustment); - gdouble ha = gtk_adjustment_get_value(hadjustment); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - - /* reopen and restore settings */ - close_file(TRUE); - open_file(path, password); - - g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); - Zathura.PDF.scale = scale; - Zathura.PDF.rotate = rotate; - gtk_adjustment_set_value(vadjustment, va); - gtk_adjustment_set_value(hadjustment, ha); - g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); - - draw(page); - - if(path) - free(path); - if(password) - free(password); -} - - -void -sc_rotate(Argument* argument) -{ - Zathura.PDF.rotate = (Zathura.PDF.rotate + 90) % 360; - Zathura.Search.draw = TRUE; - - draw(Zathura.PDF.page_number); -} - -void -sc_scroll(Argument* argument) -{ - GtkAdjustment* adjustment; - - if( (argument->n == LEFT) || (argument->n == RIGHT) ) - adjustment = gtk_scrolled_window_get_hadjustment(Zathura.UI.view); - else - adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.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; - gboolean static ss = FALSE; - - if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0) - { - int old_page = Zathura.PDF.page_number; - Argument arg; - arg.n = PREVIOUS; - sc_navigate(&arg); - if (!scroll_wrap || (Zathura.PDF.page_number < old_page)) - { - arg.n = BOTTOM; - ss = TRUE; - sc_scroll(&arg); - } - return; - } - else if((argument->n == DOWN || argument->n == HALF_DOWN || argument->n == FULL_DOWN) && value == max) - { - Argument arg; - arg.n = NEXT; - ss = TRUE; - sc_navigate(&arg); - return; - } - - gdouble new_value; - if(argument->n == FULL_UP) - new_value = (value - view_size) < 0 ? 0 : (value - view_size); - else if(argument->n == FULL_DOWN) - new_value = (value + view_size) > max ? max : (value + view_size); - else if(argument->n == HALF_UP) - new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2)); - else if(argument->n == HALF_DOWN) - new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2)); - else if((argument->n == LEFT) || (argument->n == UP)) - new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step); - else if(argument->n == TOP) - new_value = 0; - else if(argument->n == BOTTOM) - new_value = max; - else - new_value = (value + scroll_step) > max ? max : (value + scroll_step); - - Zathura.State.scroll_percentage = max == 0 ? 0 : (new_value*100/max); - - if(smooth_scrolling && !ss) - { - gdouble i; - if(new_value > value) - for(i = value; (i + smooth_scrolling) < new_value; i += smooth_scrolling) - gtk_adjustment_set_value(adjustment, i); - else - for(i = value; (i + smooth_scrolling) > new_value; i -= smooth_scrolling) - gtk_adjustment_set_value(adjustment, i); - } - - gtk_adjustment_set_value(adjustment, new_value); - ss = FALSE; - - update_status(); -} - -void -sc_search(Argument* argument) -{ - g_static_mutex_lock(&(Zathura.Lock.search_lock)); - if(Zathura.Thread.search_thread_running) - { - Zathura.Thread.search_thread_running = FALSE; - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); - gdk_threads_leave(); - g_thread_join(Zathura.Thread.search_thread); - gdk_threads_enter(); - g_static_mutex_lock(&(Zathura.Lock.search_lock)); - } - - Zathura.Thread.search_thread_running = TRUE; - Zathura.Thread.search_thread = g_thread_create(search, (gpointer) argument, TRUE, NULL); - g_static_mutex_unlock(&(Zathura.Lock.search_lock)); -} - -void -sc_switch_goto_mode(Argument* argument) -{ - switch(Zathura.Global.goto_mode) - { - case GOTO_LABELS: - Zathura.Global.goto_mode = GOTO_OFFSET; - break; - case GOTO_OFFSET: - Zathura.Global.goto_mode = GOTO_DEFAULT; - break; - default: - if(Zathura.Global.enable_labelmode) - Zathura.Global.goto_mode = GOTO_LABELS; - else - Zathura.Global.goto_mode = GOTO_OFFSET; - break; - } - - update_status(); -} - -gboolean cb_index_row_activated(GtkTreeView* treeview, GtkTreePath* path, - GtkTreeViewColumn* column, gpointer user_data) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - g_object_get(treeview, "model", &model, NULL); - - if(gtk_tree_model_get_iter(model, &iter, path)) - { - PopplerAction* action; - PopplerDest* destination; - - gtk_tree_model_get(model, &iter, 1, &action, -1); - if(!action) - return TRUE; - - if(action->type == POPPLER_ACTION_GOTO_DEST) - { - destination = action->goto_dest.dest; - int page_number = destination->page_num; - - if(action->goto_dest.dest->type == POPPLER_DEST_NAMED) - { - PopplerDest* d = poppler_document_find_dest(Zathura.PDF.document, action->goto_dest.dest->named_dest); - if(d) - { - page_number = d->page_num; - poppler_dest_free(d); - } - } - - set_page(page_number - 1); - update_status(); - Zathura.Global.show_index = FALSE; - gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.document)); - } - } - - Zathura.Global.mode = NORMAL; - g_object_unref(model); - - return TRUE; -} - -void -sc_navigate_index(Argument* argument) -{ - if(!Zathura.UI.index) - return; - - GtkTreeView *treeview = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.index))->data; - GtkTreePath *path; - - gtk_tree_view_get_cursor(treeview, &path, NULL); - if(!path) - return; - - GtkTreeModel *model = gtk_tree_view_get_model(treeview); - GtkTreeIter iter; - GtkTreeIter child_iter; - - gboolean is_valid_path = TRUE; - - switch(argument->n) - { - case UP: - if(!gtk_tree_path_prev(path)) - is_valid_path = gtk_tree_path_up(path); - else /* row above */ - { - while(gtk_tree_view_row_expanded(treeview, path)) { - gtk_tree_model_get_iter(model, &iter, path); - /* select last child */ - gtk_tree_model_iter_nth_child(model, &child_iter, &iter, - gtk_tree_model_iter_n_children(model, &iter)-1); - gtk_tree_path_free(path); - path = gtk_tree_model_get_path(model, &child_iter); - } - } - break; - case COLLAPSE: - if(!gtk_tree_view_collapse_row(treeview, path) - && gtk_tree_path_get_depth(path) > 1) - { - gtk_tree_path_up(path); - gtk_tree_view_collapse_row(treeview, path); - } - break; - case DOWN: - if(gtk_tree_view_row_expanded(treeview, path)) - gtk_tree_path_down(path); - else - { - do - { - gtk_tree_model_get_iter(model, &iter, path); - if (gtk_tree_model_iter_next(model, &iter)) - { - path = gtk_tree_model_get_path(model, &iter); - break; - } - } - while((is_valid_path = (gtk_tree_path_get_depth(path) > 1)) - && gtk_tree_path_up(path)); - } - break; - case EXPAND: - if(gtk_tree_view_expand_row(treeview, path, FALSE)) - gtk_tree_path_down(path); - break; - case SELECT: - cb_index_row_activated(treeview, path, NULL, NULL); - return; - } - - if (is_valid_path) - gtk_tree_view_set_cursor(treeview, path, NULL, FALSE); - - gtk_tree_path_free(path); -} - -void -sc_toggle_index(Argument* argument) -{ - if(!Zathura.PDF.document) - return; - - GtkWidget *treeview; - GtkTreeModel *model; - GtkCellRenderer *renderer; - PopplerIndexIter *iter; - - if(!Zathura.UI.index) - { - Zathura.UI.index = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.index), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - - if((iter = poppler_index_iter_new(Zathura.PDF.document))) - { - model = GTK_TREE_MODEL(gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER)); - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - build_index(model, NULL, iter); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - poppler_index_iter_free(iter); - } - else - { - notify(WARNING, "This document does not contain any index"); - Zathura.UI.index = NULL; - return; - } - - treeview = gtk_tree_view_new_with_model (model); - g_object_unref(model); - renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 0, "Title", - renderer, "markup", 0, NULL); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); - g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); - g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL); - - gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE); - g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), NULL); - - gtk_container_add (GTK_CONTAINER (Zathura.UI.index), treeview); - gtk_widget_show (treeview); - gtk_widget_show(Zathura.UI.index); - } - - if(!Zathura.Global.show_index) - { - switch_view(Zathura.UI.index); - Zathura.Global.mode = INDEX; - } - else - { - switch_view(Zathura.UI.document); - Zathura.Global.mode = NORMAL; - } - - Zathura.Global.show_index = !Zathura.Global.show_index; -} - -void -sc_toggle_inputbar(Argument* argument) -{ - if(GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.inputbar))) - gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar)); - else - gtk_widget_show(GTK_WIDGET(Zathura.UI.inputbar)); -} - -void -sc_toggle_fullscreen(Argument* argument) -{ - static gboolean fs = TRUE; - - if(fs) - { - gtk_window_fullscreen(GTK_WINDOW(Zathura.UI.window)); - gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar)); - gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar)); - - Argument arg; - arg.n = ADJUST_BESTFIT; - sc_adjust_window(&arg); - - Zathura.Global.mode = FULLSCREEN; - fs = FALSE; - } - else - { - gtk_window_unfullscreen(GTK_WINDOW(Zathura.UI.window)); - gtk_widget_show(GTK_WIDGET(Zathura.UI.inputbar)); - gtk_widget_show(GTK_WIDGET(Zathura.UI.statusbar)); - - Zathura.Global.mode = NORMAL; - fs = TRUE; - } -} - -void -sc_toggle_statusbar(Argument* argument) -{ - if(GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.statusbar))) - gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar)); - else - gtk_widget_show(GTK_WIDGET(Zathura.UI.statusbar)); -} - -void -sc_quit(Argument* argument) -{ - cb_destroy(NULL, NULL); -} - -void -sc_zoom(Argument* argument) -{ - bcmd_zoom(NULL, argument); -} - -/* inputbar shortcut declarations */ -void -isc_abort(Argument* argument) -{ - Argument arg = { HIDE }; - isc_completion(&arg); - - notify(DEFAULT, ""); - change_mode(NORMAL); - gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view)); - - if(!Zathura.Global.show_inputbar) - gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar)); - - /* replace default inputbar handler */ - g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate); - Zathura.Handler.inputbar_activate = g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_activate), NULL); - sc_abort(NULL); -} - -void -isc_command_history(Argument* argument) -{ - static int current = 0; - int length = g_list_length(Zathura.Global.history); - - if(length > 0) - { - if(argument->n == NEXT) - current = (length + current + 1) % length; - else - current = (length + current - 1) % length; - - gchar* command = (gchar*) g_list_nth_data(Zathura.Global.history, current); - notify(DEFAULT, command); - gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.inputbar)); - gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1); - } -} - -void -isc_completion(Argument* argument) -{ - gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 1, -1); - gchar *tmp_string = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, 1); - gchar identifier = tmp_string[0]; - int length = strlen(input); - - if(!input || !tmp_string) - { - if(input) - g_free(input); - if(tmp_string) - g_free(tmp_string); - return; - } - - /* get current information*/ - char* first_space = strstr(input, " "); - char* current_command; - char* current_parameter; - int current_command_length; - - if(!first_space) - { - current_command = g_strdup(input); - current_command_length = length; - current_parameter = NULL; - } - else - { - int offset = abs(input - first_space); - current_command = g_strndup(input, offset); - current_command_length = strlen(current_command); - current_parameter = input + offset + 1; - } - - /* if the identifier does not match the command sign and - * the completion should not be hidden, leave this function */ - if((identifier != ':') && (argument->n != HIDE)) - { - if(current_command) - g_free(current_command); - if(input) - g_free(input); - if(tmp_string) - g_free(tmp_string); - return; - } - - /* static elements */ - static GtkBox *results = NULL; - static CompletionRow *rows = NULL; - - static int current_item = 0; - static int n_items = 0; - - static char *previous_command = NULL; - static char *previous_parameter = NULL; - static int previous_id = 0; - static int previous_length = 0; - - static gboolean command_mode = TRUE; - - /* delete old list iff - * the completion should be hidden - * the current command differs from the previous one - * the current parameter differs from the previous one - */ - if( (argument->n == HIDE) || - (current_parameter && previous_parameter && strcmp(current_parameter, previous_parameter)) || - (current_command && previous_command && strcmp(current_command, previous_command)) || - (previous_length != length) - ) - { - if(results) - gtk_widget_destroy(GTK_WIDGET(results)); - - results = NULL; - - if(rows) - { - for(int i = 0; i != n_items; ++i) - { - g_free(rows[i].command); - g_free(rows[i].description); - } - free(rows); - } - - rows = NULL; - current_item = 0; - n_items = 0; - command_mode = TRUE; - - if(argument->n == HIDE) - { - if(current_command) - g_free(current_command); - if(input) - g_free(input); - if(tmp_string) - g_free(tmp_string); - return; - } - } - - /* create new list iff - * there is no current list - * the current command differs from the previous one - * the current parameter differs from the previous one - */ - if( (!results) ) - { - results = GTK_BOX(gtk_vbox_new(FALSE, 0)); - - /* create list based on parameters iff - * there is a current parameter given - * there is an old list with commands - * the current command does not differ from the previous one - * the current command has an completion function - */ - if(strchr(input, ' ')) - { - gboolean search_matching_command = FALSE; - - int i; - for(i = 0; i < LENGTH(commands); i++) - { - int abbr_length = commands[i].abbr ? strlen(commands[i].abbr) : 0; - int cmd_length = commands[i].command ? strlen(commands[i].command) : 0; - - if( ((current_command_length <= cmd_length) && !strncmp(current_command, commands[i].command, current_command_length)) || - ((current_command_length <= abbr_length) && !strncmp(current_command, commands[i].abbr, current_command_length)) - ) - { - if(commands[i].completion) - { - previous_command = current_command; - previous_id = i; - search_matching_command = TRUE; - } - else - { - if(current_command) - g_free(current_command); - if(input) - g_free(input); - if(tmp_string) - g_free(tmp_string); - return; - } - } - } - - if(!search_matching_command) - { - if(current_command) - g_free(current_command); - if(input) - g_free(input); - if(tmp_string) - g_free(tmp_string); - return; - } - - Completion *result = commands[previous_id].completion(current_parameter); - - if(!result || !result->groups) - { - if(current_command) - g_free(current_command); - if(input) - g_free(input); - if(tmp_string) - g_free(tmp_string); - return; - } - - command_mode = FALSE; - CompletionGroup* group = NULL; - CompletionElement* element = NULL; - - rows = malloc(sizeof(CompletionRow)); - if(!rows) - out_of_memory(); - - for(group = result->groups; group != NULL; group = group->next) - { - int group_elements = 0; - - for(element = group->elements; element != NULL; element = element->next) - { - if(element->value) - { - if(group->value && !group_elements) - { - rows = realloc(rows, (n_items + 1) * sizeof(CompletionRow)); - rows[n_items].command = g_strdup(group->value); - rows[n_items].description = NULL; - rows[n_items].command_id = -1; - rows[n_items].is_group = TRUE; - rows[n_items++].row = GTK_WIDGET(createCompletionRow(results, group->value, NULL, TRUE)); - } - - rows = realloc(rows, (n_items + 1) * sizeof(CompletionRow)); - rows[n_items].command = g_strdup(element->value); - rows[n_items].description = element->description ? g_strdup(element->description) : NULL; - rows[n_items].command_id = previous_id; - rows[n_items].is_group = FALSE; - rows[n_items++].row = GTK_WIDGET(createCompletionRow(results, element->value, element->description, FALSE)); - group_elements++; - } - } - } - - /* clean up */ - completion_free(result); - } - /* create list based on commands */ - else - { - int i = 0; - command_mode = TRUE; - - rows = malloc(LENGTH(commands) * sizeof(CompletionRow)); - if(!rows) - out_of_memory(); - - for(i = 0; i < LENGTH(commands); i++) - { - int abbr_length = commands[i].abbr ? strlen(commands[i].abbr) : 0; - int cmd_length = commands[i].command ? strlen(commands[i].command) : 0; - - /* add command to list iff - * the current command would match the command - * the current command would match the abbreviation - */ - if( ((current_command_length <= cmd_length) && !strncmp(current_command, commands[i].command, current_command_length)) || - ((current_command_length <= abbr_length) && !strncmp(current_command, commands[i].abbr, current_command_length)) - ) - { - rows[n_items].command = g_strdup(commands[i].command); - rows[n_items].description = g_strdup(commands[i].description); - rows[n_items].command_id = i; - rows[n_items].is_group = FALSE; - rows[n_items++].row = GTK_WIDGET(createCompletionRow(results, commands[i].command, commands[i].description, FALSE)); - } - } - - rows = realloc(rows, n_items * sizeof(CompletionRow)); - } - - gtk_box_pack_start(Zathura.UI.box, GTK_WIDGET(results), FALSE, FALSE, 0); - gtk_widget_show_all(GTK_WIDGET(Zathura.UI.window)); - - current_item = (argument->n == NEXT) ? -1 : 0; - } - - /* update coloring iff - * there is a list with items - */ - if( (results) && (n_items > 0) ) - { - setCompletionRowColor(results, NORMAL, current_item); - char* temp; - int i = 0, next_group = 0; - - for(i = 0; i < n_items; i++) - { - if(argument->n == NEXT || argument->n == NEXT_GROUP) - current_item = (current_item + n_items + 1) % n_items; - else if(argument->n == PREVIOUS || argument->n == PREVIOUS_GROUP) - current_item = (current_item + n_items - 1) % n_items; - - if(rows[current_item].is_group) - { - if(!command_mode && (argument->n == NEXT_GROUP || argument->n == PREVIOUS_GROUP)) - next_group = 1; - continue; - } - else - { - if(!command_mode && (next_group == 0) && (argument->n == NEXT_GROUP || argument->n == PREVIOUS_GROUP)) - continue; - break; - } - } - - setCompletionRowColor(results, HIGHLIGHT, current_item); - - /* hide other items */ - int uh = ceil(n_completion_items / 2); - int lh = floor(n_completion_items / 2); - - for(i = 0; i < n_items; i++) - { - if((n_items > 1) && ( - (i >= (current_item - lh) && (i <= current_item + uh)) || - (i < n_completion_items && current_item < lh) || - (i >= (n_items - n_completion_items) && (current_item >= (n_items - uh)))) - ) - gtk_widget_show(rows[i].row); - else - gtk_widget_hide(rows[i].row); - } - - if(command_mode) - temp = g_strconcat(":", rows[current_item].command, (n_items == 1) ? " " : NULL, NULL); - else - temp = g_strconcat(":", previous_command, " ", rows[current_item].command, NULL); - - gtk_entry_set_text(Zathura.UI.inputbar, temp); - gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1); - g_free(temp); - - previous_command = g_strdup((command_mode) ? rows[current_item].command : current_command); - previous_parameter = g_strdup((command_mode) ? current_parameter : rows[current_item].command); - previous_length = strlen(previous_command) + ((command_mode) ? (length - current_command_length) : (strlen(previous_parameter) + 1)); - previous_id = rows[current_item].command_id; - } - - if(current_command) - g_free(current_command); - if(input) - g_free(input); - if(tmp_string) - g_free(tmp_string); -} - -void -isc_string_manipulation(Argument* argument) -{ - gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, -1); - int length = strlen(input); - int pos = gtk_editable_get_position(GTK_EDITABLE(Zathura.UI.inputbar)); - int i; - - switch (argument->n) { - case DELETE_LAST_WORD: - i = pos - 1; - - if(!pos) - return; - - /* remove trailing spaces */ - for(; i >= 0 && input[i] == ' '; i--); - - /* find the beginning of the word */ - while((i > 0) && (input[i] != ' ') && (input[i] != '/')) - i--; - - gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), i, pos); - gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), i); - break; - case DELETE_LAST_CHAR: - if((length - 1) <= 0) - isc_abort(NULL); - - gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), pos - 1, pos); - break; - case DELETE_TO_LINE_START: - gtk_editable_delete_text(GTK_EDITABLE(Zathura.UI.inputbar), 1, pos); - break; - case NEXT_CHAR: - gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), pos + 1); - break; - case PREVIOUS_CHAR: - gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), (pos == 0) ? 0 : pos - 1); - break; - default: /* unreachable */ - break; - } -} - -/* command implementation */ -gboolean -cmd_bookmark(int argc, char** argv) -{ - if(!Zathura.PDF.document || argc < 1) - return TRUE; - - /* get id */ - int i; - GString *id = g_string_new(""); - - for(i = 0; i < argc; i++) - { - if(i != 0) - id = g_string_append_c(id, ' '); - - id = g_string_append(id, argv[i]); - } - - /* check for existing bookmark to overwrite */ - for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++) - { - if(!strcmp(id->str, Zathura.Bookmarks.bookmarks[i].id)) - { - Zathura.Bookmarks.bookmarks[i].page = Zathura.PDF.page_number; - return TRUE; - } - } - - /* add new bookmark */ - Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks, - (Zathura.Bookmarks.number_of_bookmarks + 1) * sizeof(Bookmark)); - - Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].id = id->str; - Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks].page = Zathura.PDF.page_number; - Zathura.Bookmarks.number_of_bookmarks++; - - return TRUE; -} - -gboolean -cmd_open_bookmark(int argc, char** argv) -{ - if(!Zathura.PDF.document || argc < 1) - return TRUE; - - /* get id */ - int i; - GString *id = g_string_new(""); - - for(i = 0; i < argc; i++) - { - if(i != 0) - id = g_string_append_c(id, ' '); - - id = g_string_append(id, argv[i]); - } - - /* find bookmark */ - for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++) - { - if(!strcmp(id->str, Zathura.Bookmarks.bookmarks[i].id)) - { - set_page(Zathura.Bookmarks.bookmarks[i].page); - return TRUE; - } - } - - notify(WARNING, "No matching bookmark found"); - return FALSE; -} - -gboolean -cmd_close(int argc, char** argv) -{ - close_file(FALSE); - - return TRUE; -} - -gboolean -cmd_correct_offset(int argc, char** argv) -{ - if(!Zathura.PDF.document || argc == 0) - return TRUE; - - Zathura.PDF.page_offset = (Zathura.PDF.page_number + 1) - atoi(argv[0]); - - if(Zathura.PDF.page_offset != 0) - Zathura.Global.goto_mode = GOTO_OFFSET; - else - Zathura.Global.goto_mode = GOTO_MODE; - - update_status(); - - return TRUE; -} - -gboolean -cmd_delete_bookmark(int argc, char** argv) -{ - if(!Zathura.PDF.document || argc < 1) - return TRUE; - - /* get id */ - int i; - GString *id = g_string_new(""); - - for(i = 0; i < argc; i++) - { - if(i != 0) - id = g_string_append_c(id, ' '); - - id = g_string_append(id, argv[i]); - } - - /* check for bookmark to delete */ - for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++) - { - if(!strcmp(id->str, Zathura.Bookmarks.bookmarks[i].id)) - { - /* update key file */ - g_key_file_remove_key(Zathura.Bookmarks.data, Zathura.PDF.file, Zathura.Bookmarks.bookmarks[i].id, NULL); - - /* update bookmarks */ - Zathura.Bookmarks.bookmarks[i].id = Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks - 1].id; - Zathura.Bookmarks.bookmarks[i].page = Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks - 1].page; - Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks, - Zathura.Bookmarks.number_of_bookmarks * sizeof(Bookmark)); - - Zathura.Bookmarks.number_of_bookmarks--; - - return TRUE; - } - } - - return TRUE; -} - -gboolean -cmd_export(int argc, char** argv) -{ - if(argc == 0 || !Zathura.PDF.document) - return TRUE; - - if(argc < 2) - { - notify(WARNING, "No export path specified"); - return FALSE; - } - - /* export images */ - if(!strcmp(argv[0], "images")) - { - int page_number; - for(page_number = 0; page_number < Zathura.PDF.number_of_pages; page_number++) - { - GList *image_list; - GList *images; - cairo_surface_t *image; - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - image_list = poppler_page_get_image_mapping(Zathura.PDF.pages[page_number]->page); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - if(!g_list_length(image_list)) - { - notify(WARNING, "This document does not contain any images"); - return FALSE; - } - - for(images = image_list; images; images = g_list_next(images)) - { - PopplerImageMapping *image_mapping; - gint image_id; - char* file; - char* filename; - - image_mapping = (PopplerImageMapping*) images->data; - image_id = image_mapping->image_id; - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - image = poppler_page_get_image(Zathura.PDF.pages[page_number]->page, image_id); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - if(!image) - continue; - - filename = g_strdup_printf("%s_p%i_i%i.png", Zathura.PDF.file, page_number + 1, image_id); - - if(argv[1][0] == '~') - { - gchar* home_path = get_home_dir(); - file = malloc(((int) strlen(filename) + (int) strlen(argv[1]) - + (int) strlen(home_path) - 1) * sizeof(char)); - if(!file) - out_of_memory(); - - file = g_strdup_printf("%s%s%s", home_path, argv[1] + 1, filename); - g_free(home_path); - } - else - file = g_strdup_printf("%s%s", argv[1], filename); - - cairo_surface_write_to_png(image, file); - - g_free(filename); - g_free(file); - } - } - } - else if(!strcmp(argv[0], "attachments")) - { - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - if(!poppler_document_has_attachments(Zathura.PDF.document)) - { - notify(WARNING, "PDF file has no attachments"); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - return FALSE; - } - - GList *attachment_list = poppler_document_get_attachments(Zathura.PDF.document); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - GList *attachments; - char *file; - - for(attachments = attachment_list; attachments; attachments = g_list_next(attachments)) - { - PopplerAttachment *attachment = (PopplerAttachment*) attachments->data; - - if(argv[1][0] == '~') - { - gchar* home_path = get_home_dir(); - file = malloc(((int) strlen(attachment->name) + (int) strlen(argv[1]) - + (int) strlen(home_path) - 1) * sizeof(char)); - if(!file) - out_of_memory(); - - file = g_strdup_printf("%s%s%s", home_path, argv[1] + 1, attachment->name); - g_free(home_path); - } - else - file = g_strdup_printf("%s%s", argv[1], attachment->name); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_attachment_save(attachment, file, NULL); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - g_free(file); - } - } - - return TRUE; -} - -gboolean -cmd_info(int argc, char** argv) -{ - if(!Zathura.PDF.document) - return TRUE; - - static gboolean visible = FALSE; - - if(!Zathura.UI.information) - { - GtkListStore *list; - GtkTreeIter iter; - GtkCellRenderer *renderer; - GtkTreeSelection *selection; - - list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); - - /* read document information */ - gchar *title, *author; - gchar *subject, *keywords; - gchar *creator, *producer; - GTime creation_date, modification_date; - - g_object_get(Zathura.PDF.document, - "title", &title, - "author", &author, - "subject", &subject, - "keywords", &keywords, - "creator", &creator, - "producer", &producer, - "creation-date", &creation_date, - "mod-date", &modification_date, - NULL); - - /* append information to list */ - gtk_list_store_append(list, &iter); - gtk_list_store_set(list, &iter, 0, "Author", 1, author ? author : "", -1); - gtk_list_store_append(list, &iter); - gtk_list_store_set(list, &iter, 0, "Title", 1, title ? title : "", -1); - gtk_list_store_append(list, &iter); - gtk_list_store_set(list, &iter, 0, "Subject", 1, subject ? subject : "", -1); - gtk_list_store_append(list, &iter); - gtk_list_store_set(list, &iter, 0, "Keywords", 1, keywords ? keywords : "", -1); - gtk_list_store_append(list, &iter); - gtk_list_store_set(list, &iter, 0, "Creator", 1, creator ? creator : "", -1); - gtk_list_store_append(list, &iter); - gtk_list_store_set(list, &iter, 0, "Producer", 1, producer ? producer : "", -1); - - Zathura.UI.information = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list)); - renderer = gtk_cell_renderer_text_new(); - - gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(Zathura.UI.information), -1, - "Name", renderer, "text", 0, NULL); - gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(Zathura.UI.information), -1, - "Value", renderer, "text", 1, NULL); - - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(Zathura.UI.information)); - gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); - - gtk_widget_show_all(Zathura.UI.information); - } - - if(!visible) - switch_view(Zathura.UI.information); - else - switch_view(Zathura.UI.document); - - visible = !visible; - - return FALSE; -} - -gboolean -cmd_map(int argc, char** argv) -{ - if(argc < 2) - return TRUE; - - char* ks = argv[0]; - - /* search for the right shortcut function */ - int sc_id = -1; - - int sc_c; - for(sc_c = 0; sc_c < LENGTH(shortcut_names); sc_c++) - { - if(!strcmp(argv[1], shortcut_names[sc_c].name)) - { - sc_id = sc_c; - break; - } - } - - if(sc_id == -1) - { - notify(WARNING, "No such shortcut function exists"); - return FALSE; - } - - /* parse modifier and key */ - int mask = 0; - int key = 0; - int keyl = strlen(ks); - int mode = NORMAL; - - // single key (e.g.: g) - if(keyl == 1) - key = ks[0]; - - // modifier and key (e.g.: - // special key or modifier and key/special key (e.g.: , ) - - else if(keyl >= 3 && ks[0] == '<' && ks[keyl-1] == '>') - { - char* specialkey = NULL; - - /* check for modifier */ - if(keyl >= 5 && ks[2] == '-') - { - /* evaluate modifier */ - switch(ks[1]) - { - case 'S': - mask = GDK_SHIFT_MASK; - break; - case 'C': - mask = GDK_CONTROL_MASK; - break; - } - - /* no valid modifier */ - if(!mask) - { - notify(WARNING, "No valid modifier given."); - return FALSE; - } - - /* modifier and special key */ - if(keyl > 5) - specialkey = g_strndup(ks + 3, keyl - 4); - else - key = ks[3]; - } - else - specialkey = ks; - - /* search special key */ - int g_c; - for(g_c = 0; specialkey && g_c < LENGTH(gdk_keys); g_c++) - { - if(!strcmp(specialkey, gdk_keys[g_c].identifier)) - { - key = gdk_keys[g_c].key; - break; - } - } - - if(specialkey) - g_free(specialkey); - } - - if(!key) - { - notify(WARNING, "No valid key binding given."); - return FALSE; - } - - /* parse argument */ - Argument arg = {0, 0}; - - if(argc >= 3) - { - int arg_id = -1; - - /* compare argument with given argument names... */ - int arg_c; - for(arg_c = 0; arg_c < LENGTH(argument_names); arg_c++) - { - if(!strcmp(argv[2], argument_names[arg_c].name)) - { - arg_id = argument_names[arg_c].argument; - break; - } - } - - /* if not, save it do .data */ - if(arg_id == -1) - arg.data = argv[2]; - else - arg.n = arg_id; - } - - /* parse mode */ - if(argc >= 4) - { - int mode_c; - for(mode_c = 0; mode_c < LENGTH(mode_names); mode_c++) - { - if(!strcmp(argv[3], mode_names[mode_c].name)) - { - mode = mode_names[mode_c].mode; - break; - } - } - } - - /* search for existing binding to overwrite it */ - ShortcutList* sc = Zathura.Bindings.sclist; - while(sc && sc->next != NULL) - { - if(sc->element.key == key && sc->element.mask == mask - && sc->element.mode == mode) - { - sc->element.function = shortcut_names[sc_id].function; - sc->element.argument = arg; - return TRUE; - } - - sc = sc->next; - } - - /* create new entry */ - ShortcutList* entry = malloc(sizeof(ShortcutList)); - if(!entry) - out_of_memory(); - - entry->element.mask = mask; - entry->element.key = key; - entry->element.function = shortcut_names[sc_id].function; - entry->element.mode = mode; - entry->element.argument = arg; - entry->next = NULL; - - /* append to list */ - if(!Zathura.Bindings.sclist) - Zathura.Bindings.sclist = entry; - - if(sc) - sc->next = entry; - - return TRUE; -} - -gboolean -cmd_open(int argc, char** argv) -{ - if(argc == 0 || strlen(argv[0]) == 0) - return TRUE; - - /* assembly the arguments back to one string */ - int i = 0; - GString *filepath = g_string_new(""); - for(i = 0; i < argc; i++) - { - if(i != 0) - filepath = g_string_append_c(filepath, ' '); - - filepath = g_string_append(filepath, argv[i]); - } - - gboolean res = open_file(filepath->str, NULL); - g_string_free(filepath, TRUE); - return res; -} - -gboolean -cmd_print(int argc, char** argv) -{ - if(!Zathura.PDF.document) - return TRUE; - - if(argc == 0) - { - notify(WARNING, "No printer specified"); - return FALSE; - } - - char* printer = argv[0]; - char* sites = (argc == 2) ? g_strdup(argv[1]) : g_strdup_printf("1-%i", Zathura.PDF.number_of_pages); - GString *addit = g_string_new(""); - - int i; - for(i = 2; i < argc; i++) - { - if(i != 0) - addit = g_string_append_c(addit, ' '); - - addit = g_string_append(addit, argv[i]); - } - - char* escaped_filename = g_shell_quote(Zathura.PDF.file); - char* escaped_addit = addit->len ? g_shell_quote(addit->str) : g_strdup(""); - char* command = g_strdup_printf(print_command, printer, sites, escaped_addit, escaped_filename); - system(command); - - g_free(sites); - g_free(escaped_filename); - g_free(escaped_addit); - g_free(command); - g_string_free(addit, TRUE); - - return TRUE; -} - -gboolean -cmd_rotate(int argc, char** argv) -{ - return TRUE; -} - -gboolean -cmd_set(int argc, char** argv) -{ - if(argc <= 0) - return FALSE; - - int i; - for(i = 0; i < LENGTH(settings); i++) - { - if(!strcmp(argv[0], settings[i].name)) - { - /* check var type */ - if(settings[i].type == 'b') - { - gboolean *x = (gboolean*) (settings[i].variable); - *x = !(*x); - - if(argv[1]) - { - if(!strcmp(argv[1], "false") || !strcmp(argv[1], "0")) - *x = FALSE; - else - *x = TRUE; - } - } - else if(settings[i].type == 'i') - { - if(argc != 2) - return FALSE; - - int *x = (int*) (settings[i].variable); - - int id = -1; - int arg_c; - for(arg_c = 0; arg_c < LENGTH(argument_names); arg_c++) - { - if(!strcmp(argv[1], argument_names[arg_c].name)) - { - id = argument_names[arg_c].argument; - break; - } - } - - if(id == -1) - id = atoi(argv[1]); - - *x = id; - } - else if(settings[i].type == 'f') - { - if(argc != 2) - return FALSE; - - float *x = (float*) (settings[i].variable); - if(argv[1]) - *x = atof(argv[1]); - } - else if(settings[i].type == 's') - { - if(argc < 2) - return FALSE; - - /* assembly the arguments back to one string */ - int j; - GString *s = g_string_new(""); - for(j = 1; j < argc; j++) - { - if(j != 1) - s = g_string_append_c(s, ' '); - - s = g_string_append(s, argv[j]); - } - - char **x = (char**) settings[i].variable; - *x = s->str; - } - else if(settings[i].type == 'c') - { - if(argc != 2) - return FALSE; - - char *x = (char*) (settings[i].variable); - if(argv[1]) - *x = argv[1][0]; - } - - /* re-init */ - if(settings[i].reinit) - init_look(); - - /* render */ - if(settings[i].render) - { - if(!Zathura.PDF.document) - return FALSE; - - draw(Zathura.PDF.page_number); - } - } - } - - update_status(); - return TRUE; -} - -gboolean -cmd_quit(int argc, char** argv) -{ - cb_destroy(NULL, NULL); - return TRUE; -} - -gboolean -cmd_save(int argc, char** argv) -{ - if(argc == 0 || !Zathura.PDF.document) - return TRUE; - - gchar* file_path = NULL; - - if(argv[0][0] == '~') - { - gchar* home_path = get_home_dir(); - file_path = g_build_filename(home_path, argv[0] + 1, NULL); - g_free(home_path); - } - else - file_path = g_strdup(argv[0]); - - char* path = g_strdup_printf("file://%s", file_path); - g_free(file_path); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_document_save(Zathura.PDF.document, path, NULL); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - g_free(path); - - return TRUE; -} - -/* completion command implementation */ -Completion* -cc_bookmark(char* input) -{ - Completion* completion = completion_init(); - CompletionGroup* group = completion_group_create(NULL); - - completion_add_group(completion, group); - - int i = 0; - int input_length = input ? strlen(input) : 0; - - for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++) - { - if( (input_length <= strlen(Zathura.Bookmarks.bookmarks[i].id)) && - !strncmp(input, Zathura.Bookmarks.bookmarks[i].id, input_length) ) - { - completion_group_add_element(group, Zathura.Bookmarks.bookmarks[i].id, g_strdup_printf("Page %d", Zathura.Bookmarks.bookmarks[i].page)); - } - } - - return completion; -} - -Completion* -cc_export(char* input) -{ - Completion* completion = completion_init(); - CompletionGroup* group = completion_group_create(NULL); - - completion_add_group(completion, group); - - completion_group_add_element(group, "images", "Export images"); - completion_group_add_element(group, "attachments", "Export attachments"); - - return completion; -} - -Completion* -cc_open(char* input) -{ - Completion* completion = completion_init(); - CompletionGroup* group = completion_group_create(NULL); - - completion_add_group(completion, group); - - /* ~ */ - if(input && input[0] == '~') - { - gchar* home_path = get_home_dir(); - char *file = g_strdup_printf(":open %s/%s", home_path, input + 1); - g_free(home_path); - gtk_entry_set_text(Zathura.UI.inputbar, file); - gtk_editable_set_position(GTK_EDITABLE(Zathura.UI.inputbar), -1); - g_free(file); - return NULL; - } - - /* read dir */ - char* path = g_strdup("/"); - char* file = g_strdup(""); - int file_length = 0; - - /* parse input string */ - if(input && strlen(input) > 0) - { - char* dinput = g_strdup(input); - char* binput = g_strdup(input); - char* path_temp = dirname(dinput); - char* file_temp = basename(binput); - char last_char = input[strlen(input) - 1]; - - if( !strcmp(path_temp, "/") && !strcmp(file_temp, "/") ) - { - g_free(file); - file = g_strdup(""); - } - else if( !strcmp(path_temp, "/") && strcmp(file_temp, "/") && last_char != '/') - { - g_free(file); - file = g_strdup(file_temp); - } - else if( !strcmp(path_temp, "/") && strcmp(file_temp, "/") && last_char == '/') - { - g_free(path); - path = g_strdup_printf("/%s/", file_temp); - } - else if(last_char == '/') - { - g_free(path); - path = g_strdup(input); - } - else - { - g_free(path); - g_free(file); - path = g_strdup_printf("%s/", path_temp); - file = g_strdup(file_temp); - } - - g_free(dinput); - g_free(binput); - } - - file_length = strlen(file); - - /* open directory */ - GDir* dir = g_dir_open(path, 0, NULL); - if(!dir) - { - g_free(path); - g_free(file); - return NULL; - } - - /* create element list */ - char* name = NULL; - - while((name = (char*) g_dir_read_name(dir)) != NULL) - { - char* d_name = g_filename_display_name(name); - int d_length = strlen(d_name); - - if( ((file_length <= d_length) && !strncmp(file, d_name, file_length)) || - (file_length == 0) ) - { - char* d = g_strdup_printf("%s%s", path, d_name); - if(g_file_test(d, G_FILE_TEST_IS_DIR)) - { - gchar *subdir = d; - d = g_strdup_printf("%s/", subdir); - g_free(subdir); - } - completion_group_add_element(group, d, NULL); - g_free(d); - } - g_free(d_name); - } - - g_dir_close(dir); - g_free(file); - g_free(path); - - return completion; -} - -Completion* -cc_print(char* input) -{ - Completion* completion = completion_init(); - CompletionGroup* group = completion_group_create(NULL); - - completion_add_group(completion, group); - - int input_length = input ? strlen(input) : 0; - - /* read printers */ - char *current_line = NULL, current_char; - int count = 0; - FILE *fp; - - fp = popen(list_printer_command, "r"); - - if(!fp) - { - completion_free(completion); - return NULL; - } - - while((current_char = fgetc(fp)) != EOF) - { - if(!current_line) - current_line = malloc(sizeof(char)); - if(!current_line) - out_of_memory(); - - current_line = realloc(current_line, (count + 1) * sizeof(char)); - - if(current_char != '\n') - current_line[count++] = current_char; - else - { - current_line[count] = '\0'; - int line_length = strlen(current_line); - - if( (input_length <= line_length) || - (!strncmp(input, current_line, input_length)) ) - { - completion_group_add_element(group, current_line, NULL); - } - - free(current_line); - current_line = NULL; - count = 0; - } - } - - pclose(fp); - - return completion; -} - -Completion* -cc_set(char* input) -{ - Completion* completion = completion_init(); - CompletionGroup* group = completion_group_create(NULL); - - completion_add_group(completion, group); - - int i = 0; - int input_length = input ? strlen(input) : 0; - - for(i = 0; i < LENGTH(settings); i++) - { - if( (input_length <= strlen(settings[i].name)) && - !strncmp(input, settings[i].name, input_length) ) - { - completion_group_add_element(group, settings[i].name, settings[i].description); - } - } - - return completion; -} - -/* buffer command implementation */ -void -bcmd_goto(char* buffer, Argument* argument) -{ - if(!Zathura.PDF.document) - return; - - int b_length = strlen(buffer); - if(b_length < 1) - return; - - if(!strcmp(buffer, "gg")) - set_page(0); - else if(!strcmp(buffer, "G")) - set_page(Zathura.PDF.number_of_pages - 1); - else - { - char* id = g_strndup(buffer, b_length - 1); - int pid = atoi(id); - - if(Zathura.Global.goto_mode == GOTO_LABELS) - { - int i; - for(i = 0; i < Zathura.PDF.number_of_pages; i++) - if(!strcmp(id, Zathura.PDF.pages[i]->label)) - pid = Zathura.PDF.pages[i]->id; - } - else if(Zathura.Global.goto_mode == GOTO_OFFSET) - pid += Zathura.PDF.page_offset; - - set_page(pid - 1); - g_free(id); - } - - update_status(); -} - -void -bcmd_scroll(char* buffer, Argument* argument) -{ - int b_length = strlen(buffer); - if(b_length < 1) - return; - - int percentage = atoi(g_strndup(buffer, b_length - 1)); - percentage = (percentage < 0) ? 0 : ((percentage > 100) ? 100 : percentage); - - GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(Zathura.UI.view); - - gdouble view_size = gtk_adjustment_get_page_size(adjustment); - gdouble max = gtk_adjustment_get_upper(adjustment) - view_size; - gdouble nvalue = (percentage * max) / 100; - - Zathura.State.scroll_percentage = percentage; - gtk_adjustment_set_value(adjustment, nvalue); - update_status(); -} - -void -bcmd_zoom(char* buffer, Argument* argument) -{ - Zathura.Global.adjust_mode = ADJUST_NONE; - - if(argument->n == ZOOM_IN) - { - if((Zathura.PDF.scale + zoom_step) <= zoom_max) - Zathura.PDF.scale += zoom_step; - else - Zathura.PDF.scale = zoom_max; - } - else if(argument->n == ZOOM_OUT) - { - if((Zathura.PDF.scale - zoom_step) >= zoom_min) - Zathura.PDF.scale -= zoom_step; - else - Zathura.PDF.scale = zoom_min; - } - else if(argument->n == ZOOM_SPECIFIC) - { - int b_length = strlen(buffer); - if(b_length < 1) - return; - - int value = atoi(g_strndup(buffer, b_length - 1)); - if(value <= zoom_min) - Zathura.PDF.scale = zoom_min; - else if(value >= zoom_max) - Zathura.PDF.scale = zoom_max; - else - Zathura.PDF.scale = value; - } - else - Zathura.PDF.scale = 100; - - Zathura.Search.draw = TRUE; - draw(Zathura.PDF.page_number); - update_status(); -} - -/* special command implementation */ -gboolean -scmd_search(char* input, Argument* argument) -{ - if(!strlen(input)) - return TRUE; - - argument->data = input; - sc_search(argument); - - return TRUE; -} - -/* callback implementation */ -gboolean -cb_destroy(GtkWidget* widget, gpointer data) -{ - pango_font_description_free(Zathura.Style.font); - - if(Zathura.PDF.document) - close_file(FALSE); - - /* clean up other variables */ - g_free(Zathura.Bookmarks.file); - - /* inotify */ - if(Zathura.FileMonitor.monitor) - g_object_unref(Zathura.FileMonitor.monitor); - if(Zathura.FileMonitor.file) - g_object_unref(Zathura.FileMonitor.file); - - g_list_free(Zathura.Global.history); - - /* clean shortcut list */ - ShortcutList* sc = Zathura.Bindings.sclist; - - while(sc) - { - ShortcutList* ne = sc->next; - free(sc); - sc = ne; - } - - g_free(Zathura.State.filename); - g_free(Zathura.State.pages); - - g_free(Zathura.Config.config_dir); - g_free(Zathura.Config.data_dir); - if (Zathura.StdinSupport.file) - g_unlink(Zathura.StdinSupport.file); - g_free(Zathura.StdinSupport.file); - - gtk_main_quit(); - - return TRUE; -} - -gboolean cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data) -{ - if(!Zathura.PDF.document) - return FALSE; - - int page_id = Zathura.PDF.page_number; - if(page_id < 0 || page_id > Zathura.PDF.number_of_pages) - return FALSE; - - gdk_window_clear(widget->window); - cairo_t *cairo = gdk_cairo_create(widget->window); - - double page_width, page_height, width, height; - double scale = ((double) Zathura.PDF.scale / 100.0); - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_page_get_size(Zathura.PDF.pages[page_id]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - if(Zathura.PDF.rotate == 0 || Zathura.PDF.rotate == 180) - { - width = page_width * scale; - height = page_height * scale; - } - else - { - width = page_height * scale; - height = page_width * scale; - } - - int window_x, window_y; - gdk_drawable_get_size(widget->window, &window_x, &window_y); - - int offset_x, offset_y; - - if (window_x > width) - offset_x = (window_x - width) / 2; - else - offset_x = 0; - - if (window_y > height) - offset_y = (window_y - height) / 2; - else - offset_y = 0; - - if(Zathura.Search.draw) - { - GList* list; - for(list = Zathura.Search.results; list && list->data; list = g_list_next(list)) - highlight_result(Zathura.Search.page, (PopplerRectangle*) list->data); - Zathura.Search.draw = FALSE; - } - - cairo_set_source_surface(cairo, Zathura.PDF.surface, offset_x, offset_y); - cairo_paint(cairo); - cairo_destroy(cairo); - - return TRUE; -} - -gboolean -cb_inputbar_kb_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data) -{ - int i; - - /* inputbar shortcuts */ - for(i = 0; i < LENGTH(inputbar_shortcuts); i++) - { - if(event->keyval == inputbar_shortcuts[i].key && - (((event->state & inputbar_shortcuts[i].mask) == inputbar_shortcuts[i].mask) - || inputbar_shortcuts[i].mask == 0)) - { - inputbar_shortcuts[i].function(&(inputbar_shortcuts[i].argument)); - return TRUE; - } - } - - /* special commands */ - char identifier = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 0, 1)[0]; - for(i = 0; i < LENGTH(special_commands); i++) - { - if((identifier == special_commands[i].identifier) && - (special_commands[i].always == 1)) - { - gchar *input = gtk_editable_get_chars(GTK_EDITABLE(Zathura.UI.inputbar), 1, -1); - special_commands[i].function(input, &(special_commands[i].argument)); - return FALSE; - } - } - - return FALSE; -} - -gboolean -cb_inputbar_activate(GtkEntry* entry, gpointer data) -{ - gchar *input = gtk_editable_get_chars(GTK_EDITABLE(entry), 1, -1); - gchar **tokens = g_strsplit(input, " ", -1); - gchar *command = tokens[0]; - int length = g_strv_length(tokens); - int i = 0; - gboolean retv = FALSE; - gboolean succ = FALSE; - - /* no input */ - if(length < 1) - { - isc_abort(NULL); - return FALSE; - } - - /* append input to the command history */ - Zathura.Global.history = g_list_append(Zathura.Global.history, g_strdup(gtk_entry_get_text(entry))); - - /* special commands */ - char identifier = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, 1)[0]; - for(i = 0; i < LENGTH(special_commands); i++) - { - if(identifier == special_commands[i].identifier) - { - /* special commands that are evaluated every key change are not - * called here */ - if(special_commands[i].always == 1) - { - isc_abort(NULL); - return TRUE; - } - - retv = special_commands[i].function(input, &(special_commands[i].argument)); - if(retv) isc_abort(NULL); - gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view)); - return TRUE; - } - } - - /* search commands */ - for(i = 0; i < LENGTH(commands); i++) - { - if((g_strcmp0(command, commands[i].command) == 0) || - (g_strcmp0(command, commands[i].abbr) == 0)) - { - retv = commands[i].function(length - 1, tokens + 1); - succ = TRUE; - break; - } - } - - if(retv) - isc_abort(NULL); - - if(!succ) - notify(ERROR, "Unknown command."); - - Argument arg = { HIDE }; - isc_completion(&arg); - gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view)); - - return TRUE; -} - -gboolean -cb_inputbar_form_activate(GtkEntry* entry, gpointer data) -{ - if(!Zathura.PDF.document) - return TRUE; - - Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number]; - int number_of_links = 0, link_id = 1, new_page_id = Zathura.PDF.page_number; - - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - GList *link_list = poppler_page_get_link_mapping(current_page->page); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - link_list = g_list_reverse(link_list); - - if((number_of_links = g_list_length(link_list)) <= 0) - return FALSE; - - /* parse entry */ - gchar *input = gtk_editable_get_chars(GTK_EDITABLE(entry), 1, -1); - gchar *token = input + strlen("Follow hint: ") - 1; - if(!token) - return FALSE; - - int li = atoi(token); - if(li <= 0 || li > number_of_links) - { - set_page(Zathura.PDF.page_number); - isc_abort(NULL); - notify(WARNING, "Invalid hint"); - return TRUE; - } - - /* compare entry */ - GList *links; - for(links = link_list; links; links = g_list_next(links)) - { - PopplerLinkMapping *link_mapping = (PopplerLinkMapping*) links->data; - PopplerAction *action = link_mapping->action; - - /* only handle URI and internal links */ - if(action->type == POPPLER_ACTION_URI) - { - if(li == link_id) - open_uri(action->uri.uri); - } - else if(action->type == POPPLER_ACTION_GOTO_DEST) - { - if(li == link_id) - { - if(action->goto_dest.dest->type == POPPLER_DEST_NAMED) - { - PopplerDest* destination = poppler_document_find_dest(Zathura.PDF.document, action->goto_dest.dest->named_dest); - if(destination) - { - new_page_id = destination->page_num - 1; - poppler_dest_free(destination); - } - } - else - new_page_id = action->goto_dest.dest->page_num - 1; - } - } - else - continue; - - link_id++; - } - - poppler_page_free_link_mapping(link_list); - - /* reset all */ - set_page(new_page_id); - isc_abort(NULL); - - return TRUE; -} - -gboolean -cb_inputbar_password_activate(GtkEntry* entry, gpointer data) -{ - gchar *input = gtk_editable_get_chars(GTK_EDITABLE(entry), 1, -1); - gchar *token = input + strlen("Enter password: ") - 1; - if(!token) - return FALSE; - - if(!open_file(Zathura.PDF.file, token)) - { - enter_password(); - return TRUE; - } - - /* replace default inputbar handler */ - g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate); - Zathura.Handler.inputbar_activate = g_signal_connect(G_OBJECT(Zathura.UI.inputbar), "activate", G_CALLBACK(cb_inputbar_activate), NULL); - - isc_abort(NULL); - - return TRUE; -} - -gboolean -cb_view_kb_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data) -{ - ShortcutList* sc = Zathura.Bindings.sclist; - while(sc) - { - if( - event->keyval == sc->element.key - && (CLEAN(event->state) == sc->element.mask || (sc->element.key >= 0x21 - && sc->element.key <= 0x7E && CLEAN(event->state) == GDK_SHIFT_MASK)) - && (Zathura.Global.mode & sc->element.mode || sc->element.mode == ALL) - && sc->element.function - ) - { - if(!(Zathura.Global.buffer && strlen(Zathura.Global.buffer->str)) || (sc->element.mask == GDK_CONTROL_MASK) || - (sc->element.key <= 0x21 || sc->element.key >= 0x7E) - ) - { - sc->element.function(&(sc->element.argument)); - return TRUE; - } - } - - sc = sc->next; - } - - if(Zathura.Global.mode == ADD_MARKER) - { - add_marker(event->keyval); - change_mode(NORMAL); - return TRUE; - } - else if(Zathura.Global.mode == EVAL_MARKER) - { - eval_marker(event->keyval); - change_mode(NORMAL); - return TRUE; - } - - /* append only numbers and characters to buffer */ - if( (event->keyval >= 0x21) && (event->keyval <= 0x7E)) - { - if(!Zathura.Global.buffer) - Zathura.Global.buffer = g_string_new(""); - - Zathura.Global.buffer = g_string_append_c(Zathura.Global.buffer, event->keyval); - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, Zathura.Global.buffer->str); - } - - /* search buffer commands */ - if(Zathura.Global.buffer) - { - int i; - for(i = 0; i < LENGTH(buffer_commands); i++) - { - regex_t regex; - int status; - - regcomp(®ex, buffer_commands[i].regex, REG_EXTENDED); - status = regexec(®ex, Zathura.Global.buffer->str, (size_t) 0, NULL, 0); - regfree(®ex); - - if(status == 0) - { - buffer_commands[i].function(Zathura.Global.buffer->str, &(buffer_commands[i].argument)); - g_string_free(Zathura.Global.buffer, TRUE); - Zathura.Global.buffer = NULL; - gtk_label_set_markup((GtkLabel*) Zathura.Global.status_buffer, ""); - - return TRUE; - } - } - } - - return FALSE; -} - -gboolean -cb_view_resized(GtkWidget* widget, GtkAllocation* allocation, gpointer data) -{ - Argument arg; - arg.n = Zathura.Global.adjust_mode; - sc_adjust_window(&arg); - - return TRUE; -} - -gboolean -cb_view_button_pressed(GtkWidget* widget, GdkEventButton* event, gpointer data) -{ - if(!Zathura.PDF.document) - return FALSE; - - /* clean page */ - draw(Zathura.PDF.page_number); - g_static_mutex_lock(&(Zathura.Lock.select_lock)); - Zathura.SelectPoint.x = event->x; - Zathura.SelectPoint.y = event->y; - g_static_mutex_unlock(&(Zathura.Lock.select_lock)); - - return TRUE; -} - -gboolean -cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data) -{ - if(!Zathura.PDF.document) - return FALSE; - - double scale, offset_x, offset_y, page_width, page_height; - PopplerRectangle rectangle; - cairo_t* cairo; - - /* build selection rectangle */ - rectangle.x1 = event->x; - rectangle.y1 = event->y; - - g_static_mutex_lock(&(Zathura.Lock.select_lock)); - rectangle.x2 = Zathura.SelectPoint.x; - rectangle.y2 = Zathura.SelectPoint.y; - g_static_mutex_unlock(&(Zathura.Lock.select_lock)); - - /* calculate offset */ - calculate_offset(widget, &offset_x, &offset_y); - - /* draw selection rectangle */ - cairo = cairo_create(Zathura.PDF.surface); - cairo_set_source_rgba(cairo, Zathura.Style.select_text.red, Zathura.Style.select_text.green, - Zathura.Style.select_text.blue, transparency); - cairo_rectangle(cairo, rectangle.x1 - offset_x, rectangle.y1 - offset_y, - (rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1)); - cairo_fill(cairo); - cairo_destroy(cairo); - gtk_widget_queue_draw(Zathura.UI.drawing_area); - - /* resize selection rectangle to document page */ - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height); - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - scale = ((double) Zathura.PDF.scale / 100.0); - rectangle.x1 = (rectangle.x1 - offset_x) / scale; - rectangle.y1 = (rectangle.y1 - offset_y) / scale; - rectangle.x2 = (rectangle.x2 - offset_x) / scale; - rectangle.y2 = (rectangle.y2 - offset_y) / scale; - - /* rotation */ - int rotate = Zathura.PDF.rotate; - double x1 = rectangle.x1; - double x2 = rectangle.x2; - double y1 = rectangle.y1; - double y2 = rectangle.y2; - - switch(rotate) - { - case 90: - rectangle.x1 = y1; - rectangle.y1 = page_height - x2; - rectangle.x2 = y2; - rectangle.y2 = page_height - x1; - break; - case 180: - rectangle.x1 = (page_height - y1); - rectangle.y1 = (page_width - x2); - rectangle.x2 = (page_height - y2); - rectangle.y2 = (page_width - x1); - break; - case 270: - rectangle.x1 = page_width - y2; - rectangle.y1 = x1; - rectangle.x2 = page_width - y1; - rectangle.y2 = x2; - break; - } - - /* reset points of the rectangle so that p1 is in the top-left corner - * and p2 is in the bottom right corner */ - if(rectangle.x1 > rectangle.x2) - { - double d = rectangle.x1; - rectangle.x1 = rectangle.x2; - rectangle.x2 = d; - } - if(rectangle.y2 > rectangle.y1) - { - double d = rectangle.y1; - rectangle.y1 = rectangle.y2; - rectangle.y2 = d; - } - - /* adapt y coordinates */ - rectangle.y1 = page_height - rectangle.y1; - rectangle.y2 = page_height - rectangle.y2; - - /* get selected text */ - g_static_mutex_lock(&(Zathura.Lock.pdflib_lock)); - char* selected_text = poppler_page_get_text( - Zathura.PDF.pages[Zathura.PDF.page_number]->page,SELECTION_STYLE, - &rectangle); - - if(selected_text) - { - gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), selected_text, -1); - g_free(selected_text); - } - g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock)); - - - return TRUE; -} - -gboolean -cb_view_motion_notify(GtkWidget* widget, GdkEventMotion* event, gpointer data) -{ - return TRUE; -} - -gboolean -cb_view_scrolled(GtkWidget* widget, GdkEventScroll* event, gpointer data) -{ - int i; - for(i = 0; i < LENGTH(mouse_scroll_events); i++) - { - if(event->direction == mouse_scroll_events[i].direction) - { - mouse_scroll_events[i].function(&(mouse_scroll_events[i].argument)); - return TRUE; - } - } - - return FALSE; -} - -gboolean -cb_watch_file(GFileMonitor* monitor, GFile* file, GFile* other_file, GFileMonitorEvent event, gpointer data) -{ - if(event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) - return FALSE; - - sc_reload(NULL); - - return TRUE; + return true; } /* main function */ int main(int argc, char* argv[]) { - /* embed */ - Zathura.UI.embed = 0; - - Zathura.Config.config_dir = 0; - Zathura.Config.data_dir = 0; - - char* config_dir = 0; - char* data_dir = 0; - GOptionEntry entries[] = - { - { "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, &config_dir, "Path to the config directory", "path" }, - { "data-dir", 'd', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_STRING, &data_dir, "Path to the data directory", "path" }, - { NULL } - }; - - 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); - - if (config_dir) - Zathura.Config.config_dir = g_strdup(config_dir); - if (data_dir) - Zathura.Config.data_dir = g_strdup(data_dir); - g_thread_init(NULL); gdk_threads_init(); - gtk_init(&argc, &argv); - init_zathura(); - init_directories(); - init_keylist(); - read_configuration(); - init_settings(); - init_bookmarks(); - init_look(); - - if(argc > 1) - { - char* password = (argc == 3) ? argv[2] : NULL; - if (strcmp(argv[1], "-") == 0) - open_stdin(password); - else - open_file(argv[1], password); + if(!init_zathura()) { + printf("error: coult not initialize zathura\n"); + return -1; } - switch_view(Zathura.UI.document); - update_status(); - - gtk_widget_show_all(GTK_WIDGET(Zathura.UI.window)); - gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view)); - - if(!Zathura.Global.show_inputbar) - gtk_widget_hide(GTK_WIDGET(Zathura.UI.inputbar)); - - if(!Zathura.Global.show_statusbar) - gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar)); - gdk_threads_enter(); gtk_main(); gdk_threads_leave(); diff --git a/zathura.h b/zathura.h new file mode 100644 index 0000000..5cb2b9b --- /dev/null +++ b/zathura.h @@ -0,0 +1,25 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef ZATHURA_H +#define ZATHURA_H + +#include +#include + +struct +{ + struct + { + girara_session_t* session; /**> girara interface session */ + } UI; +} Zathura; + +/** + * Initializes zathura + * + * @return If no error occured true, otherwise false, is returned. + */ + +bool init_zathura(); + +#endif // ZATHURA_H From d51bd2bbe6efb32c226d3228bfe0e8985e5abfe8 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 10 Nov 2010 20:31:15 +0100 Subject: [PATCH 002/197] Updated file structure --- Makefile | 2 +- callbacks.c | 1 + callbacks.h | 1 + commands.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ commands.h | 12 ++++++++++++ completion.c | 1 + completion.h | 1 + config.c | 1 + config.h | 1 + shortcuts.h | 1 + utils.h | 1 + 11 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 completion.c create mode 100644 completion.h create mode 100644 config.h diff --git a/Makefile b/Makefile index 9623fbb..3b988ed 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include config.mk PROJECT = zathura -SOURCE = zathura.c +SOURCE = callbacks.c commands.c config.c shortcuts.c utils.c zathura.c OBJECTS = ${SOURCE:.c=.o} DOBJECTS = ${SOURCE:.c=.do} diff --git a/callbacks.c b/callbacks.c index e69de29..6c3efe1 100644 --- a/callbacks.c +++ b/callbacks.c @@ -0,0 +1 @@ +/* See LICENSE file for license and copyright information */ diff --git a/callbacks.h b/callbacks.h index e69de29..6c3efe1 100644 --- a/callbacks.h +++ b/callbacks.h @@ -0,0 +1 @@ +/* See LICENSE file for license and copyright information */ diff --git a/commands.c b/commands.c index e69de29..4774076 100644 --- a/commands.c +++ b/commands.c @@ -0,0 +1,45 @@ +/* See LICENSE file for license and copyright information */ + +#include "commands.h" + +bool +cmd_bookmark_create(girara_session_t* session, int argc, char** argv) +{ + return true; +} + +bool +cmd_bookmark_delete(girara_session_t* session, int argc, char** argv) +{ + return true; +} + +bool +cmd_bookmark_open(girara_session_t* session, int argc, char** argv) +{ + return true; +} + +bool +cmd_close(girara_session_t* session, int argc, char** argv) +{ + return true; +} + +bool +cmd_info(girara_session_t* session, int argc, char** argv) +{ + return true; +} + +bool +cmd_print(girara_session_t* session, int argc, char** argv) +{ + return true; +} + +bool +cmd_save(girara_session_t* session, int argc, char** argv) +{ + return true; +} diff --git a/commands.h b/commands.h index e69de29..31d6b06 100644 --- a/commands.h +++ b/commands.h @@ -0,0 +1,12 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include + +bool cmd_bookmark_create(girara_session_t* session, int argc, char** argv); +bool cmd_bookmark_delete(girara_session_t* session, int argc, char** argv); +bool cmd_bookmark_open(girara_session_t* session, int argc, char** argv); +bool cmd_close(girara_session_t* session, int argc, char** argv); +bool cmd_info(girara_session_t* session, int argc, char** argv); +bool cmd_print(girara_session_t* session, int argc, char** argv); +bool cmd_save(girara_session_t* session, int argc, char** argv); diff --git a/completion.c b/completion.c new file mode 100644 index 0000000..6c3efe1 --- /dev/null +++ b/completion.c @@ -0,0 +1 @@ +/* See LICENSE file for license and copyright information */ diff --git a/completion.h b/completion.h new file mode 100644 index 0000000..6c3efe1 --- /dev/null +++ b/completion.h @@ -0,0 +1 @@ +/* See LICENSE file for license and copyright information */ diff --git a/config.c b/config.c index e69de29..6c3efe1 100644 --- a/config.c +++ b/config.c @@ -0,0 +1 @@ +/* See LICENSE file for license and copyright information */ diff --git a/config.h b/config.h new file mode 100644 index 0000000..6c3efe1 --- /dev/null +++ b/config.h @@ -0,0 +1 @@ +/* See LICENSE file for license and copyright information */ diff --git a/shortcuts.h b/shortcuts.h index e69de29..6c3efe1 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -0,0 +1 @@ +/* See LICENSE file for license and copyright information */ diff --git a/utils.h b/utils.h index e69de29..6c3efe1 100644 --- a/utils.h +++ b/utils.h @@ -0,0 +1 @@ +/* See LICENSE file for license and copyright information */ From 6046fc71fbdb39a87ce3e6115aeb3fd28c097828 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 10 Nov 2010 20:47:53 +0100 Subject: [PATCH 003/197] Include guards and shortcut definitions --- callbacks.h | 5 +++ commands.h | 5 +++ completion.h | 5 +++ config.h | 5 +++ shortcuts.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++ shortcuts.h | 28 ++++++++++++ utils.h | 5 +++ 7 files changed, 176 insertions(+) diff --git a/callbacks.h b/callbacks.h index 6c3efe1..5e6ddf9 100644 --- a/callbacks.h +++ b/callbacks.h @@ -1 +1,6 @@ /* See LICENSE file for license and copyright information */ + +#ifndef CALLBACKS_H +#define CALLBACKS_H + +#endif // CALLBACKS_H diff --git a/commands.h b/commands.h index 31d6b06..5096510 100644 --- a/commands.h +++ b/commands.h @@ -1,5 +1,8 @@ /* See LICENSE file for license and copyright information */ +#ifndef COMMANDS_H +#define COMMANDS_H + #include #include @@ -10,3 +13,5 @@ bool cmd_close(girara_session_t* session, int argc, char** argv); bool cmd_info(girara_session_t* session, int argc, char** argv); bool cmd_print(girara_session_t* session, int argc, char** argv); bool cmd_save(girara_session_t* session, int argc, char** argv); + +#endif // COMMANDS_H diff --git a/completion.h b/completion.h index 6c3efe1..ea9c0a2 100644 --- a/completion.h +++ b/completion.h @@ -1 +1,6 @@ /* See LICENSE file for license and copyright information */ + +#ifndef COMPLETION_H +#define COMPLETION_H + +#endif // COMPLETION_H diff --git a/config.h b/config.h index 6c3efe1..8f118bf 100644 --- a/config.h +++ b/config.h @@ -1 +1,6 @@ /* See LICENSE file for license and copyright information */ + +#ifndef CONFIG_H +#define CONFIG_H + +#endif // CONFIG_H diff --git a/shortcuts.c b/shortcuts.c index e69de29..fc7c936 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -0,0 +1,123 @@ +/* See LICENSE file for license and copyright information */ + +#include "shortcuts.h" + +void +sc_abort(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_adjust_window(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_change_buffer(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_change_mode(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_follow(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_navigate(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_recolor(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_reload(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_rotate(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_scroll(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_search(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_navigate_index(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_toggle_index(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_quit(girara_session_t* session, girara_argument_t* argument) +{ + +} + +void +sc_zoom(girara_session_t* session, girara_argument_t* argument) +{ + +} diff --git a/shortcuts.h b/shortcuts.h index 6c3efe1..5b8f747 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -1 +1,29 @@ /* See LICENSE file for license and copyright information */ + +#ifndef SHORTCUTS_H +#define SHORTCUTS_H + +#include + +void sc_abort(girara_session_t* session, girara_argument_t* argument); +void sc_adjust_window(girara_session_t* session, girara_argument_t* argument); +void sc_change_buffer(girara_session_t* session, girara_argument_t* argument); +void sc_change_mode(girara_session_t* session, girara_argument_t* argument); +void sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument); +void sc_follow(girara_session_t* session, girara_argument_t* argument); +void sc_navigate(girara_session_t* session, girara_argument_t* argument); +void sc_recolor(girara_session_t* session, girara_argument_t* argument); +void sc_reload(girara_session_t* session, girara_argument_t* argument); +void sc_rotate(girara_session_t* session, girara_argument_t* argument); +void sc_scroll(girara_session_t* session, girara_argument_t* argument); +void sc_search(girara_session_t* session, girara_argument_t* argument); +void sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument); +void sc_navigate_index(girara_session_t* session, girara_argument_t* argument); +void sc_toggle_index(girara_session_t* session, girara_argument_t* argument); +void sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument); +void sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument); +void sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument); +void sc_quit(girara_session_t* session, girara_argument_t* argument); +void sc_zoom(girara_session_t* session, girara_argument_t* argument); + +#endif // SHORTCUTS_H diff --git a/utils.h b/utils.h index 6c3efe1..931b644 100644 --- a/utils.h +++ b/utils.h @@ -1 +1,6 @@ /* See LICENSE file for license and copyright information */ + +#ifndef UTILS_H +#define UTILS_H + +#endif // UTILS_H From 98d42ed3ce019398d00d6f623c1a1664760b4418 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 12 Nov 2010 13:48:18 +0100 Subject: [PATCH 004/197] Begin to test config structure --- callbacks.c | 14 ++++++++++++++ callbacks.h | 4 ++++ config.c | 12 ++++++++++++ config.h | 2 ++ shortcuts.c | 9 +++++++++ zathura.c | 9 +++++++++ 6 files changed, 50 insertions(+) diff --git a/callbacks.c b/callbacks.c index 6c3efe1..0b5f007 100644 --- a/callbacks.c +++ b/callbacks.c @@ -1 +1,15 @@ /* See LICENSE file for license and copyright information */ + +#include +#include + +#include "zathura.h" + +gboolean +cb_destroy(GtkWidget* widget, gpointer data) +{ + if(Zathura.UI.session) + girara_session_destroy(Zathura.UI.session); + + return TRUE; +} diff --git a/callbacks.h b/callbacks.h index 5e6ddf9..bc544f1 100644 --- a/callbacks.h +++ b/callbacks.h @@ -3,4 +3,8 @@ #ifndef CALLBACKS_H #define CALLBACKS_H +#include + +gboolean cb_destroy(GtkWidget* widget, gpointer data); + #endif // CALLBACKS_H diff --git a/config.c b/config.c index 6c3efe1..b3c9f38 100644 --- a/config.c +++ b/config.c @@ -1 +1,13 @@ /* See LICENSE file for license and copyright information */ + +#include "shortcuts.h" +#include "zathura.h" + +void +config_load_default() +{ + if(!Zathura.UI.session) + return; + + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_q, NULL, sc_quit, 0, 0, NULL); +} diff --git a/config.h b/config.h index 8f118bf..f9f46b8 100644 --- a/config.h +++ b/config.h @@ -3,4 +3,6 @@ #ifndef CONFIG_H #define CONFIG_H +void config_load_default(); + #endif // CONFIG_H diff --git a/shortcuts.c b/shortcuts.c index fc7c936..50f7a6d 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -1,5 +1,9 @@ /* See LICENSE file for license and copyright information */ +#include +#include + +#include "callbacks.h" #include "shortcuts.h" void @@ -113,7 +117,12 @@ sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument) void sc_quit(girara_session_t* session, girara_argument_t* argument) { + girara_argument_t arg = { GIRARA_HIDE, NULL }; + girara_isc_completion(session, &arg); + cb_destroy(NULL, NULL); + + gtk_main_quit(); } void diff --git a/zathura.c b/zathura.c index cd40790..d8656e7 100644 --- a/zathura.c +++ b/zathura.c @@ -1,5 +1,8 @@ /* See LICENSE file for license and copyright information */ +#include "callbacks.h" +#include "config.h" +#include "shortcuts.h" #include "zathura.h" /* function implementation */ @@ -12,6 +15,12 @@ init_zathura() if(!girara_session_init(Zathura.UI.session)) return false; + /* signals */ + g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); + + /* configuration */ + config_load_default(); + return true; } From 9348a128ff7e21d8125b37db8e785df7076f66c8 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 13 Nov 2010 10:05:28 +0100 Subject: [PATCH 005/197] Add default shortcuts --- config.c | 64 ++++++++++++++++++++++++++++++++++++++- shortcuts.c | 86 +++++++++++++++++++++++++++++------------------------ shortcuts.h | 41 ++++++++++++------------- zathura.h | 15 ++++++++++ 4 files changed, 146 insertions(+), 60 deletions(-) diff --git a/config.c b/config.c index b3c9f38..7f81bc9 100644 --- a/config.c +++ b/config.c @@ -9,5 +9,67 @@ config_load_default() if(!Zathura.UI.session) return; - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_q, NULL, sc_quit, 0, 0, NULL); + /* define default shortcuts */ + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, ALL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, ALL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, ALL, DELETE_LAST, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(Zathura.UI.session, GDK_SHIFT_MASK, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(Zathura.UI.session, 0, GDK_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); + girara_shortcut_add(Zathura.UI.session, 0, GDK_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); + girara_shortcut_add(Zathura.UI.session, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); + girara_shortcut_add(Zathura.UI.session, 0, GDK_O, NULL, sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); + girara_shortcut_add(Zathura.UI.session, 0, GDK_f, NULL, sc_follow, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, 0, "gg", sc_goto, NORMAL | FULLSCREEN, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, 0, "G", sc_goto, NORMAL | FULLSCREEN, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_J, NULL, sc_navigate, NORMAL, NEXT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_K, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_MOD1_MASK, GDK_Right, NULL, sc_navigate, NORMAL, NEXT, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_MOD1_MASK, GDK_Left, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Left, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Right, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_k, NULL, sc_navigate_index, INDEX, UP, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_navigate_index, INDEX, SELECT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Return, NULL, sc_navigate_index, INDEX, SELECT, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_i, NULL, sc_recolor, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_R, NULL, sc_reload, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_r, NULL, sc_rotate, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_h, NULL, sc_scroll, NORMAL, LEFT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_j, NULL, sc_scroll, NORMAL, DOWN, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_k, NULL, sc_scroll, NORMAL, UP, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_l, NULL, sc_scroll, NORMAL, RIGHT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Left, NULL, sc_scroll, NORMAL, LEFT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Up, NULL, sc_scroll, NORMAL, DOWN, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Down, NULL, sc_scroll, NORMAL, RIGHT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Right, NULL, sc_scroll, NORMAL, UP, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_d, NULL, sc_scroll, NORMAL, HALF_DOWN, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_u, NULL, sc_scroll, NORMAL, HALF_UP, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_f, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); + girara_shortcut_add(Zathura.UI.session, 0, 0, "%", sc_scroll, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_n, NULL, sc_search, NORMAL, FORWARD, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_N, NULL, sc_search, NORMAL, BACKWARD, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_0, NULL, sc_switch_goto_mode, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Tab, NULL, sc_toggle_index, NORMAL | INDEX, 0, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_m, NULL, sc_toggle_inputbar, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_F5, NULL, sc_toggle_fullscreen, NORMAL | FULLSCREEN, 0, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_n, NULL, sc_toggle_statusbar, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_q, NULL, sc_quit, NORMAL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_plus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_minus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_equal, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(Zathura.UI.session, 0, 0, "zI", sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(Zathura.UI.session, 0, 0, "zO", sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(Zathura.UI.session, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); } diff --git a/shortcuts.c b/shortcuts.c index 50f7a6d..b47db30 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -6,115 +6,121 @@ #include "callbacks.h" #include "shortcuts.h" -void +bool sc_abort(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_change_mode(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_follow(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool +sc_goto(girara_session_t* session, girara_argument_t* argument) +{ + return false; +} + +bool sc_navigate(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_recolor(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_reload(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_rotate(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_scroll(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_search(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument) { - + return false; } -void +bool sc_quit(girara_session_t* session, girara_argument_t* argument) { girara_argument_t arg = { GIRARA_HIDE, NULL }; @@ -123,10 +129,12 @@ sc_quit(girara_session_t* session, girara_argument_t* argument) cb_destroy(NULL, NULL); gtk_main_quit(); + + return false; } -void +bool sc_zoom(girara_session_t* session, girara_argument_t* argument) { - + return false; } diff --git a/shortcuts.h b/shortcuts.h index 5b8f747..22b0310 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -5,25 +5,26 @@ #include -void sc_abort(girara_session_t* session, girara_argument_t* argument); -void sc_adjust_window(girara_session_t* session, girara_argument_t* argument); -void sc_change_buffer(girara_session_t* session, girara_argument_t* argument); -void sc_change_mode(girara_session_t* session, girara_argument_t* argument); -void sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument); -void sc_follow(girara_session_t* session, girara_argument_t* argument); -void sc_navigate(girara_session_t* session, girara_argument_t* argument); -void sc_recolor(girara_session_t* session, girara_argument_t* argument); -void sc_reload(girara_session_t* session, girara_argument_t* argument); -void sc_rotate(girara_session_t* session, girara_argument_t* argument); -void sc_scroll(girara_session_t* session, girara_argument_t* argument); -void sc_search(girara_session_t* session, girara_argument_t* argument); -void sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument); -void sc_navigate_index(girara_session_t* session, girara_argument_t* argument); -void sc_toggle_index(girara_session_t* session, girara_argument_t* argument); -void sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument); -void sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument); -void sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument); -void sc_quit(girara_session_t* session, girara_argument_t* argument); -void sc_zoom(girara_session_t* session, girara_argument_t* argument); +bool sc_abort(girara_session_t* session, girara_argument_t* argument); +bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument); +bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument); +bool sc_change_mode(girara_session_t* session, girara_argument_t* argument); +bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument); +bool sc_follow(girara_session_t* session, girara_argument_t* argument); +bool sc_goto(girara_session_t* session, girara_argument_t* argument); +bool sc_navigate(girara_session_t* session, girara_argument_t* argument); +bool sc_recolor(girara_session_t* session, girara_argument_t* argument); +bool sc_reload(girara_session_t* session, girara_argument_t* argument); +bool sc_rotate(girara_session_t* session, girara_argument_t* argument); +bool sc_scroll(girara_session_t* session, girara_argument_t* argument); +bool sc_search(girara_session_t* session, girara_argument_t* argument); +bool sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument); +bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument); +bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument); +bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument); +bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument); +bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument); +bool sc_quit(girara_session_t* session, girara_argument_t* argument); +bool sc_zoom(girara_session_t* session, girara_argument_t* argument); #endif // SHORTCUTS_H diff --git a/zathura.h b/zathura.h index 5cb2b9b..1a824fc 100644 --- a/zathura.h +++ b/zathura.h @@ -6,6 +6,21 @@ #include #include +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 }; + +/* define modes */ +#define ALL (1 << 0) +#define FULLSCREEN (1 << 1) +#define INDEX (1 << 2) +#define NORMAL (1 << 3) +#define INSERT (1 << 4) + struct { struct From ade141aadcb6b1d33cb0401a5a99a8dee990c8d8 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 13 Nov 2010 12:40:48 +0100 Subject: [PATCH 006/197] Update buffer in the statusbar --- callbacks.c | 18 +++++++++++++++++- callbacks.h | 2 ++ config.c | 9 ++++++--- shortcuts.c | 21 +++++++++++++++++++++ zathura.c | 10 ++++++++++ zathura.h | 1 + 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/callbacks.c b/callbacks.c index 0b5f007..80506e4 100644 --- a/callbacks.c +++ b/callbacks.c @@ -2,14 +2,30 @@ #include #include +#include #include "zathura.h" gboolean cb_destroy(GtkWidget* widget, gpointer data) { - if(Zathura.UI.session) + if(Zathura.UI.session) { girara_session_destroy(Zathura.UI.session); + } return TRUE; } + +void +buffer_changed(girara_session_t* session) +{ + g_return_if_fail(session != NULL); + g_return_if_fail(Zathura.UI.buffer != NULL); + + char* buffer = girara_buffer_get(session); + + if(buffer) { + girara_statusbar_item_set_text(session, Zathura.UI.buffer, buffer); + free(buffer); + } +} diff --git a/callbacks.h b/callbacks.h index bc544f1..254d7e8 100644 --- a/callbacks.h +++ b/callbacks.h @@ -4,7 +4,9 @@ #define CALLBACKS_H #include +#include gboolean cb_destroy(GtkWidget* widget, gpointer data); +void buffer_changed(girara_session_t* session); #endif // CALLBACKS_H diff --git a/config.c b/config.c index 7f81bc9..c8ce721 100644 --- a/config.c +++ b/config.c @@ -9,12 +9,15 @@ config_load_default() if(!Zathura.UI.session) return; + /* general settings */ + girara_mode_set(Zathura.UI.session, NORMAL); + /* define default shortcuts */ - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, ALL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, ALL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, ALL, DELETE_LAST, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, 0, DELETE_LAST, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); diff --git a/shortcuts.c b/shortcuts.c index b47db30..658595c 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -5,10 +5,15 @@ #include "callbacks.h" #include "shortcuts.h" +#include "zathura.h" bool sc_abort(girara_session_t* session, girara_argument_t* argument) { + g_return_val_if_fail(session != NULL, false); + + girara_mode_set(session, NORMAL); + return false; } @@ -27,12 +32,28 @@ sc_change_buffer(girara_session_t* session, girara_argument_t* argument) bool sc_change_mode(girara_session_t* session, girara_argument_t* argument) { + g_return_val_if_fail(session != NULL, false); + + girara_mode_set(session, argument->n); + return false; } bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) { + g_return_val_if_fail(session != NULL, false); + + if(!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) + gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); + + if(argument->data) + { + gtk_entry_set_text(session->gtk.inputbar, (char*) argument->data); + gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar)); + gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar), -1); + } + return false; } diff --git a/zathura.c b/zathura.c index d8656e7..25dbeb7 100644 --- a/zathura.c +++ b/zathura.c @@ -15,9 +15,19 @@ init_zathura() if(!girara_session_init(Zathura.UI.session)) return false; + /* UI */ + Zathura.UI.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); + if(!Zathura.UI.buffer) { + girara_session_destroy(Zathura.UI.session); + return false; + } + /* signals */ g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); + /* girara events */ + Zathura.UI.session->events.buffer_changed = buffer_changed; + /* configuration */ config_load_default(); diff --git a/zathura.h b/zathura.h index 1a824fc..d74a202 100644 --- a/zathura.h +++ b/zathura.h @@ -26,6 +26,7 @@ struct struct { girara_session_t* session; /**> girara interface session */ + girara_statusbar_item_t* buffer; /**> buffer statusbar entry */ } UI; } Zathura; From 6d5ac53aa32ceca0f6623784e0e6bc592cecb649 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 17 Nov 2010 22:51:15 +0100 Subject: [PATCH 007/197] Document structure --- Makefile | 6 +-- ft/document.c | 77 ++++++++++++++++++++++++++++++++++++++ ft/document.h | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ shortcuts.c | 6 +-- zathura.c | 6 ++- 5 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 ft/document.c diff --git a/Makefile b/Makefile index 3b988ed..408d01d 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ include config.mk PROJECT = zathura -SOURCE = callbacks.c commands.c config.c shortcuts.c utils.c zathura.c -OBJECTS = ${SOURCE:.c=.o} -DOBJECTS = ${SOURCE:.c=.do} +SOURCE = $(shell find . -iname "*.c" -a ! -iwholename "*./doc*") +OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) +DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) all: options ${PROJECT} diff --git a/ft/document.c b/ft/document.c new file mode 100644 index 0000000..41522bb --- /dev/null +++ b/ft/document.c @@ -0,0 +1,77 @@ +/* See LICENSE file for license and copyright information */ + +#include + +#include "document.h" + +zathura_page_t* +zathura_page_get(zathura_document_t* document, unsigned int page) +{ + return NULL; +} + +zathura_list_t* +zathura_page_search_text(zathura_page_t* page, const char* text) +{ + return NULL; +} + +zathura_list_t* +zathura_page_links_get(zathura_page_t* page) +{ + return NULL; +} + +bool +zathura_page_links_free(zathura_list_t* list) +{ + return false; +} + +zathura_list_t* +zathura_page_form_fields_get(zathura_page_t* page) +{ + return NULL; +} + +bool +zathura_page_form_fields_free(zathura_list_t* list) +{ + return false; +} + +cairo_surface_t* +zathura_page_render(zathura_page_t* page) +{ + return NULL; +} + +zathura_list_t* +zathura_document_index_generate(zathura_document_t* document) +{ + return NULL; +} + +bool +zathura_document_index_free(zathura_list_t* list) +{ + return false; +} + +bool +zathura_document_save_as(zathura_document_t* document, const char* path) +{ + return false; +} + +zathura_list_t* +zathura_document_attachments_get(zathura_document_t* document) +{ + return NULL; +} + +bool +zathura_document_attachments_free(zathura_list_t* list) +{ + return false; +} diff --git a/ft/document.h b/ft/document.h index e69de29..3acdff9 100644 --- a/ft/document.h +++ b/ft/document.h @@ -0,0 +1,100 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef DOCUMENT_H +#define DOCUMENT_H + +#include +#include + +typedef struct zathura_list_s zathura_list_t; +typedef struct zathura_document_s zathura_document_t; + +struct zathura_list_s +{ + void* data; + struct zathura_list_s* next; +}; + +typedef struct zathura_rectangle_s +{ + double x1; + double y1; + double x2; + double y2; +} zathura_rectangle_t; + +typedef enum zathura_link_type_e +{ + ZATHURA_LINK_TO_PAGE, + ZATHURA_LINK_EXTERNAL, +} zathura_link_type_t; + +typedef struct zathura_link_s +{ + zathura_rectangle_t position; + zathura_link_type_t type; + union + { + unsigned int page_number; + char* value; + } target; +} zathura_link_t; + +typedef enum zathura_form_type_e +{ + ZATHURA_FORM_CHECKBOX, + ZATHURA_FORM_TEXTFIELD +} zathura_form_type_t; + +typedef struct zathura_form_s +{ + zathura_rectangle_t position; + zathura_form_type_t type; +} zathura_form_t; + +typedef struct zathura_page_s +{ + unsigned int height; + unsigned int width; + zathura_document_t* document; + void* data; +} zathura_page_t; + +struct zathura_document_s +{ + char* file_path; + char* password; + unsigned int current_page_number; + unsigned int number_of_pages; + int scale; + int rotate; + + struct + { + zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page); + zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); + zathura_list_t* (*page_links_get)(zathura_page_t* page); + zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); + cairo_surface_t* (*page_render)(zathura_page_t* page); + + zathura_list_t* (*document_index_generate)(zathura_document_t* document); + bool (*document_save_as)(zathura_document_t* document, const char* path); + zathura_list_t* (*document_attachments_get)(zathura_document_t* document); + } functions; +}; + +zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page); +zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text); +zathura_list_t* zathura_page_links_get(zathura_page_t* page); +bool zathura_page_links_free(zathura_list_t* list); +zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page); +bool zathura_page_form_fields_free(zathura_list_t* list); +cairo_surface_t* zathura_page_render(zathura_page_t* page); + +zathura_list_t* zathura_document_index_generate(zathura_document_t* document); +bool zathura_document_index_free(zathura_list_t* list); +bool zathura_document_save_as(zathura_document_t* document, const char* path); +zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); +bool zathura_document_attachments_free(zathura_list_t* list); + +#endif // DOCUMENT_H diff --git a/shortcuts.c b/shortcuts.c index 658595c..28cf0bf 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -44,11 +44,11 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) { g_return_val_if_fail(session != NULL, false); - if(!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) + if(!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); + } - if(argument->data) - { + if(argument->data) { gtk_entry_set_text(session->gtk.inputbar, (char*) argument->data); gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar)); gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar), -1); diff --git a/zathura.c b/zathura.c index 25dbeb7..586edb6 100644 --- a/zathura.c +++ b/zathura.c @@ -9,11 +9,13 @@ bool init_zathura() { - if(!(Zathura.UI.session = girara_session_create())) + if(!(Zathura.UI.session = girara_session_create())) { return false; + } - if(!girara_session_init(Zathura.UI.session)) + if(!girara_session_init(Zathura.UI.session)) { return false; + } /* UI */ Zathura.UI.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); From f1438f5f858388deae5da53fc6317ab26b42ba16 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 17 Nov 2010 23:15:08 +0100 Subject: [PATCH 008/197] Update document definition --- ft/document.c | 160 +++++++++++++++++++++++++++++++++++++++----------- ft/document.h | 15 +++-- 2 files changed, 136 insertions(+), 39 deletions(-) diff --git a/ft/document.c b/ft/document.c index 41522bb..c9a899c 100644 --- a/ft/document.c +++ b/ft/document.c @@ -1,25 +1,131 @@ /* See LICENSE file for license and copyright information */ #include +#include #include "document.h" +zathura_document_t* +zathura_document_create(const char* path) +{ + return NULL; +} + +bool +zathura_document_free(zathura_document_t* document) +{ + if(!document) { + return NULL; + } + + if(!document->functions.document_free(document)) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return NULL; + } + + return document->functions.document_free(document); +} + +bool +zathura_document_save_as(zathura_document_t* document, const char* path) +{ + if(!document || !path) { + return false; + } + + if(!document->functions.document_save_as) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return false; + } + + return document->functions.document_save_as(document, path); +} + +zathura_list_t* +zathura_document_index_generate(zathura_document_t* document) +{ + if(!document) { + return NULL; + } + + if(!document->functions.document_index_generate) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return NULL; + } + + return document->functions.document_index_generate(document); +} + +bool +zathura_document_index_free(zathura_list_t* list) +{ + return false; +} + +zathura_list_t* +zathura_document_attachments_get(zathura_document_t* document) +{ + if(!document) { + return NULL; + } + + if(!document->functions.document_attachments_get) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return NULL; + } + + return document->functions.document_attachments_get(document); +} + +bool +zathura_document_attachments_free(zathura_list_t* list) +{ + return false; +} + zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page) { - return NULL; + if(!document) { + return NULL; + } + + if(!document->functions.page_get) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return NULL; + } + + return document->functions.page_get(document, page); } zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text) { - return NULL; + if(!page || !page->document || !text) { + return NULL; + } + + if(!page->document->functions.page_search_text) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return NULL; + } + + return page->document->functions.page_search_text(page, text); } zathura_list_t* zathura_page_links_get(zathura_page_t* page) { - return NULL; + if(!page || !page->document) { + return NULL; + } + + if(!page->document->functions.page_links_get) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return NULL; + } + + return page->document->functions.page_links_get(page); } bool @@ -31,7 +137,16 @@ zathura_page_links_free(zathura_list_t* list) zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page) { - return NULL; + if(!page || !page->document) { + return NULL; + } + + if(!page->document->functions.page_form_fields_get) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return NULL; + } + + return page->document->functions.page_form_fields_get(page); } bool @@ -43,35 +158,14 @@ zathura_page_form_fields_free(zathura_list_t* list) cairo_surface_t* zathura_page_render(zathura_page_t* page) { - return NULL; -} + if(!page || !page->document) { + return NULL; + } -zathura_list_t* -zathura_document_index_generate(zathura_document_t* document) -{ - return NULL; -} + if(!page->document->functions.page_render) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return NULL; + } -bool -zathura_document_index_free(zathura_list_t* list) -{ - return false; -} - -bool -zathura_document_save_as(zathura_document_t* document, const char* path) -{ - return false; -} - -zathura_list_t* -zathura_document_attachments_get(zathura_document_t* document) -{ - return NULL; -} - -bool -zathura_document_attachments_free(zathura_list_t* list) -{ - return false; + return page->document->functions.page_render(page); } diff --git a/ft/document.h b/ft/document.h index 3acdff9..ada8507 100644 --- a/ft/document.h +++ b/ft/document.h @@ -80,9 +80,18 @@ struct zathura_document_s zathura_list_t* (*document_index_generate)(zathura_document_t* document); bool (*document_save_as)(zathura_document_t* document, const char* path); zathura_list_t* (*document_attachments_get)(zathura_document_t* document); + bool (*document_free)(zathura_document_t* document); } functions; }; +zathura_document_t* zathura_document_create(const char* path); +bool zathura_document_free(zathura_document_t* document); +bool zathura_document_save_as(zathura_document_t* document, const char* path); +zathura_list_t* zathura_document_index_generate(zathura_document_t* document); +bool zathura_document_index_free(zathura_list_t* list); +zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); +bool zathura_document_attachments_free(zathura_list_t* list); + zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* zathura_page_links_get(zathura_page_t* page); @@ -91,10 +100,4 @@ zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page); bool zathura_page_form_fields_free(zathura_list_t* list); cairo_surface_t* zathura_page_render(zathura_page_t* page); -zathura_list_t* zathura_document_index_generate(zathura_document_t* document); -bool zathura_document_index_free(zathura_list_t* list); -bool zathura_document_save_as(zathura_document_t* document, const char* path); -zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); -bool zathura_document_attachments_free(zathura_list_t* list); - #endif // DOCUMENT_H From 4857d62fdea0736970db0400c0268dc767ed85ae Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 18 Nov 2010 02:35:33 +0100 Subject: [PATCH 009/197] Init document, some changes --- ft/document.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++-- ft/document.h | 26 +++++++++++------ ft/pdf/pdf.c | 9 ++++++ ft/pdf/pdf.h | 7 +++++ utils.c | 22 +++++++++++++++ utils.h | 5 ++++ zathura.c | 21 ++++++++++---- 7 files changed, 151 insertions(+), 17 deletions(-) diff --git a/ft/document.c b/ft/document.c index c9a899c..7f6b62f 100644 --- a/ft/document.c +++ b/ft/document.c @@ -4,10 +4,63 @@ #include #include "document.h" +#include "../utils.h" +#include "pdf/pdf.h" + +#define LENGTH(x) (sizeof(x)/sizeof((x)[0])) + +zathura_document_plugin_t zathura_document_plugins[] = { + { "pdf", pdf_document_open }, +}; zathura_document_t* -zathura_document_create(const char* path) +zathura_document_open(const char* path, const char* password) { + if(!path) { + return NULL; + } + + if(!file_exists(path)) { + fprintf(stderr, "error: file does not exist\n"); + return NULL; + } + + const char* file_extension = file_get_extension(path); + if(!file_extension) { + fprintf(stderr, "error: could not determine file type\n"); + return NULL; + } + + zathura_document_t* document = malloc(sizeof(zathura_document_t)); + if(!document) { + return NULL; + } + + + document->file_path = path; + document->password = password; + document->current_page_number = 0; + document->number_of_pages = 0; + document->scale = 100; + document->rotate = 0; + + document->functions.document_free = NULL; + document->functions.document_index_generate = NULL; + document->functions.document_save_as = NULL; + document->functions.document_attachments_get = NULL; + document->functions.page_get = NULL; + document->functions.page_free = NULL; + document->functions.page_search_text = NULL; + document->functions.page_links_get = NULL; + document->functions.page_form_fields_get = NULL; + document->functions.page_render = NULL; + + /* init plugin with associated file type */ + for(unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++) + { + + } + return NULL; } @@ -23,7 +76,11 @@ zathura_document_free(zathura_document_t* document) return NULL; } - return document->functions.document_free(document); + bool r = document->functions.document_free(document); + + free(document); + + return r; } bool @@ -86,7 +143,7 @@ zathura_document_attachments_free(zathura_list_t* list) zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page) { - if(!document) { + if(!document || !page) { return NULL; } @@ -98,6 +155,21 @@ zathura_page_get(zathura_document_t* document, unsigned int page) return document->functions.page_get(document, page); } +bool +zathura_page_free(zathura_page_t* page) +{ + if(!page || !page->document) { + return false; + } + + if(!page->document->functions.page_free) { + fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + return false; + } + + return page->document->functions.page_free(page); +} + zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text) { diff --git a/ft/document.h b/ft/document.h index ada8507..28b18d9 100644 --- a/ft/document.h +++ b/ft/document.h @@ -9,6 +9,14 @@ typedef struct zathura_list_s zathura_list_t; typedef struct zathura_document_s zathura_document_t; +typedef bool (*zathura_document_open_t)(zathura_document_t* document); + +typedef struct zathura_document_plugin_s +{ + const char* file_type; + zathura_document_open_t open_function; +} zathura_document_plugin_t; + struct zathura_list_s { void* data; @@ -62,8 +70,8 @@ typedef struct zathura_page_s struct zathura_document_s { - char* file_path; - char* password; + const char* file_path; + const char* password; unsigned int current_page_number; unsigned int number_of_pages; int scale; @@ -71,20 +79,21 @@ struct zathura_document_s struct { + bool (*document_free)(zathura_document_t* document); + zathura_list_t* (*document_index_generate)(zathura_document_t* document); + bool (*document_save_as)(zathura_document_t* document, const char* path); + zathura_list_t* (*document_attachments_get)(zathura_document_t* document); + zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page); zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); zathura_list_t* (*page_links_get)(zathura_page_t* page); zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); cairo_surface_t* (*page_render)(zathura_page_t* page); - - zathura_list_t* (*document_index_generate)(zathura_document_t* document); - bool (*document_save_as)(zathura_document_t* document, const char* path); - zathura_list_t* (*document_attachments_get)(zathura_document_t* document); - bool (*document_free)(zathura_document_t* document); + bool (*page_free)(zathura_page_t* page); } functions; }; -zathura_document_t* zathura_document_create(const char* path); +zathura_document_t* zathura_document_open(const char* path, const char* password); bool zathura_document_free(zathura_document_t* document); bool zathura_document_save_as(zathura_document_t* document, const char* path); zathura_list_t* zathura_document_index_generate(zathura_document_t* document); @@ -93,6 +102,7 @@ zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); bool zathura_document_attachments_free(zathura_list_t* list); zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page); +bool zathura_page_free(zathura_page_t* page); zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* zathura_page_links_get(zathura_page_t* page); bool zathura_page_links_free(zathura_list_t* list); diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index e69de29..83bc422 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -0,0 +1,9 @@ +/* See LICENSE file for license and copyright information */ + +#include "pdf.h" + +bool +pdf_document_open(zathura_document_t* document) +{ + return true; +} diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h index e69de29..e207dd2 100644 --- a/ft/pdf/pdf.h +++ b/ft/pdf/pdf.h @@ -0,0 +1,7 @@ +/* See LICENSE file for license and copyright information */ + +#include + +#include "../document.h" + +bool pdf_document_open(zathura_document_t* document); diff --git a/utils.c b/utils.c index e69de29..47d1690 100644 --- a/utils.c +++ b/utils.c @@ -0,0 +1,22 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include + +#include "utils.h" + +bool +file_exists(const char* path) +{ + if(!access(path, F_OK)) { + return true; + } else { + return false; + } +} + +const char* +file_get_extension(const char* path) +{ + return NULL; +} diff --git a/utils.h b/utils.h index 931b644..bacc9b8 100644 --- a/utils.h +++ b/utils.h @@ -3,4 +3,9 @@ #ifndef UTILS_H #define UTILS_H +#include + +bool file_exists(const char* path); +const char* file_get_extension(const char* path); + #endif // UTILS_H diff --git a/zathura.c b/zathura.c index 586edb6..59bd0ed 100644 --- a/zathura.c +++ b/zathura.c @@ -2,6 +2,7 @@ #include "callbacks.h" #include "config.h" +#include "ft/document.h" #include "shortcuts.h" #include "zathura.h" @@ -43,14 +44,22 @@ int main(int argc, char* argv[]) gdk_threads_init(); gtk_init(&argc, &argv); - if(!init_zathura()) { - printf("error: coult not initialize zathura\n"); - return -1; + /*if(!init_zathura()) {*/ + /*printf("error: coult not initialize zathura\n");*/ + /*return -1;*/ + /*}*/ + + if(argc > 1) { + zathura_document_t* document = zathura_document_open(argv[1], NULL); + if(!document) { + return -1; + } + zathura_document_free(document); } - gdk_threads_enter(); - gtk_main(); - gdk_threads_leave(); + /*gdk_threads_enter();*/ + /*gtk_main();*/ + /*gdk_threads_leave();*/ return 0; } From cd7fda37cfa5a25d23196391a1d42836fb1c1c2d Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 18 Nov 2010 03:15:32 +0100 Subject: [PATCH 010/197] PDF function definitions --- ft/document.c | 19 ++++++++++--- ft/document.h | 3 +- ft/pdf/pdf.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ ft/pdf/pdf.h | 15 ++++++++++ utils.c | 20 +++++++++++++- 5 files changed, 127 insertions(+), 6 deletions(-) diff --git a/ft/document.c b/ft/document.c index 7f6b62f..387be7c 100644 --- a/ft/document.c +++ b/ft/document.c @@ -2,6 +2,7 @@ #include #include +#include #include "document.h" #include "../utils.h" @@ -43,6 +44,7 @@ zathura_document_open(const char* path, const char* password) document->number_of_pages = 0; document->scale = 100; document->rotate = 0; + document->data = NULL; document->functions.document_free = NULL; document->functions.document_index_generate = NULL; @@ -58,9 +60,17 @@ zathura_document_open(const char* path, const char* password) /* init plugin with associated file type */ for(unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++) { - + if(!strcmp(file_extension, zathura_document_plugins[i].file_extension)) { + if(zathura_document_plugins[i].open_function) { + if(zathura_document_plugins[i].open_function(document)) { + return document; + } + } + } } + fprintf(stderr, "error: unknown file type\n"); + return NULL; } @@ -68,12 +78,13 @@ bool zathura_document_free(zathura_document_t* document) { if(!document) { - return NULL; + return false; } - if(!document->functions.document_free(document)) { + if(!document->functions.document_free) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); - return NULL; + free(document); + return true; } bool r = document->functions.document_free(document); diff --git a/ft/document.h b/ft/document.h index 28b18d9..9976639 100644 --- a/ft/document.h +++ b/ft/document.h @@ -13,7 +13,7 @@ typedef bool (*zathura_document_open_t)(zathura_document_t* document); typedef struct zathura_document_plugin_s { - const char* file_type; + const char* file_extension; zathura_document_open_t open_function; } zathura_document_plugin_t; @@ -76,6 +76,7 @@ struct zathura_document_s unsigned int number_of_pages; int scale; int rotate; + void* data; struct { diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 83bc422..35b0995 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -1,9 +1,85 @@ /* See LICENSE file for license and copyright information */ +#include + #include "pdf.h" bool pdf_document_open(zathura_document_t* document) { + if(!document) + return false; + + document->functions.document_free = pdf_document_free; + document->functions.document_index_generate = pdf_document_index_generate;; + document->functions.document_save_as = pdf_document_save_as; + document->functions.document_attachments_get = pdf_document_attachments_get; + document->functions.page_get = pdf_page_get; + document->functions.page_search_text = pdf_page_search_text; + document->functions.page_links_get = pdf_page_links_get; + document->functions.page_form_fields_get = pdf_page_form_fields_get; + document->functions.page_render = pdf_page_render; + document->functions.page_free = pdf_page_free; + return true; } + +bool +pdf_document_free(zathura_document_t* document) +{ + return false; +} + +zathura_list_t* +pdf_document_index_generate(zathura_document_t* document) +{ + return NULL; +} + +bool +pdf_document_save_as(zathura_document_t* document, const char* path) +{ + return false; +} + +zathura_list_t* +pdf_document_attachments_get(zathura_document_t* document) +{ + return NULL; +} + +zathura_page_t* +pdf_page_get(zathura_document_t* document, unsigned int page) +{ + return NULL; +} + +zathura_list_t* +pdf_page_search_text(zathura_page_t* page, const char* text) +{ + return NULL; +} + +zathura_list_t* +pdf_page_links_get(zathura_page_t* page) +{ + return NULL; +} + +zathura_list_t* +pdf_page_form_fields_get(zathura_page_t* page) +{ + return NULL; +} + +cairo_surface_t* +pdf_page_render(zathura_page_t* page) +{ + return NULL; +} + +bool +pdf_page_free(zathura_page_t* page) +{ + return false; +} diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h index e207dd2..1d7563d 100644 --- a/ft/pdf/pdf.h +++ b/ft/pdf/pdf.h @@ -1,7 +1,22 @@ /* See LICENSE file for license and copyright information */ +#ifndef PDF_H +#define PDF_H + #include #include "../document.h" bool pdf_document_open(zathura_document_t* document); +bool pdf_document_free(zathura_document_t* document); +zathura_list_t* pdf_document_index_generate(zathura_document_t* document); +bool pdf_document_save_as(zathura_document_t* document, const char* path); +zathura_list_t* pdf_document_attachments_get(zathura_document_t* document); +zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); +zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); +zathura_list_t* pdf_page_links_get(zathura_page_t* page); +zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); +cairo_surface_t* pdf_page_render(zathura_page_t* page); +bool pdf_page_free(zathura_page_t* page); + +#endif // PDF_H diff --git a/utils.c b/utils.c index 47d1690..9938900 100644 --- a/utils.c +++ b/utils.c @@ -1,6 +1,7 @@ /* See LICENSE file for license and copyright information */ #include +#include #include #include "utils.h" @@ -18,5 +19,22 @@ file_exists(const char* path) const char* file_get_extension(const char* path) { - return NULL; + if(!path) { + return NULL; + } + + unsigned int i = strlen(path); + for(; i > 0; i--) + { + if(*(path + i) != '.') + continue; + else + break; + } + + if(!i) { + return NULL; + } + + return path + i + 1; } From f5fabb01ba27fa223252926a4c3a4ec018da71ad Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 18 Nov 2010 13:54:35 +0100 Subject: [PATCH 011/197] Determine realpath of path --- ft/document.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- ft/document.h | 2 +- ft/pdf/pdf.c | 36 +++++++++++++++++++++++++++++++++++- ft/pdf/pdf.h | 6 ++++++ 4 files changed, 87 insertions(+), 5 deletions(-) diff --git a/ft/document.c b/ft/document.c index 387be7c..925791a 100644 --- a/ft/document.c +++ b/ft/document.c @@ -1,8 +1,13 @@ /* See LICENSE file for license and copyright information */ +#define _BSD_SOURCE +#define _XOPEN_SOURCE 500 +// TODO: Implement realpath + #include #include #include +#include #include "document.h" #include "../utils.h" @@ -32,13 +37,33 @@ zathura_document_open(const char* path, const char* password) return NULL; } - zathura_document_t* document = malloc(sizeof(zathura_document_t)); - if(!document) { + /* determine real path */ + size_t path_max; +#ifdef PATH_MAX + path_max = PATH_MAX; +#else + path_max = pathconf(path,_PC_PATH_MAX); + if(path_max <= 0) + path_max = 4096; +#endif + + char* real_path = malloc(sizeof(char) * path_max); + if(!real_path) { return NULL; } + if(!realpath(path, real_path)) { + free(real_path); + return NULL; + } - document->file_path = path; + zathura_document_t* document = malloc(sizeof(zathura_document_t)); + if(!document) { + free(real_path); + return NULL; + } + + document->file_path = real_path; document->password = password; document->current_page_number = 0; document->number_of_pages = 0; @@ -64,6 +89,11 @@ zathura_document_open(const char* path, const char* password) if(zathura_document_plugins[i].open_function) { if(zathura_document_plugins[i].open_function(document)) { return document; + } else { + fprintf(stderr, "error: could not open file\n"); + free(real_path); + free(document); + return NULL; } } } @@ -71,6 +101,9 @@ zathura_document_open(const char* path, const char* password) fprintf(stderr, "error: unknown file type\n"); + free(real_path); + free(document); + return NULL; } @@ -83,12 +116,21 @@ zathura_document_free(zathura_document_t* document) if(!document->functions.document_free) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + + if(document->file_path) { + free(document->file_path); + } + free(document); return true; } bool r = document->functions.document_free(document); + if(document->file_path) { + free(document->file_path); + } + free(document); return r; diff --git a/ft/document.h b/ft/document.h index 9976639..5defeb5 100644 --- a/ft/document.h +++ b/ft/document.h @@ -70,7 +70,7 @@ typedef struct zathura_page_s struct zathura_document_s { - const char* file_path; + char* file_path; const char* password; unsigned int current_page_number; unsigned int number_of_pages; diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 35b0995..130db05 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -21,13 +21,47 @@ pdf_document_open(zathura_document_t* document) document->functions.page_render = pdf_page_render; document->functions.page_free = pdf_page_free; + document->data = malloc(sizeof(pdf_document_t)); + if(!document->data) { + return false; + } + + /* format path */ + GError* error = NULL; + char* file_uri = g_filename_to_uri(document->file_path, NULL, &error); + + if(!file_uri) { + fprintf(stderr, "error: could not open file: %s\n", error->message); + g_error_free(error); + free(document->data); + return false; + } + + pdf_document_t* pdf_document = (pdf_document_t*) document->data; + pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error); + + if(!pdf_document->document) { + fprintf(stderr, "error: could not open file: %s\n", error->message); + g_error_free(error); + free(document->data); + return false; + } + return true; } bool pdf_document_free(zathura_document_t* document) { - return false; + if(!document) { + return false; + } + + if(document->data) { + free(document->data); + } + + return true; } zathura_list_t* diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h index 1d7563d..971bedc 100644 --- a/ft/pdf/pdf.h +++ b/ft/pdf/pdf.h @@ -4,9 +4,15 @@ #define PDF_H #include +#include #include "../document.h" +typedef struct pdf_document_s +{ + PopplerDocument *document; +} pdf_document_t; + bool pdf_document_open(zathura_document_t* document); bool pdf_document_free(zathura_document_t* document); zathura_list_t* pdf_document_index_generate(zathura_document_t* document); From 43727a597b4846215eb696394b15e712c7cfd8ac Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 18 Nov 2010 14:51:13 +0100 Subject: [PATCH 012/197] Get and free pdf page --- ft/document.c | 2 +- ft/document.h | 4 ++-- ft/pdf/pdf.c | 58 ++++++++++++++++++++++++++++++++++++++++++++------- zathura.c | 24 ++++++++++++++------- 4 files changed, 70 insertions(+), 18 deletions(-) diff --git a/ft/document.c b/ft/document.c index 925791a..2395f84 100644 --- a/ft/document.c +++ b/ft/document.c @@ -196,7 +196,7 @@ zathura_document_attachments_free(zathura_list_t* list) zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page) { - if(!document || !page) { + if(!document) { return NULL; } diff --git a/ft/document.h b/ft/document.h index 5defeb5..8b5c2fb 100644 --- a/ft/document.h +++ b/ft/document.h @@ -62,8 +62,8 @@ typedef struct zathura_form_s typedef struct zathura_page_s { - unsigned int height; - unsigned int width; + double height; + double width; zathura_document_t* document; void* data; } zathura_page_t; diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 130db05..e201092 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -38,7 +38,7 @@ pdf_document_open(zathura_document_t* document) } pdf_document_t* pdf_document = (pdf_document_t*) document->data; - pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error); + pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error); if(!pdf_document->document) { fprintf(stderr, "error: could not open file: %s\n", error->message); @@ -47,6 +47,8 @@ pdf_document_open(zathura_document_t* document) return false; } + document->number_of_pages = poppler_document_get_n_pages(pdf_document->document); + return true; } @@ -58,6 +60,8 @@ pdf_document_free(zathura_document_t* document) } if(document->data) { + pdf_document_t* pdf_document = (pdf_document_t*) document->data; + g_object_unref(pdf_document->document); free(document->data); } @@ -73,6 +77,16 @@ pdf_document_index_generate(zathura_document_t* document) bool pdf_document_save_as(zathura_document_t* document, const char* path) { + if(!document || !document->data || !path) { + return false; + } + + pdf_document_t* pdf_document = (pdf_document_t*) document->data; + + char* file_path = g_strdup_printf("file://%s", path); + poppler_document_save(pdf_document->document, file_path, NULL); + g_free(file_path); + return false; } @@ -85,7 +99,41 @@ pdf_document_attachments_get(zathura_document_t* document) zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page) { - return NULL; + if(!document || !document->data) { + return NULL; + } + + pdf_document_t* pdf_document = (pdf_document_t*) document->data; + zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); + + if(!document_page) { + return NULL; + } + + document_page->document = document; + document_page->data = poppler_document_get_page(pdf_document->document, page); + + if(!document_page->data) { + free(document_page); + return NULL; + } + + poppler_page_get_size(document_page->data, &(document_page->width), &(document_page->height)); + + return document_page; +} + +bool +pdf_page_free(zathura_page_t* page) +{ + if(!page) { + return false; + } + + g_object_unref(page->data); + free(page); + + return true; } zathura_list_t* @@ -111,9 +159,3 @@ pdf_page_render(zathura_page_t* page) { return NULL; } - -bool -pdf_page_free(zathura_page_t* page) -{ - return false; -} diff --git a/zathura.c b/zathura.c index 59bd0ed..ce3f9cc 100644 --- a/zathura.c +++ b/zathura.c @@ -44,22 +44,32 @@ int main(int argc, char* argv[]) gdk_threads_init(); gtk_init(&argc, &argv); - /*if(!init_zathura()) {*/ - /*printf("error: coult not initialize zathura\n");*/ - /*return -1;*/ - /*}*/ + if(!init_zathura()) { + printf("error: coult not initialize zathura\n"); + return -1; + } if(argc > 1) { zathura_document_t* document = zathura_document_open(argv[1], NULL); + if(!document) { return -1; } + + zathura_page_t* page = zathura_page_get(document, 0); + + if(!page) { + zathura_document_free(document); + return -2; + } + + zathura_page_free(page); zathura_document_free(document); } - /*gdk_threads_enter();*/ - /*gtk_main();*/ - /*gdk_threads_leave();*/ + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); return 0; } From ff2b588ea57cdca2c3a3bfbf73600b1c72a6e26c Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 18 Nov 2010 21:22:43 +0100 Subject: [PATCH 013/197] Statusbar entries --- callbacks.c | 4 ++-- ft/document.c | 2 ++ zathura.c | 18 ++++++++++++++++-- zathura.h | 8 +++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/callbacks.c b/callbacks.c index 80506e4..2f9bf63 100644 --- a/callbacks.c +++ b/callbacks.c @@ -20,12 +20,12 @@ void buffer_changed(girara_session_t* session) { g_return_if_fail(session != NULL); - g_return_if_fail(Zathura.UI.buffer != NULL); + g_return_if_fail(Zathura.UI.statusbar.buffer != NULL); char* buffer = girara_buffer_get(session); if(buffer) { - girara_statusbar_item_set_text(session, Zathura.UI.buffer, buffer); + girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer); free(buffer); } } diff --git a/ft/document.c b/ft/document.c index 2395f84..f4e354d 100644 --- a/ft/document.c +++ b/ft/document.c @@ -11,6 +11,7 @@ #include "document.h" #include "../utils.h" +#include "../zathura.h" #include "pdf/pdf.h" #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) @@ -88,6 +89,7 @@ zathura_document_open(const char* path, const char* password) if(!strcmp(file_extension, zathura_document_plugins[i].file_extension)) { if(zathura_document_plugins[i].open_function) { if(zathura_document_plugins[i].open_function(document)) { + girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, real_path); return document; } else { fprintf(stderr, "error: could not open file\n"); diff --git a/zathura.c b/zathura.c index ce3f9cc..d89c74e 100644 --- a/zathura.c +++ b/zathura.c @@ -19,12 +19,26 @@ init_zathura() } /* UI */ - Zathura.UI.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); - if(!Zathura.UI.buffer) { + Zathura.UI.statusbar.file = girara_statusbar_item_add(Zathura.UI.session, TRUE, TRUE, TRUE, NULL); + if(!Zathura.UI.statusbar.file) { girara_session_destroy(Zathura.UI.session); return false; } + Zathura.UI.statusbar.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); + if(!Zathura.UI.statusbar.buffer) { + girara_session_destroy(Zathura.UI.session); + return false; + } + + Zathura.UI.statusbar.page_number = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); + if(!Zathura.UI.statusbar.page_number) { + girara_session_destroy(Zathura.UI.session); + return false; + } + + girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, "[No Name]"); + /* signals */ g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); diff --git a/zathura.h b/zathura.h index d74a202..ba8d3ec 100644 --- a/zathura.h +++ b/zathura.h @@ -26,7 +26,13 @@ struct struct { girara_session_t* session; /**> girara interface session */ - girara_statusbar_item_t* buffer; /**> buffer statusbar entry */ + + struct + { + girara_statusbar_item_t* buffer; /**> buffer statusbar entry */ + girara_statusbar_item_t* file; /**> file statusbar entry */ + girara_statusbar_item_t* page_number; /**> page number statusbar entry */ + } statusbar; } UI; } Zathura; From 2cfe3f86b8a83d1852a398489ff9ae2a6fb876b5 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 29 Nov 2010 14:58:56 +0100 Subject: [PATCH 014/197] Complete printer list and execute command --- callbacks.c | 4 ++- completion.c | 65 +++++++++++++++++++++++++++++++++++++++++ completion.h | 4 +++ config.c | 11 +++++++ utils.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ utils.h | 1 + 6 files changed, 166 insertions(+), 1 deletion(-) diff --git a/callbacks.c b/callbacks.c index 2f9bf63..8c299a6 100644 --- a/callbacks.c +++ b/callbacks.c @@ -20,7 +20,6 @@ void buffer_changed(girara_session_t* session) { g_return_if_fail(session != NULL); - g_return_if_fail(Zathura.UI.statusbar.buffer != NULL); char* buffer = girara_buffer_get(session); @@ -28,4 +27,7 @@ buffer_changed(girara_session_t* session) girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer); free(buffer); } + else { + girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, ""); + } } diff --git a/completion.c b/completion.c index 6c3efe1..6bfa583 100644 --- a/completion.c +++ b/completion.c @@ -1 +1,66 @@ /* See LICENSE file for license and copyright information */ + +#include +#include +#include + +#include "completion.h" +#include "utils.h" + +girara_completion_t* +cc_print(girara_session_t* session, char* input) +{ + girara_completion_t* completion = girara_completion_init(); + girara_completion_group_t* group = girara_completion_group_create(session, NULL); + + if(!session || !input || !completion || !group) + return NULL; + + girara_completion_add_group(completion, group); + + char* const list_printers[] = { + "lpstat", "-v", NULL + }; + + char* output; + if(!execute_command(list_printers, &output)) { + girara_completion_free(completion); + return false; + } + + /* parse single lines */ + unsigned int prefix_length = strlen("device for "); + char* p = strtok(output, "\n"); + char* q; + + while(p) + { + if(!(p = strstr(p, "device for ")) || !(q = strchr(p, ':'))) { + p = strtok(NULL, "\n"); + continue; + } + + unsigned int printer_length = q - p - prefix_length; + char* printer_name = malloc(sizeof(char) * printer_length); + + if(!printer_name) { + p = strtok(NULL, "\n"); + continue; + } + + strncpy(printer_name, p + prefix_length, printer_length - 1); + printer_name[printer_length - 1] = '\0'; + + /* add printer */ + girara_completion_group_add_element(group, printer_name, NULL); + + free(printer_name); + + /* next line */ + p = strtok(NULL, "\n"); + } + + free(output); + + return completion; +} diff --git a/completion.h b/completion.h index ea9c0a2..81800e9 100644 --- a/completion.h +++ b/completion.h @@ -3,4 +3,8 @@ #ifndef COMPLETION_H #define COMPLETION_H +#include + +girara_completion_t* cc_print(girara_session_t* session, char* input); + #endif // COMPLETION_H diff --git a/config.c b/config.c index c8ce721..f44025b 100644 --- a/config.c +++ b/config.c @@ -1,5 +1,7 @@ /* See LICENSE file for license and copyright information */ +#include "commands.h" +#include "completion.h" #include "shortcuts.h" #include "zathura.h" @@ -75,4 +77,13 @@ config_load_default() girara_shortcut_add(Zathura.UI.session, 0, 0, "zI", sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); girara_shortcut_add(Zathura.UI.session, 0, 0, "zO", sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); girara_shortcut_add(Zathura.UI.session, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); + + /* define default inputbar commands */ + girara_inputbar_command_add(Zathura.UI.session, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark"); + girara_inputbar_command_add(Zathura.UI.session, "bdelete", NULL, cmd_bookmark_delete, NULL, "Delete a bookmark"); + girara_inputbar_command_add(Zathura.UI.session, "blist", NULL, cmd_bookmark_open, NULL, "List all bookmarks"); + girara_inputbar_command_add(Zathura.UI.session, "close", NULL, cmd_close, NULL, "Close current file"); + girara_inputbar_command_add(Zathura.UI.session, "info", NULL, cmd_info, NULL, "Show file information"); + girara_inputbar_command_add(Zathura.UI.session, "print", NULL, cmd_print, cc_print, "Print document"); + girara_inputbar_command_add(Zathura.UI.session, "save", NULL, cmd_save, NULL, "Save document"); } diff --git a/utils.c b/utils.c index 9938900..5737152 100644 --- a/utils.c +++ b/utils.c @@ -2,10 +2,15 @@ #include #include +#include #include +#include +#include #include "utils.h" +#define BLOCK_SIZE 64 + bool file_exists(const char* path) { @@ -38,3 +43,80 @@ file_get_extension(const char* path) return path + i + 1; } + +bool +execute_command(char* const argv[], char** output) +{ + if(!output) { + return false; + } + + int p[2]; + if(pipe(p)) + return -1; + + pid_t pid = fork(); + + if(pid == -1) { // failure + return false; + } + else if(pid == 0) { // child + dup2(p[1], 1); + close(p[0]); + + if(execvp(argv[0], argv) == -1) { + return false; + } + } + else { // parent + dup2(p[0], 0); + close(p[1]); + + /* read output */ + unsigned int bc = BLOCK_SIZE; + unsigned int i = 0; + char* buffer = malloc(sizeof(char) * bc); + *output = NULL; + + if(!buffer) { + close(p[0]); + return false; + } + + char c; + while(1 == read(p[0], &c, 1)) { + buffer[i++] = c; + + if(i == bc) { + bc += BLOCK_SIZE; + char* tmp = realloc(buffer, sizeof(char) * bc); + + if(!tmp) { + free(buffer); + close(p[0]); + return false; + } + + buffer = tmp; + } + } + + char* tmp = realloc(buffer, sizeof(char) * (bc + 1)); + if(!tmp) { + free(buffer); + close(p[0]); + return false; + } + + buffer = tmp; + buffer[i] = '\0'; + + *output = buffer; + + /* wait for child to terminate */ + waitpid(pid, NULL, 0); + close(p[0]); + } + + return true; +} diff --git a/utils.h b/utils.h index bacc9b8..c10ea26 100644 --- a/utils.h +++ b/utils.h @@ -7,5 +7,6 @@ bool file_exists(const char* path); const char* file_get_extension(const char* path); +bool execute_command(char* const argv[], char** output); #endif // UTILS_H From 3d027dd7738286497a3d2d12beccb6271a92d42d Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 12 Dec 2010 22:04:42 +0100 Subject: [PATCH 015/197] Set page --- shortcuts.c | 16 +++++++++++++ zathura.c | 69 +++++++++++++++++++++++++++++++++++++++++++---------- zathura.h | 30 ++++++++++++++++++++++- 3 files changed, 101 insertions(+), 14 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index 28cf0bf..ac1429f 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -72,6 +72,22 @@ sc_goto(girara_session_t* session, girara_argument_t* argument) bool sc_navigate(girara_session_t* session, girara_argument_t* argument) { + if(!session || !argument || !Zathura.document) { + return false; + } + + unsigned int number_of_pages = Zathura.document->number_of_pages; + unsigned int new_page = Zathura.document->current_page_number; + + if(argument->n == NEXT) { + new_page = (new_page + 1) % number_of_pages; + } + else if(argument->n == PREVIOUS) { + new_page = (new_page + number_of_pages - 1) % number_of_pages; + } + + page_set(new_page); + return false; } diff --git a/zathura.c b/zathura.c index d89c74e..dd456c4 100644 --- a/zathura.c +++ b/zathura.c @@ -51,6 +51,60 @@ init_zathura() return true; } +bool +document_open(const char* path, const char* password) +{ + if(!path) { + return false; + } + + zathura_document_t* document = zathura_document_open(path, password); + + if(!document) { + return false; + } + + Zathura.document = document; + + if(!page_set(0)) { + return false; + } + + return true; +} + +bool +document_close() +{ + if(!Zathura.document) { + return false; + } + + zathura_document_free(Zathura.document); + + return true; +} + +bool +page_set(unsigned int page_id) +{ + if(!Zathura.document) { + return false; + } + + if(page_id >= Zathura.document->number_of_pages) { + return false; + } + + Zathura.document->current_page_number = page_id; + + char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, Zathura.document->number_of_pages); + girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.page_number, page_number); + g_free(page_number); + + return true; +} + /* main function */ int main(int argc, char* argv[]) { @@ -64,21 +118,10 @@ int main(int argc, char* argv[]) } if(argc > 1) { - zathura_document_t* document = zathura_document_open(argv[1], NULL); - - if(!document) { + if(!document_open(argv[1], NULL)) { + printf("error: could not open document\n"); return -1; } - - zathura_page_t* page = zathura_page_get(document, 0); - - if(!page) { - zathura_document_free(document); - return -2; - } - - zathura_page_free(page); - zathura_document_free(document); } gdk_threads_enter(); diff --git a/zathura.h b/zathura.h index ba8d3ec..132b3b2 100644 --- a/zathura.h +++ b/zathura.h @@ -6,6 +6,8 @@ #include #include +#include "ft/document.h" + 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, @@ -23,7 +25,7 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, struct { - struct + struct { girara_session_t* session; /**> girara interface session */ @@ -34,6 +36,8 @@ struct girara_statusbar_item_t* page_number; /**> page number statusbar entry */ } statusbar; } UI; + + zathura_document_t* document; /**> The current document */ } Zathura; /** @@ -44,4 +48,28 @@ struct bool init_zathura(); +/** + * Opens a file + * + * @param path The path to the file + * @param password The password of the file + * + * @return If no error occured true, otherwise false, is returned. + */ +bool document_open(const char* path, const char* password); + +/** + * Closes the current opened document + * + * @return If no error occured true, otherwise false, is returned. + */ +bool document_close(); + +/** + * Opens the page with the given number + * + * @return If no error occured true, otherwise false, is returned. + */ +bool page_set(unsigned int page_id); + #endif // ZATHURA_H From f8aa8773f3091867593449005a6c8751e077972c Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 23 Dec 2010 19:41:07 +0100 Subject: [PATCH 016/197] Began to add djvu support --- config.mk | 4 +- ft/djvu/djvu.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ ft/djvu/djvu.h | 29 +++++++++++ ft/document.c | 6 ++- ft/pdf/pdf.c | 3 ++ zathura.c | 1 + 6 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 ft/djvu/djvu.c create mode 100644 ft/djvu/djvu.h diff --git a/config.mk b/config.mk index c9a7738..fbb9fd4 100644 --- a/config.mk +++ b/config.mk @@ -8,8 +8,8 @@ PREFIX ?= /usr MANPREFIX ?= ${PREFIX}/share/man # libs -GTK_INC = $(shell pkg-config --cflags gtk+-2.0 poppler-glib) -GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0 poppler-glib) +GTK_INC = $(shell pkg-config --cflags gtk+-2.0 poppler-glib ddjvuapi) +GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0 poppler-glib ddjvuapi) INCS = -I. -I/usr/include ${GTK_INC} LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c new file mode 100644 index 0000000..19a53b5 --- /dev/null +++ b/ft/djvu/djvu.c @@ -0,0 +1,127 @@ +/* See LICENSE file for license and copyright information */ + +#include + +#include "djvu.h" + +bool +djvu_document_open(zathura_document_t* document) +{ + if(!document) { + return false; + } + + document->functions.document_free = djvu_document_free; + document->functions.document_index_generate = djvu_document_index_generate;; + document->functions.document_save_as = djvu_document_save_as; + document->functions.document_attachments_get = djvu_document_attachments_get; + document->functions.page_get = djvu_page_get; + document->functions.page_search_text = djvu_page_search_text; + document->functions.page_links_get = djvu_page_links_get; + document->functions.page_form_fields_get = djvu_page_form_fields_get; + document->functions.page_render = djvu_page_render; + document->functions.page_free = djvu_page_free; + + document->data = malloc(sizeof(djvu_document_t)); + if(!document->data) { + return false; + } + + djvu_document_t* djvu_document = (djvu_document_t*) document->data; + djvu_document->context = ddjvu_context_create("zathura"); + + if(!djvu_document->context) { + free(document->data); + document->data = NULL; + return false; + } + + djvu_document->document = ddjvu_document_create_by_filename(djvu_document->context, document->file_path, FALSE); + + if(!djvu_document->document) { + ddjvu_context_release(djvu_document->context); + free(document->data); + document->data = NULL; + return false; + } + + document->number_of_pages = ddjvu_document_get_pagenum(djvu_document->document); + + return true; +} + +bool +djvu_document_free(zathura_document_t* document) +{ + if(!document) { + return false; + } + + return true; +} + +zathura_list_t* +djvu_document_index_generate(zathura_document_t* document) +{ + return NULL; +} + +bool +djvu_document_save_as(zathura_document_t* document, const char* path) +{ + if(!document || !document->data || !path) { + return false; + } + + return false; +} + +zathura_list_t* +djvu_document_attachments_get(zathura_document_t* document) +{ + return NULL; +} + +zathura_page_t* +djvu_page_get(zathura_document_t* document, unsigned int page) +{ + if(!document || !document->data) { + return NULL; + } + + return NULL; +} + +bool +djvu_page_free(zathura_page_t* page) +{ + if(!page) { + return false; + } + + return true; +} + +zathura_list_t* +djvu_page_search_text(zathura_page_t* page, const char* text) +{ + return NULL; +} + +zathura_list_t* +djvu_page_links_get(zathura_page_t* page) +{ + return NULL; +} + +zathura_list_t* +djvu_page_form_fields_get(zathura_page_t* page) +{ + return NULL; +} + +cairo_surface_t* +djvu_page_render(zathura_page_t* page) +{ + return NULL; +} diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h new file mode 100644 index 0000000..92f94c8 --- /dev/null +++ b/ft/djvu/djvu.h @@ -0,0 +1,29 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef DJVU_H +#define DJVU_H + +#include +#include + +#include "../document.h" + +typedef struct djvu_document_s +{ + ddjvu_context_t* context; + ddjvu_document_t* document; +} djvu_document_t; + +bool djvu_document_open(zathura_document_t* document); +bool djvu_document_free(zathura_document_t* document); +zathura_list_t* djvu_document_index_generate(zathura_document_t* document); +bool djvu_document_save_as(zathura_document_t* document, const char* path); +zathura_list_t* djvu_document_attachments_get(zathura_document_t* document); +zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page); +zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text); +zathura_list_t* djvu_page_links_get(zathura_page_t* page); +zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page); +cairo_surface_t* djvu_page_render(zathura_page_t* page); +bool djvu_page_free(zathura_page_t* page); + +#endif // DJVU_H diff --git a/ft/document.c b/ft/document.c index f4e354d..69180b8 100644 --- a/ft/document.c +++ b/ft/document.c @@ -10,14 +10,16 @@ #include #include "document.h" +#include "pdf/pdf.h" +#include "djvu/djvu.h" #include "../utils.h" #include "../zathura.h" -#include "pdf/pdf.h" #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) zathura_document_plugin_t zathura_document_plugins[] = { - { "pdf", pdf_document_open }, + { "pdf", pdf_document_open }, + { "djvu", djvu_document_open }, }; zathura_document_t* diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index e201092..2928dae 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -34,6 +34,7 @@ pdf_document_open(zathura_document_t* document) fprintf(stderr, "error: could not open file: %s\n", error->message); g_error_free(error); free(document->data); + document->data = NULL; return false; } @@ -44,6 +45,7 @@ pdf_document_open(zathura_document_t* document) fprintf(stderr, "error: could not open file: %s\n", error->message); g_error_free(error); free(document->data); + document->data = NULL; return false; } @@ -63,6 +65,7 @@ pdf_document_free(zathura_document_t* document) pdf_document_t* pdf_document = (pdf_document_t*) document->data; g_object_unref(pdf_document->document); free(document->data); + document->data = NULL; } return true; diff --git a/zathura.c b/zathura.c index dd456c4..d1a747b 100644 --- a/zathura.c +++ b/zathura.c @@ -67,6 +67,7 @@ document_open(const char* path, const char* password) Zathura.document = document; if(!page_set(0)) { + zathura_document_free(document); return false; } From 876f1e9eadd27d58e65415b87f4cfc1cd72c8c76 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 23 Dec 2010 19:45:06 +0100 Subject: [PATCH 017/197] Implemented djvu_document_free --- ft/djvu/djvu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 19a53b5..d323cde 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -57,6 +57,13 @@ djvu_document_free(zathura_document_t* document) return false; } + if(document->data) { + djvu_document_t* djvu_document = (djvu_document_t*) document->data; + ddjvu_context_release(djvu_document->context); + ddjvu_document_release(djvu_document->document); + free(document->data); + } + return true; } From 7c6b0819845b1ae4db34981a3fa5fb53b36431c8 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 23 Dec 2010 20:26:36 +0100 Subject: [PATCH 018/197] Revised pdf/djvu open functions --- ft/djvu/djvu.c | 62 ++++++++++++++++++++++++++++++++++++++++---------- ft/djvu/djvu.h | 1 + ft/pdf/pdf.c | 34 ++++++++++++++++++--------- 3 files changed, 74 insertions(+), 23 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index d323cde..de965ba 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -8,7 +8,7 @@ bool djvu_document_open(zathura_document_t* document) { if(!document) { - return false; + goto error_out; } document->functions.document_free = djvu_document_free; @@ -24,30 +24,57 @@ djvu_document_open(zathura_document_t* document) document->data = malloc(sizeof(djvu_document_t)); if(!document->data) { - return false; + goto error_out; } djvu_document_t* djvu_document = (djvu_document_t*) document->data; - djvu_document->context = ddjvu_context_create("zathura"); + djvu_document->context = NULL; + djvu_document->document = NULL; + djvu_document->format = NULL; - if(!djvu_document->context) { - free(document->data); - document->data = NULL; - return false; + /* setup format */ + djvu_document->format = ddjvu_format_create (DDJVU_FORMAT_RGBMASK32, 0, NULL); + + if(!djvu_document->format) { + goto error_free; } + ddjvu_format_set_row_order(djvu_document->format, TRUE); + + /* setup context */ + djvu_document->context = ddjvu_context_create("zathura"); + + if(!djvu_document->context) { + goto error_free; + } + + /* setup document */ djvu_document->document = ddjvu_document_create_by_filename(djvu_document->context, document->file_path, FALSE); if(!djvu_document->document) { - ddjvu_context_release(djvu_document->context); - free(document->data); - document->data = NULL; - return false; + goto error_free; } document->number_of_pages = ddjvu_document_get_pagenum(djvu_document->document); return true; + +error_free: + + if(djvu_document->format) { + ddjvu_format_release(djvu_document->format); + } + + if(djvu_document->context) { + ddjvu_context_release(djvu_document->context); + } + + free(document->data); + document->data = NULL; + +error_out: + + return false; } bool @@ -61,6 +88,7 @@ djvu_document_free(zathura_document_t* document) djvu_document_t* djvu_document = (djvu_document_t*) document->data; ddjvu_context_release(djvu_document->context); ddjvu_document_release(djvu_document->document); + ddjvu_format_release(djvu_document->format); free(document->data); } @@ -80,7 +108,17 @@ djvu_document_save_as(zathura_document_t* document, const char* path) return false; } - return false; + djvu_document_t* djvu_document = (djvu_document_t*) document->data; + + FILE* fp = fopen(path, "w"); + if(!fp) { + return false; + } + + ddjvu_document_save(djvu_document->document, fp, 0, NULL); + fclose(fp); + + return true; } zathura_list_t* diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h index 92f94c8..6ece4a6 100644 --- a/ft/djvu/djvu.h +++ b/ft/djvu/djvu.h @@ -12,6 +12,7 @@ typedef struct djvu_document_s { ddjvu_context_t* context; ddjvu_document_t* document; + ddjvu_format_t* format; } djvu_document_t; bool djvu_document_open(zathura_document_t* document); diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 2928dae..d43ffb9 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -7,8 +7,9 @@ bool pdf_document_open(zathura_document_t* document) { - if(!document) - return false; + if(!document) { + goto error_out; + } document->functions.document_free = pdf_document_free; document->functions.document_index_generate = pdf_document_index_generate;; @@ -23,7 +24,7 @@ pdf_document_open(zathura_document_t* document) document->data = malloc(sizeof(pdf_document_t)); if(!document->data) { - return false; + goto error_out; } /* format path */ @@ -32,10 +33,7 @@ pdf_document_open(zathura_document_t* document) if(!file_uri) { fprintf(stderr, "error: could not open file: %s\n", error->message); - g_error_free(error); - free(document->data); - document->data = NULL; - return false; + goto error_free; } pdf_document_t* pdf_document = (pdf_document_t*) document->data; @@ -43,15 +41,29 @@ pdf_document_open(zathura_document_t* document) if(!pdf_document->document) { fprintf(stderr, "error: could not open file: %s\n", error->message); - g_error_free(error); - free(document->data); - document->data = NULL; - return false; + goto error_free; } document->number_of_pages = poppler_document_get_n_pages(pdf_document->document); return true; + +error_free: + + if(error) { + g_error_free(error); + } + + if(file_uri) { + g_free(file_uri); + } + + free(document->data); + document->data = NULL; + +error_out: + + return false; } bool From 7d73b15e852f96e1be53b9eace564e6ed00960b1 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 24 Dec 2010 16:21:54 +0100 Subject: [PATCH 019/197] document_index_generate should return tree-like data structures --- ft/djvu/djvu.c | 2 +- ft/djvu/djvu.h | 2 +- ft/document.c | 2 +- ft/document.h | 6 ++++-- ft/pdf/pdf.c | 2 +- ft/pdf/pdf.h | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index de965ba..c66cc5d 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -95,7 +95,7 @@ djvu_document_free(zathura_document_t* document) return true; } -zathura_list_t* +girara_tree_node_t* djvu_document_index_generate(zathura_document_t* document) { return NULL; diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h index 6ece4a6..bc3b4a9 100644 --- a/ft/djvu/djvu.h +++ b/ft/djvu/djvu.h @@ -17,7 +17,7 @@ typedef struct djvu_document_s bool djvu_document_open(zathura_document_t* document); bool djvu_document_free(zathura_document_t* document); -zathura_list_t* djvu_document_index_generate(zathura_document_t* document); +girara_tree_node_t* djvu_document_index_generate(zathura_document_t* document); bool djvu_document_save_as(zathura_document_t* document, const char* path); zathura_list_t* djvu_document_attachments_get(zathura_document_t* document); zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page); diff --git a/ft/document.c b/ft/document.c index 69180b8..e049486 100644 --- a/ft/document.c +++ b/ft/document.c @@ -155,7 +155,7 @@ zathura_document_save_as(zathura_document_t* document, const char* path) return document->functions.document_save_as(document, path); } -zathura_list_t* +girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document) { if(!document) { diff --git a/ft/document.h b/ft/document.h index 8b5c2fb..c322f0d 100644 --- a/ft/document.h +++ b/ft/document.h @@ -6,6 +6,8 @@ #include #include +#include + typedef struct zathura_list_s zathura_list_t; typedef struct zathura_document_s zathura_document_t; @@ -81,7 +83,7 @@ struct zathura_document_s struct { bool (*document_free)(zathura_document_t* document); - zathura_list_t* (*document_index_generate)(zathura_document_t* document); + girara_tree_node_t* (*document_index_generate)(zathura_document_t* document); bool (*document_save_as)(zathura_document_t* document, const char* path); zathura_list_t* (*document_attachments_get)(zathura_document_t* document); @@ -97,7 +99,7 @@ struct zathura_document_s zathura_document_t* zathura_document_open(const char* path, const char* password); bool zathura_document_free(zathura_document_t* document); bool zathura_document_save_as(zathura_document_t* document, const char* path); -zathura_list_t* zathura_document_index_generate(zathura_document_t* document); +girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document); bool zathura_document_index_free(zathura_list_t* list); zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); bool zathura_document_attachments_free(zathura_list_t* list); diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index d43ffb9..688d59b 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -83,7 +83,7 @@ pdf_document_free(zathura_document_t* document) return true; } -zathura_list_t* +girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document) { return NULL; diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h index 971bedc..1506880 100644 --- a/ft/pdf/pdf.h +++ b/ft/pdf/pdf.h @@ -15,7 +15,7 @@ typedef struct pdf_document_s bool pdf_document_open(zathura_document_t* document); bool pdf_document_free(zathura_document_t* document); -zathura_list_t* pdf_document_index_generate(zathura_document_t* document); +girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document); bool pdf_document_save_as(zathura_document_t* document, const char* path); zathura_list_t* pdf_document_attachments_get(zathura_document_t* document); zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); From 1b0d1da6b49faed60c644253f445cf9cb53841ba Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 25 Dec 2010 00:47:52 +0100 Subject: [PATCH 020/197] create index of PDF documents --- ft/document.c | 25 +++++++++++++++++++ ft/document.h | 14 +++++++++++ ft/pdf/pdf.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/ft/document.c b/ft/document.c index e049486..a0dacad 100644 --- a/ft/document.c +++ b/ft/document.c @@ -298,3 +298,28 @@ zathura_page_render(zathura_page_t* page) return page->document->functions.page_render(page); } + +zathura_index_element_t* +zathura_index_element_new(const char* title) +{ + if (!title) + return NULL; + + zathura_index_element_t* res = g_malloc0(sizeof(zathura_index_element_t)); + if (!res) + return NULL; + res->title = g_strdup(title); + return res; +} + +void +zathura_index_element_free(zathura_index_element_t* index) +{ + if (!index) + return; + + g_free(index->title); + if (index->type == ZATHURA_LINK_EXTERNAL) + g_free(index->target.uri); + g_free(index); +} diff --git a/ft/document.h b/ft/document.h index c322f0d..f193837 100644 --- a/ft/document.h +++ b/ft/document.h @@ -50,6 +50,17 @@ typedef struct zathura_link_s } target; } zathura_link_t; +typedef struct zathura_index_element_s +{ + char* title; + zathura_link_type_t type; + union + { + unsigned int page_number; + char* uri; + } target; +} zathura_index_element_t; + typedef enum zathura_form_type_e { ZATHURA_FORM_CHECKBOX, @@ -113,4 +124,7 @@ zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page); bool zathura_page_form_fields_free(zathura_list_t* list); cairo_surface_t* zathura_page_render(zathura_page_t* page); +zathura_index_element_t* zathura_index_element_new(const char* title); +void zathura_index_element_free(zathura_index_element_t* index); + #endif // DOCUMENT_H diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 688d59b..a2d6454 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -83,10 +83,76 @@ pdf_document_free(zathura_document_t* document) return true; } +static void +build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* iter) +{ + if (!root || !iter) + return; + + do + { + PopplerAction* action = poppler_index_iter_get_action(iter); + if (!action) + continue; + + gchar* markup = g_markup_escape_text(action->any.title, -1); + zathura_index_element_t* indexelement = zathura_index_element_new(markup); + if (action->type == POPPLER_ACTION_URI) + { + indexelement->type = ZATHURA_LINK_EXTERNAL; + indexelement->target.uri = g_strdup(action->uri.uri); + } + else if (action->type == POPPLER_ACTION_GOTO_DEST) + { + indexelement->type = ZATHURA_LINK_TO_PAGE; + if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) + { + PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest); + if (dest) + { + indexelement->target.page_number = dest->page_num - 1; + poppler_dest_free(dest); + } + } + else + indexelement->target.page_number = action->goto_dest.dest->page_num - 1; + } + else + { + poppler_action_free(action); + zathura_index_element_free(indexelement); + continue; + } + poppler_action_free(action); + + girara_tree_node_t* node = girara_node_append_data(root, indexelement); + PopplerIndexIter* child = poppler_index_iter_get_child(iter); + if (child) + build_index(pdf, node, child); + poppler_index_iter_free(child); + } while (poppler_index_iter_next(iter)); +} + girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document) { - return NULL; + if (!document || !document->data) { + return NULL; + } + + pdf_document_t* pdf_document = (pdf_document_t*) document->data; + PopplerIndexIter* iter = poppler_index_iter_new(pdf_document->document); + if (!iter) { + // XXX: error message? + return NULL; + } + + girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); + girara_node_set_free_function(root, (girara_free_function_t)zathura_index_element_free); + build_index(pdf_document, root, iter); + + poppler_index_iter_free(iter); + return root; } bool From 1814caff30d80fa5dd2e75dc7a005051d325fc4a Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 25 Dec 2010 18:41:20 +0100 Subject: [PATCH 021/197] ignore debug object files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e3120a6..720cd3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +*.do *~ *.rej *.swp From ecef579ce07d76ff6e0bee99bf8461e7674a8f68 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 00:28:53 +0100 Subject: [PATCH 022/197] Get/Free djvu page --- ft/djvu/djvu.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index c66cc5d..b6c3a61 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -33,7 +33,7 @@ djvu_document_open(zathura_document_t* document) djvu_document->format = NULL; /* setup format */ - djvu_document->format = ddjvu_format_create (DDJVU_FORMAT_RGBMASK32, 0, NULL); + djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGB24, 0, NULL); if(!djvu_document->format) { goto error_free; @@ -134,7 +134,25 @@ djvu_page_get(zathura_document_t* document, unsigned int page) return NULL; } - return NULL; + djvu_document_t* djvu_document = (djvu_document_t*) document->data; + zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); + + if(!document_page) { + return NULL; + } + + document_page->document = document; + document_page->data = ddjvu_page_create_by_pageno(djvu_document->document, page);; + + if(!document_page->data) { + free(document_page); + return NULL; + } + + document_page->width = ddjvu_page_get_width(document_page->data); + document_page->height = ddjvu_page_get_width(document_page->data); + + return document_page; } bool @@ -144,6 +162,9 @@ djvu_page_free(zathura_page_t* page) return false; } + ddjvu_page_release(page->data); + free(page); + return true; } From c0cfa407ca2b27aa69b2fe37be490152f862ee44 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 00:47:42 +0100 Subject: [PATCH 023/197] Began with ddjvu render method --- ft/djvu/djvu.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index b6c3a61..9f45e5e 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -1,8 +1,10 @@ /* See LICENSE file for license and copyright information */ #include +#include #include "djvu.h" +#include "../../zathura.h" bool djvu_document_open(zathura_document_t* document) @@ -189,5 +191,52 @@ djvu_page_form_fields_get(zathura_page_t* page) cairo_surface_t* djvu_page_render(zathura_page_t* page) { - return NULL; + if(Zathura.document || !page || !page->data || !page->document) { + return NULL; + } + + /* calculate sizes */ + unsigned int page_width = page->width; + unsigned int page_height = page->height; + + /* init ddjvu render data */ + ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; + ddjvu_rect_t prect = { 0, 0, page_width, page_height }; + + ddjvu_page_rotation_t rotation = DDJVU_ROTATE_0; + + switch(Zathura.document->rotate) { + case 90: + rotation = DDJVU_ROTATE_90; + break; + case 180: + rotation = DDJVU_ROTATE_180; + break; + case 270: + rotation = DDJVU_ROTATE_270; + break; + } + + djvu_document_t* djvu_document = (djvu_document_t*) page->document->data; + + /* create cairo data */ + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, + page->width, page->height); + + if(!surface) { + return NULL; + } + + int rowsize = cairo_image_surface_get_stride(surface); + char* data = (char*) cairo_image_surface_get_data(surface); + + /* render */ + ddjvu_page_set_rotation(page->data, rotation); + + ddjvu_page_render(page->data, DDJVU_RENDER_COLOR, &prect, &rrect, + djvu_document->format, rowsize, data); + + cairo_surface_mark_dirty(surface); + + return surface; } From 7627c56d30c3b70497f164823e834b72a4269fcf Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 00:54:07 +0100 Subject: [PATCH 024/197] Update width/height on rotation --- ft/djvu/djvu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 9f45e5e..b1b5df6 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -205,14 +205,24 @@ djvu_page_render(zathura_page_t* page) ddjvu_page_rotation_t rotation = DDJVU_ROTATE_0; + unsigned int dim_temp = 0; + switch(Zathura.document->rotate) { case 90: + tmp = page_width; + page_width = page_height; + page_height = page_tmp; + rotation = DDJVU_ROTATE_90; break; case 180: rotation = DDJVU_ROTATE_180; break; case 270: + tmp = page_width; + page_width = page_height; + page_height = page_tmp; + rotation = DDJVU_ROTATE_270; break; } From abc7deadd3ef9cdb6b163811f93b75dc02948184 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 01:03:04 +0100 Subject: [PATCH 025/197] Update djvu/pdf render functions --- ft/djvu/djvu.c | 12 ++++++------ ft/pdf/pdf.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index b1b5df6..8c8e2ad 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -196,8 +196,8 @@ djvu_page_render(zathura_page_t* page) } /* calculate sizes */ - unsigned int page_width = page->width; - unsigned int page_height = page->height; + unsigned int page_width = Zathura.document->scale * page->width; + unsigned int page_height = Zathura.document->scale * page->height; /* init ddjvu render data */ ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; @@ -209,9 +209,9 @@ djvu_page_render(zathura_page_t* page) switch(Zathura.document->rotate) { case 90: - tmp = page_width; + dim_temp = page_width; page_width = page_height; - page_height = page_tmp; + page_height = dim_temp; rotation = DDJVU_ROTATE_90; break; @@ -219,9 +219,9 @@ djvu_page_render(zathura_page_t* page) rotation = DDJVU_ROTATE_180; break; case 270: - tmp = page_width; + dim_temp = page_width; page_width = page_height; - page_height = page_tmp; + page_height = dim_temp; rotation = DDJVU_ROTATE_270; break; diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index a2d6454..0673015 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -1,8 +1,11 @@ /* See LICENSE file for license and copyright information */ #include +#include +#include #include "pdf.h" +#include "../../zathura.h" bool pdf_document_open(zathura_document_t* document) @@ -238,5 +241,48 @@ pdf_page_form_fields_get(zathura_page_t* page) cairo_surface_t* pdf_page_render(zathura_page_t* page) { - return NULL; + if(Zathura.document || !page || !page->data || !page->document) { + return NULL; + } + + /* create cairo data */ + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, + page->width, page->height); + + if(!surface) { + return NULL; + } + + cairo_t* cairo = cairo_create(surface); + + if(!cairo) { + cairo_surface_destroy(surface); + return NULL; + } + + switch(Zathura.document->rotate) { + case 90: + cairo_translate(cairo, page->width, 0); + break; + case 180: + cairo_translate(cairo, page->width, page->height); + break; + case 270: + cairo_translate(cairo, 0, page->height); + break; + default: + cairo_translate(cairo, 0, 0); + break; + } + + cairo_scale(cairo, Zathura.document->scale, Zathura.document->scale); + cairo_rotate(cairo, Zathura.document->rotate * G_PI / 180.0); + + /* render */ + poppler_page_render(page->data, cairo); + + cairo_paint(cairo); + cairo_destroy(cairo); + + return surface; } From 890d6b3299a65c28fe9236223a2286c5909b55d3 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 01:12:20 +0100 Subject: [PATCH 026/197] Update coding standard --- callbacks.c | 3 +-- ft/document.c | 17 +++++++++++++---- ft/pdf/pdf.c | 46 +++++++++++++++++++++++++--------------------- shortcuts.c | 3 +-- utils.c | 14 +++++++------- 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/callbacks.c b/callbacks.c index 8c299a6..07c0f5e 100644 --- a/callbacks.c +++ b/callbacks.c @@ -26,8 +26,7 @@ buffer_changed(girara_session_t* session) if(buffer) { girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer); free(buffer); - } - else { + } else { girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, ""); } } diff --git a/ft/document.c b/ft/document.c index a0dacad..b0b1b91 100644 --- a/ft/document.c +++ b/ft/document.c @@ -302,24 +302,33 @@ zathura_page_render(zathura_page_t* page) zathura_index_element_t* zathura_index_element_new(const char* title) { - if (!title) + if(!title) { return NULL; + } zathura_index_element_t* res = g_malloc0(sizeof(zathura_index_element_t)); - if (!res) + + if(!res) { return NULL; + } + res->title = g_strdup(title); + return res; } void zathura_index_element_free(zathura_index_element_t* index) { - if (!index) + if(!index) { return; + } g_free(index->title); - if (index->type == ZATHURA_LINK_EXTERNAL) + + if(index->type == ZATHURA_LINK_EXTERNAL) { g_free(index->target.uri); + } + g_free(index); } diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 0673015..2c89879 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -89,63 +89,67 @@ pdf_document_free(zathura_document_t* document) static void build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* iter) { - if (!root || !iter) + if(!root || !iter) { return; + } do { PopplerAction* action = poppler_index_iter_get_action(iter); - if (!action) + + if(!action) { continue; + } gchar* markup = g_markup_escape_text(action->any.title, -1); zathura_index_element_t* indexelement = zathura_index_element_new(markup); - if (action->type == POPPLER_ACTION_URI) - { + + if(action->type == POPPLER_ACTION_URI) { indexelement->type = ZATHURA_LINK_EXTERNAL; indexelement->target.uri = g_strdup(action->uri.uri); - } - else if (action->type == POPPLER_ACTION_GOTO_DEST) - { + } else if (action->type == POPPLER_ACTION_GOTO_DEST) { indexelement->type = ZATHURA_LINK_TO_PAGE; - if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) - { + + if(action->goto_dest.dest->type == POPPLER_DEST_NAMED) { PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest); - if (dest) - { + if(dest) { indexelement->target.page_number = dest->page_num - 1; poppler_dest_free(dest); } - } - else + } else { indexelement->target.page_number = action->goto_dest.dest->page_num - 1; - } - else - { + } + } else { poppler_action_free(action); zathura_index_element_free(indexelement); continue; } + poppler_action_free(action); girara_tree_node_t* node = girara_node_append_data(root, indexelement); - PopplerIndexIter* child = poppler_index_iter_get_child(iter); - if (child) + PopplerIndexIter* child = poppler_index_iter_get_child(iter); + + if(child) { build_index(pdf, node, child); + } + poppler_index_iter_free(child); + } while (poppler_index_iter_next(iter)); } girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document) { - if (!document || !document->data) { + if(!document || !document->data) { return NULL; } pdf_document_t* pdf_document = (pdf_document_t*) document->data; - PopplerIndexIter* iter = poppler_index_iter_new(pdf_document->document); - if (!iter) { + PopplerIndexIter* iter = poppler_index_iter_new(pdf_document->document); + + if(!iter) { // XXX: error message? return NULL; } diff --git a/shortcuts.c b/shortcuts.c index ac1429f..db0ef77 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -81,8 +81,7 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument) if(argument->n == NEXT) { new_page = (new_page + 1) % number_of_pages; - } - else if(argument->n == PREVIOUS) { + } else if(argument->n == PREVIOUS) { new_page = (new_page + number_of_pages - 1) % number_of_pages; } diff --git a/utils.c b/utils.c index 5737152..c03a5c9 100644 --- a/utils.c +++ b/utils.c @@ -31,10 +31,11 @@ file_get_extension(const char* path) unsigned int i = strlen(path); for(; i > 0; i--) { - if(*(path + i) != '.') + if(*(path + i) != '.') { continue; - else + } else { break; + } } if(!i) { @@ -52,23 +53,22 @@ execute_command(char* const argv[], char** output) } int p[2]; - if(pipe(p)) + if(pipe(p)) { return -1; + } pid_t pid = fork(); if(pid == -1) { // failure return false; - } - else if(pid == 0) { // child + } else if(pid == 0) { // child dup2(p[1], 1); close(p[0]); if(execvp(argv[0], argv) == -1) { return false; } - } - else { // parent + } else { // parent dup2(p[0], 0); close(p[1]); From ca35db2dc900f129ecce0d0eb6fdb746ba895061 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 01:52:17 +0100 Subject: [PATCH 027/197] Added drawing area --- callbacks.c | 29 ++++++++++++++++++++++++++++ callbacks.h | 1 + ft/djvu/djvu.c | 2 +- ft/pdf/pdf.c | 3 ++- zathura.c | 51 ++++++++++++++++++++++++++++++++++++++++---------- zathura.h | 2 ++ 6 files changed, 76 insertions(+), 12 deletions(-) diff --git a/callbacks.c b/callbacks.c index 07c0f5e..7a3f5dc 100644 --- a/callbacks.c +++ b/callbacks.c @@ -16,6 +16,35 @@ cb_destroy(GtkWidget* widget, gpointer data) return TRUE; } +gboolean +cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data) +{ + // FIXME: Split up + zathura_page_t* page = zathura_page_get(Zathura.document, Zathura.document->current_page_number); + if(!page) { + goto error_out; + } + + cairo_surface_t* surface = zathura_page_render(page); + if(!surface) { + zathura_page_free(page); + fprintf(stderr, "error: rendering failed\n"); + goto error_out; + } + + cairo_surface_destroy(surface); + zathura_page_free(page); + + gtk_widget_set_size_request(Zathura.UI.drawing_area, page->width, page->height); + gtk_widget_queue_draw(Zathura.UI.drawing_area); + + return true; + +error_out: + + return false; +} + void buffer_changed(girara_session_t* session) { diff --git a/callbacks.h b/callbacks.h index 254d7e8..45aa179 100644 --- a/callbacks.h +++ b/callbacks.h @@ -7,6 +7,7 @@ #include gboolean cb_destroy(GtkWidget* widget, gpointer data); +gboolean cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data); void buffer_changed(girara_session_t* session); #endif // CALLBACKS_H diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 8c8e2ad..3100ad3 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -191,7 +191,7 @@ djvu_page_form_fields_get(zathura_page_t* page) cairo_surface_t* djvu_page_render(zathura_page_t* page) { - if(Zathura.document || !page || !page->data || !page->document) { + if(!Zathura.document || !page || !page->data || !page->document) { return NULL; } diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 2c89879..a20f286 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -245,7 +245,8 @@ pdf_page_form_fields_get(zathura_page_t* page) cairo_surface_t* pdf_page_render(zathura_page_t* page) { - if(Zathura.document || !page || !page->data || !page->document) { + if(!Zathura.document || !page || !page->data || !page->document) { + printf("die\n"); return NULL; } diff --git a/zathura.c b/zathura.c index d1a747b..ce4657c 100644 --- a/zathura.c +++ b/zathura.c @@ -11,34 +11,49 @@ bool init_zathura() { if(!(Zathura.UI.session = girara_session_create())) { - return false; + goto error_out; } if(!girara_session_init(Zathura.UI.session)) { - return false; + goto error_out; } + Zathura.UI.statusbar.file = NULL; + Zathura.UI.statusbar.buffer = NULL; + Zathura.UI.statusbar.page_number = NULL; + Zathura.UI.drawing_area = NULL; + /* UI */ Zathura.UI.statusbar.file = girara_statusbar_item_add(Zathura.UI.session, TRUE, TRUE, TRUE, NULL); if(!Zathura.UI.statusbar.file) { - girara_session_destroy(Zathura.UI.session); - return false; + goto error_free; } Zathura.UI.statusbar.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); if(!Zathura.UI.statusbar.buffer) { - girara_session_destroy(Zathura.UI.session); - return false; + goto error_free; } Zathura.UI.statusbar.page_number = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); if(!Zathura.UI.statusbar.page_number) { - girara_session_destroy(Zathura.UI.session); - return false; + goto error_free; } girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, "[No Name]"); + Zathura.UI.drawing_area = gtk_drawing_area_new(); + if(!Zathura.UI.drawing_area) { + goto error_free; + } + + gtk_widget_show(Zathura.UI.drawing_area); + g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL); + + /* set view */ + if(!girara_set_view(Zathura.UI.session, Zathura.UI.drawing_area)) { + goto error_free; + } + /* signals */ g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); @@ -49,6 +64,18 @@ init_zathura() config_load_default(); return true; + +error_free: + + if(Zathura.UI.drawing_area) { + g_object_unref(Zathura.UI.drawing_area); + } + + girara_session_destroy(Zathura.UI.session); + +error_out: + + return false; } bool @@ -90,11 +117,11 @@ bool page_set(unsigned int page_id) { if(!Zathura.document) { - return false; + goto error_out; } if(page_id >= Zathura.document->number_of_pages) { - return false; + goto error_out; } Zathura.document->current_page_number = page_id; @@ -104,6 +131,10 @@ page_set(unsigned int page_id) g_free(page_number); return true; + +error_out: + + return false; } /* main function */ diff --git a/zathura.h b/zathura.h index 132b3b2..cc15c33 100644 --- a/zathura.h +++ b/zathura.h @@ -35,6 +35,8 @@ struct girara_statusbar_item_t* file; /**> file statusbar entry */ girara_statusbar_item_t* page_number; /**> page number statusbar entry */ } statusbar; + + GtkWidget *drawing_area; } UI; zathura_document_t* document; /**> The current document */ From b8aa82b4b1d5c2a881670c5bd99e083ea3bba20b Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 02:22:08 +0100 Subject: [PATCH 028/197] Render (does not work yet) --- callbacks.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/callbacks.c b/callbacks.c index 7a3f5dc..d625798 100644 --- a/callbacks.c +++ b/callbacks.c @@ -19,9 +19,21 @@ cb_destroy(GtkWidget* widget, gpointer data) gboolean cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data) { + if(!widget) { + return false; + } + + gdk_window_clear(widget->window); + cairo_t *cairo = gdk_cairo_create(widget->window); + + if(!cairo) { + return false; + } + // FIXME: Split up zathura_page_t* page = zathura_page_get(Zathura.document, Zathura.document->current_page_number); if(!page) { + cairo_destroy(cairo); goto error_out; } @@ -32,6 +44,10 @@ cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data) goto error_out; } + cairo_set_source_surface(cairo, surface, 0, 0); + cairo_paint(cairo); + cairo_destroy(cairo); + cairo_surface_destroy(surface); zathura_page_free(page); From 726766549e341c692822e16b996e1e67bbbcf127 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 11:10:10 +0100 Subject: [PATCH 029/197] Fix segmentation fault if no file has been opened --- callbacks.c | 2 +- zathura.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/callbacks.c b/callbacks.c index d625798..a76e5ca 100644 --- a/callbacks.c +++ b/callbacks.c @@ -19,7 +19,7 @@ cb_destroy(GtkWidget* widget, gpointer data) gboolean cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data) { - if(!widget) { + if(!widget || !Zathura.document) { return false; } diff --git a/zathura.c b/zathura.c index ce4657c..7bb4dc1 100644 --- a/zathura.c +++ b/zathura.c @@ -10,6 +10,7 @@ bool init_zathura() { + /* UI */ if(!(Zathura.UI.session = girara_session_create())) { goto error_out; } @@ -23,7 +24,7 @@ init_zathura() Zathura.UI.statusbar.page_number = NULL; Zathura.UI.drawing_area = NULL; - /* UI */ + /* statusbar */ Zathura.UI.statusbar.file = girara_statusbar_item_add(Zathura.UI.session, TRUE, TRUE, TRUE, NULL); if(!Zathura.UI.statusbar.file) { goto error_free; @@ -41,13 +42,17 @@ init_zathura() girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, "[No Name]"); + /* drawing area */ Zathura.UI.drawing_area = gtk_drawing_area_new(); if(!Zathura.UI.drawing_area) { goto error_free; } - gtk_widget_show(Zathura.UI.drawing_area); + gtk_widget_modify_bg(Zathura.UI.drawing_area, GTK_STATE_NORMAL, + &(Zathura.UI.session->style.default_background)); + g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL); + gtk_widget_show(Zathura.UI.drawing_area); /* set view */ if(!girara_set_view(Zathura.UI.session, Zathura.UI.drawing_area)) { From a76dd2f4feff93444edf9cc1dcc9fff1195d4cac Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 26 Dec 2010 20:35:26 +0100 Subject: [PATCH 030/197] Render PDF page --- ft/document.c | 2 +- ft/document.h | 2 +- ft/pdf/pdf.c | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ft/document.c b/ft/document.c index b0b1b91..d07e42c 100644 --- a/ft/document.c +++ b/ft/document.c @@ -70,7 +70,7 @@ zathura_document_open(const char* path, const char* password) document->password = password; document->current_page_number = 0; document->number_of_pages = 0; - document->scale = 100; + document->scale = 1.0; document->rotate = 0; document->data = NULL; diff --git a/ft/document.h b/ft/document.h index f193837..a374374 100644 --- a/ft/document.h +++ b/ft/document.h @@ -87,7 +87,7 @@ struct zathura_document_s const char* password; unsigned int current_page_number; unsigned int number_of_pages; - int scale; + double scale; int rotate; void* data; diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index a20f286..63abe0c 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -250,9 +250,20 @@ pdf_page_render(zathura_page_t* page) return NULL; } + /* calculate sizes */ + unsigned int page_width = Zathura.document->scale * page->width; + unsigned int page_height = Zathura.document->scale * page->height; + + if(Zathura.document->rotate == 90 || Zathura.document->rotate == 270) { + unsigned int dim_temp = 0; + dim_temp = page_width; + page_width = page_height; + page_height = dim_temp; + } + /* create cairo data */ cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, - page->width, page->height); + page_width, page_height); if(!surface) { return NULL; @@ -265,6 +276,10 @@ pdf_page_render(zathura_page_t* page) return NULL; } + cairo_set_source_rgb(cairo, 1, 1, 1); + cairo_rectangle(cairo, 0, 0, page_width, page_height); + cairo_fill(cairo); + switch(Zathura.document->rotate) { case 90: cairo_translate(cairo, page->width, 0); @@ -286,7 +301,6 @@ pdf_page_render(zathura_page_t* page) /* render */ poppler_page_render(page->data, cairo); - cairo_paint(cairo); cairo_destroy(cairo); return surface; From 14d744befe904c2aca07c05993b7316d459888e0 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 27 Dec 2010 09:07:17 +0100 Subject: [PATCH 031/197] [testing] Use GdkPixbuf instead of cairo --- callbacks.c | 45 -------------------------- callbacks.h | 1 - ft/djvu/djvu.c | 86 ++++++++++++++++++++++++-------------------------- ft/djvu/djvu.h | 2 +- ft/document.c | 2 +- ft/document.h | 6 ++-- ft/pdf/pdf.c | 49 ++++++++-------------------- ft/pdf/pdf.h | 2 +- zathura.c | 38 ++++++++++++---------- 9 files changed, 82 insertions(+), 149 deletions(-) diff --git a/callbacks.c b/callbacks.c index a76e5ca..07c0f5e 100644 --- a/callbacks.c +++ b/callbacks.c @@ -16,51 +16,6 @@ cb_destroy(GtkWidget* widget, gpointer data) return TRUE; } -gboolean -cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data) -{ - if(!widget || !Zathura.document) { - return false; - } - - gdk_window_clear(widget->window); - cairo_t *cairo = gdk_cairo_create(widget->window); - - if(!cairo) { - return false; - } - - // FIXME: Split up - zathura_page_t* page = zathura_page_get(Zathura.document, Zathura.document->current_page_number); - if(!page) { - cairo_destroy(cairo); - goto error_out; - } - - cairo_surface_t* surface = zathura_page_render(page); - if(!surface) { - zathura_page_free(page); - fprintf(stderr, "error: rendering failed\n"); - goto error_out; - } - - cairo_set_source_surface(cairo, surface, 0, 0); - cairo_paint(cairo); - cairo_destroy(cairo); - - cairo_surface_destroy(surface); - zathura_page_free(page); - - gtk_widget_set_size_request(Zathura.UI.drawing_area, page->width, page->height); - gtk_widget_queue_draw(Zathura.UI.drawing_area); - - return true; - -error_out: - - return false; -} - void buffer_changed(girara_session_t* session) { diff --git a/callbacks.h b/callbacks.h index 45aa179..254d7e8 100644 --- a/callbacks.h +++ b/callbacks.h @@ -7,7 +7,6 @@ #include gboolean cb_destroy(GtkWidget* widget, gpointer data); -gboolean cb_draw(GtkWidget* widget, GdkEventExpose* expose, gpointer data); void buffer_changed(girara_session_t* session); #endif // CALLBACKS_H diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 3100ad3..da8ba9c 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -1,7 +1,6 @@ /* See LICENSE file for license and copyright information */ #include -#include #include "djvu.h" #include "../../zathura.h" @@ -188,7 +187,7 @@ djvu_page_form_fields_get(zathura_page_t* page) return NULL; } -cairo_surface_t* +GtkWidget* djvu_page_render(zathura_page_t* page) { if(!Zathura.document || !page || !page->data || !page->document) { @@ -199,54 +198,51 @@ djvu_page_render(zathura_page_t* page) unsigned int page_width = Zathura.document->scale * page->width; unsigned int page_height = Zathura.document->scale * page->height; - /* init ddjvu render data */ - ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; - ddjvu_rect_t prect = { 0, 0, page_width, page_height }; - - ddjvu_page_rotation_t rotation = DDJVU_ROTATE_0; - - unsigned int dim_temp = 0; - - switch(Zathura.document->rotate) { - case 90: - dim_temp = page_width; - page_width = page_height; - page_height = dim_temp; - - rotation = DDJVU_ROTATE_90; - break; - case 180: - rotation = DDJVU_ROTATE_180; - break; - case 270: - dim_temp = page_width; - page_width = page_height; - page_height = dim_temp; - - rotation = DDJVU_ROTATE_270; - break; - } - - djvu_document_t* djvu_document = (djvu_document_t*) page->document->data; - - /* create cairo data */ - cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, - page->width, page->height); - - if(!surface) { + if(!page_width || !page_height) { return NULL; } - int rowsize = cairo_image_surface_get_stride(surface); - char* data = (char*) cairo_image_surface_get_data(surface); + /* init ddjvu render data */ + djvu_document_t* djvu_document = (djvu_document_t*) page->document->data; - /* render */ - ddjvu_page_set_rotation(page->data, rotation); + ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; + ddjvu_rect_t prect = { 0, 0, page_width, page_height }; - ddjvu_page_render(page->data, DDJVU_RENDER_COLOR, &prect, &rrect, - djvu_document->format, rowsize, data); + guchar* buffer = malloc(sizeof(char) * (page_width * page_height * 3)); + if(!buffer) { + goto error_out; + } - cairo_surface_mark_dirty(surface); + ddjvu_page_set_rotation(page->data, Zathura.document->rotate); - return surface; + /* render page */ + ddjvu_page_render(page->data, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, + 3 * page_width, (char*) buffer); + + /* create pixbuf */ + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8, + page_width, page_height, 3 * page_width, NULL, NULL); + + if(!pixbuf) { + free(buffer); + g_object_unref(pixbuf); + goto error_out; + } + + GtkWidget* image = gtk_image_new(); + + if(!image) { + free(buffer); + g_object_unref(pixbuf); + goto error_out; + } + + gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); + gtk_widget_show(image); + + return image; + +error_out: + + return NULL; } diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h index bc3b4a9..5f6d894 100644 --- a/ft/djvu/djvu.h +++ b/ft/djvu/djvu.h @@ -24,7 +24,7 @@ zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* djvu_page_links_get(zathura_page_t* page); zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page); -cairo_surface_t* djvu_page_render(zathura_page_t* page); +GtkWidget* djvu_page_render(zathura_page_t* page); bool djvu_page_free(zathura_page_t* page); #endif // DJVU_H diff --git a/ft/document.c b/ft/document.c index d07e42c..d202893 100644 --- a/ft/document.c +++ b/ft/document.c @@ -284,7 +284,7 @@ zathura_page_form_fields_free(zathura_list_t* list) return false; } -cairo_surface_t* +GtkWidget* zathura_page_render(zathura_page_t* page) { if(!page || !page->document) { diff --git a/ft/document.h b/ft/document.h index a374374..1442382 100644 --- a/ft/document.h +++ b/ft/document.h @@ -3,7 +3,7 @@ #ifndef DOCUMENT_H #define DOCUMENT_H -#include +#include #include #include @@ -102,7 +102,7 @@ struct zathura_document_s zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); zathura_list_t* (*page_links_get)(zathura_page_t* page); zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); - cairo_surface_t* (*page_render)(zathura_page_t* page); + GtkWidget* (*page_render)(zathura_page_t* page); bool (*page_free)(zathura_page_t* page); } functions; }; @@ -122,7 +122,7 @@ zathura_list_t* zathura_page_links_get(zathura_page_t* page); bool zathura_page_links_free(zathura_list_t* list); zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page); bool zathura_page_form_fields_free(zathura_list_t* list); -cairo_surface_t* zathura_page_render(zathura_page_t* page); +GtkWidget* zathura_page_render(zathura_page_t* page); zathura_index_element_t* zathura_index_element_new(const char* title); void zathura_index_element_free(zathura_index_element_t* index); diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 63abe0c..de003f3 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -1,7 +1,6 @@ /* See LICENSE file for license and copyright information */ #include -#include #include #include "pdf.h" @@ -242,7 +241,7 @@ pdf_page_form_fields_get(zathura_page_t* page) return NULL; } -cairo_surface_t* +GtkWidget* pdf_page_render(zathura_page_t* page) { if(!Zathura.document || !page || !page->data || !page->document) { @@ -261,47 +260,27 @@ pdf_page_render(zathura_page_t* page) page_height = dim_temp; } - /* create cairo data */ - cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, + /* create pixbuf */ + GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, page_width, page_height); - if(!surface) { + if(!pixbuf) { return NULL; } - cairo_t* cairo = cairo_create(surface); + poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, Zathura.document->scale, + Zathura.document->rotate, pixbuf); - if(!cairo) { - cairo_surface_destroy(surface); + /* write pixbuf */ + GtkWidget* image = gtk_image_new(); + + if(!image) { + g_object_unref(pixbuf); return NULL; } - cairo_set_source_rgb(cairo, 1, 1, 1); - cairo_rectangle(cairo, 0, 0, page_width, page_height); - cairo_fill(cairo); + gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); + gtk_widget_show(image); - switch(Zathura.document->rotate) { - case 90: - cairo_translate(cairo, page->width, 0); - break; - case 180: - cairo_translate(cairo, page->width, page->height); - break; - case 270: - cairo_translate(cairo, 0, page->height); - break; - default: - cairo_translate(cairo, 0, 0); - break; - } - - cairo_scale(cairo, Zathura.document->scale, Zathura.document->scale); - cairo_rotate(cairo, Zathura.document->rotate * G_PI / 180.0); - - /* render */ - poppler_page_render(page->data, cairo); - - cairo_destroy(cairo); - - return surface; + return image; } diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h index 1506880..39afbe0 100644 --- a/ft/pdf/pdf.h +++ b/ft/pdf/pdf.h @@ -22,7 +22,7 @@ zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* pdf_page_links_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -cairo_surface_t* pdf_page_render(zathura_page_t* page); +GtkWidget* pdf_page_render(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page); #endif // PDF_H diff --git a/zathura.c b/zathura.c index 7bb4dc1..f0a41a9 100644 --- a/zathura.c +++ b/zathura.c @@ -42,23 +42,6 @@ init_zathura() girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, "[No Name]"); - /* drawing area */ - Zathura.UI.drawing_area = gtk_drawing_area_new(); - if(!Zathura.UI.drawing_area) { - goto error_free; - } - - gtk_widget_modify_bg(Zathura.UI.drawing_area, GTK_STATE_NORMAL, - &(Zathura.UI.session->style.default_background)); - - g_signal_connect(G_OBJECT(Zathura.UI.drawing_area), "expose-event", G_CALLBACK(cb_draw), NULL); - gtk_widget_show(Zathura.UI.drawing_area); - - /* set view */ - if(!girara_set_view(Zathura.UI.session, Zathura.UI.drawing_area)) { - goto error_free; - } - /* signals */ g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); @@ -129,6 +112,27 @@ page_set(unsigned int page_id) goto error_out; } + /* render page */ + zathura_page_t* page = zathura_page_get(Zathura.document, page_id); + if(!page) { + goto error_out; + } + + GtkWidget* image = zathura_page_render(page); + if(!image) { + zathura_page_free(page); + fprintf(stderr, "error: rendering failed\n"); + goto error_out; + } + + zathura_page_free(page); + + /* draw new rendered page */ + if(!girara_set_view(Zathura.UI.session, image)) { + goto error_out; + } + + /* update page number */ Zathura.document->current_page_number = page_id; char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, Zathura.document->number_of_pages); From 14fbe0f72e1b6a537530491b77479ed2cbbacbbf Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 27 Dec 2010 09:22:08 +0100 Subject: [PATCH 032/197] Render ddjvu document --- ft/djvu/djvu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index da8ba9c..ca04c14 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -56,6 +56,23 @@ djvu_document_open(zathura_document_t* document) goto error_free; } + /* load document info */ + ddjvu_message_t* msg; + ddjvu_message_wait(djvu_document->context); + + while((msg = ddjvu_message_peek(djvu_document->context)) && (msg->m_any.tag != DDJVU_DOCINFO)) { + if(msg->m_any.tag == DDJVU_ERROR) { + goto error_free; + } + + ddjvu_message_pop(djvu_document->context); + } + + /* decoding error */ + if(ddjvu_document_decoding_error(djvu_document->document)) { + goto error_free; + } + document->number_of_pages = ddjvu_document_get_pagenum(djvu_document->document); return true; @@ -150,6 +167,8 @@ djvu_page_get(zathura_document_t* document, unsigned int page) return NULL; } + while(!ddjvu_page_decoding_done(document_page->data)); + document_page->width = ddjvu_page_get_width(document_page->data); document_page->height = ddjvu_page_get_width(document_page->data); From ace7e41a17bbb688a3f099789d7db192854d6e75 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 27 Dec 2010 09:26:53 +0100 Subject: [PATCH 033/197] Update README --- README | 1 - 1 file changed, 1 deletion(-) diff --git a/README b/README index ea68a92..fea03be 100644 --- a/README +++ b/README @@ -5,7 +5,6 @@ zathura is a pdf viewer based on the poppler pdf rendering library Requirements ------------ poppler-glib (0.12.3) -cairo (1.8.8) gtk2 (2.18.6) glib2 (2.22.4) From 19637bcd541c6628a0c277817c77118483e0550b Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 27 Dec 2010 09:44:28 +0100 Subject: [PATCH 034/197] djvu support rotation --- ft/djvu/djvu.c | 39 +++++++++++++++++++++++++++++++++------ zathura.c | 29 ++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index ca04c14..ca59d71 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -243,17 +243,39 @@ djvu_page_render(zathura_page_t* page) page_width, page_height, 3 * page_width, NULL, NULL); if(!pixbuf) { - free(buffer); - g_object_unref(pixbuf); - goto error_out; + goto error_free; + } + + /* rotate page */ + if(Zathura.document->rotate != 0) { + GdkPixbufRotation angle = GDK_PIXBUF_ROTATE_NONE; + + switch(Zathura.document->rotate) { + case 90: + angle = GDK_PIXBUF_ROTATE_CLOCKWISE; + break; + case 180: + angle = GDK_PIXBUF_ROTATE_UPSIDEDOWN; + break; + case 270: + angle = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE; + break; + default: + goto error_free; + } + + GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, Zathura.document->rotate); + if(!pixbuf_temp) { + goto error_free; + } + + pixbuf = pixbuf_temp; } GtkWidget* image = gtk_image_new(); if(!image) { - free(buffer); - g_object_unref(pixbuf); - goto error_out; + goto error_free; } gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); @@ -261,6 +283,11 @@ djvu_page_render(zathura_page_t* page) return image; +error_free: + + free(buffer); + g_object_unref(pixbuf); + error_out: return NULL; diff --git a/zathura.c b/zathura.c index f0a41a9..7c81c1b 100644 --- a/zathura.c +++ b/zathura.c @@ -101,6 +101,26 @@ document_close() return true; } +bool +page_render(zathura_page_t* page) +{ + GtkWidget* image = zathura_page_render(page); + if(!image) { + goto error_out; + } + + /* draw new rendered page */ + if(!girara_set_view(Zathura.UI.session, image)) { + goto error_out; + } + + return true; + +error_out: + + return false; +} + bool page_set(unsigned int page_id) { @@ -114,12 +134,12 @@ page_set(unsigned int page_id) /* render page */ zathura_page_t* page = zathura_page_get(Zathura.document, page_id); + if(!page) { goto error_out; } - GtkWidget* image = zathura_page_render(page); - if(!image) { + if(!page_render(page)) { zathura_page_free(page); fprintf(stderr, "error: rendering failed\n"); goto error_out; @@ -127,11 +147,6 @@ page_set(unsigned int page_id) zathura_page_free(page); - /* draw new rendered page */ - if(!girara_set_view(Zathura.UI.session, image)) { - goto error_out; - } - /* update page number */ Zathura.document->current_page_number = page_id; From 139493c62934fd39c6ed28e8f11db2ac7ef2042b Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 27 Dec 2010 09:49:22 +0100 Subject: [PATCH 035/197] Update rotation to use DDJVU internals --- ft/djvu/djvu.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index ca59d71..9b55c44 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -232,7 +232,31 @@ djvu_page_render(zathura_page_t* page) goto error_out; } - ddjvu_page_set_rotation(page->data, Zathura.document->rotate); + /* set rotation */ + GdkPixbufRotation gdk_angle = GDK_PIXBUF_ROTATE_NONE; + ddjvu_page_rotation_t ddjvu_angle = DDJVU_ROTATE_0; + + switch(Zathura.document->rotate) { + case 90: + gdk_angle = GDK_PIXBUF_ROTATE_CLOCKWISE; + ddjvu_angle = DDJVU_ROTATE_90; + break; + case 180: + gdk_angle = GDK_PIXBUF_ROTATE_UPSIDEDOWN; + ddjvu_angle = DDJVU_ROTATE_180; + break; + case 270: + gdk_angle = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE; + ddjvu_angle = DDJVU_ROTATE_270; + break; + default: + gdk_angle = GDK_PIXBUF_ROTATE_NONE; + ddjvu_angle = DDJVU_ROTATE_0; + break; + } + + + ddjvu_page_set_rotation(page->data, ddjvu_angle); /* render page */ ddjvu_page_render(page->data, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, @@ -248,23 +272,7 @@ djvu_page_render(zathura_page_t* page) /* rotate page */ if(Zathura.document->rotate != 0) { - GdkPixbufRotation angle = GDK_PIXBUF_ROTATE_NONE; - - switch(Zathura.document->rotate) { - case 90: - angle = GDK_PIXBUF_ROTATE_CLOCKWISE; - break; - case 180: - angle = GDK_PIXBUF_ROTATE_UPSIDEDOWN; - break; - case 270: - angle = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE; - break; - default: - goto error_free; - } - - GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, Zathura.document->rotate); + GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, gdk_angle) if(!pixbuf_temp) { goto error_free; } From 88f4bbab96439d76cdf6ab11072a55765dcfb61c Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 27 Dec 2010 10:24:12 +0100 Subject: [PATCH 036/197] Added missing semicolon --- ft/djvu/djvu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 9b55c44..5be2f67 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -272,7 +272,7 @@ djvu_page_render(zathura_page_t* page) /* rotate page */ if(Zathura.document->rotate != 0) { - GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, gdk_angle) + GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, gdk_angle); if(!pixbuf_temp) { goto error_free; } From 61782f4bf19354a04d1aeefb115f1f79cce6800c Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 27 Dec 2010 11:11:35 +0100 Subject: [PATCH 037/197] Fixed get_height --- ft/djvu/djvu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 5be2f67..5927638 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -170,7 +170,7 @@ djvu_page_get(zathura_document_t* document, unsigned int page) while(!ddjvu_page_decoding_done(document_page->data)); document_page->width = ddjvu_page_get_width(document_page->data); - document_page->height = ddjvu_page_get_width(document_page->data); + document_page->height = ddjvu_page_get_height(document_page->data); return document_page; } From eebdc8dece7140302c531ce27db805374cadf5c1 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 28 Dec 2010 00:47:41 +0100 Subject: [PATCH 038/197] Get all pages --- ft/document.c | 67 +++++++++++++++++++++++++++++++++++++++++---------- ft/document.h | 2 ++ ft/pdf/pdf.c | 1 - zathura.c | 8 +++--- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/ft/document.c b/ft/document.c index d202893..616b32e 100644 --- a/ft/document.c +++ b/ft/document.c @@ -26,18 +26,18 @@ zathura_document_t* zathura_document_open(const char* path, const char* password) { if(!path) { - return NULL; + goto error_out; } if(!file_exists(path)) { fprintf(stderr, "error: file does not exist\n"); - return NULL; + goto error_out; } const char* file_extension = file_get_extension(path); if(!file_extension) { fprintf(stderr, "error: could not determine file type\n"); - return NULL; + goto error_out; } /* determine real path */ @@ -50,20 +50,21 @@ zathura_document_open(const char* path, const char* password) path_max = 4096; #endif - char* real_path = malloc(sizeof(char) * path_max); + char* real_path = NULL; + zathura_document_t* document = NULL; + + real_path = malloc(sizeof(char) * path_max); if(!real_path) { - return NULL; + goto error_out; } if(!realpath(path, real_path)) { - free(real_path); - return NULL; + goto error_free; } - zathura_document_t* document = malloc(sizeof(zathura_document_t)); + document = malloc(sizeof(zathura_document_t)); if(!document) { - free(real_path); - return NULL; + goto error_free; } document->file_path = real_path; @@ -73,6 +74,7 @@ zathura_document_open(const char* path, const char* password) document->scale = 1.0; document->rotate = 0; document->data = NULL; + document->pages = NULL; document->functions.document_free = NULL; document->functions.document_index_generate = NULL; @@ -91,13 +93,29 @@ zathura_document_open(const char* path, const char* password) if(!strcmp(file_extension, zathura_document_plugins[i].file_extension)) { if(zathura_document_plugins[i].open_function) { if(zathura_document_plugins[i].open_function(document)) { + /* update statusbar */ girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, real_path); + + /* read all pages */ + document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*)); + if(!document->pages) { + goto error_free; + } + + for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) + { + zathura_page_t* page = zathura_page_get(document, page_id); + if(!page) { + goto error_free; + } + + document->pages[page_id] = page; + } + return document; } else { fprintf(stderr, "error: could not open file\n"); - free(real_path); - free(document); - return NULL; + goto error_free; } } } @@ -105,9 +123,23 @@ zathura_document_open(const char* path, const char* password) fprintf(stderr, "error: unknown file type\n"); +error_free: + free(real_path); + + if(document && document->pages) { + for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) + { + zathura_page_free(document->pages[page_id]); + } + + free(document->pages); + } + free(document); +error_out: + return NULL; } @@ -118,6 +150,15 @@ zathura_document_free(zathura_document_t* document) return false; } + /* free pages */ + for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) + { + zathura_page_free(document->pages[page_id]); + } + + free(document->pages); + + /* free document */ if(!document->functions.document_free) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); diff --git a/ft/document.h b/ft/document.h index 1442382..ffc86a7 100644 --- a/ft/document.h +++ b/ft/document.h @@ -105,6 +105,8 @@ struct zathura_document_s GtkWidget* (*page_render)(zathura_page_t* page); bool (*page_free)(zathura_page_t* page); } functions; + + zathura_page_t** pages; }; zathura_document_t* zathura_document_open(const char* path, const char* password); diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index de003f3..0c31371 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -245,7 +245,6 @@ GtkWidget* pdf_page_render(zathura_page_t* page) { if(!Zathura.document || !page || !page->data || !page->document) { - printf("die\n"); return NULL; } diff --git a/zathura.c b/zathura.c index 7c81c1b..eb7d39b 100644 --- a/zathura.c +++ b/zathura.c @@ -81,10 +81,10 @@ document_open(const char* path, const char* password) Zathura.document = document; - if(!page_set(0)) { - zathura_document_free(document); - return false; - } + /*if(!page_set(0)) {*/ + /*zathura_document_free(document);*/ + /*return false;*/ + /*}*/ return true; } From 3f961f6c182003d7c1b5447250f102e768ea3ad4 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 28 Dec 2010 09:47:09 +0100 Subject: [PATCH 039/197] Continuous basics --- utils.c | 28 ++++++++++++++++++++++++++++ utils.h | 2 ++ zathura.c | 31 +++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/utils.c b/utils.c index c03a5c9..6a0012a 100644 --- a/utils.c +++ b/utils.c @@ -120,3 +120,31 @@ execute_command(char* const argv[], char** output) return true; } + +GdkPixbuf* +page_blank(unsigned int width, unsigned int height) +{ + if((width == 0) || (height == 0)) { + return NULL; + } + + guchar* buffer = malloc(sizeof(guchar) * (width * height * 1)); + if(!buffer) { + return NULL; + } + + /* draw white */ + for(unsigned int i = 0; i < width * height; i++) { + buffer[i] = 255; + } + + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8, + width, height, 1, NULL, NULL); + + if(!pixbuf) { + free(buffer); + return NULL; + } + + return pixbuf; +} diff --git a/utils.h b/utils.h index c10ea26..f70b962 100644 --- a/utils.h +++ b/utils.h @@ -4,9 +4,11 @@ #define UTILS_H #include +#include bool file_exists(const char* path); const char* file_get_extension(const char* path); bool execute_command(char* const argv[], char** output); +GdkPixbuf* page_blank(unsigned int width, unsigned int height); #endif // UTILS_H diff --git a/zathura.c b/zathura.c index eb7d39b..60638e5 100644 --- a/zathura.c +++ b/zathura.c @@ -1,10 +1,13 @@ /* See LICENSE file for license and copyright information */ +#include + #include "callbacks.h" #include "config.h" #include "ft/document.h" #include "shortcuts.h" #include "zathura.h" +#include "utils.h" /* function implementation */ bool @@ -81,10 +84,30 @@ document_open(const char* path, const char* password) Zathura.document = document; - /*if(!page_set(0)) {*/ - /*zathura_document_free(document);*/ - /*return false;*/ - /*}*/ + GtkWidget* page_view = gtk_vbox_new(FALSE, 0); + gtk_box_set_spacing(GTK_BOX(page_view), 0); + + for(unsigned int i = 0; i < document->number_of_pages; i++) + { + GdkPixbuf* pixbuf = page_blank(document->pages[i]->width, document->pages[i]->height); + if(!pixbuf) { + return false; + } + + GtkWidget* image = gtk_image_new(); + if(!image) { + g_object_unref(pixbuf); + return false; + } + + gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); + gtk_widget_show(image); + gtk_box_pack_start(GTK_BOX(page_view), image, TRUE, TRUE, 0); + } + + gtk_widget_show(page_view); + + girara_set_view(Zathura.UI.session, page_view); return true; } From 0398692705f1279319f9f8f1753b7cf6db2c0f55 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 29 Dec 2010 11:46:13 +0100 Subject: [PATCH 040/197] Detect which page should be rendered --- callbacks.c | 35 ++++++++++++++++++++++++++ callbacks.h | 1 + ft/document.c | 6 +++++ ft/document.h | 2 ++ utils.c | 15 ++++++++++-- utils.h | 2 +- zathura.c | 68 +++++++++++++++++++++++++++++++-------------------- zathura.h | 1 + 8 files changed, 101 insertions(+), 29 deletions(-) diff --git a/callbacks.c b/callbacks.c index 07c0f5e..28f1979 100644 --- a/callbacks.c +++ b/callbacks.c @@ -3,8 +3,10 @@ #include #include #include +#include #include "zathura.h" +#include "ft/document.h" gboolean cb_destroy(GtkWidget* widget, gpointer data) @@ -30,3 +32,36 @@ buffer_changed(girara_session_t* session) girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, ""); } } + +void +cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) +{ + if(!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) { + return; + } + + /* get current adjustment values */ + gdouble lower = gtk_adjustment_get_lower(adjustment); + gdouble upper = gtk_adjustment_get_lower(adjustment); + + /* find page that fits */ + for(unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) + { + zathura_page_t* page = Zathura.document->pages[page_id]; + double begin = page->offset; + double end = page->offset + page->height; + + if( begin <= 10 ) { // FIXME + /* render page */ + GtkWidget* image = zathura_page_render(page); + if(!image) { + printf("error: rendering failed\n"); + return; + } + + /* add new page */ + gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); + gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + } + } +} diff --git a/callbacks.h b/callbacks.h index 254d7e8..2e4d575 100644 --- a/callbacks.h +++ b/callbacks.h @@ -8,5 +8,6 @@ gboolean cb_destroy(GtkWidget* widget, gpointer data); void buffer_changed(girara_session_t* session); +void cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data); #endif // CALLBACKS_H diff --git a/ft/document.c b/ft/document.c index 616b32e..fcf9a86 100644 --- a/ft/document.c +++ b/ft/document.c @@ -102,6 +102,7 @@ zathura_document_open(const char* path, const char* password) goto error_free; } + double offset = 0; for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_t* page = zathura_page_get(document, page_id); @@ -109,6 +110,11 @@ zathura_document_open(const char* path, const char* password) goto error_free; } + page->offset = offset; + page->number = page_id; + + offset += page->height; + document->pages[page_id] = page; } diff --git a/ft/document.h b/ft/document.h index ffc86a7..6c581be 100644 --- a/ft/document.h +++ b/ft/document.h @@ -77,6 +77,8 @@ typedef struct zathura_page_s { double height; double width; + double offset; + unsigned int number; zathura_document_t* document; void* data; } zathura_page_t; diff --git a/utils.c b/utils.c index 6a0012a..80cb3a5 100644 --- a/utils.c +++ b/utils.c @@ -121,7 +121,7 @@ execute_command(char* const argv[], char** output) return true; } -GdkPixbuf* +GtkWidget* page_blank(unsigned int width, unsigned int height) { if((width == 0) || (height == 0)) { @@ -146,5 +146,16 @@ page_blank(unsigned int width, unsigned int height) return NULL; } - return pixbuf; + /* convert to image */ + GtkWidget* image = gtk_image_new(); + if(!image) { + free(buffer); + g_object_unref(pixbuf); + return false; + } + + gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); + gtk_widget_show(image); + + return image; } diff --git a/utils.h b/utils.h index f70b962..0331196 100644 --- a/utils.h +++ b/utils.h @@ -9,6 +9,6 @@ bool file_exists(const char* path); const char* file_get_extension(const char* path); bool execute_command(char* const argv[], char** output); -GdkPixbuf* page_blank(unsigned int width, unsigned int height); +GtkWidget* page_blank(unsigned int width, unsigned int height); #endif // UTILS_H diff --git a/zathura.c b/zathura.c index 60638e5..b1b61df 100644 --- a/zathura.c +++ b/zathura.c @@ -26,6 +26,16 @@ init_zathura() Zathura.UI.statusbar.buffer = NULL; Zathura.UI.statusbar.page_number = NULL; Zathura.UI.drawing_area = NULL; + Zathura.UI.page_view = NULL; + + /* page view */ + Zathura.UI.page_view = gtk_vbox_new(FALSE, 0); + if(!Zathura.UI.page_view) { + goto error_free; + } + + gtk_widget_show(Zathura.UI.page_view); + gtk_box_set_spacing(GTK_BOX(Zathura.UI.page_view), 0); /* statusbar */ Zathura.UI.statusbar.file = girara_statusbar_item_add(Zathura.UI.session, TRUE, TRUE, TRUE, NULL); @@ -48,6 +58,9 @@ init_zathura() /* signals */ g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), NULL); + /* girara events */ Zathura.UI.session->events.buffer_changed = buffer_changed; @@ -62,6 +75,10 @@ error_free: g_object_unref(Zathura.UI.drawing_area); } + if(Zathura.UI.page_view) { + g_object_unref(Zathura.UI.page_view); + } + girara_session_destroy(Zathura.UI.session); error_out: @@ -73,43 +90,47 @@ bool document_open(const char* path, const char* password) { if(!path) { - return false; + goto error_out; } zathura_document_t* document = zathura_document_open(path, password); if(!document) { - return false; + goto error_out; } Zathura.document = document; - GtkWidget* page_view = gtk_vbox_new(FALSE, 0); - gtk_box_set_spacing(GTK_BOX(page_view), 0); - + /* create blank pages */ for(unsigned int i = 0; i < document->number_of_pages; i++) { - GdkPixbuf* pixbuf = page_blank(document->pages[i]->width, document->pages[i]->height); - if(!pixbuf) { - return false; - } + /* create blank page */ + GtkWidget* image = page_blank(document->pages[i]->width, document->pages[i]->height); - GtkWidget* image = gtk_image_new(); if(!image) { - g_object_unref(pixbuf); - return false; + goto error_free; } - gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); - gtk_widget_show(image); - gtk_box_pack_start(GTK_BOX(page_view), image, TRUE, TRUE, 0); + /* pack to page view */ + gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); } - gtk_widget_show(page_view); + girara_set_view(Zathura.UI.session, Zathura.UI.page_view); - girara_set_view(Zathura.UI.session, page_view); + /* first page */ + if(!page_set(0)) { + goto error_free; + } return true; + +error_free: + + zathura_document_free(document); + +error_out: + + return false; } bool @@ -147,7 +168,7 @@ error_out: bool page_set(unsigned int page_id) { - if(!Zathura.document) { + if(!Zathura.document || !Zathura.document->pages) { goto error_out; } @@ -156,19 +177,14 @@ page_set(unsigned int page_id) } /* render page */ - zathura_page_t* page = zathura_page_get(Zathura.document, page_id); + zathura_page_t* page = Zathura.document->pages[page_id]; if(!page) { goto error_out; } - if(!page_render(page)) { - zathura_page_free(page); - fprintf(stderr, "error: rendering failed\n"); - goto error_out; - } - - zathura_page_free(page); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + gtk_adjustment_set_value(view_vadjustment, page->offset); /* update page number */ Zathura.document->current_page_number = page_id; diff --git a/zathura.h b/zathura.h index cc15c33..b5d781a 100644 --- a/zathura.h +++ b/zathura.h @@ -37,6 +37,7 @@ struct } statusbar; GtkWidget *drawing_area; + GtkWidget *page_view; } UI; zathura_document_t* document; /**> The current document */ From 88fd3e555af371b3b7c3819f9a7b5cc510e28090 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 29 Dec 2010 12:26:47 +0100 Subject: [PATCH 041/197] Render first page immediatly --- zathura.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zathura.c b/zathura.c index b1b61df..0592154 100644 --- a/zathura.c +++ b/zathura.c @@ -184,7 +184,7 @@ page_set(unsigned int page_id) } GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); - gtk_adjustment_set_value(view_vadjustment, page->offset); + cb_view_vadjustment_value_changed(view_vadjustment, NULL); /* update page number */ Zathura.document->current_page_number = page_id; From ce09e56e2ab998835b73c46a7cb046bcf7ae14fb Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 5 Jan 2011 23:37:47 +0100 Subject: [PATCH 042/197] Speed up djvu --- ft/djvu/djvu.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 5927638..135a585 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -160,17 +160,20 @@ djvu_page_get(zathura_document_t* document, unsigned int page) } document_page->document = document; - document_page->data = ddjvu_page_create_by_pageno(djvu_document->document, page);; + document_page->data = NULL; - if(!document_page->data) { + ddjvu_status_t status; + ddjvu_pageinfo_t page_info; + + while((status = ddjvu_document_get_pageinfo(djvu_document->document, page, &page_info)) < DDJVU_JOB_OK); + + if(status >= DDJVU_JOB_FAILED) { free(document_page); return NULL; } - while(!ddjvu_page_decoding_done(document_page->data)); - - document_page->width = ddjvu_page_get_width(document_page->data); - document_page->height = ddjvu_page_get_height(document_page->data); + document_page->width = 0.2 * page_info.width; + document_page->height = 0.2 * page_info.height; return document_page; } @@ -182,7 +185,6 @@ djvu_page_free(zathura_page_t* page) return false; } - ddjvu_page_release(page->data); free(page); return true; @@ -209,7 +211,7 @@ djvu_page_form_fields_get(zathura_page_t* page) GtkWidget* djvu_page_render(zathura_page_t* page) { - if(!Zathura.document || !page || !page->data || !page->document) { + if(!Zathura.document || !page || !page->document) { return NULL; } @@ -218,18 +220,25 @@ djvu_page_render(zathura_page_t* page) unsigned int page_height = Zathura.document->scale * page->height; if(!page_width || !page_height) { - return NULL; + goto error_out; } /* init ddjvu render data */ djvu_document_t* djvu_document = (djvu_document_t*) page->document->data; + ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno(djvu_document->document, page->number); + + if(!djvu_page) { + goto error_out; + } + + while(!ddjvu_page_decoding_done(djvu_page)); ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; ddjvu_rect_t prect = { 0, 0, page_width, page_height }; guchar* buffer = malloc(sizeof(char) * (page_width * page_height * 3)); if(!buffer) { - goto error_out; + goto error_free; } /* set rotation */ @@ -255,11 +264,10 @@ djvu_page_render(zathura_page_t* page) break; } - - ddjvu_page_set_rotation(page->data, ddjvu_angle); + ddjvu_page_set_rotation(djvu_page, ddjvu_angle); /* render page */ - ddjvu_page_render(page->data, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, + ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, 3 * page_width, (char*) buffer); /* create pixbuf */ @@ -289,10 +297,13 @@ djvu_page_render(zathura_page_t* page) gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); gtk_widget_show(image); + ddjvu_page_release(djvu_page); + return image; error_free: + ddjvu_page_release(djvu_page); free(buffer); g_object_unref(pixbuf); From 88d4766a75cbc86da9e7a61c87a421d7d885568d Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 6 Jan 2011 08:59:10 +0100 Subject: [PATCH 043/197] Render page when needed --- callbacks.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- ft/document.c | 13 ++++++++++--- ft/document.h | 1 + 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/callbacks.c b/callbacks.c index 28f1979..74a8648 100644 --- a/callbacks.c +++ b/callbacks.c @@ -41,17 +41,27 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) } /* get current adjustment values */ - gdouble lower = gtk_adjustment_get_lower(adjustment); - gdouble upper = gtk_adjustment_get_lower(adjustment); + gdouble lower = gtk_adjustment_get_value(adjustment); + gdouble upper = lower + gtk_adjustment_get_page_size(adjustment); /* find page that fits */ for(unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) { zathura_page_t* page = Zathura.document->pages[page_id]; - double begin = page->offset; - double end = page->offset + page->height; - if( begin <= 10 ) { // FIXME + /* check for rendered attribute */ + if(page->rendered) { + continue; + } + + double begin = page->offset; + double end = page->offset + page->height; + + if( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */ + || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */ + || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */ + ) { + /* render page */ GtkWidget* image = zathura_page_render(page); if(!image) { @@ -60,8 +70,34 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) } /* add new page */ - gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); - gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); + GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page_id); + + if(widget) { + /* child packaging information */ + gboolean expand; + gboolean fill; + guint padding; + GtkPackType pack_type; + + gtk_box_query_child_packing(GTK_BOX(Zathura.UI.page_view), widget, &expand, &fill, &padding, &pack_type); + + /* delete old widget */ + gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); + + /* add new widget */ + gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); + + /* set old packaging values */ + gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); + + /* reorder child */ + gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page_id); + } else { + printf("error: page container does not exist\n"); + g_object_unref(image); + return; + } } } } diff --git a/ft/document.c b/ft/document.c index fcf9a86..fc340e6 100644 --- a/ft/document.c +++ b/ft/document.c @@ -110,8 +110,9 @@ zathura_document_open(const char* path, const char* password) goto error_free; } - page->offset = offset; - page->number = page_id; + page->offset = offset; + page->number = page_id; + page->rendered = false; offset += page->height; @@ -343,7 +344,13 @@ zathura_page_render(zathura_page_t* page) return NULL; } - return page->document->functions.page_render(page); + GtkWidget* widget = page->document->functions.page_render(page); + + if(widget) { + page->rendered = true; + } + + return widget; } zathura_index_element_t* diff --git a/ft/document.h b/ft/document.h index 6c581be..45aba4d 100644 --- a/ft/document.h +++ b/ft/document.h @@ -81,6 +81,7 @@ typedef struct zathura_page_s unsigned int number; zathura_document_t* document; void* data; + bool rendered; } zathura_page_t; struct zathura_document_s From f2b24f75b51a327be447ddfb838abbfecc6c817c Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 6 Jan 2011 09:40:56 +0100 Subject: [PATCH 044/197] Show page border --- zathura.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zathura.c b/zathura.c index 0592154..e263bad 100644 --- a/zathura.c +++ b/zathura.c @@ -112,7 +112,7 @@ document_open(const char* path, const char* password) } /* pack to page view */ - gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 1); } girara_set_view(Zathura.UI.session, Zathura.UI.page_view); From a819cf51269eb043742238ddddbfaeba814ade94 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 6 Jan 2011 11:54:31 +0100 Subject: [PATCH 045/197] Fixed some memory leaks --- callbacks.c | 1 + ft/pdf/pdf.c | 2 ++ utils.c | 3 +++ 3 files changed, 6 insertions(+) diff --git a/callbacks.c b/callbacks.c index 74a8648..dec83ba 100644 --- a/callbacks.c +++ b/callbacks.c @@ -72,6 +72,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) /* add new page */ GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page_id); + g_list_free(list); if(widget) { /* child packaging information */ diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 0c31371..cbe3769 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -48,6 +48,8 @@ pdf_document_open(zathura_document_t* document) document->number_of_pages = poppler_document_get_n_pages(pdf_document->document); + g_free(file_uri); + return true; error_free: diff --git a/utils.c b/utils.c index 80cb3a5..91e9096 100644 --- a/utils.c +++ b/utils.c @@ -157,5 +157,8 @@ page_blank(unsigned int width, unsigned int height) gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); gtk_widget_show(image); + free(buffer); + g_object_unref(pixbuf); + return image; } From 02f646751d516e467f31b13182e6431465ad6dcd Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 7 Jan 2011 09:07:02 +0100 Subject: [PATCH 046/197] Moved render function --- callbacks.c | 40 ++-------------------------------------- render.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ render.h | 7 +++++++ zathura.c | 20 -------------------- 4 files changed, 53 insertions(+), 58 deletions(-) create mode 100644 render.c create mode 100644 render.h diff --git a/callbacks.c b/callbacks.c index dec83ba..8fab8ab 100644 --- a/callbacks.c +++ b/callbacks.c @@ -6,6 +6,7 @@ #include #include "zathura.h" +#include "render.h" #include "ft/document.h" gboolean @@ -61,44 +62,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */ || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */ ) { - - /* render page */ - GtkWidget* image = zathura_page_render(page); - if(!image) { - printf("error: rendering failed\n"); - return; - } - - /* add new page */ - GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); - GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page_id); - g_list_free(list); - - if(widget) { - /* child packaging information */ - gboolean expand; - gboolean fill; - guint padding; - GtkPackType pack_type; - - gtk_box_query_child_packing(GTK_BOX(Zathura.UI.page_view), widget, &expand, &fill, &padding, &pack_type); - - /* delete old widget */ - gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); - - /* add new widget */ - gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); - - /* set old packaging values */ - gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); - - /* reorder child */ - gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page_id); - } else { - printf("error: page container does not exist\n"); - g_object_unref(image); - return; - } + page_render(Zathura.document->pages[page_id]); } } } diff --git a/render.c b/render.c new file mode 100644 index 0000000..1e067fd --- /dev/null +++ b/render.c @@ -0,0 +1,44 @@ +#include "render.h" +#include "zathura.h" + +bool page_render(zathura_page_t* page) +{ + GtkWidget* image = zathura_page_render(page); + if(!image) { + printf("error: rendering failed\n"); + return false; + } + + /* add new page */ + GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); + GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page->number); + g_list_free(list); + + if(!widget) { + printf("error: page container does not exist\n"); + g_object_unref(image); + return false; + } + + /* child packaging information */ + gboolean expand; + gboolean fill; + guint padding; + GtkPackType pack_type; + + gtk_box_query_child_packing(GTK_BOX(Zathura.UI.page_view), widget, &expand, &fill, &padding, &pack_type); + + /* delete old widget */ + gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); + + /* add new widget */ + gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); + + /* set old packaging values */ + gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); + + /* reorder child */ + gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + + return true; +} diff --git a/render.h b/render.h new file mode 100644 index 0000000..e162f91 --- /dev/null +++ b/render.h @@ -0,0 +1,7 @@ +/* See LICENSE file for license and copyright information */ + +#include + +#include "ft/document.h" + +bool page_render(zathura_page_t* page); diff --git a/zathura.c b/zathura.c index e263bad..a3fc688 100644 --- a/zathura.c +++ b/zathura.c @@ -145,26 +145,6 @@ document_close() return true; } -bool -page_render(zathura_page_t* page) -{ - GtkWidget* image = zathura_page_render(page); - if(!image) { - goto error_out; - } - - /* draw new rendered page */ - if(!girara_set_view(Zathura.UI.session, image)) { - goto error_out; - } - - return true; - -error_out: - - return false; -} - bool page_set(unsigned int page_id) { From 22fea7d28185f465fa230b0f4691d028de9b4115 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 11 Jan 2011 10:57:59 +0100 Subject: [PATCH 047/197] Began to set locks for rendering thread --- ft/document.c | 17 +++++++++++------ ft/document.h | 5 +++-- render.c | 6 ++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ft/document.c b/ft/document.c index fc340e6..040d0bf 100644 --- a/ft/document.c +++ b/ft/document.c @@ -110,10 +110,7 @@ zathura_document_open(const char* path, const char* password) goto error_free; } - page->offset = offset; - page->number = page_id; - page->rendered = false; - + page->offset = offset; offset += page->height; document->pages[page_id] = page; @@ -246,7 +243,7 @@ zathura_document_attachments_free(zathura_list_t* list) } zathura_page_t* -zathura_page_get(zathura_document_t* document, unsigned int page) +zathura_page_get(zathura_document_t* document, unsigned int page_id) { if(!document) { return NULL; @@ -257,7 +254,15 @@ zathura_page_get(zathura_document_t* document, unsigned int page) return NULL; } - return document->functions.page_get(document, page); + zathura_page_t* page = document->functions.page_get(document, page_id); + + if(page) { + page->number = page_id; + page->rendered = false; + g_static_mutex_init(&(page->lock)); + } + + return page; } bool diff --git a/ft/document.h b/ft/document.h index 45aba4d..52b09f7 100644 --- a/ft/document.h +++ b/ft/document.h @@ -82,6 +82,7 @@ typedef struct zathura_page_s zathura_document_t* document; void* data; bool rendered; + GStaticMutex lock; } zathura_page_t; struct zathura_document_s @@ -101,7 +102,7 @@ struct zathura_document_s bool (*document_save_as)(zathura_document_t* document, const char* path); zathura_list_t* (*document_attachments_get)(zathura_document_t* document); - zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page); + zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id); zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); zathura_list_t* (*page_links_get)(zathura_page_t* page); zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); @@ -120,7 +121,7 @@ bool zathura_document_index_free(zathura_list_t* list); zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); bool zathura_document_attachments_free(zathura_list_t* list); -zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page); +zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id); bool zathura_page_free(zathura_page_t* page); zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* zathura_page_links_get(zathura_page_t* page); diff --git a/render.c b/render.c index 1e067fd..2597251 100644 --- a/render.c +++ b/render.c @@ -3,13 +3,17 @@ bool page_render(zathura_page_t* page) { + g_static_mutex_lock(&(page->lock)); GtkWidget* image = zathura_page_render(page); + g_static_mutex_unlock(&(page->lock)); + if(!image) { printf("error: rendering failed\n"); return false; } /* add new page */ + g_static_mutex_lock(&(page->lock)); GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page->number); g_list_free(list); @@ -17,6 +21,7 @@ bool page_render(zathura_page_t* page) if(!widget) { printf("error: page container does not exist\n"); g_object_unref(image); + g_static_mutex_unlock(&(page->lock)); return false; } @@ -39,6 +44,7 @@ bool page_render(zathura_page_t* page) /* reorder child */ gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + g_static_mutex_unlock(&(page->lock)); return true; } From 1fc97838e1f691272f9fb1e0a8742c6c3574361e Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 24 Jan 2011 16:40:05 +0800 Subject: [PATCH 048/197] Update config_load_default function header --- config.c | 2 +- config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index f44025b..8a5fee6 100644 --- a/config.c +++ b/config.c @@ -6,7 +6,7 @@ #include "zathura.h" void -config_load_default() +config_load_default(void) { if(!Zathura.UI.session) return; diff --git a/config.h b/config.h index f9f46b8..7b8293b 100644 --- a/config.h +++ b/config.h @@ -3,6 +3,6 @@ #ifndef CONFIG_H #define CONFIG_H -void config_load_default(); +void config_load_default(void); #endif // CONFIG_H From 55eaca8ec7bb9135d33f75afd216d690a0124e46 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 24 Jan 2011 19:43:39 +0800 Subject: [PATCH 049/197] Render thread --- callbacks.c | 4 ++- render.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++--- render.h | 18 +++++++++- zathura.c | 11 ++++++ zathura.h | 6 ++++ 5 files changed, 131 insertions(+), 6 deletions(-) diff --git a/callbacks.c b/callbacks.c index 8fab8ab..820a053 100644 --- a/callbacks.c +++ b/callbacks.c @@ -16,6 +16,8 @@ cb_destroy(GtkWidget* widget, gpointer data) girara_session_destroy(Zathura.UI.session); } + document_close(); + return TRUE; } @@ -62,7 +64,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */ || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */ ) { - page_render(Zathura.document->pages[page_id]); + render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); } } } diff --git a/render.c b/render.c index 2597251..eed5d7d 100644 --- a/render.c +++ b/render.c @@ -1,27 +1,117 @@ #include "render.h" #include "zathura.h" -bool page_render(zathura_page_t* page) +void* search(void* data); +bool render(zathura_page_t* page); + +void* +search(void* data) +{ + render_thread_t* render_thread = (render_thread_t*) data; + + while(true) { + g_static_mutex_lock(&(render_thread->lock)); + + if(girara_list_size(render_thread->list) <= 0) { + g_static_mutex_unlock(&(render_thread->lock)); + g_thread_yield(); + continue; + } + + zathura_page_t* page = (zathura_page_t*) girara_list_nth(render_thread->list, 0); + girara_list_remove(render_thread->list, page); + g_static_mutex_unlock(&(render_thread->lock)); + + printf("Rendered %d\n", page->number); + + render(page); + } + + return NULL; +} + +render_thread_t* +render_init(void) +{ + render_thread_t* render_thread = malloc(sizeof(render_thread_t)); + + if(!render_thread) { + goto error_ret; + } + + render_thread->list = girara_list_new(); + + if(!render_thread->list) { + goto error_free; + } + + render_thread->thread = g_thread_create(search, render_thread, TRUE, NULL); + + if(!render_thread->thread) { + goto error_free; + } + + g_static_mutex_init(&(render_thread->lock)); + + return render_thread; + +error_free: + + free(render_thread); + +error_ret: + + return NULL; +} + +void +render_free(render_thread_t* render_thread) +{ + if(!render_thread) { + return; + } + + girara_list_free(render_thread->list); + g_static_mutex_free(&(render_thread->lock)); +} + +bool +render_page(render_thread_t* render_thread, zathura_page_t* page) +{ + if(!render_thread || !page || !render_thread->list) { + return false; + } + + g_static_mutex_lock(&(render_thread->lock)); + if(!girara_list_contains(render_thread->list, page)) { + girara_list_append(render_thread->list, page); + } + g_static_mutex_unlock(&(render_thread->lock)); + + return true; +} + +bool +render(zathura_page_t* page) { g_static_mutex_lock(&(page->lock)); GtkWidget* image = zathura_page_render(page); - g_static_mutex_unlock(&(page->lock)); if(!image) { + g_static_mutex_unlock(&(page->lock)); printf("error: rendering failed\n"); return false; } /* add new page */ - g_static_mutex_lock(&(page->lock)); GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page->number); g_list_free(list); if(!widget) { + g_static_mutex_unlock(&(page->lock)); printf("error: page container does not exist\n"); g_object_unref(image); - g_static_mutex_unlock(&(page->lock)); return false; } diff --git a/render.h b/render.h index e162f91..f1961fe 100644 --- a/render.h +++ b/render.h @@ -1,7 +1,23 @@ /* See LICENSE file for license and copyright information */ +#ifndef RENDER_H +#define RENDER_H + #include +#include +#include #include "ft/document.h" -bool page_render(zathura_page_t* page); +typedef struct render_thread_s +{ + girara_list_t* list; + GThread* thread; + GStaticMutex lock; +} render_thread_t; + +render_thread_t* render_init(void); +void render_free(render_thread_t* render_thread); +bool render_page(render_thread_t* render_thread, zathura_page_t* page); + +#endif // RENDER_H diff --git a/zathura.c b/zathura.c index a3fc688..473e2fa 100644 --- a/zathura.c +++ b/zathura.c @@ -117,6 +117,13 @@ document_open(const char* path, const char* password) girara_set_view(Zathura.UI.session, Zathura.UI.page_view); + /* threads */ + Zathura.Sync.render_thread = render_init(); + + if(!Zathura.Sync.render_thread) { + goto error_free; + } + /* first page */ if(!page_set(0)) { goto error_free; @@ -140,6 +147,10 @@ document_close() return false; } + if(Zathura.Sync.render_thread) { + render_free(Zathura.Sync.render_thread); + } + zathura_document_free(Zathura.document); return true; diff --git a/zathura.h b/zathura.h index b5d781a..7c9827c 100644 --- a/zathura.h +++ b/zathura.h @@ -5,6 +5,7 @@ #include #include +#include #include "ft/document.h" @@ -40,6 +41,11 @@ struct GtkWidget *page_view; } UI; + struct + { + render_thread_t* render_thread; + } Sync; + zathura_document_t* document; /**> The current document */ } Zathura; From 93e2edf4c9bdb0ef5609ae383ba47680fb62a2c7 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 24 Jan 2011 19:54:20 +0800 Subject: [PATCH 050/197] sc_scroll --- config.c | 1 - shortcuts.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 8a5fee6..c957def 100644 --- a/config.c +++ b/config.c @@ -62,7 +62,6 @@ config_load_default(void) girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_f, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "%", sc_scroll, NORMAL, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_n, NULL, sc_search, NORMAL, FORWARD, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_N, NULL, sc_search, NORMAL, BACKWARD, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_0, NULL, sc_switch_goto_mode, NORMAL, 0, NULL); diff --git a/shortcuts.c b/shortcuts.c index db0ef77..82cf482 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -111,6 +111,52 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument) bool sc_scroll(girara_session_t* session, girara_argument_t* argument) { + GtkAdjustment* adjustment = NULL; + if( (argument->n == LEFT) || (argument->n == RIGHT) ) + adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + else + adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.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 scroll_step = 40; + + gdouble new_value; + switch(argument->n) + { + case FULL_UP: + new_value = (value - view_size) < 0 ? 0 : (value - view_size); + break; + case FULL_DOWN: + new_value = (value + view_size) > max ? max : (value + view_size); + break; + case HALF_UP: + new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2)); + break; + case HALF_DOWN: + new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2)); + break; + case LEFT: + case UP: + new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step); + break; + case RIGHT: + case DOWN: + new_value = (value + scroll_step) > max ? max : (value + scroll_step); + break; + case TOP: + new_value = 0; + break; + case BOTTOM: + new_value = max; + break; + default: + new_value = 0; + } + + gtk_adjustment_set_value(adjustment, new_value); + return false; } From 056269fcae4b825faeb24c7b091999513b0c76a4 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 24 Jan 2011 20:10:06 +0800 Subject: [PATCH 051/197] Renamed search to render --- callbacks.c | 2 +- render.c | 8 ++++---- utils.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/callbacks.c b/callbacks.c index 820a053..74c2ef1 100644 --- a/callbacks.c +++ b/callbacks.c @@ -64,7 +64,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */ || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */ ) { - render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); + render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); } } } diff --git a/render.c b/render.c index eed5d7d..884d623 100644 --- a/render.c +++ b/render.c @@ -1,11 +1,11 @@ #include "render.h" #include "zathura.h" -void* search(void* data); +void* render_job(void* data); bool render(zathura_page_t* page); void* -search(void* data) +render_job(void* data) { render_thread_t* render_thread = (render_thread_t*) data; @@ -45,7 +45,7 @@ render_init(void) goto error_free; } - render_thread->thread = g_thread_create(search, render_thread, TRUE, NULL); + render_thread->thread = g_thread_create(render_job, render_thread, TRUE, NULL); if(!render_thread->thread) { goto error_free; @@ -78,7 +78,7 @@ render_free(render_thread_t* render_thread) bool render_page(render_thread_t* render_thread, zathura_page_t* page) { - if(!render_thread || !page || !render_thread->list) { + if(!render_thread || !page || !render_thread->list || page->rendered) { return false; } diff --git a/utils.c b/utils.c index 91e9096..a5fafd8 100644 --- a/utils.c +++ b/utils.c @@ -157,7 +157,7 @@ page_blank(unsigned int width, unsigned int height) gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); gtk_widget_show(image); - free(buffer); + /*free(buffer);*/ g_object_unref(pixbuf); return image; From e043e55b13b5979ae98af7519f4f32a6afb55936 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 26 Jan 2011 19:06:57 +0800 Subject: [PATCH 052/197] Use GCond for rendering thread --- render.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++---------- render.h | 3 ++- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/render.c b/render.c index 884d623..1a6d893 100644 --- a/render.c +++ b/render.c @@ -10,17 +10,15 @@ render_job(void* data) render_thread_t* render_thread = (render_thread_t*) data; while(true) { - g_static_mutex_lock(&(render_thread->lock)); + g_mutex_lock(render_thread->lock); if(girara_list_size(render_thread->list) <= 0) { - g_static_mutex_unlock(&(render_thread->lock)); - g_thread_yield(); - continue; + g_cond_wait(render_thread->cond, render_thread->lock); } zathura_page_t* page = (zathura_page_t*) girara_list_nth(render_thread->list, 0); girara_list_remove(render_thread->list, page); - g_static_mutex_unlock(&(render_thread->lock)); + g_mutex_unlock(render_thread->lock); printf("Rendered %d\n", page->number); @@ -39,6 +37,12 @@ render_init(void) goto error_ret; } + /* init */ + render_thread->list = NULL; + render_thread->thread = NULL; + render_thread->cond = NULL; + + /* setup */ render_thread->list = girara_list_new(); if(!render_thread->list) { @@ -51,12 +55,34 @@ render_init(void) goto error_free; } - g_static_mutex_init(&(render_thread->lock)); + render_thread->cond = g_cond_new(); + + if(!render_thread->cond) { + goto error_free; + } + + render_thread->lock = g_mutex_new(); + + if(!render_thread->lock) { + goto error_free; + } return render_thread; error_free: + if(render_thread->list) { + girara_list_free(render_thread->list); + } + + if(render_thread->cond) { + g_cond_free(render_thread->cond); + } + + if(render_thread->lock) { + g_mutex_free(render_thread->lock); + } + free(render_thread); error_ret: @@ -71,8 +97,17 @@ render_free(render_thread_t* render_thread) return; } - girara_list_free(render_thread->list); - g_static_mutex_free(&(render_thread->lock)); + if(render_thread->list) { + girara_list_free(render_thread->list); + } + + if(render_thread->cond) { + g_cond_free(render_thread->cond); + } + + if(render_thread->lock) { + g_mutex_free(render_thread->lock); + } } bool @@ -82,11 +117,12 @@ render_page(render_thread_t* render_thread, zathura_page_t* page) return false; } - g_static_mutex_lock(&(render_thread->lock)); + g_mutex_lock(render_thread->lock); if(!girara_list_contains(render_thread->list, page)) { girara_list_append(render_thread->list, page); } - g_static_mutex_unlock(&(render_thread->lock)); + g_cond_signal(render_thread->cond); + g_mutex_unlock(render_thread->lock); return true; } diff --git a/render.h b/render.h index f1961fe..89e2024 100644 --- a/render.h +++ b/render.h @@ -13,7 +13,8 @@ typedef struct render_thread_s { girara_list_t* list; GThread* thread; - GStaticMutex lock; + GMutex* lock; + GCond* cond; } render_thread_t; render_thread_t* render_init(void); From ccfe1d9fbab52843f742de7d62bec4dc1b47e18f Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 1 Feb 2011 22:48:16 +0800 Subject: [PATCH 053/197] Added some function comments --- callbacks.h | 21 +++++++++++++++++++++ utils.h | 29 +++++++++++++++++++++++++++++ zathura.h | 1 - 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/callbacks.h b/callbacks.h index 2e4d575..8743be1 100644 --- a/callbacks.h +++ b/callbacks.h @@ -6,8 +6,29 @@ #include #include +/** + * Quits the current zathura session + * + * @param widget The gtk window of zathura + * @param data NULL + * @return TRUE + */ gboolean cb_destroy(GtkWidget* widget, gpointer data); + +/** + * This function gets called when the buffer of girara changes + * + * @param session The girara session + */ void buffer_changed(girara_session_t* session); + +/** + * This function gets called when the the value of the vertical scrollbars + * changes (e.g.: by scrolling, moving to another page) + * + * @param adjustment The vadjustment of the page view + * @param data NULL + */ void cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data); #endif // CALLBACKS_H diff --git a/utils.h b/utils.h index 0331196..66401d4 100644 --- a/utils.h +++ b/utils.h @@ -6,9 +6,38 @@ #include #include +/** + * Checks if the given file exists + * + * @param path Path to the file + * @return true if the file exists, otherwise false + */ bool file_exists(const char* path); + +/** + * Returns the file extension of a path + * + * @param path Path to the file + * @return The file extension or NULL + */ const char* file_get_extension(const char* path); + +/** + * Executes a system command and saves its output into output + * + * @param argv The command + * @param output Pointer where the output will be saved + * @return true if no error occured, otherwise false + */ bool execute_command(char* const argv[], char** output); + +/** + * Creates a blank page + * + * @param width The width of the page + * @param height The height of the page + * @return The widget of the page or NULL if an error occured + */ GtkWidget* page_blank(unsigned int width, unsigned int height); #endif // UTILS_H diff --git a/zathura.h b/zathura.h index 7c9827c..f45a8bf 100644 --- a/zathura.h +++ b/zathura.h @@ -54,7 +54,6 @@ struct * * @return If no error occured true, otherwise false, is returned. */ - bool init_zathura(); /** From 4c19c798f729d167e6dd58872489f5ad7adfea47 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 8 Feb 2011 14:51:53 +0800 Subject: [PATCH 054/197] Add function documentation --- commands.h | 62 +++++++++++++++++++ completion.h | 7 +++ config.h | 3 + render.h | 28 +++++++-- shortcuts.h | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++ zathura.c | 5 -- zathura.h | 5 +- 7 files changed, 265 insertions(+), 12 deletions(-) diff --git a/commands.h b/commands.h index 5096510..471aa3c 100644 --- a/commands.h +++ b/commands.h @@ -6,12 +6,74 @@ #include #include +/** + * Create a bookmark + * + * @param session The used girara session + * @param argc Number of arguments + * @param argv Value of the arguments + * @return true if no error occured + */ bool cmd_bookmark_create(girara_session_t* session, int argc, char** argv); + +/** + * Delete a bookmark + * + * @param session The used girara session + * @param argc Number of arguments + * @param argv Value of the arguments + * @return true if no error occured + */ bool cmd_bookmark_delete(girara_session_t* session, int argc, char** argv); + +/** + * Open a bookmark + * + * @param session The used girara session + * @param argc Number of arguments + * @param argv Value of the arguments + * @return true if no error occured + */ bool cmd_bookmark_open(girara_session_t* session, int argc, char** argv); + +/** + * Close zathura + * + * @param session The used girara session + * @param argc Number of arguments + * @param argv Value of the arguments + * @return true if no error occured + */ bool cmd_close(girara_session_t* session, int argc, char** argv); + +/** + * Display document information + * + * @param session The used girara session + * @param argc Number of arguments + * @param argv Value of the arguments + * @return true if no error occured + */ bool cmd_info(girara_session_t* session, int argc, char** argv); + +/** + * Print the current file + * + * @param session The used girara session + * @param argc Number of arguments + * @param argv Value of the arguments + * @return true if no error occured + */ bool cmd_print(girara_session_t* session, int argc, char** argv); + +/** + * Save the current file + * + * @param session The used girara session + * @param argc Number of arguments + * @param argv Value of the arguments + * @return true if no error occured + */ bool cmd_save(girara_session_t* session, int argc, char** argv); #endif // COMMANDS_H diff --git a/completion.h b/completion.h index 81800e9..3baba94 100644 --- a/completion.h +++ b/completion.h @@ -5,6 +5,13 @@ #include +/** + * Completion for the print command. Creates a list of available printers + * + * @param session The used girara session + * @param input The current input + * @return The completion object or NULL if an error occured + */ girara_completion_t* cc_print(girara_session_t* session, char* input); #endif // COMPLETION_H diff --git a/config.h b/config.h index 7b8293b..a3a03e7 100644 --- a/config.h +++ b/config.h @@ -3,6 +3,9 @@ #ifndef CONFIG_H #define CONFIG_H +/** + * This function loads the default values of the configuration + */ void config_load_default(void); #endif // CONFIG_H diff --git a/render.h b/render.h index 89e2024..29e2607 100644 --- a/render.h +++ b/render.h @@ -11,14 +11,34 @@ typedef struct render_thread_s { - girara_list_t* list; - GThread* thread; - GMutex* lock; - GCond* cond; + girara_list_t* list; /**> The list of pages */ + GThread* thread; /**> The thread object */ + GMutex* lock; /**> Lock */ + GCond* cond; /**> Condition */ } render_thread_t; +/** + * This function initializes a render thread + * + * @return The render thread object or NULL if an error occured + */ render_thread_t* render_init(void); + +/** + * This function destroys the render thread object + * + * @param render_thread The render thread object + */ void render_free(render_thread_t* render_thread); + +/** + * This function is used to add a page to the render thread list + * that should be rendered. + * + * @param render_thread The render thread object + * @param page The page that should be rendered + * @return true if no error occured + */ bool render_page(render_thread_t* render_thread, zathura_page_t* page); #endif // RENDER_H diff --git a/shortcuts.h b/shortcuts.h index 22b0310..88c21c9 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -5,26 +5,193 @@ #include +/** + * Abort the current action and return to normal mode + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_abort(girara_session_t* session, girara_argument_t* argument); + +/** + * Adjust the rendered pages to the window + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument); + +/** + * Modify the current buffer + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument); + +/** + * Change the current mode + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument); + +/** + * Focus the inputbar + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument); + +/** + * Follow a link + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_follow(girara_session_t* session, girara_argument_t* argument); + +/** + * Go to a specific page or position + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_goto(girara_session_t* session, girara_argument_t* argument); + +/** + * Navigate through the document + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_navigate(girara_session_t* session, girara_argument_t* argument); + +/** + * Recolor the pages + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_recolor(girara_session_t* session, girara_argument_t* argument); + +/** + * Reload the current document + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_reload(girara_session_t* session, girara_argument_t* argument); + +/** + * Rotate the pages + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_rotate(girara_session_t* session, girara_argument_t* argument); + +/** + * Scroll through the pages + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_scroll(girara_session_t* session, girara_argument_t* argument); + +/** + * Search through the document for the latest search item + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_search(girara_session_t* session, girara_argument_t* argument); + +/** + * Switch go to mode (numeric, labels) + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument); + +/** + * Navigate through the index of the document + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument); + +/** + * Show/Hide the index of the document + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument); + +/** + * Show/Hide the inputbar + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument); + +/** + * Toggle fullscreen mode + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument); + +/** + * Show/Hide the statusbar + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument); + +/** + * Quit zathura + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_quit(girara_session_t* session, girara_argument_t* argument); + +/** + * Change the zoom level + * + * @param session The used girara session + * @param argument The used argument + * @return true if no error occured otherwise false + */ bool sc_zoom(girara_session_t* session, girara_argument_t* argument); #endif // SHORTCUTS_H diff --git a/zathura.c b/zathura.c index 473e2fa..9d92db7 100644 --- a/zathura.c +++ b/zathura.c @@ -25,7 +25,6 @@ init_zathura() Zathura.UI.statusbar.file = NULL; Zathura.UI.statusbar.buffer = NULL; Zathura.UI.statusbar.page_number = NULL; - Zathura.UI.drawing_area = NULL; Zathura.UI.page_view = NULL; /* page view */ @@ -71,10 +70,6 @@ init_zathura() error_free: - if(Zathura.UI.drawing_area) { - g_object_unref(Zathura.UI.drawing_area); - } - if(Zathura.UI.page_view) { g_object_unref(Zathura.UI.page_view); } diff --git a/zathura.h b/zathura.h index f45a8bf..e857ac0 100644 --- a/zathura.h +++ b/zathura.h @@ -37,13 +37,12 @@ struct girara_statusbar_item_t* page_number; /**> page number statusbar entry */ } statusbar; - GtkWidget *drawing_area; - GtkWidget *page_view; + GtkWidget *page_view; /**> Widget that contains all rendered pages */ } UI; struct { - render_thread_t* render_thread; + render_thread_t* render_thread; /**> The thread responsible for rendering the pages */ } Sync; zathura_document_t* document; /**> The current document */ From 5e7a774101471a63ecf73ce77e69d06d00f9aefb Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 9 Feb 2011 19:29:09 +0800 Subject: [PATCH 055/197] Updated coding standard --- callbacks.c | 12 +++---- completion.c | 11 +++--- config.c | 2 +- ft/djvu/djvu.c | 56 +++++++++++++++---------------- ft/document.c | 90 +++++++++++++++++++++++++------------------------- ft/pdf/pdf.c | 50 ++++++++++++++-------------- render.c | 36 ++++++++++---------- shortcuts.c | 12 +++---- utils.c | 40 +++++++++++----------- zathura.c | 42 +++++++++++------------ 10 files changed, 175 insertions(+), 176 deletions(-) diff --git a/callbacks.c b/callbacks.c index 74c2ef1..fd1c1a0 100644 --- a/callbacks.c +++ b/callbacks.c @@ -12,7 +12,7 @@ gboolean cb_destroy(GtkWidget* widget, gpointer data) { - if(Zathura.UI.session) { + if (Zathura.UI.session) { girara_session_destroy(Zathura.UI.session); } @@ -28,7 +28,7 @@ buffer_changed(girara_session_t* session) char* buffer = girara_buffer_get(session); - if(buffer) { + if (buffer) { girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer); free(buffer); } else { @@ -39,7 +39,7 @@ buffer_changed(girara_session_t* session) void cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { - if(!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) { + if (!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) { return; } @@ -48,19 +48,19 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) gdouble upper = lower + gtk_adjustment_get_page_size(adjustment); /* find page that fits */ - for(unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) + for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) { zathura_page_t* page = Zathura.document->pages[page_id]; /* check for rendered attribute */ - if(page->rendered) { + if (page->rendered) { continue; } double begin = page->offset; double end = page->offset + page->height; - if( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */ + if ( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */ || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */ || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */ ) { diff --git a/completion.c b/completion.c index 6bfa583..b51927e 100644 --- a/completion.c +++ b/completion.c @@ -13,7 +13,7 @@ cc_print(girara_session_t* session, char* input) girara_completion_t* completion = girara_completion_init(); girara_completion_group_t* group = girara_completion_group_create(session, NULL); - if(!session || !input || !completion || !group) + if (!session || !input || !completion || !group) return NULL; girara_completion_add_group(completion, group); @@ -23,7 +23,7 @@ cc_print(girara_session_t* session, char* input) }; char* output; - if(!execute_command(list_printers, &output)) { + if (!execute_command(list_printers, &output)) { girara_completion_free(completion); return false; } @@ -33,9 +33,8 @@ cc_print(girara_session_t* session, char* input) char* p = strtok(output, "\n"); char* q; - while(p) - { - if(!(p = strstr(p, "device for ")) || !(q = strchr(p, ':'))) { + while (p) { + if (!(p = strstr(p, "device for ")) || !(q = strchr(p, ':'))) { p = strtok(NULL, "\n"); continue; } @@ -43,7 +42,7 @@ cc_print(girara_session_t* session, char* input) unsigned int printer_length = q - p - prefix_length; char* printer_name = malloc(sizeof(char) * printer_length); - if(!printer_name) { + if (!printer_name) { p = strtok(NULL, "\n"); continue; } diff --git a/config.c b/config.c index c957def..e305e52 100644 --- a/config.c +++ b/config.c @@ -8,7 +8,7 @@ void config_load_default(void) { - if(!Zathura.UI.session) + if (!Zathura.UI.session) return; /* general settings */ diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 135a585..b7040a8 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -8,7 +8,7 @@ bool djvu_document_open(zathura_document_t* document) { - if(!document) { + if (!document) { goto error_out; } @@ -24,7 +24,7 @@ djvu_document_open(zathura_document_t* document) document->functions.page_free = djvu_page_free; document->data = malloc(sizeof(djvu_document_t)); - if(!document->data) { + if (!document->data) { goto error_out; } @@ -36,7 +36,7 @@ djvu_document_open(zathura_document_t* document) /* setup format */ djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGB24, 0, NULL); - if(!djvu_document->format) { + if (!djvu_document->format) { goto error_free; } @@ -45,14 +45,14 @@ djvu_document_open(zathura_document_t* document) /* setup context */ djvu_document->context = ddjvu_context_create("zathura"); - if(!djvu_document->context) { + if (!djvu_document->context) { goto error_free; } /* setup document */ djvu_document->document = ddjvu_document_create_by_filename(djvu_document->context, document->file_path, FALSE); - if(!djvu_document->document) { + if (!djvu_document->document) { goto error_free; } @@ -60,8 +60,8 @@ djvu_document_open(zathura_document_t* document) ddjvu_message_t* msg; ddjvu_message_wait(djvu_document->context); - while((msg = ddjvu_message_peek(djvu_document->context)) && (msg->m_any.tag != DDJVU_DOCINFO)) { - if(msg->m_any.tag == DDJVU_ERROR) { + while ((msg = ddjvu_message_peek(djvu_document->context)) && (msg->m_any.tag != DDJVU_DOCINFO)) { + if (msg->m_any.tag == DDJVU_ERROR) { goto error_free; } @@ -69,7 +69,7 @@ djvu_document_open(zathura_document_t* document) } /* decoding error */ - if(ddjvu_document_decoding_error(djvu_document->document)) { + if (ddjvu_document_decoding_error(djvu_document->document)) { goto error_free; } @@ -79,11 +79,11 @@ djvu_document_open(zathura_document_t* document) error_free: - if(djvu_document->format) { + if (djvu_document->format) { ddjvu_format_release(djvu_document->format); } - if(djvu_document->context) { + if (djvu_document->context) { ddjvu_context_release(djvu_document->context); } @@ -98,11 +98,11 @@ error_out: bool djvu_document_free(zathura_document_t* document) { - if(!document) { + if (!document) { return false; } - if(document->data) { + if (document->data) { djvu_document_t* djvu_document = (djvu_document_t*) document->data; ddjvu_context_release(djvu_document->context); ddjvu_document_release(djvu_document->document); @@ -122,14 +122,14 @@ djvu_document_index_generate(zathura_document_t* document) bool djvu_document_save_as(zathura_document_t* document, const char* path) { - if(!document || !document->data || !path) { + if (!document || !document->data || !path) { return false; } djvu_document_t* djvu_document = (djvu_document_t*) document->data; FILE* fp = fopen(path, "w"); - if(!fp) { + if (!fp) { return false; } @@ -148,14 +148,14 @@ djvu_document_attachments_get(zathura_document_t* document) zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page) { - if(!document || !document->data) { + if (!document || !document->data) { return NULL; } djvu_document_t* djvu_document = (djvu_document_t*) document->data; zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); - if(!document_page) { + if (!document_page) { return NULL; } @@ -165,9 +165,9 @@ djvu_page_get(zathura_document_t* document, unsigned int page) ddjvu_status_t status; ddjvu_pageinfo_t page_info; - while((status = ddjvu_document_get_pageinfo(djvu_document->document, page, &page_info)) < DDJVU_JOB_OK); + while ((status = ddjvu_document_get_pageinfo(djvu_document->document, page, &page_info)) < DDJVU_JOB_OK); - if(status >= DDJVU_JOB_FAILED) { + if (status >= DDJVU_JOB_FAILED) { free(document_page); return NULL; } @@ -181,7 +181,7 @@ djvu_page_get(zathura_document_t* document, unsigned int page) bool djvu_page_free(zathura_page_t* page) { - if(!page) { + if (!page) { return false; } @@ -211,7 +211,7 @@ djvu_page_form_fields_get(zathura_page_t* page) GtkWidget* djvu_page_render(zathura_page_t* page) { - if(!Zathura.document || !page || !page->document) { + if (!Zathura.document || !page || !page->document) { return NULL; } @@ -219,7 +219,7 @@ djvu_page_render(zathura_page_t* page) unsigned int page_width = Zathura.document->scale * page->width; unsigned int page_height = Zathura.document->scale * page->height; - if(!page_width || !page_height) { + if (!page_width || !page_height) { goto error_out; } @@ -227,17 +227,17 @@ djvu_page_render(zathura_page_t* page) djvu_document_t* djvu_document = (djvu_document_t*) page->document->data; ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno(djvu_document->document, page->number); - if(!djvu_page) { + if (!djvu_page) { goto error_out; } - while(!ddjvu_page_decoding_done(djvu_page)); + while (!ddjvu_page_decoding_done(djvu_page)); ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; ddjvu_rect_t prect = { 0, 0, page_width, page_height }; guchar* buffer = malloc(sizeof(char) * (page_width * page_height * 3)); - if(!buffer) { + if (!buffer) { goto error_free; } @@ -274,14 +274,14 @@ djvu_page_render(zathura_page_t* page) GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8, page_width, page_height, 3 * page_width, NULL, NULL); - if(!pixbuf) { + if (!pixbuf) { goto error_free; } /* rotate page */ - if(Zathura.document->rotate != 0) { + if (Zathura.document->rotate != 0) { GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, gdk_angle); - if(!pixbuf_temp) { + if (!pixbuf_temp) { goto error_free; } @@ -290,7 +290,7 @@ djvu_page_render(zathura_page_t* page) GtkWidget* image = gtk_image_new(); - if(!image) { + if (!image) { goto error_free; } diff --git a/ft/document.c b/ft/document.c index 040d0bf..98dd0ac 100644 --- a/ft/document.c +++ b/ft/document.c @@ -25,17 +25,17 @@ zathura_document_plugin_t zathura_document_plugins[] = { zathura_document_t* zathura_document_open(const char* path, const char* password) { - if(!path) { + if (!path) { goto error_out; } - if(!file_exists(path)) { + if (!file_exists(path)) { fprintf(stderr, "error: file does not exist\n"); goto error_out; } const char* file_extension = file_get_extension(path); - if(!file_extension) { + if (!file_extension) { fprintf(stderr, "error: could not determine file type\n"); goto error_out; } @@ -46,7 +46,7 @@ zathura_document_open(const char* path, const char* password) path_max = PATH_MAX; #else path_max = pathconf(path,_PC_PATH_MAX); - if(path_max <= 0) + if (path_max <= 0) path_max = 4096; #endif @@ -54,16 +54,16 @@ zathura_document_open(const char* path, const char* password) zathura_document_t* document = NULL; real_path = malloc(sizeof(char) * path_max); - if(!real_path) { + if (!real_path) { goto error_out; } - if(!realpath(path, real_path)) { + if (!realpath(path, real_path)) { goto error_free; } document = malloc(sizeof(zathura_document_t)); - if(!document) { + if (!document) { goto error_free; } @@ -88,25 +88,25 @@ zathura_document_open(const char* path, const char* password) document->functions.page_render = NULL; /* init plugin with associated file type */ - for(unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++) + for (unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++) { - if(!strcmp(file_extension, zathura_document_plugins[i].file_extension)) { - if(zathura_document_plugins[i].open_function) { - if(zathura_document_plugins[i].open_function(document)) { + if (!strcmp(file_extension, zathura_document_plugins[i].file_extension)) { + if (zathura_document_plugins[i].open_function) { + if (zathura_document_plugins[i].open_function(document)) { /* update statusbar */ girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, real_path); /* read all pages */ document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*)); - if(!document->pages) { + if (!document->pages) { goto error_free; } double offset = 0; - for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) + for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_t* page = zathura_page_get(document, page_id); - if(!page) { + if (!page) { goto error_free; } @@ -131,8 +131,8 @@ error_free: free(real_path); - if(document && document->pages) { - for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) + if (document && document->pages) { + for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_free(document->pages[page_id]); } @@ -150,12 +150,12 @@ error_out: bool zathura_document_free(zathura_document_t* document) { - if(!document) { + if (!document) { return false; } /* free pages */ - for(unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) + for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_free(document->pages[page_id]); } @@ -163,10 +163,10 @@ zathura_document_free(zathura_document_t* document) free(document->pages); /* free document */ - if(!document->functions.document_free) { + if (!document->functions.document_free) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); - if(document->file_path) { + if (document->file_path) { free(document->file_path); } @@ -176,7 +176,7 @@ zathura_document_free(zathura_document_t* document) bool r = document->functions.document_free(document); - if(document->file_path) { + if (document->file_path) { free(document->file_path); } @@ -188,11 +188,11 @@ zathura_document_free(zathura_document_t* document) bool zathura_document_save_as(zathura_document_t* document, const char* path) { - if(!document || !path) { + if (!document || !path) { return false; } - if(!document->functions.document_save_as) { + if (!document->functions.document_save_as) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return false; } @@ -203,11 +203,11 @@ zathura_document_save_as(zathura_document_t* document, const char* path) girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document) { - if(!document) { + if (!document) { return NULL; } - if(!document->functions.document_index_generate) { + if (!document->functions.document_index_generate) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return NULL; } @@ -224,11 +224,11 @@ zathura_document_index_free(zathura_list_t* list) zathura_list_t* zathura_document_attachments_get(zathura_document_t* document) { - if(!document) { + if (!document) { return NULL; } - if(!document->functions.document_attachments_get) { + if (!document->functions.document_attachments_get) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return NULL; } @@ -245,18 +245,18 @@ zathura_document_attachments_free(zathura_list_t* list) zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id) { - if(!document) { + if (!document) { return NULL; } - if(!document->functions.page_get) { + if (!document->functions.page_get) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return NULL; } zathura_page_t* page = document->functions.page_get(document, page_id); - if(page) { + if (page) { page->number = page_id; page->rendered = false; g_static_mutex_init(&(page->lock)); @@ -268,11 +268,11 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) bool zathura_page_free(zathura_page_t* page) { - if(!page || !page->document) { + if (!page || !page->document) { return false; } - if(!page->document->functions.page_free) { + if (!page->document->functions.page_free) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return false; } @@ -283,11 +283,11 @@ zathura_page_free(zathura_page_t* page) zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text) { - if(!page || !page->document || !text) { + if (!page || !page->document || !text) { return NULL; } - if(!page->document->functions.page_search_text) { + if (!page->document->functions.page_search_text) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return NULL; } @@ -298,11 +298,11 @@ zathura_page_search_text(zathura_page_t* page, const char* text) zathura_list_t* zathura_page_links_get(zathura_page_t* page) { - if(!page || !page->document) { + if (!page || !page->document) { return NULL; } - if(!page->document->functions.page_links_get) { + if (!page->document->functions.page_links_get) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return NULL; } @@ -319,11 +319,11 @@ zathura_page_links_free(zathura_list_t* list) zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page) { - if(!page || !page->document) { + if (!page || !page->document) { return NULL; } - if(!page->document->functions.page_form_fields_get) { + if (!page->document->functions.page_form_fields_get) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return NULL; } @@ -340,18 +340,18 @@ zathura_page_form_fields_free(zathura_list_t* list) GtkWidget* zathura_page_render(zathura_page_t* page) { - if(!page || !page->document) { + if (!page || !page->document) { return NULL; } - if(!page->document->functions.page_render) { + if (!page->document->functions.page_render) { fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); return NULL; } GtkWidget* widget = page->document->functions.page_render(page); - if(widget) { + if (widget) { page->rendered = true; } @@ -361,13 +361,13 @@ zathura_page_render(zathura_page_t* page) zathura_index_element_t* zathura_index_element_new(const char* title) { - if(!title) { + if (!title) { return NULL; } zathura_index_element_t* res = g_malloc0(sizeof(zathura_index_element_t)); - if(!res) { + if (!res) { return NULL; } @@ -379,13 +379,13 @@ zathura_index_element_new(const char* title) void zathura_index_element_free(zathura_index_element_t* index) { - if(!index) { + if (!index) { return; } g_free(index->title); - if(index->type == ZATHURA_LINK_EXTERNAL) { + if (index->type == ZATHURA_LINK_EXTERNAL) { g_free(index->target.uri); } diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index cbe3769..6147d9c 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -9,7 +9,7 @@ bool pdf_document_open(zathura_document_t* document) { - if(!document) { + if (!document) { goto error_out; } @@ -25,7 +25,7 @@ pdf_document_open(zathura_document_t* document) document->functions.page_free = pdf_page_free; document->data = malloc(sizeof(pdf_document_t)); - if(!document->data) { + if (!document->data) { goto error_out; } @@ -33,7 +33,7 @@ pdf_document_open(zathura_document_t* document) GError* error = NULL; char* file_uri = g_filename_to_uri(document->file_path, NULL, &error); - if(!file_uri) { + if (!file_uri) { fprintf(stderr, "error: could not open file: %s\n", error->message); goto error_free; } @@ -41,7 +41,7 @@ pdf_document_open(zathura_document_t* document) pdf_document_t* pdf_document = (pdf_document_t*) document->data; pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error); - if(!pdf_document->document) { + if (!pdf_document->document) { fprintf(stderr, "error: could not open file: %s\n", error->message); goto error_free; } @@ -54,11 +54,11 @@ pdf_document_open(zathura_document_t* document) error_free: - if(error) { + if (error) { g_error_free(error); } - if(file_uri) { + if (file_uri) { g_free(file_uri); } @@ -73,11 +73,11 @@ error_out: bool pdf_document_free(zathura_document_t* document) { - if(!document) { + if (!document) { return false; } - if(document->data) { + if (document->data) { pdf_document_t* pdf_document = (pdf_document_t*) document->data; g_object_unref(pdf_document->document); free(document->data); @@ -90,7 +90,7 @@ pdf_document_free(zathura_document_t* document) static void build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* iter) { - if(!root || !iter) { + if (!root || !iter) { return; } @@ -98,22 +98,22 @@ build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* ite { PopplerAction* action = poppler_index_iter_get_action(iter); - if(!action) { + if (!action) { continue; } gchar* markup = g_markup_escape_text(action->any.title, -1); zathura_index_element_t* indexelement = zathura_index_element_new(markup); - if(action->type == POPPLER_ACTION_URI) { + if (action->type == POPPLER_ACTION_URI) { indexelement->type = ZATHURA_LINK_EXTERNAL; indexelement->target.uri = g_strdup(action->uri.uri); } else if (action->type == POPPLER_ACTION_GOTO_DEST) { indexelement->type = ZATHURA_LINK_TO_PAGE; - if(action->goto_dest.dest->type == POPPLER_DEST_NAMED) { + if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) { PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest); - if(dest) { + if (dest) { indexelement->target.page_number = dest->page_num - 1; poppler_dest_free(dest); } @@ -131,7 +131,7 @@ build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* ite girara_tree_node_t* node = girara_node_append_data(root, indexelement); PopplerIndexIter* child = poppler_index_iter_get_child(iter); - if(child) { + if (child) { build_index(pdf, node, child); } @@ -143,14 +143,14 @@ build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* ite girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document) { - if(!document || !document->data) { + if (!document || !document->data) { return NULL; } pdf_document_t* pdf_document = (pdf_document_t*) document->data; PopplerIndexIter* iter = poppler_index_iter_new(pdf_document->document); - if(!iter) { + if (!iter) { // XXX: error message? return NULL; } @@ -166,7 +166,7 @@ pdf_document_index_generate(zathura_document_t* document) bool pdf_document_save_as(zathura_document_t* document, const char* path) { - if(!document || !document->data || !path) { + if (!document || !document->data || !path) { return false; } @@ -188,21 +188,21 @@ pdf_document_attachments_get(zathura_document_t* document) zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page) { - if(!document || !document->data) { + if (!document || !document->data) { return NULL; } pdf_document_t* pdf_document = (pdf_document_t*) document->data; zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); - if(!document_page) { + if (!document_page) { return NULL; } document_page->document = document; document_page->data = poppler_document_get_page(pdf_document->document, page); - if(!document_page->data) { + if (!document_page->data) { free(document_page); return NULL; } @@ -215,7 +215,7 @@ pdf_page_get(zathura_document_t* document, unsigned int page) bool pdf_page_free(zathura_page_t* page) { - if(!page) { + if (!page) { return false; } @@ -246,7 +246,7 @@ pdf_page_form_fields_get(zathura_page_t* page) GtkWidget* pdf_page_render(zathura_page_t* page) { - if(!Zathura.document || !page || !page->data || !page->document) { + if (!Zathura.document || !page || !page->data || !page->document) { return NULL; } @@ -254,7 +254,7 @@ pdf_page_render(zathura_page_t* page) unsigned int page_width = Zathura.document->scale * page->width; unsigned int page_height = Zathura.document->scale * page->height; - if(Zathura.document->rotate == 90 || Zathura.document->rotate == 270) { + if (Zathura.document->rotate == 90 || Zathura.document->rotate == 270) { unsigned int dim_temp = 0; dim_temp = page_width; page_width = page_height; @@ -265,7 +265,7 @@ pdf_page_render(zathura_page_t* page) GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, page_width, page_height); - if(!pixbuf) { + if (!pixbuf) { return NULL; } @@ -275,7 +275,7 @@ pdf_page_render(zathura_page_t* page) /* write pixbuf */ GtkWidget* image = gtk_image_new(); - if(!image) { + if (!image) { g_object_unref(pixbuf); return NULL; } diff --git a/render.c b/render.c index 1a6d893..4d4bdda 100644 --- a/render.c +++ b/render.c @@ -9,10 +9,10 @@ render_job(void* data) { render_thread_t* render_thread = (render_thread_t*) data; - while(true) { + while (true) { g_mutex_lock(render_thread->lock); - if(girara_list_size(render_thread->list) <= 0) { + if (girara_list_size(render_thread->list) <= 0) { g_cond_wait(render_thread->cond, render_thread->lock); } @@ -33,7 +33,7 @@ render_init(void) { render_thread_t* render_thread = malloc(sizeof(render_thread_t)); - if(!render_thread) { + if (!render_thread) { goto error_ret; } @@ -45,25 +45,25 @@ render_init(void) /* setup */ render_thread->list = girara_list_new(); - if(!render_thread->list) { + if (!render_thread->list) { goto error_free; } render_thread->thread = g_thread_create(render_job, render_thread, TRUE, NULL); - if(!render_thread->thread) { + if (!render_thread->thread) { goto error_free; } render_thread->cond = g_cond_new(); - if(!render_thread->cond) { + if (!render_thread->cond) { goto error_free; } render_thread->lock = g_mutex_new(); - if(!render_thread->lock) { + if (!render_thread->lock) { goto error_free; } @@ -71,15 +71,15 @@ render_init(void) error_free: - if(render_thread->list) { + if (render_thread->list) { girara_list_free(render_thread->list); } - if(render_thread->cond) { + if (render_thread->cond) { g_cond_free(render_thread->cond); } - if(render_thread->lock) { + if (render_thread->lock) { g_mutex_free(render_thread->lock); } @@ -93,19 +93,19 @@ error_ret: void render_free(render_thread_t* render_thread) { - if(!render_thread) { + if (!render_thread) { return; } - if(render_thread->list) { + if (render_thread->list) { girara_list_free(render_thread->list); } - if(render_thread->cond) { + if (render_thread->cond) { g_cond_free(render_thread->cond); } - if(render_thread->lock) { + if (render_thread->lock) { g_mutex_free(render_thread->lock); } } @@ -113,12 +113,12 @@ render_free(render_thread_t* render_thread) bool render_page(render_thread_t* render_thread, zathura_page_t* page) { - if(!render_thread || !page || !render_thread->list || page->rendered) { + if (!render_thread || !page || !render_thread->list || page->rendered) { return false; } g_mutex_lock(render_thread->lock); - if(!girara_list_contains(render_thread->list, page)) { + if (!girara_list_contains(render_thread->list, page)) { girara_list_append(render_thread->list, page); } g_cond_signal(render_thread->cond); @@ -133,7 +133,7 @@ render(zathura_page_t* page) g_static_mutex_lock(&(page->lock)); GtkWidget* image = zathura_page_render(page); - if(!image) { + if (!image) { g_static_mutex_unlock(&(page->lock)); printf("error: rendering failed\n"); return false; @@ -144,7 +144,7 @@ render(zathura_page_t* page) GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page->number); g_list_free(list); - if(!widget) { + if (!widget) { g_static_mutex_unlock(&(page->lock)); printf("error: page container does not exist\n"); g_object_unref(image); diff --git a/shortcuts.c b/shortcuts.c index 82cf482..8068938 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -44,11 +44,11 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) { g_return_val_if_fail(session != NULL, false); - if(!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) { + if (!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); } - if(argument->data) { + if (argument->data) { gtk_entry_set_text(session->gtk.inputbar, (char*) argument->data); gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar)); gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar), -1); @@ -72,16 +72,16 @@ sc_goto(girara_session_t* session, girara_argument_t* argument) bool sc_navigate(girara_session_t* session, girara_argument_t* argument) { - if(!session || !argument || !Zathura.document) { + if (!session || !argument || !Zathura.document) { return false; } unsigned int number_of_pages = Zathura.document->number_of_pages; unsigned int new_page = Zathura.document->current_page_number; - if(argument->n == NEXT) { + if (argument->n == NEXT) { new_page = (new_page + 1) % number_of_pages; - } else if(argument->n == PREVIOUS) { + } else if (argument->n == PREVIOUS) { new_page = (new_page + number_of_pages - 1) % number_of_pages; } @@ -112,7 +112,7 @@ bool sc_scroll(girara_session_t* session, girara_argument_t* argument) { GtkAdjustment* adjustment = NULL; - if( (argument->n == LEFT) || (argument->n == RIGHT) ) + if ( (argument->n == LEFT) || (argument->n == RIGHT) ) adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); else adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); diff --git a/utils.c b/utils.c index a5fafd8..1952735 100644 --- a/utils.c +++ b/utils.c @@ -14,7 +14,7 @@ bool file_exists(const char* path) { - if(!access(path, F_OK)) { + if (!access(path, F_OK)) { return true; } else { return false; @@ -24,21 +24,21 @@ file_exists(const char* path) const char* file_get_extension(const char* path) { - if(!path) { + if (!path) { return NULL; } unsigned int i = strlen(path); - for(; i > 0; i--) + for (; i > 0; i--) { - if(*(path + i) != '.') { + if (*(path + i) != '.') { continue; } else { break; } } - if(!i) { + if (!i) { return NULL; } @@ -48,24 +48,24 @@ file_get_extension(const char* path) bool execute_command(char* const argv[], char** output) { - if(!output) { + if (!output) { return false; } int p[2]; - if(pipe(p)) { + if (pipe(p)) { return -1; } pid_t pid = fork(); - if(pid == -1) { // failure + if (pid == -1) { // failure return false; - } else if(pid == 0) { // child + } else if (pid == 0) { // child dup2(p[1], 1); close(p[0]); - if(execvp(argv[0], argv) == -1) { + if (execvp(argv[0], argv) == -1) { return false; } } else { // parent @@ -78,20 +78,20 @@ execute_command(char* const argv[], char** output) char* buffer = malloc(sizeof(char) * bc); *output = NULL; - if(!buffer) { + if (!buffer) { close(p[0]); return false; } char c; - while(1 == read(p[0], &c, 1)) { + while (1 == read(p[0], &c, 1)) { buffer[i++] = c; - if(i == bc) { + if (i == bc) { bc += BLOCK_SIZE; char* tmp = realloc(buffer, sizeof(char) * bc); - if(!tmp) { + if (!tmp) { free(buffer); close(p[0]); return false; @@ -102,7 +102,7 @@ execute_command(char* const argv[], char** output) } char* tmp = realloc(buffer, sizeof(char) * (bc + 1)); - if(!tmp) { + if (!tmp) { free(buffer); close(p[0]); return false; @@ -124,31 +124,31 @@ execute_command(char* const argv[], char** output) GtkWidget* page_blank(unsigned int width, unsigned int height) { - if((width == 0) || (height == 0)) { + if ((width == 0) || (height == 0)) { return NULL; } guchar* buffer = malloc(sizeof(guchar) * (width * height * 1)); - if(!buffer) { + if (!buffer) { return NULL; } /* draw white */ - for(unsigned int i = 0; i < width * height; i++) { + for (unsigned int i = 0; i < width * height; i++) { buffer[i] = 255; } GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8, width, height, 1, NULL, NULL); - if(!pixbuf) { + if (!pixbuf) { free(buffer); return NULL; } /* convert to image */ GtkWidget* image = gtk_image_new(); - if(!image) { + if (!image) { free(buffer); g_object_unref(pixbuf); return false; diff --git a/zathura.c b/zathura.c index 9d92db7..4ed58b6 100644 --- a/zathura.c +++ b/zathura.c @@ -14,11 +14,11 @@ bool init_zathura() { /* UI */ - if(!(Zathura.UI.session = girara_session_create())) { + if (!(Zathura.UI.session = girara_session_create())) { goto error_out; } - if(!girara_session_init(Zathura.UI.session)) { + if (!girara_session_init(Zathura.UI.session)) { goto error_out; } @@ -29,7 +29,7 @@ init_zathura() /* page view */ Zathura.UI.page_view = gtk_vbox_new(FALSE, 0); - if(!Zathura.UI.page_view) { + if (!Zathura.UI.page_view) { goto error_free; } @@ -38,17 +38,17 @@ init_zathura() /* statusbar */ Zathura.UI.statusbar.file = girara_statusbar_item_add(Zathura.UI.session, TRUE, TRUE, TRUE, NULL); - if(!Zathura.UI.statusbar.file) { + if (!Zathura.UI.statusbar.file) { goto error_free; } Zathura.UI.statusbar.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); - if(!Zathura.UI.statusbar.buffer) { + if (!Zathura.UI.statusbar.buffer) { goto error_free; } 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) { goto error_free; } @@ -70,7 +70,7 @@ init_zathura() error_free: - if(Zathura.UI.page_view) { + if (Zathura.UI.page_view) { g_object_unref(Zathura.UI.page_view); } @@ -84,25 +84,25 @@ error_out: bool document_open(const char* path, const char* password) { - if(!path) { + if (!path) { goto error_out; } zathura_document_t* document = zathura_document_open(path, password); - if(!document) { + if (!document) { goto error_out; } Zathura.document = document; /* create blank pages */ - for(unsigned int i = 0; i < document->number_of_pages; i++) + for (unsigned int i = 0; i < document->number_of_pages; i++) { /* create blank page */ GtkWidget* image = page_blank(document->pages[i]->width, document->pages[i]->height); - if(!image) { + if (!image) { goto error_free; } @@ -115,12 +115,12 @@ document_open(const char* path, const char* password) /* threads */ Zathura.Sync.render_thread = render_init(); - if(!Zathura.Sync.render_thread) { + if (!Zathura.Sync.render_thread) { goto error_free; } /* first page */ - if(!page_set(0)) { + if (!page_set(0)) { goto error_free; } @@ -138,11 +138,11 @@ error_out: bool document_close() { - if(!Zathura.document) { + if (!Zathura.document) { return false; } - if(Zathura.Sync.render_thread) { + if (Zathura.Sync.render_thread) { render_free(Zathura.Sync.render_thread); } @@ -154,18 +154,18 @@ document_close() bool page_set(unsigned int page_id) { - if(!Zathura.document || !Zathura.document->pages) { + if (!Zathura.document || !Zathura.document->pages) { goto error_out; } - if(page_id >= Zathura.document->number_of_pages) { + if (page_id >= Zathura.document->number_of_pages) { goto error_out; } /* render page */ zathura_page_t* page = Zathura.document->pages[page_id]; - if(!page) { + if (!page) { goto error_out; } @@ -193,13 +193,13 @@ int main(int argc, char* argv[]) gdk_threads_init(); gtk_init(&argc, &argv); - if(!init_zathura()) { + if (!init_zathura()) { printf("error: coult not initialize zathura\n"); return -1; } - if(argc > 1) { - if(!document_open(argv[1], NULL)) { + if (argc > 1) { + if (!document_open(argv[1], NULL)) { printf("error: could not open document\n"); return -1; } From a97cda9176191364c403d7c5d004046a9944f2b9 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 9 Feb 2011 23:53:18 +0800 Subject: [PATCH 056/197] Update shortcuts function to girara interface --- shortcuts.c | 44 ++++++++++++++++++------------------- shortcuts.h | 63 +++++++++++++++++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 43 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index 8068938..d5bf8e1 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -8,7 +8,7 @@ #include "zathura.h" bool -sc_abort(girara_session_t* session, girara_argument_t* argument) +sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); @@ -18,19 +18,19 @@ sc_abort(girara_session_t* session, girara_argument_t* argument) } bool -sc_adjust_window(girara_session_t* session, girara_argument_t* argument) +sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_change_buffer(girara_session_t* session, girara_argument_t* argument) +sc_change_buffer(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_change_mode(girara_session_t* session, girara_argument_t* argument) +sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); @@ -40,7 +40,7 @@ sc_change_mode(girara_session_t* session, girara_argument_t* argument) } bool -sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) +sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); @@ -58,19 +58,19 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) } bool -sc_follow(girara_session_t* session, girara_argument_t* argument) +sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_goto(girara_session_t* session, girara_argument_t* argument) +sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_navigate(girara_session_t* session, girara_argument_t* argument) +sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int t) { if (!session || !argument || !Zathura.document) { return false; @@ -91,25 +91,25 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument) } bool -sc_recolor(girara_session_t* session, girara_argument_t* argument) +sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_reload(girara_session_t* session, girara_argument_t* argument) +sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_rotate(girara_session_t* session, girara_argument_t* argument) +sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_scroll(girara_session_t* session, girara_argument_t* argument) +sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t) { GtkAdjustment* adjustment = NULL; if ( (argument->n == LEFT) || (argument->n == RIGHT) ) @@ -161,52 +161,52 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument) } bool -sc_search(girara_session_t* session, girara_argument_t* argument) +sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument) +sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_navigate_index(girara_session_t* session, girara_argument_t* argument) +sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_toggle_index(girara_session_t* session, girara_argument_t* argument) +sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument) +sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument) +sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument) +sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } bool -sc_quit(girara_session_t* session, girara_argument_t* argument) +sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) { girara_argument_t arg = { GIRARA_HIDE, NULL }; - girara_isc_completion(session, &arg); + girara_isc_completion(session, &arg, 0); cb_destroy(NULL, NULL); @@ -216,7 +216,7 @@ sc_quit(girara_session_t* session, girara_argument_t* argument) } bool -sc_zoom(girara_session_t* session, girara_argument_t* argument) +sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) { return false; } diff --git a/shortcuts.h b/shortcuts.h index 88c21c9..78f87ef 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -10,188 +10,209 @@ * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_abort(girara_session_t* session, girara_argument_t* argument); +bool sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Adjust the rendered pages to the window * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument); +bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Modify the current buffer * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument); +bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Change the current mode * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_change_mode(girara_session_t* session, girara_argument_t* argument); +bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Focus the inputbar * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument); +bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Follow a link * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_follow(girara_session_t* session, girara_argument_t* argument); +bool sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Go to a specific page or position * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_goto(girara_session_t* session, girara_argument_t* argument); +bool sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Navigate through the document * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_navigate(girara_session_t* session, girara_argument_t* argument); +bool sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Recolor the pages * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_recolor(girara_session_t* session, girara_argument_t* argument); +bool sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Reload the current document * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_reload(girara_session_t* session, girara_argument_t* argument); +bool sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Rotate the pages * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_rotate(girara_session_t* session, girara_argument_t* argument); +bool sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Scroll through the pages * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_scroll(girara_session_t* session, girara_argument_t* argument); +bool sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Search through the document for the latest search item * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_search(girara_session_t* session, girara_argument_t* argument); +bool sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Switch go to mode (numeric, labels) * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument); +bool sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Navigate through the index of the document * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument); +bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Show/Hide the index of the document * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument); +bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Show/Hide the inputbar * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument); +bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Toggle fullscreen mode * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument); +bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Show/Hide the statusbar * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument); +bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Quit zathura * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_quit(girara_session_t* session, girara_argument_t* argument); +bool sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t); /** * Change the zoom level * * @param session The used girara session * @param argument The used argument + * @param t Number of executions * @return true if no error occured otherwise false */ -bool sc_zoom(girara_session_t* session, girara_argument_t* argument); +bool sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t); #endif // SHORTCUTS_H From 498a1c31e492cbc3ed206aff12ec53fda1ac27dd Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 10 Feb 2011 00:12:09 +0800 Subject: [PATCH 057/197] Experimental implementation of sc_goto --- config.c | 4 ++-- shortcuts.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index e305e52..702c8a6 100644 --- a/config.c +++ b/config.c @@ -30,8 +30,8 @@ config_load_default(void) girara_shortcut_add(Zathura.UI.session, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); girara_shortcut_add(Zathura.UI.session, 0, GDK_O, NULL, sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); girara_shortcut_add(Zathura.UI.session, 0, GDK_f, NULL, sc_follow, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "gg", sc_goto, NORMAL | FULLSCREEN, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "G", sc_goto, NORMAL | FULLSCREEN, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, 0, "gg", sc_goto, NORMAL | FULLSCREEN, TOP, NULL); + girara_shortcut_add(Zathura.UI.session, 0, 0, "G", sc_goto, NORMAL | FULLSCREEN, BOTTOM, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_J, NULL, sc_navigate, NORMAL, NEXT, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_K, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); girara_shortcut_add(Zathura.UI.session, GDK_MOD1_MASK, GDK_Right, NULL, sc_navigate, NORMAL, NEXT, NULL); diff --git a/shortcuts.c b/shortcuts.c index d5bf8e1..26bd6d5 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -66,6 +66,32 @@ sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t bool sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + if (!session || !argument) { + return false; + } + + if (argument->n == TOP) { + girara_argument_t arg = { TOP, NULL }; + sc_scroll(session, &arg, 0); + + return false; + } else { + if (t == 0) { + girara_argument_t arg = { BOTTOM, NULL }; + sc_scroll(session, &arg, 0); + + return true; + } + + unsigned int number_of_pages = Zathura.document->number_of_pages; + + if (t > 0 && t <= number_of_pages) { + GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + unsigned int offset = Zathura.document->pages[t - 1]->offset * Zathura.document->scale; + gtk_adjustment_set_value(adjustment, offset); + } + } + return false; } From dbb304af35e6ee919897fdd3a256efaaa6a05548 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 10 Feb 2011 04:28:36 +0800 Subject: [PATCH 058/197] Experimental implementation of sc_zoom --- config.c | 4 ++++ ft/document.c | 3 +-- render.c | 17 +++++++++++++++++ render.h | 8 ++++++++ shortcuts.c | 23 +++++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 702c8a6..d85d891 100644 --- a/config.c +++ b/config.c @@ -14,6 +14,10 @@ config_load_default(void) /* general settings */ girara_mode_set(Zathura.UI.session, NORMAL); + /* zathura settings */ + int int_value = 10; + girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + /* define default shortcuts */ girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL); diff --git a/ft/document.c b/ft/document.c index 98dd0ac..8b335dc 100644 --- a/ft/document.c +++ b/ft/document.c @@ -103,8 +103,7 @@ zathura_document_open(const char* path, const char* password) } double offset = 0; - for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) - { + for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_t* page = zathura_page_get(document, page_id); if (!page) { goto error_free; diff --git a/render.c b/render.c index 4d4bdda..d0ffbe9 100644 --- a/render.c +++ b/render.c @@ -174,3 +174,20 @@ render(zathura_page_t* page) return true; } + +void +render_all(void) +{ + if (Zathura.document == NULL) { + return; + } + + /* unmark all pages */ + for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) { + Zathura.document->pages[page_id]->rendered = false; + } + + /* redraw current page */ + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + cb_view_vadjustment_value_changed(view_vadjustment, NULL); +} diff --git a/render.h b/render.h index 29e2607..4e430ab 100644 --- a/render.h +++ b/render.h @@ -8,6 +8,7 @@ #include #include "ft/document.h" +#include "callbacks.h" typedef struct render_thread_s { @@ -41,4 +42,11 @@ void render_free(render_thread_t* render_thread); */ bool render_page(render_thread_t* render_thread, zathura_page_t* page); +/** + * This function is used to unmark all pages as not rendered. This should + * be used if all pages should be rendered again (e.g.: the zoom level or the + * colors have changed) + */ +void render_all(void); + #endif // RENDER_H diff --git a/shortcuts.c b/shortcuts.c index 26bd6d5..e077f64 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -6,6 +6,7 @@ #include "callbacks.h" #include "shortcuts.h" #include "zathura.h" +#include "render.h" bool sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) @@ -244,5 +245,27 @@ sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + if (session == NULL || argument == NULL) { + return false; + } + + /* retreive zoom step value */ + int* value = girara_setting_get(Zathura.UI.session, "zoom-step"); + if (value == NULL) { + return false; + } + + float zoom_step = *value / 100.0f; + + if (argument->n == ZOOM_IN) { + Zathura.document->scale += zoom_step; + } else if (argument->n == ZOOM_OUT) { + Zathura.document->scale -= zoom_step; + } else { + Zathura.document->scale = 1.0; + } + + render_all(); + return false; } From 9c27ab49e8d613631aa1f82207b59d83efee7069 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 10 Feb 2011 10:06:13 +0800 Subject: [PATCH 059/197] Implemented sc_toggle_fullscreen --- config.c | 1 - shortcuts.c | 20 ++++++++++++++------ shortcuts.h | 10 ---------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/config.c b/config.c index d85d891..a93af7b 100644 --- a/config.c +++ b/config.c @@ -68,7 +68,6 @@ config_load_default(void) girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_n, NULL, sc_search, NORMAL, FORWARD, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_N, NULL, sc_search, NORMAL, BACKWARD, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_0, NULL, sc_switch_goto_mode, NORMAL, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_Tab, NULL, sc_toggle_index, NORMAL | INDEX, 0, NULL); girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_m, NULL, sc_toggle_inputbar, NORMAL, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_F5, NULL, sc_toggle_fullscreen, NORMAL | FULLSCREEN, 0, NULL); diff --git a/shortcuts.c b/shortcuts.c index e077f64..d577a30 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -193,12 +193,6 @@ sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int t return false; } -bool -sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) -{ - return false; -} - bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) { @@ -220,6 +214,20 @@ sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsig bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + if (session == NULL) { + return false; + } + + static bool fullscreen = false; + + if (fullscreen) { + gtk_window_unfullscreen(GTK_WINDOW(session->gtk.window)); + } else { + gtk_window_fullscreen(GTK_WINDOW(session->gtk.window)); + } + + fullscreen = fullscreen ? false : true; + return false; } diff --git a/shortcuts.h b/shortcuts.h index 78f87ef..b920f87 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -135,16 +135,6 @@ bool sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned */ bool sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int t); -/** - * Switch go to mode (numeric, labels) - * - * @param session The used girara session - * @param argument The used argument - * @param t Number of executions - * @return true if no error occured otherwise false - */ -bool sc_switch_goto_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t); - /** * Navigate through the index of the document * From c41f945994e7da4c8695b14bdcf7de07eebf2f7e Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 10 Feb 2011 10:10:58 +0800 Subject: [PATCH 060/197] Implemented toggle inputbar/statusbar --- shortcuts.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/shortcuts.c b/shortcuts.c index d577a30..55e1398 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -208,6 +208,15 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + if (session == NULL) { + return false; + } + + if(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar))) + gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar)); + else + gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); + return false; } @@ -234,6 +243,15 @@ sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, uns bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + if (session == NULL) { + return false; + } + + if(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.statusbar))) + gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar)); + else + gtk_widget_show(GTK_WIDGET(session->gtk.statusbar)); + return false; } From 31027cbaad067ee90297aeba0add2fe2800f016f Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 10 Feb 2011 11:33:28 +0800 Subject: [PATCH 061/197] Began to implement the index view --- ft/document.c | 6 ---- ft/document.h | 1 - ft/pdf/pdf.c | 16 ++++----- shortcuts.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++---- utils.c | 15 +++++++- utils.h | 11 ++++++ zathura.c | 1 + zathura.h | 1 + 8 files changed, 127 insertions(+), 23 deletions(-) diff --git a/ft/document.c b/ft/document.c index 8b335dc..e672257 100644 --- a/ft/document.c +++ b/ft/document.c @@ -214,12 +214,6 @@ zathura_document_index_generate(zathura_document_t* document) return document->functions.document_index_generate(document); } -bool -zathura_document_index_free(zathura_list_t* list) -{ - return false; -} - zathura_list_t* zathura_document_attachments_get(zathura_document_t* document) { diff --git a/ft/document.h b/ft/document.h index 52b09f7..725c8e8 100644 --- a/ft/document.h +++ b/ft/document.h @@ -117,7 +117,6 @@ zathura_document_t* zathura_document_open(const char* path, const char* password bool zathura_document_free(zathura_document_t* document); bool zathura_document_save_as(zathura_document_t* document, const char* path); girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document); -bool zathura_document_index_free(zathura_list_t* list); zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); bool zathura_document_attachments_free(zathura_list_t* list); diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 6147d9c..b4adf36 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -103,32 +103,32 @@ build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* ite } gchar* markup = g_markup_escape_text(action->any.title, -1); - zathura_index_element_t* indexelement = zathura_index_element_new(markup); + zathura_index_element_t* index_element = zathura_index_element_new(markup); if (action->type == POPPLER_ACTION_URI) { - indexelement->type = ZATHURA_LINK_EXTERNAL; - indexelement->target.uri = g_strdup(action->uri.uri); + index_element->type = ZATHURA_LINK_EXTERNAL; + index_element->target.uri = g_strdup(action->uri.uri); } else if (action->type == POPPLER_ACTION_GOTO_DEST) { - indexelement->type = ZATHURA_LINK_TO_PAGE; + index_element->type = ZATHURA_LINK_TO_PAGE; if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) { PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest); if (dest) { - indexelement->target.page_number = dest->page_num - 1; + index_element->target.page_number = dest->page_num - 1; poppler_dest_free(dest); } } else { - indexelement->target.page_number = action->goto_dest.dest->page_num - 1; + index_element->target.page_number = action->goto_dest.dest->page_num - 1; } } else { poppler_action_free(action); - zathura_index_element_free(indexelement); + zathura_index_element_free(index_element); continue; } poppler_action_free(action); - girara_tree_node_t* node = girara_node_append_data(root, indexelement); + girara_tree_node_t* node = girara_node_append_data(root, index_element); PopplerIndexIter* child = poppler_index_iter_get_child(iter); if (child) { diff --git a/shortcuts.c b/shortcuts.c index 55e1398..3a4115b 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -7,6 +7,7 @@ #include "shortcuts.h" #include "zathura.h" #include "render.h" +#include "utils.h" bool sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) @@ -67,7 +68,7 @@ sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t bool sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (!session || !argument) { + if (session == NULL || argument == NULL || Zathura.document == NULL) { return false; } @@ -99,7 +100,7 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (!session || !argument || !Zathura.document) { + if (session == NULL || argument == NULL || Zathura.document == NULL) { return false; } @@ -202,6 +203,88 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsign bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + if (session == NULL || Zathura.document == NULL) { + return false; + } + + girara_tree_node_t* document_index = NULL; + GtkWidget* treeview = NULL; + GtkTreeModel* model = NULL; + GtkCellRenderer* renderer = NULL; + + if (Zathura.UI.index == NULL) { + /* create new index widget */ + Zathura.UI.index = gtk_scrolled_window_new(NULL, NULL); + + if (Zathura.UI.index == NULL) { + goto error_ret; + } + + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.index), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + /* create index */ + document_index = zathura_document_index_generate(Zathura.document); + if (document_index == NULL) { + // TODO: Error message + goto error_free; + } + + model = GTK_TREE_MODEL(gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER)); + if (model == NULL) { + goto error_free; + } + + treeview = gtk_tree_view_new_with_model(model); + if (treeview == NULL) { + goto error_free; + } + + g_object_unref(model); + + renderer = gtk_cell_renderer_text_new(); + if (renderer == NULL) { + goto error_free; + } + + document_index_build(model, NULL, document_index); + girara_node_free(document_index); + + /* setup widget */ + gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 0, "Title", renderer, "markup", 0, NULL); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); + g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); + g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL); + gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE); + /*g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), NULL); TODO*/ + + gtk_container_add(GTK_CONTAINER(Zathura.UI.index), treeview); + gtk_widget_show(treeview); + } + + if (GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.index))) { + girara_set_view(session, Zathura.UI.page_view); + gtk_widget_hide(GTK_WIDGET(Zathura.UI.index)); + } else { + girara_set_view(session, Zathura.UI.index); + gtk_widget_show(GTK_WIDGET(Zathura.UI.index)); + } + + return false; + +error_free: + + if (Zathura.UI.index != NULL) { + g_object_unref(Zathura.UI.index); + Zathura.UI.index = NULL; + } + + if (document_index != NULL) { + girara_node_free(document_index); + } + +error_ret: + return false; } @@ -212,10 +295,11 @@ sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsig return false; } - if(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar))) + if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar))) { gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar)); - else + } else { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); + } return false; } @@ -247,10 +331,11 @@ sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsi return false; } - if(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.statusbar))) + if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.statusbar))) { gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar)); - else + } else { gtk_widget_show(GTK_WIDGET(session->gtk.statusbar)); + } return false; } @@ -271,7 +356,7 @@ sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || argument == NULL) { + if (session == NULL || argument == NULL || Zathura.document == NULL) { return false; } diff --git a/utils.c b/utils.c index 1952735..81b3c2e 100644 --- a/utils.c +++ b/utils.c @@ -8,6 +8,7 @@ #include #include "utils.h" +#include "zathura.h" #define BLOCK_SIZE 64 @@ -157,8 +158,20 @@ page_blank(unsigned int width, unsigned int height) gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); gtk_widget_show(image); - /*free(buffer);*/ + /*free(buffer);*/ // XXX: Read documentation g_object_unref(pixbuf); return image; } + +void +document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree) +{ + girara_list_t* list = girara_node_get_children(tree); + girara_list_iterator_t* it = girara_list_iterator(list); + + do { + zathura_index_element_t* index_element = (zathura_index_element_t*) girara_list_iterator_data(it); + printf("%s\n", index_element->title); + } while ((it = girara_list_iterator_next(it))); +} diff --git a/utils.h b/utils.h index 66401d4..02c33f9 100644 --- a/utils.h +++ b/utils.h @@ -5,6 +5,7 @@ #include #include +#include /** * Checks if the given file exists @@ -40,4 +41,14 @@ bool execute_command(char* const argv[], char** output); */ GtkWidget* page_blank(unsigned int width, unsigned int height); +/** + * Generates the document index based upon the list retreived from the document + * object. + * + * @param model The tree model + * @param tree_it The Tree iterator + * @param list_it The index list iterator + */ +void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree); + #endif // UTILS_H diff --git a/zathura.c b/zathura.c index 4ed58b6..26bedde 100644 --- a/zathura.c +++ b/zathura.c @@ -26,6 +26,7 @@ init_zathura() Zathura.UI.statusbar.buffer = NULL; Zathura.UI.statusbar.page_number = NULL; Zathura.UI.page_view = NULL; + Zathura.UI.index = NULL; /* page view */ Zathura.UI.page_view = gtk_vbox_new(FALSE, 0); diff --git a/zathura.h b/zathura.h index e857ac0..7b283c5 100644 --- a/zathura.h +++ b/zathura.h @@ -38,6 +38,7 @@ struct } statusbar; GtkWidget *page_view; /**> Widget that contains all rendered pages */ + GtkWidget *index; /**> Widget to show the index of the document */ } UI; struct From f9c51655cfa7bb27b819d4f3a6273ef330e8f2e0 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 26 Feb 2011 11:15:50 +0800 Subject: [PATCH 062/197] Began to use mupdf instead of poppler --- config.mk | 2 +- ft/pdf/pdf.c | 227 ++++++++++++++++++++------------------------------- ft/pdf/pdf.h | 15 ++-- 3 files changed, 101 insertions(+), 143 deletions(-) diff --git a/config.mk b/config.mk index fbb9fd4..7092e2e 100644 --- a/config.mk +++ b/config.mk @@ -12,7 +12,7 @@ GTK_INC = $(shell pkg-config --cflags gtk+-2.0 poppler-glib ddjvuapi) GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0 poppler-glib ddjvuapi) INCS = -I. -I/usr/include ${GTK_INC} -LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara +LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara -lmupdf -ljbig2dec # flags CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index b4adf36..0f79cd3 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -1,7 +1,6 @@ /* See LICENSE file for license and copyright information */ #include -#include #include "pdf.h" #include "../../zathura.h" @@ -10,13 +9,10 @@ bool pdf_document_open(zathura_document_t* document) { if (!document) { - goto error_out; + goto error_ret; } document->functions.document_free = pdf_document_free; - document->functions.document_index_generate = pdf_document_index_generate;; - document->functions.document_save_as = pdf_document_save_as; - document->functions.document_attachments_get = pdf_document_attachments_get; document->functions.page_get = pdf_page_get; document->functions.page_search_text = pdf_page_search_text; document->functions.page_links_get = pdf_page_links_get; @@ -26,46 +22,42 @@ pdf_document_open(zathura_document_t* document) document->data = malloc(sizeof(pdf_document_t)); if (!document->data) { - goto error_out; - } - - /* format path */ - GError* error = NULL; - char* file_uri = g_filename_to_uri(document->file_path, NULL, &error); - - if (!file_uri) { - fprintf(stderr, "error: could not open file: %s\n", error->message); - goto error_free; + goto error_ret; } pdf_document_t* pdf_document = (pdf_document_t*) document->data; - pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error); - if (!pdf_document->document) { - fprintf(stderr, "error: could not open file: %s\n", error->message); + fz_accelerate(); + pdf_document->glyphcache = fz_newglyphcache(); + + if (pdf_openxref(&(pdf_document->document), document->file_path, NULL)) { + fprintf(stderr, "error: could not open file\n"); goto error_free; } - document->number_of_pages = poppler_document_get_n_pages(pdf_document->document); + if (pdf_loadpagetree(pdf_document->document)) { + fprintf(stderr, "error: could not open file\n"); + goto error_free; + } - g_free(file_uri); + document->number_of_pages = pdf_getpagecount(pdf_document->document); return true; error_free: - if (error) { - g_error_free(error); - } + if (pdf_document->document) { + pdf_freexref(pdf_document->document); + } - if (file_uri) { - g_free(file_uri); - } + if (pdf_document->glyphcache) { + fz_freeglyphcache(pdf_document->glyphcache); + } - free(document->data); - document->data = NULL; + free(document->data); + document->data = NULL; -error_out: +error_ret: return false; } @@ -79,7 +71,8 @@ pdf_document_free(zathura_document_t* document) if (document->data) { pdf_document_t* pdf_document = (pdf_document_t*) document->data; - g_object_unref(pdf_document->document); + pdf_freexref(pdf_document->document); + fz_freeglyphcache(pdf_document->glyphcache); free(document->data); document->data = NULL; } @@ -87,104 +80,6 @@ pdf_document_free(zathura_document_t* document) return true; } -static void -build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* iter) -{ - if (!root || !iter) { - return; - } - - do - { - PopplerAction* action = poppler_index_iter_get_action(iter); - - if (!action) { - continue; - } - - gchar* markup = g_markup_escape_text(action->any.title, -1); - zathura_index_element_t* index_element = zathura_index_element_new(markup); - - if (action->type == POPPLER_ACTION_URI) { - index_element->type = ZATHURA_LINK_EXTERNAL; - index_element->target.uri = g_strdup(action->uri.uri); - } else if (action->type == POPPLER_ACTION_GOTO_DEST) { - index_element->type = ZATHURA_LINK_TO_PAGE; - - if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) { - PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest); - if (dest) { - index_element->target.page_number = dest->page_num - 1; - poppler_dest_free(dest); - } - } else { - index_element->target.page_number = action->goto_dest.dest->page_num - 1; - } - } else { - poppler_action_free(action); - zathura_index_element_free(index_element); - continue; - } - - poppler_action_free(action); - - girara_tree_node_t* node = girara_node_append_data(root, index_element); - PopplerIndexIter* child = poppler_index_iter_get_child(iter); - - if (child) { - build_index(pdf, node, child); - } - - poppler_index_iter_free(child); - - } while (poppler_index_iter_next(iter)); -} - -girara_tree_node_t* -pdf_document_index_generate(zathura_document_t* document) -{ - if (!document || !document->data) { - return NULL; - } - - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - PopplerIndexIter* iter = poppler_index_iter_new(pdf_document->document); - - if (!iter) { - // XXX: error message? - return NULL; - } - - girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); - girara_node_set_free_function(root, (girara_free_function_t)zathura_index_element_free); - build_index(pdf_document, root, iter); - - poppler_index_iter_free(iter); - return root; -} - -bool -pdf_document_save_as(zathura_document_t* document, const char* path) -{ - if (!document || !document->data || !path) { - return false; - } - - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - - char* file_path = g_strdup_printf("file://%s", path); - poppler_document_save(pdf_document->document, file_path, NULL); - g_free(file_path); - - return false; -} - -zathura_list_t* -pdf_document_attachments_get(zathura_document_t* document) -{ - return NULL; -} - zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page) { @@ -195,21 +90,38 @@ pdf_page_get(zathura_document_t* document, unsigned int page) pdf_document_t* pdf_document = (pdf_document_t*) document->data; zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); - if (!document_page) { - return NULL; + if (document_page == NULL) { + goto error_ret; + } + + mupdf_page_t* mupdf_page = malloc(sizeof(mupdf_page_t)); + + if (mupdf_page == NULL) { + goto error_free; } document_page->document = document; - document_page->data = poppler_document_get_page(pdf_document->document, page); + document_page->data = mupdf_page; - if (!document_page->data) { - free(document_page); - return NULL; + mupdf_page->page_object = pdf_getpageobject(pdf_document->document, page + 1); + + if (pdf_loadpage(&(mupdf_page->page), pdf_document->document, mupdf_page->page_object)) { + goto error_free; } - poppler_page_get_size(document_page->data, &(document_page->width), &(document_page->height)); + document_page->width = mupdf_page->page->mediabox.x1 - mupdf_page->page->mediabox.x0; + document_page->height = mupdf_page->page->mediabox.y1 - mupdf_page->page->mediabox.y0; return document_page; + +error_free: + + free(document_page); + free(mupdf_page); + +error_ret: + + return NULL; } bool @@ -269,8 +181,49 @@ pdf_page_render(zathura_page_t* page) return NULL; } - poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, Zathura.document->scale, - Zathura.document->rotate, pixbuf); + pdf_document_t* pdf_document = (pdf_document_t*) page->document->data; + mupdf_page_t* mupdf_page = (mupdf_page_t*) page->data; + + /* render */ + fz_displaylist* list = fz_newdisplaylist(); + fz_device* dev = fz_newlistdevice(list); + + if (pdf_runpage(pdf_document->document, mupdf_page->page, dev, fz_identity)) { + return NULL; + } + + fz_freedevice(dev); + + fz_matrix ctm = fz_translate(0, -mupdf_page->page->mediabox.y1); + ctm = fz_concat(ctm, fz_scale(Zathura.document->scale, -Zathura.document->scale)); + + fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); + + guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); + int rowstride = gdk_pixbuf_get_rowstride(pixbuf); + int n_channels = gdk_pixbuf_get_n_channels(pixbuf); + + fz_pixmap* pix = fz_newpixmapwithrect(fz_devicergb, bbox); + fz_clearpixmap(pix, 0xff); + + dev = fz_newdrawdevice(pdf_document->glyphcache, pix); + fz_executedisplaylist(list, dev, ctm); + fz_freedevice(dev); + + for (unsigned int y = 0; y < pix->h; y++) { + for (unsigned int x = 0; x < pix->w; x++) { + unsigned char *s = pix->samples + y * pix->w * 4 + x * 4; + guchar* p = pixels + y * rowstride + x * n_channels; + p[0] = s[0]; + p[1] = s[1]; + p[2] = s[2]; + } + } + + fz_droppixmap(pix); + fz_freedisplaylist(list); + pdf_freepage(mupdf_page->page); + pdf_agestore(pdf_document->document->store, 3); /* write pixbuf */ GtkWidget* image = gtk_image_new(); diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h index 39afbe0..73871a7 100644 --- a/ft/pdf/pdf.h +++ b/ft/pdf/pdf.h @@ -4,20 +4,25 @@ #define PDF_H #include -#include +#include +#include #include "../document.h" typedef struct pdf_document_s { - PopplerDocument *document; + fz_glyphcache *glyphcache; + pdf_xref *document; } pdf_document_t; +typedef struct mupdf_page_s +{ + fz_obj* page_object; + pdf_page* page; +} mupdf_page_t; + bool pdf_document_open(zathura_document_t* document); bool pdf_document_free(zathura_document_t* document); -girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document); -bool pdf_document_save_as(zathura_document_t* document, const char* path); -zathura_list_t* pdf_document_attachments_get(zathura_document_t* document); zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* pdf_page_links_get(zathura_page_t* page); From 890280ba23c43d29a7288839ca547d1ccc061745 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 27 Feb 2011 08:19:26 +0800 Subject: [PATCH 063/197] Update page_free --- ft/pdf/pdf.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index 0f79cd3..44e730e 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -116,6 +116,14 @@ pdf_page_get(zathura_document_t* document, unsigned int page) error_free: + if (mupdf_page && mupdf_page->page_object) { + fz_dropobj(mupdf_page->page_object); + } + + if (mupdf_page && mupdf_page->page) { + pdf_freepage(mupdf_page->page); + } + free(document_page); free(mupdf_page); @@ -131,7 +139,10 @@ pdf_page_free(zathura_page_t* page) return false; } - g_object_unref(page->data); + mupdf_page_t* mupdf_page = (mupdf_page_t*) page->data; + pdf_freepage(mupdf_page->page); + fz_dropobj(mupdf_page->page_object); + free(mupdf_page); free(page); return true; @@ -182,37 +193,36 @@ pdf_page_render(zathura_page_t* page) } pdf_document_t* pdf_document = (pdf_document_t*) page->document->data; - mupdf_page_t* mupdf_page = (mupdf_page_t*) page->data; + mupdf_page_t* mupdf_page = (mupdf_page_t*) page->data; /* render */ - fz_displaylist* list = fz_newdisplaylist(); - fz_device* dev = fz_newlistdevice(list); + fz_displaylist* display_list = fz_newdisplaylist(); + fz_device* device = fz_newlistdevice(display_list); - if (pdf_runpage(pdf_document->document, mupdf_page->page, dev, fz_identity)) { + if (pdf_runpage(pdf_document->document, mupdf_page->page, device, fz_identity)) { return NULL; } - fz_freedevice(dev); + fz_freedevice(device); fz_matrix ctm = fz_translate(0, -mupdf_page->page->mediabox.y1); - ctm = fz_concat(ctm, fz_scale(Zathura.document->scale, -Zathura.document->scale)); - - fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); + ctm = fz_concat(ctm, fz_scale(Zathura.document->scale, -Zathura.document->scale)); + fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); int rowstride = gdk_pixbuf_get_rowstride(pixbuf); int n_channels = gdk_pixbuf_get_n_channels(pixbuf); - fz_pixmap* pix = fz_newpixmapwithrect(fz_devicergb, bbox); - fz_clearpixmap(pix, 0xff); + fz_pixmap* pixmap = fz_newpixmapwithrect(fz_devicergb, bbox); + fz_clearpixmap(pixmap, 0xFF); - dev = fz_newdrawdevice(pdf_document->glyphcache, pix); - fz_executedisplaylist(list, dev, ctm); - fz_freedevice(dev); + device = fz_newdrawdevice(pdf_document->glyphcache, pixmap); + fz_executedisplaylist(display_list, device, ctm); + fz_freedevice(device); - for (unsigned int y = 0; y < pix->h; y++) { - for (unsigned int x = 0; x < pix->w; x++) { - unsigned char *s = pix->samples + y * pix->w * 4 + x * 4; + for (unsigned int y = 0; y < pixmap->h; y++) { + for (unsigned int x = 0; x < pixmap->w; x++) { + unsigned char *s = pixmap->samples + y * pixmap->w * 4 + x * 4; guchar* p = pixels + y * rowstride + x * n_channels; p[0] = s[0]; p[1] = s[1]; @@ -220,8 +230,8 @@ pdf_page_render(zathura_page_t* page) } } - fz_droppixmap(pix); - fz_freedisplaylist(list); + fz_droppixmap(pixmap); + fz_freedisplaylist(display_list); pdf_freepage(mupdf_page->page); pdf_agestore(pdf_document->document->store, 3); From ef3944421b0dfe6f7420169c103f4f9ad78fe6d0 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 28 Feb 2011 11:27:03 +0800 Subject: [PATCH 064/197] Surround render call by tenter/tleave --- render.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/render.c b/render.c index d0ffbe9..f863ae7 100644 --- a/render.c +++ b/render.c @@ -20,9 +20,10 @@ render_job(void* data) girara_list_remove(render_thread->list, page); g_mutex_unlock(render_thread->lock); - printf("Rendered %d\n", page->number); - + gdk_threads_enter(); render(page); + printf("Rendered %d\n", page->number); + gdk_threads_leave(); } return NULL; From 7629a30a2722136953ece994d006ee35d6a245c5 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 5 Mar 2011 19:46:05 +0100 Subject: [PATCH 065/197] Register document plugin and free registered plugins --- Makefile | 2 +- callbacks.c | 5 ++- ft/document.c => document.c | 81 +++++++++++++++++++++++++++++++------ ft/document.h => document.h | 6 ++- ft/djvu/djvu.h | 2 +- ft/pdf/pdf.h | 2 +- render.h | 2 +- zathura.c | 2 +- zathura.h | 2 +- 9 files changed, 83 insertions(+), 21 deletions(-) rename ft/document.c => document.c (82%) rename ft/document.h => document.h (94%) diff --git a/Makefile b/Makefile index 408d01d..c3efd9d 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include config.mk PROJECT = zathura -SOURCE = $(shell find . -iname "*.c" -a ! -iwholename "*./doc*") +SOURCE = $(shell find . -iname "*.c" -a ! -iwholename "*./doc*|*./ft*") OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) diff --git a/callbacks.c b/callbacks.c index fd1c1a0..66c166b 100644 --- a/callbacks.c +++ b/callbacks.c @@ -7,7 +7,7 @@ #include "zathura.h" #include "render.h" -#include "ft/document.h" +#include "document.h" gboolean cb_destroy(GtkWidget* widget, gpointer data) @@ -18,6 +18,9 @@ cb_destroy(GtkWidget* widget, gpointer data) document_close(); + /* free registered plugins */ + zathura_document_plugin_free(); + return TRUE; } diff --git a/ft/document.c b/document.c similarity index 82% rename from ft/document.c rename to document.c index e672257..3fa9d5d 100644 --- a/ft/document.c +++ b/document.c @@ -10,17 +10,70 @@ #include #include "document.h" -#include "pdf/pdf.h" -#include "djvu/djvu.h" -#include "../utils.h" -#include "../zathura.h" +#include "utils.h" +#include "zathura.h" #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) -zathura_document_plugin_t zathura_document_plugins[] = { - { "pdf", pdf_document_open }, - { "djvu", djvu_document_open }, -}; +zathura_document_plugin_t* zathura_document_plugins = NULL; + +bool +zathura_document_register_plugin(char* file_extension, zathura_document_open_t open_function) +{ + if( (file_extension == NULL) || (open_function == NULL) ) { + fprintf(stderr, "plugin: could not register\n"); + return false; + } + + /* search existing plugins */ + zathura_document_plugin_t* plugin = zathura_document_plugins; + while (plugin) { + if (!strcmp(plugin->file_extension, file_extension)) { + fprintf(stderr, "plugin: already registered for filetype %s\n", file_extension); + return false; + } + + if (plugin->next == NULL) { + break; + } + + plugin = plugin->next; + } + + /* create new plugin */ + zathura_document_plugin_t* new_plugin = malloc(sizeof(zathura_document_plugin_t)); + + if (new_plugin == NULL) { + return false; + } + + new_plugin->file_extension = file_extension; + new_plugin->open_function = open_function; + new_plugin->next = NULL; + + /* append to list */ + if (plugin == NULL) { + zathura_document_plugins = new_plugin; + } else { + plugin->next = new_plugin; + } + + return true; +} + +void +zathura_document_plugin_free(void) +{ + /* free registered plugins */ + zathura_document_plugin_t* plugin = zathura_document_plugins; + while (plugin) { + zathura_document_plugin_t* tmp = plugin->next; + free(plugin); + plugin = tmp; + } + + zathura_document_plugins = NULL; +} zathura_document_t* zathura_document_open(const char* path, const char* password) @@ -88,11 +141,11 @@ zathura_document_open(const char* path, const char* password) document->functions.page_render = NULL; /* init plugin with associated file type */ - for (unsigned int i = 0; i < LENGTH(zathura_document_plugins); i++) - { - if (!strcmp(file_extension, zathura_document_plugins[i].file_extension)) { - if (zathura_document_plugins[i].open_function) { - if (zathura_document_plugins[i].open_function(document)) { + zathura_document_plugin_t* plugin = zathura_document_plugins; + while (plugin) { + if (!strcmp(file_extension, plugin->file_extension)) { + if (plugin->open_function) { + if (plugin->open_function(document)) { /* update statusbar */ girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, real_path); @@ -122,6 +175,8 @@ zathura_document_open(const char* path, const char* password) } } } + + plugin = plugin->next; } fprintf(stderr, "error: unknown file type\n"); diff --git a/ft/document.h b/document.h similarity index 94% rename from ft/document.h rename to document.h index 725c8e8..b8e03d3 100644 --- a/ft/document.h +++ b/document.h @@ -15,8 +15,9 @@ typedef bool (*zathura_document_open_t)(zathura_document_t* document); typedef struct zathura_document_plugin_s { - const char* file_extension; + char* file_extension; zathura_document_open_t open_function; + struct zathura_document_plugin_s *next; } zathura_document_plugin_t; struct zathura_list_s @@ -113,6 +114,9 @@ struct zathura_document_s zathura_page_t** pages; }; +bool zathura_document_plugin_register(char* file_extension, zathura_document_open_t open_function); +void zathura_document_plugin_free(void); + zathura_document_t* zathura_document_open(const char* path, const char* password); bool zathura_document_free(zathura_document_t* document); bool zathura_document_save_as(zathura_document_t* document, const char* path); diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h index 5f6d894..f043f69 100644 --- a/ft/djvu/djvu.h +++ b/ft/djvu/djvu.h @@ -6,7 +6,7 @@ #include #include -#include "../document.h" +#include "../../document.h" typedef struct djvu_document_s { diff --git a/ft/pdf/pdf.h b/ft/pdf/pdf.h index 39afbe0..5b959d0 100644 --- a/ft/pdf/pdf.h +++ b/ft/pdf/pdf.h @@ -6,7 +6,7 @@ #include #include -#include "../document.h" +#include "../../document.h" typedef struct pdf_document_s { diff --git a/render.h b/render.h index 4e430ab..1f48f95 100644 --- a/render.h +++ b/render.h @@ -7,7 +7,7 @@ #include #include -#include "ft/document.h" +#include "document.h" #include "callbacks.h" typedef struct render_thread_s diff --git a/zathura.c b/zathura.c index 26bedde..7295957 100644 --- a/zathura.c +++ b/zathura.c @@ -4,7 +4,7 @@ #include "callbacks.h" #include "config.h" -#include "ft/document.h" +#include "document.h" #include "shortcuts.h" #include "zathura.h" #include "utils.h" diff --git a/zathura.h b/zathura.h index 7b283c5..2002e27 100644 --- a/zathura.h +++ b/zathura.h @@ -7,7 +7,7 @@ #include #include -#include "ft/document.h" +#include "document.h" enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, DELETE_LAST_WORD, DELETE_LAST_CHAR, DEFAULT, ERROR, WARNING, NEXT_GROUP, From 52377b994dfe934ed6ecbae5911fcc13ed1dd712 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 5 Mar 2011 21:00:41 +0100 Subject: [PATCH 066/197] Plugin register mechanism --- callbacks.c | 2 +- config.mk | 2 +- document.c | 87 ++++++++++++++++++++++++++++++++++++++++++++--------- document.h | 8 ++++- utils.c | 58 +++++++++++++++++++++++++++++++++++ utils.h | 10 ++++++ zathura.c | 3 ++ 7 files changed, 153 insertions(+), 17 deletions(-) diff --git a/callbacks.c b/callbacks.c index 66c166b..d8384bf 100644 --- a/callbacks.c +++ b/callbacks.c @@ -19,7 +19,7 @@ cb_destroy(GtkWidget* widget, gpointer data) document_close(); /* free registered plugins */ - zathura_document_plugin_free(); + zathura_document_plugins_free(); return TRUE; } diff --git a/config.mk b/config.mk index fbb9fd4..a6a4747 100644 --- a/config.mk +++ b/config.mk @@ -12,7 +12,7 @@ GTK_INC = $(shell pkg-config --cflags gtk+-2.0 poppler-glib ddjvuapi) GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0 poppler-glib ddjvuapi) INCS = -I. -I/usr/include ${GTK_INC} -LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara +LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara -ldl # flags CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) diff --git a/document.c b/document.c index 3fa9d5d..72e8851 100644 --- a/document.c +++ b/document.c @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include #include "document.h" #include "utils.h" @@ -17,6 +20,76 @@ zathura_document_plugin_t* zathura_document_plugins = NULL; +void +zathura_document_plugins_load(void) +{ + /* read all files in the plugin directory */ + DIR* dir = opendir(PLUGIN_DIR); + if (dir == NULL) { + fprintf(stderr, "error: could not open plugin directory: %s\n", PLUGIN_DIR); + return; + } + + struct dirent* entry; + while ((entry = readdir(dir)) != NULL) { + /* check if entry is a file */ + if (entry->d_type == 0x8) { + /* get full path */ + char* path = string_concat(PLUGIN_DIR, "/", entry->d_name, NULL); + + if (path == NULL) { + continue; + } + + /* load plugin */ + void* handle = dlopen(path, RTLD_NOW); + free(path); + + if (handle == NULL) { + fprintf(stderr, "error: could not load plugin (%s)\n", dlerror()); + continue; + } + + /* resolve symbol */ + zathura_plugin_register_service_t register_plugin; + *(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION); + + if (register_plugin == NULL) { + fprintf(stderr, "error: could not find '%s' function in the plugin\n", PLUGIN_REGISTER_FUNCTION); + dlclose(handle); + continue; + } + + bool r = register_plugin(); + + if (r == false) { + fprintf(stderr, "error: could not register plugin\n"); + } + + dlclose(handle); + } + } + + if (closedir(dir) == -1) { + fprintf(stderr, "error: could not close plugin directory: %s\n", PLUGIN_DIR); + } + +} + +void +zathura_document_plugins_free(void) +{ + /* free registered plugins */ + zathura_document_plugin_t* plugin = zathura_document_plugins; + while (plugin) { + zathura_document_plugin_t* tmp = plugin->next; + free(plugin); + plugin = tmp; + } + + zathura_document_plugins = NULL; +} + bool zathura_document_register_plugin(char* file_extension, zathura_document_open_t open_function) { @@ -61,20 +134,6 @@ zathura_document_register_plugin(char* file_extension, zathura_document_open_t o return true; } -void -zathura_document_plugin_free(void) -{ - /* free registered plugins */ - zathura_document_plugin_t* plugin = zathura_document_plugins; - while (plugin) { - zathura_document_plugin_t* tmp = plugin->next; - free(plugin); - plugin = tmp; - } - - zathura_document_plugins = NULL; -} - zathura_document_t* zathura_document_open(const char* path, const char* password) { diff --git a/document.h b/document.h index b8e03d3..eafa376 100644 --- a/document.h +++ b/document.h @@ -8,6 +8,9 @@ #include +#define PLUGIN_DIR "/usr/lib/zathura" +#define PLUGIN_REGISTER_FUNCTION "plugin_register" + typedef struct zathura_list_s zathura_list_t; typedef struct zathura_document_s zathura_document_t; @@ -20,6 +23,8 @@ typedef struct zathura_document_plugin_s struct zathura_document_plugin_s *next; } zathura_document_plugin_t; +typedef bool (*zathura_plugin_register_service_t)(void); + struct zathura_list_s { void* data; @@ -114,8 +119,9 @@ struct zathura_document_s zathura_page_t** pages; }; +void zathura_document_plugins_load(void); +void zathura_document_plugins_free(void); bool zathura_document_plugin_register(char* file_extension, zathura_document_open_t open_function); -void zathura_document_plugin_free(void); zathura_document_t* zathura_document_open(const char* path, const char* password); bool zathura_document_free(zathura_document_t* document); diff --git a/utils.c b/utils.c index 81b3c2e..79494f8 100644 --- a/utils.c +++ b/utils.c @@ -1,6 +1,7 @@ /* See LICENSE file for license and copyright information */ #include +#include #include #include #include @@ -175,3 +176,60 @@ document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_ printf("%s\n", index_element->title); } while ((it = girara_list_iterator_next(it))); } + +char* string_concat(const char* string1, ...) +{ + if(!string1) { + return NULL; + } + + va_list args; + char* s; + int l = strlen(string1) + 1; + + /* calculate length */ + va_start(args, string1); + + s = va_arg(args, char*); + + while(s) { + l += strlen(s); + s = va_arg(args, char*); + } + + va_end(args); + + /* prepare */ + char* c = malloc(sizeof(char) * l); + char* p = c; + + /* copy */ + char* d = p; + char* x = (char*) string1; + + do { + *d++ = *x; + } while (*x++ != '\0'); + + p = d - 1; + + va_start(args, string1); + + s = va_arg(args, char*); + + while(s) { + d = p; + x = s; + + do { + *d++ = *x; + } while (*x++ != '\0'); + + p = d - 1; + s = va_arg(args, char*); + } + + va_end(args); + + return c; +} diff --git a/utils.h b/utils.h index 02c33f9..735317a 100644 --- a/utils.h +++ b/utils.h @@ -51,4 +51,14 @@ GtkWidget* page_blank(unsigned int width, unsigned int height); */ void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree); +/** + * This function is used to concatenate multiple strings. Argument list has to + * be ended with NULL. Returned string has to be freed with free(). + * + * @param string1 First string + * @param ... Additional strings + * @return Concatenated string or NULL if an error occured + */ +char* string_concat(const char* string1, ...); + #endif // UTILS_H diff --git a/zathura.c b/zathura.c index 7295957..90e07ee 100644 --- a/zathura.c +++ b/zathura.c @@ -64,6 +64,9 @@ init_zathura() /* girara events */ Zathura.UI.session->events.buffer_changed = buffer_changed; + /* load plugins */ + zathura_document_plugins_load(); + /* configuration */ config_load_default(); From dc706aa912db6799421749dd573be04a1a5429a4 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 5 Mar 2011 22:11:08 +0100 Subject: [PATCH 067/197] Updated Makefiles (not finished) --- Makefile | 6 ++++-- config.mk | 4 ++-- ft/Makefile | 18 ++++++++++++++++++ ft/djvu/Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ ft/djvu/config.mk | 21 +++++++++++++++++++++ ft/pdf/Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ ft/pdf/config.mk | 21 +++++++++++++++++++++ zathura.h | 2 +- 8 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 ft/Makefile create mode 100644 ft/djvu/Makefile create mode 100644 ft/djvu/config.mk create mode 100644 ft/pdf/Makefile create mode 100644 ft/pdf/config.mk diff --git a/Makefile b/Makefile index c3efd9d..4152c2c 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ # See LICENSE file for license and copyright information -# zathura - user interface include config.mk PROJECT = zathura -SOURCE = $(shell find . -iname "*.c" -a ! -iwholename "*./doc*|*./ft*") +SOURCE = $(shell find . -iname "*.c" -a ! -iwholename "*./ft*") OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) all: options ${PROJECT} + make -C ft options: @echo ${PROJECT} build options: @@ -35,12 +35,14 @@ ${PROJECT}: ${OBJECTS} clean: @rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ ${DOBJECTS} ${PROJECT}-debug + make -C ft clean ${PROJECT}-debug: ${DOBJECTS} @echo CC -o ${PROJECT}-debug @${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS} debug: ${PROJECT}-debug + make -C ft debug valgrind: debug valgrind --tool=memcheck --leak-check=yes --show-reachable=yes \ diff --git a/config.mk b/config.mk index a6a4747..086388e 100644 --- a/config.mk +++ b/config.mk @@ -8,8 +8,8 @@ PREFIX ?= /usr MANPREFIX ?= ${PREFIX}/share/man # libs -GTK_INC = $(shell pkg-config --cflags gtk+-2.0 poppler-glib ddjvuapi) -GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0 poppler-glib ddjvuapi) +GTK_INC = $(shell pkg-config --cflags gtk+-2.0) +GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0) INCS = -I. -I/usr/include ${GTK_INC} LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara -ldl diff --git a/ft/Makefile b/ft/Makefile new file mode 100644 index 0000000..2e3e593 --- /dev/null +++ b/ft/Makefile @@ -0,0 +1,18 @@ +# See LICENSE file for license and copyright information + +SUBDIRS = $(shell find -mindepth 2 -maxdepth 2 -iname "Makefile" -exec dirname '{}' \;) + +all: + @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir}; done + +debug: + @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} clean; done + +clean: + @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} clean; done + +install: + @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} install; done + +uninstall: + @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} uninstall; done diff --git a/ft/djvu/Makefile b/ft/djvu/Makefile new file mode 100644 index 0000000..02cabfe --- /dev/null +++ b/ft/djvu/Makefile @@ -0,0 +1,42 @@ +# See LICENSE file for license and copyright information + +include config.mk + +PLUGIN = djvu +SOURCE = djvu.c +OBJECTS = ${SOURCE:.c=.o} +DOBJECTS = ${SOURCE:.c=.do} + +all: options ${PLUGIN} + +options: + @echo ${PLUGIN} build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "DFLAGS = ${DFLAGS}" + @echo "CC = ${CC}" + +%.o: %.c + @echo CC $< + @${CC} -c ${CFLAGS} -o $@ $< + +%.do: %.c + @echo CC $< + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + +${OBJECTS}: config.mk +${DOBJECTS}: config.mk + +${PLUGIN}: ${OBJECTS} + @echo LD $@ + @${LD} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) + +${PLUGIN}-debug: ${DOBJECTS} + @echo LD $@ + @${LD} -shared ${LDFLAGS} -o ${PLUGIN}-debug.so $(DOBJECTS) + +clean: + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so ${PLUGIN}-debug.so + +debug: options ${PLUGIN}-debug + @make -C debug diff --git a/ft/djvu/config.mk b/ft/djvu/config.mk new file mode 100644 index 0000000..54154b3 --- /dev/null +++ b/ft/djvu/config.mk @@ -0,0 +1,21 @@ +# See LICENSE file for license and copyright information + +# paths +PREFIX ?= /usr + +# libs +DJVU_INC = $(shell pkg-config --cflags gtk+-2.0 ddjvuapi) +DJVU_LIB = $(shell pkg-config --libs gtk+-2.0 ddjvuapi) + +INCS = -I. -I/usr/include ${DJVU_INC} +LIBS = -lc ${DJVU_LIB} + +# flags +CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) + +# debug +DFLAGS = -g + +# compiler +CC ?= gcc +LD ?= ld diff --git a/ft/pdf/Makefile b/ft/pdf/Makefile new file mode 100644 index 0000000..ce038cb --- /dev/null +++ b/ft/pdf/Makefile @@ -0,0 +1,42 @@ +# See LICENSE file for license and copyright information + +include config.mk + +PLUGIN = pdf +SOURCE = pdf.c +OBJECTS = ${SOURCE:.c=.o} +DOBJECTS = ${SOURCE:.c=.do} + +all: options ${PLUGIN} + +options: + @echo ${PLUGIN} build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "DFLAGS = ${DFLAGS}" + @echo "CC = ${CC}" + +%.o: %.c + @echo CC $< + @${CC} -c ${CFLAGS} -o $@ $< + +%.do: %.c + @echo CC $< + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + +${OBJECTS}: config.mk +${DOBJECTS}: config.mk + +${PLUGIN}: ${OBJECTS} + @echo LD $@ + @${LD} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) + +${PLUGIN}-debug: ${DOBJECTS} + @echo LD $@ + @${LD} -shared ${LDFLAGS} -o ${PLUGIN}-debug.so $(DOBJECTS) + +clean: + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so ${PLUGIN}-debug.so + +debug: options ${PLUGIN}-debug + @make -C debug diff --git a/ft/pdf/config.mk b/ft/pdf/config.mk new file mode 100644 index 0000000..2e505e9 --- /dev/null +++ b/ft/pdf/config.mk @@ -0,0 +1,21 @@ +# See LICENSE file for license and copyright information + +# paths +PREFIX ?= /usr + +# libs +PDF_INC = $(shell pkg-config --cflags gtk+-2.0 poppler-glib) +PDF_LIB = $(shell pkg-config --libs gtk+-2.0 poppler-glib) + +INCS = -I. -I/usr/include ${PDF_INC} +LIBS = -lc ${PDF_LIB} + +# flags +CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) + +# debug +DFLAGS = -g + +# compiler +CC ?= gcc +LD ?= ld diff --git a/zathura.h b/zathura.h index 2002e27..3052e32 100644 --- a/zathura.h +++ b/zathura.h @@ -5,8 +5,8 @@ #include #include -#include +#include "render.h" #include "document.h" enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, From 95c3037a4540ee71514c823c43fab081279c88b7 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 01:43:04 +0100 Subject: [PATCH 068/197] Updated Makefile and register file type --- config.mk | 3 +++ ft/djvu/Makefile | 4 ++-- ft/djvu/djvu.c | 9 +++++++++ ft/pdf/Makefile | 4 ++-- ft/pdf/pdf.c | 9 +++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/config.mk b/config.mk index 086388e..b0200e1 100644 --- a/config.mk +++ b/config.mk @@ -20,6 +20,9 @@ CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) # debug DFLAGS = -g +# ld +LDFLAGS = -rdynamic + # compiler CC ?= gcc diff --git a/ft/djvu/Makefile b/ft/djvu/Makefile index 02cabfe..83193ab 100644 --- a/ft/djvu/Makefile +++ b/ft/djvu/Makefile @@ -29,11 +29,11 @@ ${DOBJECTS}: config.mk ${PLUGIN}: ${OBJECTS} @echo LD $@ - @${LD} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) + @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS} ${PLUGIN}-debug: ${DOBJECTS} @echo LD $@ - @${LD} -shared ${LDFLAGS} -o ${PLUGIN}-debug.so $(DOBJECTS) + @${CC} -shared ${LDFLAGS} -o ${PLUGIN}-debug.so $(DOBJECTS) ${LIBS} clean: @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so ${PLUGIN}-debug.so diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index b7040a8..00f82cb 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -5,6 +5,15 @@ #include "djvu.h" #include "../../zathura.h" +bool +plugin_register(void) +{ + zathura_document_plugin_register("djvu", djvu_document_open); + zathura_document_plugin_register("DJVU", djvu_document_open); + + return true; +} + bool djvu_document_open(zathura_document_t* document) { diff --git a/ft/pdf/Makefile b/ft/pdf/Makefile index ce038cb..e260d91 100644 --- a/ft/pdf/Makefile +++ b/ft/pdf/Makefile @@ -29,11 +29,11 @@ ${DOBJECTS}: config.mk ${PLUGIN}: ${OBJECTS} @echo LD $@ - @${LD} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) + @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS} ${PLUGIN}-debug: ${DOBJECTS} @echo LD $@ - @${LD} -shared ${LDFLAGS} -o ${PLUGIN}-debug.so $(DOBJECTS) + @${CC} -shared ${LDFLAGS} -o ${PLUGIN}-debug.so $(DOBJECTS) ${LIBS} clean: @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so ${PLUGIN}-debug.so diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index b4adf36..ba6d06d 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -6,6 +6,15 @@ #include "pdf.h" #include "../../zathura.h" +bool +plugin_register(void) +{ + zathura_document_plugin_register("pdf", pdf_document_open); + zathura_document_plugin_register("PDF", pdf_document_open); + + return true; +} + bool pdf_document_open(zathura_document_t* document) { From 86b54e728bdde11ee40cf1fe4c2b950055db4e89 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 02:21:46 +0100 Subject: [PATCH 069/197] Update Makefile --- document.c | 6 +++--- ft/djvu/Makefile | 5 ++--- ft/pdf/Makefile | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/document.c b/document.c index 72e8851..0d62532 100644 --- a/document.c +++ b/document.c @@ -73,7 +73,6 @@ zathura_document_plugins_load(void) if (closedir(dir) == -1) { fprintf(stderr, "error: could not close plugin directory: %s\n", PLUGIN_DIR); } - } void @@ -83,6 +82,7 @@ zathura_document_plugins_free(void) zathura_document_plugin_t* plugin = zathura_document_plugins; while (plugin) { zathura_document_plugin_t* tmp = plugin->next; + free(plugin->file_extension); free(plugin); plugin = tmp; } @@ -91,7 +91,7 @@ zathura_document_plugins_free(void) } bool -zathura_document_register_plugin(char* file_extension, zathura_document_open_t open_function) +zathura_document_plugin_register(char* file_extension, zathura_document_open_t open_function) { if( (file_extension == NULL) || (open_function == NULL) ) { fprintf(stderr, "plugin: could not register\n"); @@ -120,7 +120,7 @@ zathura_document_register_plugin(char* file_extension, zathura_document_open_t o return false; } - new_plugin->file_extension = file_extension; + new_plugin->file_extension = strdup(file_extension); new_plugin->open_function = open_function; new_plugin->next = NULL; diff --git a/ft/djvu/Makefile b/ft/djvu/Makefile index 83193ab..46f0612 100644 --- a/ft/djvu/Makefile +++ b/ft/djvu/Makefile @@ -33,10 +33,9 @@ ${PLUGIN}: ${OBJECTS} ${PLUGIN}-debug: ${DOBJECTS} @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}-debug.so $(DOBJECTS) ${LIBS} + @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so ${PLUGIN}-debug.so + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so debug: options ${PLUGIN}-debug - @make -C debug diff --git a/ft/pdf/Makefile b/ft/pdf/Makefile index e260d91..444888f 100644 --- a/ft/pdf/Makefile +++ b/ft/pdf/Makefile @@ -33,10 +33,9 @@ ${PLUGIN}: ${OBJECTS} ${PLUGIN}-debug: ${DOBJECTS} @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}-debug.so $(DOBJECTS) ${LIBS} + @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so ${PLUGIN}-debug.so + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so debug: options ${PLUGIN}-debug - @make -C debug From d1cef30ef3614780ebd5262612eb91a7d1eabe0b Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 02:39:25 +0100 Subject: [PATCH 070/197] FIXME: Close dlhandle --- document.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document.c b/document.c index 0d62532..8b4ed91 100644 --- a/document.c +++ b/document.c @@ -66,7 +66,7 @@ zathura_document_plugins_load(void) fprintf(stderr, "error: could not register plugin\n"); } - dlclose(handle); + /*dlclose(handle);*/ // FIXME } } From dc660d2c56352bc7ade237bb66151d6bc9eb0fb3 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 09:14:36 +0100 Subject: [PATCH 071/197] Register plugin correctly and handle dlhandle correctly --- document.c | 119 ++++++++++++++++++++++++++++++------------------- document.h | 5 ++- ft/djvu/djvu.c | 10 ++--- ft/pdf/pdf.c | 10 ++--- 4 files changed, 83 insertions(+), 61 deletions(-) diff --git a/document.c b/document.c index 8b4ed91..48d97d1 100644 --- a/document.c +++ b/document.c @@ -33,41 +33,72 @@ zathura_document_plugins_load(void) struct dirent* entry; while ((entry = readdir(dir)) != NULL) { /* check if entry is a file */ - if (entry->d_type == 0x8) { - /* get full path */ - char* path = string_concat(PLUGIN_DIR, "/", entry->d_name, NULL); - - if (path == NULL) { - continue; - } - - /* load plugin */ - void* handle = dlopen(path, RTLD_NOW); - free(path); - - if (handle == NULL) { - fprintf(stderr, "error: could not load plugin (%s)\n", dlerror()); - continue; - } - - /* resolve symbol */ - zathura_plugin_register_service_t register_plugin; - *(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION); - - if (register_plugin == NULL) { - fprintf(stderr, "error: could not find '%s' function in the plugin\n", PLUGIN_REGISTER_FUNCTION); - dlclose(handle); - continue; - } - - bool r = register_plugin(); - - if (r == false) { - fprintf(stderr, "error: could not register plugin\n"); - } - - /*dlclose(handle);*/ // FIXME + if (entry->d_type != 0x8) { + continue; } + + void* handle = NULL; + zathura_document_plugin_t* plugin = NULL; + char* path = NULL; + + /* get full path */ + path = string_concat(PLUGIN_DIR, "/", entry->d_name, NULL); + + if (path == NULL) { + goto error_continue; + } + + /* load plugin */ + handle = dlopen(path, RTLD_NOW); + + if (handle == NULL) { + fprintf(stderr, "error: could not load plugin (%s)\n", dlerror()); + goto error_free; + } + + /* resolve symbol */ + zathura_plugin_register_service_t register_plugin; + *(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION); + + if (register_plugin == NULL) { + fprintf(stderr, "error: could not find '%s' function in the plugin\n", PLUGIN_REGISTER_FUNCTION); + goto error_free; + } + + plugin = malloc(sizeof(zathura_document_plugin_t)); + + if (plugin == NULL) { + goto error_free; + } + + plugin->file_extension = NULL; + plugin->open_function = NULL; + + register_plugin(plugin); + + bool r = zathura_document_plugin_register(plugin, handle); + + if (r == false) { + fprintf(stderr, "error: could not register plugin (%s)\n", path); + goto error_free; + } + + free(path); + + continue; + +error_free: + + free(path); + free(plugin); + + if (handle) { + dlclose(handle); + } + +error_continue: + + continue; } if (closedir(dir) == -1) { @@ -91,9 +122,10 @@ zathura_document_plugins_free(void) } bool -zathura_document_plugin_register(char* file_extension, zathura_document_open_t open_function) +zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle) { - if( (file_extension == NULL) || (open_function == NULL) ) { + if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) + || (handle == NULL) ) { fprintf(stderr, "plugin: could not register\n"); return false; } @@ -101,8 +133,8 @@ zathura_document_plugin_register(char* file_extension, zathura_document_open_t o /* search existing plugins */ zathura_document_plugin_t* plugin = zathura_document_plugins; while (plugin) { - if (!strcmp(plugin->file_extension, file_extension)) { - fprintf(stderr, "plugin: already registered for filetype %s\n", file_extension); + if (!strcmp(plugin->file_extension, new_plugin->file_extension)) { + fprintf(stderr, "plugin: already registered for filetype %s\n", plugin->file_extension); return false; } @@ -114,15 +146,8 @@ zathura_document_plugin_register(char* file_extension, zathura_document_open_t o } /* create new plugin */ - zathura_document_plugin_t* new_plugin = malloc(sizeof(zathura_document_plugin_t)); - - if (new_plugin == NULL) { - return false; - } - - new_plugin->file_extension = strdup(file_extension); - new_plugin->open_function = open_function; - new_plugin->next = NULL; + new_plugin->handle = handle; + new_plugin->next = NULL; /* append to list */ if (plugin == NULL) { diff --git a/document.h b/document.h index eafa376..c331597 100644 --- a/document.h +++ b/document.h @@ -20,10 +20,11 @@ typedef struct zathura_document_plugin_s { char* file_extension; zathura_document_open_t open_function; + void* handle; struct zathura_document_plugin_s *next; } zathura_document_plugin_t; -typedef bool (*zathura_plugin_register_service_t)(void); +typedef void (*zathura_plugin_register_service_t)(zathura_document_plugin_t*); struct zathura_list_s { @@ -121,7 +122,7 @@ struct zathura_document_s void zathura_document_plugins_load(void); void zathura_document_plugins_free(void); -bool zathura_document_plugin_register(char* file_extension, zathura_document_open_t open_function); +bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle); zathura_document_t* zathura_document_open(const char* path, const char* password); bool zathura_document_free(zathura_document_t* document); diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 00f82cb..a45ac83 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -5,13 +5,11 @@ #include "djvu.h" #include "../../zathura.h" -bool -plugin_register(void) +void +plugin_register(zathura_document_plugin_t* plugin) { - zathura_document_plugin_register("djvu", djvu_document_open); - zathura_document_plugin_register("DJVU", djvu_document_open); - - return true; + plugin->file_extension = "djvu"; + plugin->open_function = djvu_document_open; } bool diff --git a/ft/pdf/pdf.c b/ft/pdf/pdf.c index ba6d06d..36b192e 100644 --- a/ft/pdf/pdf.c +++ b/ft/pdf/pdf.c @@ -6,13 +6,11 @@ #include "pdf.h" #include "../../zathura.h" -bool -plugin_register(void) +void +plugin_register(zathura_document_plugin_t* plugin) { - zathura_document_plugin_register("pdf", pdf_document_open); - zathura_document_plugin_register("PDF", pdf_document_open); - - return true; + plugin->file_extension = "pdf"; + plugin->open_function = pdf_document_open; } bool From 4eabd47949778fb8b167f5243f8e8c573b24785a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 09:19:21 +0100 Subject: [PATCH 072/197] Added install/uninstall targets for plugins --- Makefile | 2 ++ ft/djvu/Makefile | 10 ++++++++++ ft/pdf/Makefile | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/Makefile b/Makefile index 4152c2c..27daaaa 100644 --- a/Makefile +++ b/Makefile @@ -68,9 +68,11 @@ install: all @mkdir -p ${DESTDIR}${MANPREFIX}/man1 @sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 + @make -C ft install uninstall: @echo removing executable file @rm -f ${DESTDIR}${MANPREFIX}/bin/${PROJECT} @echo removing manual page @rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 + @make -C ft uninstall diff --git a/ft/djvu/Makefile b/ft/djvu/Makefile index 46f0612..d5e7617 100644 --- a/ft/djvu/Makefile +++ b/ft/djvu/Makefile @@ -39,3 +39,13 @@ clean: @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so debug: options ${PLUGIN}-debug + +install: all + @echo installing ${PLUGIN} plugin + @mkdir -p ${DESTDIR}${PREFIX}/lib/zathura + @cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura + +uninstall: + @echo uninstalling ${PLUGIN} plugin + @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so + @rm -rf ${DESTDIR}${PREFIX}/lib/zathura diff --git a/ft/pdf/Makefile b/ft/pdf/Makefile index 444888f..e14ed8c 100644 --- a/ft/pdf/Makefile +++ b/ft/pdf/Makefile @@ -39,3 +39,13 @@ clean: @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so debug: options ${PLUGIN}-debug + +install: all + @echo installing ${PLUGIN} plugin + @mkdir -p ${DESTDIR}${PREFIX}/lib/zathura + @cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura + +uninstall: + @echo uninstalling ${PLUGIN} plugin + @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so + @rm -rf ${DESTDIR}${PREFIX}/lib/zathura From bf456a8c9f536caf98cc94572bd99a9921634a71 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 09:20:45 +0100 Subject: [PATCH 073/197] Renamed mupdf plugin directory --- ft/{pdf => pdf-mupdf}/pdf.c | 0 ft/{pdf => pdf-mupdf}/pdf.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename ft/{pdf => pdf-mupdf}/pdf.c (100%) rename ft/{pdf => pdf-mupdf}/pdf.h (100%) diff --git a/ft/pdf/pdf.c b/ft/pdf-mupdf/pdf.c similarity index 100% rename from ft/pdf/pdf.c rename to ft/pdf-mupdf/pdf.c diff --git a/ft/pdf/pdf.h b/ft/pdf-mupdf/pdf.h similarity index 100% rename from ft/pdf/pdf.h rename to ft/pdf-mupdf/pdf.h From ff4df5e385d242d3da6bd8528e6ca58af68872d6 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 09:22:38 +0100 Subject: [PATCH 074/197] Renamed pdf poppler plugin --- ft/{pdf => pdf-poppler}/Makefile | 0 ft/{pdf => pdf-poppler}/config.mk | 0 ft/{pdf => pdf-poppler}/pdf.c | 0 ft/{pdf => pdf-poppler}/pdf.h | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename ft/{pdf => pdf-poppler}/Makefile (100%) rename ft/{pdf => pdf-poppler}/config.mk (100%) rename ft/{pdf => pdf-poppler}/pdf.c (100%) rename ft/{pdf => pdf-poppler}/pdf.h (100%) diff --git a/ft/pdf/Makefile b/ft/pdf-poppler/Makefile similarity index 100% rename from ft/pdf/Makefile rename to ft/pdf-poppler/Makefile diff --git a/ft/pdf/config.mk b/ft/pdf-poppler/config.mk similarity index 100% rename from ft/pdf/config.mk rename to ft/pdf-poppler/config.mk diff --git a/ft/pdf/pdf.c b/ft/pdf-poppler/pdf.c similarity index 100% rename from ft/pdf/pdf.c rename to ft/pdf-poppler/pdf.c diff --git a/ft/pdf/pdf.h b/ft/pdf-poppler/pdf.h similarity index 100% rename from ft/pdf/pdf.h rename to ft/pdf-poppler/pdf.h From 4eca9796950b155ff9b4a1178015b30f490dddf5 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 11:24:30 +0100 Subject: [PATCH 075/197] Updated mupdf backend --- ft/pdf-mupdf/pdf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index 8af67a0..09bd3e0 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -212,8 +212,13 @@ pdf_page_render(zathura_page_t* page) fz_freedevice(device); - fz_matrix ctm = fz_translate(0, -mupdf_page->page->mediabox.y1); + pdf_agestore(pdf_document->document->store, 3); + + fz_matrix ctm = fz_identity; + ctm = fz_concat(ctm, fz_translate(0, -mupdf_page->page->mediabox.y1)); ctm = fz_concat(ctm, fz_scale(Zathura.document->scale, -Zathura.document->scale)); + ctm = fz_concat(ctm, fz_rotate(mupdf_page->page->rotate)); + ctm = fz_concat(ctm, fz_rotate(Zathura.document->rotate)); fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); @@ -239,8 +244,6 @@ pdf_page_render(zathura_page_t* page) fz_droppixmap(pixmap); fz_freedisplaylist(display_list); - pdf_freepage(mupdf_page->page); - pdf_agestore(pdf_document->document->store, 3); /* write pixbuf */ GtkWidget* image = gtk_image_new(); From 1fbe59aabf4e5225df2444a14a9aaf684f73dce1 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 14:49:44 +0100 Subject: [PATCH 076/197] Implemented sc_rotate --- config.c | 4 +++- shortcuts.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index a93af7b..70b4543 100644 --- a/config.c +++ b/config.c @@ -11,11 +11,13 @@ config_load_default(void) if (!Zathura.UI.session) return; + int int_value = 0; + /* general settings */ girara_mode_set(Zathura.UI.session, NORMAL); /* zathura settings */ - int int_value = 10; + int_value = 10; girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL); /* define default shortcuts */ diff --git a/shortcuts.c b/shortcuts.c index 3a4115b..7bbd2e6 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -133,6 +133,16 @@ sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t bool sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + if (session == NULL || Zathura.document == NULL) { + return false; + } + + /* update rotate value */ + Zathura.document->rotate = (Zathura.document->rotate + 90) % 360; + + /* render all pages again */ + render_all(); + return false; } From d56b79b3c00cd509efb71f94a2c6818856101b36 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 Mar 2011 15:21:38 +0100 Subject: [PATCH 077/197] Little fix in sc_toggle_index --- shortcuts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shortcuts.c b/shortcuts.c index 7bbd2e6..aa8b664 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -285,7 +285,7 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned error_free: if (Zathura.UI.index != NULL) { - g_object_unref(Zathura.UI.index); + g_object_ref_sink(Zathura.UI.index); Zathura.UI.index = NULL; } From 04ffece35bdbe712c5c317c525daff35c2d7c999 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 7 Mar 2011 15:18:25 +0100 Subject: [PATCH 078/197] Treat LDFLAGS the same way as CFLAGS --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index b0200e1..b1efcf6 100644 --- a/config.mk +++ b/config.mk @@ -21,7 +21,7 @@ CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) DFLAGS = -g # ld -LDFLAGS = -rdynamic +LDFLAGS += -rdynamic # compiler CC ?= gcc From e04c86a7f34e54a463d79e5fd61e496c812c2a4f Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 12 Mar 2011 11:32:24 +0100 Subject: [PATCH 079/197] Documented document.h --- commands.c | 3 + document.h | 310 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 274 insertions(+), 39 deletions(-) diff --git a/commands.c b/commands.c index 4774076..a7dd660 100644 --- a/commands.c +++ b/commands.c @@ -1,6 +1,7 @@ /* See LICENSE file for license and copyright information */ #include "commands.h" +#include "zathura.h" bool cmd_bookmark_create(girara_session_t* session, int argc, char** argv) @@ -23,6 +24,8 @@ cmd_bookmark_open(girara_session_t* session, int argc, char** argv) bool cmd_close(girara_session_t* session, int argc, char** argv) { + document_close(); + return true; } diff --git a/document.h b/document.h index c331597..6af627d 100644 --- a/document.h +++ b/document.h @@ -16,131 +16,363 @@ typedef struct zathura_document_s zathura_document_t; typedef bool (*zathura_document_open_t)(zathura_document_t* document); +/** + * Document plugin structure + */ typedef struct zathura_document_plugin_s { - char* file_extension; - zathura_document_open_t open_function; - void* handle; - struct zathura_document_plugin_s *next; + char* file_extension; /**> File extension */ + zathura_document_open_t open_function; /**> Document open function */ + void* handle; /**> DLL handle */ + struct zathura_document_plugin_s *next; /**> Next plugin */ // TODO: Use list_t } zathura_document_plugin_t; +/** + * Function prototype that is called to register a document plugin + * + * @param The document plugin + */ typedef void (*zathura_plugin_register_service_t)(zathura_document_plugin_t*); +/** + * Structure for a list + */ struct zathura_list_s { - void* data; - struct zathura_list_s* next; + void* data; /**> Data value */ + struct zathura_list_s* next; /**> Next element in the list */ }; +/** + * Rectangle structure + */ typedef struct zathura_rectangle_s { - double x1; - double y1; - double x2; - double y2; + double x1; /**> X coordinate of point 1 */ + double y1; /**> Y coordinate of point 1 */ + double x2; /**> X coordinate of point 2 */ + double y2; /**> Y coordinate of point 2 */ } zathura_rectangle_t; +/** + * Possible link types + */ typedef enum zathura_link_type_e { - ZATHURA_LINK_TO_PAGE, - ZATHURA_LINK_EXTERNAL, + ZATHURA_LINK_TO_PAGE, /**> Links to a page */ + ZATHURA_LINK_EXTERNAL, /**> Links to an external source */ } zathura_link_type_t; +/** + * Link + */ typedef struct zathura_link_s { - zathura_rectangle_t position; - zathura_link_type_t type; + zathura_rectangle_t position; /**> Position of the link */ + zathura_link_type_t type; /**> Link type */ union { - unsigned int page_number; - char* value; + unsigned int page_number; /**> Page number */ + char* value; /**> Value */ } target; } zathura_link_t; +/** + * Index element + */ typedef struct zathura_index_element_s { - char* title; - zathura_link_type_t type; + char* title; /**> Title of the element */ + zathura_link_type_t type; /**> Type */ union { - unsigned int page_number; - char* uri; + unsigned int page_number; /**> Page number */ + char* uri; /**> Uri */ } target; } zathura_index_element_t; +/** + * Form type + */ typedef enum zathura_form_type_e { - ZATHURA_FORM_CHECKBOX, - ZATHURA_FORM_TEXTFIELD + ZATHURA_FORM_CHECKBOX, /**> Checkbox */ + ZATHURA_FORM_TEXTFIELD /**> Textfield */ } zathura_form_type_t; +/** + * Form element + */ typedef struct zathura_form_s { - zathura_rectangle_t position; - zathura_form_type_t type; + zathura_rectangle_t position; /**> Position */ + zathura_form_type_t type; /**> Type */ } zathura_form_t; +/** + * Page + */ typedef struct zathura_page_s { - double height; - double width; - double offset; - unsigned int number; - zathura_document_t* document; - void* data; - bool rendered; - GStaticMutex lock; + double height; /**> Page height */ + double width; /**> Page width */ + double offset; /**> Page offset */ + unsigned int number; /**> Page number */ + zathura_document_t* document; /**> Document */ + void* data; /**> Custom data */ + bool rendered; /**> Page has been rendered */ + GStaticMutex lock; /**> Lock */ } zathura_page_t; +/** + * Document + */ struct zathura_document_s { - char* file_path; - const char* password; - unsigned int current_page_number; - unsigned int number_of_pages; - double scale; - int rotate; - void* data; + char* file_path; /**> File path of the document */ + const char* password; /**> Password of the document */ + unsigned int current_page_number; /**> Current page number */ + unsigned int number_of_pages; /**> Number of pages */ + double scale; /**> Scale value */ + int rotate; /**> Rotation */ + void* data; /**> Custom data */ struct { + /** + * Frees the document + * + * @param document The document + */ bool (*document_free)(zathura_document_t* document); + + /** + * Generates the document index + * + * @param document The document + * @return NULL if an error occured or no index exists + */ girara_tree_node_t* (*document_index_generate)(zathura_document_t* document); + + /** + * Save the document + * + * @param document The document + * @param path The new path + * @return true if no error occured + */ bool (*document_save_as)(zathura_document_t* document, const char* path); + + /** + * Get list of attachments + * + * @param document The document + * @return NULL if an error occured, otherwise the attachment list + */ zathura_list_t* (*document_attachments_get)(zathura_document_t* document); + /** + * Gets the page object + * + * @param document The document + * @param page_id Number of the page + * @return The page object or NULL, if an error occured + */ zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id); + + /** + * Search text + * + * @param page The page + * @param text Search item + * @return List of results + */ zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); + + /** + * Get links on a page + * + * @param page + * @return List of links + */ zathura_list_t* (*page_links_get)(zathura_page_t* page); + + /** + * Get form fields + * + * @param page + * @return List of form fields + */ zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); + + /** + * Renders the page + * + * @param page + * @return Rendered page + */ GtkWidget* (*page_render)(zathura_page_t* page); + + /** + * Free page + * + * @param page + * @return true if no error occured, otherwise false + */ bool (*page_free)(zathura_page_t* page); } functions; + /** + * Document pages + */ zathura_page_t** pages; }; +/** + * Load all document plugins + */ void zathura_document_plugins_load(void); + +/** + * Free all document plugins + */ void zathura_document_plugins_free(void); + +/** + * Register document plugin + */ bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle); +/** + * Open the document + * + * @param path Path to the document + * @param password Password of the document or NULL + * @return The document object + */ zathura_document_t* zathura_document_open(const char* path, const char* password); + +/** + * Free the document + * + * @param document + * @return true if no error occured, otherwise false + */ bool zathura_document_free(zathura_document_t* document); + +/** + * Save the document + * + * @param document The document object + * @param path Path for the saved file + * @return true if no error occured, otherwise false + */ bool zathura_document_save_as(zathura_document_t* document, const char* path); + +/** + * Generate the document index + * + * @param document The document object + * @return Generated index + */ + girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document); + +/** + * Get list of attachments + * + * @param document The document object + * @return List of attachments + */ zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); + +/** + * Free document attachments + * + * @param list list of document attachments + * @return + */ bool zathura_document_attachments_free(zathura_list_t* list); +/** + * Get the page object + * + * @param document The document + * @param page_id Page number + * @return Page object or NULL if an error occured + */ zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id); + +/** + * Frees the page object + * + * @param page The page object + * @return true if no error occured, otherwise false + */ bool zathura_page_free(zathura_page_t* page); + +/** + * Search page + * + * @param page The page object + * @param text Search item + * @return List of results + */ zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text); + +/** + * Get page links + * + * @param page The page object + * @return List of links + */ zathura_list_t* zathura_page_links_get(zathura_page_t* page); + +/** + * Free page links + * + * @param list List of links + * @return true if no error occured, otherwise false + */ bool zathura_page_links_free(zathura_list_t* list); + +/** + * Get list of form fields + * + * @param page The page object + * @return List of form fields + */ zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page); + +/** + * Free list of form fields + * + * @param list List of form fields + * @return true if no error occured, otherwise false + */ bool zathura_page_form_fields_free(zathura_list_t* list); + +/** + * Render page + * + * @param page The page object + * @return Rendered page + */ GtkWidget* zathura_page_render(zathura_page_t* page); +/** + * Create new index element + * + * @param title Title of the index element + * @return Index element + */ zathura_index_element_t* zathura_index_element_new(const char* title); + +/** + * Free index element + * + * @param index The index element + */ void zathura_index_element_free(zathura_index_element_t* index); #endif // DOCUMENT_H From 58c2ee7dd33c644fbe10ad03e476ec3c7fd83965 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 18 Mar 2011 10:09:07 +0100 Subject: [PATCH 080/197] Updated Makefile --- ft/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ft/Makefile b/ft/Makefile index 2e3e593..324326f 100644 --- a/ft/Makefile +++ b/ft/Makefile @@ -6,7 +6,7 @@ all: @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir}; done debug: - @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} clean; done + @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} debug; done clean: @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} clean; done From 7d18faa452dfedd241bb5bbd8aec407b3693e848 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 18 Mar 2011 13:27:21 +0100 Subject: [PATCH 081/197] Replace GtkWidget with zathura_image_buffer_t --- document.c | 42 +++++++++++++++++++++++++---- document.h | 64 ++++++++++++++++++++------------------------ ft/djvu/djvu.c | 2 +- ft/djvu/djvu.h | 2 +- ft/pdf-mupdf/pdf.c | 2 +- ft/pdf-mupdf/pdf.h | 2 +- ft/pdf-poppler/pdf.c | 2 +- ft/pdf-poppler/pdf.h | 2 +- render.c | 12 ++++----- 9 files changed, 78 insertions(+), 52 deletions(-) diff --git a/document.c b/document.c index 48d97d1..b1d0e4f 100644 --- a/document.c +++ b/document.c @@ -124,7 +124,7 @@ zathura_document_plugins_free(void) bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle) { - if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) + if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) || (handle == NULL) ) { fprintf(stderr, "plugin: could not register\n"); return false; @@ -469,7 +469,7 @@ zathura_page_form_fields_free(zathura_list_t* list) return false; } -GtkWidget* +zathura_image_buffer_t* zathura_page_render(zathura_page_t* page) { if (!page || !page->document) { @@ -481,13 +481,13 @@ zathura_page_render(zathura_page_t* page) return NULL; } - GtkWidget* widget = page->document->functions.page_render(page); + zathura_image_buffer_t* buffer = page->document->functions.page_render(page); - if (widget) { + if (buffer) { page->rendered = true; } - return widget; + return buffer; } zathura_index_element_t* @@ -523,3 +523,35 @@ zathura_index_element_free(zathura_index_element_t* index) g_free(index); } + +zathura_image_buffer_t* +zathura_image_buffer_create(unsigned int width, unsigned int height) +{ + zathura_image_buffer_t* image_buffer = malloc(sizeof(zathura_image_buffer_t)); + + if (image_buffer == NULL) { + return NULL; + } + + image_buffer->data = calloc(width * height * 3, sizeof(unsigned char)); + + if (image_buffer->data == NULL) { + free(image_buffer); + return NULL; + } + + image_buffer->width = width; + image_buffer->height = height; + + return image_buffer; +} + +void +zathura_image_buffer_free(zathura_image_buffer_t* image_buffer) +{ + if (image_buffer == NULL) { + return; + } + + free(image_buffer->data); +} diff --git a/document.h b/document.h index 6af627d..f05ee68 100644 --- a/document.h +++ b/document.h @@ -43,6 +43,32 @@ struct zathura_list_s struct zathura_list_s* next; /**> Next element in the list */ }; +/** + * Image buffer + */ +typedef struct zathura_image_buffer_s +{ + unsigned char* data; /**> Image buffer data */ + unsigned int height; /**> Height of the image */ + unsigned int width; /**> Width of the image */ +} zathura_image_buffer_t; + +/** + * Creates an image buffer + * + * @param width Width of the image stored in the buffer + * @param height Height of the image stored in the buffer + * @return Image buffer or NULL if an error occured + */ +zathura_image_buffer_t* zathura_image_buffer_create(unsigned int width, unsigned int height); + +/** + * Frees the image buffer + * + * @param zathura_image_buffer_t + */ +void zathura_image_buffer_free(zathura_image_buffer_t*); + /** * Rectangle structure */ @@ -141,83 +167,51 @@ struct zathura_document_s { /** * Frees the document - * - * @param document The document */ bool (*document_free)(zathura_document_t* document); /** * Generates the document index - * - * @param document The document - * @return NULL if an error occured or no index exists */ girara_tree_node_t* (*document_index_generate)(zathura_document_t* document); /** * Save the document - * - * @param document The document - * @param path The new path - * @return true if no error occured */ bool (*document_save_as)(zathura_document_t* document, const char* path); /** * Get list of attachments - * - * @param document The document - * @return NULL if an error occured, otherwise the attachment list */ zathura_list_t* (*document_attachments_get)(zathura_document_t* document); /** * Gets the page object - * - * @param document The document - * @param page_id Number of the page - * @return The page object or NULL, if an error occured */ zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id); /** * Search text - * - * @param page The page - * @param text Search item - * @return List of results */ zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); /** * Get links on a page - * - * @param page - * @return List of links */ zathura_list_t* (*page_links_get)(zathura_page_t* page); /** * Get form fields - * - * @param page - * @return List of form fields */ zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); /** * Renders the page - * - * @param page - * @return Rendered page */ - GtkWidget* (*page_render)(zathura_page_t* page); + zathura_image_buffer_t* (*page_render)(zathura_page_t* page); /** * Free page - * - * @param page - * @return true if no error occured, otherwise false */ bool (*page_free)(zathura_page_t* page); } functions; @@ -356,9 +350,9 @@ bool zathura_page_form_fields_free(zathura_list_t* list); * Render page * * @param page The page object - * @return Rendered page + * @return Image buffer or NULL if an error occured */ -GtkWidget* zathura_page_render(zathura_page_t* page); +zathura_image_buffer_t* zathura_page_render(zathura_page_t* page); /** * Create new index element diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index a45ac83..7c795ce 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -215,7 +215,7 @@ djvu_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* djvu_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->document) { diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h index f043f69..31444ff 100644 --- a/ft/djvu/djvu.h +++ b/ft/djvu/djvu.h @@ -24,7 +24,7 @@ zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* djvu_page_links_get(zathura_page_t* page); zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page); -GtkWidget* djvu_page_render(zathura_page_t* page); +zathura_image_buffer_t* djvu_page_render(zathura_page_t* page); bool djvu_page_free(zathura_page_t* page); #endif // DJVU_H diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index 09bd3e0..a676826 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -173,7 +173,7 @@ pdf_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->data || !page->document) { diff --git a/ft/pdf-mupdf/pdf.h b/ft/pdf-mupdf/pdf.h index 9d53949..84d7b38 100644 --- a/ft/pdf-mupdf/pdf.h +++ b/ft/pdf-mupdf/pdf.h @@ -27,7 +27,7 @@ zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* pdf_page_links_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -GtkWidget* pdf_page_render(zathura_page_t* page); +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page); #endif // PDF_H diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index 36b192e..8415468 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -250,7 +250,7 @@ pdf_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->data || !page->document) { diff --git a/ft/pdf-poppler/pdf.h b/ft/pdf-poppler/pdf.h index 5b959d0..ce76613 100644 --- a/ft/pdf-poppler/pdf.h +++ b/ft/pdf-poppler/pdf.h @@ -22,7 +22,7 @@ zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* pdf_page_links_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -GtkWidget* pdf_page_render(zathura_page_t* page); +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page); #endif // PDF_H diff --git a/render.c b/render.c index f863ae7..c163638 100644 --- a/render.c +++ b/render.c @@ -132,9 +132,9 @@ bool render(zathura_page_t* page) { g_static_mutex_lock(&(page->lock)); - GtkWidget* image = zathura_page_render(page); + zathura_image_buffer_t* buffer = zathura_page_render(page); - if (!image) { + if (!buffer) { g_static_mutex_unlock(&(page->lock)); printf("error: rendering failed\n"); return false; @@ -148,7 +148,7 @@ render(zathura_page_t* page) if (!widget) { g_static_mutex_unlock(&(page->lock)); printf("error: page container does not exist\n"); - g_object_unref(image); + // TODO: zathura_image_buffer_free(image); return false; } @@ -164,13 +164,13 @@ render(zathura_page_t* page) gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); /* add new widget */ - gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); + // TODO: gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); /* set old packaging values */ - gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); + // TODO: gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); /* reorder child */ - gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + // TODO: gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); g_static_mutex_unlock(&(page->lock)); return true; From 6689a3422a8a2309c3bae8a724c8038d3b2a61bd Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 18 Mar 2011 14:10:42 +0100 Subject: [PATCH 082/197] Updated plugin render functions --- ft/djvu/djvu.c | 65 +++++--------------------------------------- ft/pdf-mupdf/pdf.c | 26 ++++-------------- ft/pdf-poppler/pdf.c | 39 +++++++++++++++----------- 3 files changed, 35 insertions(+), 95 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 7c795ce..5fe130e 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -243,76 +243,25 @@ djvu_page_render(zathura_page_t* page) ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; ddjvu_rect_t prect = { 0, 0, page_width, page_height }; - guchar* buffer = malloc(sizeof(char) * (page_width * page_height * 3)); - if (!buffer) { + zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); + + if (image_buffer == NULL) { goto error_free; } /* set rotation */ - GdkPixbufRotation gdk_angle = GDK_PIXBUF_ROTATE_NONE; - ddjvu_page_rotation_t ddjvu_angle = DDJVU_ROTATE_0; - - switch(Zathura.document->rotate) { - case 90: - gdk_angle = GDK_PIXBUF_ROTATE_CLOCKWISE; - ddjvu_angle = DDJVU_ROTATE_90; - break; - case 180: - gdk_angle = GDK_PIXBUF_ROTATE_UPSIDEDOWN; - ddjvu_angle = DDJVU_ROTATE_180; - break; - case 270: - gdk_angle = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE; - ddjvu_angle = DDJVU_ROTATE_270; - break; - default: - gdk_angle = GDK_PIXBUF_ROTATE_NONE; - ddjvu_angle = DDJVU_ROTATE_0; - break; - } - - ddjvu_page_set_rotation(djvu_page, ddjvu_angle); + ddjvu_page_set_rotation(djvu_page, DDJVU_ROTATE_0); /* render page */ ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, - 3 * page_width, (char*) buffer); + 3 * page_width, (char*) image_buffer); - /* create pixbuf */ - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8, - page_width, page_height, 3 * page_width, NULL, NULL); - - if (!pixbuf) { - goto error_free; - } - - /* rotate page */ - if (Zathura.document->rotate != 0) { - GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, gdk_angle); - if (!pixbuf_temp) { - goto error_free; - } - - pixbuf = pixbuf_temp; - } - - GtkWidget* image = gtk_image_new(); - - if (!image) { - goto error_free; - } - - gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); - gtk_widget_show(image); - - ddjvu_page_release(djvu_page); - - return image; + return image_buffer; error_free: ddjvu_page_release(djvu_page); - free(buffer); - g_object_unref(pixbuf); + zathura_image_buffer_free(image_buffer); error_out: diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index a676826..bb760c4 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -191,11 +191,10 @@ pdf_page_render(zathura_page_t* page) page_height = dim_temp; } - /* create pixbuf */ - GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, - page_width, page_height); + /* create image buffer */ + zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); - if (!pixbuf) { + if (image_buffer == NULL) { return NULL; } @@ -221,10 +220,6 @@ pdf_page_render(zathura_page_t* page) ctm = fz_concat(ctm, fz_rotate(Zathura.document->rotate)); fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); - guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); - int rowstride = gdk_pixbuf_get_rowstride(pixbuf); - int n_channels = gdk_pixbuf_get_n_channels(pixbuf); - fz_pixmap* pixmap = fz_newpixmapwithrect(fz_devicergb, bbox); fz_clearpixmapwithcolor(pixmap, 0xFF); @@ -235,7 +230,7 @@ pdf_page_render(zathura_page_t* page) for (unsigned int y = 0; y < pixmap->h; y++) { for (unsigned int x = 0; x < pixmap->w; x++) { unsigned char *s = pixmap->samples + y * pixmap->w * 4 + x * 4; - guchar* p = pixels + y * rowstride + x * n_channels; + guchar* p = image_buffer->data + y * image_buffer->width + x; p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; @@ -245,16 +240,5 @@ pdf_page_render(zathura_page_t* page) fz_droppixmap(pixmap); fz_freedisplaylist(display_list); - /* write pixbuf */ - GtkWidget* image = gtk_image_new(); - - if (!image) { - g_object_unref(pixbuf); - return NULL; - } - - gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); - gtk_widget_show(image); - - return image; + return image_buffer; } diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index 8415468..fadf9cc 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -261,34 +261,41 @@ pdf_page_render(zathura_page_t* page) unsigned int page_width = Zathura.document->scale * page->width; unsigned int page_height = Zathura.document->scale * page->height; - if (Zathura.document->rotate == 90 || Zathura.document->rotate == 270) { - unsigned int dim_temp = 0; - dim_temp = page_width; - page_width = page_height; - page_height = dim_temp; - } - /* create pixbuf */ GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, page_width, page_height); - if (!pixbuf) { + if (pixbuf == NULL) { return NULL; } - poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, Zathura.document->scale, - Zathura.document->rotate, pixbuf); + poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, + Zathura.document->scale, 90, pixbuf); - /* write pixbuf */ - GtkWidget* image = gtk_image_new(); + /* create image buffer */ + zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); - if (!image) { + if (image_buffer == NULL) { g_object_unref(pixbuf); return NULL; } - gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); - gtk_widget_show(image); + /* copy buffer */ + guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); + int rowstride = gdk_pixbuf_get_rowstride(pixbuf); + int n_channels = gdk_pixbuf_get_n_channels(pixbuf); - return image; + for (unsigned int y = 0; y < page_height; y++) { + for (unsigned int x = 0; x < page_width; x++) { + unsigned char *s = pixels + y * rowstride + x * n_channels; + guchar* p = image_buffer->data + y * image_buffer->width + x; + p[0] = s[0]; + p[1] = s[1]; + p[2] = s[2]; + } + } + + g_object_unref(pixbuf); + + return image_buffer; } From dd973877159fbb872c780ca8f051b7e4f047b4dc Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 18 Mar 2011 18:40:20 +0100 Subject: [PATCH 083/197] Began to implement dual/multiple view --- callbacks.c | 19 ++++++++------ config.c | 4 ++- document.c | 9 +++---- document.h | 2 +- render.c | 43 ++++++++++-------------------- shortcuts.c | 7 ++--- zathura.c | 75 ++++++++++++++++++++++++++++++++++++++++++++--------- zathura.h | 12 +++++++++ 8 files changed, 110 insertions(+), 61 deletions(-) diff --git a/callbacks.c b/callbacks.c index d8384bf..e6b03ae 100644 --- a/callbacks.c +++ b/callbacks.c @@ -46,9 +46,10 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) return; } + // FIXME /* get current adjustment values */ - gdouble lower = gtk_adjustment_get_value(adjustment); - gdouble upper = lower + gtk_adjustment_get_page_size(adjustment); + /*gdouble lower = gtk_adjustment_get_value(adjustment);*/ + /*gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);*/ /* find page that fits */ for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) @@ -60,14 +61,16 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) continue; } - double begin = page->offset; - double end = page->offset + page->height; + /*double begin = page->offset;*/ + /*double end = page->offset + page->height;*/ - if ( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */ - || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */ - || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */ - ) { + /*if ( ( (begin >= lower) && (end <= upper) ) [> page is in viewport <]*/ + /*|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) [> end of the page is in viewport <]*/ + /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ + /*) {*/ + if (page_id < 5) { render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); } + /*}*/ } } diff --git a/config.c b/config.c index 70b4543..e45454f 100644 --- a/config.c +++ b/config.c @@ -18,7 +18,9 @@ config_load_default(void) /* zathura settings */ int_value = 10; - girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + int_value = 2; + girara_setting_add(Zathura.UI.session, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL); /* define default shortcuts */ girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); diff --git a/document.c b/document.c index b1d0e4f..fb6901d 100644 --- a/document.c +++ b/document.c @@ -239,16 +239,12 @@ zathura_document_open(const char* path, const char* password) goto error_free; } - double offset = 0; for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_t* page = zathura_page_get(document, page_id); if (!page) { goto error_free; } - page->offset = offset; - offset += page->height; - document->pages[page_id] = page; } @@ -389,8 +385,9 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) zathura_page_t* page = document->functions.page_get(document, page_id); if (page) { - page->number = page_id; - page->rendered = false; + page->number = page_id; + page->rendered = false; + page->event_box = gtk_event_box_new(); g_static_mutex_init(&(page->lock)); } diff --git a/document.h b/document.h index f05ee68..5f48fae 100644 --- a/document.h +++ b/document.h @@ -142,11 +142,11 @@ typedef struct zathura_page_s { double height; /**> Page height */ double width; /**> Page width */ - double offset; /**> Page offset */ unsigned int number; /**> Page number */ zathura_document_t* document; /**> Document */ void* data; /**> Custom data */ bool rendered; /**> Page has been rendered */ + GtkWidget* event_box; /**> Widget wrapper */ GStaticMutex lock; /**> Lock */ } zathura_page_t; diff --git a/render.c b/render.c index c163638..fccf2bf 100644 --- a/render.c +++ b/render.c @@ -20,10 +20,8 @@ render_job(void* data) girara_list_remove(render_thread->list, page); g_mutex_unlock(render_thread->lock); - gdk_threads_enter(); render(page); printf("Rendered %d\n", page->number); - gdk_threads_leave(); } return NULL; @@ -131,48 +129,33 @@ render_page(render_thread_t* render_thread, zathura_page_t* page) bool render(zathura_page_t* page) { + gdk_threads_enter(); g_static_mutex_lock(&(page->lock)); zathura_image_buffer_t* buffer = zathura_page_render(page); if (!buffer) { g_static_mutex_unlock(&(page->lock)); printf("error: rendering failed\n"); + gdk_threads_leave(); return false; } - /* add new page */ - GList* list = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); - GtkWidget* widget = (GtkWidget*) g_list_nth_data(list, page->number); - g_list_free(list); + /* create drawing area */ + /*GtkWidget* drawing_area = gtk_drawing_area_new();*/ - if (!widget) { - g_static_mutex_unlock(&(page->lock)); - printf("error: page container does not exist\n"); - // TODO: zathura_image_buffer_free(image); - return false; - } + /*[> remove old image <]*/ + /*GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box));*/ + /*if (widget != NULL) {*/ + /*g_object_unref(widget);*/ + /*}*/ - /* child packaging information */ - gboolean expand; - gboolean fill; - guint padding; - GtkPackType pack_type; + /*[> set new image <]*/ + /*gtk_box_pack_start(GTK_BOX(page->event_box), drawing_area, TRUE, TRUE, 0);*/ - gtk_box_query_child_packing(GTK_BOX(Zathura.UI.page_view), widget, &expand, &fill, &padding, &pack_type); - - /* delete old widget */ - gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); - - /* add new widget */ - // TODO: gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); - - /* set old packaging values */ - // TODO: gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); - - /* reorder child */ - // TODO: gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + zathura_image_buffer_free(buffer); g_static_mutex_unlock(&(page->lock)); + gdk_threads_leave(); return true; } diff --git a/shortcuts.c b/shortcuts.c index aa8b664..3a8ce74 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -88,9 +88,10 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) unsigned int number_of_pages = Zathura.document->number_of_pages; if (t > 0 && t <= number_of_pages) { - GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); - unsigned int offset = Zathura.document->pages[t - 1]->offset * Zathura.document->scale; - gtk_adjustment_set_value(adjustment, offset); + // TODO: Calculate offset + /*GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view));*/ + /*unsigned int offset = Zathura.document->pages[t - 1]->offset * Zathura.document->scale;*/ + /*gtk_adjustment_set_value(adjustment, offset);*/ } } diff --git a/zathura.c b/zathura.c index 90e07ee..86d73d2 100644 --- a/zathura.c +++ b/zathura.c @@ -100,19 +100,14 @@ document_open(const char* path, const char* password) Zathura.document = document; - /* create blank pages */ - for (unsigned int i = 0; i < document->number_of_pages; i++) - { - /* create blank page */ - GtkWidget* image = page_blank(document->pages[i]->width, document->pages[i]->height); + /* init view */ + create_blank_pages(); - if (!image) { - goto error_free; - } - - /* pack to page view */ - gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 1); - } + /* view mode */ + int* value = girara_setting_get(Zathura.UI.session, "pages-per-row"); + int pages_per_row = (value) ? *value : 1; + free(value); + page_view_set_mode(pages_per_row); girara_set_view(Zathura.UI.session, Zathura.UI.page_view); @@ -190,6 +185,62 @@ error_out: return false; } +void +page_view_set_mode(unsigned int pages_per_row) +{ + gdk_threads_enter(); + + /* empty page view */ + GList* container = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); + for (GList* child = container; child; child = g_list_next(child)) { + gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), child->data); + } + + GtkWidget* row = NULL; + + /* create blank pages */ + for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++) + { + if (i % pages_per_row == 0) { + row = gtk_hbox_new(FALSE, 0); + } + + /* pack row */ + gtk_box_pack_start(GTK_BOX(row), Zathura.document->pages[i]->event_box, FALSE, FALSE, 1); + + /* pack row to page view */ + if ((i + 1) % pages_per_row == 0) { + gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), row, FALSE, FALSE, 1); + } + } + + gtk_widget_show_all(Zathura.UI.page_view); + gdk_threads_leave(); +} + +void +create_blank_pages() +{ + /* create blank pages */ + for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++) + { + zathura_page_t* page = Zathura.document->pages[i]; + g_static_mutex_lock(&(page->lock)); + + /* create blank page */ + GtkWidget* image = page_blank(page->width, page->height); + + if (!image) { + g_static_mutex_unlock(&(page->lock)); + continue; + } + + /* pack to page view */ + gtk_container_add(GTK_CONTAINER(page->event_box), image); + g_static_mutex_unlock(&(page->lock)); + } +} + /* main function */ int main(int argc, char* argv[]) { diff --git a/zathura.h b/zathura.h index 3052e32..5378480 100644 --- a/zathura.h +++ b/zathura.h @@ -80,4 +80,16 @@ bool document_close(); */ bool page_set(unsigned int page_id); +/** + * Builds the box structure to show the rendered pages + * + * @param pages_per_row Number of shown pages per row + */ +void page_view_set_mode(unsigned int pages_per_row); + +/** + * Create blank pages + */ +void create_blank_pages(); + #endif // ZATHURA_H From 43a89cc2f84938840786285fcab558a382ff5108 Mon Sep 17 00:00:00 2001 From: Johannes Meng Date: Sat, 19 Mar 2011 15:24:50 +0100 Subject: [PATCH 084/197] Fixed uninstall path typo in Makefile. Signed-off-by: Moritz Lipp --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 27daaaa..c0b112f 100644 --- a/Makefile +++ b/Makefile @@ -72,7 +72,7 @@ install: all uninstall: @echo removing executable file - @rm -f ${DESTDIR}${MANPREFIX}/bin/${PROJECT} + @rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT} @echo removing manual page @rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 @make -C ft uninstall From fdeb73436aacdaf1cc5d58250c947c4c59ed3422 Mon Sep 17 00:00:00 2001 From: Johannes Meng Date: Sat, 19 Mar 2011 15:26:13 +0100 Subject: [PATCH 085/197] Fixed plugin file type determination to be more fs-independent. Signed-off-by: Moritz Lipp --- document.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/document.c b/document.c index 48d97d1..a67ea43 100644 --- a/document.c +++ b/document.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -32,22 +33,23 @@ zathura_document_plugins_load(void) struct dirent* entry; while ((entry = readdir(dir)) != NULL) { - /* check if entry is a file */ - if (entry->d_type != 0x8) { - continue; - } - void* handle = NULL; zathura_document_plugin_t* plugin = NULL; char* path = NULL; + struct stat fstat; /* get full path */ path = string_concat(PLUGIN_DIR, "/", entry->d_name, NULL); - if (path == NULL) { + if (path == NULL || stat(path, &fstat) != 0) { goto error_continue; } + /* check if entry is a file. */ + if (!(fstat.st_mode & S_IFREG)) { + continue; + } + /* load plugin */ handle = dlopen(path, RTLD_NOW); From e5d0b6bac0e6ff27567cb84cd9bc55383d8a4dad Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 20 Mar 2011 01:43:02 +0100 Subject: [PATCH 086/197] Remove wrong threads_enter/leave --- zathura.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/zathura.c b/zathura.c index 86d73d2..2bdc7ff 100644 --- a/zathura.c +++ b/zathura.c @@ -188,8 +188,6 @@ error_out: void page_view_set_mode(unsigned int pages_per_row) { - gdk_threads_enter(); - /* empty page view */ GList* container = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); for (GList* child = container; child; child = g_list_next(child)) { @@ -215,7 +213,6 @@ page_view_set_mode(unsigned int pages_per_row) } gtk_widget_show_all(Zathura.UI.page_view); - gdk_threads_leave(); } void From c5491675aa41eb6c283166a4a46fd0eeae8a9487 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 20 Mar 2011 02:09:04 +0100 Subject: [PATCH 087/197] Update rendering --- callbacks.c | 2 +- document.c | 5 +++-- document.h | 1 + render.c | 54 +++++++++++++++++++++++++++++++++++++++-------------- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/callbacks.c b/callbacks.c index e6b03ae..f90d632 100644 --- a/callbacks.c +++ b/callbacks.c @@ -68,7 +68,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) /*|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) [> end of the page is in viewport <]*/ /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ /*) {*/ - if (page_id < 5) { + if (page_id < 1) { render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); } /*}*/ diff --git a/document.c b/document.c index fb6901d..7af7f23 100644 --- a/document.c +++ b/document.c @@ -537,8 +537,9 @@ zathura_image_buffer_create(unsigned int width, unsigned int height) return NULL; } - image_buffer->width = width; - image_buffer->height = height; + image_buffer->width = width; + image_buffer->height = height; + image_buffer->rowstride = width * 3; return image_buffer; } diff --git a/document.h b/document.h index 5f48fae..c39d8e1 100644 --- a/document.h +++ b/document.h @@ -51,6 +51,7 @@ typedef struct zathura_image_buffer_s unsigned char* data; /**> Image buffer data */ unsigned int height; /**> Height of the image */ unsigned int width; /**> Width of the image */ + unsigned int rowstride; /**> Rowstride of the image */ } zathura_image_buffer_t; /** diff --git a/render.c b/render.c index fccf2bf..61fd660 100644 --- a/render.c +++ b/render.c @@ -20,7 +20,10 @@ render_job(void* data) girara_list_remove(render_thread->list, page); g_mutex_unlock(render_thread->lock); - render(page); + if (render(page) != true) { + fprintf(stderr, "rendering failed\n"); + } + printf("Rendered %d\n", page->number); } @@ -131,28 +134,51 @@ render(zathura_page_t* page) { gdk_threads_enter(); g_static_mutex_lock(&(page->lock)); - zathura_image_buffer_t* buffer = zathura_page_render(page); + zathura_image_buffer_t* image_buffer = zathura_page_render(page); - if (!buffer) { + if (image_buffer == NULL) { g_static_mutex_unlock(&(page->lock)); - printf("error: rendering failed\n"); gdk_threads_leave(); return false; } - /* create drawing area */ - /*GtkWidget* drawing_area = gtk_drawing_area_new();*/ + /* remove old image */ + GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box)); + if (widget != NULL) { + gtk_container_remove(GTK_CONTAINER(page->event_box), widget); + } - /*[> remove old image <]*/ - /*GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box));*/ - /*if (widget != NULL) {*/ - /*g_object_unref(widget);*/ - /*}*/ + /* create cairo surface */ + unsigned int page_width = page->width * Zathura.document->scale; + unsigned int page_height = page->height * Zathura.document->scale; - /*[> set new image <]*/ - /*gtk_box_pack_start(GTK_BOX(page->event_box), drawing_area, TRUE, TRUE, 0);*/ + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height); - zathura_image_buffer_free(buffer); + int rowstride = cairo_image_surface_get_stride(surface); + unsigned char* image = cairo_image_surface_get_data(surface); + + for (unsigned int y = 0; y < page_height; y++) { + unsigned char* dst = image + y * rowstride; + unsigned char* src = image_buffer->data + y * image_buffer->rowstride; + + for (unsigned int x = 0; x < page_width; x++) { + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + dst += 3; + } + } + + /* draw to gtk widget */ + GtkWidget* drawing_area = gtk_drawing_area_new(); + gtk_container_add(GTK_CONTAINER(page->event_box), drawing_area); + + cairo_t* cairo = gdk_cairo_create(drawing_area->window); + cairo_set_source_surface(cairo, surface, 0, 0); + cairo_paint(cairo); + cairo_destroy(cairo); + + zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); gdk_threads_leave(); From 801fe030099374e56b0644570cd5673a718ca686 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 20 Mar 2011 02:53:24 +0100 Subject: [PATCH 088/197] Changed the strucure a bit --- document.c | 10 +++++++--- document.h | 3 ++- render.c | 5 +---- zathura.c | 14 +++++--------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/document.c b/document.c index 7af7f23..99a41fb 100644 --- a/document.c +++ b/document.c @@ -385,9 +385,13 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) zathura_page_t* page = document->functions.page_get(document, page_id); if (page) { - page->number = page_id; - page->rendered = false; - page->event_box = gtk_event_box_new(); + page->number = page_id; + page->rendered = false; + page->event_box = gtk_event_box_new(); + page->drawing_area = gtk_drawing_area_new(); + + gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); + g_static_mutex_init(&(page->lock)); } diff --git a/document.h b/document.h index c39d8e1..5fb78e2 100644 --- a/document.h +++ b/document.h @@ -147,7 +147,8 @@ typedef struct zathura_page_s zathura_document_t* document; /**> Document */ void* data; /**> Custom data */ bool rendered; /**> Page has been rendered */ - GtkWidget* event_box; /**> Widget wrapper */ + GtkWidget* event_box; /**> Widget wrapper for mouse events */ + GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ } zathura_page_t; diff --git a/render.c b/render.c index 61fd660..02208b7 100644 --- a/render.c +++ b/render.c @@ -170,10 +170,7 @@ render(zathura_page_t* page) } /* draw to gtk widget */ - GtkWidget* drawing_area = gtk_drawing_area_new(); - gtk_container_add(GTK_CONTAINER(page->event_box), drawing_area); - - cairo_t* cairo = gdk_cairo_create(drawing_area->window); + cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); cairo_set_source_surface(cairo, surface, 0, 0); cairo_paint(cairo); cairo_destroy(cairo); diff --git a/zathura.c b/zathura.c index 2bdc7ff..df916b2 100644 --- a/zathura.c +++ b/zathura.c @@ -224,16 +224,12 @@ create_blank_pages() zathura_page_t* page = Zathura.document->pages[i]; g_static_mutex_lock(&(page->lock)); - /* create blank page */ - GtkWidget* image = page_blank(page->width, page->height); + cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); + cairo_set_source_rgb(cairo, 1, 1, 1); + cairo_rectangle(cairo, 0, 0, page->width, page->height); + cairo_fill(cairo); + cairo_destroy(cairo); - if (!image) { - g_static_mutex_unlock(&(page->lock)); - continue; - } - - /* pack to page view */ - gtk_container_add(GTK_CONTAINER(page->event_box), image); g_static_mutex_unlock(&(page->lock)); } } From 3335e71ed8642f20a3d241a066a6b76b17ff16a5 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 1 Apr 2011 09:55:37 +0200 Subject: [PATCH 089/197] Load configuration files --- config.c | 17 ++++++++++++++++- config.h | 11 +++++++++++ zathura.c | 10 ++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 70b4543..6863269 100644 --- a/config.c +++ b/config.c @@ -4,6 +4,7 @@ #include "completion.h" #include "shortcuts.h" #include "zathura.h" +#include "config.h" void config_load_default(void) @@ -11,15 +12,19 @@ config_load_default(void) if (!Zathura.UI.session) return; - int int_value = 0; + int int_value = 0; + char* string_value = NULL; /* general settings */ girara_mode_set(Zathura.UI.session, NORMAL); /* zathura settings */ + string_value = CONFIG_DIR; + girara_setting_add(Zathura.UI.session, "config-dir", string_value, STRING, true, "Configuration directory", NULL); int_value = 10; girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + /* define default shortcuts */ girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL); @@ -91,3 +96,13 @@ config_load_default(void) girara_inputbar_command_add(Zathura.UI.session, "print", NULL, cmd_print, cc_print, "Print document"); girara_inputbar_command_add(Zathura.UI.session, "save", NULL, cmd_save, NULL, "Save document"); } + +void +config_load_file(char* path) +{ + if (Zathura.UI.session == NULL) { + return; + } + + girara_config_parse(Zathura.UI.session, path); +} diff --git a/config.h b/config.h index a3a03e7..42344f3 100644 --- a/config.h +++ b/config.h @@ -3,9 +3,20 @@ #ifndef CONFIG_H #define CONFIG_H +#define GLOBAL_RC "/etc/zathurarc" +#define ZATHURA_RC "zathurarc" +#define CONFIG_DIR "~/.config/zathura" + /** * This function loads the default values of the configuration */ void config_load_default(void); +/** + * Loads and evaluates a configuration file + * + * @param path Path to the configuration file + */ +void config_load_file(char* path); + #endif // CONFIG_H diff --git a/zathura.c b/zathura.c index 90e07ee..1947439 100644 --- a/zathura.c +++ b/zathura.c @@ -70,6 +70,16 @@ init_zathura() /* configuration */ config_load_default(); + /* load global configuration files */ + config_load_file(GLOBAL_RC); + + /* load local configuration files */ + char* config_dir = girara_setting_get(Zathura.UI.session, "config-dir"); + char* configuration_file = g_build_filename(config_dir ? config_dir : CONFIG_DIR, ZATHURA_RC, NULL); + config_load_file(configuration_file); + free(config_dir); + free(configuration_file); + return true; error_free: From 15d51567aa4a445d9fcd002886d3d132c8428252 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 2 Apr 2011 23:40:57 +0200 Subject: [PATCH 090/197] Use girara debug functions --- document.c | 40 +++++++++++++++++++--------------------- render.c | 6 +++--- utils.c | 11 +++++------ zathura.c | 4 ++-- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/document.c b/document.c index a67ea43..e79a4cc 100644 --- a/document.c +++ b/document.c @@ -27,7 +27,7 @@ zathura_document_plugins_load(void) /* read all files in the plugin directory */ DIR* dir = opendir(PLUGIN_DIR); if (dir == NULL) { - fprintf(stderr, "error: could not open plugin directory: %s\n", PLUGIN_DIR); + girara_error("Could not open plugin directory: %s", PLUGIN_DIR); return; } @@ -54,7 +54,7 @@ zathura_document_plugins_load(void) handle = dlopen(path, RTLD_NOW); if (handle == NULL) { - fprintf(stderr, "error: could not load plugin (%s)\n", dlerror()); + girara_error("Could not load plugin (%s)", dlerror()); goto error_free; } @@ -63,7 +63,7 @@ zathura_document_plugins_load(void) *(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION); if (register_plugin == NULL) { - fprintf(stderr, "error: could not find '%s' function in the plugin\n", PLUGIN_REGISTER_FUNCTION); + girara_error("Could not find '%s' in plugin", PLUGIN_REGISTER_FUNCTION); goto error_free; } @@ -81,7 +81,7 @@ zathura_document_plugins_load(void) bool r = zathura_document_plugin_register(plugin, handle); if (r == false) { - fprintf(stderr, "error: could not register plugin (%s)\n", path); + girara_error("Could not register plugin (%s)", path); goto error_free; } @@ -104,7 +104,7 @@ error_continue: } if (closedir(dir) == -1) { - fprintf(stderr, "error: could not close plugin directory: %s\n", PLUGIN_DIR); + girara_error("Could not close plugin directory: %s", PLUGIN_DIR); } } @@ -128,7 +128,6 @@ zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* ha { if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) || (handle == NULL) ) { - fprintf(stderr, "plugin: could not register\n"); return false; } @@ -136,7 +135,7 @@ zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* ha zathura_document_plugin_t* plugin = zathura_document_plugins; while (plugin) { if (!strcmp(plugin->file_extension, new_plugin->file_extension)) { - fprintf(stderr, "plugin: already registered for filetype %s\n", plugin->file_extension); + girara_warning("%s-plugin already registered", plugin->file_extension); return false; } @@ -169,13 +168,13 @@ zathura_document_open(const char* path, const char* password) } if (!file_exists(path)) { - fprintf(stderr, "error: file does not exist\n"); + girara_error("File does not exist"); goto error_out; } const char* file_extension = file_get_extension(path); if (!file_extension) { - fprintf(stderr, "error: could not determine file type\n"); + girara_error("Could not determine file type"); goto error_out; } @@ -256,7 +255,6 @@ zathura_document_open(const char* path, const char* password) return document; } else { - fprintf(stderr, "error: could not open file\n"); goto error_free; } } @@ -265,7 +263,7 @@ zathura_document_open(const char* path, const char* password) plugin = plugin->next; } - fprintf(stderr, "error: unknown file type\n"); + girara_error("Unknown file type"); error_free: @@ -304,7 +302,7 @@ zathura_document_free(zathura_document_t* document) /* free document */ if (!document->functions.document_free) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); if (document->file_path) { free(document->file_path); @@ -333,7 +331,7 @@ zathura_document_save_as(zathura_document_t* document, const char* path) } if (!document->functions.document_save_as) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return false; } @@ -348,7 +346,7 @@ zathura_document_index_generate(zathura_document_t* document) } if (!document->functions.document_index_generate) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -363,7 +361,7 @@ zathura_document_attachments_get(zathura_document_t* document) } if (!document->functions.document_attachments_get) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -384,7 +382,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) } if (!document->functions.page_get) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -407,7 +405,7 @@ zathura_page_free(zathura_page_t* page) } if (!page->document->functions.page_free) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return false; } @@ -422,7 +420,7 @@ zathura_page_search_text(zathura_page_t* page, const char* text) } if (!page->document->functions.page_search_text) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -437,7 +435,7 @@ zathura_page_links_get(zathura_page_t* page) } if (!page->document->functions.page_links_get) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -458,7 +456,7 @@ zathura_page_form_fields_get(zathura_page_t* page) } if (!page->document->functions.page_form_fields_get) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -479,7 +477,7 @@ zathura_page_render(zathura_page_t* page) } if (!page->document->functions.page_render) { - fprintf(stderr, "error: %s not implemented\n", __FUNCTION__); + girara_error("%s not implemented", __FUNCTION__); return NULL; } diff --git a/render.c b/render.c index f863ae7..e8dba53 100644 --- a/render.c +++ b/render.c @@ -22,7 +22,7 @@ render_job(void* data) gdk_threads_enter(); render(page); - printf("Rendered %d\n", page->number); + girara_debug("Rendered %d", page->number); gdk_threads_leave(); } @@ -135,8 +135,8 @@ render(zathura_page_t* page) GtkWidget* image = zathura_page_render(page); if (!image) { + girara_error("Failed to render page %d", page->number); g_static_mutex_unlock(&(page->lock)); - printf("error: rendering failed\n"); return false; } @@ -147,7 +147,7 @@ render(zathura_page_t* page) if (!widget) { g_static_mutex_unlock(&(page->lock)); - printf("error: page container does not exist\n"); + girara_error("Page container does not exist"); g_object_unref(image); return false; } diff --git a/utils.c b/utils.c index 79494f8..85863cd 100644 --- a/utils.c +++ b/utils.c @@ -168,13 +168,12 @@ page_blank(unsigned int width, unsigned int height) void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree) { - girara_list_t* list = girara_node_get_children(tree); - girara_list_iterator_t* it = girara_list_iterator(list); + /*girara_list_t* list = girara_node_get_children(tree);*/ + /*girara_list_iterator_t* it = girara_list_iterator(list);*/ - do { - zathura_index_element_t* index_element = (zathura_index_element_t*) girara_list_iterator_data(it); - printf("%s\n", index_element->title); - } while ((it = girara_list_iterator_next(it))); + /*do {*/ + /*zathura_index_element_t* index_element = (zathura_index_element_t*) girara_list_iterator_data(it);*/ + /*} while ((it = girara_list_iterator_next(it)));*/ } char* string_concat(const char* string1, ...) diff --git a/zathura.c b/zathura.c index 1947439..d0c41be 100644 --- a/zathura.c +++ b/zathura.c @@ -208,13 +208,13 @@ int main(int argc, char* argv[]) gtk_init(&argc, &argv); if (!init_zathura()) { - printf("error: coult not initialize zathura\n"); + girara_error("Coult not initialize zathura\n"); return -1; } if (argc > 1) { if (!document_open(argv[1], NULL)) { - printf("error: could not open document\n"); + girara_error("Failed to open document\n"); return -1; } } From aac703778f9b1b0deaf22117ace368f15b58d52c Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 4 Apr 2011 16:02:38 +0200 Subject: [PATCH 091/197] Make it build with BSD make. Ported changes from girara. --- BSDmakefile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 BSDmakefile diff --git a/BSDmakefile b/BSDmakefile new file mode 100644 index 0000000..362214d --- /dev/null +++ b/BSDmakefile @@ -0,0 +1,9 @@ +# See LICENSE file for license and copyright information + +all ${.TARGETS}: + @if [ ! `which gmake` ] ; then \ + echo "zathura cannot be built with BSD make and GNU make cannot be found." \ + "Please install GNU make."; \ + exit 1; \ + fi + @gmake $@ From a98f69c3f30369095e7fde438761973f094dfa23 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 11:31:57 +0200 Subject: [PATCH 092/197] add .PHONY in Makefile --- Makefile | 14 ++++++++------ ft/Makefile | 2 ++ ft/djvu/Makefile | 2 ++ ft/pdf-mupdf/Makefile | 2 ++ ft/pdf-poppler/Makefile | 2 ++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c0b112f..ca8eab6 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) all: options ${PROJECT} - make -C ft + ${MAKE} -C ft options: @echo ${PROJECT} build options: @@ -35,14 +35,14 @@ ${PROJECT}: ${OBJECTS} clean: @rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ ${DOBJECTS} ${PROJECT}-debug - make -C ft clean + @${MAKE} -C ft clean ${PROJECT}-debug: ${DOBJECTS} @echo CC -o ${PROJECT}-debug @${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS} debug: ${PROJECT}-debug - make -C ft debug + @${MAKE} -C ft debug valgrind: debug valgrind --tool=memcheck --leak-check=yes --show-reachable=yes \ @@ -52,7 +52,7 @@ gdb: debug cgdb ${PROJECT}-debug dist: clean - @mkdir -p ${PROJECT}-${VERSION} + @${MAKE} -p ${PROJECT}-${VERSION} @cp -R LICENSE Makefile config.mk README \ ${PROJECT}.1 ${SOURCE} ${PROJECT}-${VERSION} @tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION} @@ -68,11 +68,13 @@ install: all @mkdir -p ${DESTDIR}${MANPREFIX}/man1 @sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 - @make -C ft install + @${MAKE} -C ft install uninstall: @echo removing executable file @rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT} @echo removing manual page @rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 - @make -C ft uninstall + @${MAKE} -C ft uninstall + +.PHONY: all options clean debug valgrind gdb dist install uninstall diff --git a/ft/Makefile b/ft/Makefile index 324326f..254eeb4 100644 --- a/ft/Makefile +++ b/ft/Makefile @@ -16,3 +16,5 @@ install: uninstall: @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} uninstall; done + +.PHONY: all debug clean install uninstall diff --git a/ft/djvu/Makefile b/ft/djvu/Makefile index d5e7617..a08e271 100644 --- a/ft/djvu/Makefile +++ b/ft/djvu/Makefile @@ -49,3 +49,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +.PHONY: all options clean debug install uninstall diff --git a/ft/pdf-mupdf/Makefile b/ft/pdf-mupdf/Makefile index e14ed8c..16afa5a 100644 --- a/ft/pdf-mupdf/Makefile +++ b/ft/pdf-mupdf/Makefile @@ -49,3 +49,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +.PHONY: all options clean debug install uninstall diff --git a/ft/pdf-poppler/Makefile b/ft/pdf-poppler/Makefile index e14ed8c..16afa5a 100644 --- a/ft/pdf-poppler/Makefile +++ b/ft/pdf-poppler/Makefile @@ -49,3 +49,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +.PHONY: all options clean debug install uninstall From cfb2580b7b553dff1fc3512f7d31864dd17476ae Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:03:08 +0200 Subject: [PATCH 093/197] Return value for create_blank_pages --- zathura.c | 17 +++++++++++++++-- zathura.h | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/zathura.c b/zathura.c index df916b2..86d9dc3 100644 --- a/zathura.c +++ b/zathura.c @@ -2,6 +2,8 @@ #include +#include + #include "callbacks.h" #include "config.h" #include "document.h" @@ -101,7 +103,9 @@ document_open(const char* path, const char* password) Zathura.document = document; /* init view */ - create_blank_pages(); + if (create_blank_pages() == false) { + return false; + } /* view mode */ int* value = girara_setting_get(Zathura.UI.session, "pages-per-row"); @@ -215,7 +219,7 @@ page_view_set_mode(unsigned int pages_per_row) gtk_widget_show_all(Zathura.UI.page_view); } -void +bool create_blank_pages() { /* create blank pages */ @@ -225,6 +229,13 @@ create_blank_pages() g_static_mutex_lock(&(page->lock)); cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); + + if (cairo == NULL) { + girara_error("Could not create blank page"); + g_static_mutex_unlock(&(page->lock)); + return false; + } + cairo_set_source_rgb(cairo, 1, 1, 1); cairo_rectangle(cairo, 0, 0, page->width, page->height); cairo_fill(cairo); @@ -232,6 +243,8 @@ create_blank_pages() g_static_mutex_unlock(&(page->lock)); } + + return true; } /* main function */ diff --git a/zathura.h b/zathura.h index 5378480..fc59099 100644 --- a/zathura.h +++ b/zathura.h @@ -89,7 +89,9 @@ void page_view_set_mode(unsigned int pages_per_row); /** * Create blank pages + * + * @return false if an error occured, otherwise true */ -void create_blank_pages(); +bool create_blank_pages(); #endif // ZATHURA_H From db832069ea31f0e00a3c40f73a27636f255a03e6 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 17:22:44 +0200 Subject: [PATCH 094/197] replace global Zathura object with zathura session --- config.c | 148 ++++++++++++++++++++++++++++--------------------------- config.h | 4 +- 2 files changed, 78 insertions(+), 74 deletions(-) diff --git a/config.c b/config.c index e45454f..aaedab2 100644 --- a/config.c +++ b/config.c @@ -1,95 +1,97 @@ /* See LICENSE file for license and copyright information */ +#include "config.h" #include "commands.h" #include "completion.h" #include "shortcuts.h" -#include "zathura.h" void -config_load_default(void) +config_load_default(zathura_t* zathura) { - if (!Zathura.UI.session) + if (zathura || !session->UI.session) { return; + } int int_value = 0; + girara_session_t* gsession = zathura->ui.session; /* general settings */ - girara_mode_set(Zathura.UI.session, NORMAL); + girara_mode_set(gsession, NORMAL); /* zathura settings */ int_value = 10; - girara_setting_add(Zathura.UI.session, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + girara_setting_add(gsession, "zoom-step", &int_value, INT, false, "Zoom step", NULL); int_value = 2; - girara_setting_add(Zathura.UI.session, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL); + girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL); /* define default shortcuts */ - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, 0, DELETE_LAST, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(Zathura.UI.session, GDK_SHIFT_MASK, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_O, NULL, sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); - girara_shortcut_add(Zathura.UI.session, 0, GDK_f, NULL, sc_follow, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "gg", sc_goto, NORMAL | FULLSCREEN, TOP, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "G", sc_goto, NORMAL | FULLSCREEN, BOTTOM, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_J, NULL, sc_navigate, NORMAL, NEXT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_K, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_MOD1_MASK, GDK_Right, NULL, sc_navigate, NORMAL, NEXT, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_MOD1_MASK, GDK_Left, NULL, sc_navigate, NORMAL, PREVIOUS, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Left, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Up, NULL, sc_navigate, FULLSCREEN, PREVIOUS, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Down, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Right, NULL, sc_navigate, FULLSCREEN, NEXT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_k, NULL, sc_navigate_index, INDEX, UP, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_j, NULL, sc_navigate_index, INDEX, DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_h, NULL, sc_navigate_index, INDEX, COLLAPSE, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_l, NULL, sc_navigate_index, INDEX, EXPAND, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_navigate_index, INDEX, SELECT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Return, NULL, sc_navigate_index, INDEX, SELECT, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_i, NULL, sc_recolor, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_R, NULL, sc_reload, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_r, NULL, sc_rotate, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_h, NULL, sc_scroll, NORMAL, LEFT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_j, NULL, sc_scroll, NORMAL, DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_k, NULL, sc_scroll, NORMAL, UP, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_l, NULL, sc_scroll, NORMAL, RIGHT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Left, NULL, sc_scroll, NORMAL, LEFT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Up, NULL, sc_scroll, NORMAL, DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Down, NULL, sc_scroll, NORMAL, RIGHT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Right, NULL, sc_scroll, NORMAL, UP, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_d, NULL, sc_scroll, NORMAL, HALF_DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_u, NULL, sc_scroll, NORMAL, HALF_UP, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_f, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_n, NULL, sc_search, NORMAL, FORWARD, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_N, NULL, sc_search, NORMAL, BACKWARD, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Tab, NULL, sc_toggle_index, NORMAL | INDEX, 0, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_m, NULL, sc_toggle_inputbar, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_F5, NULL, sc_toggle_fullscreen, NORMAL | FULLSCREEN, 0, NULL); - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_n, NULL, sc_toggle_statusbar, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_q, NULL, sc_quit, NORMAL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_plus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_minus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_equal, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "zI", sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "zO", sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); + 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_BackSpace, NULL, sc_change_buffer, 0, DELETE_LAST, 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, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, 0, GDK_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); + girara_shortcut_add(gsession, 0, GDK_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); + girara_shortcut_add(gsession, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); + girara_shortcut_add(gsession, 0, GDK_O, NULL, 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 | FULLSCREEN, TOP, NULL); + girara_shortcut_add(gsession, 0, 0, "G", sc_goto, NORMAL | 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, DOWN, NULL); + girara_shortcut_add(gsession, 0, GDK_Down, NULL, sc_scroll, NORMAL, RIGHT, NULL); + girara_shortcut_add(gsession, 0, GDK_Right, NULL, sc_scroll, NORMAL, UP, 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, 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 | INDEX, 0, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_m, NULL, sc_toggle_inputbar, NORMAL, 0, NULL); + girara_shortcut_add(gsession, 0, GDK_F5, NULL, sc_toggle_fullscreen, NORMAL | FULLSCREEN, 0, NULL); + girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_n, NULL, 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 | FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, GDK_minus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, GDK_equal, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); /* define default inputbar commands */ - girara_inputbar_command_add(Zathura.UI.session, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark"); - girara_inputbar_command_add(Zathura.UI.session, "bdelete", NULL, cmd_bookmark_delete, NULL, "Delete a bookmark"); - girara_inputbar_command_add(Zathura.UI.session, "blist", NULL, cmd_bookmark_open, NULL, "List all bookmarks"); - girara_inputbar_command_add(Zathura.UI.session, "close", NULL, cmd_close, NULL, "Close current file"); - girara_inputbar_command_add(Zathura.UI.session, "info", NULL, cmd_info, NULL, "Show file information"); - girara_inputbar_command_add(Zathura.UI.session, "print", NULL, cmd_print, cc_print, "Print document"); - girara_inputbar_command_add(Zathura.UI.session, "save", NULL, cmd_save, NULL, "Save document"); + girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark"); + girara_inputbar_command_add(gsession, "bdelete", NULL, cmd_bookmark_delete, NULL, "Delete a bookmark"); + girara_inputbar_command_add(gsession, "blist", NULL, cmd_bookmark_open, NULL, "List all bookmarks"); + girara_inputbar_command_add(gsession, "close", NULL, cmd_close, NULL, "Close current file"); + girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, "Show file information"); + girara_inputbar_command_add(gsession, "print", NULL, cmd_print, cc_print, "Print document"); + girara_inputbar_command_add(gsession, "save", NULL, cmd_save, NULL, "Save document"); } diff --git a/config.h b/config.h index a3a03e7..4103598 100644 --- a/config.h +++ b/config.h @@ -3,9 +3,11 @@ #ifndef CONFIG_H #define CONFIG_H +#include "zathura.h" + /** * This function loads the default values of the configuration */ -void config_load_default(void); +void config_load_default(zathura_t* zathura); #endif // CONFIG_H From 87df00fef053579716a97e03abe7cd7663309c5b Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 17:24:19 +0200 Subject: [PATCH 095/197] typo --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index aaedab2..33972f9 100644 --- a/config.c +++ b/config.c @@ -8,7 +8,7 @@ void config_load_default(zathura_t* zathura) { - if (zathura || !session->UI.session) { + if (zathura || !zathura->UI.session) { return; } From 8960b6e83d8137bc4e1eb86ed482e87ca932d796 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:27:49 +0200 Subject: [PATCH 096/197] Updated zathura.h/zathura.c --- callbacks.c | 9 +--- zathura.c | 148 ++++++++++++++++++++++++++++++---------------------- zathura.h | 36 +++++++++---- 3 files changed, 112 insertions(+), 81 deletions(-) diff --git a/callbacks.c b/callbacks.c index f90d632..c16b6c5 100644 --- a/callbacks.c +++ b/callbacks.c @@ -12,14 +12,7 @@ gboolean cb_destroy(GtkWidget* widget, gpointer data) { - if (Zathura.UI.session) { - girara_session_destroy(Zathura.UI.session); - } - - document_close(); - - /* free registered plugins */ - zathura_document_plugins_free(); + zathura_free(data); return TRUE; } diff --git a/zathura.c b/zathura.c index 86d9dc3..f889ae3 100644 --- a/zathura.c +++ b/zathura.c @@ -12,59 +12,65 @@ #include "utils.h" /* function implementation */ -bool -init_zathura() +zathura_t* +zathura_init(int argc, char* argv[]) { + zathura_t* zathura = malloc(sizeof(zathura_t)); + + if (zathura == NULL) { + return NULL; + } + /* UI */ - if (!(Zathura.UI.session = girara_session_create())) { + if ((zathura->ui.session = girara_session_create()) == NULL) { goto error_out; } - if (!girara_session_init(Zathura.UI.session)) { + if (girara_session_init(zathura->ui.session) == false) { goto error_out; } - Zathura.UI.statusbar.file = NULL; - Zathura.UI.statusbar.buffer = NULL; - Zathura.UI.statusbar.page_number = NULL; - Zathura.UI.page_view = NULL; - Zathura.UI.index = NULL; + zathura->ui.statusbar.file = NULL; + zathura->ui.statusbar.buffer = NULL; + zathura->ui.statusbar.page_number = NULL; + zathura->ui.page_view = NULL; + zathura->ui.index = NULL; /* page view */ - Zathura.UI.page_view = gtk_vbox_new(FALSE, 0); - if (!Zathura.UI.page_view) { + zathura->ui.page_view = gtk_vbox_new(FALSE, 0); + if (!zathura->ui.page_view) { goto error_free; } - gtk_widget_show(Zathura.UI.page_view); - gtk_box_set_spacing(GTK_BOX(Zathura.UI.page_view), 0); + gtk_widget_show(zathura->ui.page_view); + gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0); /* statusbar */ - Zathura.UI.statusbar.file = girara_statusbar_item_add(Zathura.UI.session, TRUE, TRUE, TRUE, NULL); - if (!Zathura.UI.statusbar.file) { + zathura->ui.statusbar.file = girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); + if (zathura->ui.statusbar.file == NULL) { goto error_free; } - Zathura.UI.statusbar.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); - if (!Zathura.UI.statusbar.buffer) { + zathura->ui.statusbar.buffer = girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); + if (zathura->ui.statusbar.buffer == NULL) { goto error_free; } - Zathura.UI.statusbar.page_number = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); - if (!Zathura.UI.statusbar.page_number) { + zathura->ui.statusbar.page_number = girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL); + if (!zathura->ui.statusbar.page_number) { goto error_free; } - girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, "[No Name]"); + girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, "[No Name]"); /* signals */ - g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), NULL); /* girara events */ - Zathura.UI.session->events.buffer_changed = buffer_changed; + zathura->ui.session->events.buffer_changed = buffer_changed; /* load plugins */ zathura_document_plugins_load(); @@ -72,23 +78,40 @@ init_zathura() /* configuration */ config_load_default(); - return true; + return zathura; error_free: - if (Zathura.UI.page_view) { - g_object_unref(Zathura.UI.page_view); + if (zathura->ui.page_view) { + g_object_unref(zathura->ui.page_view); } - girara_session_destroy(Zathura.UI.session); + girara_session_destroy(zathura->ui.session); error_out: - return false; + return NULL; +} + +void +zathura_free(zathura_t* zathura) +{ + if (zathura == NULL) { + return; + } + + if (zathura->ui.session != NULL) { + girara_session_destroy(zathura->ui.session); + } + + document_close(zathura); + + /* free registered plugins */ + zathura_document_plugins_free(); } bool -document_open(const char* path, const char* password) +document_open(zathura_t* zathura, const char* path, const char* password) { if (!path) { goto error_out; @@ -100,30 +123,30 @@ document_open(const char* path, const char* password) goto error_out; } - Zathura.document = document; + zathura->document = document; /* init view */ - if (create_blank_pages() == false) { + if (create_blank_pages(zathura) == false) { return false; } /* view mode */ - int* value = girara_setting_get(Zathura.UI.session, "pages-per-row"); + int* value = girara_setting_get(zathura->ui.session, "pages-per-row"); int pages_per_row = (value) ? *value : 1; free(value); - page_view_set_mode(pages_per_row); + page_view_set_mode(zathura, pages_per_row); - girara_set_view(Zathura.UI.session, Zathura.UI.page_view); + girara_set_view(zathura->ui.session, zathura->ui.page_view); /* threads */ - Zathura.Sync.render_thread = render_init(); + zathura->sync.render_thread = render_init(); - if (!Zathura.Sync.render_thread) { + if (!zathura->sync.render_thread) { goto error_free; } /* first page */ - if (!page_set(0)) { + if (!page_set(zathura, 0)) { goto error_free; } @@ -139,47 +162,47 @@ error_out: } bool -document_close() +document_close(zathura_t* zathura) { - if (!Zathura.document) { + if (!zathura->document) { return false; } - if (Zathura.Sync.render_thread) { - render_free(Zathura.Sync.render_thread); + if (zathura->sync.render_thread) { + render_free(zathura->sync.render_thread); } - zathura_document_free(Zathura.document); + zathura_document_free(zathura->document); return true; } bool -page_set(unsigned int page_id) +page_set(zathura_t* zathura, unsigned int page_id) { - if (!Zathura.document || !Zathura.document->pages) { + if (!zathura->document || !zathura->document->pages) { goto error_out; } - if (page_id >= Zathura.document->number_of_pages) { + if (page_id >= zathura->document->number_of_pages) { goto error_out; } /* render page */ - zathura_page_t* page = Zathura.document->pages[page_id]; + zathura_page_t* page = zathura->document->pages[page_id]; if (!page) { goto error_out; } - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); cb_view_vadjustment_value_changed(view_vadjustment, NULL); /* update page number */ - Zathura.document->current_page_number = page_id; + zathura->document->current_page_number = page_id; - char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, Zathura.document->number_of_pages); - girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.page_number, page_number); + char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, zathura->document->number_of_pages); + girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, page_number); g_free(page_number); return true; @@ -190,42 +213,42 @@ error_out: } void -page_view_set_mode(unsigned int pages_per_row) +page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { /* empty page view */ - GList* container = gtk_container_get_children(GTK_CONTAINER(Zathura.UI.page_view)); + GList* container = gtk_container_get_children(GTK_CONTAINER(zathura->ui.page_view)); for (GList* child = container; child; child = g_list_next(child)) { - gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), child->data); + gtk_container_remove(GTK_CONTAINER(zathura->ui.page_view), child->data); } GtkWidget* row = NULL; /* create blank pages */ - for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++) + for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { if (i % pages_per_row == 0) { row = gtk_hbox_new(FALSE, 0); } /* pack row */ - gtk_box_pack_start(GTK_BOX(row), Zathura.document->pages[i]->event_box, FALSE, FALSE, 1); + gtk_box_pack_start(GTK_BOX(row), zathura->document->pages[i]->event_box, FALSE, FALSE, 1); /* pack row to page view */ if ((i + 1) % pages_per_row == 0) { - gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), row, FALSE, FALSE, 1); + gtk_box_pack_start(GTK_BOX(zathura->ui.page_view), row, FALSE, FALSE, 1); } } - gtk_widget_show_all(Zathura.UI.page_view); + gtk_widget_show_all(zathura->ui.page_view); } bool -create_blank_pages() +create_blank_pages(zathura_t* zathura) { /* create blank pages */ - for (unsigned int i = 0; i < Zathura.document->number_of_pages; i++) + for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { - zathura_page_t* page = Zathura.document->pages[i]; + zathura_page_t* page = zathura->document->pages[i]; g_static_mutex_lock(&(page->lock)); cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); @@ -254,13 +277,14 @@ int main(int argc, char* argv[]) gdk_threads_init(); gtk_init(&argc, &argv); - if (!init_zathura()) { + zathura_t* zathura = zathura_init(argc, argv); + if (zathura == NULL) { printf("error: coult not initialize zathura\n"); return -1; } if (argc > 1) { - if (!document_open(argv[1], NULL)) { + if (!document_open(zathura, argv[1], NULL)) { printf("error: could not open document\n"); return -1; } diff --git a/zathura.h b/zathura.h index fc59099..bb3a2cc 100644 --- a/zathura.h +++ b/zathura.h @@ -24,7 +24,7 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, #define NORMAL (1 << 3) #define INSERT (1 << 4) -struct +typedef struct zathura_s { struct { @@ -39,59 +39,73 @@ struct GtkWidget *page_view; /**> Widget that contains all rendered pages */ GtkWidget *index; /**> Widget to show the index of the document */ - } UI; + } ui; struct { render_thread_t* render_thread; /**> The thread responsible for rendering the pages */ - } Sync; + } sync; zathura_document_t* document; /**> The current document */ -} Zathura; +} zathura_t; /** * Initializes zathura * - * @return If no error occured true, otherwise false, is returned. + * @param argc Number of arguments + * @param argv Values of arguments + * @return Zathura zathura object or NULL if zathura could not been initialized */ -bool init_zathura(); +zathura_t* zathura_init(int argc, char* argv[]); + +/** + * Free zathura zathura + * + * @param zathura The zathura zathura + */ +void zathura_free(zathura_t* zathura); /** * Opens a file * + * @param zathura The zathura zathura * @param path The path to the file * @param password The password of the file * * @return If no error occured true, otherwise false, is returned. */ -bool document_open(const char* path, const char* password); +bool document_open(zathura_t* zathura, const char* path, const char* password); /** * Closes the current opened document * + * @param zathura The zathura zathura * @return If no error occured true, otherwise false, is returned. */ -bool document_close(); +bool document_close(zathura_t* zathura); /** * Opens the page with the given number * + * @param zathura The zathura zathura * @return If no error occured true, otherwise false, is returned. */ -bool page_set(unsigned int page_id); +bool page_set(zathura_t* zathura, unsigned int page_id); /** * Builds the box structure to show the rendered pages * + * @param zathura The zathura zathura * @param pages_per_row Number of shown pages per row */ -void page_view_set_mode(unsigned int pages_per_row); +void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row); /** * Create blank pages * + * @param zathura The zathura zathura * @return false if an error occured, otherwise true */ -bool create_blank_pages(); +bool create_blank_pages(zathura_t* zathura); #endif // ZATHURA_H From a181c0477505cdaf7e05052805026379cd3e6542 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:28:27 +0200 Subject: [PATCH 097/197] Fixed config.c --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index 33972f9..b847456 100644 --- a/config.c +++ b/config.c @@ -8,7 +8,7 @@ void config_load_default(zathura_t* zathura) { - if (zathura || !zathura->UI.session) { + if (zathura || !zathura->ui.session) { return; } From daa523aaf5f6e4769ee9a8be679736f1da5c4f7d Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:37:03 +0200 Subject: [PATCH 098/197] Updated callbacks.c --- callbacks.c | 19 +++++++++++++------ zathura.c | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/callbacks.c b/callbacks.c index c16b6c5..8fb333d 100644 --- a/callbacks.c +++ b/callbacks.c @@ -21,33 +21,40 @@ void buffer_changed(girara_session_t* session) { g_return_if_fail(session != NULL); + g_return_if_fail(session->global.data != NULL); + + zathura_t* zathura = session->global.data; char* buffer = girara_buffer_get(session); if (buffer) { - girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer); + girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, buffer); free(buffer); } else { - girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, ""); + girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, ""); } } void cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { - if (!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) { + g_return_if_fail(data != NULL); + + zathura_t* zathura = data; + if (!zathura->document || !zathura->document->pages || !zathura->ui.page_view) { return; } + // FIXME /* get current adjustment values */ /*gdouble lower = gtk_adjustment_get_value(adjustment);*/ /*gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);*/ /* find page that fits */ - for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) + 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_page_t* page = zathura->document->pages[page_id]; /* check for rendered attribute */ if (page->rendered) { @@ -62,7 +69,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ /*) {*/ if (page_id < 1) { - render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]); + render_page(zathura->sync.render_thread, zathura->document->pages[page_id]); } /*}*/ } diff --git a/zathura.c b/zathura.c index f889ae3..602cfb8 100644 --- a/zathura.c +++ b/zathura.c @@ -30,6 +30,7 @@ zathura_init(int argc, char* argv[]) goto error_out; } + zathura->ui.session->global.data = zathura; zathura->ui.statusbar.file = NULL; zathura->ui.statusbar.buffer = NULL; zathura->ui.statusbar.page_number = NULL; @@ -67,7 +68,7 @@ zathura_init(int argc, char* argv[]) g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), NULL); + g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura); /* girara events */ zathura->ui.session->events.buffer_changed = buffer_changed; @@ -76,7 +77,7 @@ zathura_init(int argc, char* argv[]) zathura_document_plugins_load(); /* configuration */ - config_load_default(); + config_load_default(zathura); return zathura; From 9026f9246911562482e9796ca323fad192cea9d0 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 17:55:50 +0200 Subject: [PATCH 099/197] Updated shortcuts.c --- shortcuts.c | 153 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 51 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index 3a8ce74..8178891 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -13,6 +13,8 @@ bool sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; girara_mode_set(session, NORMAL); @@ -22,12 +24,20 @@ sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + return false; } bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + return false; } @@ -35,6 +45,8 @@ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; girara_mode_set(session, argument->n); @@ -45,6 +57,8 @@ bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; if (!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); @@ -62,15 +76,21 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsign bool sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + return false; } bool sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || argument == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != 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); + g_return_val_if_fail(zathura->document != NULL, false); if (argument->n == TOP) { girara_argument_t arg = { TOP, NULL }; @@ -85,12 +105,12 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) return true; } - unsigned int number_of_pages = Zathura.document->number_of_pages; + unsigned int number_of_pages = zathura->document->number_of_pages; if (t > 0 && t <= number_of_pages) { // TODO: Calculate offset - /*GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view));*/ - /*unsigned int offset = Zathura.document->pages[t - 1]->offset * Zathura.document->scale;*/ + /*GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view));*/ + /*unsigned int offset = zathura->document->pages[t - 1]->offset * zathura->document->scale;*/ /*gtk_adjustment_set_value(adjustment, offset);*/ } } @@ -101,12 +121,14 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || argument == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != 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); + g_return_val_if_fail(zathura->document != NULL, false); - unsigned int number_of_pages = Zathura.document->number_of_pages; - unsigned int new_page = Zathura.document->current_page_number; + unsigned int number_of_pages = zathura->document->number_of_pages; + unsigned int new_page = zathura->document->current_page_number; if (argument->n == NEXT) { new_page = (new_page + 1) % number_of_pages; @@ -122,24 +144,35 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int bool sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + + zathura_t* zathura = session->global.data; + return false; } bool sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + + zathura_t* zathura = session->global.data; + return false; } bool sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(zathura->document != NULL, false); /* update rotate value */ - Zathura.document->rotate = (Zathura.document->rotate + 90) % 360; + zathura->document->rotate = (zathura->document->rotate + 90) % 360; /* render all pages again */ render_all(); @@ -150,11 +183,17 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t bool sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != 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); + g_return_val_if_fail(zathura->document != NULL, false); + GtkAdjustment* adjustment = NULL; if ( (argument->n == LEFT) || (argument->n == RIGHT) ) - adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); else - adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); gdouble view_size = gtk_adjustment_get_page_size(adjustment); gdouble value = gtk_adjustment_get_value(adjustment); @@ -202,40 +241,54 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t bool sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != 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); + g_return_val_if_fail(zathura->document != NULL, false); + return false; } bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != 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); + g_return_val_if_fail(zathura->document != NULL, false); + return false; } bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != 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); + g_return_val_if_fail(zathura->document != NULL, false); girara_tree_node_t* document_index = NULL; GtkWidget* treeview = NULL; GtkTreeModel* model = NULL; GtkCellRenderer* renderer = NULL; - if (Zathura.UI.index == NULL) { + if (zathura->UI.index == NULL) { /* create new index widget */ - Zathura.UI.index = gtk_scrolled_window_new(NULL, NULL); + zathura->UI.index = gtk_scrolled_window_new(NULL, NULL); - if (Zathura.UI.index == NULL) { + if (zathura->UI.index == NULL) { goto error_ret; } - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(Zathura.UI.index), + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->UI.index), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); /* create index */ - document_index = zathura_document_index_generate(Zathura.document); + document_index = zathura_document_index_generate(zathura->document); if (document_index == NULL) { // TODO: Error message goto error_free; @@ -269,31 +322,31 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE); /*g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), NULL); TODO*/ - gtk_container_add(GTK_CONTAINER(Zathura.UI.index), treeview); + gtk_container_add(GTK_CONTAINER(zathura->UI.index), treeview); gtk_widget_show(treeview); } - if (GTK_WIDGET_VISIBLE(GTK_WIDGET(Zathura.UI.index))) { - girara_set_view(session, Zathura.UI.page_view); - gtk_widget_hide(GTK_WIDGET(Zathura.UI.index)); + if (GTK_WIDGET_VISIBLE(GTK_WIDGET(zathura->UI.index))) { + girara_set_view(session, zathura->UI.page_view); + gtk_widget_hide(GTK_WIDGET(zathura->UI.index)); } else { - girara_set_view(session, Zathura.UI.index); - gtk_widget_show(GTK_WIDGET(Zathura.UI.index)); + girara_set_view(session, zathura->UI.index); + gtk_widget_show(GTK_WIDGET(zathura->UI.index)); } return false; error_free: - if (Zathura.UI.index != NULL) { - g_object_ref_sink(Zathura.UI.index); - Zathura.UI.index = NULL; + if (zathura->UI.index != NULL) { + g_object_ref_sink(zathura->UI.index); + zathura->UI.index = NULL; } if (document_index != NULL) { girara_node_free(document_index); } - + error_ret: return false; @@ -302,9 +355,7 @@ error_ret: bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar))) { gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar)); @@ -318,9 +369,7 @@ sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsig bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); static bool fullscreen = false; @@ -338,9 +387,7 @@ sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, uns bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL) { - return false; - } + g_return_val_if_fail(session != NULL, false); if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.statusbar))) { gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar)); @@ -354,6 +401,8 @@ sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsi bool sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) { + g_return_val_if_fail(session != NULL, false); + girara_argument_t arg = { GIRARA_HIDE, NULL }; girara_isc_completion(session, &arg, 0); @@ -367,12 +416,14 @@ sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) bool sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) { - if (session == NULL || argument == NULL || Zathura.document == NULL) { - return false; - } + g_return_val_if_fail(session != 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); + g_return_val_if_fail(zathura->document != NULL, false); /* retreive zoom step value */ - int* value = girara_setting_get(Zathura.UI.session, "zoom-step"); + int* value = girara_setting_get(zathura->UI.session, "zoom-step"); if (value == NULL) { return false; } @@ -380,11 +431,11 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) float zoom_step = *value / 100.0f; if (argument->n == ZOOM_IN) { - Zathura.document->scale += zoom_step; + zathura->document->scale += zoom_step; } else if (argument->n == ZOOM_OUT) { - Zathura.document->scale -= zoom_step; + zathura->document->scale -= zoom_step; } else { - Zathura.document->scale = 1.0; + zathura->document->scale = 1.0; } render_all(); From 2eed47a31445b6b944e2485ce684b14ce8d56f34 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 18:00:08 +0200 Subject: [PATCH 100/197] Updated render.c/render.h --- render.c | 27 ++++++++++++++------------- render.h | 8 ++++++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/render.c b/render.c index 02208b7..0329711 100644 --- a/render.c +++ b/render.c @@ -20,7 +20,7 @@ render_job(void* data) girara_list_remove(render_thread->list, page); g_mutex_unlock(render_thread->lock); - if (render(page) != true) { + if (render(render_thread->zathura, page) != true) { fprintf(stderr, "rendering failed\n"); } @@ -31,7 +31,7 @@ render_job(void* data) } render_thread_t* -render_init(void) +render_init(zathura_t* zathura) { render_thread_t* render_thread = malloc(sizeof(render_thread_t)); @@ -40,9 +40,10 @@ render_init(void) } /* init */ - render_thread->list = NULL; - render_thread->thread = NULL; - render_thread->cond = NULL; + render_thread->list = NULL; + render_thread->thread = NULL; + render_thread->cond = NULL; + render_thread->zathura = zathura; /* setup */ render_thread->list = girara_list_new(); @@ -130,7 +131,7 @@ render_page(render_thread_t* render_thread, zathura_page_t* page) } bool -render(zathura_page_t* page) +render(zathura_t* zathura, zathura_page_t* page) { gdk_threads_enter(); g_static_mutex_lock(&(page->lock)); @@ -149,8 +150,8 @@ render(zathura_page_t* page) } /* create cairo surface */ - unsigned int page_width = page->width * Zathura.document->scale; - unsigned int page_height = page->height * Zathura.document->scale; + unsigned int page_width = page->width * zathura->document->scale; + unsigned int page_height = page->height * zathura->document->scale; cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height); @@ -183,18 +184,18 @@ render(zathura_page_t* page) } void -render_all(void) +render_all(zathura_t* zathura) { - if (Zathura.document == NULL) { + if (zathura->document == NULL) { return; } /* unmark all pages */ - for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++) { - Zathura.document->pages[page_id]->rendered = false; + for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) { + zathura->document->pages[page_id]->rendered = false; } /* redraw current page */ - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); cb_view_vadjustment_value_changed(view_vadjustment, NULL); } diff --git a/render.h b/render.h index 1f48f95..53f03e3 100644 --- a/render.h +++ b/render.h @@ -16,14 +16,16 @@ typedef struct render_thread_s GThread* thread; /**> The thread object */ GMutex* lock; /**> Lock */ GCond* cond; /**> Condition */ + zathura_t* zathura; /**> Zathura object */ } render_thread_t; /** * This function initializes a render thread * + * @param Zathura object * @return The render thread object or NULL if an error occured */ -render_thread_t* render_init(void); +render_thread_t* render_init(zathura_t* zathura); /** * This function destroys the render thread object @@ -46,7 +48,9 @@ bool render_page(render_thread_t* render_thread, zathura_page_t* page); * This function is used to unmark all pages as not rendered. This should * be used if all pages should be rendered again (e.g.: the zoom level or the * colors have changed) + * + * @param zathura Zathura object */ -void render_all(void); +void render_all(zathura_t* zathura); #endif // RENDER_H From 08117975d3dffa4e0692643dae6b1691af81c86a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 18:05:17 +0200 Subject: [PATCH 101/197] Updated plugins --- ft/djvu/djvu.c | 6 +++--- ft/pdf-mupdf/pdf.c | 12 ++++++------ ft/pdf-poppler/pdf.c | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 5fe130e..26b822a 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -218,13 +218,13 @@ djvu_page_form_fields_get(zathura_page_t* page) zathura_image_buffer_t* djvu_page_render(zathura_page_t* page) { - if (!Zathura.document || !page || !page->document) { + if (!page || !page->document) { return NULL; } /* calculate sizes */ - unsigned int page_width = Zathura.document->scale * page->width; - unsigned int page_height = Zathura.document->scale * page->height; + unsigned int page_width = page->document->scale * page->width; + unsigned int page_height = page->document->scale * page->height; if (!page_width || !page_height) { goto error_out; diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index bb760c4..f602ffa 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -176,15 +176,15 @@ pdf_page_form_fields_get(zathura_page_t* page) zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { - if (!Zathura.document || !page || !page->data || !page->document) { + if (!page || !page->data || !page->document) { return NULL; } /* calculate sizes */ - unsigned int page_width = Zathura.document->scale * page->width; - unsigned int page_height = Zathura.document->scale * page->height; + unsigned int page_width = page->document->scale * page->width; + unsigned int page_height = page->document->scale * page->height; - if (Zathura.document->rotate == 90 || Zathura.document->rotate == 270) { + if (page->document->rotate == 90 || page->document->rotate == 270) { unsigned int dim_temp = 0; dim_temp = page_width; page_width = page_height; @@ -215,9 +215,9 @@ pdf_page_render(zathura_page_t* page) fz_matrix ctm = fz_identity; ctm = fz_concat(ctm, fz_translate(0, -mupdf_page->page->mediabox.y1)); - ctm = fz_concat(ctm, fz_scale(Zathura.document->scale, -Zathura.document->scale)); + ctm = fz_concat(ctm, fz_scale(page->document->scale, -page->document->scale)); ctm = fz_concat(ctm, fz_rotate(mupdf_page->page->rotate)); - ctm = fz_concat(ctm, fz_rotate(Zathura.document->rotate)); + ctm = fz_concat(ctm, fz_rotate(page->document->rotate)); fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); fz_pixmap* pixmap = fz_newpixmapwithrect(fz_devicergb, bbox); diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index fadf9cc..6d50638 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -253,13 +253,13 @@ pdf_page_form_fields_get(zathura_page_t* page) zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { - if (!Zathura.document || !page || !page->data || !page->document) { + if (!page || !page->data || !page->document) { return NULL; } /* calculate sizes */ - unsigned int page_width = Zathura.document->scale * page->width; - unsigned int page_height = Zathura.document->scale * page->height; + unsigned int page_width = page->document->scale * page->width; + unsigned int page_height = page->document->scale * page->height; /* create pixbuf */ GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, @@ -270,7 +270,7 @@ pdf_page_render(zathura_page_t* page) } poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, - Zathura.document->scale, 90, pixbuf); + page->document->scale, 90, pixbuf); /* create image buffer */ zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); From f57fe5dfde903b01e442faf6754f5715c522465f Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 18:19:41 +0200 Subject: [PATCH 102/197] update document.c/.h --- config.h | 2 ++ document.c | 92 ++++++++++++++++++++++++++---------------------------- document.h | 20 +++++++----- render.h | 6 ++-- zathura.c | 11 +++++-- zathura.h | 19 +++++++++-- 6 files changed, 85 insertions(+), 65 deletions(-) diff --git a/config.h b/config.h index 4103598..b5b152d 100644 --- a/config.h +++ b/config.h @@ -7,6 +7,8 @@ /** * This function loads the default values of the configuration + * + * @param zathura the zathura session */ void config_load_default(zathura_t* zathura); diff --git a/document.c b/document.c index 99a41fb..6a1d462 100644 --- a/document.c +++ b/document.c @@ -18,10 +18,8 @@ #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) -zathura_document_plugin_t* zathura_document_plugins = NULL; - void -zathura_document_plugins_load(void) +zathura_document_plugins_load(zathura_t* zathura) { /* read all files in the plugin directory */ DIR* dir = opendir(PLUGIN_DIR); @@ -76,7 +74,7 @@ zathura_document_plugins_load(void) register_plugin(plugin); - bool r = zathura_document_plugin_register(plugin, handle); + bool r = zathura_document_plugin_register(zathura, plugin, handle); if (r == false) { fprintf(stderr, "error: could not register plugin (%s)\n", path); @@ -107,60 +105,54 @@ error_continue: } void -zathura_document_plugins_free(void) +zathura_document_plugins_free(zathura_t* zathura) { - /* free registered plugins */ - zathura_document_plugin_t* plugin = zathura_document_plugins; - while (plugin) { - zathura_document_plugin_t* tmp = plugin->next; - free(plugin->file_extension); - free(plugin); - plugin = tmp; + if (zathura == NULL) { + return; } - zathura_document_plugins = NULL; + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); + if (iter == NULL) { + return; + } + + do { + zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); + free(plugin->file_extension); + free(plugin); + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); } bool -zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle) +zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t* new_plugin, void* handle) { if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) || (handle == NULL) ) { - fprintf(stderr, "plugin: could not register\n"); + girara_error("plugin: could not register\n"); return false; } /* search existing plugins */ - zathura_document_plugin_t* plugin = zathura_document_plugins; - while (plugin) { - if (!strcmp(plugin->file_extension, new_plugin->file_extension)) { - fprintf(stderr, "plugin: already registered for filetype %s\n", plugin->file_extension); - return false; - } - - if (plugin->next == NULL) { - break; - } - - plugin = plugin->next; - } - - /* create new plugin */ - new_plugin->handle = handle; - new_plugin->next = NULL; - - /* append to list */ - if (plugin == NULL) { - zathura_document_plugins = new_plugin; - } else { - plugin->next = new_plugin; + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); + if (iter) { + do { + zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); + if (!strcmp(plugin->file_extension, new_plugin->file_extension)) { + girara_error("plugin: already registered for filetype %s\n", plugin->file_extension); + girara_list_iterator_free(iter); + return false; + } + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); } + girara_list_append(zathura->plugins.plugins, new_plugin); return true; } zathura_document_t* -zathura_document_open(const char* path, const char* password) +zathura_document_open(zathura_t* zathura, const char* path, const char* password) { if (!path) { goto error_out; @@ -224,14 +216,19 @@ zathura_document_open(const char* path, const char* password) document->functions.page_form_fields_get = NULL; document->functions.page_render = NULL; - /* init plugin with associated file type */ - zathura_document_plugin_t* plugin = zathura_document_plugins; - while (plugin) { + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); + if (iter == NULL) { + return; + } + + do { + zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); if (!strcmp(file_extension, plugin->file_extension)) { + girara_list_iterator_free(iter); if (plugin->open_function) { if (plugin->open_function(document)) { /* update statusbar */ - girara_statusbar_item_set_text(Zathura.UI.session, Zathura.UI.statusbar.file, real_path); + girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, real_path); /* read all pages */ document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*)); @@ -250,16 +247,15 @@ zathura_document_open(const char* path, const char* password) return document; } else { - fprintf(stderr, "error: could not open file\n"); + girara_error("could not open file\n"); goto error_free; } } } + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); - plugin = plugin->next; - } - - fprintf(stderr, "error: unknown file type\n"); + girara_error("unknown file type\n"); error_free: diff --git a/document.h b/document.h index 5fb78e2..2536958 100644 --- a/document.h +++ b/document.h @@ -7,12 +7,13 @@ #include #include +#include "zathura.h" #define PLUGIN_DIR "/usr/lib/zathura" #define PLUGIN_REGISTER_FUNCTION "plugin_register" typedef struct zathura_list_s zathura_list_t; -typedef struct zathura_document_s zathura_document_t; +// typedef struct zathura_document_s zathura_document_t; typedef bool (*zathura_document_open_t)(zathura_document_t* document); @@ -24,7 +25,6 @@ typedef struct zathura_document_plugin_s char* file_extension; /**> File extension */ zathura_document_open_t open_function; /**> Document open function */ void* handle; /**> DLL handle */ - struct zathura_document_plugin_s *next; /**> Next plugin */ // TODO: Use list_t } zathura_document_plugin_t; /** @@ -139,7 +139,7 @@ typedef struct zathura_form_s /** * Page */ -typedef struct zathura_page_s +struct zathura_page_s { double height; /**> Page height */ double width; /**> Page width */ @@ -150,7 +150,7 @@ typedef struct zathura_page_s GtkWidget* event_box; /**> Widget wrapper for mouse events */ GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ -} zathura_page_t; +}; /** * Document @@ -226,18 +226,22 @@ struct zathura_document_s /** * Load all document plugins + * + * @param zathura the zathura session */ -void zathura_document_plugins_load(void); +void zathura_document_plugins_load(zathura_t* zathura); /** * Free all document plugins + * + * @param zathura the zathura session */ -void zathura_document_plugins_free(void); +void zathura_document_plugins_free(zathura_t* zathura); /** * Register document plugin */ -bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle); +bool zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t* new_plugin, void* handle); /** * Open the document @@ -246,7 +250,7 @@ bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, voi * @param password Password of the document or NULL * @return The document object */ -zathura_document_t* zathura_document_open(const char* path, const char* password); +zathura_document_t* zathura_document_open(zathura_t* zathura, const char* path, const char* password); /** * Free the document diff --git a/render.h b/render.h index 1f48f95..362bafd 100644 --- a/render.h +++ b/render.h @@ -7,16 +7,16 @@ #include #include -#include "document.h" +#include "zathura.h" #include "callbacks.h" -typedef struct render_thread_s +struct render_thread_s { girara_list_t* list; /**> The list of pages */ GThread* thread; /**> The thread object */ GMutex* lock; /**> Lock */ GCond* cond; /**> Condition */ -} render_thread_t; +}; /** * This function initializes a render thread diff --git a/zathura.c b/zathura.c index 602cfb8..f1715ff 100644 --- a/zathura.c +++ b/zathura.c @@ -10,6 +10,7 @@ #include "shortcuts.h" #include "zathura.h" #include "utils.h" +#include "render.h" /* function implementation */ zathura_t* @@ -21,6 +22,10 @@ zathura_init(int argc, char* argv[]) return NULL; } + /* plugins */ + zathura->plugins.plugins = girara_list_new(); + zathura->plugins.path = NULL; + /* UI */ if ((zathura->ui.session = girara_session_create()) == NULL) { goto error_out; @@ -74,7 +79,7 @@ zathura_init(int argc, char* argv[]) zathura->ui.session->events.buffer_changed = buffer_changed; /* load plugins */ - zathura_document_plugins_load(); + zathura_document_plugins_load(zathura); /* configuration */ config_load_default(zathura); @@ -108,7 +113,7 @@ zathura_free(zathura_t* zathura) document_close(zathura); /* free registered plugins */ - zathura_document_plugins_free(); + zathura_document_plugins_free(zathura); } bool @@ -118,7 +123,7 @@ document_open(zathura_t* zathura, const char* path, const char* password) goto error_out; } - zathura_document_t* document = zathura_document_open(path, password); + zathura_document_t* document = zathura_document_open(zathura, path, password); if (!document) { goto error_out; diff --git a/zathura.h b/zathura.h index bb3a2cc..c90d5c1 100644 --- a/zathura.h +++ b/zathura.h @@ -6,9 +6,6 @@ #include #include -#include "render.h" -#include "document.h" - 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, @@ -24,6 +21,16 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, #define NORMAL (1 << 3) #define INSERT (1 << 4) +/* forward declaration for types from document.h */ +struct zathura_document_s; +struct zathura_page_s; +typedef struct zathura_document_s zathura_document_t; +typedef struct zathura_page_s zathura_page_t; + +/* forward declaration for types from render.h */ +struct render_thread_s; +typedef struct render_thread_s render_thread_t; + typedef struct zathura_s { struct @@ -46,6 +53,12 @@ typedef struct zathura_s render_thread_t* render_thread; /**> The thread responsible for rendering the pages */ } sync; + struct + { + girara_list_t* plugins; + girara_list_t* path; + } plugins; + zathura_document_t* document; /**> The current document */ } zathura_t; From 0d5a06ce291df348c3637f8ea0a9ebafe4504970 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 18 Apr 2011 18:21:33 +0200 Subject: [PATCH 103/197] free plugins --- zathura.c | 1 + 1 file changed, 1 insertion(+) diff --git a/zathura.c b/zathura.c index f1715ff..62411a5 100644 --- a/zathura.c +++ b/zathura.c @@ -114,6 +114,7 @@ zathura_free(zathura_t* zathura) /* free registered plugins */ zathura_document_plugins_free(zathura); + girara_list_free(zathura->plugins.plugins); } bool From 536862900ea352fcc06dd8a72f71201430f4d4b2 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 18:23:34 +0200 Subject: [PATCH 104/197] Updated document.c/zathura.c --- document.c | 2 +- zathura.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/document.c b/document.c index 6a1d462..4979b1d 100644 --- a/document.c +++ b/document.c @@ -218,7 +218,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); if (iter == NULL) { - return; + goto error_free; } do { diff --git a/zathura.c b/zathura.c index 62411a5..5bfed4c 100644 --- a/zathura.c +++ b/zathura.c @@ -146,7 +146,7 @@ document_open(zathura_t* zathura, const char* path, const char* password) girara_set_view(zathura->ui.session, zathura->ui.page_view); /* threads */ - zathura->sync.render_thread = render_init(); + zathura->sync.render_thread = render_init(zathura); if (!zathura->sync.render_thread) { goto error_free; From 4a8f4df2dbc02ea49a7bcd8468115f7be96169c2 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 18:29:50 +0200 Subject: [PATCH 105/197] Updated commands/render/shortcuts/utils for zathura object --- commands.c | 7 ++++++- render.c | 5 +++-- shortcuts.c | 57 +++++++++++++++++++---------------------------------- utils.c | 1 + 4 files changed, 30 insertions(+), 40 deletions(-) diff --git a/commands.c b/commands.c index a7dd660..bfe368a 100644 --- a/commands.c +++ b/commands.c @@ -24,7 +24,12 @@ cmd_bookmark_open(girara_session_t* session, int argc, char** argv) bool cmd_close(girara_session_t* session, int argc, char** argv) { - document_close(); + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + g_return_val_if_fail(zathura->document != NULL, false); + + document_close(zathura); return true; } diff --git a/render.c b/render.c index 0329711..821d665 100644 --- a/render.c +++ b/render.c @@ -1,8 +1,9 @@ #include "render.h" #include "zathura.h" +#include "document.h" void* render_job(void* data); -bool render(zathura_page_t* page); +bool render(zathura_t* zathura, zathura_page_t* page); void* render_job(void* data) @@ -196,6 +197,6 @@ render_all(zathura_t* zathura) } /* redraw current page */ - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); cb_view_vadjustment_value_changed(view_vadjustment, NULL); } diff --git a/shortcuts.c b/shortcuts.c index 8178891..72acb44 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -5,6 +5,7 @@ #include "callbacks.h" #include "shortcuts.h" +#include "document.h" #include "zathura.h" #include "render.h" #include "utils.h" @@ -13,8 +14,6 @@ bool sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; girara_mode_set(session, NORMAL); @@ -25,8 +24,6 @@ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; return false; } @@ -35,8 +32,6 @@ bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; return false; } @@ -45,8 +40,6 @@ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; girara_mode_set(session, argument->n); @@ -57,8 +50,6 @@ bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; if (!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); @@ -77,8 +68,6 @@ bool sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; return false; } @@ -136,7 +125,7 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int new_page = (new_page + number_of_pages - 1) % number_of_pages; } - page_set(new_page); + page_set(zathura, new_page); return false; } @@ -145,9 +134,6 @@ bool sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - - zathura_t* zathura = session->global.data; return false; } @@ -156,9 +142,6 @@ bool sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - - zathura_t* zathura = session->global.data; return false; } @@ -175,7 +158,7 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t zathura->document->rotate = (zathura->document->rotate + 90) % 360; /* render all pages again */ - render_all(); + render_all(zathura); return false; } @@ -191,9 +174,9 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t GtkAdjustment* adjustment = NULL; if ( (argument->n == LEFT) || (argument->n == RIGHT) ) - adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); + adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); else - adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view)); + adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); gdouble view_size = gtk_adjustment_get_page_size(adjustment); gdouble value = gtk_adjustment_get_value(adjustment); @@ -276,15 +259,15 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned GtkTreeModel* model = NULL; GtkCellRenderer* renderer = NULL; - if (zathura->UI.index == NULL) { + if (zathura->ui.index == NULL) { /* create new index widget */ - zathura->UI.index = gtk_scrolled_window_new(NULL, NULL); + zathura->ui.index = gtk_scrolled_window_new(NULL, NULL); - if (zathura->UI.index == NULL) { + if (zathura->ui.index == NULL) { goto error_ret; } - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->UI.index), + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->ui.index), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); /* create index */ @@ -322,25 +305,25 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE); /*g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), NULL); TODO*/ - gtk_container_add(GTK_CONTAINER(zathura->UI.index), treeview); + gtk_container_add(GTK_CONTAINER(zathura->ui.index), treeview); gtk_widget_show(treeview); } - if (GTK_WIDGET_VISIBLE(GTK_WIDGET(zathura->UI.index))) { - girara_set_view(session, zathura->UI.page_view); - gtk_widget_hide(GTK_WIDGET(zathura->UI.index)); + if (GTK_WIDGET_VISIBLE(GTK_WIDGET(zathura->ui.index))) { + girara_set_view(session, zathura->ui.page_view); + gtk_widget_hide(GTK_WIDGET(zathura->ui.index)); } else { - girara_set_view(session, zathura->UI.index); - gtk_widget_show(GTK_WIDGET(zathura->UI.index)); + girara_set_view(session, zathura->ui.index); + gtk_widget_show(GTK_WIDGET(zathura->ui.index)); } return false; error_free: - if (zathura->UI.index != NULL) { - g_object_ref_sink(zathura->UI.index); - zathura->UI.index = NULL; + if (zathura->ui.index != NULL) { + g_object_ref_sink(zathura->ui.index); + zathura->ui.index = NULL; } if (document_index != NULL) { @@ -423,7 +406,7 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) g_return_val_if_fail(zathura->document != NULL, false); /* retreive zoom step value */ - int* value = girara_setting_get(zathura->UI.session, "zoom-step"); + int* value = girara_setting_get(zathura->ui.session, "zoom-step"); if (value == NULL) { return false; } @@ -438,7 +421,7 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) zathura->document->scale = 1.0; } - render_all(); + render_all(zathura); return false; } diff --git a/utils.c b/utils.c index 79494f8..9183924 100644 --- a/utils.c +++ b/utils.c @@ -10,6 +10,7 @@ #include "utils.h" #include "zathura.h" +#include "document.h" #define BLOCK_SIZE 64 From 8bcb79ea940d30523ec9b03416e01941ca9d6cb5 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 21:22:35 +0200 Subject: [PATCH 106/197] Update --- callbacks.c | 5 +--- document.c | 2 ++ render.c | 32 ++++++++++++++++++++-- render.h | 10 +++++++ zathura.c | 78 +++++++++++++++++++++++++---------------------------- zathura.h | 8 ------ 6 files changed, 80 insertions(+), 55 deletions(-) diff --git a/callbacks.c b/callbacks.c index 8fb333d..be7f3a4 100644 --- a/callbacks.c +++ b/callbacks.c @@ -38,14 +38,11 @@ buffer_changed(girara_session_t* session) void cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { - g_return_if_fail(data != NULL); - zathura_t* zathura = data; - if (!zathura->document || !zathura->document->pages || !zathura->ui.page_view) { + if (!zathura || !zathura->document || !zathura->document->pages || !zathura->ui.page_view) { return; } - // FIXME /* get current adjustment values */ /*gdouble lower = gtk_adjustment_get_value(adjustment);*/ diff --git a/document.c b/document.c index 4979b1d..8802593 100644 --- a/document.c +++ b/document.c @@ -15,6 +15,7 @@ #include "document.h" #include "utils.h" #include "zathura.h" +#include "render.h" #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) @@ -385,6 +386,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) page->rendered = false; page->event_box = gtk_event_box_new(); page->drawing_area = gtk_drawing_area_new(); + g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page); gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); diff --git a/render.c b/render.c index 821d665..967f7b9 100644 --- a/render.c +++ b/render.c @@ -22,7 +22,7 @@ render_job(void* data) g_mutex_unlock(render_thread->lock); if (render(render_thread->zathura, page) != true) { - fprintf(stderr, "rendering failed\n"); + girara_error("Rendering failed\n"); } printf("Rendered %d\n", page->number); @@ -134,6 +134,10 @@ render_page(render_thread_t* render_thread, zathura_page_t* page) bool render(zathura_t* zathura, zathura_page_t* page) { + if (zathura == NULL || page == NULL) { + return false; + } + gdk_threads_enter(); g_static_mutex_lock(&(page->lock)); zathura_image_buffer_t* image_buffer = zathura_page_render(page); @@ -198,5 +202,29 @@ render_all(zathura_t* zathura) /* redraw current page */ GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - cb_view_vadjustment_value_changed(view_vadjustment, NULL); + cb_view_vadjustment_value_changed(view_vadjustment, zathura); +} + +gboolean +page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) +{ + zathura_page_t* page = data; + g_static_mutex_lock(&(page->lock)); + + cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); + + if (cairo == NULL) { + girara_error("Could not create blank page"); + g_static_mutex_unlock(&(page->lock)); + return false; + } + + cairo_set_source_rgb(cairo, 0, 0, 0); + cairo_rectangle(cairo, 0, 0, page->width, page->height); + cairo_fill(cairo); + cairo_destroy(cairo); + + g_static_mutex_unlock(&(page->lock)); + + return true; } diff --git a/render.h b/render.h index c20c5c7..73f2a27 100644 --- a/render.h +++ b/render.h @@ -53,4 +53,14 @@ bool render_page(render_thread_t* render_thread, zathura_page_t* page); */ void render_all(zathura_t* zathura); +/** + * Renders page + * + * @param widget Drawing area + * @param event Event + * @param data Optional data + * @return true if no error occured + */ +gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data); + #endif // RENDER_H diff --git a/zathura.c b/zathura.c index 5bfed4c..25d479c 100644 --- a/zathura.c +++ b/zathura.c @@ -12,6 +12,15 @@ #include "utils.h" #include "render.h" +typedef struct zathura_document_info_s +{ + zathura_t* zathura; + const char* path; + const char* password; +} zathura_document_info_t; + +gboolean document_info_open(gpointer data); + /* function implementation */ zathura_t* zathura_init(int argc, char* argv[]) @@ -84,6 +93,17 @@ zathura_init(int argc, char* argv[]) /* configuration */ config_load_default(zathura); + if (argc > 1) { + zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t)); + + if (document_info != NULL) { + 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); + } + } + return zathura; error_free: @@ -117,6 +137,22 @@ zathura_free(zathura_t* zathura) girara_list_free(zathura->plugins.plugins); } +gboolean +document_info_open(gpointer data) +{ + zathura_document_info_t* document_info = data; + g_return_val_if_fail(document_info != NULL, FALSE); + + if (document_info->zathura == NULL || document_info->path == NULL) { + free(document_info); + return FALSE; + } + + document_open(document_info->zathura, document_info->path, document_info->password); + + return FALSE; +} + bool document_open(zathura_t* zathura, const char* path, const char* password) { @@ -132,11 +168,6 @@ document_open(zathura_t* zathura, const char* path, const char* password) zathura->document = document; - /* init view */ - if (create_blank_pages(zathura) == false) { - return false; - } - /* view mode */ int* value = girara_setting_get(zathura->ui.session, "pages-per-row"); int pages_per_row = (value) ? *value : 1; @@ -203,7 +234,7 @@ page_set(zathura_t* zathura, unsigned int page_id) } GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - cb_view_vadjustment_value_changed(view_vadjustment, NULL); + cb_view_vadjustment_value_changed(view_vadjustment, zathura); /* update page number */ zathura->document->current_page_number = page_id; @@ -249,34 +280,6 @@ page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) gtk_widget_show_all(zathura->ui.page_view); } -bool -create_blank_pages(zathura_t* zathura) -{ - /* create blank pages */ - for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) - { - zathura_page_t* page = zathura->document->pages[i]; - g_static_mutex_lock(&(page->lock)); - - cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); - - if (cairo == NULL) { - girara_error("Could not create blank page"); - g_static_mutex_unlock(&(page->lock)); - return false; - } - - cairo_set_source_rgb(cairo, 1, 1, 1); - cairo_rectangle(cairo, 0, 0, page->width, page->height); - cairo_fill(cairo); - cairo_destroy(cairo); - - g_static_mutex_unlock(&(page->lock)); - } - - return true; -} - /* main function */ int main(int argc, char* argv[]) { @@ -290,13 +293,6 @@ int main(int argc, char* argv[]) return -1; } - if (argc > 1) { - if (!document_open(zathura, argv[1], NULL)) { - printf("error: could not open document\n"); - return -1; - } - } - gdk_threads_enter(); gtk_main(); gdk_threads_leave(); diff --git a/zathura.h b/zathura.h index c90d5c1..739cd76 100644 --- a/zathura.h +++ b/zathura.h @@ -113,12 +113,4 @@ bool page_set(zathura_t* zathura, unsigned int page_id); */ void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row); -/** - * Create blank pages - * - * @param zathura The zathura zathura - * @return false if an error occured, otherwise true - */ -bool create_blank_pages(zathura_t* zathura); - #endif // ZATHURA_H From fdf0bd56495fce0bc9bcd49d026df40b67f94226 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 18 Apr 2011 22:59:59 +0200 Subject: [PATCH 107/197] Save surface temporary in page_t --- document.c | 1 + document.h | 1 + render.c | 27 ++++++++++++++++----------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/document.c b/document.c index 8802593..6525711 100644 --- a/document.c +++ b/document.c @@ -386,6 +386,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) page->rendered = false; page->event_box = gtk_event_box_new(); page->drawing_area = gtk_drawing_area_new(); + page->surface = NULL; g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page); gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); diff --git a/document.h b/document.h index 2536958..56a3e90 100644 --- a/document.h +++ b/document.h @@ -150,6 +150,7 @@ struct zathura_page_s GtkWidget* event_box; /**> Widget wrapper for mouse events */ GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ + cairo_surface_t* surface; /** Cairo surface */ }; /** diff --git a/render.c b/render.c index 967f7b9..3be9558 100644 --- a/render.c +++ b/render.c @@ -176,10 +176,7 @@ render(zathura_t* zathura, zathura_page_t* page) } /* draw to gtk widget */ - cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); - cairo_set_source_surface(cairo, surface, 0, 0); - cairo_paint(cairo); - cairo_destroy(cairo); + page->surface = surface; zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); @@ -209,22 +206,30 @@ gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) { zathura_page_t* page = data; + if (page == NULL) { + return FALSE; + } + g_static_mutex_lock(&(page->lock)); cairo_t* cairo = gdk_cairo_create(page->drawing_area->window); if (cairo == NULL) { - girara_error("Could not create blank page"); + girara_error("Could not retreive cairo object"); g_static_mutex_unlock(&(page->lock)); - return false; + return FALSE; } - cairo_set_source_rgb(cairo, 0, 0, 0); - cairo_rectangle(cairo, 0, 0, page->width, page->height); - cairo_fill(cairo); - cairo_destroy(cairo); + if (page->surface == NULL) { + cairo_set_source_surface(cairo, page->surface, 0, 0); + cairo_paint(cairo); + cairo_destroy(cairo); + + cairo_surface_destroy(page->surface); + page->surface = NULL; + } g_static_mutex_unlock(&(page->lock)); - return true; + return TRUE; } From b2fc17207eb9c1e2dbae5f9e66b2ae834c6913e4 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 00:36:56 +0200 Subject: [PATCH 108/197] Make plugin path configurable * We don't fail if we can't load a plugin. There can be anything. * Reintroduce the command line parser from glib. * Use fstatat as it is more reliable than d_type from dirent. --- document.c | 156 +++++++++++++++++++++++++++++------------------------ document.h | 1 - zathura.c | 60 ++++++++++++++++++++- zathura.h | 6 +++ 4 files changed, 150 insertions(+), 73 deletions(-) diff --git a/document.c b/document.c index 6525711..34ab250 100644 --- a/document.c +++ b/document.c @@ -1,7 +1,7 @@ /* See LICENSE file for license and copyright information */ #define _BSD_SOURCE -#define _XOPEN_SOURCE 500 +#define _XOPEN_SOURCE 700 // TODO: Implement realpath #include @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include #include "document.h" #include "utils.h" @@ -22,87 +25,98 @@ void zathura_document_plugins_load(zathura_t* zathura) { - /* read all files in the plugin directory */ - DIR* dir = opendir(PLUGIN_DIR); - if (dir == NULL) { - fprintf(stderr, "error: could not open plugin directory: %s\n", PLUGIN_DIR); + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.path); + if (iter == NULL) { return; } - struct dirent* entry; - while ((entry = readdir(dir)) != NULL) { - /* check if entry is a file */ - if (entry->d_type != 0x8) { + do + { + char* plugindir = girara_list_iterator_data(iter); + + /* read all files in the plugin directory */ + DIR* dir = opendir(plugindir); + if (dir == NULL) { + girara_error("could not open plugin directory: %s", plugindir); continue; } - void* handle = NULL; - zathura_document_plugin_t* plugin = NULL; - char* path = NULL; + int fddir = dirfd(dir); + struct dirent* entry; + while ((entry = readdir(dir)) != NULL) { + struct stat statbuf; + if (fstatat(fddir, entry->d_name, &statbuf, 0) != 0) { + girara_error("failed to fstatat %s/%s; errno is %d.", plugindir, entry->d_name, errno); + continue; + } - /* get full path */ - path = string_concat(PLUGIN_DIR, "/", entry->d_name, NULL); + /* check if entry is a file */ + if (S_ISREG(statbuf.st_mode) == 0) { + girara_info("%s/%s is not a regular file. Skipping.", plugindir, entry->d_name); + continue; + } - if (path == NULL) { - goto error_continue; + void* handle = NULL; + zathura_document_plugin_t* plugin = NULL; + char* path = NULL; + + /* get full path */ + path = g_build_filename(plugindir, entry->d_name, NULL); + if (path == NULL) { + g_error("failed to allocate memory!"); + break; + } + + /* load plugin */ + handle = dlopen(path, RTLD_NOW); + if (handle == NULL) { + girara_error("could not load plugin %s (%s)", path, dlerror()); + g_free(path); + continue; + } + + /* resolve symbol */ + zathura_plugin_register_service_t register_plugin; + *(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION); + + if (register_plugin == NULL) { + girara_error("could not find '%s' function in plugin %s", PLUGIN_REGISTER_FUNCTION, path); + g_free(path); + dlclose(handle); + continue; + } + + plugin = malloc(sizeof(zathura_document_plugin_t)); + + if (plugin == NULL) { + g_error("failed to allocate memory!"); + break; + } + + plugin->file_extension = NULL; + plugin->open_function = NULL; + + register_plugin(plugin); + + bool r = zathura_document_plugin_register(zathura, plugin, handle); + + if (r == false) { + girara_error("could not register plugin %s", path); + free(plugin); + dlclose(handle); + } + else { + girara_info("successfully loaded plugin %s", path); + } + + g_free(path); } - /* load plugin */ - handle = dlopen(path, RTLD_NOW); - - if (handle == NULL) { - fprintf(stderr, "error: could not load plugin (%s)\n", dlerror()); - goto error_free; + if (closedir(dir) == -1) { + girara_error("could not close plugin directory %s", plugindir); } - - /* resolve symbol */ - zathura_plugin_register_service_t register_plugin; - *(void**)(®ister_plugin) = dlsym(handle, PLUGIN_REGISTER_FUNCTION); - - if (register_plugin == NULL) { - fprintf(stderr, "error: could not find '%s' function in the plugin\n", PLUGIN_REGISTER_FUNCTION); - goto error_free; - } - - plugin = malloc(sizeof(zathura_document_plugin_t)); - - if (plugin == NULL) { - goto error_free; - } - - plugin->file_extension = NULL; - plugin->open_function = NULL; - - register_plugin(plugin); - - bool r = zathura_document_plugin_register(zathura, plugin, handle); - - if (r == false) { - fprintf(stderr, "error: could not register plugin (%s)\n", path); - goto error_free; - } - - free(path); - - continue; - -error_free: - - free(path); - free(plugin); - - if (handle) { - dlclose(handle); - } - -error_continue: - - continue; - } - - if (closedir(dir) == -1) { - fprintf(stderr, "error: could not close plugin directory: %s\n", PLUGIN_DIR); - } + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); } void diff --git a/document.h b/document.h index 56a3e90..358b945 100644 --- a/document.h +++ b/document.h @@ -9,7 +9,6 @@ #include #include "zathura.h" -#define PLUGIN_DIR "/usr/lib/zathura" #define PLUGIN_REGISTER_FUNCTION "plugin_register" typedef struct zathura_list_s zathura_list_t; diff --git a/zathura.c b/zathura.c index 25d479c..f444c3b 100644 --- a/zathura.c +++ b/zathura.c @@ -33,7 +33,8 @@ zathura_init(int argc, char* argv[]) /* plugins */ zathura->plugins.plugins = girara_list_new(); - zathura->plugins.path = NULL; + zathura->plugins.path = girara_list_new(); + girara_list_set_free_function(zathura->plugins.path, g_free); /* UI */ if ((zathura->ui.session = girara_session_create()) == NULL) { @@ -87,6 +88,58 @@ zathura_init(int argc, char* argv[]) /* girara events */ zathura->ui.session->events.buffer_changed = buffer_changed; + /* parse command line options */ + gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; + GOptionEntry entries[] = + { + /* { "reparent", 'e', 0, G_OPTION_ARG_INT, &Zathura.UI.embed, "Reparents to window specified by xid", "xid" }, */ + { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" }, + { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, "Path to the data directory", "path" }, + { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, "Path to the directories containing plugins", "path" }, + { NULL } + }; + + 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); + goto error_free; + } + g_option_context_free(context); + + if (config_dir) { + zathura->config.config_dir = g_strdup(config_dir); + } else { + gchar* path = girara_get_xdg_path(XDG_CONFIG); + zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } + + if (data_dir) { + zathura->config.data_dir = g_strdup(config_dir); + } else { + gchar* path = girara_get_xdg_path(XDG_DATA); + zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } + + if (plugin_path) { + gchar** paths = g_strsplit(plugin_path, ":", 0); + for (unsigned int i = 0; paths[i] != '\0'; ++i) { + girara_list_append(zathura->plugins.path, g_strdup(paths[i])); + } + g_strfreev(paths); + } else { + /* XXX: this shouldn't be hard coded! */ + girara_list_append(zathura->plugins.path, g_strdup("/usr/local/lib/zathura")); + girara_list_append(zathura->plugins.path, g_strdup("/usr/lib/zathura")); + } + /* load plugins */ zathura_document_plugins_load(zathura); @@ -135,6 +188,11 @@ zathura_free(zathura_t* zathura) /* free registered plugins */ zathura_document_plugins_free(zathura); girara_list_free(zathura->plugins.plugins); + girara_list_free(zathura->plugins.path); + + /* free config variables */ + g_free(zathura->config.config_dir); + g_free(zathura->config.data_dir); } gboolean diff --git a/zathura.h b/zathura.h index 739cd76..86c17a9 100644 --- a/zathura.h +++ b/zathura.h @@ -59,6 +59,12 @@ typedef struct zathura_s girara_list_t* path; } plugins; + struct + { + gchar* config_dir; + gchar* data_dir; + } config; + zathura_document_t* document; /**> The current document */ } zathura_t; From 12793b355295fa0bbfc646ed5b36a468702618a5 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 10:38:59 +0200 Subject: [PATCH 109/197] Update cmd_* definitions The command definitions are now updated to fit to the updated definitions of girara. --- commands.c | 14 +++++++------- commands.h | 35 ++++++++++++++--------------------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/commands.c b/commands.c index a7dd660..d017320 100644 --- a/commands.c +++ b/commands.c @@ -4,25 +4,25 @@ #include "zathura.h" bool -cmd_bookmark_create(girara_session_t* session, int argc, char** argv) +cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list) { return true; } bool -cmd_bookmark_delete(girara_session_t* session, int argc, char** argv) +cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list) { return true; } bool -cmd_bookmark_open(girara_session_t* session, int argc, char** argv) +cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list) { return true; } bool -cmd_close(girara_session_t* session, int argc, char** argv) +cmd_close(girara_session_t* session, girara_list_t* argument_list) { document_close(); @@ -30,19 +30,19 @@ cmd_close(girara_session_t* session, int argc, char** argv) } bool -cmd_info(girara_session_t* session, int argc, char** argv) +cmd_info(girara_session_t* session, girara_list_t* argument_list) { return true; } bool -cmd_print(girara_session_t* session, int argc, char** argv) +cmd_print(girara_session_t* session, girara_list_t* argument_list) { return true; } bool -cmd_save(girara_session_t* session, int argc, char** argv) +cmd_save(girara_session_t* session, girara_list_t* argument_list) { return true; } diff --git a/commands.h b/commands.h index 471aa3c..fa6d8eb 100644 --- a/commands.h +++ b/commands.h @@ -10,70 +10,63 @@ * Create a bookmark * * @param session The used girara session - * @param argc Number of arguments - * @param argv Value of the arguments + * @param argument_list List of passed arguments * @return true if no error occured */ -bool cmd_bookmark_create(girara_session_t* session, int argc, char** argv); +bool cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list); /** * Delete a bookmark * * @param session The used girara session - * @param argc Number of arguments - * @param argv Value of the arguments + * @param argument_list List of passed arguments * @return true if no error occured */ -bool cmd_bookmark_delete(girara_session_t* session, int argc, char** argv); +bool cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list); /** * Open a bookmark * * @param session The used girara session - * @param argc Number of arguments - * @param argv Value of the arguments + * @param argument_list List of passed arguments * @return true if no error occured */ -bool cmd_bookmark_open(girara_session_t* session, int argc, char** argv); +bool cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list); /** * Close zathura * * @param session The used girara session - * @param argc Number of arguments - * @param argv Value of the arguments + * @param argument_list List of passed arguments * @return true if no error occured */ -bool cmd_close(girara_session_t* session, int argc, char** argv); +bool cmd_close(girara_session_t* session, girara_list_t* argument_list); /** * Display document information * * @param session The used girara session - * @param argc Number of arguments - * @param argv Value of the arguments + * @param argument_list List of passed arguments * @return true if no error occured */ -bool cmd_info(girara_session_t* session, int argc, char** argv); +bool cmd_info(girara_session_t* session, girara_list_t* argument_list); /** * Print the current file * * @param session The used girara session - * @param argc Number of arguments - * @param argv Value of the arguments + * @param argument_list List of passed arguments * @return true if no error occured */ -bool cmd_print(girara_session_t* session, int argc, char** argv); +bool cmd_print(girara_session_t* session, girara_list_t* argument_list); /** * Save the current file * * @param session The used girara session - * @param argc Number of arguments - * @param argv Value of the arguments + * @param argument_list List of passed arguments * @return true if no error occured */ -bool cmd_save(girara_session_t* session, int argc, char** argv); +bool cmd_save(girara_session_t* session, girara_list_t* argument_list); #endif // COMMANDS_H From 298c9d2c7a807f4d529fbfa8d3b5b73124b19305 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 14:46:08 +0200 Subject: [PATCH 110/197] readd tabbed support --- zathura.c | 106 +++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/zathura.c b/zathura.c index f444c3b..ddd5540 100644 --- a/zathura.c +++ b/zathura.c @@ -36,11 +36,65 @@ zathura_init(int argc, char* argv[]) zathura->plugins.path = girara_list_new(); girara_list_set_free_function(zathura->plugins.path, g_free); + /* parse command line options */ + GdkNativeWindow embed = 0; + gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; + GOptionEntry entries[] = + { + { "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, "Reparents to window specified by xid", "xid" }, + { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" }, + { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, "Path to the data directory", "path" }, + { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, "Path to the directories containing plugins", "path" }, + { NULL } + }; + + 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); + goto error_free; + } + g_option_context_free(context); + + if (config_dir) { + zathura->config.config_dir = g_strdup(config_dir); + } else { + gchar* path = girara_get_xdg_path(XDG_CONFIG); + zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } + + if (data_dir) { + zathura->config.data_dir = g_strdup(config_dir); + } else { + gchar* path = girara_get_xdg_path(XDG_DATA); + zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + g_free(path); + } + + if (plugin_path) { + gchar** paths = g_strsplit(plugin_path, ":", 0); + for (unsigned int i = 0; paths[i] != '\0'; ++i) { + girara_list_append(zathura->plugins.path, g_strdup(paths[i])); + } + g_strfreev(paths); + } else { + /* XXX: this shouldn't be hard coded! */ + girara_list_append(zathura->plugins.path, g_strdup("/usr/local/lib/zathura")); + girara_list_append(zathura->plugins.path, g_strdup("/usr/lib/zathura")); + } + /* UI */ if ((zathura->ui.session = girara_session_create()) == NULL) { goto error_out; } + zathura->ui.session->gtk.embed = embed; if (girara_session_init(zathura->ui.session) == false) { goto error_out; } @@ -88,58 +142,6 @@ zathura_init(int argc, char* argv[]) /* girara events */ zathura->ui.session->events.buffer_changed = buffer_changed; - /* parse command line options */ - gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; - GOptionEntry entries[] = - { - /* { "reparent", 'e', 0, G_OPTION_ARG_INT, &Zathura.UI.embed, "Reparents to window specified by xid", "xid" }, */ - { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" }, - { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, "Path to the data directory", "path" }, - { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, "Path to the directories containing plugins", "path" }, - { NULL } - }; - - 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); - goto error_free; - } - g_option_context_free(context); - - if (config_dir) { - zathura->config.config_dir = g_strdup(config_dir); - } else { - gchar* path = girara_get_xdg_path(XDG_CONFIG); - zathura->config.config_dir = g_build_filename(path, "zathura", NULL); - g_free(path); - } - - if (data_dir) { - zathura->config.data_dir = g_strdup(config_dir); - } else { - gchar* path = girara_get_xdg_path(XDG_DATA); - zathura->config.config_dir = g_build_filename(path, "zathura", NULL); - g_free(path); - } - - if (plugin_path) { - gchar** paths = g_strsplit(plugin_path, ":", 0); - for (unsigned int i = 0; paths[i] != '\0'; ++i) { - girara_list_append(zathura->plugins.path, g_strdup(paths[i])); - } - g_strfreev(paths); - } else { - /* XXX: this shouldn't be hard coded! */ - girara_list_append(zathura->plugins.path, g_strdup("/usr/local/lib/zathura")); - girara_list_append(zathura->plugins.path, g_strdup("/usr/lib/zathura")); - } - /* load plugins */ zathura_document_plugins_load(zathura); From 45afe89e874d913ac77c596b0976704558284c09 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 15:23:55 +0200 Subject: [PATCH 111/197] invalidate rect --- render.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/render.c b/render.c index 3be9558..05cb7d5 100644 --- a/render.c +++ b/render.c @@ -148,12 +148,6 @@ render(zathura_t* zathura, zathura_page_t* page) return false; } - /* remove old image */ - GtkWidget* widget = gtk_bin_get_child(GTK_BIN(page->event_box)); - if (widget != NULL) { - gtk_container_remove(GTK_CONTAINER(page->event_box), widget); - } - /* create cairo surface */ unsigned int page_width = page->width * zathura->document->scale; unsigned int page_height = page->height * zathura->document->scale; @@ -176,7 +170,9 @@ render(zathura_t* zathura, zathura_page_t* page) } /* draw to gtk widget */ + girara_info("surface: %d %p", page->number, surface); page->surface = surface; + gdk_window_invalidate_rect(page->drawing_area->window, NULL, TRUE); zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); @@ -205,6 +201,7 @@ render_all(zathura_t* zathura) gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) { + girara_info("in expose"); zathura_page_t* page = data; if (page == NULL) { return FALSE; @@ -220,14 +217,16 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) return FALSE; } + girara_info("page->num %d page->surface: %p", page->number, page->surface); if (page->surface == NULL) { cairo_set_source_surface(cairo, page->surface, 0, 0); cairo_paint(cairo); - cairo_destroy(cairo); cairo_surface_destroy(page->surface); page->surface = NULL; } + girara_info("visible: %d", GTK_WIDGET_VISIBLE(GTK_WIDGET(page->drawing_area))); + cairo_destroy(cairo); g_static_mutex_unlock(&(page->lock)); From 4eef03c2015b2b09e685b13bc99da132456e55c2 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 15:26:26 +0200 Subject: [PATCH 112/197] invalidate rect --- render.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/render.c b/render.c index 05cb7d5..f22427f 100644 --- a/render.c +++ b/render.c @@ -218,7 +218,7 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) } girara_info("page->num %d page->surface: %p", page->number, page->surface); - if (page->surface == NULL) { + if (page->surface != NULL) { cairo_set_source_surface(cairo, page->surface, 0, 0); cairo_paint(cairo); From 7dd5c0d5672b8fb533d2e69864e457ba7cabe1be Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 15:39:10 +0200 Subject: [PATCH 113/197] resize --- render.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/render.c b/render.c index f22427f..45802df 100644 --- a/render.c +++ b/render.c @@ -172,7 +172,8 @@ render(zathura_t* zathura, zathura_page_t* page) /* draw to gtk widget */ girara_info("surface: %d %p", page->number, surface); page->surface = surface; - gdk_window_invalidate_rect(page->drawing_area->window, NULL, TRUE); + gtk_widget_set_size_request(page->drawing_area, page_width, page_height); + gtk_widget_queue_draw(page->drawing_area); zathura_image_buffer_free(image_buffer); g_static_mutex_unlock(&(page->lock)); From fd283c8873e499bef254c64f4aa622b4cb932fa7 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 16:02:54 +0200 Subject: [PATCH 114/197] memory leak --- document.c | 1 + 1 file changed, 1 insertion(+) diff --git a/document.c b/document.c index 34ab250..9ee63ae 100644 --- a/document.c +++ b/document.c @@ -569,4 +569,5 @@ zathura_image_buffer_free(zathura_image_buffer_t* image_buffer) } free(image_buffer->data); + free(image_buffer); } From 5151b84a6fe9da205366868f5aed1e32055a7552 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 16:03:42 +0200 Subject: [PATCH 115/197] Update render function --- ft/pdf-poppler/pdf.c | 2 +- render.c | 3 ++- zathura.c | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index 6d50638..ac5eb07 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -270,7 +270,7 @@ pdf_page_render(zathura_page_t* page) } poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, - page->document->scale, 90, pixbuf); + page->document->scale, 0, pixbuf); /* create image buffer */ zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); diff --git a/render.c b/render.c index 45802df..66b3a40 100644 --- a/render.c +++ b/render.c @@ -165,7 +165,8 @@ render(zathura_t* zathura, zathura_page_t* page) dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; - dst += 3; + src += 3; + dst += 4; } } diff --git a/zathura.c b/zathura.c index ddd5540..a2e9055 100644 --- a/zathura.c +++ b/zathura.c @@ -321,7 +321,6 @@ page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) GtkWidget* row = NULL; - /* create blank pages */ for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { if (i % pages_per_row == 0) { From 07cc456ae9969f1b507f3a9423562480e9d3d61e Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 16:24:19 +0200 Subject: [PATCH 116/197] Fixed rendering for mupdf/poppler backend --- ft/pdf-mupdf/pdf.c | 2 +- ft/pdf-poppler/pdf.c | 4 ++-- render.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index f602ffa..31d7cb2 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -230,7 +230,7 @@ pdf_page_render(zathura_page_t* page) for (unsigned int y = 0; y < pixmap->h; y++) { for (unsigned int x = 0; x < pixmap->w; x++) { unsigned char *s = pixmap->samples + y * pixmap->w * 4 + x * 4; - guchar* p = image_buffer->data + y * image_buffer->width + x; + guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index ac5eb07..3850ceb 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -269,7 +269,7 @@ pdf_page_render(zathura_page_t* page) return NULL; } - poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, + poppler_page_render_to_pixbuf(page->data, 0, 0, page->width, page->height, page->document->scale, 0, pixbuf); /* create image buffer */ @@ -288,7 +288,7 @@ pdf_page_render(zathura_page_t* page) for (unsigned int y = 0; y < page_height; y++) { for (unsigned int x = 0; x < page_width; x++) { unsigned char *s = pixels + y * rowstride + x * n_channels; - guchar* p = image_buffer->data + y * image_buffer->width + x; + guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; p[0] = s[0]; p[1] = s[1]; p[2] = s[2]; diff --git a/render.c b/render.c index 66b3a40..ef3a7af 100644 --- a/render.c +++ b/render.c @@ -162,9 +162,9 @@ render(zathura_t* zathura, zathura_page_t* page) unsigned char* src = image_buffer->data + y * image_buffer->rowstride; for (unsigned int x = 0; x < page_width; x++) { - dst[0] = src[0]; + dst[0] = src[2]; dst[1] = src[1]; - dst[2] = src[2]; + dst[2] = src[0]; src += 3; dst += 4; } From 48d5dad99d43717de077924c1600b576953d4917 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 16:42:16 +0200 Subject: [PATCH 117/197] Fixed rendering for djvu backend --- ft/djvu/djvu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index 26b822a..46908c2 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -254,7 +254,7 @@ djvu_page_render(zathura_page_t* page) /* render page */ ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, - 3 * page_width, (char*) image_buffer); + 3 * page_width, (char*) image_buffer->data); return image_buffer; From a80770a32050557730c8a1810cc64627120eb266 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 17:46:44 +0200 Subject: [PATCH 118/197] Save zathura object in zathura_ocument_t --- document.c | 1 + document.h | 1 + 2 files changed, 2 insertions(+) diff --git a/document.c b/document.c index 9ee63ae..db8dd07 100644 --- a/document.c +++ b/document.c @@ -219,6 +219,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password document->rotate = 0; document->data = NULL; document->pages = NULL; + document->zathura = zathura; document->functions.document_free = NULL; document->functions.document_index_generate = NULL; diff --git a/document.h b/document.h index 358b945..5fc5ae6 100644 --- a/document.h +++ b/document.h @@ -164,6 +164,7 @@ struct zathura_document_s double scale; /**> Scale value */ int rotate; /**> Rotation */ void* data; /**> Custom data */ + zathura_t* zathura; /** Zathura object */ struct { From a415666cc1ebcdd7683937417a884a8e3f60d02b Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 18:33:28 +0200 Subject: [PATCH 119/197] zathura_page_t: replace rendered by visible --- callbacks.c | 5 +++-- document.c | 7 +------ document.h | 2 +- render.c | 14 ++++++++------ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/callbacks.c b/callbacks.c index be7f3a4..5677e54 100644 --- a/callbacks.c +++ b/callbacks.c @@ -54,7 +54,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) zathura_page_t* page = zathura->document->pages[page_id]; /* check for rendered attribute */ - if (page->rendered) { + if (page->surface != NULL) { continue; } @@ -66,7 +66,8 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ /*) {*/ if (page_id < 1) { - render_page(zathura->sync.render_thread, zathura->document->pages[page_id]); + page->visible = true; + render_page(zathura->sync.render_thread, page); } /*}*/ } diff --git a/document.c b/document.c index db8dd07..894722b 100644 --- a/document.c +++ b/document.c @@ -398,7 +398,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) if (page) { page->number = page_id; - page->rendered = false; + page->visible = false; page->event_box = gtk_event_box_new(); page->drawing_area = gtk_drawing_area_new(); page->surface = NULL; @@ -497,11 +497,6 @@ zathura_page_render(zathura_page_t* page) } zathura_image_buffer_t* buffer = page->document->functions.page_render(page); - - if (buffer) { - page->rendered = true; - } - return buffer; } diff --git a/document.h b/document.h index 5fc5ae6..63517c4 100644 --- a/document.h +++ b/document.h @@ -145,7 +145,7 @@ struct zathura_page_s unsigned int number; /**> Page number */ zathura_document_t* document; /**> Document */ void* data; /**> Custom data */ - bool rendered; /**> Page has been rendered */ + bool visible; /**> Page is visible */ GtkWidget* event_box; /**> Widget wrapper for mouse events */ GtkWidget* drawing_area; /**> Drawing area */ GStaticMutex lock; /**> Lock */ diff --git a/render.c b/render.c index ef3a7af..a363cac 100644 --- a/render.c +++ b/render.c @@ -25,7 +25,7 @@ render_job(void* data) girara_error("Rendering failed\n"); } - printf("Rendered %d\n", page->number); + girara_info("rendered page %d\n", page->number); } return NULL; @@ -117,7 +117,7 @@ render_free(render_thread_t* render_thread) bool render_page(render_thread_t* render_thread, zathura_page_t* page) { - if (!render_thread || !page || !render_thread->list || page->rendered) { + if (!render_thread || !page || !render_thread->list || page->surface) { return false; } @@ -192,7 +192,8 @@ render_all(zathura_t* zathura) /* unmark all pages */ for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) { - zathura->document->pages[page_id]->rendered = false; + cairo_surface_destroy(zathura->document->pages[page_id]->surface); + zathura->document->pages[page_id]->surface = NULL; } /* redraw current page */ @@ -224,10 +225,11 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) cairo_set_source_surface(cairo, page->surface, 0, 0); cairo_paint(cairo); - cairo_surface_destroy(page->surface); - page->surface = NULL; + // cairo_surface_destroy(page->surface); + // page->surface = NULL; + } else if (page->visible) { + render_page(page->document->zathura->sync.render_thread, page); } - girara_info("visible: %d", GTK_WIDGET_VISIBLE(GTK_WIDGET(page->drawing_area))); cairo_destroy(cairo); g_static_mutex_unlock(&(page->lock)); From 8025225e149720dc1efce41cfa2bc5694de965f9 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 18:53:41 +0200 Subject: [PATCH 120/197] create dependencies --- Makefile | 10 +++++++--- ft/djvu/Makefile | 10 +++++++--- ft/pdf-mupdf/Makefile | 10 +++++++--- ft/pdf-poppler/Makefile | 10 +++++++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 27daaaa..9bb1219 100644 --- a/Makefile +++ b/Makefile @@ -19,11 +19,13 @@ options: %.o: %.c @echo CC $< - @${CC} -c ${CFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c @echo CC $< - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk @@ -34,7 +36,7 @@ ${PROJECT}: ${OBJECTS} clean: @rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ - ${DOBJECTS} ${PROJECT}-debug + ${DOBJECTS} ${PROJECT}-debug .depend make -C ft clean ${PROJECT}-debug: ${DOBJECTS} @@ -76,3 +78,5 @@ uninstall: @echo removing manual page @rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 @make -C ft uninstall + +-include $(wildcard .depend/*.dep) diff --git a/ft/djvu/Makefile b/ft/djvu/Makefile index d5e7617..bf406b2 100644 --- a/ft/djvu/Makefile +++ b/ft/djvu/Makefile @@ -18,11 +18,13 @@ options: %.o: %.c @echo CC $< - @${CC} -c ${CFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c @echo CC $< - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk @@ -36,7 +38,7 @@ ${PLUGIN}-debug: ${DOBJECTS} @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend debug: options ${PLUGIN}-debug @@ -49,3 +51,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +-include $(wildcard .depend/*.dep) diff --git a/ft/pdf-mupdf/Makefile b/ft/pdf-mupdf/Makefile index e14ed8c..e191eb9 100644 --- a/ft/pdf-mupdf/Makefile +++ b/ft/pdf-mupdf/Makefile @@ -18,11 +18,13 @@ options: %.o: %.c @echo CC $< - @${CC} -c ${CFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c @echo CC $< - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk @@ -36,7 +38,7 @@ ${PLUGIN}-debug: ${DOBJECTS} @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend debug: options ${PLUGIN}-debug @@ -49,3 +51,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +-include $(wildcard .depend/*.dep) diff --git a/ft/pdf-poppler/Makefile b/ft/pdf-poppler/Makefile index e14ed8c..e191eb9 100644 --- a/ft/pdf-poppler/Makefile +++ b/ft/pdf-poppler/Makefile @@ -18,11 +18,13 @@ options: %.o: %.c @echo CC $< - @${CC} -c ${CFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c @echo CC $< - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk @@ -36,7 +38,7 @@ ${PLUGIN}-debug: ${DOBJECTS} @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend debug: options ${PLUGIN}-debug @@ -49,3 +51,5 @@ uninstall: @echo uninstalling ${PLUGIN} plugin @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +-include $(wildcard .depend/*.dep) From 0a18af5912a2764066ab83243694773f4f81cb93 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 19:07:18 +0200 Subject: [PATCH 121/197] ignore .depend --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 720cd3f..bceaf5a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *~ *.rej *.swp +.depend From dc7c3d86eb59462f1a287164369e56a9d3b9fa9c Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 19:24:03 +0200 Subject: [PATCH 122/197] Calculate page offset --- config.c | 2 ++ utils.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- utils.h | 17 +++++++++++++++ zathura.c | 5 +++++ zathura.h | 5 +++++ 5 files changed, 93 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index b847456..287b991 100644 --- a/config.c +++ b/config.c @@ -21,6 +21,8 @@ config_load_default(zathura_t* zathura) /* zathura settings */ int_value = 10; girara_setting_add(gsession, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + int_value = 1; + girara_setting_add(gsession, "page-padding", &int_value, INT, true, "Padding between pages", NULL); int_value = 2; girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL); diff --git a/utils.c b/utils.c index 9183924..42aad30 100644 --- a/utils.c +++ b/utils.c @@ -178,7 +178,8 @@ document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_ } while ((it = girara_list_iterator_next(it))); } -char* string_concat(const char* string1, ...) +char* +string_concat(const char* string1, ...) { if(!string1) { return NULL; @@ -234,3 +235,65 @@ char* string_concat(const char* string1, ...) return c; } + + +page_offset_t* +page_offset_top(zathura_page_t* page) +{ + if (page == NULL || page->document == NULL || page->document->zathura == NULL) { + return NULL; + } + + page_offset_t* offset = malloc(sizeof(page_offset_t)); + + if (offset == NULL) { + return NULL; + } + + zathura_document_t* document = page->document; + zathura_t* zathura = document->zathura; + + int* tmp = girara_setting_get(zathura->ui.session, "pages-per-row"); + + unsigned int page_padding = zathura->global.page_padding; + unsigned int pages_per_row = (tmp && *tmp != 0) ? *tmp : 1; + unsigned int number_of_rows = (document->number_of_pages / pages_per_row) + 1; + + free(tmp); + + for (unsigned int row = 0; row < number_of_rows; row++) { + unsigned int tmp = -1; + for (unsigned int column = 0; column < pages_per_row; column++) + { + unsigned int page_id = row * pages_per_row + column; + double page_height = document->pages[page_id]->height * document->scale; + + if (tmp == -1) { + tmp = page_height; + } else if (page_height > tmp) { + tmp = page_height; + } + } + + offset->y += tmp + (row == (number_of_rows - 1)) ? 0 : page_padding; + } + + for (unsigned int column = 0; column < pages_per_row; column++) { + unsigned int tmp = -1; + for (unsigned int row = 0; row < number_of_rows; row++) + { + unsigned int page_id = row * pages_per_row + column; + double page_width = document->pages[page_id]->width * document->scale; + + if (tmp == -1) { + tmp = page_width; + } else if (page_width > tmp) { + tmp = page_width; + } + } + + offset->x += tmp + (column == (pages_per_row - 1)) ? 0 : page_padding; + } + + return offset; +} diff --git a/utils.h b/utils.h index 735317a..8c10724 100644 --- a/utils.h +++ b/utils.h @@ -7,6 +7,14 @@ #include #include +#include "document.h" + +typedef struct page_offset_s +{ + int x; + int y; +} page_offset_t; + /** * Checks if the given file exists * @@ -61,4 +69,13 @@ void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_ */ char* string_concat(const char* string1, ...); +/** + * Calculates the offset of the page to the top of the viewing area as + * well as to the left side of it. The result has to be freed. + * + * @param page The Page + * @return The calculated offset or NULL if an error occured + */ +page_offset_t* page_calculate_offset(zathura_page_t* page); + #endif // UTILS_H diff --git a/zathura.c b/zathura.c index a2e9055..5e823c7 100644 --- a/zathura.c +++ b/zathura.c @@ -148,6 +148,11 @@ zathura_init(int argc, char* argv[]) /* configuration */ config_load_default(zathura); + /* save page padding */ + int* page_padding = girara_setting_get(zathura->ui.session, "page-padding"); + zathura->global.page_padding = (page_padding) ? *page_padding : 1; + + /* open document if passed */ if (argc > 1) { zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t)); diff --git a/zathura.h b/zathura.h index 86c17a9..262ee74 100644 --- a/zathura.h +++ b/zathura.h @@ -65,6 +65,11 @@ typedef struct zathura_s gchar* data_dir; } config; + struct + { + unsigned int page_padding; + } global; + zathura_document_t* document; /**> The current document */ } zathura_t; From 222bd718e4b87e3373ba5b7b4223d858545e8a24 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 20:23:58 +0200 Subject: [PATCH 123/197] Simplify offset calculation --- callbacks.c | 9 ++++++++- utils.c | 45 ++++----------------------------------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/callbacks.c b/callbacks.c index 5677e54..cc5464a 100644 --- a/callbacks.c +++ b/callbacks.c @@ -8,6 +8,7 @@ #include "zathura.h" #include "render.h" #include "document.h" +#include "utils.h" gboolean cb_destroy(GtkWidget* widget, gpointer data) @@ -53,6 +54,12 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { zathura_page_t* page = zathura->document->pages[page_id]; + page_offset_t* offset = page_calculate_offset(page); + if (offset) { + fprintf(stderr, "offset: %d %d\n", offset->x, offset->y); + free(offset); + } + /* check for rendered attribute */ if (page->surface != NULL) { continue; @@ -65,7 +72,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) /*|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) [> end of the page is in viewport <]*/ /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ /*) {*/ - if (page_id < 1) { + if (page_id < 10) { page->visible = true; render_page(zathura->sync.render_thread, page); } diff --git a/utils.c b/utils.c index 42aad30..68d6d50 100644 --- a/utils.c +++ b/utils.c @@ -238,7 +238,7 @@ string_concat(const char* string1, ...) page_offset_t* -page_offset_top(zathura_page_t* page) +page_calculate_offset(zathura_page_t* page) { if (page == NULL || page->document == NULL || page->document->zathura == NULL) { return NULL; @@ -253,46 +253,9 @@ page_offset_top(zathura_page_t* page) zathura_document_t* document = page->document; zathura_t* zathura = document->zathura; - int* tmp = girara_setting_get(zathura->ui.session, "pages-per-row"); - - unsigned int page_padding = zathura->global.page_padding; - unsigned int pages_per_row = (tmp && *tmp != 0) ? *tmp : 1; - unsigned int number_of_rows = (document->number_of_pages / pages_per_row) + 1; - - free(tmp); - - for (unsigned int row = 0; row < number_of_rows; row++) { - unsigned int tmp = -1; - for (unsigned int column = 0; column < pages_per_row; column++) - { - unsigned int page_id = row * pages_per_row + column; - double page_height = document->pages[page_id]->height * document->scale; - - if (tmp == -1) { - tmp = page_height; - } else if (page_height > tmp) { - tmp = page_height; - } - } - - offset->y += tmp + (row == (number_of_rows - 1)) ? 0 : page_padding; - } - - for (unsigned int column = 0; column < pages_per_row; column++) { - unsigned int tmp = -1; - for (unsigned int row = 0; row < number_of_rows; row++) - { - unsigned int page_id = row * pages_per_row + column; - double page_width = document->pages[page_id]->width * document->scale; - - if (tmp == -1) { - tmp = page_width; - } else if (page_width > tmp) { - tmp = page_width; - } - } - - offset->x += tmp + (column == (pages_per_row - 1)) ? 0 : page_padding; + if (gtk_widget_translate_coordinates(page->event_box, zathura->ui.page_view, 0, 0, &(offset->x), &(offset->y)) == false) { + free(offset); + return NULL; } return offset; From 09328e8e895975c26a41733ed914a3dfba3b8491 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 19 Apr 2011 20:41:16 +0200 Subject: [PATCH 124/197] use GtkTable for page layout --- callbacks.c | 33 +++++++++++++++++---------------- zathura.c | 28 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/callbacks.c b/callbacks.c index cc5464a..79d0857 100644 --- a/callbacks.c +++ b/callbacks.c @@ -46,36 +46,37 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) // FIXME /* get current adjustment values */ - /*gdouble lower = gtk_adjustment_get_value(adjustment);*/ - /*gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);*/ + gdouble lower = gtk_adjustment_get_value(adjustment); + gdouble upper = lower + gtk_adjustment_get_page_size(adjustment); /* find page that fits */ for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) { zathura_page_t* page = zathura->document->pages[page_id]; - page_offset_t* offset = page_calculate_offset(page); - if (offset) { - fprintf(stderr, "offset: %d %d\n", offset->x, offset->y); - free(offset); - } - /* check for rendered attribute */ if (page->surface != NULL) { continue; } - /*double begin = page->offset;*/ - /*double end = page->offset + page->height;*/ + page_offset_t* offset = page_calculate_offset(page); + if (offset == NULL) { + continue; + } - /*if ( ( (begin >= lower) && (end <= upper) ) [> page is in viewport <]*/ - /*|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) [> end of the page is in viewport <]*/ - /*|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) [> begin of the page is in viewport <]*/ - /*) {*/ - if (page_id < 10) { + double begin = offset->y; + double end = offset->y + page->height; + + girara_info("%f %f; %f %f", begin, end, lower, upper); + + if ( ( (begin >= lower) && (end <= upper) ) /* [> page is in viewport <]*/ + || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* [> end of the page is in viewport <] */ + || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* [> begin of the page is in viewport <] */ + ) { page->visible = true; render_page(zathura->sync.render_thread, page); } - /*}*/ + + free(offset); } } diff --git a/zathura.c b/zathura.c index 5e823c7..43aec68 100644 --- a/zathura.c +++ b/zathura.c @@ -107,7 +107,7 @@ zathura_init(int argc, char* argv[]) zathura->ui.index = NULL; /* page view */ - zathura->ui.page_view = gtk_vbox_new(FALSE, 0); + zathura->ui.page_view = gtk_table_new(0, 0, TRUE); if (!zathura->ui.page_view) { goto error_free; } @@ -115,6 +115,9 @@ zathura_init(int argc, char* argv[]) gtk_widget_show(zathura->ui.page_view); gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0); + /* Put the table in the main window */ + // gtk_container_add(GTK_CONTAINER (zathura->ui.page_view), table); + /* statusbar */ zathura->ui.statusbar.file = girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); if (zathura->ui.statusbar.file == NULL) { @@ -319,26 +322,23 @@ void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { /* empty page view */ - GList* container = gtk_container_get_children(GTK_CONTAINER(zathura->ui.page_view)); + /* GList* container = gtk_container_get_children(GTK_CONTAINER(zathura->ui.page_view)); for (GList* child = container; child; child = g_list_next(child)) { gtk_container_remove(GTK_CONTAINER(zathura->ui.page_view), child->data); } - GtkWidget* row = NULL; + GtkWidget* row = NULL; */ + /* create blank pages */ + + + gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row); for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { - if (i % pages_per_row == 0) { - row = gtk_hbox_new(FALSE, 0); - } - - /* pack row */ - gtk_box_pack_start(GTK_BOX(row), zathura->document->pages[i]->event_box, FALSE, FALSE, 1); - - /* pack row to page view */ - if ((i + 1) % pages_per_row == 0) { - gtk_box_pack_start(GTK_BOX(zathura->ui.page_view), row, FALSE, FALSE, 1); - } + int x = i % pages_per_row; + int y = i / pages_per_row; + girara_info("x, y, page: %d, %d, %d (%d)", x, y, i, pages_per_row); + gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, zathura->global.page_padding, zathura->global.page_padding); } gtk_widget_show_all(zathura->ui.page_view); From 752ca8ec1184eafdfb3368e62d37a5dad2e3c65a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 20:46:33 +0200 Subject: [PATCH 125/197] Destroy surface if page is not visible --- callbacks.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/callbacks.c b/callbacks.c index 79d0857..fb4a180 100644 --- a/callbacks.c +++ b/callbacks.c @@ -75,6 +75,10 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) ) { page->visible = true; render_page(zathura->sync.render_thread, page); + } else { + page->visible = false; + cairo_surface_destroy(page->surface); + page->surface = NULL; } free(offset); From 5c5df5bf828c15e7eceee2b81dc9d461f61084a7 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 19 Apr 2011 21:42:18 +0200 Subject: [PATCH 126/197] Fixed rendering --- callbacks.c | 14 ++++---------- document.c | 1 + render.c | 26 ++++++++++++++++++-------- zathura.c | 34 ++++++++++++++-------------------- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/callbacks.c b/callbacks.c index fb4a180..e027b6b 100644 --- a/callbacks.c +++ b/callbacks.c @@ -44,7 +44,6 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) return; } - // FIXME /* get current adjustment values */ gdouble lower = gtk_adjustment_get_value(adjustment); gdouble upper = lower + gtk_adjustment_get_page_size(adjustment); @@ -54,11 +53,6 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) { zathura_page_t* page = zathura->document->pages[page_id]; - /* check for rendered attribute */ - if (page->surface != NULL) { - continue; - } - page_offset_t* offset = page_calculate_offset(page); if (offset == NULL) { continue; @@ -67,14 +61,14 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) double begin = offset->y; double end = offset->y + page->height; - girara_info("%f %f; %f %f", begin, end, lower, upper); - - if ( ( (begin >= lower) && (end <= upper) ) /* [> page is in viewport <]*/ + if ( ( (begin >= lower) && (end <= upper) ) /* [> page is in viewport <]*/ || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* [> end of the page is in viewport <] */ || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* [> begin of the page is in viewport <] */ ) { page->visible = true; - render_page(zathura->sync.render_thread, page); + if (page->surface == NULL) { + render_page(zathura->sync.render_thread, page); + } } else { page->visible = false; cairo_surface_destroy(page->surface); diff --git a/document.c b/document.c index 894722b..d553a57 100644 --- a/document.c +++ b/document.c @@ -404,6 +404,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) page->surface = NULL; g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page); + gtk_widget_set_size_request(page->drawing_area, page->width * document->scale, page->height * document->scale); gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area); g_static_mutex_init(&(page->lock)); diff --git a/render.c b/render.c index a363cac..9e4f288 100644 --- a/render.c +++ b/render.c @@ -24,8 +24,6 @@ render_job(void* data) if (render(render_thread->zathura, page) != true) { girara_error("Rendering failed\n"); } - - girara_info("rendered page %d\n", page->number); } return NULL; @@ -171,7 +169,6 @@ render(zathura_t* zathura, zathura_page_t* page) } /* draw to gtk widget */ - girara_info("surface: %d %p", page->number, surface); page->surface = surface; gtk_widget_set_size_request(page->drawing_area, page_width, page_height); gtk_widget_queue_draw(page->drawing_area); @@ -204,7 +201,6 @@ render_all(zathura_t* zathura) gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) { - girara_info("in expose"); zathura_page_t* page = data; if (page == NULL) { return FALSE; @@ -220,14 +216,28 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) return FALSE; } - girara_info("page->num %d page->surface: %p", page->number, page->surface); if (page->surface != NULL) { cairo_set_source_surface(cairo, page->surface, 0, 0); cairo_paint(cairo); + } else { + /* set background color */ + cairo_set_source_rgb(cairo, 255, 255, 255); + cairo_rectangle(cairo, 0, 0, page->width * page->document->scale, page->height * page->document->scale); + cairo_fill(cairo); - // cairo_surface_destroy(page->surface); - // page->surface = NULL; - } else if (page->visible) { + /* write text */ + cairo_set_source_rgb(cairo, 0, 0, 0); + const char* text = "Loading..."; + cairo_select_font_face(cairo, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size(cairo, 16.0); + cairo_text_extents_t extents; + cairo_text_extents(cairo, text, &extents); + double x = (page->width * page->document->scale) / 2 - (extents.width / 2 + extents.x_bearing); + double y = (page->height * page->document->scale) / 2 - (extents.height / 2 + extents.y_bearing); + cairo_move_to(cairo, x, y); + cairo_show_text(cairo, text); + + /* render real page */ render_page(page->document->zathura->sync.render_thread, page); } cairo_destroy(cairo); diff --git a/zathura.c b/zathura.c index 43aec68..c476245 100644 --- a/zathura.c +++ b/zathura.c @@ -112,8 +112,13 @@ zathura_init(int argc, char* argv[]) goto error_free; } + /* callbacks */ + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura); + GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + g_signal_connect(G_OBJECT(view_hadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura); + gtk_widget_show(zathura->ui.page_view); - gtk_box_set_spacing(GTK_BOX(zathura->ui.page_view), 0); /* Put the table in the main window */ // gtk_container_add(GTK_CONTAINER (zathura->ui.page_view), table); @@ -139,9 +144,6 @@ zathura_init(int argc, char* argv[]) /* signals */ g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); - GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura); - /* girara events */ zathura->ui.session->events.buffer_changed = buffer_changed; @@ -155,6 +157,9 @@ zathura_init(int argc, char* argv[]) int* page_padding = girara_setting_get(zathura->ui.session, "page-padding"); zathura->global.page_padding = (page_padding) ? *page_padding : 1; + gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding); + gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding); + /* open document if passed */ if (argc > 1) { zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t)); @@ -251,9 +256,10 @@ document_open(zathura_t* zathura, const char* path, const char* password) goto error_free; } - /* first page */ - if (!page_set(zathura, 0)) { - goto error_free; + /* create blank pages */ + for (int page_id = 0; page_id < document->number_of_pages; page_id++) { + zathura_page_t* page = document->pages[page_id]; + gtk_widget_realize(page->event_box); } return true; @@ -321,24 +327,12 @@ error_out: void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { - /* empty page view */ - /* GList* container = gtk_container_get_children(GTK_CONTAINER(zathura->ui.page_view)); - for (GList* child = container; child; child = g_list_next(child)) { - gtk_container_remove(GTK_CONTAINER(zathura->ui.page_view), child->data); - } - - GtkWidget* row = NULL; */ - - /* create blank pages */ - - gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row); for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { int x = i % pages_per_row; int y = i / pages_per_row; - girara_info("x, y, page: %d, %d, %d (%d)", x, y, i, pages_per_row); - gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, zathura->global.page_padding, zathura->global.page_padding); + gtk_table_attach(GTK_TABLE(zathura->ui.page_view), zathura->document->pages[i]->event_box, x, x + 1, y, y + 1, GTK_EXPAND, GTK_EXPAND, 0, 0); } gtk_widget_show_all(zathura->ui.page_view); From 08c8187ef57d135b58223b1aac36bc787822f29a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 20 Apr 2011 15:55:09 +0200 Subject: [PATCH 127/197] Load default configuration --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index f1f8577..02508c4 100644 --- a/config.c +++ b/config.c @@ -9,7 +9,7 @@ void config_load_default(zathura_t* zathura) { - if (zathura || !zathura->ui.session) { + if (!zathura || !zathura->ui.session) { return; } From 48f04fc587d5788ff1eccd5ce9adbcb9c4d12f1d Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 20 Apr 2011 16:58:08 +0200 Subject: [PATCH 128/197] fix a typo --- zathura.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zathura.c b/zathura.c index 0c7aa65..c323f91 100644 --- a/zathura.c +++ b/zathura.c @@ -73,7 +73,7 @@ zathura_init(int argc, char* argv[]) zathura->config.data_dir = g_strdup(config_dir); } else { gchar* path = girara_get_xdg_path(XDG_DATA); - zathura->config.config_dir = g_build_filename(path, "zathura", NULL); + zathura->config.data_dir = g_build_filename(path, "zathura", NULL); g_free(path); } From 4146cfbb84b0c4345a0b90085d43b1b5970f663f Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 21 Apr 2011 14:30:23 +0200 Subject: [PATCH 129/197] Added shift-space command --- config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/config.c b/config.c index 02508c4..2ef4c24 100644 --- a/config.c +++ b/config.c @@ -76,6 +76,7 @@ config_load_default(zathura_t* zathura) 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 | INDEX, 0, NULL); From 9f5430e4497489a3b27bbdb723fbf4f5d37feb57 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 25 Apr 2011 16:54:21 +0200 Subject: [PATCH 130/197] Handle 0 pages-per-row --- zathura.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zathura.c b/zathura.c index c323f91..5295987 100644 --- a/zathura.c +++ b/zathura.c @@ -335,6 +335,11 @@ error_out: void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { + /* show at least one page */ + if (pages_per_row == 0) { + pages_per_row = 1; + } + gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row); for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { From 68bda8550f5d5bd266d00a3f4d05f621df71dc06 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 25 Apr 2011 17:41:45 +0200 Subject: [PATCH 131/197] Initialize girara after parsing the configuration --- zathura.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/zathura.c b/zathura.c index 5295987..430c009 100644 --- a/zathura.c +++ b/zathura.c @@ -94,11 +94,6 @@ zathura_init(int argc, char* argv[]) goto error_out; } - zathura->ui.session->gtk.embed = embed; - if (girara_session_init(zathura->ui.session) == false) { - goto error_out; - } - zathura->ui.session->global.data = zathura; zathura->ui.statusbar.file = NULL; zathura->ui.statusbar.buffer = NULL; @@ -106,6 +101,29 @@ zathura_init(int argc, char* argv[]) zathura->ui.page_view = NULL; zathura->ui.index = NULL; + /* load plugins */ + zathura_document_plugins_load(zathura); + + /* configuration */ + config_load_default(zathura); + + /* load global configuration files */ + config_load_file(zathura, GLOBAL_RC); + + /* load local configuration files */ + char* configuration_file = g_build_filename(zathura->config.config_dir, ZATHURA_RC, NULL); + config_load_file(zathura, configuration_file); + free(configuration_file); + + /* initialize girara */ + zathura->ui.session->gtk.embed = embed; + if (girara_session_init(zathura->ui.session) == false) { + goto error_out; + } + + /* girara events */ + zathura->ui.session->events.buffer_changed = buffer_changed; + /* page view */ zathura->ui.page_view = gtk_table_new(0, 0, TRUE); if (!zathura->ui.page_view) { @@ -120,9 +138,6 @@ zathura_init(int argc, char* argv[]) gtk_widget_show(zathura->ui.page_view); - /* Put the table in the main window */ - // gtk_container_add(GTK_CONTAINER (zathura->ui.page_view), table); - /* statusbar */ zathura->ui.statusbar.file = girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL); if (zathura->ui.statusbar.file == NULL) { @@ -144,23 +159,6 @@ zathura_init(int argc, char* argv[]) /* signals */ g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); - /* girara events */ - zathura->ui.session->events.buffer_changed = buffer_changed; - - /* load plugins */ - zathura_document_plugins_load(zathura); - - /* configuration */ - config_load_default(zathura); - - /* load global configuration files */ - config_load_file(zathura, GLOBAL_RC); - - /* load local configuration files */ - char* configuration_file = g_build_filename(zathura->config.config_dir, ZATHURA_RC, NULL); - config_load_file(zathura, configuration_file); - free(configuration_file); - /* save page padding */ int* page_padding = girara_setting_get(zathura->ui.session, "page-padding"); zathura->global.page_padding = (page_padding) ? *page_padding : 1; From 8af8103bf3f3dea9bebe45683b0ba0a4f3edd9ed Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 25 Apr 2011 19:52:04 +0200 Subject: [PATCH 132/197] Updated key bindings --- config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.c b/config.c index 2ef4c24..34532b0 100644 --- a/config.c +++ b/config.c @@ -68,9 +68,9 @@ config_load_default(zathura_t* zathura) 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, DOWN, NULL); - girara_shortcut_add(gsession, 0, GDK_Down, NULL, sc_scroll, NORMAL, RIGHT, NULL); - girara_shortcut_add(gsession, 0, GDK_Right, NULL, sc_scroll, NORMAL, UP, 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); From a5bf154dfa39f7d519bd381b539cefba04f4c425 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 25 Apr 2011 23:49:38 +0200 Subject: [PATCH 133/197] Fix zooming in poppler pdf backend --- ft/pdf-poppler/pdf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index 3850ceb..e0ce1cc 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -269,7 +269,7 @@ pdf_page_render(zathura_page_t* page) return NULL; } - poppler_page_render_to_pixbuf(page->data, 0, 0, page->width, page->height, + poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, page->document->scale, 0, pixbuf); /* create image buffer */ From 1806b047866c869b4857333e5d9624054ec73317 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 26 Apr 2011 16:39:40 +0200 Subject: [PATCH 134/197] Initialize lock before creating the render thread --- render.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/render.c b/render.c index 9e4f288..ec7797a 100644 --- a/render.c +++ b/render.c @@ -51,12 +51,6 @@ render_init(zathura_t* zathura) goto error_free; } - render_thread->thread = g_thread_create(render_job, render_thread, TRUE, NULL); - - if (!render_thread->thread) { - goto error_free; - } - render_thread->cond = g_cond_new(); if (!render_thread->cond) { @@ -69,6 +63,12 @@ render_init(zathura_t* zathura) goto error_free; } + render_thread->thread = g_thread_create(render_job, render_thread, TRUE, NULL); + + if (!render_thread->thread) { + goto error_free; + } + return render_thread; error_free: From 691b5c7697ce606f6b4e256f07d77baccecf653f Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 26 Apr 2011 17:09:39 +0200 Subject: [PATCH 135/197] Postscript support through libspectre --- README | 23 ++----- document.c | 7 +- ft/ps/Makefile | 57 +++++++++++++++ ft/ps/config.mk | 21 ++++++ ft/ps/ps.c | 180 ++++++++++++++++++++++++++++++++++++++++++++++++ ft/ps/ps.h | 22 ++++++ 6 files changed, 290 insertions(+), 20 deletions(-) create mode 100644 ft/ps/Makefile create mode 100644 ft/ps/config.mk create mode 100644 ft/ps/ps.c create mode 100644 ft/ps/ps.h diff --git a/README b/README index fea03be..ead997d 100644 --- a/README +++ b/README @@ -1,21 +1,16 @@ -zathura - pdf viewer +zathura - a document viewer -------------------- -zathura is a pdf viewer based on the poppler pdf rendering library +zathura is a highly customizable and functional document viewer based on the +girara user interface library and several document libraries. Requirements ------------ -poppler-glib (0.12.3) -gtk2 (2.18.6) -glib2 (2.22.4) - -Configuration -------------- -You can modify some parts of zathura by editing the config.h file +gtk2 (>= 2.18.6) +girara Installation ------------ -Customise config.h according to your wishes and run the following -command to build and install zathura: +To build and install zathura: make install @@ -24,9 +19,3 @@ Uninstall: To delete zathura from your system, just type: make uninstall - -Use zathura ------------ -Just run: - - zathura diff --git a/document.c b/document.c index f688f9a..761113a 100644 --- a/document.c +++ b/document.c @@ -131,7 +131,7 @@ zathura_document_plugins_free(zathura_t* zathura) if (iter == NULL) { return; } - + do { zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); free(plugin->file_extension); @@ -158,7 +158,7 @@ zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t* girara_error("plugin: already registered for filetype %s\n", plugin->file_extension); girara_list_iterator_free(iter); return false; - } + } } while (girara_list_iterator_next(iter)); girara_list_iterator_free(iter); } @@ -237,7 +237,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password if (iter == NULL) { goto error_free; } - + do { zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); if (!strcmp(file_extension, plugin->file_extension)) { @@ -403,6 +403,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) page->event_box = gtk_event_box_new(); page->drawing_area = gtk_drawing_area_new(); page->surface = NULL; + page->document = document; g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page); gtk_widget_set_size_request(page->drawing_area, page->width * document->scale, page->height * document->scale); diff --git a/ft/ps/Makefile b/ft/ps/Makefile new file mode 100644 index 0000000..df35a2a --- /dev/null +++ b/ft/ps/Makefile @@ -0,0 +1,57 @@ +# See LICENSE file for license and copyright information + +include config.mk + +PLUGIN = ps +SOURCE = ps.c +OBJECTS = ${SOURCE:.c=.o} +DOBJECTS = ${SOURCE:.c=.do} + +all: options ${PLUGIN} + +options: + @echo ${PLUGIN} build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "DFLAGS = ${DFLAGS}" + @echo "CC = ${CC}" + +%.o: %.c + @echo CC $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep + +%.do: %.c + @echo CC $< + @mkdir -p .depend + @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep + +${OBJECTS}: config.mk +${DOBJECTS}: config.mk + +${PLUGIN}: ${OBJECTS} + @echo LD $@ + @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS} + +${PLUGIN}-debug: ${DOBJECTS} + @echo LD $@ + @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} + +clean: + @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend + +debug: options ${PLUGIN}-debug + +install: all + @echo installing ${PLUGIN} plugin + @mkdir -p ${DESTDIR}${PREFIX}/lib/zathura + @cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura + +uninstall: + @echo uninstalling ${PLUGIN} plugin + @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so + @rm -rf ${DESTDIR}${PREFIX}/lib/zathura + +-include $(wildcard .depend/*.dep) + +.PHONY: all options clean debug install uninstall diff --git a/ft/ps/config.mk b/ft/ps/config.mk new file mode 100644 index 0000000..d44baaf --- /dev/null +++ b/ft/ps/config.mk @@ -0,0 +1,21 @@ +# See LICENSE file for license and copyright information + +# paths +PREFIX ?= /usr + +# libs +GTK_INC = $(shell pkg-config --cflags gtk+-2.0) +GTK_LIB = $(shell pkg-config --libs gtk+-2.0) + +INCS = -I. -I/usr/include ${GTK_INC} +LIBS = -lc ${GTK_LIB} -lspectre + +# flags +CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) + +# debug +DFLAGS = -g + +# compiler +CC ?= gcc +LD ?= ld diff --git a/ft/ps/ps.c b/ft/ps/ps.c new file mode 100644 index 0000000..d5f5a0e --- /dev/null +++ b/ft/ps/ps.c @@ -0,0 +1,180 @@ +/* See LICENSE file for license and copyright information */ + +#include + +#include "ps.h" +#include "../../zathura.h" + +void +plugin_register(zathura_document_plugin_t* plugin) +{ + plugin->file_extension = "ps"; + plugin->open_function = ps_document_open; +} + +bool +ps_document_open(zathura_document_t* document) +{ + if (!document) { + goto error_ret; + } + + document->functions.document_free = ps_document_free; + document->functions.page_get = ps_page_get; + document->functions.page_render = ps_page_render; + document->functions.page_free = ps_page_free; + + document->data = malloc(sizeof(ps_document_t)); + if (!document->data) { + goto error_ret; + } + + ps_document_t* ps_document = (ps_document_t*) document->data; + ps_document->document = spectre_document_new(); + + if (ps_document->document == NULL) { + goto error_free; + } + + spectre_document_load(ps_document->document, document->file_path); + + if (spectre_document_status(ps_document->document) != SPECTRE_STATUS_SUCCESS) { + goto error_free; + } + + document->number_of_pages = spectre_document_get_n_pages(ps_document->document); + + return true; + +error_free: + + if (ps_document->document != NULL) { + spectre_document_free(ps_document->document); + } + + free(document->data); + document->data = NULL; + +error_ret: + + return false; +} + +bool +ps_document_free(zathura_document_t* document) +{ + if (!document) { + return false; + } + + if (document->data != NULL) { + ps_document_t* ps_document = (ps_document_t*) document->data; + spectre_document_free(ps_document->document); + free(document->data); + document->data = NULL; + } + + return true; +} + +zathura_page_t* +ps_page_get(zathura_document_t* document, unsigned int page) +{ + if (!document || !document->data) { + return NULL; + } + + ps_document_t* ps_document = (ps_document_t*) document->data; + zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); + + if (document_page == NULL) { + goto error_ret; + } + + SpectrePage* ps_page = spectre_document_get_page(ps_document->document, page); + + if (ps_page == NULL) { + goto error_free; + } + + int page_width; + int page_height; + spectre_page_get_size(ps_page, &(page_width), &(page_height)); + + document_page->width = page_width; + document_page->height = page_height; + document_page->document = document; + document_page->data = ps_page; + + return document_page; + +error_free: + + free(document_page); + +error_ret: + + return NULL; +} + +bool +ps_page_free(zathura_page_t* page) +{ + if (page == NULL) { + return false; + } + + if (page->data != NULL) { + SpectrePage* ps_page = (SpectrePage*) page->data; + spectre_page_free(ps_page); + } + + free(page); + + return true; +} + +zathura_image_buffer_t* +ps_page_render(zathura_page_t* page) +{ + if (!page || !page->data || !page->document) { + return NULL; + } + + /* calculate sizes */ + unsigned int page_width = page->document->scale * page->width; + unsigned int page_height = page->document->scale * page->height; + + /* create image buffer */ + zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); + + if (image_buffer == NULL) { + return NULL; + } + + SpectrePage* ps_page = (SpectrePage*) page->data; + SpectreRenderContext* context = spectre_render_context_new(); + + spectre_render_context_set_scale(context, page->document->scale, page->document->scale); + spectre_render_context_set_rotation(context, 0); + + unsigned char* page_data; + int row_length; + spectre_page_render(ps_page, context, &page_data, &row_length); + + for (unsigned int y = 0; y < page_height; y++) { + for (unsigned int x = 0; x < page_width; x++) { + unsigned char *s = page_data + y * row_length + x * 4; + guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; + p[0] = s[0]; + p[1] = s[1]; + p[2] = s[2]; + } + } + + spectre_render_context_free(context); + + ps_document_t* ps_document = (ps_document_t*) page->document->data; + + return image_buffer; +} diff --git a/ft/ps/ps.h b/ft/ps/ps.h new file mode 100644 index 0000000..4ef3560 --- /dev/null +++ b/ft/ps/ps.h @@ -0,0 +1,22 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef PS_H +#define PS_H + +#include +#include + +#include "../../document.h" + +typedef struct ps_document_s +{ + SpectreDocument* document; +} ps_document_t; + +bool ps_document_open(zathura_document_t* document); +bool ps_document_free(zathura_document_t* document); +zathura_page_t* ps_page_get(zathura_document_t* document, unsigned int page); +zathura_image_buffer_t* ps_page_render(zathura_page_t* page); +bool ps_page_free(zathura_page_t* page); + +#endif // PS_H From 1ba891658c705d774da1740e644d761c3f65edb9 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 27 Apr 2011 19:03:08 +0200 Subject: [PATCH 136/197] Moved plugins to own repositories Every plugin is now accesible in a separate repository --- Makefile | 14 +- ft/Makefile | 20 --- ft/djvu/Makefile | 57 -------- ft/djvu/config.mk | 21 --- ft/djvu/djvu.c | 269 ---------------------------------- ft/djvu/djvu.h | 30 ---- ft/pdf-mupdf/Makefile | 57 -------- ft/pdf-mupdf/config.mk | 21 --- ft/pdf-mupdf/pdf.c | 244 ------------------------------- ft/pdf-mupdf/pdf.h | 33 ----- ft/pdf-poppler/Makefile | 57 -------- ft/pdf-poppler/config.mk | 21 --- ft/pdf-poppler/pdf.c | 301 --------------------------------------- ft/pdf-poppler/pdf.h | 28 ---- ft/ps/Makefile | 57 -------- ft/ps/config.mk | 21 --- ft/ps/ps.c | 180 ----------------------- ft/ps/ps.h | 22 --- 18 files changed, 8 insertions(+), 1445 deletions(-) delete mode 100644 ft/Makefile delete mode 100644 ft/djvu/Makefile delete mode 100644 ft/djvu/config.mk delete mode 100644 ft/djvu/djvu.c delete mode 100644 ft/djvu/djvu.h delete mode 100644 ft/pdf-mupdf/Makefile delete mode 100644 ft/pdf-mupdf/config.mk delete mode 100644 ft/pdf-mupdf/pdf.c delete mode 100644 ft/pdf-mupdf/pdf.h delete mode 100644 ft/pdf-poppler/Makefile delete mode 100644 ft/pdf-poppler/config.mk delete mode 100644 ft/pdf-poppler/pdf.c delete mode 100644 ft/pdf-poppler/pdf.h delete mode 100644 ft/ps/Makefile delete mode 100644 ft/ps/config.mk delete mode 100644 ft/ps/ps.c delete mode 100644 ft/ps/ps.h diff --git a/Makefile b/Makefile index f73901f..2e2616c 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,11 @@ include config.mk PROJECT = zathura -SOURCE = $(shell find . -iname "*.c" -a ! -iwholename "*./ft*") +SOURCE = $(shell find . -iname "*.c") OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) all: options ${PROJECT} - ${MAKE} -C ft options: @echo ${PROJECT} build options: @@ -37,14 +36,12 @@ ${PROJECT}: ${OBJECTS} clean: @rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ ${DOBJECTS} ${PROJECT}-debug .depend - @${MAKE} -C ft clean ${PROJECT}-debug: ${DOBJECTS} @echo CC -o ${PROJECT}-debug @${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS} debug: ${PROJECT}-debug - @${MAKE} -C ft debug valgrind: debug valgrind --tool=memcheck --leak-check=yes --show-reachable=yes \ @@ -66,18 +63,23 @@ install: all @mkdir -p ${DESTDIR}${PREFIX}/bin @cp -f ${PROJECT} ${DESTDIR}${PREFIX}/bin @chmod 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin/${PROJECT} + @echo installing header file + @mkdir -p ${DESTDIR}${PREFIX}/include/${PROJECT} + @cp -f document.h ${DESTDIR}${PREFIX}/include/${PROJECT} + @cp -f zathura.h ${DESTDIR}${PREFIX}/include/${PROJECT} @echo installing manual page @mkdir -p ${DESTDIR}${MANPREFIX}/man1 @sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 - @${MAKE} -C ft install uninstall: @echo removing executable file @rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT} + @echo removing header file + @rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/document.h + @rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/zathura.h @echo removing manual page @rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 - @${MAKE} -C ft uninstall -include $(wildcard .depend/*.dep) diff --git a/ft/Makefile b/ft/Makefile deleted file mode 100644 index 254eeb4..0000000 --- a/ft/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# See LICENSE file for license and copyright information - -SUBDIRS = $(shell find -mindepth 2 -maxdepth 2 -iname "Makefile" -exec dirname '{}' \;) - -all: - @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir}; done - -debug: - @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} debug; done - -clean: - @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} clean; done - -install: - @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} install; done - -uninstall: - @for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} uninstall; done - -.PHONY: all debug clean install uninstall diff --git a/ft/djvu/Makefile b/ft/djvu/Makefile deleted file mode 100644 index a19da49..0000000 --- a/ft/djvu/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -# See LICENSE file for license and copyright information - -include config.mk - -PLUGIN = djvu -SOURCE = djvu.c -OBJECTS = ${SOURCE:.c=.o} -DOBJECTS = ${SOURCE:.c=.do} - -all: options ${PLUGIN} - -options: - @echo ${PLUGIN} build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "DFLAGS = ${DFLAGS}" - @echo "CC = ${CC}" - -%.o: %.c - @echo CC $< - @mkdir -p .depend - @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep - -%.do: %.c - @echo CC $< - @mkdir -p .depend - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep - -${OBJECTS}: config.mk -${DOBJECTS}: config.mk - -${PLUGIN}: ${OBJECTS} - @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS} - -${PLUGIN}-debug: ${DOBJECTS} - @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} - -clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend - -debug: options ${PLUGIN}-debug - -install: all - @echo installing ${PLUGIN} plugin - @mkdir -p ${DESTDIR}${PREFIX}/lib/zathura - @cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura - -uninstall: - @echo uninstalling ${PLUGIN} plugin - @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so - @rm -rf ${DESTDIR}${PREFIX}/lib/zathura - --include $(wildcard .depend/*.dep) - -.PHONY: all options clean debug install uninstall diff --git a/ft/djvu/config.mk b/ft/djvu/config.mk deleted file mode 100644 index 54154b3..0000000 --- a/ft/djvu/config.mk +++ /dev/null @@ -1,21 +0,0 @@ -# See LICENSE file for license and copyright information - -# paths -PREFIX ?= /usr - -# libs -DJVU_INC = $(shell pkg-config --cflags gtk+-2.0 ddjvuapi) -DJVU_LIB = $(shell pkg-config --libs gtk+-2.0 ddjvuapi) - -INCS = -I. -I/usr/include ${DJVU_INC} -LIBS = -lc ${DJVU_LIB} - -# flags -CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) - -# debug -DFLAGS = -g - -# compiler -CC ?= gcc -LD ?= ld diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c deleted file mode 100644 index 46908c2..0000000 --- a/ft/djvu/djvu.c +++ /dev/null @@ -1,269 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include - -#include "djvu.h" -#include "../../zathura.h" - -void -plugin_register(zathura_document_plugin_t* plugin) -{ - plugin->file_extension = "djvu"; - plugin->open_function = djvu_document_open; -} - -bool -djvu_document_open(zathura_document_t* document) -{ - if (!document) { - goto error_out; - } - - document->functions.document_free = djvu_document_free; - document->functions.document_index_generate = djvu_document_index_generate;; - document->functions.document_save_as = djvu_document_save_as; - document->functions.document_attachments_get = djvu_document_attachments_get; - document->functions.page_get = djvu_page_get; - document->functions.page_search_text = djvu_page_search_text; - document->functions.page_links_get = djvu_page_links_get; - document->functions.page_form_fields_get = djvu_page_form_fields_get; - document->functions.page_render = djvu_page_render; - document->functions.page_free = djvu_page_free; - - document->data = malloc(sizeof(djvu_document_t)); - if (!document->data) { - goto error_out; - } - - djvu_document_t* djvu_document = (djvu_document_t*) document->data; - djvu_document->context = NULL; - djvu_document->document = NULL; - djvu_document->format = NULL; - - /* setup format */ - djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGB24, 0, NULL); - - if (!djvu_document->format) { - goto error_free; - } - - ddjvu_format_set_row_order(djvu_document->format, TRUE); - - /* setup context */ - djvu_document->context = ddjvu_context_create("zathura"); - - if (!djvu_document->context) { - goto error_free; - } - - /* setup document */ - djvu_document->document = ddjvu_document_create_by_filename(djvu_document->context, document->file_path, FALSE); - - if (!djvu_document->document) { - goto error_free; - } - - /* load document info */ - ddjvu_message_t* msg; - ddjvu_message_wait(djvu_document->context); - - while ((msg = ddjvu_message_peek(djvu_document->context)) && (msg->m_any.tag != DDJVU_DOCINFO)) { - if (msg->m_any.tag == DDJVU_ERROR) { - goto error_free; - } - - ddjvu_message_pop(djvu_document->context); - } - - /* decoding error */ - if (ddjvu_document_decoding_error(djvu_document->document)) { - goto error_free; - } - - document->number_of_pages = ddjvu_document_get_pagenum(djvu_document->document); - - return true; - -error_free: - - if (djvu_document->format) { - ddjvu_format_release(djvu_document->format); - } - - if (djvu_document->context) { - ddjvu_context_release(djvu_document->context); - } - - free(document->data); - document->data = NULL; - -error_out: - - return false; -} - -bool -djvu_document_free(zathura_document_t* document) -{ - if (!document) { - return false; - } - - if (document->data) { - djvu_document_t* djvu_document = (djvu_document_t*) document->data; - ddjvu_context_release(djvu_document->context); - ddjvu_document_release(djvu_document->document); - ddjvu_format_release(djvu_document->format); - free(document->data); - } - - return true; -} - -girara_tree_node_t* -djvu_document_index_generate(zathura_document_t* document) -{ - return NULL; -} - -bool -djvu_document_save_as(zathura_document_t* document, const char* path) -{ - if (!document || !document->data || !path) { - return false; - } - - djvu_document_t* djvu_document = (djvu_document_t*) document->data; - - FILE* fp = fopen(path, "w"); - if (!fp) { - return false; - } - - ddjvu_document_save(djvu_document->document, fp, 0, NULL); - fclose(fp); - - return true; -} - -zathura_list_t* -djvu_document_attachments_get(zathura_document_t* document) -{ - return NULL; -} - -zathura_page_t* -djvu_page_get(zathura_document_t* document, unsigned int page) -{ - if (!document || !document->data) { - return NULL; - } - - djvu_document_t* djvu_document = (djvu_document_t*) document->data; - zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); - - if (!document_page) { - return NULL; - } - - document_page->document = document; - document_page->data = NULL; - - ddjvu_status_t status; - ddjvu_pageinfo_t page_info; - - while ((status = ddjvu_document_get_pageinfo(djvu_document->document, page, &page_info)) < DDJVU_JOB_OK); - - if (status >= DDJVU_JOB_FAILED) { - free(document_page); - return NULL; - } - - document_page->width = 0.2 * page_info.width; - document_page->height = 0.2 * page_info.height; - - return document_page; -} - -bool -djvu_page_free(zathura_page_t* page) -{ - if (!page) { - return false; - } - - free(page); - - return true; -} - -zathura_list_t* -djvu_page_search_text(zathura_page_t* page, const char* text) -{ - return NULL; -} - -zathura_list_t* -djvu_page_links_get(zathura_page_t* page) -{ - return NULL; -} - -zathura_list_t* -djvu_page_form_fields_get(zathura_page_t* page) -{ - return NULL; -} - -zathura_image_buffer_t* -djvu_page_render(zathura_page_t* page) -{ - if (!page || !page->document) { - return NULL; - } - - /* calculate sizes */ - unsigned int page_width = page->document->scale * page->width; - unsigned int page_height = page->document->scale * page->height; - - if (!page_width || !page_height) { - goto error_out; - } - - /* init ddjvu render data */ - djvu_document_t* djvu_document = (djvu_document_t*) page->document->data; - ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno(djvu_document->document, page->number); - - if (!djvu_page) { - goto error_out; - } - - while (!ddjvu_page_decoding_done(djvu_page)); - - ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; - ddjvu_rect_t prect = { 0, 0, page_width, page_height }; - - zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); - - if (image_buffer == NULL) { - goto error_free; - } - - /* set rotation */ - ddjvu_page_set_rotation(djvu_page, DDJVU_ROTATE_0); - - /* render page */ - ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, djvu_document->format, - 3 * page_width, (char*) image_buffer->data); - - return image_buffer; - -error_free: - - ddjvu_page_release(djvu_page); - zathura_image_buffer_free(image_buffer); - -error_out: - - return NULL; -} diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h deleted file mode 100644 index 31444ff..0000000 --- a/ft/djvu/djvu.h +++ /dev/null @@ -1,30 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef DJVU_H -#define DJVU_H - -#include -#include - -#include "../../document.h" - -typedef struct djvu_document_s -{ - ddjvu_context_t* context; - ddjvu_document_t* document; - ddjvu_format_t* format; -} djvu_document_t; - -bool djvu_document_open(zathura_document_t* document); -bool djvu_document_free(zathura_document_t* document); -girara_tree_node_t* djvu_document_index_generate(zathura_document_t* document); -bool djvu_document_save_as(zathura_document_t* document, const char* path); -zathura_list_t* djvu_document_attachments_get(zathura_document_t* document); -zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page); -zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text); -zathura_list_t* djvu_page_links_get(zathura_page_t* page); -zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page); -zathura_image_buffer_t* djvu_page_render(zathura_page_t* page); -bool djvu_page_free(zathura_page_t* page); - -#endif // DJVU_H diff --git a/ft/pdf-mupdf/Makefile b/ft/pdf-mupdf/Makefile deleted file mode 100644 index cdc30ff..0000000 --- a/ft/pdf-mupdf/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -# See LICENSE file for license and copyright information - -include config.mk - -PLUGIN = pdf -SOURCE = pdf.c -OBJECTS = ${SOURCE:.c=.o} -DOBJECTS = ${SOURCE:.c=.do} - -all: options ${PLUGIN} - -options: - @echo ${PLUGIN} build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "DFLAGS = ${DFLAGS}" - @echo "CC = ${CC}" - -%.o: %.c - @echo CC $< - @mkdir -p .depend - @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep - -%.do: %.c - @echo CC $< - @mkdir -p .depend - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep - -${OBJECTS}: config.mk -${DOBJECTS}: config.mk - -${PLUGIN}: ${OBJECTS} - @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS} - -${PLUGIN}-debug: ${DOBJECTS} - @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} - -clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend - -debug: options ${PLUGIN}-debug - -install: all - @echo installing ${PLUGIN} plugin - @mkdir -p ${DESTDIR}${PREFIX}/lib/zathura - @cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura - -uninstall: - @echo uninstalling ${PLUGIN} plugin - @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so - @rm -rf ${DESTDIR}${PREFIX}/lib/zathura - --include $(wildcard .depend/*.dep) - -.PHONY: all options clean debug install uninstall diff --git a/ft/pdf-mupdf/config.mk b/ft/pdf-mupdf/config.mk deleted file mode 100644 index 9aeb43a..0000000 --- a/ft/pdf-mupdf/config.mk +++ /dev/null @@ -1,21 +0,0 @@ -# See LICENSE file for license and copyright information - -# paths -PREFIX ?= /usr - -# libs -GTK_INC = $(shell pkg-config --cflags gtk+-2.0) -GTK_LIB = $(shell pkg-config --libs gtk+-2.0) - -INCS = -I. -I/usr/include ${GTK_INC} -LIBS = -lc ${GTK_LIB} -lmupdf -ljbig2dec -ljpeg -lopenjpeg - -# flags -CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) - -# debug -DFLAGS = -g - -# compiler -CC ?= gcc -LD ?= ld diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c deleted file mode 100644 index 31d7cb2..0000000 --- a/ft/pdf-mupdf/pdf.c +++ /dev/null @@ -1,244 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include - -#include "pdf.h" -#include "../../zathura.h" - -void -plugin_register(zathura_document_plugin_t* plugin) -{ - plugin->file_extension = "pdf"; - plugin->open_function = pdf_document_open; -} - -bool -pdf_document_open(zathura_document_t* document) -{ - if (!document) { - goto error_ret; - } - - document->functions.document_free = pdf_document_free; - document->functions.page_get = pdf_page_get; - document->functions.page_search_text = pdf_page_search_text; - document->functions.page_links_get = pdf_page_links_get; - document->functions.page_form_fields_get = pdf_page_form_fields_get; - document->functions.page_render = pdf_page_render; - document->functions.page_free = pdf_page_free; - - document->data = malloc(sizeof(pdf_document_t)); - if (!document->data) { - goto error_ret; - } - - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - - fz_accelerate(); - pdf_document->glyphcache = fz_newglyphcache(); - - if (pdf_openxref(&(pdf_document->document), document->file_path, NULL)) { - fprintf(stderr, "error: could not open file\n"); - goto error_free; - } - - if (pdf_loadpagetree(pdf_document->document)) { - fprintf(stderr, "error: could not open file\n"); - goto error_free; - } - - document->number_of_pages = pdf_getpagecount(pdf_document->document); - - return true; - -error_free: - - if (pdf_document->document) { - pdf_freexref(pdf_document->document); - } - - if (pdf_document->glyphcache) { - fz_freeglyphcache(pdf_document->glyphcache); - } - - free(document->data); - document->data = NULL; - -error_ret: - - return false; -} - -bool -pdf_document_free(zathura_document_t* document) -{ - if (!document) { - return false; - } - - if (document->data) { - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - pdf_freexref(pdf_document->document); - fz_freeglyphcache(pdf_document->glyphcache); - free(document->data); - document->data = NULL; - } - - return true; -} - -zathura_page_t* -pdf_page_get(zathura_document_t* document, unsigned int page) -{ - if (!document || !document->data) { - return NULL; - } - - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); - - if (document_page == NULL) { - goto error_ret; - } - - mupdf_page_t* mupdf_page = malloc(sizeof(mupdf_page_t)); - - if (mupdf_page == NULL) { - goto error_free; - } - - document_page->document = document; - document_page->data = mupdf_page; - - mupdf_page->page_object = pdf_getpageobject(pdf_document->document, page + 1); - - if (pdf_loadpage(&(mupdf_page->page), pdf_document->document, mupdf_page->page_object)) { - goto error_free; - } - - document_page->width = mupdf_page->page->mediabox.x1 - mupdf_page->page->mediabox.x0; - document_page->height = mupdf_page->page->mediabox.y1 - mupdf_page->page->mediabox.y0; - - return document_page; - -error_free: - - if (mupdf_page && mupdf_page->page_object) { - fz_dropobj(mupdf_page->page_object); - } - - if (mupdf_page && mupdf_page->page) { - pdf_freepage(mupdf_page->page); - } - - free(document_page); - free(mupdf_page); - -error_ret: - - return NULL; -} - -bool -pdf_page_free(zathura_page_t* page) -{ - if (!page) { - return false; - } - - mupdf_page_t* mupdf_page = (mupdf_page_t*) page->data; - pdf_freepage(mupdf_page->page); - fz_dropobj(mupdf_page->page_object); - free(mupdf_page); - free(page); - - return true; -} - -zathura_list_t* -pdf_page_search_text(zathura_page_t* page, const char* text) -{ - return NULL; -} - -zathura_list_t* -pdf_page_links_get(zathura_page_t* page) -{ - return NULL; -} - -zathura_list_t* -pdf_page_form_fields_get(zathura_page_t* page) -{ - return NULL; -} - -zathura_image_buffer_t* -pdf_page_render(zathura_page_t* page) -{ - if (!page || !page->data || !page->document) { - return NULL; - } - - /* calculate sizes */ - unsigned int page_width = page->document->scale * page->width; - unsigned int page_height = page->document->scale * page->height; - - if (page->document->rotate == 90 || page->document->rotate == 270) { - unsigned int dim_temp = 0; - dim_temp = page_width; - page_width = page_height; - page_height = dim_temp; - } - - /* create image buffer */ - zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); - - if (image_buffer == NULL) { - return NULL; - } - - pdf_document_t* pdf_document = (pdf_document_t*) page->document->data; - mupdf_page_t* mupdf_page = (mupdf_page_t*) page->data; - - /* render */ - fz_displaylist* display_list = fz_newdisplaylist(); - fz_device* device = fz_newlistdevice(display_list); - - if (pdf_runpage(pdf_document->document, mupdf_page->page, device, fz_identity)) { - return NULL; - } - - fz_freedevice(device); - - pdf_agestore(pdf_document->document->store, 3); - - fz_matrix ctm = fz_identity; - ctm = fz_concat(ctm, fz_translate(0, -mupdf_page->page->mediabox.y1)); - ctm = fz_concat(ctm, fz_scale(page->document->scale, -page->document->scale)); - ctm = fz_concat(ctm, fz_rotate(mupdf_page->page->rotate)); - ctm = fz_concat(ctm, fz_rotate(page->document->rotate)); - fz_bbox bbox = fz_roundrect(fz_transformrect(ctm, mupdf_page->page->mediabox)); - - fz_pixmap* pixmap = fz_newpixmapwithrect(fz_devicergb, bbox); - fz_clearpixmapwithcolor(pixmap, 0xFF); - - device = fz_newdrawdevice(pdf_document->glyphcache, pixmap); - fz_executedisplaylist(display_list, device, ctm); - fz_freedevice(device); - - for (unsigned int y = 0; y < pixmap->h; y++) { - for (unsigned int x = 0; x < pixmap->w; x++) { - unsigned char *s = pixmap->samples + y * pixmap->w * 4 + x * 4; - guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; - p[0] = s[0]; - p[1] = s[1]; - p[2] = s[2]; - } - } - - fz_droppixmap(pixmap); - fz_freedisplaylist(display_list); - - return image_buffer; -} diff --git a/ft/pdf-mupdf/pdf.h b/ft/pdf-mupdf/pdf.h deleted file mode 100644 index 84d7b38..0000000 --- a/ft/pdf-mupdf/pdf.h +++ /dev/null @@ -1,33 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef PDF_H -#define PDF_H - -#include -#include -#include - -#include "../../document.h" - -typedef struct pdf_document_s -{ - fz_glyphcache *glyphcache; - pdf_xref *document; -} pdf_document_t; - -typedef struct mupdf_page_s -{ - fz_obj* page_object; - pdf_page* page; -} mupdf_page_t; - -bool pdf_document_open(zathura_document_t* document); -bool pdf_document_free(zathura_document_t* document); -zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); -zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); -zathura_list_t* pdf_page_links_get(zathura_page_t* page); -zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -zathura_image_buffer_t* pdf_page_render(zathura_page_t* page); -bool pdf_page_free(zathura_page_t* page); - -#endif // PDF_H diff --git a/ft/pdf-poppler/Makefile b/ft/pdf-poppler/Makefile deleted file mode 100644 index cdc30ff..0000000 --- a/ft/pdf-poppler/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -# See LICENSE file for license and copyright information - -include config.mk - -PLUGIN = pdf -SOURCE = pdf.c -OBJECTS = ${SOURCE:.c=.o} -DOBJECTS = ${SOURCE:.c=.do} - -all: options ${PLUGIN} - -options: - @echo ${PLUGIN} build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "DFLAGS = ${DFLAGS}" - @echo "CC = ${CC}" - -%.o: %.c - @echo CC $< - @mkdir -p .depend - @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep - -%.do: %.c - @echo CC $< - @mkdir -p .depend - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep - -${OBJECTS}: config.mk -${DOBJECTS}: config.mk - -${PLUGIN}: ${OBJECTS} - @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS} - -${PLUGIN}-debug: ${DOBJECTS} - @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} - -clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend - -debug: options ${PLUGIN}-debug - -install: all - @echo installing ${PLUGIN} plugin - @mkdir -p ${DESTDIR}${PREFIX}/lib/zathura - @cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura - -uninstall: - @echo uninstalling ${PLUGIN} plugin - @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so - @rm -rf ${DESTDIR}${PREFIX}/lib/zathura - --include $(wildcard .depend/*.dep) - -.PHONY: all options clean debug install uninstall diff --git a/ft/pdf-poppler/config.mk b/ft/pdf-poppler/config.mk deleted file mode 100644 index 2e505e9..0000000 --- a/ft/pdf-poppler/config.mk +++ /dev/null @@ -1,21 +0,0 @@ -# See LICENSE file for license and copyright information - -# paths -PREFIX ?= /usr - -# libs -PDF_INC = $(shell pkg-config --cflags gtk+-2.0 poppler-glib) -PDF_LIB = $(shell pkg-config --libs gtk+-2.0 poppler-glib) - -INCS = -I. -I/usr/include ${PDF_INC} -LIBS = -lc ${PDF_LIB} - -# flags -CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) - -# debug -DFLAGS = -g - -# compiler -CC ?= gcc -LD ?= ld diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c deleted file mode 100644 index e0ce1cc..0000000 --- a/ft/pdf-poppler/pdf.c +++ /dev/null @@ -1,301 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include -#include - -#include "pdf.h" -#include "../../zathura.h" - -void -plugin_register(zathura_document_plugin_t* plugin) -{ - plugin->file_extension = "pdf"; - plugin->open_function = pdf_document_open; -} - -bool -pdf_document_open(zathura_document_t* document) -{ - if (!document) { - goto error_out; - } - - document->functions.document_free = pdf_document_free; - document->functions.document_index_generate = pdf_document_index_generate;; - document->functions.document_save_as = pdf_document_save_as; - document->functions.document_attachments_get = pdf_document_attachments_get; - document->functions.page_get = pdf_page_get; - document->functions.page_search_text = pdf_page_search_text; - document->functions.page_links_get = pdf_page_links_get; - document->functions.page_form_fields_get = pdf_page_form_fields_get; - document->functions.page_render = pdf_page_render; - document->functions.page_free = pdf_page_free; - - document->data = malloc(sizeof(pdf_document_t)); - if (!document->data) { - goto error_out; - } - - /* format path */ - GError* error = NULL; - char* file_uri = g_filename_to_uri(document->file_path, NULL, &error); - - if (!file_uri) { - fprintf(stderr, "error: could not open file: %s\n", error->message); - goto error_free; - } - - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - pdf_document->document = poppler_document_new_from_file(file_uri, document->password, &error); - - if (!pdf_document->document) { - fprintf(stderr, "error: could not open file: %s\n", error->message); - goto error_free; - } - - document->number_of_pages = poppler_document_get_n_pages(pdf_document->document); - - g_free(file_uri); - - return true; - -error_free: - - if (error) { - g_error_free(error); - } - - if (file_uri) { - g_free(file_uri); - } - - free(document->data); - document->data = NULL; - -error_out: - - return false; -} - -bool -pdf_document_free(zathura_document_t* document) -{ - if (!document) { - return false; - } - - if (document->data) { - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - g_object_unref(pdf_document->document); - free(document->data); - document->data = NULL; - } - - return true; -} - -static void -build_index(pdf_document_t* pdf, girara_tree_node_t* root, PopplerIndexIter* iter) -{ - if (!root || !iter) { - return; - } - - do - { - PopplerAction* action = poppler_index_iter_get_action(iter); - - if (!action) { - continue; - } - - gchar* markup = g_markup_escape_text(action->any.title, -1); - zathura_index_element_t* index_element = zathura_index_element_new(markup); - - if (action->type == POPPLER_ACTION_URI) { - index_element->type = ZATHURA_LINK_EXTERNAL; - index_element->target.uri = g_strdup(action->uri.uri); - } else if (action->type == POPPLER_ACTION_GOTO_DEST) { - index_element->type = ZATHURA_LINK_TO_PAGE; - - if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) { - PopplerDest* dest = poppler_document_find_dest(pdf->document, action->goto_dest.dest->named_dest); - if (dest) { - index_element->target.page_number = dest->page_num - 1; - poppler_dest_free(dest); - } - } else { - index_element->target.page_number = action->goto_dest.dest->page_num - 1; - } - } else { - poppler_action_free(action); - zathura_index_element_free(index_element); - continue; - } - - poppler_action_free(action); - - girara_tree_node_t* node = girara_node_append_data(root, index_element); - PopplerIndexIter* child = poppler_index_iter_get_child(iter); - - if (child) { - build_index(pdf, node, child); - } - - poppler_index_iter_free(child); - - } while (poppler_index_iter_next(iter)); -} - -girara_tree_node_t* -pdf_document_index_generate(zathura_document_t* document) -{ - if (!document || !document->data) { - return NULL; - } - - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - PopplerIndexIter* iter = poppler_index_iter_new(pdf_document->document); - - if (!iter) { - // XXX: error message? - return NULL; - } - - girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); - girara_node_set_free_function(root, (girara_free_function_t)zathura_index_element_free); - build_index(pdf_document, root, iter); - - poppler_index_iter_free(iter); - return root; -} - -bool -pdf_document_save_as(zathura_document_t* document, const char* path) -{ - if (!document || !document->data || !path) { - return false; - } - - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - - char* file_path = g_strdup_printf("file://%s", path); - poppler_document_save(pdf_document->document, file_path, NULL); - g_free(file_path); - - return false; -} - -zathura_list_t* -pdf_document_attachments_get(zathura_document_t* document) -{ - return NULL; -} - -zathura_page_t* -pdf_page_get(zathura_document_t* document, unsigned int page) -{ - if (!document || !document->data) { - return NULL; - } - - pdf_document_t* pdf_document = (pdf_document_t*) document->data; - zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); - - if (!document_page) { - return NULL; - } - - document_page->document = document; - document_page->data = poppler_document_get_page(pdf_document->document, page); - - if (!document_page->data) { - free(document_page); - return NULL; - } - - poppler_page_get_size(document_page->data, &(document_page->width), &(document_page->height)); - - return document_page; -} - -bool -pdf_page_free(zathura_page_t* page) -{ - if (!page) { - return false; - } - - g_object_unref(page->data); - free(page); - - return true; -} - -zathura_list_t* -pdf_page_search_text(zathura_page_t* page, const char* text) -{ - return NULL; -} - -zathura_list_t* -pdf_page_links_get(zathura_page_t* page) -{ - return NULL; -} - -zathura_list_t* -pdf_page_form_fields_get(zathura_page_t* page) -{ - return NULL; -} - -zathura_image_buffer_t* -pdf_page_render(zathura_page_t* page) -{ - if (!page || !page->data || !page->document) { - return NULL; - } - - /* calculate sizes */ - unsigned int page_width = page->document->scale * page->width; - unsigned int page_height = page->document->scale * page->height; - - /* create pixbuf */ - GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, - page_width, page_height); - - if (pixbuf == NULL) { - return NULL; - } - - poppler_page_render_to_pixbuf(page->data, 0, 0, page_width, page_height, - page->document->scale, 0, pixbuf); - - /* create image buffer */ - zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); - - if (image_buffer == NULL) { - g_object_unref(pixbuf); - return NULL; - } - - /* copy buffer */ - guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); - int rowstride = gdk_pixbuf_get_rowstride(pixbuf); - int n_channels = gdk_pixbuf_get_n_channels(pixbuf); - - for (unsigned int y = 0; y < page_height; y++) { - for (unsigned int x = 0; x < page_width; x++) { - unsigned char *s = pixels + y * rowstride + x * n_channels; - guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; - p[0] = s[0]; - p[1] = s[1]; - p[2] = s[2]; - } - } - - g_object_unref(pixbuf); - - return image_buffer; -} diff --git a/ft/pdf-poppler/pdf.h b/ft/pdf-poppler/pdf.h deleted file mode 100644 index ce76613..0000000 --- a/ft/pdf-poppler/pdf.h +++ /dev/null @@ -1,28 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef PDF_H -#define PDF_H - -#include -#include - -#include "../../document.h" - -typedef struct pdf_document_s -{ - PopplerDocument *document; -} pdf_document_t; - -bool pdf_document_open(zathura_document_t* document); -bool pdf_document_free(zathura_document_t* document); -girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document); -bool pdf_document_save_as(zathura_document_t* document, const char* path); -zathura_list_t* pdf_document_attachments_get(zathura_document_t* document); -zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); -zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); -zathura_list_t* pdf_page_links_get(zathura_page_t* page); -zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -zathura_image_buffer_t* pdf_page_render(zathura_page_t* page); -bool pdf_page_free(zathura_page_t* page); - -#endif // PDF_H diff --git a/ft/ps/Makefile b/ft/ps/Makefile deleted file mode 100644 index df35a2a..0000000 --- a/ft/ps/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -# See LICENSE file for license and copyright information - -include config.mk - -PLUGIN = ps -SOURCE = ps.c -OBJECTS = ${SOURCE:.c=.o} -DOBJECTS = ${SOURCE:.c=.do} - -all: options ${PLUGIN} - -options: - @echo ${PLUGIN} build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "DFLAGS = ${DFLAGS}" - @echo "CC = ${CC}" - -%.o: %.c - @echo CC $< - @mkdir -p .depend - @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep - -%.do: %.c - @echo CC $< - @mkdir -p .depend - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep - -${OBJECTS}: config.mk -${DOBJECTS}: config.mk - -${PLUGIN}: ${OBJECTS} - @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS} - -${PLUGIN}-debug: ${DOBJECTS} - @echo LD $@ - @${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS} - -clean: - @rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend - -debug: options ${PLUGIN}-debug - -install: all - @echo installing ${PLUGIN} plugin - @mkdir -p ${DESTDIR}${PREFIX}/lib/zathura - @cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura - -uninstall: - @echo uninstalling ${PLUGIN} plugin - @rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so - @rm -rf ${DESTDIR}${PREFIX}/lib/zathura - --include $(wildcard .depend/*.dep) - -.PHONY: all options clean debug install uninstall diff --git a/ft/ps/config.mk b/ft/ps/config.mk deleted file mode 100644 index d44baaf..0000000 --- a/ft/ps/config.mk +++ /dev/null @@ -1,21 +0,0 @@ -# See LICENSE file for license and copyright information - -# paths -PREFIX ?= /usr - -# libs -GTK_INC = $(shell pkg-config --cflags gtk+-2.0) -GTK_LIB = $(shell pkg-config --libs gtk+-2.0) - -INCS = -I. -I/usr/include ${GTK_INC} -LIBS = -lc ${GTK_LIB} -lspectre - -# flags -CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) - -# debug -DFLAGS = -g - -# compiler -CC ?= gcc -LD ?= ld diff --git a/ft/ps/ps.c b/ft/ps/ps.c deleted file mode 100644 index d5f5a0e..0000000 --- a/ft/ps/ps.c +++ /dev/null @@ -1,180 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include - -#include "ps.h" -#include "../../zathura.h" - -void -plugin_register(zathura_document_plugin_t* plugin) -{ - plugin->file_extension = "ps"; - plugin->open_function = ps_document_open; -} - -bool -ps_document_open(zathura_document_t* document) -{ - if (!document) { - goto error_ret; - } - - document->functions.document_free = ps_document_free; - document->functions.page_get = ps_page_get; - document->functions.page_render = ps_page_render; - document->functions.page_free = ps_page_free; - - document->data = malloc(sizeof(ps_document_t)); - if (!document->data) { - goto error_ret; - } - - ps_document_t* ps_document = (ps_document_t*) document->data; - ps_document->document = spectre_document_new(); - - if (ps_document->document == NULL) { - goto error_free; - } - - spectre_document_load(ps_document->document, document->file_path); - - if (spectre_document_status(ps_document->document) != SPECTRE_STATUS_SUCCESS) { - goto error_free; - } - - document->number_of_pages = spectre_document_get_n_pages(ps_document->document); - - return true; - -error_free: - - if (ps_document->document != NULL) { - spectre_document_free(ps_document->document); - } - - free(document->data); - document->data = NULL; - -error_ret: - - return false; -} - -bool -ps_document_free(zathura_document_t* document) -{ - if (!document) { - return false; - } - - if (document->data != NULL) { - ps_document_t* ps_document = (ps_document_t*) document->data; - spectre_document_free(ps_document->document); - free(document->data); - document->data = NULL; - } - - return true; -} - -zathura_page_t* -ps_page_get(zathura_document_t* document, unsigned int page) -{ - if (!document || !document->data) { - return NULL; - } - - ps_document_t* ps_document = (ps_document_t*) document->data; - zathura_page_t* document_page = malloc(sizeof(zathura_page_t)); - - if (document_page == NULL) { - goto error_ret; - } - - SpectrePage* ps_page = spectre_document_get_page(ps_document->document, page); - - if (ps_page == NULL) { - goto error_free; - } - - int page_width; - int page_height; - spectre_page_get_size(ps_page, &(page_width), &(page_height)); - - document_page->width = page_width; - document_page->height = page_height; - document_page->document = document; - document_page->data = ps_page; - - return document_page; - -error_free: - - free(document_page); - -error_ret: - - return NULL; -} - -bool -ps_page_free(zathura_page_t* page) -{ - if (page == NULL) { - return false; - } - - if (page->data != NULL) { - SpectrePage* ps_page = (SpectrePage*) page->data; - spectre_page_free(ps_page); - } - - free(page); - - return true; -} - -zathura_image_buffer_t* -ps_page_render(zathura_page_t* page) -{ - if (!page || !page->data || !page->document) { - return NULL; - } - - /* calculate sizes */ - unsigned int page_width = page->document->scale * page->width; - unsigned int page_height = page->document->scale * page->height; - - /* create image buffer */ - zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height); - - if (image_buffer == NULL) { - return NULL; - } - - SpectrePage* ps_page = (SpectrePage*) page->data; - SpectreRenderContext* context = spectre_render_context_new(); - - spectre_render_context_set_scale(context, page->document->scale, page->document->scale); - spectre_render_context_set_rotation(context, 0); - - unsigned char* page_data; - int row_length; - spectre_page_render(ps_page, context, &page_data, &row_length); - - for (unsigned int y = 0; y < page_height; y++) { - for (unsigned int x = 0; x < page_width; x++) { - unsigned char *s = page_data + y * row_length + x * 4; - guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3; - p[0] = s[0]; - p[1] = s[1]; - p[2] = s[2]; - } - } - - spectre_render_context_free(context); - - ps_document_t* ps_document = (ps_document_t*) page->document->data; - - return image_buffer; -} diff --git a/ft/ps/ps.h b/ft/ps/ps.h deleted file mode 100644 index 4ef3560..0000000 --- a/ft/ps/ps.h +++ /dev/null @@ -1,22 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef PS_H -#define PS_H - -#include -#include - -#include "../../document.h" - -typedef struct ps_document_s -{ - SpectreDocument* document; -} ps_document_t; - -bool ps_document_open(zathura_document_t* document); -bool ps_document_free(zathura_document_t* document); -zathura_page_t* ps_page_get(zathura_document_t* document, unsigned int page); -zathura_image_buffer_t* ps_page_render(zathura_page_t* page); -bool ps_page_free(zathura_page_t* page); - -#endif // PS_H From 4763624dab38bbb50ce68a1dc700e336a156581a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 27 Apr 2011 19:57:49 +0200 Subject: [PATCH 137/197] Display current page number in statusbar --- render.c | 5 +++++ zathura.c | 17 +++++++++++++---- zathura.h | 22 +++++++++++++++------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/render.c b/render.c index ec7797a..81695b0 100644 --- a/render.c +++ b/render.c @@ -239,9 +239,14 @@ page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) /* render real page */ render_page(page->document->zathura->sync.render_thread, page); + + /* update statusbar */ } cairo_destroy(cairo); + page->document->current_page_number = page->number; + statusbar_page_number_update(page->document->zathura); + g_static_mutex_unlock(&(page->lock)); return TRUE; diff --git a/zathura.c b/zathura.c index 430c009..76c78fd 100644 --- a/zathura.c +++ b/zathura.c @@ -318,10 +318,7 @@ page_set(zathura_t* zathura, unsigned int page_id) /* update page number */ zathura->document->current_page_number = page_id; - - char* page_number = g_strdup_printf("[%d/%d]", page_id + 1, zathura->document->number_of_pages); - girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, page_number); - g_free(page_number); + statusbar_page_number_update(zathura); return true; @@ -330,6 +327,18 @@ error_out: return false; } +void +statusbar_page_number_update(zathura_t* zathura) +{ + if (zathura == NULL || zathura->ui.statusbar.page_number == NULL) { + return; + } + + char* page_number_text = g_strdup_printf("[%d/%d]", zathura->document->current_page_number + 1, zathura->document->number_of_pages); + girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, page_number_text); + g_free(page_number_text); +} + void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { diff --git a/zathura.h b/zathura.h index 262ee74..2005082 100644 --- a/zathura.h +++ b/zathura.h @@ -78,21 +78,21 @@ typedef struct zathura_s * * @param argc Number of arguments * @param argv Values of arguments - * @return Zathura zathura object or NULL if zathura could not been initialized + * @return zathura session object or NULL if zathura could not been initialized */ zathura_t* zathura_init(int argc, char* argv[]); /** - * Free zathura zathura + * Free zathura session * - * @param zathura The zathura zathura + * @param zathura The zathura session */ void zathura_free(zathura_t* zathura); /** * Opens a file * - * @param zathura The zathura zathura + * @param zathura The zathura session * @param path The path to the file * @param password The password of the file * @@ -103,7 +103,7 @@ bool document_open(zathura_t* zathura, const char* path, const char* password); /** * Closes the current opened document * - * @param zathura The zathura zathura + * @param zathura The zathura session * @return If no error occured true, otherwise false, is returned. */ bool document_close(zathura_t* zathura); @@ -111,7 +111,7 @@ bool document_close(zathura_t* zathura); /** * Opens the page with the given number * - * @param zathura The zathura zathura + * @param zathura The zathura session * @return If no error occured true, otherwise false, is returned. */ bool page_set(zathura_t* zathura, unsigned int page_id); @@ -119,9 +119,17 @@ bool page_set(zathura_t* zathura, unsigned int page_id); /** * Builds the box structure to show the rendered pages * - * @param zathura The zathura zathura + * @param zathura The zathura session * @param pages_per_row Number of shown pages per row */ void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row); +/** + * Updates the page number in the statusbar. Note that 1 will be added to the + * displayed number + * + * @param zathura The zathura session + */ +void statusbar_page_number_update(zathura_t* zathura); + #endif // ZATHURA_H From 40ae60ea42add6c446a69e11bdcb6029c42f6072 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 27 Apr 2011 20:32:57 +0200 Subject: [PATCH 138/197] Updated page_set function --- shortcuts.c | 9 +-------- zathura.c | 9 ++++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index 72acb44..1758bcc 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -94,14 +94,7 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) return true; } - unsigned int number_of_pages = zathura->document->number_of_pages; - - if (t > 0 && t <= number_of_pages) { - // TODO: Calculate offset - /*GtkAdjustment* adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->UI.session->gtk.view));*/ - /*unsigned int offset = zathura->document->pages[t - 1]->offset * zathura->document->scale;*/ - /*gtk_adjustment_set_value(adjustment, offset);*/ - } + page_set(zathura, t - 1); } return false; diff --git a/zathura.c b/zathura.c index 76c78fd..70037df 100644 --- a/zathura.c +++ b/zathura.c @@ -313,8 +313,15 @@ page_set(zathura_t* zathura, unsigned int page_id) goto error_out; } + page_offset_t* offset = page_calculate_offset(page); + if (offset == NULL) { + goto error_out; + } + GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); - cb_view_vadjustment_value_changed(view_vadjustment, zathura); + GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); + gtk_adjustment_set_value(view_hadjustment, offset->x); + gtk_adjustment_set_value(view_vadjustment, offset->y); /* update page number */ zathura->document->current_page_number = page_id; From 8de7969b2d487e1a9303b7c98b8d6f91b2572669 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 27 Apr 2011 20:41:02 +0200 Subject: [PATCH 139/197] Drop sc_change_buffer --- shortcuts.c | 8 -------- shortcuts.h | 10 ---------- 2 files changed, 18 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index 1758bcc..a47f69a 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -28,14 +28,6 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigne return false; } -bool -sc_change_buffer(girara_session_t* session, girara_argument_t* argument, unsigned int t) -{ - g_return_val_if_fail(session != NULL, false); - - return false; -} - bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) { diff --git a/shortcuts.h b/shortcuts.h index b920f87..8a0bade 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -25,16 +25,6 @@ bool sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned i */ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigned int t); -/** - * Modify the current buffer - * - * @param session The used girara session - * @param argument The used argument - * @param t Number of executions - * @return true if no error occured otherwise false - */ -bool sc_change_buffer(girara_session_t* session, girara_argument_t* argument, unsigned int t); - /** * Change the current mode * From 2504604e7338be69143c7e55e290b2aca5977d80 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 28 Apr 2011 17:27:44 +0200 Subject: [PATCH 140/197] Remove sc_change_buffer from config.h --- config.c | 1 - 1 file changed, 1 deletion(-) diff --git a/config.c b/config.c index 34532b0..30bf0f3 100644 --- a/config.c +++ b/config.c @@ -33,7 +33,6 @@ config_load_default(zathura_t* zathura) 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_BackSpace, NULL, sc_change_buffer, 0, DELETE_LAST, 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); From ebd6605adffa6fee118efc8cbb7dde3fbb29d37a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 29 Apr 2011 00:28:19 +0200 Subject: [PATCH 141/197] Began to implement the printing dialog --- commands.c | 12 +++++++++++ print.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ print.h | 26 +++++++++++++++++++++++ zathura.c | 11 ++++++++++ zathura.h | 6 ++++++ 5 files changed, 116 insertions(+) create mode 100644 print.c create mode 100644 print.h diff --git a/commands.c b/commands.c index cc4d7ae..a8450b4 100644 --- a/commands.c +++ b/commands.c @@ -2,6 +2,7 @@ #include "commands.h" #include "zathura.h" +#include "print.h" bool cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list) @@ -43,6 +44,17 @@ cmd_info(girara_session_t* session, girara_list_t* argument_list) bool cmd_print(girara_session_t* session, girara_list_t* argument_list) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + + if (zathura->document == NULL) { + girara_error("no document as been opened"); + return false; + } + + print((zathura_t*) session->global.data);; + return true; } diff --git a/print.c b/print.c new file mode 100644 index 0000000..3332ff1 --- /dev/null +++ b/print.c @@ -0,0 +1,61 @@ +#include "print.h" +#include "document.h" + +void +print(zathura_t* zathura) +{ + g_return_if_fail(zathura != NULL); + g_return_if_fail(zathura->document != NULL); + + GtkPrintOperation* print_operation = gtk_print_operation_new(); + + /* print operation settings */ + if (zathura->print.settings != NULL) { + gtk_print_operation_set_print_settings(print_operation, zathura->print.settings); + } + + if (zathura->print.page_setup != NULL) { + gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup); + } + + gtk_print_operation_set_show_progress(print_operation, TRUE); + gtk_print_operation_set_n_pages(print_operation, zathura->document->number_of_pages); + gtk_print_operation_set_current_page(print_operation, zathura->document->current_page_number); + + /* print operation signals */ + g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura); + + /* print */ + GtkPrintOperationResult result = gtk_print_operation_run(print_operation, + GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); + + if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { + /* save previous settings */ + zathura->print.settings = gtk_print_operation_get_print_settings(print_operation); + zathura->print.page_setup = gtk_print_operation_get_default_page_setup(print_operation); + } else if (result == GTK_PRINT_OPERATION_RESULT_ERROR) { + girara_error("Error occured while printing progress"); + } + + g_object_unref(print_operation); +} + +void +cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext* context, gint page_number, zathura_t* zathura) +{ + cairo_t* cairo = gtk_print_context_get_cairo_context(context); + + /*zathura_page_t* page = zathura->document->pages[page_number];*/ + /*g_static_mutex_lock(&(page->lock));*/ + /*zathura_image_buffer_t* image_buffer = zathura_page_render(page);*/ + /*g_static_mutex_unlock(&(page->lock));*/ + + /*for (unsigned int y = 0; y < image_buffer->height; y++) {*/ + /*unsigned char* src = image_buffer->data + y * image_buffer->rowstride;*/ + /*for (unsigned int x = 0; x < image_buffer->width; x++) {*/ + /*cairo_set_source_rgb(cairo, src[0], src[1], src[2]);*/ + /*cairo_rectangle(cairo, x, y, 1, 1);*/ + /*cairo_fill(cairo);*/ + /*}*/ + /*}*/ +} diff --git a/print.h b/print.h new file mode 100644 index 0000000..a8fcb5a --- /dev/null +++ b/print.h @@ -0,0 +1,26 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef PRINT_H +#define PRINT_H + +#include "zathura.h" + +/** + * Opens a print dialog to print the current file + * + * @param zathura + */ +void print(zathura_t* zathura); + +/** + * Callback that is executed for every page that should be printed + * + * @param print_operation Print operation object + * @param context Print context + * @param page_number Current page number + * @param zathura Zathura object + */ +void cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext* + context, gint page_number, zathura_t* zathura); + +#endif // PRINT_H diff --git a/zathura.c b/zathura.c index 70037df..892654e 100644 --- a/zathura.c +++ b/zathura.c @@ -31,6 +31,9 @@ zathura_init(int argc, char* argv[]) return NULL; } + /* general */ + zathura->document = NULL; + /* plugins */ zathura->plugins.plugins = girara_list_new(); zathura->plugins.path = girara_list_new(); @@ -101,6 +104,10 @@ zathura_init(int argc, char* argv[]) zathura->ui.page_view = NULL; zathura->ui.index = NULL; + /* Print settings */ + zathura->print.settings = NULL; + zathura->print.page_setup = NULL; + /* load plugins */ zathura_document_plugins_load(zathura); @@ -206,6 +213,10 @@ zathura_free(zathura_t* zathura) document_close(zathura); + /* free print settings */ + g_object_unref(zathura->print.settings); + g_object_unref(zathura->print.page_setup); + /* free registered plugins */ zathura_document_plugins_free(zathura); girara_list_free(zathura->plugins.plugins); diff --git a/zathura.h b/zathura.h index 2005082..1421751 100644 --- a/zathura.h +++ b/zathura.h @@ -65,6 +65,12 @@ typedef struct zathura_s gchar* data_dir; } config; + struct + { + GtkPrintSettings* settings; + GtkPageSetup* page_setup; + } print; + struct { unsigned int page_padding; From 4806163e244e38a708c38efc8cf682462061af52 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 30 Apr 2011 13:07:14 +0200 Subject: [PATCH 142/197] Comment unused variable --- print.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print.c b/print.c index 3332ff1..3545997 100644 --- a/print.c +++ b/print.c @@ -43,7 +43,7 @@ print(zathura_t* zathura) void cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext* context, gint page_number, zathura_t* zathura) { - cairo_t* cairo = gtk_print_context_get_cairo_context(context); + /*cairo_t* cairo = gtk_print_context_get_cairo_context(context);*/ /*zathura_page_t* page = zathura->document->pages[page_number];*/ /*g_static_mutex_lock(&(page->lock));*/ From 00589a72953dff4b907144f53eae588f27c942f0 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 30 Apr 2011 13:27:27 +0200 Subject: [PATCH 143/197] Implemented recoloring --- config.c | 5 +++++ render.c | 33 +++++++++++++++++++++++++++++++++ shortcuts.c | 5 +++++ zathura.c | 18 +++++++++++++++++- zathura.h | 21 ++++++++++++++------- 5 files changed, 74 insertions(+), 8 deletions(-) diff --git a/config.c b/config.c index 30bf0f3..cea5207 100644 --- a/config.c +++ b/config.c @@ -14,6 +14,7 @@ config_load_default(zathura_t* zathura) } int int_value = 0; + char* string_value = NULL; girara_session_t* gsession = zathura->ui.session; /* general settings */ @@ -27,6 +28,10 @@ config_load_default(zathura_t* zathura) int_value = 2; girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL); + string_value = "#FFFFFF"; + girara_setting_add(gsession, "recolor-dark-color", string_value, STRING, false, "Recoloring (dark color)", NULL); + string_value = "#000000"; + girara_setting_add(gsession, "recolor-light-color", string_value, STRING, false, "Recoloring (light color)", NULL); /* define default shortcuts */ girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); diff --git a/render.c b/render.c index 81695b0..16c129a 100644 --- a/render.c +++ b/render.c @@ -168,6 +168,39 @@ render(zathura_t* zathura, zathura_page_t* page) } } + /* recolor */ + if (zathura->global.recolor) { + /* recolor code based on qimageblitz library flatten() function + (http://sourceforge.net/projects/qimageblitz/) */ + + int r1 = zathura->ui.colors.recolor_dark_color.red / 257; + int g1 = zathura->ui.colors.recolor_dark_color.green / 257; + int b1 = zathura->ui.colors.recolor_dark_color.blue / 257; + int r2 = zathura->ui.colors.recolor_light_color.red / 257; + int g2 = zathura->ui.colors.recolor_light_color.green / 257; + int b2 = zathura->ui.colors.recolor_light_color.blue / 257; + + int min = 0x00; + int max = 0xFF; + int mean = 0x00; + + float sr = ((float) r2 - r1) / (max - min); + float sg = ((float) g2 - g1) / (max - min); + float sb = ((float) b2 - b1) / (max - min); + + for (unsigned int y = 0; y < page_height; y++) { + unsigned char* data = image + y * rowstride; + + for (unsigned int x = 0; x < page_width; x++) { + mean = (data[0] + data[1] + data[2]) / 3; + data[2] = sr * (mean - min) + r1 + 0.5; + data[1] = sg * (mean - min) + g1 + 0.5; + data[0] = sb * (mean - min) + b1 + 0.5; + data += 4; + } + } + } + /* draw to gtk widget */ page->surface = surface; gtk_widget_set_size_request(page->drawing_area, page_width, page_height); diff --git a/shortcuts.c b/shortcuts.c index a47f69a..d02c5ae 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -119,6 +119,11 @@ bool sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + + zathura->global.recolor = !zathura->global.recolor; + render_all(zathura); return false; } diff --git a/zathura.c b/zathura.c index 892654e..99b389b 100644 --- a/zathura.c +++ b/zathura.c @@ -104,10 +104,13 @@ zathura_init(int argc, char* argv[]) zathura->ui.page_view = NULL; zathura->ui.index = NULL; - /* Print settings */ + /* print settings */ zathura->print.settings = NULL; zathura->print.page_setup = NULL; + /* global settings */ + zathura->global.recolor = false; + /* load plugins */ zathura_document_plugins_load(zathura); @@ -173,6 +176,19 @@ zathura_init(int argc, char* argv[]) gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding); gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_view), zathura->global.page_padding); + /* parse colors */ + char* string_value = girara_setting_get(zathura->ui.session, "recolor-dark-color"); + if (string_value != NULL) { + gdk_color_parse(string_value, &(zathura->ui.colors.recolor_dark_color)); + free(string_value); + } + + string_value = girara_setting_get(zathura->ui.session, "recolor-light-color"); + if (string_value != NULL) { + gdk_color_parse(string_value, &(zathura->ui.colors.recolor_light_color)); + free(string_value); + } + /* open document if passed */ if (argc > 1) { zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t)); diff --git a/zathura.h b/zathura.h index 1421751..0ded288 100644 --- a/zathura.h +++ b/zathura.h @@ -44,6 +44,12 @@ typedef struct zathura_s girara_statusbar_item_t* page_number; /**> page number statusbar entry */ } statusbar; + struct + { + GdkColor recolor_dark_color; /**> Dark color for recoloring */ + GdkColor recolor_light_color; /**> Light color for recoloring */ + } colors; + GtkWidget *page_view; /**> Widget that contains all rendered pages */ GtkWidget *index; /**> Widget to show the index of the document */ } ui; @@ -55,25 +61,26 @@ typedef struct zathura_s struct { - girara_list_t* plugins; - girara_list_t* path; + girara_list_t* plugins; /**> List of plugins */ + girara_list_t* path; /**> List of plugin paths */ } plugins; struct { - gchar* config_dir; - gchar* data_dir; + gchar* config_dir; /**> Path to the configuration directory */ + gchar* data_dir; /**> Path to the data directory */ } config; struct { - GtkPrintSettings* settings; - GtkPageSetup* page_setup; + GtkPrintSettings* settings; /**> Print settings */ + GtkPageSetup* page_setup; /**> Saved page setup */ } print; struct { - unsigned int page_padding; + unsigned int page_padding; /**> Padding between the pages */ + bool recolor; /**> Recoloring mode switch */ } global; zathura_document_t* document; /**> The current document */ From f0d2e71ef9de7c23e12956fae070c49891769e0a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 2 May 2011 18:49:54 +0200 Subject: [PATCH 144/197] Allow async printing and calculate scale level --- print.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/print.c b/print.c index 3545997..74a0da4 100644 --- a/print.c +++ b/print.c @@ -18,7 +18,7 @@ print(zathura_t* zathura) gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup); } - gtk_print_operation_set_show_progress(print_operation, TRUE); + gtk_print_operation_set_allow_async(print_operation, TRUE); gtk_print_operation_set_n_pages(print_operation, zathura->document->number_of_pages); gtk_print_operation_set_current_page(print_operation, zathura->document->current_page_number); @@ -40,22 +40,41 @@ print(zathura_t* zathura) g_object_unref(print_operation); } +void +cb_print_begin(GtkPrintOperation* print_operation, GtkPrintContext* context, zathura_t* zathura) +{ + +} + void cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext* context, gint page_number, zathura_t* zathura) { - /*cairo_t* cairo = gtk_print_context_get_cairo_context(context);*/ + cairo_t* cairo = gtk_print_context_get_cairo_context(context); - /*zathura_page_t* page = zathura->document->pages[page_number];*/ - /*g_static_mutex_lock(&(page->lock));*/ - /*zathura_image_buffer_t* image_buffer = zathura_page_render(page);*/ - /*g_static_mutex_unlock(&(page->lock));*/ + girara_info("Printing page %d", page_number); - /*for (unsigned int y = 0; y < image_buffer->height; y++) {*/ - /*unsigned char* src = image_buffer->data + y * image_buffer->rowstride;*/ - /*for (unsigned int x = 0; x < image_buffer->width; x++) {*/ - /*cairo_set_source_rgb(cairo, src[0], src[1], src[2]);*/ - /*cairo_rectangle(cairo, x, y, 1, 1);*/ - /*cairo_fill(cairo);*/ - /*}*/ - /*}*/ + zathura_page_t* page = zathura->document->pages[page_number]; + + double requested_with = gtk_print_context_get_width(context); + double tmp_scale = zathura->document->scale; + zathura->document->scale = requested_with / page->width; + + g_static_mutex_lock(&(page->lock)); + zathura_image_buffer_t* image_buffer = zathura_page_render(page); + g_static_mutex_unlock(&(page->lock)); + + for (unsigned int y = 0; y < image_buffer->height; y++) { + unsigned char* src = image_buffer->data + y * image_buffer->rowstride; + for (unsigned int x = 0; x < image_buffer->width; x++) { + if (src[0] != 255 && src[1] != 255 && src[2] != 255) { + cairo_set_source_rgb(cairo, src[0], src[1], src[2]); + cairo_rectangle(cairo, x, y, 1, 1); + cairo_fill(cairo); + } + + src += 3; + } + } + + zathura->document->scale = tmp_scale; } From 094acadcb3834be777a6e7908e6ce7d0e14c6e17 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 7 May 2011 00:39:34 +0200 Subject: [PATCH 145/197] Add shortcut mappings --- config.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/config.c b/config.c index cea5207..70db7c3 100644 --- a/config.c +++ b/config.c @@ -103,6 +103,27 @@ config_load_default(zathura_t* zathura) girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, "Show file information"); girara_inputbar_command_add(gsession, "print", NULL, cmd_print, cc_print, "Print document"); girara_inputbar_command_add(gsession, "save", NULL, cmd_save, NULL, "Save document"); + + /* add shortcut mappings */ + girara_shortcut_mapping_add(gsession, "abort", sc_abort); + girara_shortcut_mapping_add(gsession, "adjust_window", sc_adjust_window); + girara_shortcut_mapping_add(gsession, "change_mode", sc_change_mode); + girara_shortcut_mapping_add(gsession, "focus_inputbar", sc_focus_inputbar); + 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", sc_navigate); + girara_shortcut_mapping_add(gsession, "quit", sc_quit); + girara_shortcut_mapping_add(gsession, "recolor", sc_recolor); + girara_shortcut_mapping_add(gsession, "reload", sc_reload); + girara_shortcut_mapping_add(gsession, "rotate", sc_rotate); + girara_shortcut_mapping_add(gsession, "scroll", sc_scroll); + girara_shortcut_mapping_add(gsession, "search", sc_search); + girara_shortcut_mapping_add(gsession, "toggle_fullscreen", sc_toggle_fullscreen); + girara_shortcut_mapping_add(gsession, "toggle_index", sc_toggle_index); + girara_shortcut_mapping_add(gsession, "toggle_inputbar", sc_toggle_inputbar); + girara_shortcut_mapping_add(gsession, "toggle_statusbar", sc_toggle_statusbar); + girara_shortcut_mapping_add(gsession, "zoom", sc_zoom); } void From 17b497268300c2c66b9c9830acca1820411b3dfa Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 7 May 2011 22:00:52 +0200 Subject: [PATCH 146/197] Update modes --- config.c | 14 ++++++++++++-- shortcuts.c | 2 +- zathura.h | 15 ++++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/config.c b/config.c index 70db7c3..1b3d650 100644 --- a/config.c +++ b/config.c @@ -17,8 +17,18 @@ config_load_default(zathura_t* zathura) char* string_value = NULL; girara_session_t* gsession = zathura->ui.session; - /* general settings */ - girara_mode_set(gsession, NORMAL); + /* mode settings */ + zathura->modes.normal = gsession->modes.normal; + zathura->modes.fullscreen = girara_mode_add(gsession, "fullscreen"); + zathura->modes.index = girara_mode_add(gsession, "index"); + zathura->modes.insert = girara_mode_add(gsession, "insert"); + +#define NORMAL zathura->modes.normal +#define INSERT zathura->modes.insert +#define INDEX zathura->modes.index +#define FULLSCREEN zathura->modes.fullscreen + + girara_mode_set(gsession, zathura->modes.normal); /* zathura settings */ int_value = 10; diff --git a/shortcuts.c b/shortcuts.c index d02c5ae..51d2f45 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -15,7 +15,7 @@ sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) { g_return_val_if_fail(session != NULL, false); - girara_mode_set(session, NORMAL); + girara_mode_set(session, session->modes.normal); return false; } diff --git a/zathura.h b/zathura.h index 0ded288..af14996 100644 --- a/zathura.h +++ b/zathura.h @@ -14,13 +14,6 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, GOTO_OFFSET, HALF_UP, HALF_DOWN, FULL_UP, FULL_DOWN, NEXT_CHAR, PREVIOUS_CHAR, DELETE_TO_LINE_START, APPEND_FILEPATH }; -/* define modes */ -#define ALL (1 << 0) -#define FULLSCREEN (1 << 1) -#define INDEX (1 << 2) -#define NORMAL (1 << 3) -#define INSERT (1 << 4) - /* forward declaration for types from document.h */ struct zathura_document_s; struct zathura_page_s; @@ -83,6 +76,14 @@ typedef struct zathura_s bool recolor; /**> Recoloring mode switch */ } global; + struct + { + girara_mode_t normal; /**> Normal mode */ + girara_mode_t fullscreen; /**> Fullscreen mode */ + girara_mode_t index; /**> Index mode */ + girara_mode_t insert; /**> Insert mode */ + } modes; + zathura_document_t* document; /**> The current document */ } zathura_t; From 7a0f870ff16b7b009c34b373c84215d5dd977464 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 9 May 2011 10:53:09 +0200 Subject: [PATCH 147/197] Fixed a possible memory leak --- zathura.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zathura.c b/zathura.c index 99b389b..71dc359 100644 --- a/zathura.c +++ b/zathura.c @@ -213,6 +213,8 @@ error_free: error_out: + free(zathura); + return NULL; } From a3d0a84b60577463c92e3113744337bb2cd17423 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Thu, 19 May 2011 12:46:12 +0200 Subject: [PATCH 148/197] document pkg-config and GNU make Conflicts: README --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index ead997d..ac777c5 100644 --- a/README +++ b/README @@ -8,6 +8,9 @@ Requirements gtk2 (>= 2.18.6) girara +Please note that you need to have a working pkg-config installation +and that the Makefile is only compatible with GNU make. + Installation ------------ To build and install zathura: From bd37f6333e70b436253d7d29a36dc8e548d4df34 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 25 May 2011 00:24:43 +0200 Subject: [PATCH 149/197] Began to implement cmd_open completion --- commands.c | 6 +++++ commands.h | 9 +++++++ completion.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ completion.h | 10 +++++++ config.c | 1 + 5 files changed, 102 insertions(+) diff --git a/commands.c b/commands.c index a8450b4..bb14888 100644 --- a/commands.c +++ b/commands.c @@ -41,6 +41,12 @@ cmd_info(girara_session_t* session, girara_list_t* argument_list) return true; } +bool +cmd_open(girara_session_t* session, girara_list_t* argument_list) +{ + return true; +} + bool cmd_print(girara_session_t* session, girara_list_t* argument_list) { diff --git a/commands.h b/commands.h index fa6d8eb..d174455 100644 --- a/commands.h +++ b/commands.h @@ -51,6 +51,15 @@ bool cmd_close(girara_session_t* session, girara_list_t* argument_list); */ bool cmd_info(girara_session_t* session, girara_list_t* argument_list); +/** + * Opens a document file + * + * @param session The used girara session + * @param argument_list List of passed arguments + * @return true if no error occured + */ +bool cmd_open(girara_session_t* session, girara_list_t* argument_list); + /** * Print the current file * diff --git a/completion.c b/completion.c index b51927e..4936767 100644 --- a/completion.c +++ b/completion.c @@ -63,3 +63,79 @@ cc_print(girara_session_t* session, char* input) return completion; } + +girara_completion_t* +cc_open(girara_session_t* session, char* input) +{ + girara_completion_t* completion = girara_completion_init(); + girara_completion_group_t* group = girara_completion_group_create(session, NULL); + + if (!session || !input || !completion || !group) { + goto error_free; + } + + gchar* path = girara_fix_path(input); + if (path == NULL || strlen(path) == 0) { + goto error_free; + } + + /* If the path does not begin with a slash we update the path with the current + * working directory */ + if (path[0] != '/') { + size_t path_max; +#ifdef PATH_MAX + path_max = PATH_MAX; +#else + path_max = pathconf(path,_PC_PATH_MAX); + if (path_max <= 0) + path_max = 4096; +#endif + + char cwd[path_max]; + getcwd(cwd, path_max); + + char* tmp_path = g_strdup_printf("%s/%s", cwd, path); + if (tmp_path == NULL) { + goto error_free; + } + + g_free(path); + path = tmp_path; + } + + /* read directory */ + if (g_file_test(path, G_FILE_TEST_IS_DIR) == TRUE) { + GDir* dir = g_dir_open(path, 0, NULL); + if (dir == NULL) { + goto error_free; + } + + /* read files */ + char* name = NULL; + while ((name = (char*) g_dir_read_name(dir)) != NULL) { + char* e_name = g_filename_display_name(name); + g_free(e_name); + } + + g_dir_close(dir); + } + + g_free(path); + + girara_completion_add_group(completion, group); + + return completion; + +error_free: + + if (completion) { + girara_completion_free(completion); + } + if (group) { + girara_completion_group_free(group); + } + + g_free(path); + + return NULL; +} diff --git a/completion.h b/completion.h index 3baba94..81b7522 100644 --- a/completion.h +++ b/completion.h @@ -14,4 +14,14 @@ */ girara_completion_t* cc_print(girara_session_t* session, char* input); +/** + * Completion for the open command - Creates a list of accesible directories or + * files + * + * @param session The used girara session + * @param input The current input + * @return The completion object or NULL if an error occured + */ +girara_completion_t* cc_open(girara_session_t* session, char* input); + #endif // COMPLETION_H diff --git a/config.c b/config.c index 1b3d650..63607b9 100644 --- a/config.c +++ b/config.c @@ -111,6 +111,7 @@ config_load_default(zathura_t* zathura) girara_inputbar_command_add(gsession, "blist", NULL, cmd_bookmark_open, NULL, "List all bookmarks"); girara_inputbar_command_add(gsession, "close", NULL, cmd_close, NULL, "Close current file"); girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, "Show file information"); + girara_inputbar_command_add(gsession, "open", "o", cmd_open, cc_open, "Open document"); girara_inputbar_command_add(gsession, "print", NULL, cmd_print, cc_print, "Print document"); girara_inputbar_command_add(gsession, "save", NULL, cmd_save, NULL, "Save document"); From caa058e4d243bdd7814248d7732a5b2c0bf16333 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 25 May 2011 00:54:16 +0200 Subject: [PATCH 150/197] cc_open: List only supported file types --- completion.c | 27 +++++++++++++++++++++++++-- utils.c | 25 +++++++++++++++++++++++++ utils.h | 10 ++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/completion.c b/completion.c index 4936767..944d79c 100644 --- a/completion.c +++ b/completion.c @@ -67,10 +67,14 @@ cc_print(girara_session_t* session, char* input) girara_completion_t* cc_open(girara_session_t* session, char* input) { + g_return_val_if_fail(session != NULL, NULL); + g_return_val_if_fail(session->global.data != NULL, NULL); + zathura_t* zathura = session->global.data; + girara_completion_t* completion = girara_completion_init(); girara_completion_group_t* group = girara_completion_group_create(session, NULL); - if (!session || !input || !completion || !group) { + if (!input || !completion || !group) { goto error_free; } @@ -113,11 +117,30 @@ cc_open(girara_session_t* session, char* input) /* read files */ char* name = NULL; while ((name = (char*) g_dir_read_name(dir)) != NULL) { - char* e_name = g_filename_display_name(name); + char* e_name = g_filename_display_name(name); + if (e_name == NULL) { + goto error_free; + } + + char* full_path = g_strdup_printf("%s/%s", path, e_name); + if (full_path == NULL) { + goto error_free; + } + + if (file_valid_extension(zathura, full_path) == true) { + girara_completion_group_add_element(group, full_path, NULL); + } + + g_free(full_path); g_free(e_name); } g_dir_close(dir); + /* given path is a file */ + } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) { + if (file_valid_extension(zathura, path) == true) { + girara_completion_group_add_element(group, path, NULL); + } } g_free(path); diff --git a/utils.c b/utils.c index 63ba736..dd37079 100644 --- a/utils.c +++ b/utils.c @@ -48,6 +48,31 @@ file_get_extension(const char* path) return path + i + 1; } +bool +file_valid_extension(zathura_t* zathura, const char* path) +{ + if (path == NULL) { + return false; + } + + const char* file_extension = file_get_extension(path); + + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); + if (iter == NULL) { + return false; + } + + do { + zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); + if (!strcmp(file_extension, plugin->file_extension)) { + return true; + } + } while (girara_list_iterator_next(iter)); + girara_list_iterator_free(iter); + + return false; +} + bool execute_command(char* const argv[], char** output) { diff --git a/utils.h b/utils.h index 8c10724..62db090 100644 --- a/utils.h +++ b/utils.h @@ -31,6 +31,16 @@ bool file_exists(const char* path); */ const char* file_get_extension(const char* path); +/** + * This function checks if the file has a valid extension. A extension is + * evaluated as valid if it matches a supported filetype. + * + * @param zathura Zathura object + * @param path The path to the file + * @return true if the extension is valid, otherwise false + */ +bool file_valid_extension(zathura_t* zathura, const char* path); + /** * Executes a system command and saves its output into output * From 196c6d2fd6bd537c5e9566533d1ae51375caabea Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 25 May 2011 10:26:37 +0200 Subject: [PATCH 151/197] Update cc_open --- completion.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/completion.c b/completion.c index 944d79c..7d7bb25 100644 --- a/completion.c +++ b/completion.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "completion.h" #include "utils.h" @@ -74,18 +75,18 @@ cc_open(girara_session_t* session, char* input) girara_completion_t* completion = girara_completion_init(); girara_completion_group_t* group = girara_completion_group_create(session, NULL); - if (!input || !completion || !group) { + if (completion == NULL || group == NULL) { goto error_free; } gchar* path = girara_fix_path(input); - if (path == NULL || strlen(path) == 0) { + if (path == NULL) { goto error_free; } /* If the path does not begin with a slash we update the path with the current * working directory */ - if (path[0] != '/') { + if (strlen(path) == 0 || path[0] != '/') { size_t path_max; #ifdef PATH_MAX path_max = PATH_MAX; @@ -107,9 +108,25 @@ cc_open(girara_session_t* session, char* input) path = tmp_path; } + /* Append a slash if the given argument is a directory */ + if ((g_file_test(path, G_FILE_TEST_IS_DIR) == TRUE) && + (path[strlen(path) - 1] != '/')) { + char* tmp_path = g_strdup_printf("%s/", path); + if (tmp_path == NULL) { + goto error_free; + } + + g_free(path); + path = tmp_path; + } + + gchar* current_path = (path[strlen(path)-1] == '/') ? path : dirname(path); + gchar* current_file = (path[strlen(path)-1] == '/') ? "" : basename(path); + int current_file_length = strlen(current_file); + /* read directory */ - if (g_file_test(path, G_FILE_TEST_IS_DIR) == TRUE) { - GDir* dir = g_dir_open(path, 0, NULL); + if (g_file_test(current_path, G_FILE_TEST_IS_DIR) == TRUE) { + GDir* dir = g_dir_open(current_path, 0, NULL); if (dir == NULL) { goto error_free; } @@ -117,17 +134,25 @@ cc_open(girara_session_t* session, char* input) /* read files */ char* name = NULL; while ((name = (char*) g_dir_read_name(dir)) != NULL) { - char* e_name = g_filename_display_name(name); + char* e_name = g_filename_display_name(name); + int e_length = strlen(e_name); + if (e_name == NULL) { goto error_free; } - char* full_path = g_strdup_printf("%s/%s", path, e_name); + char* full_path = g_strdup_printf("%s%s", current_path, e_name); if (full_path == NULL) { + g_free(e_name); goto error_free; } - if (file_valid_extension(zathura, full_path) == true) { + 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); + g_free(tmp_path); + girara_completion_group_add_element(group, full_path, NULL); + } else if (file_valid_extension(zathura, full_path) == true) { girara_completion_group_add_element(group, full_path, NULL); } @@ -136,11 +161,6 @@ cc_open(girara_session_t* session, char* input) } g_dir_close(dir); - /* given path is a file */ - } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) { - if (file_valid_extension(zathura, path) == true) { - girara_completion_group_add_element(group, path, NULL); - } } g_free(path); From 032af18f368b3c3fedb4482f02f10d5ac60de3d8 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 26 May 2011 11:58:27 +0200 Subject: [PATCH 152/197] Remove obsolete print completion --- completion.c | 57 ---------------------------------------------------- completion.h | 9 --------- 2 files changed, 66 deletions(-) diff --git a/completion.c b/completion.c index 7d7bb25..a069e55 100644 --- a/completion.c +++ b/completion.c @@ -8,63 +8,6 @@ #include "completion.h" #include "utils.h" -girara_completion_t* -cc_print(girara_session_t* session, char* input) -{ - girara_completion_t* completion = girara_completion_init(); - girara_completion_group_t* group = girara_completion_group_create(session, NULL); - - if (!session || !input || !completion || !group) - return NULL; - - girara_completion_add_group(completion, group); - - char* const list_printers[] = { - "lpstat", "-v", NULL - }; - - char* output; - if (!execute_command(list_printers, &output)) { - girara_completion_free(completion); - return false; - } - - /* parse single lines */ - unsigned int prefix_length = strlen("device for "); - char* p = strtok(output, "\n"); - char* q; - - while (p) { - if (!(p = strstr(p, "device for ")) || !(q = strchr(p, ':'))) { - p = strtok(NULL, "\n"); - continue; - } - - unsigned int printer_length = q - p - prefix_length; - char* printer_name = malloc(sizeof(char) * printer_length); - - if (!printer_name) { - p = strtok(NULL, "\n"); - continue; - } - - strncpy(printer_name, p + prefix_length, printer_length - 1); - printer_name[printer_length - 1] = '\0'; - - /* add printer */ - girara_completion_group_add_element(group, printer_name, NULL); - - free(printer_name); - - /* next line */ - p = strtok(NULL, "\n"); - } - - free(output); - - return completion; -} - girara_completion_t* cc_open(girara_session_t* session, char* input) { diff --git a/completion.h b/completion.h index 81b7522..7041d8a 100644 --- a/completion.h +++ b/completion.h @@ -5,15 +5,6 @@ #include -/** - * Completion for the print command. Creates a list of available printers - * - * @param session The used girara session - * @param input The current input - * @return The completion object or NULL if an error occured - */ -girara_completion_t* cc_print(girara_session_t* session, char* input); - /** * Completion for the open command - Creates a list of accesible directories or * files From 5847b5e2501d3b4f5d7676bdd0d7737cf5001546 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 26 May 2011 12:00:11 +0200 Subject: [PATCH 153/197] Fix: Remove obsolete print completion --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.c b/config.c index 63607b9..3c95c83 100644 --- a/config.c +++ b/config.c @@ -112,7 +112,7 @@ config_load_default(zathura_t* zathura) girara_inputbar_command_add(gsession, "close", NULL, cmd_close, NULL, "Close current file"); girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, "Show file information"); girara_inputbar_command_add(gsession, "open", "o", cmd_open, cc_open, "Open document"); - girara_inputbar_command_add(gsession, "print", NULL, cmd_print, cc_print, "Print document"); + girara_inputbar_command_add(gsession, "print", NULL, cmd_print, NULL, "Print document"); girara_inputbar_command_add(gsession, "save", NULL, cmd_save, NULL, "Save document"); /* add shortcut mappings */ From b4f834d462e8a469751abe4640ead5c96dccb91d Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 26 May 2011 12:05:10 +0200 Subject: [PATCH 154/197] Fix segmentation fault in extension checking --- utils.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils.c b/utils.c index dd37079..43511a8 100644 --- a/utils.c +++ b/utils.c @@ -57,6 +57,10 @@ file_valid_extension(zathura_t* zathura, const char* path) const char* file_extension = file_get_extension(path); + if (file_extension == NULL) { + return false; + } + girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins); if (iter == NULL) { return false; From ec836f333459555c20184188b5eebe48caf28c31 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 26 May 2011 14:58:10 +0200 Subject: [PATCH 155/197] Update cc_open --- completion.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/completion.c b/completion.c index a069e55..f9c0ef6 100644 --- a/completion.c +++ b/completion.c @@ -18,11 +18,14 @@ cc_open(girara_session_t* session, char* input) girara_completion_t* completion = girara_completion_init(); girara_completion_group_t* group = girara_completion_group_create(session, NULL); + gchar* path = NULL; + gchar* current_path = NULL; + if (completion == NULL || group == NULL) { goto error_free; } - gchar* path = girara_fix_path(input); + path = girara_fix_path(input); if (path == NULL) { goto error_free; } @@ -52,8 +55,8 @@ cc_open(girara_session_t* session, char* input) } /* Append a slash if the given argument is a directory */ - if ((g_file_test(path, G_FILE_TEST_IS_DIR) == TRUE) && - (path[strlen(path) - 1] != '/')) { + 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; @@ -61,10 +64,16 @@ cc_open(girara_session_t* session, char* input) g_free(path); path = tmp_path; + is_dir = true; } - gchar* current_path = (path[strlen(path)-1] == '/') ? path : dirname(path); - gchar* current_file = (path[strlen(path)-1] == '/') ? "" : basename(path); + /* get current path */ + char* tmp = g_strdup(path); + current_path = is_dir ? g_strdup(tmp) : g_strdup(dirname(tmp)); + g_free(tmp); + + /* get current file */ + gchar* current_file = is_dir ? "" : basename(path); int current_file_length = strlen(current_file); /* read directory */ @@ -84,7 +93,13 @@ cc_open(girara_session_t* session, char* input) goto error_free; } - char* full_path = g_strdup_printf("%s%s", current_path, e_name); + if ((current_file_length > e_length) || strncmp(current_file, e_name, + current_file_length)) { + g_free(e_name); + continue; + } + + char* full_path = g_strdup_printf("%s%s%s", current_path, is_dir ? "" : "/", e_name); if (full_path == NULL) { g_free(e_name); goto error_free; @@ -121,6 +136,7 @@ error_free: girara_completion_group_free(group); } + g_free(current_path); g_free(path); return NULL; From 731628990f33736a4ee53ebc52ae4db0f397ee29 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 27 May 2011 12:38:41 +0200 Subject: [PATCH 156/197] Cleaned man page --- zathura.1 | 236 ++++-------------------------------------------------- 1 file changed, 14 insertions(+), 222 deletions(-) diff --git a/zathura.1 b/zathura.1 index 1deadd6..a38bb6a 100644 --- a/zathura.1 +++ b/zathura.1 @@ -1,235 +1,27 @@ .TH ZATHURA 1 zathura\-VERSION + .SH NAME -zathura \- a PDF viewer +zathura \- a document viewer + .SH SYNOPSIS .B zathura -.RB [-e\ xid] -.RB [-c\ path] -.RB [-d\ path] +.RB [options] .RB [file] .RB [password] -.SH DESCRIPTION -zathura is a highly customizable and functional PDF viewer based on the poppler -rendering library and the gtk+ toolkit. zathura provides a minimalistic and -space saving interface, with a focus on keyboard interaction. -If instead of a filename - is specified on the command line, zathura tries to -render a PDF file piped to zathura via stdin. +.SH DESCRIPTION +zathura is a highly customizable and functional document viewer. + .SH OPTIONS .TP -.B -e xid +.B "-e xid" Reparents to window specified by xid. -.B -c path -Path to the config directory (defaults to .config/zathura) -.B -d path -Path to the data directory (defaults to .local/share/zathura) -.SH DEFAULT SETTINGS -.SS Shortcuts .TP -.B J -Go to next page +.B "-c path" +Path to the config directory. .TP -.B K -Go to previous page +.B "-d path" +Path to the data directory. .TP -.B h -Scroll to the left -.TP -.B k -Scroll upwards -.TP -.B j -Scroll downwards -.TP -.B ^f -Scroll page down -.TP -.B ^b -Scroll page up -.TP -.B ^d -Scroll half a page down -.TP -.B ^u -Scroll half a page up -.TP -.B l -Scroll to the right -.TP -.B / -Search forwards -.TP -.B ? -Search backwards -.TP -.B n -Search last keyword forwards -.TP -.B N -Search last keyword backwards -.TP -.B Tab -Toggle index -.TP -.B o -Open a file -.TP -.B a -Zoom to fit -.TP -.B s -Zoom to width -.TP -.B f -Follow a link on the page -.TP -.B m -Mark current position and save it in register specified by a character -.TP -.B ' -Go to saved position specified by the ensuing character -.TP -.B r -Rotate the page -.TP -.B R -Reload the document -.TP -.B O -Change goto mode (L: search labels, D: default, O: manual offset) -.TP -.B ^i -Recolors the page -.TP -.B i -Change to insert mode -.TP -.B v -Change to visual mode -.TP -.B : -Focus inputbar -.TP -.B Backspace -Delete last character in the buffer -.TP -.B F5 -Toggle fullscreen mode -.TP -.B ^n -Toggle statusbar visibility -.TP -.B ^m -Toggle inputbar visibility -.TP -.B Esc | ^c -Abort -.TP -.B ^q -Quit the program -.SS Index commands -.TP -.B k -Navigate to one element above the current position -.TP -.B j -Navigate to one element below the current position -.TP -.B h -Collapse current element -.TP -.B l -Expand current element -.TP -.B Space | Return -Select current element -.SS Buffered commands -.TP -.B gg -Go to the first page -.TP -.B GG -Go to the last page -.TP -.B [0-9]+G -Go to the specified page -.TP -.B zI -Zoom in -.TP -.B zO -Zoom out -.TP -.B z0 -Zoom to the original size -.TP -.B [0-9]+Z -Zoom to the given level -.TP -.B [0-9]+% -Move to the given position -.SS Commands -.TP -.B blist -List and open bookmark -.TP -.B bmark -Bookmark current page -.TP -.B close -Close current file -.TP -.B coffset -Set page offset -.TP -.B delbmark -Delete given bookmark -.TP -.B export -Export images or attached files -.TP -.B info -Show information about the document -.TP -.B map -Map shortcut functions (map ) -.TP -.B open -Open a file -.TP -.B print -Print the document -.TP -.B quit -Quit the program -.TP -.B rotate -Rotate the page -.TP -.B set -Set an option (set ) -.TP -.B write -Save the document -.SS Inputbar shortcuts -.TP -.B Up -Move up in the command history -.TP -.B Down -Move down in the command history -.TP -.B Tab | Shift + Tab -Tab completion -.TP -.B ^w -Delete last word -.SH CONFIGURATION -The complete configuration including the appearance and shortcuts of the program -are defined in a separate file named config.h. In this file you are able to -change and adjust all the settings of zathura according to your wishes. - -In addition you can create a zathurarc file (default path: ~/.config/zathura/zathurarc) -to overwrite settings and keybindings by using the set and map function. For -more information please check the faq on the website: -http://pwmt.org/projects/zathura +.B "-p path" +Path to the plugin directory. From 3c9e1f6e550bf7ee82e5b420ff8f709de5e1e857 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 27 May 2011 12:42:37 +0200 Subject: [PATCH 157/197] Use gtk_widget_get_visible instead of deprecated macro --- shortcuts.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index 51d2f45..d9d728f 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -43,7 +43,7 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsign { g_return_val_if_fail(session != NULL, false); - if (!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) { + if (!(gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)))) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); } @@ -299,7 +299,7 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned gtk_widget_show(treeview); } - if (GTK_WIDGET_VISIBLE(GTK_WIDGET(zathura->ui.index))) { + if (gtk_widget_get_visible(GTK_WIDGET(zathura->ui.index))) { girara_set_view(session, zathura->ui.page_view); gtk_widget_hide(GTK_WIDGET(zathura->ui.index)); } else { @@ -330,7 +330,7 @@ sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsig { g_return_val_if_fail(session != NULL, false); - if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar))) { + if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar))) { gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar)); } else { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); @@ -362,7 +362,7 @@ sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsi { g_return_val_if_fail(session != NULL, false); - if (GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.statusbar))) { + if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.statusbar))) { gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar)); } else { gtk_widget_show(GTK_WIDGET(session->gtk.statusbar)); From 2437d854718de954dcd51f00e6ffbe0bb80adbf3 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 27 May 2011 12:57:57 +0200 Subject: [PATCH 158/197] Remove obsolete page_blank function --- utils.c | 42 ------------------------------------------ utils.h | 9 --------- 2 files changed, 51 deletions(-) diff --git a/utils.c b/utils.c index 43511a8..40e5412 100644 --- a/utils.c +++ b/utils.c @@ -153,48 +153,6 @@ execute_command(char* const argv[], char** output) return true; } -GtkWidget* -page_blank(unsigned int width, unsigned int height) -{ - if ((width == 0) || (height == 0)) { - return NULL; - } - - guchar* buffer = malloc(sizeof(guchar) * (width * height * 1)); - if (!buffer) { - return NULL; - } - - /* draw white */ - for (unsigned int i = 0; i < width * height; i++) { - buffer[i] = 255; - } - - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8, - width, height, 1, NULL, NULL); - - if (!pixbuf) { - free(buffer); - return NULL; - } - - /* convert to image */ - GtkWidget* image = gtk_image_new(); - if (!image) { - free(buffer); - g_object_unref(pixbuf); - return false; - } - - gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); - gtk_widget_show(image); - - /*free(buffer);*/ // XXX: Read documentation - g_object_unref(pixbuf); - - return image; -} - void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree) { diff --git a/utils.h b/utils.h index 62db090..3637b58 100644 --- a/utils.h +++ b/utils.h @@ -50,15 +50,6 @@ bool file_valid_extension(zathura_t* zathura, const char* path); */ bool execute_command(char* const argv[], char** output); -/** - * Creates a blank page - * - * @param width The width of the page - * @param height The height of the page - * @return The widget of the page or NULL if an error occured - */ -GtkWidget* page_blank(unsigned int width, unsigned int height); - /** * Generates the document index based upon the list retreived from the document * object. From 234b9785c97a6459ce46efed47a4458c0f6b20f4 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Fri, 27 May 2011 12:59:05 +0200 Subject: [PATCH 159/197] Remove BSDmakefile --- BSDmakefile | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 BSDmakefile diff --git a/BSDmakefile b/BSDmakefile deleted file mode 100644 index 362214d..0000000 --- a/BSDmakefile +++ /dev/null @@ -1,9 +0,0 @@ -# See LICENSE file for license and copyright information - -all ${.TARGETS}: - @if [ ! `which gmake` ] ; then \ - echo "zathura cannot be built with BSD make and GNU make cannot be found." \ - "Please install GNU make."; \ - exit 1; \ - fi - @gmake $@ From 48c2d01bef95a956ccebe0aeae3f7aa4ba15d986 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 23 Jun 2011 14:31:41 +0200 Subject: [PATCH 160/197] Use giraras toggle functions --- config.c | 124 ++++++++++++++++++++++++++-------------------------- shortcuts.c | 28 ------------ shortcuts.h | 20 --------- 3 files changed, 62 insertions(+), 110 deletions(-) diff --git a/config.c b/config.c index 3c95c83..bf5bf99 100644 --- a/config.c +++ b/config.c @@ -44,66 +44,66 @@ config_load_default(zathura_t* zathura) girara_setting_add(gsession, "recolor-light-color", string_value, STRING, false, "Recoloring (light color)", 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, sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(gsession, 0, GDK_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); - girara_shortcut_add(gsession, 0, GDK_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); - girara_shortcut_add(gsession, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); - girara_shortcut_add(gsession, 0, GDK_O, NULL, 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 | FULLSCREEN, TOP, NULL); - girara_shortcut_add(gsession, 0, 0, "G", sc_goto, NORMAL | 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 | INDEX, 0, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_m, NULL, sc_toggle_inputbar, NORMAL, 0, NULL); - girara_shortcut_add(gsession, 0, GDK_F5, NULL, sc_toggle_fullscreen, NORMAL | FULLSCREEN, 0, NULL); - girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_n, NULL, 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 | FULLSCREEN, ZOOM_IN, NULL); - girara_shortcut_add(gsession, 0, GDK_minus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); - girara_shortcut_add(gsession, 0, GDK_equal, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); - girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); - girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); - girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); + 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, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); + girara_shortcut_add(gsession, 0, GDK_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); + girara_shortcut_add(gsession, 0, GDK_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); + girara_shortcut_add(gsession, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); + girara_shortcut_add(gsession, 0, GDK_O, NULL, 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 | FULLSCREEN, TOP, NULL); + girara_shortcut_add(gsession, 0, 0, "G", sc_goto, NORMAL | 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 | 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 | 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 | FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, GDK_minus, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, GDK_equal, NULL, sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); + girara_shortcut_add(gsession, 0, 0, "zI", sc_zoom, NORMAL | FULLSCREEN, ZOOM_IN, NULL); + girara_shortcut_add(gsession, 0, 0, "zO", sc_zoom, NORMAL | FULLSCREEN, ZOOM_OUT, NULL); + girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); /* define default inputbar commands */ girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark"); @@ -132,8 +132,8 @@ config_load_default(zathura_t* zathura) girara_shortcut_mapping_add(gsession, "search", sc_search); girara_shortcut_mapping_add(gsession, "toggle_fullscreen", sc_toggle_fullscreen); girara_shortcut_mapping_add(gsession, "toggle_index", sc_toggle_index); - girara_shortcut_mapping_add(gsession, "toggle_inputbar", sc_toggle_inputbar); - girara_shortcut_mapping_add(gsession, "toggle_statusbar", sc_toggle_statusbar); + girara_shortcut_mapping_add(gsession, "toggle_inputbar", girara_sc_toggle_inputbar); + girara_shortcut_mapping_add(gsession, "toggle_statusbar", girara_sc_toggle_statusbar); girara_shortcut_mapping_add(gsession, "zoom", sc_zoom); } diff --git a/shortcuts.c b/shortcuts.c index d9d728f..a2d484c 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -325,20 +325,6 @@ error_ret: return false; } -bool -sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) -{ - g_return_val_if_fail(session != NULL, false); - - if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar))) { - gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar)); - } else { - gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); - } - - return false; -} - bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, unsigned int t) { @@ -357,20 +343,6 @@ sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, uns return false; } -bool -sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) -{ - g_return_val_if_fail(session != NULL, false); - - if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.statusbar))) { - gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar)); - } else { - gtk_widget_show(GTK_WIDGET(session->gtk.statusbar)); - } - - return false; -} - bool sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) { diff --git a/shortcuts.h b/shortcuts.h index 8a0bade..8c7f7b4 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -145,16 +145,6 @@ bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, u */ bool sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned int t); -/** - * Show/Hide the inputbar - * - * @param session The used girara session - * @param argument The used argument - * @param t Number of executions - * @return true if no error occured otherwise false - */ -bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t); - /** * Toggle fullscreen mode * @@ -165,16 +155,6 @@ bool sc_toggle_inputbar(girara_session_t* session, girara_argument_t* argument, */ bool sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, unsigned int t); -/** - * Show/Hide the statusbar - * - * @param session The used girara session - * @param argument The used argument - * @param t Number of executions - * @return true if no error occured otherwise false - */ -bool sc_toggle_statusbar(girara_session_t* session, girara_argument_t* argument, unsigned int t); - /** * Quit zathura * From 9d5cbcabb563027649160b34fc474b9e67af3aef Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 23 Jun 2011 22:40:48 +0200 Subject: [PATCH 161/197] Fix possible segmentation fault --- zathura.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zathura.c b/zathura.c index 71dc359..88dad9f 100644 --- a/zathura.c +++ b/zathura.c @@ -60,7 +60,8 @@ zathura_init(int argc, char* argv[]) printf("Error parsing command line arguments: %s\n", error->message); g_option_context_free(context); g_error_free(error); - goto error_free; + free(zathura); + return NULL; } g_option_context_free(context); From 2a90a68ce8e168f0a983cdadf7ed08cb8b09ccfe Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 23 Jun 2011 22:43:08 +0200 Subject: [PATCH 162/197] Saner solution for the possible seg fault --- zathura.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/zathura.c b/zathura.c index 88dad9f..b8562b9 100644 --- a/zathura.c +++ b/zathura.c @@ -25,20 +25,6 @@ gboolean document_info_open(gpointer data); zathura_t* zathura_init(int argc, char* argv[]) { - zathura_t* zathura = malloc(sizeof(zathura_t)); - - if (zathura == NULL) { - return NULL; - } - - /* general */ - zathura->document = NULL; - - /* plugins */ - zathura->plugins.plugins = girara_list_new(); - zathura->plugins.path = girara_list_new(); - girara_list_set_free_function(zathura->plugins.path, g_free); - /* parse command line options */ GdkNativeWindow embed = 0; gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL; @@ -60,11 +46,24 @@ zathura_init(int argc, char* argv[]) printf("Error parsing command line arguments: %s\n", error->message); g_option_context_free(context); g_error_free(error); - free(zathura); - return NULL; + goto error_free; } g_option_context_free(context); + zathura_t* zathura = malloc(sizeof(zathura_t)); + + if (zathura == NULL) { + return NULL; + } + + /* general */ + zathura->document = NULL; + + /* plugins */ + zathura->plugins.plugins = girara_list_new(); + zathura->plugins.path = girara_list_new(); + girara_list_set_free_function(zathura->plugins.path, g_free); + if (config_dir) { zathura->config.config_dir = g_strdup(config_dir); } else { From aec6843b54c643e66e6cd1ff2a12990d06d9830b Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 25 Jun 2011 00:53:08 +0200 Subject: [PATCH 163/197] Update to new name of girara. --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index b1efcf6..f87e762 100644 --- a/config.mk +++ b/config.mk @@ -12,7 +12,7 @@ GTK_INC = $(shell pkg-config --cflags gtk+-2.0) GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0) INCS = -I. -I/usr/include ${GTK_INC} -LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara -ldl +LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara-gtk2 -ldl # flags CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) From 376390a65c2565a060bc8f10dd38ca4ed0403108 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sun, 10 Jul 2011 20:04:24 +0200 Subject: [PATCH 164/197] use pkg-config to determine girara libs and inc --- config.mk | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config.mk b/config.mk index f87e762..1c86fe0 100644 --- a/config.mk +++ b/config.mk @@ -11,8 +11,11 @@ MANPREFIX ?= ${PREFIX}/share/man GTK_INC = $(shell pkg-config --cflags gtk+-2.0) GTK_LIB = $(shell pkg-config --libs gtk+-2.0 gthread-2.0) -INCS = -I. -I/usr/include ${GTK_INC} -LIBS = -lc ${GTK_LIB} -lpthread -lm -lgirara-gtk2 -ldl +GIRARA_INC = $(shell pkg-config --cflags girara-gtk2) +GIRARA_LIB = $(shell pkg-config --libs girara-gtk2) + +INCS = -I. -I/usr/include ${GIRARA_INC} ${GTK_INC} +LIBS = -lc ${GIRARA_LIB} ${GTK_LIB} -lpthread -lm -ldl # flags CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) @@ -27,4 +30,4 @@ LDFLAGS += -rdynamic CC ?= gcc # strip -SFLAGS = -s +SFLAGS ?= -s From 87cff5ac75e92f7dd4eb189e4c97f4e3633451eb Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sun, 10 Jul 2011 20:14:31 +0200 Subject: [PATCH 165/197] provide pkg-config file to build plugins --- Makefile | 18 +++++++++++++++--- zathura.pc.in | 9 +++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 zathura.pc.in diff --git a/Makefile b/Makefile index 2e2616c..9b4459b 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ ${PROJECT}: ${OBJECTS} clean: @rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ - ${DOBJECTS} ${PROJECT}-debug .depend + ${DOBJECTS} ${PROJECT}-debug .depend ${PROJECT}.pc ${PROJECT}-debug: ${DOBJECTS} @echo CC -o ${PROJECT}-debug @@ -43,6 +43,12 @@ ${PROJECT}-debug: ${DOBJECTS} debug: ${PROJECT}-debug +${PROJECT}.pc: ${PROJECT}.pc.in config.mk + @echo project=${PROJECT} > ${PROJECT}.pc + @echo version=${VERSION} >> ${PROJECT}.pc + @echo includedir=${PREFIX}/include/${PROJECT} >> ${PROJECT}.pc + @cat ${PROJECTNV}.pc.in >> ${PROJECT}.pc + valgrind: debug valgrind --tool=memcheck --leak-check=yes --show-reachable=yes \ ./${PROJECT}-debug @@ -53,12 +59,13 @@ gdb: debug dist: clean @${MAKE} -p ${PROJECT}-${VERSION} @cp -R LICENSE Makefile config.mk README \ - ${PROJECT}.1 ${SOURCE} ${PROJECT}-${VERSION} + ${PROJECT}.1 ${SOURCE} ${PROJECT}-${VERSION} \ + ${PROJECT}.pc.in @tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION} @gzip ${PROJECT}-${VERSION}.tar @rm -rf ${PROJECT}-${VERSION} -install: all +install: all ${PROJECT}.pc @echo installing executable file @mkdir -p ${DESTDIR}${PREFIX}/bin @cp -f ${PROJECT} ${DESTDIR}${PREFIX}/bin @@ -71,6 +78,9 @@ install: all @mkdir -p ${DESTDIR}${MANPREFIX}/man1 @sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 + @echo installing pkgconfig file + @mkdir -p ${DESTDIR}${PREFIX}/lib/pkgconfig + @cp -f ${PROJECT}.pc ${DESTDIR}${PREFIX}/lib/pkgconfig uninstall: @echo removing executable file @@ -80,6 +90,8 @@ uninstall: @rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/zathura.h @echo removing manual page @rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 + @echo removing pkgconfig file + @rm -f ${DESTDIR}${PREFIX}/lib/pkgconfig -include $(wildcard .depend/*.dep) diff --git a/zathura.pc.in b/zathura.pc.in new file mode 100644 index 0000000..6e36e4f --- /dev/null +++ b/zathura.pc.in @@ -0,0 +1,9 @@ + +INC_PATH=-I${includedir} + +Name: ${project} +Description: document viewer +Version: ${version} +URL: http://pwmt.org/projects/zathura +Cflags: ${INC_PATH} +Libs: From 15afd761fae329fcd77200765ab3316b965a27b0 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sun, 10 Jul 2011 20:16:24 +0200 Subject: [PATCH 166/197] update include path --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9b4459b..8e68ce8 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ debug: ${PROJECT}-debug ${PROJECT}.pc: ${PROJECT}.pc.in config.mk @echo project=${PROJECT} > ${PROJECT}.pc @echo version=${VERSION} >> ${PROJECT}.pc - @echo includedir=${PREFIX}/include/${PROJECT} >> ${PROJECT}.pc + @echo includedir=${PREFIX}/include >> ${PROJECT}.pc @cat ${PROJECTNV}.pc.in >> ${PROJECT}.pc valgrind: debug From 894a5735bcedf952124cd0e3fb0ca238a6ac9f09 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Thu, 14 Jul 2011 21:34:16 +0200 Subject: [PATCH 167/197] fix typo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8e68ce8..8bc2857 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ ${PROJECT}.pc: ${PROJECT}.pc.in config.mk @echo project=${PROJECT} > ${PROJECT}.pc @echo version=${VERSION} >> ${PROJECT}.pc @echo includedir=${PREFIX}/include >> ${PROJECT}.pc - @cat ${PROJECTNV}.pc.in >> ${PROJECT}.pc + @cat ${PROJECT}.pc.in >> ${PROJECT}.pc valgrind: debug valgrind --tool=memcheck --leak-check=yes --show-reachable=yes \ From a58f5f0857d330a9254c4770be550a761329570f Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 20 Jul 2011 09:56:57 +0200 Subject: [PATCH 168/197] Fix build error --- completion.c | 1 + 1 file changed, 1 insertion(+) diff --git a/completion.c b/completion.c index f9c0ef6..5fc32cf 100644 --- a/completion.c +++ b/completion.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include "completion.h" From 32d90379bc274a3ebf6abd18149886542f242586 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Thu, 21 Jul 2011 14:47:24 +0200 Subject: [PATCH 169/197] Allow changing of "pages-per-row" variable at runtime --- callbacks.c | 12 ++++++++++++ callbacks.h | 10 +++++++++- config.c | 11 ++++++----- zathura.c | 13 +++++++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/callbacks.c b/callbacks.c index e027b6b..eb4f0d5 100644 --- a/callbacks.c +++ b/callbacks.c @@ -78,3 +78,15 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) free(offset); } } + +void +cb_pages_per_row_value_changed(girara_session_t* session, girara_setting_t* setting) +{ + int pages_per_row = setting->value.i; + zathura_t* zathura = setting->data; + + if (pages_per_row < 1) + pages_per_row = 1; + + page_view_set_mode(zathura, pages_per_row); +} diff --git a/callbacks.h b/callbacks.h index 8743be1..1d960c6 100644 --- a/callbacks.h +++ b/callbacks.h @@ -23,12 +23,20 @@ gboolean cb_destroy(GtkWidget* widget, gpointer data); void buffer_changed(girara_session_t* session); /** - * This function gets called when the the value of the vertical scrollbars + * This function gets called when the value of the vertical scrollbars * changes (e.g.: by scrolling, moving to another page) * * @param adjustment The vadjustment of the page view * @param data NULL */ void cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data); +/** + * This function gets called when the value of the "pages-per-row" + * variable changes + * + * @param session The current girara session + * @param setting The "pages-per-row" setting + */ +void cb_pages_per_row_value_changed(girara_session_t* session, girara_setting_t* setting); #endif // CALLBACKS_H diff --git a/config.c b/config.c index bf5bf99..96a9371 100644 --- a/config.c +++ b/config.c @@ -3,6 +3,7 @@ #include "config.h" #include "commands.h" #include "completion.h" +#include "callbacks.h" #include "shortcuts.h" #include "zathura.h" @@ -32,16 +33,16 @@ config_load_default(zathura_t* zathura) /* zathura settings */ int_value = 10; - girara_setting_add(gsession, "zoom-step", &int_value, INT, false, "Zoom step", NULL); + girara_setting_add(gsession, "zoom-step", &int_value, INT, false, "Zoom step", NULL, NULL); int_value = 1; - girara_setting_add(gsession, "page-padding", &int_value, INT, true, "Padding between pages", NULL); + girara_setting_add(gsession, "page-padding", &int_value, INT, true, "Padding between pages", NULL, NULL); int_value = 2; - girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL); + girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", cb_pages_per_row_value_changed, zathura); string_value = "#FFFFFF"; - girara_setting_add(gsession, "recolor-dark-color", string_value, STRING, false, "Recoloring (dark color)", NULL); + girara_setting_add(gsession, "recolor-dark-color", string_value, STRING, false, "Recoloring (dark color)", NULL, NULL); string_value = "#000000"; - girara_setting_add(gsession, "recolor-light-color", string_value, STRING, false, "Recoloring (light color)", NULL); + girara_setting_add(gsession, "recolor-light-color", string_value, STRING, false, "Recoloring (light color)", NULL, NULL); /* define default shortcuts */ girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); diff --git a/zathura.c b/zathura.c index b8562b9..5b0bf1a 100644 --- a/zathura.c +++ b/zathura.c @@ -378,11 +378,24 @@ statusbar_page_number_update(zathura_t* zathura) void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { + GList* child; + /* show at least one page */ if (pages_per_row == 0) { pages_per_row = 1; } + if (zathura->document == NULL) { + return; + } + + child = gtk_container_get_children(GTK_CONTAINER(zathura->ui.page_view)); + while (child) { + g_object_ref(G_OBJECT(child->data)); + gtk_container_remove(GTK_CONTAINER(zathura->ui.page_view), GTK_WIDGET(child->data)); + child = g_list_next(child); + } + gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row); for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) { From 686abbf5881f7fd1b231762421721e0bf6ed069a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 21 Jul 2011 14:48:48 +0200 Subject: [PATCH 170/197] Update coding standard --- callbacks.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/callbacks.c b/callbacks.c index eb4f0d5..8ec1b17 100644 --- a/callbacks.c +++ b/callbacks.c @@ -85,8 +85,9 @@ cb_pages_per_row_value_changed(girara_session_t* session, girara_setting_t* sett int pages_per_row = setting->value.i; zathura_t* zathura = setting->data; - if (pages_per_row < 1) + if (pages_per_row < 1) { pages_per_row = 1; + } page_view_set_mode(zathura, pages_per_row); } From 333cfa4df0542ed8d6f347b0456372b8e8d5a6dc Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Thu, 25 Aug 2011 00:45:50 +0200 Subject: [PATCH 171/197] make GIRARA/GTK_INC/LIB overwritable --- config.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.mk b/config.mk index 1c86fe0..131e2e6 100644 --- a/config.mk +++ b/config.mk @@ -8,11 +8,11 @@ PREFIX ?= /usr MANPREFIX ?= ${PREFIX}/share/man # libs -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+-2.0) +GTK_LIB ?= $(shell pkg-config --libs gtk+-2.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-gtk2) +GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk2) INCS = -I. -I/usr/include ${GIRARA_INC} ${GTK_INC} LIBS = -lc ${GIRARA_LIB} ${GTK_LIB} -lpthread -lm -ldl From caccb94c6909f99d5f6ef939b1820aa9efa753c6 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Thu, 21 Jul 2011 16:39:25 +0400 Subject: [PATCH 172/197] Fix ':close' command Currently, zathura crashes while performing ':close' command with the following error: GThread-ERROR **: file gthread-posix.c: line 226 (g_cond_free_posix_impl): error 'Device or resource busy' during 'pthread_cond_destroy ((pthread_cond_t *) cond)' The error is because 'render' thread holds condition variable while waiting for new pages to render. This patch modifies zathura's code to correctly kill render thread and free allocated resources when the document is being closed. NOTE: should be applied on top of "Allow changing of "pages-per-row" variable at runtime" commit to avoid conflicts in the 'page_view_set_mode()' function. Signed-off-by: Pavel Borzenkov --- document.c | 3 +++ render.c | 13 +++++++++++++ zathura.c | 29 ++++++++++++++++++----------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/document.c b/document.c index 761113a..55cdef9 100644 --- a/document.c +++ b/document.c @@ -305,6 +305,7 @@ zathura_document_free(zathura_document_t* document) for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_free(document->pages[page_id]); + document->pages[page_id] = NULL; } free(document->pages); @@ -427,6 +428,8 @@ zathura_page_free(zathura_page_t* page) return false; } + g_static_mutex_free(&(page->lock)); + return page->document->functions.page_free(page); } diff --git a/render.c b/render.c index 16c129a..16c0a4c 100644 --- a/render.c +++ b/render.c @@ -17,6 +17,17 @@ render_job(void* data) g_cond_wait(render_thread->cond, render_thread->lock); } + if (girara_list_size(render_thread->list) <= 0) { + /* + * We've been signaled with g_cond_signal(), but the list + * is still empty. This means that the signal came from + * render_free() and current document is being closed. + * We should unlock the mutex and kill the thread. + */ + g_mutex_unlock(render_thread->lock); + g_thread_exit(0); + } + zathura_page_t* page = (zathura_page_t*) girara_list_nth(render_thread->list, 0); girara_list_remove(render_thread->list, page); g_mutex_unlock(render_thread->lock); @@ -104,6 +115,8 @@ render_free(render_thread_t* render_thread) } if (render_thread->cond) { + g_cond_signal(render_thread->cond); + g_thread_join(render_thread->thread); g_cond_free(render_thread->cond); } diff --git a/zathura.c b/zathura.c index 5b0bf1a..dba3d87 100644 --- a/zathura.c +++ b/zathura.c @@ -308,6 +308,16 @@ error_out: return false; } +static void +remove_page_from_table(GtkWidget* page, gpointer permanent) +{ + if (!permanent) { + g_object_ref(G_OBJECT(page)); + } + + gtk_container_remove(GTK_CONTAINER(page->parent), page); +} + bool document_close(zathura_t* zathura) { @@ -315,11 +325,15 @@ document_close(zathura_t* zathura) return false; } - if (zathura->sync.render_thread) { - render_free(zathura->sync.render_thread); - } + render_free(zathura->sync.render_thread); + zathura->sync.render_thread = NULL; + + gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_view), remove_page_from_table, (gpointer)1); zathura_document_free(zathura->document); + zathura->document = NULL; + + gtk_widget_hide_all(zathura->ui.page_view); return true; } @@ -378,8 +392,6 @@ statusbar_page_number_update(zathura_t* zathura) void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) { - GList* child; - /* show at least one page */ if (pages_per_row == 0) { pages_per_row = 1; @@ -389,12 +401,7 @@ page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row) return; } - child = gtk_container_get_children(GTK_CONTAINER(zathura->ui.page_view)); - while (child) { - g_object_ref(G_OBJECT(child->data)); - gtk_container_remove(GTK_CONTAINER(zathura->ui.page_view), GTK_WIDGET(child->data)); - child = g_list_next(child); - } + gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_view), remove_page_from_table, (gpointer)0); gtk_table_resize(GTK_TABLE(zathura->ui.page_view), zathura->document->number_of_pages / pages_per_row + 1, pages_per_row); for (unsigned int i = 0; i < zathura->document->number_of_pages; i++) From e349eddd9dccd858f924007ad8a51c4e8da8eef3 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 30 Aug 2011 23:40:13 +0200 Subject: [PATCH 173/197] don't fail in :close if nothing is open --- commands.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands.c b/commands.c index bb14888..817165d 100644 --- a/commands.c +++ b/commands.c @@ -28,7 +28,10 @@ cmd_close(girara_session_t* session, girara_list_t* argument_list) g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; - g_return_val_if_fail(zathura->document != NULL, false); + if (zathura->document == NULL) { + // nothing needs to be done + return true; + } document_close(zathura); From c445b0e679656fad6a50da5c4bed47747eee8aa5 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 31 Aug 2011 00:08:33 +0200 Subject: [PATCH 174/197] implement :open --- commands.c | 21 +++++++++++++++++++++ zathura.c | 1 + 2 files changed, 22 insertions(+) diff --git a/commands.c b/commands.c index 817165d..b2353bd 100644 --- a/commands.c +++ b/commands.c @@ -47,6 +47,27 @@ cmd_info(girara_session_t* session, girara_list_t* argument_list) bool cmd_open(girara_session_t* session, girara_list_t* argument_list) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + + if (zathura->document) { + document_close(zathura); + } + + const int argc = girara_list_size(argument_list); + if (argc > 2) { + girara_error("too many arguments"); + return false; + } + else if (argc >= 1) { + document_open(zathura, girara_list_nth(argument_list, 0), (argc == 2) ? girara_list_nth(argument_list, 1) : NULL); + } + else { + girara_error("no arguments"); + return false; + } + return true; } diff --git a/zathura.c b/zathura.c index dba3d87..de24885 100644 --- a/zathura.c +++ b/zathura.c @@ -257,6 +257,7 @@ document_info_open(gpointer data) } document_open(document_info->zathura, document_info->path, document_info->password); + free(document_info); return FALSE; } From c24117b48777aae893b7c7b22573b8cb01e3f703 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 31 Aug 2011 12:42:22 +0200 Subject: [PATCH 175/197] remove extra semi-colon --- commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.c b/commands.c index b2353bd..059e0f0 100644 --- a/commands.c +++ b/commands.c @@ -83,7 +83,7 @@ cmd_print(girara_session_t* session, girara_list_t* argument_list) return false; } - print((zathura_t*) session->global.data);; + print((zathura_t*) session->global.data); return true; } From 8cee01a4d9de26cfec03991904055163fd602db9 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 31 Aug 2011 14:35:53 +0200 Subject: [PATCH 176/197] #include "..." --- .gitignore | 1 + callbacks.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bceaf5a..0cd5c09 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.rej *.swp .depend +zathura diff --git a/callbacks.c b/callbacks.c index 8ec1b17..ebac483 100644 --- a/callbacks.c +++ b/callbacks.c @@ -1,10 +1,10 @@ /* See LICENSE file for license and copyright information */ -#include #include #include #include +#include "callbacks.h" #include "zathura.h" #include "render.h" #include "document.h" From a66f2dd53a185a3495425825953988c11041f645 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 31 Aug 2011 14:36:24 +0200 Subject: [PATCH 177/197] no need to add -I. and -I/usr/include --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index 131e2e6..3e21254 100644 --- a/config.mk +++ b/config.mk @@ -14,7 +14,7 @@ GTK_LIB ?= $(shell pkg-config --libs gtk+-2.0 gthread-2.0) GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk2) GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk2) -INCS = -I. -I/usr/include ${GIRARA_INC} ${GTK_INC} +INCS = ${GIRARA_INC} ${GTK_INC} LIBS = -lc ${GIRARA_LIB} ${GTK_LIB} -lpthread -lm -ldl # flags From 36749e1266dee5d4314443bbfe4d7de7796bfc5d Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 31 Aug 2011 16:41:07 +0200 Subject: [PATCH 178/197] add verbose build output --- .gitignore | 1 + Makefile | 84 +++++++++++++++++++++++++++--------------------------- common.mk | 9 ++++++ config.mk | 3 ++ 4 files changed, 55 insertions(+), 42 deletions(-) create mode 100644 common.mk diff --git a/.gitignore b/.gitignore index 0cd5c09..b596c2d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.swp .depend zathura +zathura-debug diff --git a/Makefile b/Makefile index 8bc2857..efc70b6 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ # See LICENSE file for license and copyright information include config.mk +include common.mk PROJECT = zathura SOURCE = $(shell find . -iname "*.c") @@ -17,37 +18,37 @@ options: @echo "CC = ${CC}" %.o: %.c - @echo CC $< + $(ECHO) CC $< @mkdir -p .depend - @${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep + $(QUIET)${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep %.do: %.c - @echo CC $< + $(ECHO) CC $< @mkdir -p .depend - @${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep + $(QUIET)${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep ${OBJECTS}: config.mk ${DOBJECTS}: config.mk ${PROJECT}: ${OBJECTS} - @echo CC -o $@ - @${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS} + $(ECHO) CC -o $@ + $(QUIET)${CC} ${SFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS} clean: - @rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ + $(QUIET)rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \ ${DOBJECTS} ${PROJECT}-debug .depend ${PROJECT}.pc ${PROJECT}-debug: ${DOBJECTS} - @echo CC -o ${PROJECT}-debug - @${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS} + $(ECHO) CC -o $@ + $(QUIET)${CC} ${LDFLAGS} -o $@ ${DOBJECTS} ${LIBS} debug: ${PROJECT}-debug ${PROJECT}.pc: ${PROJECT}.pc.in config.mk - @echo project=${PROJECT} > ${PROJECT}.pc - @echo version=${VERSION} >> ${PROJECT}.pc - @echo includedir=${PREFIX}/include >> ${PROJECT}.pc - @cat ${PROJECT}.pc.in >> ${PROJECT}.pc + $(QUIET)echo project=${PROJECT} > ${PROJECT}.pc + $(QUIET)echo version=${VERSION} >> ${PROJECT}.pc + $(QUIET)echo includedir=${PREFIX}/include >> ${PROJECT}.pc + $(QUIET)cat ${PROJECT}.pc.in >> ${PROJECT}.pc valgrind: debug valgrind --tool=memcheck --leak-check=yes --show-reachable=yes \ @@ -57,41 +58,40 @@ gdb: debug cgdb ${PROJECT}-debug dist: clean - @${MAKE} -p ${PROJECT}-${VERSION} - @cp -R LICENSE Makefile config.mk README \ + $(QUIET)${MAKE} -p ${PROJECT}-${VERSION} + $(QUIET)cp -R LICENSE Makefile config.mk README \ ${PROJECT}.1 ${SOURCE} ${PROJECT}-${VERSION} \ ${PROJECT}.pc.in - @tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION} - @gzip ${PROJECT}-${VERSION}.tar - @rm -rf ${PROJECT}-${VERSION} + $(QUIET)tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION} + $(QUIET)gzip ${PROJECT}-${VERSION}.tar + $(QUIET)rm -rf ${PROJECT}-${VERSION} install: all ${PROJECT}.pc - @echo installing executable file - @mkdir -p ${DESTDIR}${PREFIX}/bin - @cp -f ${PROJECT} ${DESTDIR}${PREFIX}/bin - @chmod 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin/${PROJECT} - @echo installing header file - @mkdir -p ${DESTDIR}${PREFIX}/include/${PROJECT} - @cp -f document.h ${DESTDIR}${PREFIX}/include/${PROJECT} - @cp -f zathura.h ${DESTDIR}${PREFIX}/include/${PROJECT} - @echo installing manual page - @mkdir -p ${DESTDIR}${MANPREFIX}/man1 - @sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 - @chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 - @echo installing pkgconfig file - @mkdir -p ${DESTDIR}${PREFIX}/lib/pkgconfig - @cp -f ${PROJECT}.pc ${DESTDIR}${PREFIX}/lib/pkgconfig + $(ECHO) installing executable file + $(QUIET)mkdir -p ${DESTDIR}${PREFIX}/bin + $(QUIET)install -m 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin + $(ECHO) installing header file + $(QUIET)mkdir -p ${DESTDIR}${PREFIX}/include/${PROJECT} + $(QUIET)cp -f document.h ${DESTDIR}${PREFIX}/include/${PROJECT} + $(QUIET)cp -f zathura.h ${DESTDIR}${PREFIX}/include/${PROJECT} + $(ECHO) installing manual page + $(QUIET)mkdir -p ${DESTDIR}${MANPREFIX}/man1 + $(QUIET)sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 + $(QUIET)chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 + $(ECHO) installing pkgconfig file + $(QUIET)mkdir -p ${DESTDIR}${PREFIX}/lib/pkgconfig + $(QUIET)cp -f ${PROJECT}.pc ${DESTDIR}${PREFIX}/lib/pkgconfig uninstall: - @echo removing executable file - @rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT} - @echo removing header file - @rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/document.h - @rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/zathura.h - @echo removing manual page - @rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 - @echo removing pkgconfig file - @rm -f ${DESTDIR}${PREFIX}/lib/pkgconfig + $(ECHO) removing executable file + $(QUIET)rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT} + $(ECHO) removing header file + $(QUIET)rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/document.h + $(QUIET)rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/zathura.h + $(ECHO) removing manual page + $(QUIET)rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1 + $(ECHO) removing pkgconfig file + $(QUIET)rm -f ${DESTDIR}${PREFIX}/lib/pkgconfig -include $(wildcard .depend/*.dep) diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..eb586f8 --- /dev/null +++ b/common.mk @@ -0,0 +1,9 @@ +# See LICENSE file for license and copyright information + +ifeq "$(VERBOSE)" "0" +ECHO=@echo +QUIET=@ +else +ECHO=@\# +QUIET= +endif diff --git a/config.mk b/config.mk index 3e21254..6c08b29 100644 --- a/config.mk +++ b/config.mk @@ -31,3 +31,6 @@ CC ?= gcc # strip SFLAGS ?= -s + +# set to something != 0 if you want verbose build output +VERBOSE ?= 0 From 36bdb57bf4e379ddb0ea1ce060672a6ba0247767 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 31 Aug 2011 16:43:35 +0200 Subject: [PATCH 179/197] fix dist target --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index efc70b6..649c8bc 100644 --- a/Makefile +++ b/Makefile @@ -58,10 +58,10 @@ gdb: debug cgdb ${PROJECT}-debug dist: clean - $(QUIET)${MAKE} -p ${PROJECT}-${VERSION} + $(QUIET)mkdir -p ${PROJECT}-${VERSION} $(QUIET)cp -R LICENSE Makefile config.mk README \ - ${PROJECT}.1 ${SOURCE} ${PROJECT}-${VERSION} \ - ${PROJECT}.pc.in + ${PROJECT}.1 ${SOURCE} ${PROJECT}.pc.in \ + ${PROJECT}-${VERSION} $(QUIET)tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION} $(QUIET)gzip ${PROJECT}-${VERSION}.tar $(QUIET)rm -rf ${PROJECT}-${VERSION} From 87aa9b9a46b9170ad11ea96c5d3d1cef2dc7f659 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Thu, 1 Sep 2011 11:51:49 +0200 Subject: [PATCH 180/197] implement :write and :write! --- commands.c | 40 ++++++++++++++++++++++++++++++++++++++++ commands.h | 10 ++++++++++ config.c | 3 ++- shortcuts.c | 4 +++- zathura.c | 21 +++++++++++++++++++++ zathura.h | 12 ++++++++++++ 6 files changed, 88 insertions(+), 2 deletions(-) diff --git a/commands.c b/commands.c index 059e0f0..351ad18 100644 --- a/commands.c +++ b/commands.c @@ -91,5 +91,45 @@ cmd_print(girara_session_t* session, girara_list_t* argument_list) bool cmd_save(girara_session_t* session, girara_list_t* argument_list) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + + if (zathura->document == NULL) { + girara_error("no document as been opened"); + return false; + } + + if (girara_list_size(argument_list) == 1) { + document_save(zathura, girara_list_nth(argument_list, 0), false); + } + else { + girara_error("invalid arguments"); + return false; + } + + return true; +} + +bool +cmd_savef(girara_session_t* session, girara_list_t* argument_list) +{ + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + + if (zathura->document == NULL) { + girara_error("no document as been opened"); + return false; + } + + if (girara_list_size(argument_list) == 1) { + document_save(zathura, girara_list_nth(argument_list, 0), true); + } + else { + girara_error("invalid arguments"); + return false; + } + return true; } diff --git a/commands.h b/commands.h index d174455..a8cc7c9 100644 --- a/commands.h +++ b/commands.h @@ -78,4 +78,14 @@ bool cmd_print(girara_session_t* session, girara_list_t* argument_list); */ bool cmd_save(girara_session_t* session, girara_list_t* argument_list); +/** + * Save the current file and overwrite existing files + * + * @param session The used girara session + * @param argument_list List of passed arguments + * @return true if no error occured + */ +bool cmd_savef(girara_session_t* session, girara_list_t* argument_list); + + #endif // COMMANDS_H diff --git a/config.c b/config.c index 96a9371..a5bc669 100644 --- a/config.c +++ b/config.c @@ -114,7 +114,8 @@ config_load_default(zathura_t* zathura) girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, "Show file information"); girara_inputbar_command_add(gsession, "open", "o", cmd_open, cc_open, "Open document"); girara_inputbar_command_add(gsession, "print", NULL, cmd_print, NULL, "Print document"); - girara_inputbar_command_add(gsession, "save", NULL, cmd_save, NULL, "Save document"); + girara_inputbar_command_add(gsession, "write", NULL, cmd_save, NULL, "Save document"); + girara_inputbar_command_add(gsession, "write!", NULL, cmd_savef, NULL, "Save document (and force overwriting)"); /* add shortcut mappings */ girara_shortcut_mapping_add(gsession, "abort", sc_abort); diff --git a/shortcuts.c b/shortcuts.c index a2d484c..a3b6a20 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -160,7 +160,9 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; g_return_val_if_fail(argument != NULL, false); - g_return_val_if_fail(zathura->document != NULL, false); + if (zathura->document == NULL) { + return false; + } GtkAdjustment* adjustment = NULL; if ( (argument->n == LEFT) || (argument->n == RIGHT) ) diff --git a/zathura.c b/zathura.c index de24885..67534de 100644 --- a/zathura.c +++ b/zathura.c @@ -309,6 +309,27 @@ error_out: return false; } +bool +document_save(zathura_t* zathura, const char* path, bool overwrite) +{ + g_return_val_if_fail(zathura, false); + g_return_val_if_fail(zathura->document, false); + 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)) + { + gchar* message = g_strdup_printf("File already exists: %s. Use :write! to overwrite it.", file_path); + girara_error(message); + g_free(message); + return false; + } + + bool res = zathura_document_save_as(zathura->document, file_path); + g_free(file_path); + return res; +} + static void remove_page_from_table(GtkWidget* page, gpointer permanent) { diff --git a/zathura.h b/zathura.h index af14996..e38b64a 100644 --- a/zathura.h +++ b/zathura.h @@ -114,6 +114,18 @@ void zathura_free(zathura_t* zathura); */ bool document_open(zathura_t* zathura, const char* path, const char* password); +/** + * Save a open file + * + * @param zathura The zathura session + * @param path The path + * @param overwrite Overwrite existing file + * + * @return If no error occured true, otherwise false, is returned. + */ +bool document_save(zathura_t* zathura, const char* path, bool overwrite); + + /** * Closes the current opened document * From bb466fc8912678936016609e7c182b448b35f11e Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Thu, 1 Sep 2011 13:15:27 +0200 Subject: [PATCH 181/197] add cmd_help skeleton --- commands.c | 6 ++++++ commands.h | 9 +++++++++ config.c | 1 + zathura.h | 1 - 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/commands.c b/commands.c index 351ad18..f6fbbc6 100644 --- a/commands.c +++ b/commands.c @@ -44,6 +44,12 @@ cmd_info(girara_session_t* session, girara_list_t* argument_list) return true; } +bool +cmd_help(girara_session_t* session, girara_list_t* argument_list) +{ + return true; +} + bool cmd_open(girara_session_t* session, girara_list_t* argument_list) { diff --git a/commands.h b/commands.h index a8cc7c9..1f09318 100644 --- a/commands.h +++ b/commands.h @@ -51,6 +51,15 @@ bool cmd_close(girara_session_t* session, girara_list_t* argument_list); */ bool cmd_info(girara_session_t* session, girara_list_t* argument_list); +/** + * Display help + * + * @param session The used girara session + * @param argument_list List of passed arguments + * @return true if no error occured + */ +bool cmd_help(girara_session_t* session, girara_list_t* argument_list); + /** * Opens a document file * diff --git a/config.c b/config.c index a5bc669..d967e0c 100644 --- a/config.c +++ b/config.c @@ -112,6 +112,7 @@ config_load_default(zathura_t* zathura) girara_inputbar_command_add(gsession, "blist", NULL, cmd_bookmark_open, NULL, "List all bookmarks"); girara_inputbar_command_add(gsession, "close", NULL, cmd_close, NULL, "Close current file"); girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, "Show file information"); + girara_inputbar_command_add(gsession, "help", NULL, cmd_help, NULL, "Show help"); girara_inputbar_command_add(gsession, "open", "o", cmd_open, cc_open, "Open document"); girara_inputbar_command_add(gsession, "print", NULL, cmd_print, NULL, "Print document"); girara_inputbar_command_add(gsession, "write", NULL, cmd_save, NULL, "Save document"); diff --git a/zathura.h b/zathura.h index e38b64a..622a5a3 100644 --- a/zathura.h +++ b/zathura.h @@ -125,7 +125,6 @@ bool document_open(zathura_t* zathura, const char* path, const char* password); */ bool document_save(zathura_t* zathura, const char* path, bool overwrite); - /** * Closes the current opened document * From a6596fb908b518ba772baea302384bcf78b9079c Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Thu, 1 Sep 2011 15:43:34 +0200 Subject: [PATCH 182/197] initial bookmarks implementation --- bookmarks.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ bookmarks.h | 29 +++++++++++++++++++++++ zathura.c | 8 +++++++ zathura.h | 6 +++++ 4 files changed, 109 insertions(+) create mode 100644 bookmarks.c create mode 100644 bookmarks.h diff --git a/bookmarks.c b/bookmarks.c new file mode 100644 index 0000000..40e5a1f --- /dev/null +++ b/bookmarks.c @@ -0,0 +1,66 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include "bookmarks.h" + +zathura_bookmark_t* +zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page) +{ + g_return_val_if_fail(zathura && zathura->bookmarks.bookmarks, NULL); + g_return_val_if_fail(id, NULL); + + GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) + if (strcmp(bookmark->id, id) == 0) + { + girara_list_iterator_free(iter); + return NULL; + } + GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) + + zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t)); + bookmark->id = g_strdup(id); + bookmark->page = page; + girara_list_append(zathura->bookmarks.bookmarks, bookmark); + + return bookmark; +} + +void zathura_bookmark_remove(zathura_t* zathura, const gchar* id) +{ + g_return_if_fail(zathura && zathura->bookmarks.bookmarks); + g_return_if_fail(id); + + zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, id); + if (bookmark) + { + girara_list_remove(zathura->bookmarks.bookmarks, bookmark); + } +} + +zathura_bookmark_t* zathura_bookmark_get(zathura_t* zathura, const gchar* id) +{ + g_return_val_if_fail(zathura && zathura->bookmarks.bookmarks, NULL); + g_return_val_if_fail(id, NULL); + + GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) + if (strcmp(bookmark->id, id) == 0) + { + girara_list_iterator_free(iter); + return bookmark; + } + GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) + + return NULL; +} + +void zathura_bookmark_free(zathura_bookmark_t* bookmark) +{ + if (!bookmark) + { + return; + } + + g_free(bookmark->id); + g_free(bookmark); +} + diff --git a/bookmarks.h b/bookmarks.h new file mode 100644 index 0000000..22b8e86 --- /dev/null +++ b/bookmarks.h @@ -0,0 +1,29 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef BOOKMARKS_H +#define BOOKMARKS_H + +#include +#include "zathura.h" + +struct zathura_bookmark_s +{ + gchar* id; + unsigned int page; +}; + +typedef struct zathura_bookmark_s zathura_bookmark_t; + +zathura_bookmark_t* zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page); + +void zathura_bookmark_remove(zathura_t* zathura, const gchar* id); + +zathura_bookmark_t* zathura_bookmark_get(zathura_t* zathura, const gchar* id); + +void zathura_bookmark_free(zathura_bookmark_t* bookmark); + +bool zathura_bookmarks_load(zathura_t* zathura, const gchar* file); + +bool zathura_bookmarks_save(zathura_t* zathura, const gchar* file); + +#endif // BOOKMARKS_H diff --git a/zathura.c b/zathura.c index 67534de..dabbdff 100644 --- a/zathura.c +++ b/zathura.c @@ -4,6 +4,7 @@ #include +#include "bookmarks.h" #include "callbacks.h" #include "config.h" #include "document.h" @@ -189,6 +190,10 @@ zathura_init(int argc, char* argv[]) free(string_value); } + /* bookmarks */ + zathura->bookmarks.bookmarks = girara_list_new(); + girara_list_set_free_function(zathura->bookmarks.bookmarks, (girara_free_function_t) zathura_bookmark_free); + /* open document if passed */ if (argc > 1) { zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t)); @@ -231,6 +236,9 @@ zathura_free(zathura_t* zathura) document_close(zathura); + /* bookmarks */ + girara_list_free(zathura->bookmarks.bookmarks); + /* free print settings */ g_object_unref(zathura->print.settings); g_object_unref(zathura->print.page_setup); diff --git a/zathura.h b/zathura.h index 622a5a3..f654fb0 100644 --- a/zathura.h +++ b/zathura.h @@ -84,6 +84,12 @@ typedef struct zathura_s girara_mode_t insert; /**> Insert mode */ } modes; + struct + { + gchar* file; /**> bookmarks file */ + girara_list_t* bookmarks; /**> bookmarks */ + } bookmarks; + zathura_document_t* document; /**> The current document */ } zathura_t; From 30dd00937b65e2824233e19204aeafc980eeeeb1 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Thu, 1 Sep 2011 19:18:29 +0200 Subject: [PATCH 183/197] rotate in render --- render.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/render.c b/render.c index 16c0a4c..1d3912c 100644 --- a/render.c +++ b/render.c @@ -214,9 +214,43 @@ render(zathura_t* zathura, zathura_page_t* page) } } + /* rotate */ + unsigned int width = page_width; + unsigned int height = page_height; + if (page->document->rotate == 90 || page->document->rotate == 270) { + width = page_height; + height = page_width; + } + + cairo_surface_t* final_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height); + cairo_t* cairo = cairo_create(final_surface); + + switch(page->document->rotate) + { + case 90: + cairo_translate(cairo, width, 0); + break; + case 180: + cairo_translate(cairo, width, height); + break; + case 270: + cairo_translate(cairo, 0, height); + break; + } + + if (page->document->rotate != 0) { + cairo_rotate(cairo, page->document->rotate * G_PI / 180.0); + } + + cairo_set_source_surface(cairo, surface, 0, 0); + cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); + cairo_paint(cairo); + cairo_destroy(cairo); + cairo_surface_destroy(surface); + /* draw to gtk widget */ - page->surface = surface; - gtk_widget_set_size_request(page->drawing_area, page_width, page_height); + page->surface = final_surface; + gtk_widget_set_size_request(page->drawing_area, width, height); gtk_widget_queue_draw(page->drawing_area); zathura_image_buffer_free(image_buffer); From 0c48f8267e7c0eef462a993b205d6e98f2541b4e Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 2 Sep 2011 12:04:05 +0200 Subject: [PATCH 184/197] document bookmark functions --- bookmarks.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/bookmarks.h b/bookmarks.h index 22b8e86..fc4b8b6 100644 --- a/bookmarks.h +++ b/bookmarks.h @@ -14,16 +14,50 @@ struct zathura_bookmark_s typedef struct zathura_bookmark_s zathura_bookmark_t; +/** + * Create a bookmark and add it to the list of bookmarks. + * @param zathura The zathura instance. + * @param id The bookmark's id. + * @param page The bookmark's page. + * @return the bookmark instance or NULL on failure. + */ zathura_bookmark_t* zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page); +/** + * Remove a bookmark from the list of bookmarks. + * @param zathura The zathura instance. + * @param id The bookmark's id. + */ void zathura_bookmark_remove(zathura_t* zathura, const gchar* id); +/** + * Get bookmark from the list of bookmarks. + * @param zathura The zathura instance. + * @param id The bookmark's id. + * @return The bookmark instance if it exists or NULL otherwise. + */ zathura_bookmark_t* zathura_bookmark_get(zathura_t* zathura, const gchar* id); +/** + * Free a bookmark instance. + * @param bookmark The bookmark instance. + */ void zathura_bookmark_free(zathura_bookmark_t* bookmark); +/** + * Load bookmarks for a specific file. + * @param zathura The zathura instance. + * @param file The file. + * @param true on success, false otherwise + */ bool zathura_bookmarks_load(zathura_t* zathura, const gchar* file); +/** + * Save bookmarks for a specific file. + * @param zathura The zathura instance. + * @param file The file. + * @param true on success, false otherwise + */ bool zathura_bookmarks_save(zathura_t* zathura, const gchar* file); #endif // BOOKMARKS_H From 48448c6507b1969ea9a23f321257b9c9beca2ea4 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Fri, 2 Sep 2011 17:58:37 +0400 Subject: [PATCH 185/197] Hide notification area in sc_focus_inputbar Signed-off-by: Pavel Borzenkov Signed-off-by: Sebastian Ramacher --- shortcuts.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shortcuts.c b/shortcuts.c index a3b6a20..6512bd8 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -47,6 +47,10 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsign gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); } + if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.notification_area))) { + gtk_widget_hide(GTK_WIDGET(session->gtk.notification_area)); + } + if (argument->data) { gtk_entry_set_text(session->gtk.inputbar, (char*) argument->data); gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar)); From 6f567a6264082348989772acb1df8396be1f47d9 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Fri, 2 Sep 2011 20:46:16 +0200 Subject: [PATCH 186/197] some initial work on the sqlite database backend --- bookmarks.c | 29 +++++--- config.mk | 7 +- database-sqlite.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++ database.h | 22 ++++++ zathura.c | 14 ++++ zathura.h | 5 ++ 6 files changed, 240 insertions(+), 10 deletions(-) create mode 100644 database-sqlite.c create mode 100644 database.h diff --git a/bookmarks.c b/bookmarks.c index 40e5a1f..ec73223 100644 --- a/bookmarks.c +++ b/bookmarks.c @@ -2,6 +2,7 @@ #include #include "bookmarks.h" +#include "database.h" zathura_bookmark_t* zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page) @@ -10,8 +11,7 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page) g_return_val_if_fail(id, NULL); GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) - if (strcmp(bookmark->id, id) == 0) - { + if (strcmp(bookmark->id, id) == 0) { girara_list_iterator_free(iter); return NULL; } @@ -31,8 +31,7 @@ void zathura_bookmark_remove(zathura_t* zathura, const gchar* id) g_return_if_fail(id); zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, id); - if (bookmark) - { + if (bookmark) { girara_list_remove(zathura->bookmarks.bookmarks, bookmark); } } @@ -43,8 +42,7 @@ zathura_bookmark_t* zathura_bookmark_get(zathura_t* zathura, const gchar* id) g_return_val_if_fail(id, NULL); GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) - if (strcmp(bookmark->id, id) == 0) - { + if (strcmp(bookmark->id, id) == 0) { girara_list_iterator_free(iter); return bookmark; } @@ -55,8 +53,7 @@ zathura_bookmark_t* zathura_bookmark_get(zathura_t* zathura, const gchar* id) void zathura_bookmark_free(zathura_bookmark_t* bookmark) { - if (!bookmark) - { + if (!bookmark) { return; } @@ -64,3 +61,19 @@ void zathura_bookmark_free(zathura_bookmark_t* bookmark) g_free(bookmark); } +bool +zathura_bookmarks_load(zathura_t* zathura, const gchar* file) { + g_return_val_if_fail(zathura && zathura->database, false); + g_return_val_if_fail(file, false); + + girara_list_t* bookmarks = zathura_db_load_bookmarks(zathura->database, file); + if (!bookmarks) { + return false; + } + + girara_list_free(zathura->bookmarks.bookmarks); + zathura->bookmarks.bookmarks = bookmarks; + return true; +} + + diff --git a/config.mk b/config.mk index 6c08b29..e2e163c 100644 --- a/config.mk +++ b/config.mk @@ -14,8 +14,11 @@ GTK_LIB ?= $(shell pkg-config --libs gtk+-2.0 gthread-2.0) GIRARA_INC ?= $(shell pkg-config --cflags girara-gtk2) GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk2) -INCS = ${GIRARA_INC} ${GTK_INC} -LIBS = -lc ${GIRARA_LIB} ${GTK_LIB} -lpthread -lm -ldl +SQLITE_INC ?= $(shell pkg-config --cflags sqlite3) +SQLITE_LIB ?= $(shell pkg-config --libs sqlite3) + +INCS = ${GIRARA_INC} ${GTK_INC} $(SQLITE_INC) +LIBS = -lc ${GIRARA_LIB} ${GTK_LIB} $(SQLITE_LIB) -lpthread -lm -ldl # flags CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) diff --git a/database-sqlite.c b/database-sqlite.c new file mode 100644 index 0000000..33b41e1 --- /dev/null +++ b/database-sqlite.c @@ -0,0 +1,173 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include +#include + +#include "database.h" + +struct zathura_database_s { + sqlite3* session; +}; + +zathura_database_t* +zathura_db_init(const char* path) { + zathura_database_t* db = g_malloc0(sizeof(zathura_database_t)); + + /* create bookmarks database */ + static const char SQL_BOOKMARK_INIT[] = + "CREATE TABLE IF NOT EXISTS bookmarks (" + "file TEXT PRIMARY KEY," + "id TEXT," + "page INTEGER," + "UNIQUE(file, id));"; + + static const char SQL_FILEINFO_INIT[] = + "CREATE TABLE IF NOT EXISTS fileinfo (" + "file TEXT PRIMARY KEY," + "page INTEGER," + "offset INTEGER," + "scale INTEGER);"; + + if (sqlite3_open(path, &(db->session)) != SQLITE_OK) { + girara_error("Could not open database: %s\n", path); + zathura_db_free(db); + return NULL; + } + + if (sqlite3_exec(db->session, SQL_BOOKMARK_INIT, NULL, 0, NULL) != SQLITE_OK) { + girara_error("Failed to initialize database: %s\n", path); + zathura_db_free(db); + return NULL; + } + + if (sqlite3_exec(db->session, SQL_FILEINFO_INIT, NULL, 0, NULL) != SQLITE_OK) { + girara_error("Failed to initialize database: %s\n", path); + zathura_db_free(db); + return NULL; + } + + return db; +} + +void +zathura_db_free(zathura_database_t* db) { + if (db == NULL) { + return; + } + + sqlite3_close(db->session); + g_free(db); +} + +static sqlite3_stmt* +prepare_statement(sqlite3* session, const char* statement) +{ + if (session == NULL || statement == NULL) { + return NULL; + } + + const char* pz_tail = NULL; + sqlite3_stmt* pp_stmt = NULL; + + if (sqlite3_prepare(session, statement, -1, &pp_stmt, &pz_tail) != SQLITE_OK) { + girara_error("Failed to prepare query: %s", statement); + sqlite3_finalize(pp_stmt); + return NULL; + } else if (pz_tail && *pz_tail != '\0') { + girara_error("Unused portion of statement: %s", pz_tail); + sqlite3_finalize(pp_stmt); + return NULL; + } + + return pp_stmt; +} + +bool +zathura_db_add_bookmark(zathura_database_t* db, const char* file, zathura_bookmark_t* bookmark) +{ + g_return_val_if_fail(db && file && bookmark, false); + + static const char SQL_BOOKMARK_ADD[] = + "REPLACE INTO bookmarks (file, id, page) VALUES (?, ?, ?);"; + + sqlite3_stmt* stmt = prepare_statement(db->session, SQL_BOOKMARK_ADD); + if (stmt == NULL) { + return false; + } + + if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK || + sqlite3_bind_text(stmt, 2, bookmark->id, -1, NULL) != SQLITE_OK || + sqlite3_bind_int(stmt, 3, bookmark->page) != SQLITE_OK) { + sqlite3_finalize(stmt); + girara_error("Failed to bind arguments."); + return false; + } + + int res = sqlite3_step(stmt); + sqlite3_finalize(stmt); + return res == SQLITE_OK; +} + +bool +zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char* id) +{ + g_return_val_if_fail(db && file && id, false); + + static const char SQL_BOOKMARK_ADD[] = + "DELETE FROM bookmarks WHERE file = ? && id = ?;"; + + sqlite3_stmt* stmt = prepare_statement(db->session, SQL_BOOKMARK_ADD); + if (stmt == NULL) { + return false; + } + + if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK || + sqlite3_bind_text(stmt, 2, id, -1, NULL) != SQLITE_OK) { + sqlite3_finalize(stmt); + girara_error("Failed to bind arguments."); + return false; + } + + int res = sqlite3_step(stmt); + sqlite3_finalize(stmt); + return res == SQLITE_OK; +} + +girara_list_t* +zathura_db_load_bookmarks(zathura_database_t* db, const char* file) +{ + g_return_val_if_fail(db && file, NULL); + + static const char SQL_BOOKMARK_SELECT[] = + "SELECT id, page FROM bookmarks WHERE file = ?;"; + + sqlite3_stmt* stmt = prepare_statement(db->session, SQL_BOOKMARK_SELECT); + if (stmt == NULL) { + return NULL; + } + + if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK) { + sqlite3_finalize(stmt); + girara_error("Failed to bind arguments."); + return NULL; + } + + girara_list_t* result = girara_list_new(); + if (result == NULL) { + sqlite3_finalize(stmt); + return NULL; + } + girara_list_set_free_function(result, (girara_free_function_t) zathura_bookmark_free); + + while (sqlite3_step(stmt) == SQLITE_ROW) { + zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t)); + bookmark->id = g_strdup((const char*) sqlite3_column_text(stmt, 0)); + bookmark->page = sqlite3_column_int(stmt, 1); + + girara_list_append(result, bookmark); + } + sqlite3_finalize(stmt); + return result; +} + diff --git a/database.h b/database.h new file mode 100644 index 0000000..3430589 --- /dev/null +++ b/database.h @@ -0,0 +1,22 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef DATABASE_H +#define DATABASE_H + +#include +#include + +#include "zathura.h" +#include "bookmarks.h" + +zathura_database_t* zathura_db_init(const char* path); + +void zathura_db_free(zathura_database_t* db); + +bool zathura_db_add_bookmark(zathura_database_t* db, const char* file, zathura_bookmark_t* bookmark); + +bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char* id); + +girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char* file); + +#endif // DATABASE_H diff --git a/zathura.c b/zathura.c index dabbdff..43fd50a 100644 --- a/zathura.c +++ b/zathura.c @@ -7,6 +7,7 @@ #include "bookmarks.h" #include "callbacks.h" #include "config.h" +#include "database.h" #include "document.h" #include "shortcuts.h" #include "zathura.h" @@ -190,6 +191,14 @@ zathura_init(int argc, char* argv[]) free(string_value); } + /* database */ + char* database_path = g_build_filename(zathura->config.data_dir, "bookmarks.sqlite", NULL); + zathura->database = zathura_db_init(database_path); + if (zathura->database == NULL) { + girara_error("Unable to inizialize database. Bookmarks won't be available."); + } + g_free(database_path); + /* bookmarks */ zathura->bookmarks.bookmarks = girara_list_new(); girara_list_set_free_function(zathura->bookmarks.bookmarks, (girara_free_function_t) zathura_bookmark_free); @@ -215,6 +224,8 @@ error_free: } girara_session_destroy(zathura->ui.session); + girara_list_free(zathura->bookmarks.bookmarks); + zathura_db_free(zathura->database); error_out: @@ -239,6 +250,9 @@ zathura_free(zathura_t* zathura) /* bookmarks */ girara_list_free(zathura->bookmarks.bookmarks); + /* database */ + zathura_db_free(zathura->database); + /* free print settings */ g_object_unref(zathura->print.settings); g_object_unref(zathura->print.page_setup); diff --git a/zathura.h b/zathura.h index f654fb0..d81bfc1 100644 --- a/zathura.h +++ b/zathura.h @@ -20,6 +20,10 @@ struct zathura_page_s; typedef struct zathura_document_s zathura_document_t; typedef struct zathura_page_s zathura_page_t; +/* forward declaration for types form database.h */ +struct zathura_database_s; +typedef struct zathura_database_s zathura_database_t; + /* forward declaration for types from render.h */ struct render_thread_s; typedef struct render_thread_s render_thread_t; @@ -91,6 +95,7 @@ typedef struct zathura_s } bookmarks; zathura_document_t* document; /**> The current document */ + zathura_database_t* database; /**> The database */ } zathura_t; /** From 7b3d31a3e5bef533723fd7f31c4c8cd8e930a827 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 3 Sep 2011 13:40:28 +0200 Subject: [PATCH 187/197] implement cmd_bookmark_remove --- bookmarks.c | 34 ++++++++++++++++++++++++++-------- bookmarks.h | 3 ++- commands.c | 48 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 64 insertions(+), 21 deletions(-) diff --git a/bookmarks.c b/bookmarks.c index ec73223..c4c660c 100644 --- a/bookmarks.c +++ b/bookmarks.c @@ -3,11 +3,12 @@ #include #include "bookmarks.h" #include "database.h" +#include "document.h" zathura_bookmark_t* zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page) { - g_return_val_if_fail(zathura && zathura->bookmarks.bookmarks, NULL); + g_return_val_if_fail(zathura && zathura->document && zathura->bookmarks.bookmarks, NULL); g_return_val_if_fail(id, NULL); GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) @@ -21,22 +22,38 @@ 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)) { + girara_warning("Failed to add bookmark to database."); + } + } return bookmark; } -void zathura_bookmark_remove(zathura_t* zathura, const gchar* id) +bool +zathura_bookmark_remove(zathura_t* zathura, const gchar* id) { - g_return_if_fail(zathura && zathura->bookmarks.bookmarks); - g_return_if_fail(id); + g_return_val_if_fail(zathura && zathura->document && zathura->bookmarks.bookmarks, false); + g_return_val_if_fail(id, false); zathura_bookmark_t* bookmark = zathura_bookmark_get(zathura, id); - if (bookmark) { - girara_list_remove(zathura->bookmarks.bookmarks, bookmark); + if (!bookmark) { + return false; } + + if (zathura->database) { + if (!zathura_db_remove_bookmark(zathura->database, zathura->document->file_path, bookmark->id)) { + girara_warning("Failed to remove bookmark from database."); + } + } + girara_list_remove(zathura->bookmarks.bookmarks, bookmark); + + return true; } -zathura_bookmark_t* zathura_bookmark_get(zathura_t* zathura, const gchar* id) +zathura_bookmark_t* +zathura_bookmark_get(zathura_t* zathura, const gchar* id) { g_return_val_if_fail(zathura && zathura->bookmarks.bookmarks, NULL); g_return_val_if_fail(id, NULL); @@ -51,7 +68,8 @@ zathura_bookmark_t* zathura_bookmark_get(zathura_t* zathura, const gchar* id) return NULL; } -void zathura_bookmark_free(zathura_bookmark_t* bookmark) +void +zathura_bookmark_free(zathura_bookmark_t* bookmark) { if (!bookmark) { return; diff --git a/bookmarks.h b/bookmarks.h index fc4b8b6..bb0d252 100644 --- a/bookmarks.h +++ b/bookmarks.h @@ -27,8 +27,9 @@ zathura_bookmark_t* zathura_bookmark_add(zathura_t* zathura, const gchar* id, un * Remove a bookmark from the list of bookmarks. * @param zathura The zathura instance. * @param id The bookmark's id. + * @return true on success, false otherwise */ -void zathura_bookmark_remove(zathura_t* zathura, const gchar* id); +bool zathura_bookmark_remove(zathura_t* zathura, const gchar* id); /** * Get bookmark from the list of bookmarks. diff --git a/commands.c b/commands.c index f6fbbc6..be802bd 100644 --- a/commands.c +++ b/commands.c @@ -1,8 +1,11 @@ /* See LICENSE file for license and copyright information */ #include "commands.h" +#include "bookmarks.h" +#include "database.h" #include "zathura.h" #include "print.h" +#include "document.h" bool cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list) @@ -13,6 +16,27 @@ cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list) bool cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + if (zathura->document == NULL) { + girara_notify(session, GIRARA_ERROR, "No document opened."); + return false; + } + + const unsigned int argc = girara_list_size(argument_list); + if (argc != 1) { + girara_notify(session, GIRARA_ERROR, "Invalid number of arguments given."); + return false; + } + + const char* bookmark = girara_list_nth(argument_list, 0); + if (zathura_bookmark_remove(zathura, bookmark)) { + girara_notify(session, GIRARA_INFO, "Removed bookmark: %s", bookmark); + } else { + girara_notify(session, GIRARA_ERROR, "Failed to remove bookmark: %s", bookmark); + } + return true; } @@ -57,20 +81,20 @@ cmd_open(girara_session_t* session, girara_list_t* argument_list) g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; - if (zathura->document) { - document_close(zathura); - } - const int argc = girara_list_size(argument_list); if (argc > 2) { - girara_error("too many arguments"); + girara_notify(session, GIRARA_ERROR, "Too many arguments."); return false; } else if (argc >= 1) { + if (zathura->document) { + document_close(zathura); + } + document_open(zathura, girara_list_nth(argument_list, 0), (argc == 2) ? girara_list_nth(argument_list, 1) : NULL); } else { - girara_error("no arguments"); + girara_notify(session, GIRARA_ERROR, "No arguments given."); return false; } @@ -85,7 +109,7 @@ cmd_print(girara_session_t* session, girara_list_t* argument_list) zathura_t* zathura = session->global.data; if (zathura->document == NULL) { - girara_error("no document as been opened"); + girara_notify(session, GIRARA_ERROR, "No open document."); return false; } @@ -102,7 +126,7 @@ cmd_save(girara_session_t* session, girara_list_t* argument_list) zathura_t* zathura = session->global.data; if (zathura->document == NULL) { - girara_error("no document as been opened"); + girara_notify(session, GIRARA_ERROR, "No open document."); return false; } @@ -110,7 +134,7 @@ cmd_save(girara_session_t* session, girara_list_t* argument_list) document_save(zathura, girara_list_nth(argument_list, 0), false); } else { - girara_error("invalid arguments"); + girara_notify(session, GIRARA_ERROR, "Invalid number of arguments."); return false; } @@ -125,15 +149,15 @@ cmd_savef(girara_session_t* session, girara_list_t* argument_list) zathura_t* zathura = session->global.data; if (zathura->document == NULL) { - girara_error("no document as been opened"); - return false; + girara_notify(session, GIRARA_ERROR, "No open document."); + return false; } if (girara_list_size(argument_list) == 1) { document_save(zathura, girara_list_nth(argument_list, 0), true); } else { - girara_error("invalid arguments"); + girara_notify(session, GIRARA_ERROR, "Invalid number of arguments."); return false; } From 390061c896674fca1af7d16bfadab62a30bde27f Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 3 Sep 2011 13:49:21 +0200 Subject: [PATCH 188/197] document database functions --- database.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/database.h b/database.h index 3430589..ae954f3 100644 --- a/database.h +++ b/database.h @@ -9,14 +9,43 @@ #include "zathura.h" #include "bookmarks.h" +/** + * Initialize database system. + * @param path Path to the database file. + * @return A valid zathura_database_t instance or NULL on failure + */ zathura_database_t* zathura_db_init(const char* path); +/** + * Free database instance. + * @param The database instance to free. + */ void zathura_db_free(zathura_database_t* db); +/** + * Add or update bookmark in the database. + * @param db The database instance + * @param file The file to which the bookmark belongs to. + * @param bookmark The bookmark instance. + * @return true on success, false otherwise + */ bool zathura_db_add_bookmark(zathura_database_t* db, const char* file, zathura_bookmark_t* bookmark); +/** + * Add or update bookmark in the database. + * @param db The database instance + * @param file The file to which the bookmark belongs to. + * @param bookmark The bookmark instance. + * @return true on success, false otherwise + */ bool zathura_db_remove_bookmark(zathura_database_t* db, const char* file, const char* id); +/** + * Loads all bookmarks from the database belonging to a specific file. + * @param db The database instance. + * @param file The file for which the bookmarks should be loaded. + * @return List of zathura_bookmark_t* or NULL on failure. + */ girara_list_t* zathura_db_load_bookmarks(zathura_database_t* db, const char* file); #endif // DATABASE_H From cf3fd3510b73f43fc7b31b3a91fc5b7abda348a2 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 3 Sep 2011 14:21:36 +0200 Subject: [PATCH 189/197] load bookmarks in document_open --- bookmarks.h | 8 -------- zathura.c | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/bookmarks.h b/bookmarks.h index bb0d252..156375a 100644 --- a/bookmarks.h +++ b/bookmarks.h @@ -53,12 +53,4 @@ void zathura_bookmark_free(zathura_bookmark_t* bookmark); */ bool zathura_bookmarks_load(zathura_t* zathura, const gchar* file); -/** - * Save bookmarks for a specific file. - * @param zathura The zathura instance. - * @param file The file. - * @param true on success, false otherwise - */ -bool zathura_bookmarks_save(zathura_t* zathura, const gchar* file); - #endif // BOOKMARKS_H diff --git a/zathura.c b/zathura.c index 43fd50a..37541ad 100644 --- a/zathura.c +++ b/zathura.c @@ -320,6 +320,11 @@ document_open(zathura_t* zathura, const char* path, const char* password) gtk_widget_realize(page->event_box); } + /* bookmarks */ + if (!zathura_bookmarks_load(zathura, zathura->document->file_path)) { + girara_warning("Failed to load bookmarks for %s.\n", zathura->document->file_path); + } + return true; error_free: From 2657ff58ae05f7b551fe4752812071a3089ca99e Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 20 Sep 2011 16:47:49 +0200 Subject: [PATCH 190/197] set NEEDS_DL to 0 if you don't need to link against dl --- Makefile | 4 ++++ config.mk | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 649c8bc..a9d8902 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,10 @@ SOURCE = $(shell find . -iname "*.c") OBJECTS = $(patsubst %.c, %.o, $(SOURCE)) DOBJECTS = $(patsubst %.c, %.do, $(SOURCE)) +ifneq "$(NEEDS_DL)" "0" +LIBS += -ldl +endif + all: options ${PROJECT} options: diff --git a/config.mk b/config.mk index e2e163c..789b5ba 100644 --- a/config.mk +++ b/config.mk @@ -8,6 +8,10 @@ PREFIX ?= /usr MANPREFIX ?= ${PREFIX}/share/man # libs + +# set this to 0 if you don't need to link against dl +NEEDS_DL ?= 1 + GTK_INC ?= $(shell pkg-config --cflags gtk+-2.0) GTK_LIB ?= $(shell pkg-config --libs gtk+-2.0 gthread-2.0) @@ -18,7 +22,7 @@ SQLITE_INC ?= $(shell pkg-config --cflags sqlite3) SQLITE_LIB ?= $(shell pkg-config --libs sqlite3) INCS = ${GIRARA_INC} ${GTK_INC} $(SQLITE_INC) -LIBS = -lc ${GIRARA_LIB} ${GTK_LIB} $(SQLITE_LIB) -lpthread -lm -ldl +LIBS = ${GIRARA_LIB} ${GTK_LIB} $(SQLITE_LIB) -lpthread -lm # flags CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) From 86646affac0aa80d0665bb1a7f5e89d564bbb2f3 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 21 Sep 2011 00:25:30 +0200 Subject: [PATCH 191/197] Prevent segfault when closing zathura --- document.c | 1 - 1 file changed, 1 deletion(-) diff --git a/document.c b/document.c index 55cdef9..d3855bd 100644 --- a/document.c +++ b/document.c @@ -134,7 +134,6 @@ zathura_document_plugins_free(zathura_t* zathura) do { zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); - free(plugin->file_extension); free(plugin); } while (girara_list_iterator_next(iter)); girara_list_iterator_free(iter); From e20f42512877024f62cfd217c4d4090bfd86dc73 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 21 Sep 2011 00:25:41 +0200 Subject: [PATCH 192/197] Some style updates --- callbacks.c | 2 -- document.c | 87 ++++++++++++++++++++++++++--------------------------- zathura.c | 2 ++ 3 files changed, 44 insertions(+), 47 deletions(-) diff --git a/callbacks.c b/callbacks.c index ebac483..d507816 100644 --- a/callbacks.c +++ b/callbacks.c @@ -13,8 +13,6 @@ gboolean cb_destroy(GtkWidget* widget, gpointer data) { - zathura_free(data); - return TRUE; } diff --git a/document.c b/document.c index d3855bd..930f677 100644 --- a/document.c +++ b/document.c @@ -153,7 +153,7 @@ zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t* if (iter) { do { zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); - if (!strcmp(plugin->file_extension, new_plugin->file_extension)) { + if (strcmp(plugin->file_extension, new_plugin->file_extension) == 0) { girara_error("plugin: already registered for filetype %s\n", plugin->file_extension); girara_list_iterator_free(iter); return false; @@ -169,17 +169,17 @@ zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t* zathura_document_t* zathura_document_open(zathura_t* zathura, const char* path, const char* password) { - if (!path) { + if (path == NULL) { goto error_out; } - if (!file_exists(path)) { + if (file_exists(path) == false) { girara_error("File does not exist"); goto error_out; } const char* file_extension = file_get_extension(path); - if (!file_extension) { + if (file_extension == NULL) { girara_error("Could not determine file type"); goto error_out; } @@ -198,16 +198,16 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password zathura_document_t* document = NULL; real_path = malloc(sizeof(char) * path_max); - if (!real_path) { + if (real_path == NULL) { goto error_out; } - if (!realpath(path, real_path)) { + if (realpath(path, real_path) == NULL) { goto error_free; } document = malloc(sizeof(zathura_document_t)); - if (!document) { + if (document == NULL) { goto error_free; } @@ -239,22 +239,22 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password do { zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter); - if (!strcmp(file_extension, plugin->file_extension)) { + if (strcmp(file_extension, plugin->file_extension) == 0) { girara_list_iterator_free(iter); - if (plugin->open_function) { - if (plugin->open_function(document)) { + if (plugin->open_function != NULL) { + if (plugin->open_function(document) == true) { /* update statusbar */ girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, real_path); /* read all pages */ document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*)); - if (!document->pages) { + if (document->pages == NULL) { goto error_free; } for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_t* page = zathura_page_get(document, page_id); - if (!page) { + if (page == NULL) { goto error_free; } @@ -277,9 +277,8 @@ error_free: free(real_path); - if (document && document->pages) { - for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) - { + if (document != NULL && document->pages != NULL) { + for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_free(document->pages[page_id]); } @@ -296,13 +295,12 @@ error_out: bool zathura_document_free(zathura_document_t* document) { - if (!document) { + if (document == NULL) { return false; } /* free pages */ - for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) - { + for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_free(document->pages[page_id]); document->pages[page_id] = NULL; } @@ -310,10 +308,10 @@ zathura_document_free(zathura_document_t* document) free(document->pages); /* free document */ - if (!document->functions.document_free) { + if (document->functions.document_free == NULL) { girara_error("%s not implemented", __FUNCTION__); - if (document->file_path) { + if (document->file_path != NULL) { free(document->file_path); } @@ -323,7 +321,7 @@ zathura_document_free(zathura_document_t* document) bool r = document->functions.document_free(document); - if (document->file_path) { + if (document->file_path != NULL) { free(document->file_path); } @@ -335,11 +333,11 @@ zathura_document_free(zathura_document_t* document) bool zathura_document_save_as(zathura_document_t* document, const char* path) { - if (!document || !path) { + if (document == NULL || path == NULL) { return false; } - if (!document->functions.document_save_as) { + if (document->functions.document_save_as == NULL) { girara_error("%s not implemented", __FUNCTION__); return false; } @@ -350,11 +348,11 @@ zathura_document_save_as(zathura_document_t* document, const char* path) girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document) { - if (!document) { + if (document == NULL) { return NULL; } - if (!document->functions.document_index_generate) { + if (document->functions.document_index_generate == NULL) { girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -365,11 +363,11 @@ zathura_document_index_generate(zathura_document_t* document) zathura_list_t* zathura_document_attachments_get(zathura_document_t* document) { - if (!document) { + if (document == NULL) { return NULL; } - if (!document->functions.document_attachments_get) { + if (document->functions.document_attachments_get == NULL) { girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -386,18 +384,18 @@ zathura_document_attachments_free(zathura_list_t* list) zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id) { - if (!document) { + if (document == NULL) { return NULL; } - if (!document->functions.page_get) { + if (document->functions.page_get == NULL) { girara_error("%s not implemented", __FUNCTION__); return NULL; } zathura_page_t* page = document->functions.page_get(document, page_id); - if (page) { + if (page != NULL) { page->number = page_id; page->visible = false; page->event_box = gtk_event_box_new(); @@ -418,11 +416,11 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) bool zathura_page_free(zathura_page_t* page) { - if (!page || !page->document) { + if (page == NULL || page->document == NULL) { return false; } - if (!page->document->functions.page_free) { + if (page->document->functions.page_free == NULL) { girara_error("%s not implemented", __FUNCTION__); return false; } @@ -435,11 +433,11 @@ zathura_page_free(zathura_page_t* page) zathura_list_t* zathura_page_search_text(zathura_page_t* page, const char* text) { - if (!page || !page->document || !text) { + if (page == NULL || page->document == NULL || text == NULL) { return NULL; } - if (!page->document->functions.page_search_text) { + if (page->document->functions.page_search_text == NULL) { girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -450,11 +448,11 @@ zathura_page_search_text(zathura_page_t* page, const char* text) zathura_list_t* zathura_page_links_get(zathura_page_t* page) { - if (!page || !page->document) { + if (page == NULL || page->document == NULL) { return NULL; } - if (!page->document->functions.page_links_get) { + if (page->document->functions.page_links_get == NULL) { girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -471,11 +469,11 @@ zathura_page_links_free(zathura_list_t* list) zathura_list_t* zathura_page_form_fields_get(zathura_page_t* page) { - if (!page || !page->document) { + if (page == NULL || page->document == NULL) { return NULL; } - if (!page->document->functions.page_form_fields_get) { + if (page->document->functions.page_form_fields_get == NULL) { girara_error("%s not implemented", __FUNCTION__); return NULL; } @@ -492,29 +490,28 @@ zathura_page_form_fields_free(zathura_list_t* list) zathura_image_buffer_t* zathura_page_render(zathura_page_t* page) { - if (!page || !page->document) { + if (page == NULL || page->document == NULL) { return NULL; } - if (!page->document->functions.page_render) { + if (page->document->functions.page_render == NULL) { girara_error("%s not implemented", __FUNCTION__); return NULL; } - zathura_image_buffer_t* buffer = page->document->functions.page_render(page); - return buffer; + return page->document->functions.page_render(page); } zathura_index_element_t* zathura_index_element_new(const char* title) { - if (!title) { + if (title == NULL) { return NULL; } zathura_index_element_t* res = g_malloc0(sizeof(zathura_index_element_t)); - if (!res) { + if (res == NULL) { return NULL; } @@ -526,7 +523,7 @@ zathura_index_element_new(const char* title) void zathura_index_element_free(zathura_index_element_t* index) { - if (!index) { + if (index == NULL) { return; } diff --git a/zathura.c b/zathura.c index 37541ad..8347a88 100644 --- a/zathura.c +++ b/zathura.c @@ -480,5 +480,7 @@ int main(int argc, char* argv[]) gtk_main(); gdk_threads_leave(); + zathura_free(zathura); + return 0; } From a6268788c0c7f71d372c13715432c7684c6911ad Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 21 Sep 2011 00:46:03 +0200 Subject: [PATCH 193/197] Resolve warnings caused by -Wextra --- callbacks.c | 4 ++-- commands.c | 16 ++++++++++------ config.mk | 2 +- document.c | 6 +++--- print.c | 6 ++++-- render.c | 3 ++- shortcuts.c | 48 ++++++++++++++++++++++++++++++++---------------- utils.c | 3 ++- zathura.c | 4 ++-- zathura.h | 9 +++++++++ 10 files changed, 67 insertions(+), 34 deletions(-) diff --git a/callbacks.c b/callbacks.c index d507816..aedd9b5 100644 --- a/callbacks.c +++ b/callbacks.c @@ -11,7 +11,7 @@ #include "utils.h" gboolean -cb_destroy(GtkWidget* widget, gpointer data) +cb_destroy(GtkWidget* UNUSED(widget), gpointer UNUSED(data)) { return TRUE; } @@ -78,7 +78,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data) } void -cb_pages_per_row_value_changed(girara_session_t* session, girara_setting_t* setting) +cb_pages_per_row_value_changed(girara_session_t* UNUSED(session), girara_setting_t* setting) { int pages_per_row = setting->value.i; zathura_t* zathura = setting->data; diff --git a/commands.c b/commands.c index be802bd..a8374b8 100644 --- a/commands.c +++ b/commands.c @@ -8,7 +8,8 @@ #include "document.h" bool -cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list) +cmd_bookmark_create(girara_session_t* UNUSED(session), girara_list_t* + UNUSED(argument_list)) { return true; } @@ -41,13 +42,14 @@ cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list) } bool -cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list) +cmd_bookmark_open(girara_session_t* UNUSED(session), girara_list_t* + UNUSED(argument_list)) { return true; } bool -cmd_close(girara_session_t* session, girara_list_t* argument_list) +cmd_close(girara_session_t* session, girara_list_t* UNUSED(argument_list)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -63,13 +65,15 @@ cmd_close(girara_session_t* session, girara_list_t* argument_list) } bool -cmd_info(girara_session_t* session, girara_list_t* argument_list) +cmd_info(girara_session_t* UNUSED(session), girara_list_t* + UNUSED(argument_list)) { return true; } bool -cmd_help(girara_session_t* session, girara_list_t* argument_list) +cmd_help(girara_session_t* UNUSED(session), girara_list_t* + UNUSED(argument_list)) { return true; } @@ -102,7 +106,7 @@ cmd_open(girara_session_t* session, girara_list_t* argument_list) } bool -cmd_print(girara_session_t* session, girara_list_t* argument_list) +cmd_print(girara_session_t* session, girara_list_t* UNUSED(argument_list)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); diff --git a/config.mk b/config.mk index 789b5ba..3363edc 100644 --- a/config.mk +++ b/config.mk @@ -25,7 +25,7 @@ INCS = ${GIRARA_INC} ${GTK_INC} $(SQLITE_INC) LIBS = ${GIRARA_LIB} ${GTK_LIB} $(SQLITE_LIB) -lpthread -lm # flags -CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS) +CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS) # debug DFLAGS = -g diff --git a/document.c b/document.c index 930f677..326e006 100644 --- a/document.c +++ b/document.c @@ -376,7 +376,7 @@ zathura_document_attachments_get(zathura_document_t* document) } bool -zathura_document_attachments_free(zathura_list_t* list) +zathura_document_attachments_free(zathura_list_t* UNUSED(list)) { return false; } @@ -461,7 +461,7 @@ zathura_page_links_get(zathura_page_t* page) } bool -zathura_page_links_free(zathura_list_t* list) +zathura_page_links_free(zathura_list_t* UNUSED(list)) { return false; } @@ -482,7 +482,7 @@ zathura_page_form_fields_get(zathura_page_t* page) } bool -zathura_page_form_fields_free(zathura_list_t* list) +zathura_page_form_fields_free(zathura_list_t* UNUSED(list)) { return false; } diff --git a/print.c b/print.c index 74a0da4..a9dd536 100644 --- a/print.c +++ b/print.c @@ -41,13 +41,15 @@ print(zathura_t* zathura) } void -cb_print_begin(GtkPrintOperation* print_operation, GtkPrintContext* context, zathura_t* zathura) +cb_print_begin(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* + UNUSED(context), zathura_t* UNUSED(zathura)) { } void -cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext* context, gint page_number, zathura_t* zathura) +cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* + context, gint page_number, zathura_t* zathura) { cairo_t* cairo = gtk_print_context_get_cairo_context(context); diff --git a/render.c b/render.c index 1d3912c..e6831e9 100644 --- a/render.c +++ b/render.c @@ -279,7 +279,8 @@ render_all(zathura_t* zathura) } gboolean -page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data) +page_expose_event(GtkWidget* UNUSED(widget), GdkEventExpose* UNUSED(event), + gpointer data) { zathura_page_t* page = data; if (page == NULL) { diff --git a/shortcuts.c b/shortcuts.c index 6512bd8..c650b69 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -11,7 +11,8 @@ #include "utils.h" bool -sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument), + unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); @@ -21,7 +22,8 @@ sc_abort(girara_session_t* session, girara_argument_t* argument, unsigned int t) } bool -sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_adjust_window(girara_session_t* session, girara_argument_t* UNUSED(argument), + unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); @@ -29,7 +31,8 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument, unsigne } bool -sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned + int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); @@ -39,7 +42,8 @@ sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned } bool -sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, + unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); @@ -61,7 +65,8 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsign } bool -sc_follow(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), + unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); @@ -97,7 +102,8 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, unsigned int t) } bool -sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int + UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -120,7 +126,8 @@ sc_navigate(girara_session_t* session, girara_argument_t* argument, unsigned int } bool -sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_recolor(girara_session_t* session, girara_argument_t* UNUSED(argument), + unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -133,7 +140,8 @@ sc_recolor(girara_session_t* session, girara_argument_t* argument, unsigned int } bool -sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument), + unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); @@ -141,7 +149,8 @@ sc_reload(girara_session_t* session, girara_argument_t* argument, unsigned int t } bool -sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_rotate(girara_session_t* session, girara_argument_t* UNUSED(argument), + unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -158,7 +167,8 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument, unsigned int t } bool -sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int + UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -218,7 +228,8 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t } bool -sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int + UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -230,7 +241,8 @@ sc_search(girara_session_t* session, girara_argument_t* argument, unsigned int t } bool -sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_navigate_index(girara_session_t* session, girara_argument_t* argument, + unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -242,7 +254,8 @@ sc_navigate_index(girara_session_t* session, girara_argument_t* argument, unsign } bool -sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_toggle_index(girara_session_t* session, girara_argument_t* argument, unsigned + int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -332,7 +345,8 @@ error_ret: } bool -sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* + UNUSED(argument), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); @@ -350,7 +364,8 @@ sc_toggle_fullscreen(girara_session_t* session, girara_argument_t* argument, uns } bool -sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_quit(girara_session_t* session, girara_argument_t* UNUSED(argument), unsigned + int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); @@ -365,7 +380,8 @@ sc_quit(girara_session_t* session, girara_argument_t* argument, unsigned int t) } bool -sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int t) +sc_zoom(girara_session_t* session, girara_argument_t* argument, unsigned int + UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); diff --git a/utils.c b/utils.c index 40e5412..45bd735 100644 --- a/utils.c +++ b/utils.c @@ -154,7 +154,8 @@ execute_command(char* const argv[], char** output) } void -document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_t* tree) +document_index_build(GtkTreeModel* UNUSED(model), GtkTreeIter* UNUSED(parent), + girara_tree_node_t* UNUSED(tree)) { /*girara_list_t* list = girara_node_get_children(tree);*/ /*girara_list_iterator_t* it = girara_list_iterator(list);*/ diff --git a/zathura.c b/zathura.c index 8347a88..583f478 100644 --- a/zathura.c +++ b/zathura.c @@ -36,7 +36,7 @@ zathura_init(int argc, char* argv[]) { "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" }, { "data-dir", 'd', 0, G_OPTION_ARG_FILENAME, &data_dir, "Path to the data directory", "path" }, { "plugins-dir", 'p', 0, G_OPTION_ARG_STRING, &plugin_path, "Path to the directories containing plugins", "path" }, - { NULL } + { NULL, '\0', 0, 0, NULL, NULL, NULL } }; GOptionContext* context = g_option_context_new(" [file] [password]"); @@ -315,7 +315,7 @@ document_open(zathura_t* zathura, const char* path, const char* password) } /* create blank pages */ - for (int page_id = 0; page_id < document->number_of_pages; page_id++) { + for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { zathura_page_t* page = document->pages[page_id]; gtk_widget_realize(page->event_box); } diff --git a/zathura.h b/zathura.h index d81bfc1..d3583ec 100644 --- a/zathura.h +++ b/zathura.h @@ -6,6 +6,15 @@ #include #include +#ifdef UNUSED +#elif defined(__GNUC__) +# define UNUSED(x) UNUSED_ ## x __attribute__((unused)) +#elif defined(__LCINT__) +# define UNUSED(x) /*@unused@*/ x +#else +# define UNUSED(x) x +#endif + 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, From 2b4f5d1823944313042859f9e0c542c3ab7439ee Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Wed, 21 Sep 2011 11:14:21 +0400 Subject: [PATCH 194/197] Use girara's focus_inputbar function zathura's focus_inputbar function is a duplicate of girara's one. This patch removes it. Signed-off-by: Pavel Borzenkov Signed-off-by: Sebastian Ramacher --- config.c | 13 ++++++------- shortcuts.c | 23 ----------------------- shortcuts.h | 10 ---------- 3 files changed, 6 insertions(+), 40 deletions(-) diff --git a/config.c b/config.c index d967e0c..b54aea8 100644 --- a/config.c +++ b/config.c @@ -52,12 +52,12 @@ config_load_default(zathura_t* zathura) 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, sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(gsession, GDK_SHIFT_MASK, GDK_slash, NULL, sc_focus_inputbar, NORMAL, 0, &("/")); - girara_shortcut_add(gsession, 0, GDK_question, NULL, sc_focus_inputbar, NORMAL, 0, &("?")); - girara_shortcut_add(gsession, 0, GDK_colon, NULL, sc_focus_inputbar, NORMAL, 0, &(":")); - girara_shortcut_add(gsession, 0, GDK_o, NULL, sc_focus_inputbar, NORMAL, 0, &(":open ")); - girara_shortcut_add(gsession, 0, GDK_O, NULL, sc_focus_inputbar, NORMAL, APPEND_FILEPATH, &(":open ")); + 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 | FULLSCREEN, TOP, NULL); girara_shortcut_add(gsession, 0, 0, "G", sc_goto, NORMAL | FULLSCREEN, BOTTOM, NULL); @@ -122,7 +122,6 @@ config_load_default(zathura_t* zathura) girara_shortcut_mapping_add(gsession, "abort", sc_abort); girara_shortcut_mapping_add(gsession, "adjust_window", sc_adjust_window); girara_shortcut_mapping_add(gsession, "change_mode", sc_change_mode); - girara_shortcut_mapping_add(gsession, "focus_inputbar", sc_focus_inputbar); 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); diff --git a/shortcuts.c b/shortcuts.c index c650b69..9aed074 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -41,29 +41,6 @@ sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned return false; } -bool -sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, - unsigned int UNUSED(t)) -{ - g_return_val_if_fail(session != NULL, false); - - if (!(gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)))) { - gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); - } - - if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.notification_area))) { - gtk_widget_hide(GTK_WIDGET(session->gtk.notification_area)); - } - - if (argument->data) { - gtk_entry_set_text(session->gtk.inputbar, (char*) argument->data); - gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar)); - gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar), -1); - } - - return false; -} - bool sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), unsigned int UNUSED(t)) diff --git a/shortcuts.h b/shortcuts.h index 8c7f7b4..7123b08 100644 --- a/shortcuts.h +++ b/shortcuts.h @@ -35,16 +35,6 @@ bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, un */ bool sc_change_mode(girara_session_t* session, girara_argument_t* argument, unsigned int t); -/** - * Focus the inputbar - * - * @param session The used girara session - * @param argument The used argument - * @param t Number of executions - * @return true if no error occured otherwise false - */ -bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, unsigned int t); - /** * Follow a link * From 9474332d09f504a58b37e07d0903f93c7ab68e96 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Wed, 21 Sep 2011 11:20:14 +0400 Subject: [PATCH 195/197] Add zathura.pc to .gitignore Signed-off-by: Pavel Borzenkov Signed-off-by: Sebastian Ramacher --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b596c2d..ca38e6a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .depend zathura zathura-debug +zathura.pc From 24081171dbd3b619df01c95c5b040983a65b0947 Mon Sep 17 00:00:00 2001 From: Pavel Borzenkov Date: Wed, 21 Sep 2011 11:22:12 +0400 Subject: [PATCH 196/197] Coding style fixes No functional changes. Signed-off-by: Pavel Borzenkov Signed-off-by: Sebastian Ramacher --- commands.c | 22 +++++++++++----------- database-sqlite.c | 9 ++++++--- zathura.h | 14 +++++++------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/commands.c b/commands.c index a8374b8..82ba01e 100644 --- a/commands.c +++ b/commands.c @@ -112,12 +112,12 @@ cmd_print(girara_session_t* session, girara_list_t* UNUSED(argument_list)) g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; - if (zathura->document == NULL) { + if (zathura->document == NULL) { girara_notify(session, GIRARA_ERROR, "No open document."); - return false; - } + return false; + } - print((zathura_t*) session->global.data); + print((zathura_t*) session->global.data); return true; } @@ -129,10 +129,10 @@ cmd_save(girara_session_t* session, girara_list_t* argument_list) g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; - if (zathura->document == NULL) { - girara_notify(session, GIRARA_ERROR, "No open document."); - return false; - } + if (zathura->document == NULL) { + girara_notify(session, GIRARA_ERROR, "No open document."); + return false; + } if (girara_list_size(argument_list) == 1) { document_save(zathura, girara_list_nth(argument_list, 0), false); @@ -152,10 +152,10 @@ cmd_savef(girara_session_t* session, girara_list_t* argument_list) g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; - if (zathura->document == NULL) { - girara_notify(session, GIRARA_ERROR, "No open document."); + if (zathura->document == NULL) { + girara_notify(session, GIRARA_ERROR, "No open document."); return false; - } + } if (girara_list_size(argument_list) == 1) { document_save(zathura, girara_list_nth(argument_list, 0), true); diff --git a/database-sqlite.c b/database-sqlite.c index 33b41e1..0c71893 100644 --- a/database-sqlite.c +++ b/database-sqlite.c @@ -6,12 +6,14 @@ #include "database.h" -struct zathura_database_s { +struct zathura_database_s +{ sqlite3* session; }; zathura_database_t* -zathura_db_init(const char* path) { +zathura_db_init(const char* path) +{ zathura_database_t* db = g_malloc0(sizeof(zathura_database_t)); /* create bookmarks database */ @@ -51,7 +53,8 @@ zathura_db_init(const char* path) { } void -zathura_db_free(zathura_database_t* db) { +zathura_db_free(zathura_database_t* db) +{ if (db == NULL) { return; } diff --git a/zathura.h b/zathura.h index d3583ec..7035542 100644 --- a/zathura.h +++ b/zathura.h @@ -89,13 +89,13 @@ typedef struct zathura_s bool recolor; /**> Recoloring mode switch */ } global; - struct - { - girara_mode_t normal; /**> Normal mode */ - girara_mode_t fullscreen; /**> Fullscreen mode */ - girara_mode_t index; /**> Index mode */ - girara_mode_t insert; /**> Insert mode */ - } modes; + struct + { + girara_mode_t normal; /**> Normal mode */ + girara_mode_t fullscreen; /**> Fullscreen mode */ + girara_mode_t index; /**> Index mode */ + girara_mode_t insert; /**> Insert mode */ + } modes; struct { From e47ff9ad473c04a1486bc558ace8778f15288da9 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 21 Sep 2011 09:46:54 +0200 Subject: [PATCH 197/197] Resolve GLib-Gobject-CRITICAL warnings --- zathura.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/zathura.c b/zathura.c index 583f478..6a8a75b 100644 --- a/zathura.c +++ b/zathura.c @@ -254,8 +254,13 @@ zathura_free(zathura_t* zathura) zathura_db_free(zathura->database); /* free print settings */ - g_object_unref(zathura->print.settings); - g_object_unref(zathura->print.page_setup); + if(zathura->print.settings != NULL) { + g_object_unref(zathura->print.settings); + } + + if (zathura->print.page_setup != NULL) { + g_object_unref(zathura->print.page_setup); + } /* free registered plugins */ zathura_document_plugins_free(zathura);