From 851ef7cd7b43b60504558f982bdcc7d527f3ed8a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 9 Feb 2012 01:46:51 +0100 Subject: [PATCH] Adjust on resize / Adjust on open --- callbacks.c | 13 +++++++++++++ callbacks.h | 10 ++++++++++ config.c | 16 ++++++++++------ document.c | 6 ++++++ document.h | 1 + page_widget.c | 8 +++++--- shortcuts.c | 4 ++++ zathura.c | 2 ++ 8 files changed, 51 insertions(+), 9 deletions(-) diff --git a/callbacks.c b/callbacks.c index 3487134..1ad6b7c 100644 --- a/callbacks.c +++ b/callbacks.c @@ -281,3 +281,16 @@ error_ret: return false; } + +bool +cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* UNUSED(allocation), zathura_t* zathura) +{ + if (zathura == NULL || zathura->document == NULL) { + return false; + } + + girara_argument_t argument = { zathura->document->adjust_mode, NULL }; + sc_adjust_window(zathura->ui.session, &argument, NULL, 0); + + return true; +} diff --git a/callbacks.h b/callbacks.h index ce08397..19630d1 100644 --- a/callbacks.h +++ b/callbacks.h @@ -87,4 +87,14 @@ void cb_file_monitor(GFileMonitor* monitor, GFile* file, GFile* other_file, */ bool cb_password_dialog(GtkEntry* entry, zathura_password_dialog_info_t* dialog); +/** + * Emitted when the view has been resized + * + * @param widget View + * @param allocation Allocation + * @param zathura Zathura session + * @return true if signal has been handled successfully + */ +bool cb_view_resized(GtkWidget* widget, GtkAllocation* allocation, zathura_t* zathura); + #endif // CALLBACKS_H diff --git a/config.c b/config.c index 9d7adff..3a3e3d6 100644 --- a/config.c +++ b/config.c @@ -55,11 +55,13 @@ config_load_default(zathura_t* zathura) girara_setting_add(gsession, "recolor-lightcolor", string_value, STRING, false, "Recoloring (light color)", NULL, NULL); string_value = "#9FBC00"; - girara_setting_add(gsession, "highlight-color", string_value, STRING, false, "Color for highlighting", NULL, NULL); + girara_setting_add(gsession, "highlight-color", string_value, STRING, false, "Color for highlighting", NULL, NULL); float_value = 0.5; - girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, "Transparency for highlighting", NULL, NULL); + girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, "Transparency for highlighting", NULL, NULL); bool_value = true; girara_setting_add(gsession, "render-loading", &bool_value, BOOLEAN, false, "Render 'Loading ...'", NULL, NULL); + int_value = ADJUST_BESTFIT; + girara_setting_add(gsession, "adjust-open", &int_value, INT, false, "Adjust to when opening file", NULL, NULL); /* define default shortcuts */ girara_shortcut_add(gsession, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); @@ -184,10 +186,10 @@ config_load_default(zathura_t* zathura) girara_argument_mapping_add(gsession, "bottom", BOTTOM); girara_argument_mapping_add(gsession, "default", DEFAULT); girara_argument_mapping_add(gsession, "down", DOWN); - girara_argument_mapping_add(gsession, "full_down", FULL_DOWN); - girara_argument_mapping_add(gsession, "full_up", FULL_UP); - girara_argument_mapping_add(gsession, "half_down", HALF_DOWN); - girara_argument_mapping_add(gsession, "half_up", HALF_UP); + girara_argument_mapping_add(gsession, "full-down", FULL_DOWN); + girara_argument_mapping_add(gsession, "full-up", FULL_UP); + girara_argument_mapping_add(gsession, "half-down", HALF_DOWN); + girara_argument_mapping_add(gsession, "half-up", HALF_UP); girara_argument_mapping_add(gsession, "in", ZOOM_IN); girara_argument_mapping_add(gsession, "left", LEFT); girara_argument_mapping_add(gsession, "next", NEXT); @@ -197,6 +199,8 @@ config_load_default(zathura_t* zathura) girara_argument_mapping_add(gsession, "specific", ZOOM_SPECIFIC); girara_argument_mapping_add(gsession, "top", TOP); girara_argument_mapping_add(gsession, "up", UP); + girara_argument_mapping_add(gsession, "best-fit", ADJUST_BESTFIT); + girara_argument_mapping_add(gsession, "width", ADJUST_WIDTH); } void diff --git a/document.c b/document.c index 9b04517..dcab1a5 100644 --- a/document.c +++ b/document.c @@ -29,6 +29,7 @@ #include #include #include +#include /** * Register document plugin @@ -345,6 +346,11 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password g_signal_connect(G_OBJECT(document->file_monitor.monitor), "changed", G_CALLBACK(cb_file_monitor), zathura->ui.session); + + /* apply open adjustment */ + int adjust_open = ADJUST_BESTFIT; + girara_setting_get(zathura->ui.session, "adjust-open", &adjust_open); + g_free(file_uri); return document; diff --git a/document.h b/document.h index 324dc66..e0aac6f 100644 --- a/document.h +++ b/document.h @@ -211,6 +211,7 @@ struct zathura_document_s int rotate; /**< Rotation */ void* data; /**< Custom data */ zathura_t* zathura; /** Zathura object */ + int adjust_mode; /**< Adjust mode (best-fit, width) */ struct { diff --git a/page_widget.c b/page_widget.c index e8c7130..5c0f368 100644 --- a/page_widget.c +++ b/page_widget.c @@ -1,11 +1,13 @@ /* See LICENSE file for license and copyright information */ +#include +#include +#include + #include "page_widget.h" #include "render.h" #include "utils.h" -#include -#include -#include +#include "shortcuts.h" G_DEFINE_TYPE(ZathuraPage, zathura_page_widget, GTK_TYPE_DRAWING_AREA) diff --git a/shortcuts.c b/shortcuts.c index de32e95..c5d8a0a 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -56,6 +56,8 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument, goto error_ret; } + zathura->document->adjust_mode = argument->n; + /* get window size */ GtkAllocation allocation; gtk_widget_get_allocation(session->gtk.view, &allocation); @@ -764,6 +766,8 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* g_return_val_if_fail(argument != NULL, false); g_return_val_if_fail(zathura->document != NULL, false); + zathura->document->adjust_mode = ADJUST_NONE; + /* retreive zoom step value */ int value = 1; girara_setting_get(zathura->ui.session, "zoom-step", &value); diff --git a/zathura.c b/zathura.c index bed41be..a90177f 100644 --- a/zathura.c +++ b/zathura.c @@ -176,6 +176,8 @@ zathura_init(int argc, char* argv[]) goto error_free; } + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.view), "size-allocate", G_CALLBACK(cb_view_resized), zathura); + /* callbacks */ GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); g_signal_connect(G_OBJECT(view_vadjustment), "value-changed", G_CALLBACK(cb_view_vadjustment_value_changed), zathura);