2009-12-26 14:30:50 +01:00
|
|
|
/* See LICENSE file for license and copyright information */
|
|
|
|
|
2014-10-16 23:56:41 +02:00
|
|
|
#define _DEFAULT_SOURCE
|
2011-10-23 20:18:44 +02:00
|
|
|
#define _XOPEN_SOURCE 700
|
2011-10-21 15:00:22 +02:00
|
|
|
|
2012-10-05 00:51:28 +02:00
|
|
|
#include <errno.h>
|
2010-12-28 09:47:09 +01:00
|
|
|
#include <stdlib.h>
|
2012-02-08 21:34:53 +01:00
|
|
|
#include <math.h>
|
2015-11-07 19:55:25 +01:00
|
|
|
#include <string.h>
|
2010-12-28 09:47:09 +01:00
|
|
|
|
2011-10-23 17:01:15 +02:00
|
|
|
#include <girara/datastructures.h>
|
|
|
|
#include <girara/utils.h>
|
|
|
|
#include <girara/session.h>
|
|
|
|
#include <girara/statusbar.h>
|
|
|
|
#include <girara/settings.h>
|
Hide the inputbar and completion menu before saving the adjustments ratios into a new jump structure
Since we are now saving the adjustments ratios in the jump structures, we need
to take care of the following scenario:
- We do an action that results in a new jump structure being added to the
jumplist while the inputbar is visible (e.g., search, jumping to a
specific page, jumping to a bookmark, or following a link).
- Since we are now storing the adjustments ratios in the jump structures,
all of the above actions would result in the vertical adjustment ratio
being saved while the inputbar and/or the completion menu is visible.
- Now we are exactly on the target of the jump (note that the inputbar and
completion menu now are hidden), so suppose that we want to go back using
^o (assuming that we didn't change the adjustments after jumping), then
the check at sc_jumplist that compares the current adjustments ratios
with that of the current jump (the jump that has just been added and
which we are currently on it's position) would fail, because after the
inputbar (with possibly the completion menu in case of bookmarks) is
activated it is hidden, which results in the vertical adjustment upper
bound to change, which in turn results in the vertical adjustment ratio
returned by zathura_adjustment_get_ratio to become different from what is
stored in the current jump structure, even though we haven't changed the
adjustments at all after the jump. This would always result in taking us
back to the exact position of the jump (which would be slightly different
from the current position) when we press ^o. This can be annoying,
because it would happen, for example, every time we need to go back
quickly after jumping to a link target, a search result, or a bookmark.
So, what this patch does is essentially to make the vertical adjustment ratio
reflecting the current vertical adjustment after a jump, to always be the same
as the one stored in the newly added jump structure, since both are calculated
with zathura_adjustment_get_ratio while the inputbar is _not_ visible, so they
should be the same.
I've elaborated just to make things clear, in case the purpose of the patch
isn't obvious.
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
2013-06-21 14:25:29 +02:00
|
|
|
#include <girara/shortcuts.h>
|
2014-04-26 23:32:38 +02:00
|
|
|
#include <girara/template.h>
|
2011-10-21 15:00:22 +02:00
|
|
|
#include <glib/gstdio.h>
|
2012-03-04 18:35:16 +01:00
|
|
|
#include <glib/gi18n.h>
|
2011-04-18 17:03:08 +02:00
|
|
|
|
2014-04-23 17:27:24 +02:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
#include <glib-unix.h>
|
2016-01-20 04:12:10 +01:00
|
|
|
#include <gio/gunixinputstream.h>
|
2014-04-23 17:27:24 +02:00
|
|
|
#endif
|
|
|
|
|
2011-09-01 15:43:34 +02:00
|
|
|
#include "bookmarks.h"
|
2010-11-12 13:48:18 +01:00
|
|
|
#include "callbacks.h"
|
|
|
|
#include "config.h"
|
2012-03-04 15:56:54 +01:00
|
|
|
#ifdef WITH_SQLITE
|
|
|
|
#include "database-sqlite.h"
|
|
|
|
#endif
|
|
|
|
#include "database-plain.h"
|
2011-03-05 19:46:05 +01:00
|
|
|
#include "document.h"
|
2010-11-12 13:48:18 +01:00
|
|
|
#include "shortcuts.h"
|
2010-11-10 19:18:01 +01:00
|
|
|
#include "zathura.h"
|
2010-12-28 09:47:09 +01:00
|
|
|
#include "utils.h"
|
2012-04-21 04:59:58 +02:00
|
|
|
#include "marks.h"
|
2011-04-18 18:19:41 +02:00
|
|
|
#include "render.h"
|
2012-03-26 14:44:56 +02:00
|
|
|
#include "page.h"
|
2012-03-24 16:15:34 +01:00
|
|
|
#include "page-widget.h"
|
2012-03-27 13:30:04 +02:00
|
|
|
#include "plugin.h"
|
2013-03-23 15:59:27 +01:00
|
|
|
#include "adjustment.h"
|
2014-01-12 22:23:29 +01:00
|
|
|
#include "dbus-interface.h"
|
2017-07-08 12:19:05 +02:00
|
|
|
#include "resources.h"
|
2015-10-07 22:46:47 +02:00
|
|
|
#include "synctex.h"
|
2016-01-20 13:45:46 +01:00
|
|
|
#include "content-type.h"
|
2009-12-26 17:57:46 +01:00
|
|
|
|
2012-10-09 01:12:18 +02:00
|
|
|
typedef struct zathura_document_info_s {
|
2011-04-18 21:22:35 +02:00
|
|
|
zathura_t* zathura;
|
2015-12-06 21:04:24 +01:00
|
|
|
char* path;
|
|
|
|
char* password;
|
2013-03-17 10:56:43 +01:00
|
|
|
int page_number;
|
2015-12-06 21:04:24 +01:00
|
|
|
char* mode;
|
|
|
|
char* synctex;
|
2011-04-18 21:22:35 +02:00
|
|
|
} zathura_document_info_t;
|
|
|
|
|
2012-04-20 23:35:48 +02:00
|
|
|
|
2011-10-21 14:11:37 +02:00
|
|
|
static gboolean document_info_open(gpointer data);
|
2009-12-26 17:57:46 +01:00
|
|
|
|
2014-04-23 17:27:24 +02:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
static gboolean zathura_signal_sigterm(gpointer data);
|
|
|
|
#endif
|
|
|
|
|
2015-12-06 21:04:24 +01:00
|
|
|
static void
|
|
|
|
free_document_info(zathura_document_info_t* document_info)
|
|
|
|
{
|
|
|
|
if (document_info == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(document_info->path);
|
|
|
|
g_free(document_info->password);
|
|
|
|
g_free(document_info->mode);
|
|
|
|
g_free(document_info->synctex);
|
|
|
|
g_free(document_info);
|
|
|
|
}
|
|
|
|
|
2010-11-10 19:18:01 +01:00
|
|
|
/* function implementation */
|
2011-04-18 17:27:49 +02:00
|
|
|
zathura_t*
|
2012-08-05 15:34:10 +02:00
|
|
|
zathura_create(void)
|
2010-06-03 18:05:34 +02:00
|
|
|
{
|
2014-01-19 16:47:08 +01:00
|
|
|
zathura_t* zathura = g_try_malloc0(sizeof(zathura_t));
|
|
|
|
if (zathura == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-23 22:43:08 +02:00
|
|
|
|
2012-07-12 10:37:58 +02:00
|
|
|
/* global settings */
|
2012-12-18 04:09:09 +01:00
|
|
|
zathura->global.search_direction = FORWARD;
|
2012-07-12 10:37:58 +02:00
|
|
|
|
2011-06-23 22:43:08 +02:00
|
|
|
/* plugins */
|
2012-04-01 18:32:16 +02:00
|
|
|
zathura->plugins.manager = zathura_plugin_manager_new();
|
|
|
|
if (zathura->plugins.manager == NULL) {
|
2012-08-05 15:34:10 +02:00
|
|
|
goto error_out;
|
2012-04-01 18:32:16 +02:00
|
|
|
}
|
2011-06-23 22:43:08 +02:00
|
|
|
|
2012-08-05 15:34:10 +02:00
|
|
|
/* UI */
|
2016-01-20 02:21:15 +01:00
|
|
|
zathura->ui.session = girara_session_create();
|
|
|
|
if (zathura->ui.session == NULL) {
|
2012-08-05 15:34:10 +02:00
|
|
|
goto error_out;
|
2011-04-19 14:46:08 +02:00
|
|
|
}
|
|
|
|
|
2014-04-23 17:27:24 +02:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
/* signal handler */
|
|
|
|
zathura->signals.sigterm = g_unix_signal_add(SIGTERM, zathura_signal_sigterm, zathura);
|
|
|
|
#endif
|
|
|
|
|
2016-01-20 13:45:46 +01:00
|
|
|
/* MIME type detection */
|
|
|
|
zathura->content_type_context = zathura_content_type_new();
|
|
|
|
|
2012-08-05 15:34:10 +02:00
|
|
|
zathura->ui.session->global.data = zathura;
|
|
|
|
|
|
|
|
return zathura;
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
|
|
|
|
zathura_free(zathura);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-04-19 14:46:08 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
static void
|
|
|
|
create_directories(zathura_t* zathura)
|
2012-08-05 15:34:10 +02:00
|
|
|
{
|
2016-11-06 18:23:25 +01:00
|
|
|
static const unsigned int mode = 0700;
|
2012-07-13 15:39:16 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
if (g_mkdir_with_parents(zathura->config.config_dir, mode) == -1) {
|
|
|
|
girara_error("Could not create '%s': %s", zathura->config.config_dir,
|
|
|
|
strerror(errno));
|
2012-10-05 00:51:28 +02:00
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
if (g_mkdir_with_parents(zathura->config.data_dir, mode) == -1) {
|
|
|
|
girara_error("Could not create '%s': %s", zathura->config.data_dir,
|
|
|
|
strerror(errno));
|
2012-10-05 00:51:28 +02:00
|
|
|
}
|
2016-01-20 02:43:20 +01:00
|
|
|
}
|
2011-10-03 17:19:55 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
static bool
|
|
|
|
init_ui(zathura_t* zathura)
|
|
|
|
{
|
2011-12-13 19:59:59 +01:00
|
|
|
if (girara_session_init(zathura->ui.session, "zathura") == false) {
|
2016-01-20 02:43:20 +01:00
|
|
|
return false;
|
2011-04-25 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* girara events */
|
2012-05-01 19:09:33 +02:00
|
|
|
zathura->ui.session->events.buffer_changed = cb_buffer_changed;
|
|
|
|
zathura->ui.session->events.unknown_command = cb_unknown_command;
|
2011-04-25 17:41:45 +02:00
|
|
|
|
2013-10-22 21:24:26 +02:00
|
|
|
/* zathura signals */
|
2016-01-20 02:43:20 +01:00
|
|
|
zathura->signals.refresh_view = g_signal_new(
|
|
|
|
"refresh-view", GTK_TYPE_WIDGET, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
|
|
|
|
g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_POINTER);
|
2013-10-22 21:24:26 +02:00
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "refresh-view",
|
|
|
|
G_CALLBACK(cb_refresh_view), zathura);
|
|
|
|
|
2010-12-29 11:46:13 +01:00
|
|
|
/* page view */
|
2012-08-05 02:30:03 +02:00
|
|
|
zathura->ui.page_widget = gtk_grid_new();
|
2012-08-05 15:56:35 +02:00
|
|
|
gtk_grid_set_row_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE);
|
|
|
|
gtk_grid_set_column_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE);
|
2012-02-12 16:35:33 +01:00
|
|
|
if (zathura->ui.page_widget == NULL) {
|
2016-01-20 02:43:20 +01:00
|
|
|
return false;
|
2010-12-29 11:46:13 +01:00
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "size-allocate",
|
|
|
|
G_CALLBACK(cb_view_resized), zathura);
|
2012-02-09 01:46:51 +01:00
|
|
|
|
2013-03-23 15:59:27 +01:00
|
|
|
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(
|
2013-10-20 23:57:24 +02:00
|
|
|
GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
2013-03-23 15:59:27 +01:00
|
|
|
|
|
|
|
/* Connect hadjustment signals */
|
|
|
|
g_signal_connect(G_OBJECT(hadjustment), "value-changed",
|
2016-01-20 02:43:20 +01:00
|
|
|
G_CALLBACK(cb_view_hadjustment_value_changed), zathura);
|
2013-03-23 15:59:27 +01:00
|
|
|
g_signal_connect(G_OBJECT(hadjustment), "changed",
|
2016-01-20 02:43:20 +01:00
|
|
|
G_CALLBACK(cb_view_hadjustment_changed), zathura);
|
2013-03-23 15:59:27 +01:00
|
|
|
|
|
|
|
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(
|
2013-10-20 23:57:24 +02:00
|
|
|
GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
2013-03-23 15:59:27 +01:00
|
|
|
|
|
|
|
/* Connect vadjustment signals */
|
|
|
|
g_signal_connect(G_OBJECT(vadjustment), "value-changed",
|
2016-01-20 02:43:20 +01:00
|
|
|
G_CALLBACK(cb_view_vadjustment_value_changed), zathura);
|
2013-03-23 15:59:27 +01:00
|
|
|
g_signal_connect(G_OBJECT(vadjustment), "changed",
|
2016-01-20 02:43:20 +01:00
|
|
|
G_CALLBACK(cb_view_vadjustment_changed), zathura);
|
2011-04-19 21:42:18 +02:00
|
|
|
|
2012-01-13 17:39:46 +01:00
|
|
|
/* page view alignment */
|
2014-09-27 02:07:53 +02:00
|
|
|
gtk_widget_set_halign(zathura->ui.page_widget, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign(zathura->ui.page_widget, GTK_ALIGN_CENTER);
|
2012-01-13 17:39:46 +01:00
|
|
|
|
2014-09-27 02:07:53 +02:00
|
|
|
gtk_widget_set_hexpand_set(zathura->ui.page_widget, TRUE);
|
|
|
|
gtk_widget_set_hexpand(zathura->ui.page_widget, FALSE);
|
|
|
|
gtk_widget_set_vexpand_set(zathura->ui.page_widget, TRUE);
|
|
|
|
gtk_widget_set_vexpand(zathura->ui.page_widget, FALSE);
|
2012-08-05 15:56:35 +02:00
|
|
|
|
2012-02-07 18:30:46 +01:00
|
|
|
gtk_widget_show(zathura->ui.page_widget);
|
2010-12-26 01:52:17 +01:00
|
|
|
|
2010-12-26 11:10:10 +01:00
|
|
|
/* statusbar */
|
2016-01-20 02:43:20 +01:00
|
|
|
zathura->ui.statusbar.file =
|
|
|
|
girara_statusbar_item_add(zathura->ui.session, TRUE, TRUE, TRUE, NULL);
|
2011-04-18 17:27:49 +02:00
|
|
|
if (zathura->ui.statusbar.file == NULL) {
|
2016-01-20 02:43:20 +01:00
|
|
|
return false;
|
2010-11-13 12:40:48 +01:00
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
zathura->ui.statusbar.buffer =
|
|
|
|
girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL);
|
2011-04-18 17:27:49 +02:00
|
|
|
if (zathura->ui.statusbar.buffer == NULL) {
|
2016-01-20 02:43:20 +01:00
|
|
|
return false;
|
2010-11-18 21:22:43 +01:00
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
zathura->ui.statusbar.page_number =
|
|
|
|
girara_statusbar_item_add(zathura->ui.session, FALSE, FALSE, FALSE, NULL);
|
2012-02-12 16:35:33 +01:00
|
|
|
if (zathura->ui.statusbar.page_number == NULL) {
|
2016-01-20 02:43:20 +01:00
|
|
|
return false;
|
2010-11-18 21:22:43 +01:00
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
girara_statusbar_item_set_text(zathura->ui.session,
|
|
|
|
zathura->ui.statusbar.file, _("[No name]"));
|
2010-11-18 21:22:43 +01:00
|
|
|
|
2010-11-12 13:48:18 +01:00
|
|
|
/* signals */
|
2016-01-20 02:43:20 +01:00
|
|
|
g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy",
|
|
|
|
G_CALLBACK(cb_destroy), zathura);
|
2010-12-29 11:46:13 +01:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_css(zathura_t* zathura)
|
|
|
|
{
|
|
|
|
GiraraTemplate* csstemplate =
|
|
|
|
girara_session_get_template(zathura->ui.session);
|
|
|
|
|
|
|
|
static const char* index_settings[] = {
|
|
|
|
"index-fg",
|
|
|
|
"index-bg",
|
|
|
|
"index-active-fg",
|
|
|
|
"index-active-bg"
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t s = 0; s < LENGTH(index_settings); ++s) {
|
|
|
|
girara_template_add_variable(csstemplate, index_settings[s]);
|
|
|
|
|
|
|
|
char* tmp_value = NULL;
|
|
|
|
GdkRGBA rgba = {0, 0, 0, 0};
|
|
|
|
girara_setting_get(zathura->ui.session, index_settings[s], &tmp_value);
|
|
|
|
if (tmp_value != NULL) {
|
|
|
|
gdk_rgba_parse(&rgba, tmp_value);
|
|
|
|
g_free(tmp_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* color = gdk_rgba_to_string(&rgba);
|
|
|
|
girara_template_set_variable_value(csstemplate, index_settings[s], color);
|
|
|
|
g_free(color);
|
|
|
|
}
|
|
|
|
|
2017-07-08 12:19:05 +02:00
|
|
|
GResource* css_resource = zathura_resources_get_resource();
|
2017-05-30 23:10:06 +02:00
|
|
|
GBytes* css_data = g_resource_lookup_data(css_resource,
|
|
|
|
"/org/pwmt/zathura/CSS/zathura.css_t",
|
|
|
|
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
|
|
|
|
if (css_data != NULL) {
|
|
|
|
char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate),
|
2017-06-20 21:31:31 +02:00
|
|
|
(const char*) g_bytes_get_data(css_data, NULL));
|
2017-05-30 23:10:06 +02:00
|
|
|
girara_template_set_base(csstemplate, css);
|
|
|
|
g_free(css);
|
|
|
|
g_bytes_unref(css_data);
|
|
|
|
}
|
2016-01-20 02:43:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_database(zathura_t* zathura)
|
|
|
|
{
|
2012-03-04 15:56:54 +01:00
|
|
|
char* database = NULL;
|
|
|
|
girara_setting_get(zathura->ui.session, "database", &database);
|
|
|
|
|
|
|
|
if (g_strcmp0(database, "plain") == 0) {
|
2013-01-15 11:31:35 +01:00
|
|
|
girara_debug("Using plain database backend.");
|
2012-03-04 15:56:54 +01:00
|
|
|
zathura->database = zathura_plaindatabase_new(zathura->config.data_dir);
|
|
|
|
#ifdef WITH_SQLITE
|
|
|
|
} else if (g_strcmp0(database, "sqlite") == 0) {
|
2013-01-15 11:31:35 +01:00
|
|
|
girara_debug("Using sqlite database backend.");
|
2016-01-20 02:43:20 +01:00
|
|
|
char* tmp =
|
|
|
|
g_build_filename(zathura->config.data_dir, "bookmarks.sqlite", NULL);
|
2012-03-04 15:56:54 +01:00
|
|
|
zathura->database = zathura_sqldatabase_new(tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
#endif
|
2014-04-19 19:19:56 +02:00
|
|
|
} else if (g_strcmp0(database, "null") != 0) {
|
2012-03-04 15:56:54 +01:00
|
|
|
girara_error("Database backend '%s' is not supported.", database);
|
|
|
|
}
|
|
|
|
|
2014-04-19 19:19:56 +02:00
|
|
|
if (zathura->database == NULL && g_strcmp0(database, "null") != 0) {
|
2016-01-20 02:43:20 +01:00
|
|
|
girara_error(
|
|
|
|
"Unable to initialize database. Bookmarks won't be available.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g_object_set(G_OBJECT(zathura->ui.session->command_history), "io",
|
|
|
|
zathura->database, NULL);
|
2011-09-02 20:46:16 +02:00
|
|
|
}
|
2014-12-15 03:28:08 +01:00
|
|
|
g_free(database);
|
2016-01-20 02:43:20 +01:00
|
|
|
}
|
2011-09-02 20:46:16 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
static void
|
|
|
|
init_jumplist(zathura_t* zathura)
|
|
|
|
{
|
2013-06-21 14:30:04 +02:00
|
|
|
int jumplist_size = 20;
|
|
|
|
girara_setting_get(zathura->ui.session, "jumplist-size", &jumplist_size);
|
2012-08-17 14:14:57 +02:00
|
|
|
|
2013-06-21 14:30:04 +02:00
|
|
|
zathura->jumplist.max_size = jumplist_size < 0 ? 0 : jumplist_size;
|
2016-01-20 02:43:20 +01:00
|
|
|
zathura->jumplist.list = NULL;
|
|
|
|
zathura->jumplist.size = 0;
|
|
|
|
zathura->jumplist.cur = NULL;
|
|
|
|
}
|
2013-03-26 04:50:22 +01:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
static void
|
|
|
|
init_shortcut_helpers(zathura_t* zathura)
|
|
|
|
{
|
|
|
|
zathura->shortcut.mouse.x = 0;
|
|
|
|
zathura->shortcut.mouse.y = 0;
|
2014-04-26 23:32:38 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
zathura->shortcut.toggle_page_mode.pages = 2;
|
2014-04-26 23:32:38 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
zathura->shortcut.toggle_presentation_mode.pages = 1;
|
|
|
|
zathura->shortcut.toggle_presentation_mode.first_page_column_list = NULL;
|
|
|
|
zathura->shortcut.toggle_presentation_mode.zoom = 1.0;
|
|
|
|
}
|
2014-04-26 23:32:38 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
bool
|
|
|
|
zathura_init(zathura_t* zathura)
|
|
|
|
{
|
|
|
|
if (zathura == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-26 23:32:38 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
/* create zathura (config/data) directory */
|
|
|
|
create_directories(zathura);
|
|
|
|
|
|
|
|
/* load plugins */
|
|
|
|
zathura_plugin_manager_load(zathura->plugins.manager);
|
|
|
|
|
|
|
|
/* configuration */
|
|
|
|
config_load_default(zathura);
|
|
|
|
config_load_files(zathura);
|
|
|
|
|
|
|
|
/* UI */
|
|
|
|
if (!init_ui(zathura)) {
|
|
|
|
goto error_free;
|
2014-04-26 23:32:38 +02:00
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
/* database */
|
|
|
|
init_database(zathura);
|
2014-04-26 23:32:38 +02:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
/* bookmarks */
|
|
|
|
zathura->bookmarks.bookmarks = girara_sorted_list_new2(
|
|
|
|
(girara_compare_function_t)zathura_bookmarks_compare,
|
|
|
|
(girara_free_function_t)zathura_bookmark_free);
|
2015-11-12 23:32:59 +01:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
/* jumplist */
|
|
|
|
init_jumplist(zathura);
|
2015-11-12 23:32:59 +01:00
|
|
|
|
2016-01-20 02:43:20 +01:00
|
|
|
/* CSS for index mode */
|
|
|
|
init_css(zathura);
|
|
|
|
|
|
|
|
/* Shortcut helpers */
|
|
|
|
init_shortcut_helpers(zathura);
|
2015-11-12 23:32:59 +01:00
|
|
|
|
2014-01-11 22:03:36 +01:00
|
|
|
/* Start D-Bus service */
|
2014-01-12 22:23:29 +01:00
|
|
|
bool dbus = true;
|
|
|
|
girara_setting_get(zathura->ui.session, "dbus-service", &dbus);
|
|
|
|
if (dbus == true) {
|
|
|
|
zathura->dbus = zathura_dbus_new(zathura);
|
2014-01-11 22:03:36 +01:00
|
|
|
}
|
|
|
|
|
2012-08-05 15:34:10 +02:00
|
|
|
return true;
|
2010-12-26 01:52:17 +01:00
|
|
|
|
|
|
|
error_free:
|
|
|
|
|
2012-02-12 16:35:33 +01:00
|
|
|
if (zathura->ui.page_widget != NULL) {
|
2012-02-07 18:30:46 +01:00
|
|
|
g_object_unref(zathura->ui.page_widget);
|
2010-12-29 11:46:13 +01:00
|
|
|
}
|
|
|
|
|
2012-08-05 15:34:10 +02:00
|
|
|
return false;
|
2011-04-18 17:27:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_free(zathura_t* zathura)
|
|
|
|
{
|
|
|
|
if (zathura == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-20 20:07:24 +01:00
|
|
|
document_close(zathura, false);
|
2011-10-16 21:11:25 +02:00
|
|
|
|
2016-01-20 13:45:46 +01:00
|
|
|
/* MIME type detection */
|
|
|
|
zathura_content_type_free(zathura->content_type_context);
|
|
|
|
|
2016-01-20 02:21:15 +01:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
if (zathura->signals.sigterm > 0) {
|
|
|
|
g_source_remove(zathura->signals.sigterm);
|
|
|
|
zathura->signals.sigterm = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-11 22:03:36 +01:00
|
|
|
/* stop D-Bus */
|
2017-03-17 17:58:55 +01:00
|
|
|
g_clear_object(&zathura->dbus);
|
2014-01-11 22:03:36 +01:00
|
|
|
|
2011-04-18 17:27:49 +02:00
|
|
|
if (zathura->ui.session != NULL) {
|
|
|
|
girara_session_destroy(zathura->ui.session);
|
|
|
|
}
|
|
|
|
|
2015-11-12 23:32:59 +01:00
|
|
|
/* shortcut */
|
2016-01-20 02:43:20 +01:00
|
|
|
if (zathura->shortcut.toggle_presentation_mode.first_page_column_list != NULL) {
|
|
|
|
g_free(zathura->shortcut.toggle_presentation_mode.first_page_column_list);
|
|
|
|
}
|
2015-11-12 23:32:59 +01:00
|
|
|
|
2011-10-21 15:00:22 +02:00
|
|
|
/* stdin support */
|
|
|
|
if (zathura->stdin_support.file != NULL) {
|
|
|
|
g_unlink(zathura->stdin_support.file);
|
|
|
|
g_free(zathura->stdin_support.file);
|
|
|
|
}
|
|
|
|
|
2011-09-01 15:43:34 +02:00
|
|
|
/* bookmarks */
|
|
|
|
girara_list_free(zathura->bookmarks.bookmarks);
|
|
|
|
|
2011-09-02 20:46:16 +02:00
|
|
|
/* database */
|
2017-03-17 17:58:55 +01:00
|
|
|
g_clear_object(&zathura->database);
|
2011-09-02 20:46:16 +02:00
|
|
|
|
2011-04-29 00:28:19 +02:00
|
|
|
/* free print settings */
|
2017-03-17 17:58:55 +01:00
|
|
|
g_clear_object(&zathura->print.settings);
|
|
|
|
g_clear_object(&zathura->print.page_setup);
|
2011-04-29 00:28:19 +02:00
|
|
|
|
2011-04-18 17:27:49 +02:00
|
|
|
/* free registered plugins */
|
2012-04-01 18:32:16 +02:00
|
|
|
zathura_plugin_manager_free(zathura->plugins.manager);
|
2011-04-19 00:36:56 +02:00
|
|
|
|
|
|
|
/* free config variables */
|
|
|
|
g_free(zathura->config.config_dir);
|
|
|
|
g_free(zathura->config.data_dir);
|
2014-08-15 18:10:38 +02:00
|
|
|
g_free(zathura->config.cache_dir);
|
2011-09-30 12:33:50 +02:00
|
|
|
|
2012-08-17 14:14:57 +02:00
|
|
|
/* free jumplist */
|
|
|
|
if (zathura->jumplist.list != NULL) {
|
|
|
|
girara_list_free(zathura->jumplist.list);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zathura->jumplist.cur != NULL) {
|
|
|
|
girara_list_iterator_free(zathura->jumplist.cur);
|
|
|
|
}
|
|
|
|
|
2011-10-08 23:42:41 +02:00
|
|
|
g_free(zathura);
|
2010-06-03 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2012-08-05 15:34:10 +02:00
|
|
|
void
|
|
|
|
zathura_set_xid(zathura_t* zathura, Window xid)
|
|
|
|
{
|
|
|
|
g_return_if_fail(zathura != NULL);
|
|
|
|
|
|
|
|
zathura->ui.session->gtk.embed = xid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_set_config_dir(zathura_t* zathura, const char* dir)
|
|
|
|
{
|
|
|
|
g_return_if_fail(zathura != NULL);
|
|
|
|
|
|
|
|
if (dir != NULL) {
|
|
|
|
zathura->config.config_dir = g_strdup(dir);
|
|
|
|
} else {
|
|
|
|
gchar* path = girara_get_xdg_path(XDG_CONFIG);
|
|
|
|
zathura->config.config_dir = g_build_filename(path, "zathura", NULL);
|
|
|
|
g_free(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_set_data_dir(zathura_t* zathura, const char* dir)
|
|
|
|
{
|
2014-08-15 18:10:38 +02:00
|
|
|
g_return_if_fail(zathura != NULL);
|
|
|
|
|
2012-08-05 15:34:10 +02:00
|
|
|
if (dir != NULL) {
|
|
|
|
zathura->config.data_dir = g_strdup(dir);
|
|
|
|
} else {
|
|
|
|
gchar* path = girara_get_xdg_path(XDG_DATA);
|
|
|
|
zathura->config.data_dir = g_build_filename(path, "zathura", NULL);
|
|
|
|
g_free(path);
|
|
|
|
}
|
2014-08-15 18:10:38 +02:00
|
|
|
}
|
2012-08-05 15:34:10 +02:00
|
|
|
|
2014-08-15 18:10:38 +02:00
|
|
|
void
|
|
|
|
zathura_set_cache_dir(zathura_t* zathura, const char* dir)
|
|
|
|
{
|
2012-08-05 15:34:10 +02:00
|
|
|
g_return_if_fail(zathura != NULL);
|
2014-08-15 18:10:38 +02:00
|
|
|
|
|
|
|
if (dir != NULL) {
|
|
|
|
zathura->config.cache_dir = g_strdup(dir);
|
|
|
|
} else {
|
|
|
|
gchar* path = girara_get_xdg_path(XDG_CACHE);
|
|
|
|
zathura->config.cache_dir = g_build_filename(path, "zathura", NULL);
|
|
|
|
g_free(path);
|
|
|
|
}
|
2012-08-05 15:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_set_plugin_dir(zathura_t* zathura, const char* dir)
|
|
|
|
{
|
|
|
|
g_return_if_fail(zathura != NULL);
|
|
|
|
g_return_if_fail(zathura->plugins.manager != NULL);
|
|
|
|
|
|
|
|
if (dir != NULL) {
|
|
|
|
girara_list_t* paths = girara_split_path_array(dir);
|
|
|
|
GIRARA_LIST_FOREACH(paths, char*, iter, path)
|
2012-10-09 01:12:18 +02:00
|
|
|
zathura_plugin_manager_add_dir(zathura->plugins.manager, path);
|
2012-08-05 15:34:10 +02:00
|
|
|
GIRARA_LIST_FOREACH_END(paths, char*, iter, path);
|
|
|
|
girara_list_free(paths);
|
|
|
|
} else {
|
|
|
|
#ifdef ZATHURA_PLUGINDIR
|
|
|
|
girara_list_t* paths = girara_split_path_array(ZATHURA_PLUGINDIR);
|
|
|
|
GIRARA_LIST_FOREACH(paths, char*, iter, path)
|
2012-10-09 01:12:18 +02:00
|
|
|
zathura_plugin_manager_add_dir(zathura->plugins.manager, path);
|
2012-08-05 15:34:10 +02:00
|
|
|
GIRARA_LIST_FOREACH_END(paths, char*, iter, path);
|
|
|
|
girara_list_free(paths);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zathura_set_argv(zathura_t* zathura, char** argv)
|
|
|
|
{
|
|
|
|
g_return_if_fail(zathura != NULL);
|
|
|
|
|
|
|
|
zathura->global.arguments = argv;
|
|
|
|
}
|
|
|
|
|
2016-01-20 04:12:10 +01:00
|
|
|
#ifdef G_OS_UNIX
|
2011-10-21 15:00:22 +02:00
|
|
|
static gchar*
|
2015-12-06 19:12:51 +01:00
|
|
|
prepare_document_open_from_stdin(const char* path)
|
2011-10-21 15:00:22 +02:00
|
|
|
{
|
2014-08-08 23:27:43 +02:00
|
|
|
int infileno = -1;
|
|
|
|
if (g_strcmp0(path, "-") == 0) {
|
|
|
|
infileno = fileno(stdin);
|
|
|
|
} else if (g_str_has_prefix(path, "/proc/self/fd/") == true) {
|
|
|
|
char* begin = g_strrstr(path, "/") + 1;
|
|
|
|
gint64 temp = g_ascii_strtoll(begin, NULL, 0);
|
|
|
|
if (temp > INT_MAX || temp < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
infileno = (int) temp;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-20 02:43:56 +01:00
|
|
|
if (infileno == -1) {
|
|
|
|
girara_error("Can not read from file descriptor.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-20 04:12:10 +01:00
|
|
|
GInputStream* input_stream = g_unix_input_stream_new(infileno, false);
|
|
|
|
if (input_stream == NULL) {
|
|
|
|
girara_error("Can not read from file descriptor.");
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GFileIOStream* iostream = NULL;
|
|
|
|
GError* error = NULL;
|
|
|
|
GFile* tmpfile = g_file_new_tmp("zathura.stdin.XXXXXX", &iostream, &error);
|
|
|
|
if (tmpfile == NULL) {
|
2012-02-07 20:05:24 +01:00
|
|
|
if (error != NULL) {
|
|
|
|
girara_error("Can not create temporary file: %s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
}
|
2016-01-20 04:12:10 +01:00
|
|
|
g_object_unref(input_stream);
|
2011-10-21 15:00:22 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-20 04:12:10 +01:00
|
|
|
const ssize_t count = g_output_stream_splice(
|
|
|
|
g_io_stream_get_output_stream(G_IO_STREAM(iostream)), input_stream,
|
|
|
|
G_OUTPUT_STREAM_SPLICE_NONE, NULL, &error);
|
|
|
|
g_object_unref(input_stream);
|
|
|
|
g_object_unref(iostream);
|
|
|
|
if (count == -1) {
|
|
|
|
if (error != NULL) {
|
|
|
|
girara_error("Can not write to temporary file: %s", error->message);
|
|
|
|
g_error_free(error);
|
2011-10-21 15:00:22 +02:00
|
|
|
}
|
2016-01-20 04:12:10 +01:00
|
|
|
g_file_delete(tmpfile, NULL, NULL);
|
|
|
|
g_object_unref(tmpfile);
|
2011-10-21 15:00:22 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-20 04:12:10 +01:00
|
|
|
char* file = g_file_get_path(tmpfile);
|
|
|
|
g_object_unref(tmpfile);
|
|
|
|
|
2011-10-21 15:00:22 +02:00
|
|
|
return file;
|
|
|
|
}
|
2016-01-20 04:12:10 +01:00
|
|
|
#endif
|
2011-10-21 15:00:22 +02:00
|
|
|
|
2015-12-02 22:56:47 +01:00
|
|
|
static gchar*
|
2015-12-06 19:12:51 +01:00
|
|
|
prepare_document_open_from_gfile(GFile* source)
|
2015-12-02 22:56:47 +01:00
|
|
|
{
|
2016-01-20 02:43:20 +01:00
|
|
|
gchar* file = NULL;
|
2015-12-06 19:12:51 +01:00
|
|
|
GFileIOStream* iostream = NULL;
|
2016-01-20 02:43:20 +01:00
|
|
|
GError* error = NULL;
|
2015-12-02 22:56:47 +01:00
|
|
|
|
2016-01-20 04:12:10 +01:00
|
|
|
GFile* tmpfile = g_file_new_tmp("zathura.gio.XXXXXX", &iostream, &error);
|
2015-12-06 20:23:18 +01:00
|
|
|
if (tmpfile == NULL) {
|
2015-12-02 22:56:47 +01:00
|
|
|
if (error != NULL) {
|
|
|
|
girara_error("Can not create temporary file: %s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-20 04:12:10 +01:00
|
|
|
gboolean rc = g_file_copy(source, tmpfile, G_FILE_COPY_OVERWRITE, NULL, NULL,
|
|
|
|
NULL, &error);
|
2015-12-06 20:23:18 +01:00
|
|
|
if (rc == FALSE) {
|
2015-12-02 22:56:47 +01:00
|
|
|
if (error != NULL) {
|
|
|
|
girara_error("Can not copy to temporary file: %s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
}
|
|
|
|
g_object_unref(iostream);
|
|
|
|
g_object_unref(tmpfile);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = g_file_get_path(tmpfile);
|
|
|
|
g_object_unref(iostream);
|
|
|
|
g_object_unref(tmpfile);
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2011-10-21 14:11:37 +02:00
|
|
|
static gboolean
|
2011-04-18 21:22:35 +02:00
|
|
|
document_info_open(gpointer data)
|
|
|
|
{
|
|
|
|
zathura_document_info_t* document_info = data;
|
|
|
|
g_return_val_if_fail(document_info != NULL, FALSE);
|
2015-12-07 01:13:59 +01:00
|
|
|
char* uri = NULL;
|
2011-04-18 21:22:35 +02:00
|
|
|
|
2011-10-21 14:11:37 +02:00
|
|
|
if (document_info->zathura != NULL && document_info->path != NULL) {
|
2011-10-21 15:00:22 +02:00
|
|
|
char* file = NULL;
|
2014-08-08 23:27:43 +02:00
|
|
|
if (g_strcmp0(document_info->path, "-") == 0 ||
|
|
|
|
g_str_has_prefix(document_info->path, "/proc/self/fd/") == true) {
|
2016-01-20 04:12:10 +01:00
|
|
|
#ifdef G_OS_UNIX
|
2015-12-06 19:12:51 +01:00
|
|
|
file = prepare_document_open_from_stdin(document_info->path);
|
2016-01-20 04:12:10 +01:00
|
|
|
#endif
|
2011-10-21 15:00:22 +02:00
|
|
|
if (file == NULL) {
|
|
|
|
girara_notify(document_info->zathura->ui.session, GIRARA_ERROR,
|
2013-11-04 19:57:23 +01:00
|
|
|
_("Could not read file from stdin and write it to a temporary file."));
|
2011-10-23 17:34:10 +02:00
|
|
|
} else {
|
|
|
|
document_info->zathura->stdin_support.file = g_strdup(file);
|
2011-10-21 15:00:22 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-12-06 13:51:49 +01:00
|
|
|
GFile* gf = g_file_new_for_commandline_arg(document_info->path);
|
|
|
|
if (g_file_is_native(gf) == TRUE) {
|
|
|
|
/* file was given as a native path */
|
|
|
|
file = g_file_get_path(gf);
|
2015-12-02 22:56:47 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-12-06 17:38:14 +01:00
|
|
|
/* copy file with GIO */
|
2015-12-07 01:13:59 +01:00
|
|
|
uri = g_file_get_uri(gf);
|
2015-12-06 19:12:51 +01:00
|
|
|
file = prepare_document_open_from_gfile(gf);
|
2015-12-06 17:38:14 +01:00
|
|
|
if (file == NULL) {
|
|
|
|
girara_notify(document_info->zathura->ui.session, GIRARA_ERROR,
|
|
|
|
_("Could not read file from GIO and copy it to a temporary file."));
|
2015-12-02 22:56:47 +01:00
|
|
|
} else {
|
2015-12-06 17:38:14 +01:00
|
|
|
document_info->zathura->stdin_support.file = g_strdup(file);
|
2015-12-02 22:56:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
g_object_unref(gf);
|
2011-10-21 15:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (file != NULL) {
|
2015-10-07 22:46:47 +02:00
|
|
|
if (document_info->synctex != NULL) {
|
2015-12-07 01:13:59 +01:00
|
|
|
document_open_synctex(document_info->zathura, file, uri,
|
2015-10-07 22:46:47 +02:00
|
|
|
document_info->password, document_info->synctex);
|
|
|
|
} else {
|
2015-12-07 01:13:59 +01:00
|
|
|
document_open(document_info->zathura, file, uri, document_info->password,
|
2015-10-07 22:46:47 +02:00
|
|
|
document_info->page_number);
|
|
|
|
}
|
2011-10-21 15:00:22 +02:00
|
|
|
g_free(file);
|
2015-12-07 01:13:59 +01:00
|
|
|
g_free(uri);
|
2014-01-29 20:59:45 +01:00
|
|
|
|
|
|
|
if (document_info->mode != NULL) {
|
|
|
|
if (g_strcmp0(document_info->mode, "presentation") == 0) {
|
|
|
|
sc_toggle_presentation(document_info->zathura->ui.session, NULL, NULL,
|
|
|
|
0);
|
|
|
|
} else if (g_strcmp0(document_info->mode, "fullscreen") == 0) {
|
|
|
|
sc_toggle_fullscreen(document_info->zathura->ui.session, NULL, NULL,
|
|
|
|
0);
|
|
|
|
} else {
|
|
|
|
girara_error("Unknown mode: %s", document_info->mode);
|
|
|
|
}
|
|
|
|
}
|
2011-10-21 15:00:22 +02:00
|
|
|
}
|
2011-04-18 21:22:35 +02:00
|
|
|
}
|
|
|
|
|
2015-12-06 21:04:24 +01:00
|
|
|
free_document_info(document_info);
|
2011-04-18 21:22:35 +02:00
|
|
|
return FALSE;
|
2010-06-03 18:05:34 +02:00
|
|
|
}
|
|
|
|
|
2015-12-07 01:13:59 +01:00
|
|
|
char*
|
|
|
|
get_formatted_filename(zathura_t* zathura, bool statusbar)
|
2015-10-01 23:55:07 +02:00
|
|
|
{
|
|
|
|
bool basename_only = false;
|
2015-12-07 01:13:59 +01:00
|
|
|
const char* file_path = zathura_document_get_uri(zathura->document);
|
2015-12-07 22:27:09 +01:00
|
|
|
if (file_path == NULL) {
|
2015-12-07 01:13:59 +01:00
|
|
|
file_path = zathura_document_get_path(zathura->document);
|
|
|
|
}
|
2015-10-07 20:22:15 +02:00
|
|
|
if (statusbar == true) {
|
2015-10-05 17:37:25 +02:00
|
|
|
girara_setting_get(zathura->ui.session, "statusbar-basename", &basename_only);
|
2015-12-07 01:13:59 +01:00
|
|
|
} else {
|
|
|
|
girara_setting_get(zathura->ui.session, "window-title-basename", &basename_only);
|
2015-10-05 17:37:25 +02:00
|
|
|
}
|
|
|
|
|
2015-10-01 23:55:07 +02:00
|
|
|
if (basename_only == false) {
|
|
|
|
bool home_tilde = false;
|
2015-10-05 17:37:25 +02:00
|
|
|
if (statusbar) {
|
|
|
|
girara_setting_get(zathura->ui.session, "statusbar-home-tilde", &home_tilde);
|
|
|
|
} else {
|
|
|
|
girara_setting_get(zathura->ui.session, "window-title-home-tilde", &home_tilde);
|
|
|
|
}
|
|
|
|
|
2015-10-07 20:22:15 +02:00
|
|
|
const size_t file_path_len = file_path ? strlen(file_path) : 0;
|
2015-10-05 22:49:04 +02:00
|
|
|
|
2015-10-07 20:22:15 +02:00
|
|
|
if (home_tilde == true) {
|
|
|
|
char* home = girara_get_home_directory(NULL);
|
|
|
|
const size_t home_len = home ? strlen(home) : 0;
|
2015-10-01 23:55:07 +02:00
|
|
|
|
2015-10-07 06:31:15 +02:00
|
|
|
if (home_len > 1
|
|
|
|
&& file_path_len >= home_len
|
|
|
|
&& g_str_has_prefix(file_path, home)
|
|
|
|
&& (!file_path[home_len] || file_path[home_len] == '/')) {
|
2015-10-07 20:18:33 +02:00
|
|
|
g_free(home);
|
2015-10-07 20:10:40 +02:00
|
|
|
return g_strdup_printf("~%s", &file_path[home_len]);
|
2015-10-01 23:55:07 +02:00
|
|
|
} else {
|
2015-10-07 20:18:33 +02:00
|
|
|
g_free(home);
|
2015-10-05 22:59:31 +02:00
|
|
|
return g_strdup(file_path);
|
2015-10-01 23:55:07 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-05 22:59:31 +02:00
|
|
|
return g_strdup(file_path);
|
2015-10-01 23:55:07 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-05 22:49:04 +02:00
|
|
|
const char* basename = zathura_document_get_basename(zathura->document);
|
2015-10-05 22:59:31 +02:00
|
|
|
return g_strdup(basename);
|
2015-10-01 23:55:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 22:47:08 +02:00
|
|
|
static gboolean
|
|
|
|
document_open_password_dialog(gpointer data)
|
|
|
|
{
|
|
|
|
zathura_password_dialog_info_t* password_dialog_info = data;
|
|
|
|
|
|
|
|
girara_dialog(password_dialog_info->zathura->ui.session, _("Enter password:"), true, NULL,
|
2016-10-25 13:37:42 +02:00
|
|
|
cb_password_dialog, password_dialog_info);
|
2015-10-15 22:47:08 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-12 22:04:42 +01:00
|
|
|
bool
|
2015-12-07 01:13:59 +01:00
|
|
|
document_open(zathura_t* zathura, const char* path, const char* uri, const char* password,
|
2013-03-17 10:56:43 +01:00
|
|
|
int page_number)
|
2010-12-12 22:04:42 +01:00
|
|
|
{
|
2012-04-03 09:02:45 +02:00
|
|
|
if (zathura == NULL || zathura->plugins.manager == NULL || path == NULL) {
|
2010-12-29 11:46:13 +01:00
|
|
|
goto error_out;
|
2010-12-12 22:04:42 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
zathura_error_t error = ZATHURA_ERROR_OK;
|
2016-01-20 13:45:46 +01:00
|
|
|
zathura_document_t* document = zathura_document_open(zathura, path, uri, password, &error);
|
2010-12-12 22:04:42 +01:00
|
|
|
|
2012-02-12 16:35:33 +01:00
|
|
|
if (document == NULL) {
|
2012-04-03 09:02:45 +02:00
|
|
|
if (error == ZATHURA_ERROR_INVALID_PASSWORD) {
|
2015-10-15 22:47:08 +02:00
|
|
|
girara_debug("Invalid or no password.");
|
2012-04-03 09:02:45 +02:00
|
|
|
zathura_password_dialog_info_t* password_dialog_info = malloc(sizeof(zathura_password_dialog_info_t));
|
|
|
|
if (password_dialog_info != NULL) {
|
|
|
|
password_dialog_info->zathura = zathura;
|
2015-11-23 23:16:14 +01:00
|
|
|
password_dialog_info->path = g_strdup(path);
|
2015-12-07 01:13:59 +01:00
|
|
|
password_dialog_info->uri = g_strdup(uri);
|
2012-04-03 09:02:45 +02:00
|
|
|
|
2015-11-23 23:16:14 +01:00
|
|
|
if (password_dialog_info->path != NULL) {
|
2015-10-15 22:47:08 +02:00
|
|
|
gdk_threads_add_idle(document_open_password_dialog, password_dialog_info);
|
2012-04-03 09:02:45 +02:00
|
|
|
goto error_out;
|
|
|
|
} else {
|
|
|
|
free(password_dialog_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto error_out;
|
|
|
|
}
|
2013-05-28 18:12:15 +02:00
|
|
|
if (error == ZATHURA_ERROR_OK ) {
|
|
|
|
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Unsupported file type. Please install the necessary plugin."));
|
|
|
|
}
|
2010-12-29 11:46:13 +01:00
|
|
|
goto error_out;
|
2010-12-12 22:04:42 +01:00
|
|
|
}
|
2016-02-24 22:57:01 +01:00
|
|
|
|
2012-04-20 21:15:03 +02:00
|
|
|
const char* file_path = zathura_document_get_path(document);
|
|
|
|
unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
|
2012-04-03 09:02:45 +02:00
|
|
|
|
2013-03-11 23:26:14 +01:00
|
|
|
if (number_of_pages == 0) {
|
|
|
|
girara_notify(zathura->ui.session, GIRARA_WARNING,
|
|
|
|
_("Document does not contain any pages"));
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
2016-03-09 16:21:12 +01:00
|
|
|
zathura->document = document;
|
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
/* read history file */
|
2013-12-17 16:26:13 +01:00
|
|
|
zathura_fileinfo_t file_info = {
|
|
|
|
.current_page = 0,
|
|
|
|
.page_offset = 0,
|
|
|
|
.scale = 1,
|
|
|
|
.rotation = 0,
|
|
|
|
.pages_per_row = 0,
|
2015-11-13 00:29:35 +01:00
|
|
|
.first_page_column_list = NULL,
|
2013-12-17 16:26:13 +01:00
|
|
|
.position_x = 0,
|
|
|
|
.position_y = 0
|
|
|
|
};
|
2014-12-15 03:37:41 +01:00
|
|
|
bool known_file = false;
|
|
|
|
if (zathura->database != NULL) {
|
|
|
|
known_file = zathura_db_get_fileinfo(zathura->database, file_path, &file_info);
|
|
|
|
}
|
2012-04-03 09:02:45 +02:00
|
|
|
|
2012-04-22 10:04:46 +02:00
|
|
|
/* set page offset */
|
2012-04-20 21:15:03 +02:00
|
|
|
zathura_document_set_page_offset(document, file_info.page_offset);
|
2012-04-07 16:00:51 +02:00
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
/* check for valid scale value */
|
2014-10-27 17:09:57 +01:00
|
|
|
if (file_info.scale <= DBL_EPSILON) {
|
|
|
|
file_info.scale = 1;
|
|
|
|
}
|
2014-10-27 11:55:21 +01:00
|
|
|
zathura_document_set_scale(document,
|
|
|
|
zathura_correct_scale_value(zathura->ui.session, file_info.scale));
|
2012-04-03 09:02:45 +02:00
|
|
|
|
|
|
|
/* check current page number */
|
2013-03-17 10:56:43 +01:00
|
|
|
/* if it wasn't specified on the command-line, get it from file_info */
|
|
|
|
if (page_number == ZATHURA_PAGE_NUMBER_UNSPECIFIED)
|
|
|
|
page_number = file_info.current_page;
|
|
|
|
if (page_number < 0)
|
|
|
|
page_number += number_of_pages;
|
|
|
|
if ((unsigned)page_number > number_of_pages) {
|
2012-04-03 09:02:45 +02:00
|
|
|
girara_warning("document info: '%s' has an invalid page number", file_path);
|
|
|
|
zathura_document_set_current_page_number(document, 0);
|
2012-04-07 16:00:51 +02:00
|
|
|
} else {
|
2013-03-17 10:56:43 +01:00
|
|
|
zathura_document_set_current_page_number(document, page_number);
|
2012-04-07 16:00:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for valid rotation */
|
2012-04-20 21:15:03 +02:00
|
|
|
if (file_info.rotation % 90 != 0) {
|
2012-04-07 16:00:51 +02:00
|
|
|
girara_warning("document info: '%s' has an invalid rotation", file_path);
|
|
|
|
zathura_document_set_rotation(document, 0);
|
|
|
|
} else {
|
2012-04-20 21:15:03 +02:00
|
|
|
zathura_document_set_rotation(document, file_info.rotation % 360);
|
2012-04-03 09:02:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* jump to first page if setting enabled */
|
|
|
|
bool always_first_page = false;
|
|
|
|
girara_setting_get(zathura->ui.session, "open-first-page", &always_first_page);
|
|
|
|
if (always_first_page == true) {
|
|
|
|
zathura_document_set_current_page_number(document, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply open adjustment */
|
|
|
|
char* adjust_open = "best-fit";
|
2012-05-07 00:32:55 +02:00
|
|
|
if (known_file == false && girara_setting_get(zathura->ui.session, "adjust-open", &(adjust_open)) == true) {
|
2012-04-03 09:02:45 +02:00
|
|
|
if (g_strcmp0(adjust_open, "best-fit") == 0) {
|
|
|
|
zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_BESTFIT);
|
|
|
|
} else if (g_strcmp0(adjust_open, "width") == 0) {
|
|
|
|
zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_WIDTH);
|
|
|
|
} else {
|
|
|
|
zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_NONE);
|
|
|
|
}
|
|
|
|
g_free(adjust_open);
|
2012-05-07 00:32:55 +02:00
|
|
|
} else {
|
|
|
|
zathura_document_set_adjust_mode(document, ZATHURA_ADJUST_NONE);
|
2012-04-03 09:02:45 +02:00
|
|
|
}
|
|
|
|
|
2013-07-07 17:27:25 +02:00
|
|
|
/* initialize bisect state */
|
|
|
|
zathura->bisect.start = 0;
|
|
|
|
zathura->bisect.last_jump = zathura_document_get_current_page_number(document);
|
|
|
|
zathura->bisect.end = number_of_pages - 1;
|
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
/* update statusbar */
|
2015-12-07 01:13:59 +01:00
|
|
|
char* filename = get_formatted_filename(zathura, true);
|
2015-10-05 22:49:04 +02:00
|
|
|
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, filename);
|
|
|
|
g_free(filename);
|
2012-04-03 09:02:45 +02:00
|
|
|
|
2012-02-20 20:07:24 +01:00
|
|
|
/* install file monitor */
|
|
|
|
if (zathura->file_monitor.monitor == NULL) {
|
2016-04-24 18:26:54 +02:00
|
|
|
char* filemonitor_backend = NULL;
|
|
|
|
girara_setting_get(zathura->ui.session, "filemonitor", &filemonitor_backend);
|
|
|
|
zathura_filemonitor_type_t type = ZATHURA_FILEMONITOR_GLIB;
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
if (g_strcmp0(filemonitor_backend, "signal") == 0) {
|
|
|
|
type = ZATHURA_FILEMONITOR_SIGNAL;
|
2012-03-02 20:34:41 +01:00
|
|
|
}
|
2016-04-24 18:26:54 +02:00
|
|
|
#endif
|
2017-05-02 21:57:33 +02:00
|
|
|
g_free(filemonitor_backend);
|
2012-02-20 20:07:24 +01:00
|
|
|
|
2016-04-24 18:26:54 +02:00
|
|
|
zathura->file_monitor.monitor = zathura_filemonitor_new(file_path, type);
|
|
|
|
if (zathura->file_monitor.monitor == NULL) {
|
2012-03-02 20:34:41 +01:00
|
|
|
goto error_free;
|
|
|
|
}
|
2016-04-24 18:26:54 +02:00
|
|
|
g_signal_connect(G_OBJECT(zathura->file_monitor.monitor), "reload-file",
|
|
|
|
G_CALLBACK(cb_file_monitor), zathura->ui.session);
|
2012-02-20 20:07:24 +01:00
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
if (password != NULL) {
|
2012-03-02 20:34:41 +01:00
|
|
|
g_free(zathura->file_monitor.password);
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura->file_monitor.password = g_strdup(password);
|
2012-02-20 20:07:24 +01:00
|
|
|
if (zathura->file_monitor.password == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-21 04:59:58 +02:00
|
|
|
/* create marks list */
|
|
|
|
zathura->global.marks = girara_list_new2((girara_free_function_t) mark_free);
|
|
|
|
if (zathura->global.marks == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:00:04 +02:00
|
|
|
/* page cache size */
|
|
|
|
int cache_size = 0;
|
|
|
|
girara_setting_get(zathura->ui.session, "page-cache-size", &cache_size);
|
|
|
|
if (cache_size <= 0) {
|
|
|
|
girara_warning("page-cache-size is not positive, using %d instead",
|
|
|
|
ZATHURA_PAGE_CACHE_DEFAULT_SIZE);
|
|
|
|
cache_size = ZATHURA_PAGE_CACHE_DEFAULT_SIZE;
|
|
|
|
}
|
|
|
|
|
2013-08-21 18:32:18 +02:00
|
|
|
/* threads */
|
2013-10-18 20:00:04 +02:00
|
|
|
zathura->sync.render_thread = zathura_renderer_new(cache_size);
|
2013-08-21 18:32:18 +02:00
|
|
|
|
|
|
|
if (zathura->sync.render_thread == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
2013-08-30 15:05:00 +02:00
|
|
|
/* set up recolor info in ZathuraRenderer */
|
2016-01-20 02:21:15 +01:00
|
|
|
char* recolor_dark = NULL;
|
2013-08-24 00:07:32 +02:00
|
|
|
char* recolor_light = NULL;
|
|
|
|
girara_setting_get(zathura->ui.session, "recolor-darkcolor", &recolor_dark);
|
|
|
|
girara_setting_get(zathura->ui.session, "recolor-lightcolor", &recolor_light);
|
|
|
|
zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread,
|
|
|
|
recolor_light, recolor_dark);
|
|
|
|
g_free(recolor_dark);
|
|
|
|
g_free(recolor_light);
|
|
|
|
|
2013-08-30 18:55:42 +02:00
|
|
|
bool recolor = false;
|
|
|
|
girara_setting_get(zathura->ui.session, "recolor", &recolor);
|
|
|
|
zathura_renderer_enable_recolor(zathura->sync.render_thread, recolor);
|
|
|
|
girara_setting_get(zathura->ui.session, "recolor-keephue", &recolor);
|
|
|
|
zathura_renderer_enable_recolor_hue(zathura->sync.render_thread, recolor);
|
2014-09-30 19:45:07 +02:00
|
|
|
girara_setting_get(zathura->ui.session, "recolor-reverse-video", &recolor);
|
|
|
|
zathura_renderer_enable_recolor_reverse_video(zathura->sync.render_thread, recolor);
|
2013-08-30 18:55:42 +02:00
|
|
|
|
2013-11-05 02:22:30 +01:00
|
|
|
/* get view port size */
|
|
|
|
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(
|
|
|
|
GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
|
|
|
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(
|
|
|
|
GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
|
|
|
|
2013-11-05 02:29:20 +01:00
|
|
|
const unsigned int view_width = (unsigned int)floor(gtk_adjustment_get_page_size(hadjustment));
|
2013-11-05 02:22:30 +01:00
|
|
|
zathura_document_set_viewport_width(zathura->document, view_width);
|
2013-11-05 02:29:20 +01:00
|
|
|
const unsigned int view_height = (unsigned int)floor(gtk_adjustment_get_page_size(vadjustment));
|
2013-11-05 02:22:30 +01:00
|
|
|
zathura_document_set_viewport_height(zathura->document, view_height);
|
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
/* create blank pages */
|
|
|
|
zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*));
|
|
|
|
if (zathura->pages == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
|
|
|
|
zathura_page_t* page = zathura_document_get_page(document, page_id);
|
|
|
|
if (page == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget* page_widget = zathura_page_widget_new(zathura, page);
|
|
|
|
if (page_widget == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
2014-01-20 02:29:40 +01:00
|
|
|
g_object_ref(page_widget);
|
2012-04-03 09:02:45 +02:00
|
|
|
zathura->pages[page_id] = page_widget;
|
|
|
|
|
2014-09-27 02:07:53 +02:00
|
|
|
gtk_widget_set_halign(page_widget, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign(page_widget, GTK_ALIGN_CENTER);
|
|
|
|
|
2013-08-31 13:12:41 +02:00
|
|
|
g_signal_connect(G_OBJECT(page_widget), "text-selected",
|
|
|
|
G_CALLBACK(cb_page_widget_text_selected), zathura);
|
|
|
|
g_signal_connect(G_OBJECT(page_widget), "image-selected",
|
2013-10-31 14:39:32 +01:00
|
|
|
G_CALLBACK(cb_page_widget_image_selected), zathura);
|
2014-05-24 18:04:59 +02:00
|
|
|
g_signal_connect(G_OBJECT(page_widget), "enter-link",
|
|
|
|
G_CALLBACK(cb_page_widget_link), (gpointer) true);
|
|
|
|
g_signal_connect(G_OBJECT(page_widget), "leave-link",
|
|
|
|
G_CALLBACK(cb_page_widget_link), (gpointer) false);
|
2014-08-22 20:42:33 +02:00
|
|
|
g_signal_connect(G_OBJECT(page_widget), "scaled-button-release",
|
|
|
|
G_CALLBACK(cb_page_widget_scaled_button_release), zathura);
|
2012-04-03 09:02:45 +02:00
|
|
|
}
|
|
|
|
|
2011-03-18 18:40:20 +01:00
|
|
|
/* view mode */
|
2013-10-20 16:07:07 +02:00
|
|
|
unsigned int pages_per_row = 1;
|
2015-11-13 00:29:35 +01:00
|
|
|
char* first_page_column_list = NULL;
|
2013-10-20 16:07:07 +02:00
|
|
|
unsigned int page_padding = 1;
|
|
|
|
|
|
|
|
girara_setting_get(zathura->ui.session, "page-padding", &page_padding);
|
|
|
|
|
2012-04-20 23:35:48 +02:00
|
|
|
if (file_info.pages_per_row > 0) {
|
|
|
|
pages_per_row = file_info.pages_per_row;
|
|
|
|
} else {
|
|
|
|
girara_setting_get(zathura->ui.session, "pages-per-row", &pages_per_row);
|
|
|
|
}
|
2012-04-29 06:26:38 +02:00
|
|
|
|
2015-11-07 19:55:25 +01:00
|
|
|
/* read first_page_column list */
|
2016-06-24 19:46:09 +02:00
|
|
|
if (file_info.first_page_column_list != NULL && *file_info.first_page_column_list != '\0') {
|
2015-11-07 19:55:25 +01:00
|
|
|
first_page_column_list = file_info.first_page_column_list;
|
2015-11-13 00:29:35 +01:00
|
|
|
file_info.first_page_column_list = NULL;
|
2012-06-27 22:34:16 +02:00
|
|
|
} else {
|
2015-11-07 20:12:01 +01:00
|
|
|
girara_setting_get(zathura->ui.session, "first-page-column", &first_page_column_list);
|
2012-06-27 22:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-11-07 20:12:01 +01:00
|
|
|
/* find value for first_page_column */
|
|
|
|
unsigned int first_page_column = find_first_page_column(first_page_column_list, pages_per_row);
|
|
|
|
|
2012-04-29 06:26:38 +02:00
|
|
|
girara_setting_set(zathura->ui.session, "pages-per-row", &pages_per_row);
|
2015-11-07 20:12:01 +01:00
|
|
|
girara_setting_set(zathura->ui.session, "first-page-column", first_page_column_list);
|
2015-11-13 00:29:35 +01:00
|
|
|
g_free(file_info.first_page_column_list);
|
2015-11-07 20:12:01 +01:00
|
|
|
g_free(first_page_column_list);
|
2013-10-20 16:07:07 +02:00
|
|
|
|
|
|
|
page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column);
|
|
|
|
zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column);
|
2010-12-28 09:47:09 +01:00
|
|
|
|
2014-09-27 02:07:53 +02:00
|
|
|
girara_set_view(zathura->ui.session, zathura->ui.page_widget);
|
2010-12-28 09:47:09 +01:00
|
|
|
|
2010-12-12 22:04:42 +01:00
|
|
|
|
2011-09-03 14:21:36 +02:00
|
|
|
/* bookmarks */
|
2014-12-15 03:37:41 +01:00
|
|
|
if (zathura->database != NULL) {
|
|
|
|
if (zathura_bookmarks_load(zathura, file_path) == false) {
|
2015-01-13 02:44:05 +01:00
|
|
|
girara_debug("Failed to load bookmarks.");
|
2014-12-15 03:37:41 +01:00
|
|
|
}
|
2011-09-03 14:21:36 +02:00
|
|
|
|
2014-12-15 03:37:41 +01:00
|
|
|
/* jumplist */
|
|
|
|
if (zathura_jumplist_load(zathura, file_path) == false) {
|
|
|
|
zathura->jumplist.list = girara_list_new2(g_free);
|
|
|
|
}
|
2013-06-21 14:30:04 +02:00
|
|
|
}
|
|
|
|
|
2012-03-16 07:58:55 +01:00
|
|
|
/* update title */
|
2015-12-07 01:13:59 +01:00
|
|
|
char* formatted_filename = get_formatted_filename(zathura, false);
|
2015-10-05 22:49:04 +02:00
|
|
|
girara_set_window_title(zathura->ui.session, formatted_filename);
|
|
|
|
g_free(formatted_filename);
|
2012-03-16 07:58:55 +01:00
|
|
|
|
2013-11-05 02:22:30 +01:00
|
|
|
/* adjust_view */
|
2013-10-24 22:11:52 +02:00
|
|
|
adjust_view(zathura);
|
2013-11-05 02:22:30 +01:00
|
|
|
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
|
|
|
|
/* set widget size */
|
|
|
|
zathura_page_t* page = zathura_document_get_page(document, page_id);
|
|
|
|
unsigned int page_height = 0;
|
|
|
|
unsigned int page_width = 0;
|
|
|
|
|
|
|
|
/* adjust_view calls render_all in some cases and render_all calls
|
|
|
|
* gtk_widget_set_size_request. To be sure that it's really called, do it
|
|
|
|
* here once again. */
|
2013-12-17 16:32:50 +01:00
|
|
|
const double height = zathura_page_get_height(page);
|
|
|
|
const double width = zathura_page_get_width(page);
|
2013-11-05 02:22:30 +01:00
|
|
|
page_calc_height_width(zathura->document, height, width, &page_height, &page_width, true);
|
|
|
|
gtk_widget_set_size_request(zathura->pages[page_id], page_width, page_height);
|
|
|
|
|
|
|
|
/* show widget */
|
|
|
|
gtk_widget_show(zathura->pages[page_id]);
|
|
|
|
}
|
2012-03-25 20:31:19 +02:00
|
|
|
|
2013-12-16 19:42:35 +01:00
|
|
|
/* Set page */
|
2013-10-22 23:11:33 +02:00
|
|
|
page_set(zathura, zathura_document_get_current_page_number(document));
|
2013-12-16 19:42:35 +01:00
|
|
|
|
|
|
|
/* Set position (only if restoring from history file) */
|
2013-12-17 16:27:34 +01:00
|
|
|
if (file_info.current_page == zathura_document_get_current_page_number(document) &&
|
|
|
|
(file_info.position_x != 0 || file_info.position_y != 0)) {
|
|
|
|
position_set(zathura, file_info.position_x, file_info.position_y);
|
2012-04-20 23:35:48 +02:00
|
|
|
}
|
|
|
|
|
2014-09-04 00:42:46 +02:00
|
|
|
update_visible_pages(zathura);
|
|
|
|
|
2010-12-12 22:04:42 +01:00
|
|
|
return true;
|
2010-12-29 11:46:13 +01:00
|
|
|
|
|
|
|
error_free:
|
|
|
|
|
|
|
|
zathura_document_free(document);
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
|
|
|
|
return false;
|
2010-12-12 22:04:42 +01:00
|
|
|
}
|
|
|
|
|
2015-10-07 22:46:47 +02:00
|
|
|
bool
|
2015-12-07 01:13:59 +01:00
|
|
|
document_open_synctex(zathura_t* zathura, const char* path, const char* uri,
|
2015-10-07 22:46:47 +02:00
|
|
|
const char* password, const char* synctex)
|
|
|
|
{
|
2015-12-07 01:13:59 +01:00
|
|
|
bool ret = document_open(zathura, path, password, uri,
|
2015-10-07 22:46:47 +02:00
|
|
|
ZATHURA_PAGE_NUMBER_UNSPECIFIED);
|
|
|
|
if (ret == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (synctex == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int line = 0;
|
|
|
|
int column = 0;
|
|
|
|
char* input_file = NULL;
|
|
|
|
if (synctex_parse_input(synctex, &input_file, &line, &column) == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = synctex_view(zathura, input_file, line, column);
|
|
|
|
g_free(input_file);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-05 15:34:10 +02:00
|
|
|
void
|
2013-03-17 10:56:43 +01:00
|
|
|
document_open_idle(zathura_t* zathura, const char* path, const char* password,
|
2015-10-07 22:46:47 +02:00
|
|
|
int page_number, const char* mode, const char* synctex)
|
2012-08-05 15:34:10 +02:00
|
|
|
{
|
2015-12-06 21:04:24 +01:00
|
|
|
g_return_if_fail(zathura != NULL);
|
|
|
|
g_return_if_fail(path != NULL);
|
2012-08-05 15:34:10 +02:00
|
|
|
|
2014-01-19 16:47:08 +01:00
|
|
|
zathura_document_info_t* document_info = g_try_malloc0(sizeof(zathura_document_info_t));
|
|
|
|
if (document_info == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-05 15:34:10 +02:00
|
|
|
|
2013-03-17 10:56:43 +01:00
|
|
|
document_info->zathura = zathura;
|
2015-12-06 21:04:24 +01:00
|
|
|
document_info->path = g_strdup(path);
|
|
|
|
if (password != NULL) {
|
|
|
|
document_info->password = g_strdup(password);
|
|
|
|
}
|
2013-03-17 10:56:43 +01:00
|
|
|
document_info->page_number = page_number;
|
2015-12-06 21:04:24 +01:00
|
|
|
if (mode != NULL) {
|
|
|
|
document_info->mode = g_strdup(mode);
|
|
|
|
}
|
|
|
|
if (synctex != NULL) {
|
|
|
|
document_info->synctex = g_strdup(synctex);
|
|
|
|
}
|
2012-08-05 15:34:10 +02:00
|
|
|
|
|
|
|
gdk_threads_add_idle(document_info_open, document_info);
|
|
|
|
}
|
|
|
|
|
2011-09-01 11:51:49 +02:00
|
|
|
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);
|
2013-01-17 12:07:53 +01:00
|
|
|
/* use current basename if path points to a directory */
|
|
|
|
if (g_file_test(file_path, G_FILE_TEST_IS_DIR) == TRUE) {
|
|
|
|
char* basename = g_path_get_basename(zathura_document_get_path(zathura->document));
|
|
|
|
char* tmp = file_path;
|
2016-12-20 00:48:42 +01:00
|
|
|
file_path = g_build_filename(file_path, basename, NULL);
|
2013-01-17 12:07:53 +01:00
|
|
|
g_free(tmp);
|
|
|
|
g_free(basename);
|
|
|
|
}
|
|
|
|
|
2012-10-09 01:12:18 +02:00
|
|
|
if ((overwrite == false) && g_file_test(file_path, G_FILE_TEST_EXISTS)) {
|
2011-11-12 18:21:45 +01:00
|
|
|
girara_error("File already exists: %s. Use :write! to overwrite it.", file_path);
|
2011-10-21 15:00:22 +02:00
|
|
|
g_free(file_path);
|
2011-09-01 11:51:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
zathura_error_t error = zathura_document_save_as(zathura->document, file_path);
|
2011-09-01 11:51:49 +02:00
|
|
|
g_free(file_path);
|
2012-03-04 23:54:03 +01:00
|
|
|
|
2012-03-27 13:30:04 +02:00
|
|
|
return (error == ZATHURA_ERROR_OK) ? true : false;
|
2011-09-01 11:51:49 +02:00
|
|
|
}
|
|
|
|
|
2011-07-21 14:39:25 +02:00
|
|
|
static void
|
2014-11-07 14:24:46 +01:00
|
|
|
remove_page_from_table(GtkWidget* page, gpointer UNUSED(permanent))
|
2011-07-21 14:39:25 +02:00
|
|
|
{
|
2012-02-13 12:43:22 +01:00
|
|
|
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(page)), page);
|
2011-07-21 14:39:25 +02:00
|
|
|
}
|
|
|
|
|
2016-02-24 22:57:01 +01:00
|
|
|
static void
|
|
|
|
save_fileinfo_to_db(zathura_t* zathura)
|
|
|
|
{
|
|
|
|
const char* path = zathura_document_get_path(zathura->document);
|
|
|
|
|
|
|
|
zathura_fileinfo_t file_info = {
|
|
|
|
.current_page = zathura_document_get_current_page_number(zathura->document),
|
|
|
|
.page_offset = zathura_document_get_page_offset(zathura->document),
|
|
|
|
.scale = zathura_document_get_scale(zathura->document),
|
|
|
|
.rotation = zathura_document_get_rotation(zathura->document),
|
|
|
|
.pages_per_row = 1,
|
|
|
|
.first_page_column_list = "1:2",
|
|
|
|
.position_x = zathura_document_get_position_x(zathura->document),
|
|
|
|
.position_y = zathura_document_get_position_y(zathura->document)
|
|
|
|
};
|
|
|
|
|
|
|
|
girara_setting_get(zathura->ui.session, "pages-per-row",
|
|
|
|
&(file_info.pages_per_row));
|
|
|
|
girara_setting_get(zathura->ui.session, "first-page-column",
|
|
|
|
&(file_info.first_page_column_list));
|
|
|
|
|
|
|
|
/* save file info */
|
|
|
|
zathura_db_set_fileinfo(zathura->database, path, &file_info);
|
|
|
|
/* save jumplist */
|
|
|
|
zathura_db_save_jumplist(zathura->database, path, zathura->jumplist.list);
|
|
|
|
|
|
|
|
g_free(file_info.first_page_column_list);
|
|
|
|
}
|
|
|
|
|
2010-12-12 22:04:42 +01:00
|
|
|
bool
|
2012-02-20 20:07:24 +01:00
|
|
|
document_close(zathura_t* zathura, bool keep_monitor)
|
2010-12-12 22:04:42 +01:00
|
|
|
{
|
2012-02-20 20:07:24 +01:00
|
|
|
if (zathura == NULL || zathura->document == NULL) {
|
2010-12-12 22:04:42 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-21 18:32:18 +02:00
|
|
|
/* stop rendering */
|
|
|
|
zathura_renderer_stop(zathura->sync.render_thread);
|
|
|
|
|
2012-02-20 20:07:24 +01:00
|
|
|
/* remove monitor */
|
|
|
|
if (keep_monitor == false) {
|
2017-03-17 17:58:55 +01:00
|
|
|
g_clear_object(&zathura->file_monitor.monitor);
|
2012-02-20 20:07:24 +01:00
|
|
|
|
|
|
|
if (zathura->file_monitor.password != NULL) {
|
|
|
|
g_free(zathura->file_monitor.password);
|
|
|
|
zathura->file_monitor.password = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-21 04:59:58 +02:00
|
|
|
/* remove marks */
|
|
|
|
if (zathura->global.marks != NULL) {
|
|
|
|
girara_list_free(zathura->global.marks);
|
|
|
|
zathura->global.marks = NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-20 21:15:03 +02:00
|
|
|
/* store file information */
|
2014-12-15 03:37:41 +01:00
|
|
|
if (zathura->database != NULL) {
|
2016-02-24 22:57:01 +01:00
|
|
|
save_fileinfo_to_db(zathura);
|
2014-12-15 03:37:41 +01:00
|
|
|
}
|
2011-10-06 17:57:26 +02:00
|
|
|
|
2013-06-21 14:30:04 +02:00
|
|
|
girara_list_iterator_free(zathura->jumplist.cur);
|
|
|
|
zathura->jumplist.cur = NULL;
|
|
|
|
girara_list_free(zathura->jumplist.list);
|
|
|
|
zathura->jumplist.list = NULL;
|
|
|
|
zathura->jumplist.size = 0;
|
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
/* release render thread */
|
2017-03-17 17:58:55 +01:00
|
|
|
g_clear_object(&zathura->sync.render_thread);
|
2011-07-21 14:39:25 +02:00
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
/* remove widgets */
|
2014-11-07 14:24:46 +01:00
|
|
|
gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, NULL);
|
2012-05-08 17:10:57 +02:00
|
|
|
for (unsigned int i = 0; i < zathura_document_get_number_of_pages(zathura->document); i++) {
|
|
|
|
g_object_unref(zathura->pages[i]);
|
|
|
|
}
|
2012-04-03 09:02:45 +02:00
|
|
|
free(zathura->pages);
|
|
|
|
zathura->pages = NULL;
|
2011-01-24 12:43:39 +01:00
|
|
|
|
2012-04-03 09:02:45 +02:00
|
|
|
/* remove document */
|
2011-04-18 17:27:49 +02:00
|
|
|
zathura_document_free(zathura->document);
|
2011-07-21 14:39:25 +02:00
|
|
|
zathura->document = NULL;
|
|
|
|
|
2012-04-16 09:17:25 +02:00
|
|
|
/* remove index */
|
|
|
|
if (zathura->ui.index != NULL) {
|
|
|
|
g_object_ref_sink(zathura->ui.index);
|
|
|
|
zathura->ui.index = NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-07 18:30:46 +01:00
|
|
|
gtk_widget_hide(zathura->ui.page_widget);
|
2011-09-29 17:32:35 +02:00
|
|
|
|
|
|
|
statusbar_page_number_update(zathura);
|
|
|
|
|
|
|
|
if (zathura->ui.session != NULL && zathura->ui.statusbar.file != NULL) {
|
2012-03-16 13:42:15 +01:00
|
|
|
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, _("[No name]"));
|
2011-09-29 17:32:35 +02:00
|
|
|
}
|
2010-12-12 22:04:42 +01:00
|
|
|
|
2012-03-16 07:58:55 +01:00
|
|
|
/* update title */
|
|
|
|
girara_set_window_title(zathura->ui.session, "zathura");
|
|
|
|
|
2010-12-12 22:04:42 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-04-18 17:27:49 +02:00
|
|
|
page_set(zathura_t* zathura, unsigned int page_id)
|
2010-12-12 22:04:42 +01:00
|
|
|
{
|
2012-03-27 21:59:35 +02:00
|
|
|
if (zathura == NULL || zathura->document == NULL) {
|
2010-12-26 01:52:17 +01:00
|
|
|
goto error_out;
|
2010-12-12 22:04:42 +01:00
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
|
2012-02-12 16:35:33 +01:00
|
|
|
if (page == NULL) {
|
2010-12-27 09:07:17 +01:00
|
|
|
goto error_out;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
zathura_document_set_current_page_number(zathura->document, page_id);
|
2010-12-27 09:07:17 +01:00
|
|
|
|
2017-05-21 22:57:58 +02:00
|
|
|
bool continuous_hist_save = false;
|
|
|
|
girara_setting_get(zathura->ui.session, "continuous-hist-save", &continuous_hist_save);
|
|
|
|
if (continuous_hist_save) {
|
|
|
|
save_fileinfo_to_db(zathura);
|
|
|
|
}
|
|
|
|
|
2013-10-22 21:37:02 +02:00
|
|
|
/* negative position means auto */
|
|
|
|
return position_set(zathura, -1, -1);
|
2010-12-26 01:52:17 +01:00
|
|
|
|
|
|
|
error_out:
|
|
|
|
return false;
|
2010-12-12 22:04:42 +01:00
|
|
|
}
|
|
|
|
|
2011-04-27 19:57:49 +02:00
|
|
|
void
|
|
|
|
statusbar_page_number_update(zathura_t* zathura)
|
|
|
|
{
|
|
|
|
if (zathura == NULL || zathura->ui.statusbar.page_number == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
|
|
|
unsigned int current_page_number = zathura_document_get_current_page_number(zathura->document);
|
|
|
|
|
2011-09-29 17:32:35 +02:00
|
|
|
if (zathura->document != NULL) {
|
2012-03-27 21:59:35 +02:00
|
|
|
char* page_number_text = g_strdup_printf("[%d/%d]", current_page_number + 1, number_of_pages);
|
2011-09-29 17:32:35 +02:00
|
|
|
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, page_number_text);
|
2013-07-22 15:01:05 +02:00
|
|
|
|
|
|
|
bool page_number_in_window_title = false;
|
|
|
|
girara_setting_get(zathura->ui.session, "window-title-page", &page_number_in_window_title);
|
|
|
|
|
|
|
|
if (page_number_in_window_title == true) {
|
2015-12-07 01:13:59 +01:00
|
|
|
char* filename = get_formatted_filename(zathura, false);
|
2015-10-05 22:49:04 +02:00
|
|
|
char* title = g_strdup_printf("%s %s", filename, page_number_text);
|
2013-07-22 15:01:05 +02:00
|
|
|
girara_set_window_title(zathura->ui.session, title);
|
|
|
|
g_free(title);
|
2015-10-05 22:49:04 +02:00
|
|
|
g_free(filename);
|
2013-07-22 15:01:05 +02:00
|
|
|
}
|
|
|
|
|
2011-09-29 17:32:35 +02:00
|
|
|
g_free(page_number_text);
|
|
|
|
} else {
|
|
|
|
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.page_number, "");
|
|
|
|
}
|
2011-04-27 19:57:49 +02:00
|
|
|
}
|
|
|
|
|
2011-03-18 18:40:20 +01:00
|
|
|
void
|
2013-10-20 16:07:07 +02:00
|
|
|
page_widget_set_mode(zathura_t* zathura, unsigned int page_padding,
|
|
|
|
unsigned int pages_per_row, unsigned int first_page_column)
|
2011-03-18 18:40:20 +01:00
|
|
|
{
|
2011-04-25 16:54:21 +02:00
|
|
|
/* show at least one page */
|
|
|
|
if (pages_per_row == 0) {
|
|
|
|
pages_per_row = 1;
|
|
|
|
}
|
|
|
|
|
2012-10-09 01:12:18 +02:00
|
|
|
/* ensure: 0 < first_page_column <= pages_per_row */
|
|
|
|
if (first_page_column < 1) {
|
|
|
|
first_page_column = 1;
|
|
|
|
}
|
|
|
|
if (first_page_column > pages_per_row) {
|
|
|
|
first_page_column = ((first_page_column - 1) % pages_per_row) + 1;
|
|
|
|
}
|
2012-06-27 22:34:16 +02:00
|
|
|
|
2011-07-21 14:47:24 +02:00
|
|
|
if (zathura->document == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-07 14:24:46 +01:00
|
|
|
gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, NULL);
|
2011-07-21 14:47:24 +02:00
|
|
|
|
2012-03-27 21:59:35 +02:00
|
|
|
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
2013-10-20 16:07:07 +02:00
|
|
|
|
|
|
|
gtk_grid_set_row_spacing(GTK_GRID(zathura->ui.page_widget), page_padding);
|
|
|
|
gtk_grid_set_column_spacing(GTK_GRID(zathura->ui.page_widget), page_padding);
|
|
|
|
|
2012-08-05 02:30:03 +02:00
|
|
|
for (unsigned int i = 0; i < number_of_pages; i++) {
|
2012-06-27 22:34:16 +02:00
|
|
|
int x = (i + first_page_column - 1) % pages_per_row;
|
|
|
|
int y = (i + first_page_column - 1) / pages_per_row;
|
2012-03-26 14:44:56 +02:00
|
|
|
|
2014-01-20 02:29:40 +01:00
|
|
|
GtkWidget* page_widget = zathura->pages[i];
|
|
|
|
|
2014-09-27 02:07:53 +02:00
|
|
|
gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), page_widget, x, y, 1, 1);
|
2011-03-18 18:40:20 +01:00
|
|
|
}
|
|
|
|
|
2012-02-07 18:30:46 +01:00
|
|
|
gtk_widget_show_all(zathura->ui.page_widget);
|
2011-03-18 18:40:20 +01:00
|
|
|
}
|
2012-03-24 16:15:34 +01:00
|
|
|
|
2013-10-22 21:37:02 +02:00
|
|
|
bool
|
2013-06-09 05:53:31 +02:00
|
|
|
position_set(zathura_t* zathura, double position_x, double position_y)
|
|
|
|
{
|
2013-10-22 21:37:02 +02:00
|
|
|
if (zathura == NULL || zathura->document == NULL) {
|
2014-01-14 18:01:34 +01:00
|
|
|
return false;
|
2013-10-22 21:37:02 +02:00
|
|
|
}
|
2013-06-09 05:53:31 +02:00
|
|
|
|
2013-10-22 21:37:02 +02:00
|
|
|
double comppos_x, comppos_y;
|
2017-02-23 18:50:12 +01:00
|
|
|
const unsigned int page_id = zathura_document_get_current_page_number(zathura->document);
|
2013-06-09 05:53:31 +02:00
|
|
|
|
2017-02-23 01:18:25 +01:00
|
|
|
bool vertical_center = false;
|
|
|
|
girara_setting_get(zathura->ui.session, "vertical-center", &vertical_center);
|
|
|
|
|
2013-10-22 21:37:02 +02:00
|
|
|
/* xalign = 0.5: center horizontally (with the page, not the document) */
|
2017-02-23 18:50:12 +01:00
|
|
|
if (vertical_center == true) {
|
2017-02-23 01:18:25 +01:00
|
|
|
/* yalign = 0.0: align page an viewport edges at the top */
|
|
|
|
page_number_to_position(zathura->document, page_id, 0.5, 0.0, &comppos_x, &comppos_y);
|
|
|
|
} else {
|
|
|
|
/* yalign = 0.5: center vertically */
|
|
|
|
page_number_to_position(zathura->document, page_id, 0.5, 0.5, &comppos_x, &comppos_y);
|
|
|
|
}
|
2013-10-22 21:37:02 +02:00
|
|
|
|
|
|
|
/* automatic horizontal adjustment */
|
|
|
|
zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(zathura->document);
|
|
|
|
|
|
|
|
/* negative position_x mean: use the computed value */
|
|
|
|
if (position_x < 0) {
|
|
|
|
position_x = comppos_x;
|
|
|
|
bool zoom_center = false;
|
|
|
|
girara_setting_get(zathura->ui.session, "zoom-center", &zoom_center);
|
|
|
|
|
|
|
|
/* center horizontally */
|
|
|
|
if (adjust_mode == ZATHURA_ADJUST_BESTFIT ||
|
|
|
|
adjust_mode == ZATHURA_ADJUST_WIDTH ||
|
2017-02-23 18:50:12 +01:00
|
|
|
zoom_center == true) {
|
2013-10-22 21:37:02 +02:00
|
|
|
position_x = 0.5;
|
|
|
|
}
|
2013-06-09 05:53:31 +02:00
|
|
|
}
|
|
|
|
|
2013-10-22 21:37:02 +02:00
|
|
|
if (position_y < 0) {
|
|
|
|
position_y = comppos_y;
|
2013-06-09 05:53:31 +02:00
|
|
|
}
|
2013-10-22 21:37:02 +02:00
|
|
|
|
|
|
|
/* set the position */
|
|
|
|
zathura_document_set_position_x(zathura->document, position_x);
|
|
|
|
zathura_document_set_position_y(zathura->document, position_y);
|
|
|
|
|
|
|
|
/* trigger a 'change' event for both adjustments */
|
|
|
|
refresh_view(zathura);
|
|
|
|
|
|
|
|
return true;
|
2013-06-09 05:53:31 +02:00
|
|
|
}
|
2012-08-17 14:14:57 +02:00
|
|
|
|
2013-10-22 21:24:26 +02:00
|
|
|
|
|
|
|
void
|
2014-10-27 21:18:28 +01:00
|
|
|
refresh_view(zathura_t* zathura)
|
|
|
|
{
|
2013-10-22 21:24:26 +02:00
|
|
|
g_return_if_fail(zathura != NULL);
|
|
|
|
|
|
|
|
/* emit a custom refresh-view signal */
|
|
|
|
g_signal_emit(zathura->ui.session->gtk.view, zathura->signals.refresh_view,
|
|
|
|
0, zathura);
|
|
|
|
}
|
|
|
|
|
Hide the inputbar and completion menu before saving the adjustments ratios into a new jump structure
Since we are now saving the adjustments ratios in the jump structures, we need
to take care of the following scenario:
- We do an action that results in a new jump structure being added to the
jumplist while the inputbar is visible (e.g., search, jumping to a
specific page, jumping to a bookmark, or following a link).
- Since we are now storing the adjustments ratios in the jump structures,
all of the above actions would result in the vertical adjustment ratio
being saved while the inputbar and/or the completion menu is visible.
- Now we are exactly on the target of the jump (note that the inputbar and
completion menu now are hidden), so suppose that we want to go back using
^o (assuming that we didn't change the adjustments after jumping), then
the check at sc_jumplist that compares the current adjustments ratios
with that of the current jump (the jump that has just been added and
which we are currently on it's position) would fail, because after the
inputbar (with possibly the completion menu in case of bookmarks) is
activated it is hidden, which results in the vertical adjustment upper
bound to change, which in turn results in the vertical adjustment ratio
returned by zathura_adjustment_get_ratio to become different from what is
stored in the current jump structure, even though we haven't changed the
adjustments at all after the jump. This would always result in taking us
back to the exact position of the jump (which would be slightly different
from the current position) when we press ^o. This can be annoying,
because it would happen, for example, every time we need to go back
quickly after jumping to a link target, a search result, or a bookmark.
So, what this patch does is essentially to make the vertical adjustment ratio
reflecting the current vertical adjustment after a jump, to always be the same
as the one stored in the newly added jump structure, since both are calculated
with zathura_adjustment_get_ratio while the inputbar is _not_ visible, so they
should be the same.
I've elaborated just to make things clear, in case the purpose of the patch
isn't obvious.
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
2013-06-21 14:25:29 +02:00
|
|
|
|
2013-10-24 22:11:52 +02:00
|
|
|
bool
|
2014-10-27 21:18:28 +01:00
|
|
|
adjust_view(zathura_t* zathura)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(zathura != NULL, false);
|
2013-10-24 22:11:52 +02:00
|
|
|
|
|
|
|
if (zathura->ui.page_widget == NULL || zathura->document == NULL) {
|
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(zathura->document);
|
|
|
|
if (adjust_mode == ZATHURA_ADJUST_NONE) {
|
|
|
|
/* there is nothing todo */
|
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int cell_height = 0, cell_width = 0;
|
|
|
|
unsigned int document_height = 0, document_width = 0;
|
|
|
|
unsigned int view_height = 0, view_width = 0;
|
|
|
|
|
|
|
|
zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width);
|
|
|
|
zathura_document_get_document_size(zathura->document, &document_height, &document_width);
|
|
|
|
zathura_document_get_viewport_size(zathura->document, &view_height, &view_width);
|
|
|
|
|
|
|
|
if (view_height == 0 || view_width == 0 || cell_height == 0 || cell_width == 0) {
|
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
2013-11-05 02:22:30 +01:00
|
|
|
double page_ratio = (double)cell_height / (double)document_width;
|
2013-10-24 22:11:52 +02:00
|
|
|
double view_ratio = (double)view_height / (double)view_width;
|
2013-11-05 02:22:30 +01:00
|
|
|
double scale = zathura_document_get_scale(zathura->document);
|
2013-10-24 22:11:52 +02:00
|
|
|
double newscale = scale;
|
|
|
|
|
|
|
|
if (adjust_mode == ZATHURA_ADJUST_WIDTH ||
|
|
|
|
(adjust_mode == ZATHURA_ADJUST_BESTFIT && page_ratio < view_ratio)) {
|
2016-01-09 15:28:10 +01:00
|
|
|
newscale *= (double)view_width / (double)document_width;
|
2013-10-24 22:11:52 +02:00
|
|
|
|
|
|
|
} else if (adjust_mode == ZATHURA_ADJUST_BESTFIT) {
|
2016-01-09 15:28:10 +01:00
|
|
|
newscale *= (double)view_height / (double)cell_height;
|
2013-10-24 22:11:52 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save new scale and recompute cell size */
|
|
|
|
zathura_document_set_scale(zathura->document, newscale);
|
|
|
|
unsigned int new_cell_height = 0, new_cell_width = 0;
|
|
|
|
zathura_document_get_cell_size(zathura->document, &new_cell_height, &new_cell_width);
|
|
|
|
|
|
|
|
/* if the change in scale changes page cell dimensions by at least one pixel, render */
|
2016-01-09 15:28:10 +01:00
|
|
|
if (abs((int)new_cell_width - (int)cell_width) > 1 ||
|
|
|
|
abs((int)new_cell_height - (int)cell_height) > 1) {
|
2013-10-24 22:11:52 +02:00
|
|
|
render_all(zathura);
|
|
|
|
refresh_view(zathura);
|
|
|
|
} else {
|
2016-11-04 19:37:13 +01:00
|
|
|
/* otherwise set the old scale and leave */
|
2013-10-24 22:11:52 +02:00
|
|
|
zathura_document_set_scale(zathura->document, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_ret:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-23 17:27:24 +02:00
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
static gboolean
|
|
|
|
zathura_signal_sigterm(gpointer data)
|
|
|
|
{
|
|
|
|
if (data == NULL) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_t* zathura = (zathura_t*) data;
|
|
|
|
cb_destroy(NULL, zathura);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|