Commit 8fa192fd authored by Sebastian Ramacher's avatar Sebastian Ramacher

Imported Upstream version 0.0.8.2

parent 16c8982a
......@@ -13,6 +13,7 @@ all: options ${PROJECT}
options:
@echo ${PROJECT} build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "LIBS = ${LIBS}"
@echo "DFLAGS = ${DFLAGS}"
@echo "CC = ${CC}"
......@@ -69,7 +70,7 @@ dist: clean
@rm -rf ${PROJECT}-${VERSION}
install: all
@echo installing executeable file
@echo installing executable file
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f ${PROJECT} ${DESTDIR}${PREFIX}/bin
@chmod 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin/${PROJECT}
......@@ -79,7 +80,7 @@ install: all
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
uninstall:
@echo removing executeable file
@echo removing executable file
@rm -f ${DESTDIR}${MANPREFIX}/bin/${PROJECT}
@echo removing manual page
@rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
......@@ -13,11 +13,18 @@ int n_completion_items = 15;
static const char FORMAT_COMMAND[] = "<b>%s</b>";
static const char FORMAT_DESCRIPTION[] = "<i>%s</i>";
/* 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";
char* zathura_dir = "~/.config/zathura";
static const char CONFIG_DIR[] = "~/.config/zathura";
static const char DATA_DIR[] = "~/.local/share/zathura";
/* bookmarks */
static const char BM_PAGE_ENTRY[] = "page";
......@@ -59,6 +66,7 @@ char* uri_command = "firefox %s"; /* uri */
/* additional settings */
gboolean show_scrollbars = FALSE;
gboolean scroll_wrap = TRUE;
int adjust_open = ADJUST_BESTFIT;
#define SELECTION_STYLE POPPLER_SELECTION_GLYPH
#define GOTO_MODE GOTO_LABELS /* GOTO_DEFAULT, GOTO_LABELS, GOTO_OFFSET */
......@@ -97,6 +105,7 @@ Shortcut shortcuts[] = {
{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 } },
......@@ -131,12 +140,15 @@ Shortcut shortcuts[] = {
{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_O, sc_switch_goto_mode, NORMAL, {0} },
{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 */
......@@ -209,7 +221,7 @@ SpecialCommand special_commands[] = {
/* settings */
Setting settings[] = {
/* name, variable, type, render, re-init, description */
{"adjust_open", &(adjust_open), 'i', FALSE, FALSE, "Command to open URIs"},
{"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"},
......@@ -237,12 +249,13 @@ Setting settings[] = {
{"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, "Show scrollbars"},
{"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"},
......
# See LICENSE file for license and copyright information
# zathura make config
VERSION = 0.0.8.1
VERSION = 0.0.8.2
# paths
PREFIX ?= /usr
......@@ -12,16 +12,19 @@ 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
LIBS = -lc ${GTK_LIB} -lpthread -lm
# flags
# compiler flags
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length $(INCS)
# debug
# debug flags
DFLAGS = -g
# linker flags
LDFLAGS ?=
# compiler
CC ?= gcc
# strip
SFLAGS = -s
SFLAGS ?= -s
......@@ -5,18 +5,24 @@ zathura \- a PDF viewer
.B zathura
.RB [-e\ xid]
.RB [-c\ path]
.RB [-d\ path]
.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 OPTIONS
.TP
.B -e xid
Reparents to window specified by xid.
.B -c path
Path to the config directory
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
......@@ -93,7 +99,7 @@ Reload the document
Change goto mode (L: search labels, D: default, O: manual offset)
.TP
.B ^i
Invert the colors of the page
Recolors the page
.TP
.B i
Change to insert mode
......
/* See LICENSE file for license and copyright information */
#define _BSD_SOURCE || _XOPEN_SOURCE >= 500
#define _BSD_SOURCE
#define _XOPEN_SOURCE 500
#include <regex.h>
#include <limits.h>
......@@ -13,12 +14,19 @@
#include <poppler/glib/poppler.h>
#include <cairo.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
/* macros */
#define LENGTH(x) sizeof(x)/sizeof((x)[0])
#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,
......@@ -27,7 +35,7 @@ enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT,
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 };
DELETE_TO_LINE_START, APPEND_FILEPATH };
/* define modes */
#define ALL (1 << 0)
......@@ -328,38 +336,53 @@ struct
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 init_directories();
void init_keylist();
void init_settings();
void init_zathura();
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 enter_password(void);
void highlight_result(int, PopplerRectangle*);
void draw(int);
void eval_marker(int);
void notify(int, char*);
void notify(int, const char*);
gboolean open_file(char*, char*);
gboolean open_stdin(gchar*);
void open_uri(char*);
void out_of_memory();
void update_status();
void out_of_memory(void) NORETURN;
void update_status(void);
void read_configuration_file(const char*);
void read_configuration();
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);
char* fix_path(const char*);
gchar* fix_path(const gchar*);
gchar* path_from_env(const gchar*);
gchar* get_home_dir(void);
Completion* completion_init();
Completion* completion_init(void);
CompletionGroup* completion_group_create(char*);
void completion_add_group(Completion*, CompletionGroup*);
void completion_free(Completion*);
......@@ -450,7 +473,7 @@ gboolean cb_watch_file(GFileMonitor*, GFile*, GFile*, GFileMonitorEvent, gpointe
/* function implementation */
void
init_look()
init_look(void)
{
/* parse */
gdk_color_parse(default_fgcolor, &(Zathura.Style.default_fg));
......@@ -473,8 +496,14 @@ init_look()
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));
pango_font_description_free(Zathura.Style.font);
Zathura.Style.font = pango_font_description_from_string(font);
/* 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));
......@@ -513,28 +542,76 @@ init_look()
gtk_widget_hide(GTK_WIDGET(Zathura.UI.statusbar));
}
char*
fix_path(const char* path)
gchar*
fix_path(const gchar* path)
{
if (!path)
return NULL;
if (path[0] == '~')
return g_build_filename(g_get_home_dir(), path + 1, NULL);
{
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()
init_directories(void)
{
/* create zathura directory */
gchar *base_directory = fix_path(zathura_dir);
g_mkdir_with_parents(base_directory, 0771);
/* 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();
char* bookmarks = g_build_filename(base_directory, BOOKMARK_FILE, NULL);
gchar* bookmarks = g_build_filename(Zathura.Config.data_dir, BOOKMARK_FILE, NULL);
if(!g_file_test(bookmarks, G_FILE_TEST_IS_REGULAR))
{
......@@ -551,13 +628,11 @@ init_directories()
g_free(message);
}
Zathura.Bookmarks.file = g_strdup(bookmarks);
g_free(bookmarks);
g_free(base_directory);
Zathura.Bookmarks.file = bookmarks;
}
void
init_keylist()
init_keylist(void)
{
ShortcutList* e = NULL;
ShortcutList* p = NULL;
......@@ -582,7 +657,7 @@ init_keylist()
}
void
init_settings()
init_settings(void)
{
Zathura.State.filename = g_strdup((char*) default_text);
Zathura.Global.adjust_mode = adjust_open;
......@@ -591,14 +666,13 @@ init_settings()
}
void
init_zathura()
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;
......@@ -623,6 +697,8 @@ init_zathura()
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);
......@@ -1012,23 +1088,22 @@ close_file(gboolean keep_monitor)
}
/* reset values */
free(Zathura.PDF.pages);
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("");
if(Zathura.State.filename)
g_free(Zathura.State.filename);
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(Zathura.PDF.file)
free(Zathura.PDF.file);
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;
......@@ -1063,7 +1138,7 @@ close_file(gboolean keep_monitor)
}
void
enter_password()
enter_password(void)
{
/* replace default inputbar handler */
g_signal_handler_disconnect((gpointer) Zathura.UI.inputbar, Zathura.Handler.inputbar_activate);
......@@ -1113,7 +1188,8 @@ highlight_result(int page_id, PopplerRectangle* rectangle)
cairo_destroy(cairo);
}
void notify(int level, char* message)
void
notify(int level, const char* message)
{
switch(level)
{
......@@ -1151,33 +1227,29 @@ open_file(char* path, char* password)
#endif
/* get filename */
char* file = (char*) calloc(sizeof(char), pm);
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] == '~')
{
char* home_path = getenv("HOME");
int file_len = strlen(home_path) + strlen(path) - 1;
if(file)
free(file);
file = malloc(file_len);
if(!file)
out_of_memory();
snprintf(file, file_len, "%s%s", getenv("HOME"), path + 1);
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");
free(file);
g_free(file);
g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock));
return FALSE;
}
......@@ -1193,7 +1265,7 @@ open_file(char* path, char* password)
if (!file_uri)
{
if(file)
free(file);
g_free(file);
char* message = g_strdup_printf("Can not open file: %s", error->message);
notify(ERROR, message);
g_free(message);
......@@ -1231,7 +1303,8 @@ open_file(char* path, char* password)
}
/* save password */
Zathura.PDF.password = password;
g_free(Zathura.PDF.password);
Zathura.PDF.password = password ? g_strdup(password) : NULL;
/* inotify */
if(!Zathura.FileMonitor.monitor)
......@@ -1252,13 +1325,14 @@ open_file(char* path, char* password)
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 = malloc(Zathura.PDF.number_of_pages * sizeof(Page*));
Zathura.PDF.pages = g_malloc(Zathura.PDF.number_of_pages * sizeof(Page*));
if(!Zathura.PDF.pages)
out_of_memory();
......@@ -1341,6 +1415,71 @@ open_file(char* path, char* password)
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);
......@@ -1350,14 +1489,14 @@ void open_uri(char* uri)
g_free(escaped_uri);
}
void out_of_memory()
void out_of_memory(void)
{
printf("error: out of memory\n");
exit(-1);
}
void
update_status()
update_status(void)
{
/* update text */
gtk_label_set_markup((GtkLabel*) Zathura.Global.status_text, Zathura.State.filename);
......@@ -1375,7 +1514,7 @@ update_status()
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", zoom_level, goto_mode, Zathura.State.pages);
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);
......@@ -1417,14 +1556,12 @@ read_configuration_file(const char* rcfile)
}
void
read_configuration()
read_configuration(void)
{
char* configpath = fix_path(zathura_dir);
char* zathurarc = g_build_filename(configpath, ZATHURA_RC, NULL);
char* zathurarc = g_build_filename(Zathura.Config.config_dir, ZATHURA_RC, NULL);
read_configuration_file(GLOBAL_RC);
read_configuration_file(zathurarc);
g_free(zathurarc);
g_free(configpath);
}
void
......@@ -1591,7 +1728,7 @@ switch_view(GtkWidget* widget)
}
Completion*
completion_init()
completion_init(void)
{
Completion *completion = malloc(sizeof(Completion));
if(!completion)
......@@ -1878,7 +2015,15 @@ sc_focus_inputbar(Argument* argument)
if(argument->data)
{
notify(DEFAULT, 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);
}
......@@ -1891,14 +2036,14 @@ sc_follow(Argument* argument)
return;
Page* current_page = Zathura.PDF.pages[Zathura.PDF.page_number];
int number_of_links = 0, link_id = 1;
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((number_of_links = g_list_length(link_list)) <= 0)
if(g_list_length(link_list) <= 0)
return;
GList *links;
......@@ -1947,9 +2092,12 @@ sc_navigate(Argument* argument)
int new_page = Zathura.PDF.page_number;
if(argument->n == NEXT)
new_page = (new_page + number_of_pages + 1) % number_of_pages;
new_page = scroll_wrap ? ((new_page + 1) % number_of_pages) : (new_page + 1);
else if(argument->n == PREVIOUS)
new_page = (new_page + number_of_pages - 1) % number_of_pages;
new_page = scroll_wrap ? ((new_page + number_of_pages - 1) % number_of_pages) : (new_page - 1);
if (!scroll_wrap && (new_page < 0 || new_page >= number_of_pages))
return;
set_page(new_page);
update_status();
......@@ -2023,17 +2171,20 @@ sc_scroll(Argument* argument)
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 new_value = value;
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);
arg.n = BOTTOM;
ss = TRUE;
sc_scroll(&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)
......@@ -2044,7 +2195,9 @@ sc_scroll(Argument* argument)
sc_navigate(&arg);
return;
}
else if(argument->n == FULL_UP)
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);