2010-11-10 20:47:53 +01:00
|
|
|
/* See LICENSE file for license and copyright information */
|
|
|
|
|
2011-10-23 17:01:15 +02:00
|
|
|
#include <girara/session.h>
|
|
|
|
#include <girara/settings.h>
|
|
|
|
#include <girara/datastructures.h>
|
|
|
|
#include <girara/shortcuts.h>
|
2012-02-07 14:56:58 +01:00
|
|
|
#include <girara/utils.h>
|
2010-11-12 13:48:18 +01:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "callbacks.h"
|
2010-11-10 20:47:53 +01:00
|
|
|
#include "shortcuts.h"
|
2011-04-18 18:29:50 +02:00
|
|
|
#include "document.h"
|
2010-11-13 12:40:48 +01:00
|
|
|
#include "zathura.h"
|
2011-02-09 21:28:36 +01:00
|
|
|
#include "render.h"
|
2011-02-10 04:33:28 +01:00
|
|
|
#include "utils.h"
|
2012-02-07 18:30:46 +01:00
|
|
|
#include "page_widget.h"
|
2010-11-10 20:47:53 +01:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2010-11-13 12:40:48 +01:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
2012-02-07 14:56:58 +01:00
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
2012-02-08 23:42:09 +01:00
|
|
|
if (zathura->document != NULL) {
|
|
|
|
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; ++page_id) {
|
|
|
|
zathura_page_t* page = zathura->document->pages[page_id];
|
|
|
|
if (page == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_set(page->drawing_area, "draw-links", FALSE, NULL);
|
2012-02-07 14:56:58 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-13 12:40:48 +01:00
|
|
|
|
2011-05-07 22:00:52 +02:00
|
|
|
girara_mode_set(session, session->modes.normal);
|
2012-02-07 19:36:49 +01:00
|
|
|
girara_sc_abort(session, NULL, NULL, 0);
|
2010-11-13 12:40:48 +01:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-10-01 09:40:44 +02:00
|
|
|
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
2011-10-01 09:40:44 +02:00
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
|
2012-02-03 22:15:29 +01:00
|
|
|
unsigned int pages_per_row = 1;
|
|
|
|
girara_setting_get(session, "pages-per-row", &pages_per_row);
|
2011-10-01 09:40:44 +02:00
|
|
|
|
2012-02-07 18:30:46 +01:00
|
|
|
if (zathura->ui.page_widget == NULL || zathura->document == NULL) {
|
2011-10-01 09:40:44 +02:00
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
2012-02-09 01:46:51 +01:00
|
|
|
zathura->document->adjust_mode = argument->n;
|
|
|
|
|
2011-10-01 09:40:44 +02:00
|
|
|
/* get window size */
|
2012-02-09 01:20:42 +01:00
|
|
|
GtkAllocation allocation;
|
|
|
|
gtk_widget_get_allocation(session->gtk.view, &allocation);
|
|
|
|
gint width = allocation.width;
|
|
|
|
gint height = allocation.height;
|
2011-10-01 09:40:44 +02:00
|
|
|
|
|
|
|
/* calculate total width and max-height */
|
|
|
|
double total_width = 0;
|
|
|
|
double max_height = 0;
|
|
|
|
|
2012-02-03 22:15:29 +01:00
|
|
|
for (unsigned int page_id = 0; page_id < pages_per_row; page_id++) {
|
2011-10-01 09:40:44 +02:00
|
|
|
if (page_id == zathura->document->number_of_pages) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
zathura_page_t* page = zathura->document->pages[page_id];
|
|
|
|
if (page == NULL) {
|
2012-02-03 22:15:29 +01:00
|
|
|
goto error_ret;
|
2011-10-01 09:40:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (page->height > max_height) {
|
|
|
|
max_height = page->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
total_width += page->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argument->n == ADJUST_WIDTH) {
|
|
|
|
zathura->document->scale = width / total_width;
|
|
|
|
} else if (argument->n == ADJUST_BESTFIT) {
|
|
|
|
zathura->document->scale = height / max_height;
|
|
|
|
} else {
|
2012-02-03 22:15:29 +01:00
|
|
|
goto error_ret;
|
2011-10-01 09:40:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* re-render all pages */
|
|
|
|
render_all(zathura);
|
|
|
|
|
|
|
|
error_ret:
|
2011-04-18 17:55:50 +02:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_change_mode(girara_session_t* session, girara_argument_t* argument,
|
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2010-11-13 12:40:48 +01:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
|
|
|
|
girara_mode_set(session, argument->n);
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
2012-01-19 00:49:08 +01:00
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
2012-02-12 11:16:10 +01:00
|
|
|
if (zathura->document == NULL || zathura->ui.session == NULL) {
|
2012-01-19 00:49:08 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-07 16:39:02 +01:00
|
|
|
/* set pages to draw links */
|
2012-02-08 00:19:35 +01:00
|
|
|
bool show_links = false;
|
2012-02-07 17:31:47 +01:00
|
|
|
unsigned int page_offset = 0;
|
2012-01-19 00:49:08 +01:00
|
|
|
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
|
|
|
|
zathura_page_t* page = zathura->document->pages[page_id];
|
|
|
|
if (page == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-02-07 17:32:03 +01:00
|
|
|
g_object_set(page->drawing_area, "search-results", NULL, NULL);
|
2012-02-07 16:39:02 +01:00
|
|
|
if (page->visible == true) {
|
2012-02-07 18:00:47 +01:00
|
|
|
g_object_set(page->drawing_area, "draw-links", TRUE, NULL);
|
|
|
|
|
2012-02-07 17:31:47 +01:00
|
|
|
int number_of_links = 0;
|
|
|
|
g_object_get(page->drawing_area, "number-of-links", &number_of_links, NULL);
|
2012-02-08 00:19:35 +01:00
|
|
|
if (number_of_links != 0) {
|
|
|
|
show_links = true;
|
|
|
|
}
|
2012-02-07 17:31:47 +01:00
|
|
|
g_object_set(page->drawing_area, "offset-links", page_offset, NULL);
|
|
|
|
page_offset += number_of_links;
|
2012-02-07 16:39:02 +01:00
|
|
|
} else {
|
|
|
|
g_object_set(page->drawing_area, "draw-links", FALSE, NULL);
|
2012-01-19 00:49:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-07 16:39:02 +01:00
|
|
|
/* ask for input */
|
2012-02-08 00:19:35 +01:00
|
|
|
if (show_links == true) {
|
2012-02-12 11:16:10 +01:00
|
|
|
girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_follow, zathura->ui.session);
|
2012-02-08 00:19:35 +01:00
|
|
|
}
|
2012-02-07 16:39:02 +01:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
2010-11-10 20:47:53 +01:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_goto(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int t)
|
2010-11-13 10:05:28 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
g_return_val_if_fail(zathura->document != NULL, false);
|
2011-02-09 17:12:09 +01:00
|
|
|
|
|
|
|
if (argument->n == TOP) {
|
2011-10-13 12:15:21 +02:00
|
|
|
page_set(zathura, 0);
|
2011-02-09 17:12:09 +01:00
|
|
|
} else {
|
|
|
|
if (t == 0) {
|
2011-10-13 12:15:21 +02:00
|
|
|
page_set(zathura, zathura->document->number_of_pages - 1);
|
|
|
|
} else {
|
|
|
|
page_set(zathura, t - 1);
|
2011-02-09 17:12:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-07 15:13:36 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
g_return_val_if_fail(event != NULL, false);
|
|
|
|
|
2012-02-09 01:07:25 +01:00
|
|
|
static int x = 0;
|
|
|
|
static int y = 0;
|
|
|
|
|
2012-02-07 15:13:36 +01:00
|
|
|
if (zathura->document == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scroll event */
|
|
|
|
if (event->type == GIRARA_EVENT_SCROLL) {
|
|
|
|
switch (event->direction) {
|
|
|
|
case GIRARA_SCROLL_UP:
|
|
|
|
argument->n = UP;
|
|
|
|
break;
|
|
|
|
case GIRARA_SCROLL_DOWN:
|
|
|
|
argument->n = DOWN;
|
|
|
|
break;
|
|
|
|
case GIRARA_SCROLL_LEFT:
|
|
|
|
argument->n = LEFT;
|
|
|
|
break;
|
|
|
|
case GIRARA_SCROLL_RIGHT:
|
|
|
|
argument->n = RIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sc_scroll(session, argument, NULL, t);
|
2012-02-09 01:07:25 +01:00
|
|
|
} else if (event->type == GIRARA_EVENT_BUTTON_PRESS) {
|
|
|
|
x = event->x;
|
|
|
|
y = event->y;
|
|
|
|
} else if (event->type == GIRARA_EVENT_BUTTON_RELEASE) {
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
2012-02-09 00:36:41 +01:00
|
|
|
} else if (event->type == GIRARA_EVENT_MOTION_NOTIFY) {
|
2012-02-09 01:07:25 +01:00
|
|
|
GtkAdjustment* x_adj =
|
|
|
|
gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
|
|
|
|
GtkAdjustment* y_adj =
|
|
|
|
gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
|
|
|
|
|
|
|
|
if (x_adj == NULL || y_adj == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_adjustment(x_adj, gtk_adjustment_get_value(x_adj) - (event->x - x));
|
|
|
|
set_adjustment(y_adj, gtk_adjustment_get_value(y_adj) - (event->y - y));
|
|
|
|
|
|
|
|
x = event->x;
|
|
|
|
y = event->y;
|
2012-02-07 15:13:36 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2012-02-07 18:34:39 +01:00
|
|
|
bool
|
|
|
|
sc_mouse_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* event, unsigned int t)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
g_return_val_if_fail(event != NULL, false);
|
|
|
|
|
|
|
|
if (zathura->document == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scroll event */
|
|
|
|
if (event->type == GIRARA_EVENT_SCROLL) {
|
|
|
|
switch (event->direction) {
|
|
|
|
case GIRARA_SCROLL_UP:
|
|
|
|
argument->n = ZOOM_IN;
|
|
|
|
break;
|
|
|
|
case GIRARA_SCROLL_DOWN:
|
|
|
|
argument->n = ZOOM_OUT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sc_zoom(session, argument, NULL, t);
|
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_navigate(girara_session_t* session, girara_argument_t* argument,
|
|
|
|
girara_event_t* UNUSED(event), unsigned int t)
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
g_return_val_if_fail(zathura->document != NULL, false);
|
2010-12-12 22:04:42 +01:00
|
|
|
|
2011-04-18 17:55:50 +02:00
|
|
|
unsigned int number_of_pages = zathura->document->number_of_pages;
|
|
|
|
unsigned int new_page = zathura->document->current_page_number;
|
2010-12-12 22:04:42 +01:00
|
|
|
|
2012-01-11 16:38:50 +01:00
|
|
|
t = (t == 0) ? 1 : t;
|
2011-02-09 12:29:09 +01:00
|
|
|
if (argument->n == NEXT) {
|
2012-01-11 16:38:50 +01:00
|
|
|
new_page = (new_page + t) % number_of_pages;
|
2011-02-09 12:29:09 +01:00
|
|
|
} else if (argument->n == PREVIOUS) {
|
2012-01-11 16:38:50 +01:00
|
|
|
new_page = (new_page + number_of_pages - t) % number_of_pages;
|
2010-12-12 22:04:42 +01:00
|
|
|
}
|
|
|
|
|
2011-04-18 18:29:50 +02:00
|
|
|
page_set(zathura, new_page);
|
2010-12-12 22:04:42 +01:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
sc_recolor(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
2011-04-30 13:27:27 +02:00
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
|
|
|
zathura->global.recolor = !zathura->global.recolor;
|
|
|
|
render_all(zathura);
|
2011-04-18 17:55:50 +02:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
2011-10-01 17:47:51 +02:00
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
|
|
|
|
if (zathura->document == NULL || zathura->document->file_path == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save current document path and password */
|
|
|
|
char* path = g_strdup(zathura->document->file_path);
|
|
|
|
char* password = zathura->document->password ? g_strdup(zathura->document->password) : NULL;
|
|
|
|
|
|
|
|
/* close current document */
|
|
|
|
document_close(zathura);
|
|
|
|
|
|
|
|
/* reopen document */
|
|
|
|
document_open(zathura, path, password);
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
g_free(path);
|
|
|
|
g_free(password);
|
2011-04-18 17:55:50 +02:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
sc_rotate(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(zathura->document != NULL, false);
|
2011-03-06 14:49:44 +01:00
|
|
|
|
2012-02-08 22:06:33 +01:00
|
|
|
unsigned int page_number = zathura->document->current_page_number;
|
|
|
|
|
2011-03-06 14:49:44 +01:00
|
|
|
/* update rotate value */
|
2011-04-18 17:55:50 +02:00
|
|
|
zathura->document->rotate = (zathura->document->rotate + 90) % 360;
|
2011-03-06 14:49:44 +01:00
|
|
|
|
|
|
|
/* render all pages again */
|
2011-04-18 18:29:50 +02:00
|
|
|
render_all(zathura);
|
2011-03-06 14:49:44 +01:00
|
|
|
|
2012-02-08 22:06:33 +01:00
|
|
|
page_set_delayed(zathura, page_number);
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_scroll(girara_session_t* session, girara_argument_t* argument,
|
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
2011-09-01 11:51:49 +02:00
|
|
|
if (zathura->document == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-18 17:55:50 +02:00
|
|
|
|
2011-01-24 12:54:20 +01:00
|
|
|
GtkAdjustment* adjustment = NULL;
|
2011-10-12 16:18:40 +02:00
|
|
|
if ( (argument->n == LEFT) || (argument->n == RIGHT) ) {
|
2011-10-01 17:47:51 +02:00
|
|
|
adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
|
2011-10-12 16:18:40 +02:00
|
|
|
} else {
|
2011-10-01 17:47:51 +02:00
|
|
|
adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
|
2011-10-12 16:18:40 +02:00
|
|
|
}
|
2011-01-24 12:54:20 +01:00
|
|
|
|
2011-10-12 16:18:40 +02:00
|
|
|
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;
|
2012-02-03 22:15:29 +01:00
|
|
|
float scroll_step = 40;
|
|
|
|
girara_setting_get(session, "scroll-step", &scroll_step);
|
2011-10-19 08:24:53 +02:00
|
|
|
gdouble new_value;
|
2011-01-24 12:54:20 +01:00
|
|
|
|
2011-10-12 16:18:40 +02:00
|
|
|
switch(argument->n) {
|
2011-01-24 12:54:20 +01:00
|
|
|
case FULL_UP:
|
2012-02-08 21:34:53 +01:00
|
|
|
new_value = value - view_size;
|
2011-01-24 12:54:20 +01:00
|
|
|
break;
|
|
|
|
case FULL_DOWN:
|
2012-02-08 21:34:53 +01:00
|
|
|
new_value = value + view_size;
|
2011-01-24 12:54:20 +01:00
|
|
|
break;
|
|
|
|
case HALF_UP:
|
2012-02-08 21:34:53 +01:00
|
|
|
new_value = value - (view_size / 2);
|
2011-01-24 12:54:20 +01:00
|
|
|
break;
|
|
|
|
case HALF_DOWN:
|
2012-02-08 21:34:53 +01:00
|
|
|
new_value = value + (view_size / 2);
|
2011-01-24 12:54:20 +01:00
|
|
|
break;
|
|
|
|
case LEFT:
|
|
|
|
case UP:
|
2012-02-08 21:34:53 +01:00
|
|
|
new_value = value - scroll_step;
|
2011-01-24 12:54:20 +01:00
|
|
|
break;
|
|
|
|
case RIGHT:
|
|
|
|
case DOWN:
|
2012-02-08 21:34:53 +01:00
|
|
|
new_value = value + scroll_step;
|
2011-01-24 12:54:20 +01:00
|
|
|
break;
|
|
|
|
case TOP:
|
|
|
|
new_value = 0;
|
|
|
|
break;
|
|
|
|
case BOTTOM:
|
|
|
|
new_value = max;
|
|
|
|
break;
|
|
|
|
default:
|
2011-10-12 16:18:40 +02:00
|
|
|
new_value = value;
|
2011-01-24 12:54:20 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 21:34:53 +01:00
|
|
|
set_adjustment(adjustment, new_value);
|
2011-01-24 12:54:20 +01:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_search(girara_session_t* session, girara_argument_t* argument,
|
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
g_return_val_if_fail(zathura->document != NULL, false);
|
2012-02-07 16:39:02 +01:00
|
|
|
|
2012-02-07 19:15:01 +01:00
|
|
|
const int num_pages = zathura->document->number_of_pages;
|
|
|
|
const int cur_page = zathura->document->current_page_number;
|
|
|
|
int diff = argument->n == FORWARD ? 1 : -1;
|
|
|
|
|
2012-02-07 20:29:29 +01:00
|
|
|
zathura_page_t* target_page = NULL;
|
|
|
|
int target_idx = 0;
|
|
|
|
|
2012-02-07 19:15:01 +01:00
|
|
|
for (int page_id = 0; page_id < num_pages; ++page_id) {
|
|
|
|
int tmp = cur_page + diff * page_id;
|
|
|
|
zathura_page_t* page = zathura->document->pages[(tmp + num_pages) % num_pages];
|
|
|
|
if (page == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int num_search_results = 0, current = -1;
|
|
|
|
g_object_get(page->drawing_area, "search-current", ¤t,
|
|
|
|
"search-length", &num_search_results, NULL);
|
|
|
|
if (num_search_results == 0 || current == -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diff == 1 && current < num_search_results - 1) {
|
|
|
|
/* the next result is on the same page */
|
2012-02-07 20:29:29 +01:00
|
|
|
target_page = page;
|
|
|
|
target_idx = current + 1;
|
|
|
|
// g_object_set(page->drawing_area, "search-current", current + 1, NULL);
|
2012-02-07 19:15:01 +01:00
|
|
|
} else if (diff == -1 && current >= 1) {
|
2012-02-07 20:29:29 +01:00
|
|
|
// g_object_set(page->drawing_area, "search-current", current - 1, NULL);
|
|
|
|
target_page = page;
|
|
|
|
target_idx = current - 1;
|
2012-02-07 19:15:01 +01:00
|
|
|
} else {
|
|
|
|
/* the next result is on a different page */
|
|
|
|
g_object_set(page->drawing_area, "search-current", -1, NULL);
|
|
|
|
|
|
|
|
for (int npage_id = 1; page_id < num_pages; ++npage_id) {
|
|
|
|
int ntmp = cur_page + diff * (page_id + npage_id);
|
|
|
|
zathura_page_t* npage = zathura->document->pages[(ntmp + 2*num_pages) % num_pages];
|
|
|
|
g_object_get(npage->drawing_area, "search-length", &num_search_results, NULL);
|
|
|
|
if (num_search_results != 0) {
|
2012-02-07 20:29:29 +01:00
|
|
|
target_page = npage;
|
|
|
|
target_idx = diff == 1 ? 0 : num_search_results - 1;
|
2012-02-07 19:15:01 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-02-07 16:39:02 +01:00
|
|
|
|
2012-02-07 20:29:29 +01:00
|
|
|
if (target_page != NULL) {
|
|
|
|
girara_list_t* results = NULL;
|
|
|
|
g_object_set(target_page->drawing_area, "search-current", target_idx, NULL);
|
|
|
|
g_object_get(target_page->drawing_area, "search-results", &results, NULL);
|
|
|
|
|
|
|
|
zathura_rectangle_t* rect = girara_list_nth(results, target_idx);
|
|
|
|
zathura_rectangle_t rectangle = recalc_rectangle(target_page, *rect);
|
|
|
|
page_offset_t offset;
|
|
|
|
page_calculate_offset(target_page, &offset);
|
|
|
|
|
|
|
|
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
|
|
|
GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
|
|
|
|
|
|
|
int x = offset.x - gtk_adjustment_get_page_size(view_hadjustment) / 2 + rectangle.x1;
|
|
|
|
int y = offset.y - gtk_adjustment_get_page_size(view_vadjustment) / 2 + rectangle.y1;
|
2012-02-08 21:34:53 +01:00
|
|
|
set_adjustment(view_hadjustment, x);
|
|
|
|
set_adjustment(view_vadjustment, y);
|
2012-02-07 20:29:29 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
sc_navigate_index(girara_session_t* session, girara_argument_t* argument,
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
g_return_val_if_fail(zathura->document != NULL, false);
|
|
|
|
|
2011-09-29 18:17:03 +02:00
|
|
|
if(zathura->ui.index == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkTreeView *tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
gtk_tree_view_get_cursor(tree_view, &path, NULL);
|
2011-10-12 16:18:40 +02:00
|
|
|
if (path == NULL) {
|
2011-09-29 18:17:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
|
|
|
gboolean is_valid_path = TRUE;
|
|
|
|
|
|
|
|
switch(argument->n) {
|
|
|
|
case UP:
|
|
|
|
if(gtk_tree_path_prev(path) == FALSE) {
|
|
|
|
is_valid_path = gtk_tree_path_up(path);
|
|
|
|
} else { /* row above */
|
|
|
|
while(gtk_tree_view_row_expanded(tree_view, path)) {
|
|
|
|
gtk_tree_model_get_iter(model, &iter, path);
|
|
|
|
/* select last child */
|
|
|
|
gtk_tree_model_iter_nth_child(model, &child_iter, &iter,
|
|
|
|
gtk_tree_model_iter_n_children(model, &iter)-1);
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
path = gtk_tree_model_get_path(model, &child_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case COLLAPSE:
|
|
|
|
if(!gtk_tree_view_collapse_row(tree_view, path)
|
|
|
|
&& gtk_tree_path_get_depth(path) > 1) {
|
|
|
|
gtk_tree_path_up(path);
|
|
|
|
gtk_tree_view_collapse_row(tree_view, path);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DOWN:
|
|
|
|
if(gtk_tree_view_row_expanded(tree_view, path)) {
|
|
|
|
gtk_tree_path_down(path);
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
gtk_tree_model_get_iter(model, &iter, path);
|
|
|
|
if (gtk_tree_model_iter_next(model, &iter)) {
|
|
|
|
path = gtk_tree_model_get_path(model, &iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while((is_valid_path = (gtk_tree_path_get_depth(path) > 1))
|
|
|
|
&& gtk_tree_path_up(path));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPAND:
|
|
|
|
if(gtk_tree_view_expand_row(tree_view, path, FALSE)) {
|
|
|
|
gtk_tree_path_down(path);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SELECT:
|
|
|
|
cb_index_row_activated(tree_view, path, NULL, zathura);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_valid_path) {
|
|
|
|
gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free(path);
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-09-29 17:05:54 +02:00
|
|
|
sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
2011-10-03 17:13:33 +02:00
|
|
|
if (zathura->document == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-10 04:33:28 +01:00
|
|
|
|
|
|
|
girara_tree_node_t* document_index = NULL;
|
|
|
|
GtkWidget* treeview = NULL;
|
|
|
|
GtkTreeModel* model = NULL;
|
|
|
|
GtkCellRenderer* renderer = NULL;
|
2011-09-29 17:35:00 +02:00
|
|
|
GtkCellRenderer* renderer2 = NULL;
|
2011-02-10 04:33:28 +01:00
|
|
|
|
2011-04-18 18:29:50 +02:00
|
|
|
if (zathura->ui.index == NULL) {
|
2011-02-10 04:33:28 +01:00
|
|
|
/* create new index widget */
|
2011-04-18 18:29:50 +02:00
|
|
|
zathura->ui.index = gtk_scrolled_window_new(NULL, NULL);
|
2011-02-10 04:33:28 +01:00
|
|
|
|
2011-04-18 18:29:50 +02:00
|
|
|
if (zathura->ui.index == NULL) {
|
2011-02-10 04:33:28 +01:00
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
2011-04-18 18:29:50 +02:00
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(zathura->ui.index),
|
2011-02-10 04:33:28 +01:00
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
|
|
|
|
/* create index */
|
2012-02-07 21:01:54 +01:00
|
|
|
document_index = zathura_document_index_generate(zathura->document, NULL);
|
2011-02-10 04:33:28 +01:00
|
|
|
if (document_index == NULL) {
|
|
|
|
// TODO: Error message
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
2011-09-29 17:28:09 +02:00
|
|
|
model = GTK_TREE_MODEL(gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER));
|
2011-02-10 04:33:28 +01:00
|
|
|
if (model == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
treeview = gtk_tree_view_new_with_model(model);
|
|
|
|
if (treeview == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref(model);
|
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new();
|
|
|
|
if (renderer == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
2011-09-29 17:35:00 +02:00
|
|
|
renderer2 = gtk_cell_renderer_text_new();
|
|
|
|
if (renderer2 == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
2011-02-10 04:33:28 +01:00
|
|
|
document_index_build(model, NULL, document_index);
|
|
|
|
girara_node_free(document_index);
|
|
|
|
|
|
|
|
/* setup widget */
|
|
|
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 0, "Title", renderer, "markup", 0, NULL);
|
2011-09-29 17:35:00 +02:00
|
|
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW (treeview), 1, "Target", renderer2, "text", 1, NULL);
|
2011-09-29 17:28:09 +02:00
|
|
|
|
2011-02-10 04:33:28 +01:00
|
|
|
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
|
|
|
|
g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
g_object_set(G_OBJECT(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0)), "expand", TRUE, NULL);
|
2011-09-29 17:35:00 +02:00
|
|
|
gtk_tree_view_column_set_alignment(gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 1), 1.0f);
|
2011-02-10 04:33:28 +01:00
|
|
|
gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), gtk_tree_path_new_first(), NULL, FALSE);
|
2011-09-29 17:05:54 +02:00
|
|
|
g_signal_connect(G_OBJECT(treeview), "row-activated", G_CALLBACK(cb_index_row_activated), zathura);
|
2011-02-10 04:33:28 +01:00
|
|
|
|
2011-04-18 18:29:50 +02:00
|
|
|
gtk_container_add(GTK_CONTAINER(zathura->ui.index), treeview);
|
2011-02-10 04:33:28 +01:00
|
|
|
gtk_widget_show(treeview);
|
|
|
|
}
|
|
|
|
|
2011-05-27 12:42:37 +02:00
|
|
|
if (gtk_widget_get_visible(GTK_WIDGET(zathura->ui.index))) {
|
2012-02-07 18:30:46 +01:00
|
|
|
girara_set_view(session, zathura->ui.page_widget_alignment);
|
2011-04-18 18:29:50 +02:00
|
|
|
gtk_widget_hide(GTK_WIDGET(zathura->ui.index));
|
2011-09-29 17:05:54 +02:00
|
|
|
girara_mode_set(zathura->ui.session, zathura->modes.normal);
|
2011-02-10 04:33:28 +01:00
|
|
|
} else {
|
2011-04-18 18:29:50 +02:00
|
|
|
girara_set_view(session, zathura->ui.index);
|
|
|
|
gtk_widget_show(GTK_WIDGET(zathura->ui.index));
|
2011-09-29 17:05:54 +02:00
|
|
|
girara_mode_set(zathura->ui.session, zathura->modes.index);
|
2011-02-10 04:33:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
error_free:
|
|
|
|
|
2011-04-18 18:29:50 +02:00
|
|
|
if (zathura->ui.index != NULL) {
|
|
|
|
g_object_ref_sink(zathura->ui.index);
|
|
|
|
zathura->ui.index = NULL;
|
2011-02-10 04:33:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (document_index != NULL) {
|
|
|
|
girara_node_free(document_index);
|
|
|
|
}
|
2011-04-18 17:55:50 +02:00
|
|
|
|
2011-02-10 04:33:28 +01:00
|
|
|
error_ret:
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2011-09-21 00:46:03 +02:00
|
|
|
sc_toggle_fullscreen(girara_session_t* session, girara_argument_t*
|
2012-01-24 01:34:09 +01:00
|
|
|
UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
2012-02-01 18:00:34 +01:00
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
2011-02-10 03:06:13 +01:00
|
|
|
|
2011-10-26 20:46:59 +02:00
|
|
|
static bool fullscreen = false;
|
|
|
|
static int pages_per_row = 1;
|
2012-02-01 18:00:34 +01:00
|
|
|
static double zoom = 1.0;
|
2011-10-26 20:46:59 +02:00
|
|
|
|
|
|
|
if (fullscreen == true) {
|
|
|
|
/* reset pages per row */
|
|
|
|
girara_setting_set(session, "pages-per-row", &pages_per_row);
|
|
|
|
|
|
|
|
/* show status bar */
|
|
|
|
gtk_widget_show(GTK_WIDGET(session->gtk.statusbar));
|
|
|
|
|
|
|
|
/* set full screen */
|
2011-02-10 03:06:13 +01:00
|
|
|
gtk_window_unfullscreen(GTK_WINDOW(session->gtk.window));
|
2012-02-01 18:00:34 +01:00
|
|
|
|
|
|
|
/* reset scale */
|
|
|
|
zathura->document->scale = zoom;
|
|
|
|
render_all(zathura);
|
2011-02-10 03:06:13 +01:00
|
|
|
} else {
|
2011-10-26 20:46:59 +02:00
|
|
|
/* backup pages per row */
|
2012-02-03 22:15:29 +01:00
|
|
|
girara_setting_get(session, "pages-per-row", &pages_per_row);
|
2011-10-26 20:46:59 +02:00
|
|
|
|
|
|
|
/* set single view */
|
|
|
|
int int_value = 1;
|
|
|
|
girara_setting_set(session, "pages-per-row", &int_value);
|
|
|
|
|
2012-02-01 18:00:34 +01:00
|
|
|
/* back up zoom */
|
|
|
|
zoom = zathura->document->scale;
|
|
|
|
|
2011-10-26 20:46:59 +02:00
|
|
|
/* adjust window */
|
|
|
|
girara_argument_t argument = { ADJUST_BESTFIT, NULL };
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_adjust_window(session, &argument, NULL, 0);
|
2011-10-26 20:46:59 +02:00
|
|
|
|
|
|
|
/* hide status and inputbar */
|
|
|
|
gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar));
|
|
|
|
gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar));
|
|
|
|
|
|
|
|
/* set full screen */
|
2011-02-10 03:06:13 +01:00
|
|
|
gtk_window_fullscreen(GTK_WINDOW(session->gtk.window));
|
|
|
|
}
|
|
|
|
|
|
|
|
fullscreen = fullscreen ? false : true;
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_quit(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
|
|
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
|
2010-11-12 13:48:18 +01:00
|
|
|
girara_argument_t arg = { GIRARA_HIDE, NULL };
|
2012-01-24 01:34:09 +01:00
|
|
|
girara_isc_completion(session, &arg, NULL, 0);
|
2010-11-12 13:48:18 +01:00
|
|
|
|
|
|
|
cb_destroy(NULL, NULL);
|
2010-11-10 20:47:53 +01:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
bool
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t*
|
2012-02-08 21:02:07 +01:00
|
|
|
UNUSED(event), unsigned int t)
|
2010-11-10 20:47:53 +01:00
|
|
|
{
|
2011-04-18 17:55:50 +02:00
|
|
|
g_return_val_if_fail(session != NULL, false);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, false);
|
|
|
|
zathura_t* zathura = session->global.data;
|
|
|
|
g_return_val_if_fail(argument != NULL, false);
|
|
|
|
g_return_val_if_fail(zathura->document != NULL, false);
|
2011-02-09 21:28:36 +01:00
|
|
|
|
2012-02-09 01:46:51 +01:00
|
|
|
zathura->document->adjust_mode = ADJUST_NONE;
|
|
|
|
|
2011-02-09 21:28:36 +01:00
|
|
|
/* retreive zoom step value */
|
2012-02-03 22:15:29 +01:00
|
|
|
int value = 1;
|
|
|
|
girara_setting_get(zathura->ui.session, "zoom-step", &value);
|
2011-02-09 21:28:36 +01:00
|
|
|
|
2012-02-03 22:15:29 +01:00
|
|
|
float zoom_step = value / 100.0f;
|
2012-02-08 21:39:44 +01:00
|
|
|
float oldzoom = zathura->document->scale;
|
2011-02-09 21:28:36 +01:00
|
|
|
|
2012-02-08 21:02:07 +01:00
|
|
|
/* specify new zoom value */
|
2011-02-09 21:28:36 +01:00
|
|
|
if (argument->n == ZOOM_IN) {
|
2011-04-18 17:55:50 +02:00
|
|
|
zathura->document->scale += zoom_step;
|
2011-02-09 21:28:36 +01:00
|
|
|
} else if (argument->n == ZOOM_OUT) {
|
2011-04-18 17:55:50 +02:00
|
|
|
zathura->document->scale -= zoom_step;
|
2012-02-08 21:02:07 +01:00
|
|
|
} else if (argument->n == ZOOM_SPECIFIC) {
|
|
|
|
zathura->document->scale = t / 100.0f;
|
2011-02-09 21:28:36 +01:00
|
|
|
} else {
|
2011-04-18 17:55:50 +02:00
|
|
|
zathura->document->scale = 1.0;
|
2011-02-09 21:28:36 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 21:02:07 +01:00
|
|
|
/* zoom limitations */
|
2012-02-09 18:30:36 +01:00
|
|
|
int zoom_min_int = 10;
|
|
|
|
int zoom_max_int = 1000;
|
|
|
|
girara_setting_get(session, "zoom-min", &zoom_min_int);
|
|
|
|
girara_setting_get(session, "zoom-max", &zoom_max_int);
|
|
|
|
|
|
|
|
float zoom_min = zoom_min_int * 0.01f;
|
|
|
|
float zoom_max = zoom_max_int * 0.01f;
|
|
|
|
|
|
|
|
if (zathura->document->scale < zoom_min) {
|
|
|
|
zathura->document->scale = zoom_min;
|
|
|
|
} else if (zathura->document->scale > zoom_max) {
|
|
|
|
zathura->document->scale = zoom_max;
|
2012-02-08 21:02:07 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 21:39:44 +01:00
|
|
|
/* keep position */
|
|
|
|
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
|
|
|
GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
|
|
|
|
gdouble valx = gtk_adjustment_get_value(view_hadjustment) / oldzoom * zathura->document->scale;
|
|
|
|
gdouble valy = gtk_adjustment_get_value(view_vadjustment) / oldzoom * zathura->document->scale;
|
|
|
|
set_adjustment(view_hadjustment, valx);
|
|
|
|
set_adjustment(view_vadjustment, valy);
|
|
|
|
|
2011-04-18 18:29:50 +02:00
|
|
|
render_all(zathura);
|
2011-02-09 21:28:36 +01:00
|
|
|
|
2010-11-13 10:05:28 +01:00
|
|
|
return false;
|
2010-11-10 20:47:53 +01:00
|
|
|
}
|
2011-10-10 19:58:48 +02:00
|
|
|
|