bool sc_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(zathura->document != NULL, false); zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_NONE); /* retrieve zoom step value */ int value = 1; girara_setting_get(zathura->ui.session, "zoom-step", &value); const int nt = (t == 0) ? 1 : t; const double zoom_step = 1.0 + value / 100.0 * nt; const double old_zoom = zathura_document_get_scale(zathura->document); /* specify new zoom value */ if (argument->n == ZOOM_IN) { girara_debug("Increasing zoom by %f.", zoom_step - 1.0); zathura_document_set_scale(zathura->document, old_zoom * zoom_step); } else if (argument->n == ZOOM_OUT) { girara_debug("Decreasing zoom by %f.", zoom_step - 1.0); zathura_document_set_scale(zathura->document, old_zoom / zoom_step); } else if (argument->n == ZOOM_SPECIFIC) { if (t == 0) { girara_debug("Setting zoom to 1."); zathura_document_set_scale(zathura->document, 1.0); } else { girara_debug("Setting zoom to %f.", t / 100.0); zathura_document_set_scale(zathura->document, t / 100.0); } } else if (argument->n == ZOOM_SMOOTH) { const double dy = (event != NULL) ? event->y : 1.0; girara_debug("Increasing zoom by %f.", zoom_step * dy - 1.0); zathura_document_set_scale(zathura->document, old_zoom + zoom_step * dy); } else { girara_debug("Setting zoom to 1."); zathura_document_set_scale(zathura->document, 1.0); } /* zoom limitations */ const double scale = zathura_document_get_scale(zathura->document); zathura_document_set_scale(zathura->document, zathura_correct_scale_value(session, scale)); const double new_zoom = zathura_document_get_scale(zathura->document); if (fabs(new_zoom - old_zoom) <= DBL_EPSILON) { girara_debug("New and old zoom level are too close: %f vs. %f, diff = %f", new_zoom, old_zoom, fabs(new_zoom - old_zoom)); return false; } girara_debug("Re-rendering with new zoom level %f.", new_zoom); render_all(zathura); refresh_view(zathura); return false; }
bool sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(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(zathura->document != NULL, false); zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_NONE); /* retreive zoom step value */ int value = 1; girara_setting_get(zathura->ui.session, "zoom-step", &value); int nt = (t == 0) ? 1 : t; float zoom_step = value / 100.0f * nt; float old_zoom = zathura_document_get_scale(zathura->document); /* specify new zoom value */ if (argument->n == ZOOM_IN) { zathura_document_set_scale(zathura->document, old_zoom + zoom_step); } else if (argument->n == ZOOM_OUT) { zathura_document_set_scale(zathura->document, old_zoom - zoom_step); } else if (argument->n == ZOOM_SPECIFIC) { if (t == 0) { zathura_document_set_scale(zathura->document, 1.0f); } else { zathura_document_set_scale(zathura->document, t / 100.0f); } } else { zathura_document_set_scale(zathura->document, 1.0f); } /* zoom limitations */ 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; float scale = zathura_document_get_scale(zathura->document); if (scale < zoom_min) { zathura_document_set_scale(zathura->document, zoom_min); } else if (scale > zoom_max) { zathura_document_set_scale(zathura->document, zoom_max); } /* keep position */ readjust_view_after_zooming(zathura, old_zoom, true); render_all(zathura); return false; }
bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->gtk.inputbar_entry != 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); zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR); if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == false) { gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); } if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.notification_area)) == true) { gtk_widget_hide(GTK_WIDGET(session->gtk.notification_area)); } gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar_entry)); if (argument->data != NULL) { gtk_entry_set_text(session->gtk.inputbar_entry, (char*) argument->data); /* append filepath */ if (argument->n == APPEND_FILEPATH && zathura->document != NULL) { const char* file_path = zathura_document_get_path(zathura->document); if (file_path == NULL) { return false; } char* path = g_path_get_dirname(file_path); char* escaped = girara_escape_string(path); char* tmp = g_strdup_printf("%s%s/", (char*) argument->data, (g_strcmp0(path, "/") == 0) ? "" : escaped); g_free(path); g_free(escaped); gtk_entry_set_text(session->gtk.inputbar_entry, tmp); g_free(tmp); } /* we save the X clipboard that will be clear by "grab_focus" */ gchar* x_clipboard_text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY)); gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar_entry), -1); if (x_clipboard_text != NULL) { /* we reset the X clipboard with saved text */ gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), x_clipboard_text, -1); g_free(x_clipboard_text); } } return true; }
bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(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); zathura_document_set_adjust_mode(zathura->document, argument->n); adjust_view(zathura); return false; }
bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(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); if (argument->n < ZATHURA_ADJUST_NONE || argument->n >= ZATHURA_ADJUST_MODE_NUMBER) { girara_error("Invalid adjust mode: %d", argument->n); girara_notify(session, GIRARA_ERROR, _("Invalid adjust mode: %d"), argument->n); } else { girara_debug("Setting adjust mode to: %d", argument->n); zathura_document_set_adjust_mode(zathura->document, argument->n); adjust_view(zathura); } return false; }
bool sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; if (zathura->document == NULL || zathura->ui.session == NULL) { return false; } bool show_links = draw_links(zathura); /* ask for input */ if (show_links == true) { zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR); girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, cb_sc_follow, zathura->ui.session); } return false; }
bool sc_display_link(girara_session_t* session, girara_argument_t* UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; if (zathura->document == NULL || zathura->ui.session == NULL) { return false; } bool show_links = draw_links(zathura); /* ask for input */ if (show_links) { zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR); girara_dialog(zathura->ui.session, "Display link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_display_link, zathura->ui.session); } return false; }
bool sc_adjust_window(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(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); unsigned int pages_per_row = 1; girara_setting_get(session, "pages-per-row", &pages_per_row); unsigned int first_page_column = 1; girara_setting_get(session, "first-page-column", &first_page_column); int padding = 1; girara_setting_get(zathura->ui.session, "page-padding", &padding); if (zathura->ui.page_widget == NULL || zathura->document == NULL) { goto error_ret; } float old_zoom = zathura_document_get_scale(zathura->document); zathura_document_set_adjust_mode(zathura->document, argument->n); if (argument->n == ZATHURA_ADJUST_NONE) { /* there is nothing todo */ goto error_ret; } /* get window size */ GtkAllocation allocation; gtk_widget_get_allocation(session->gtk.view, &allocation); unsigned int width = allocation.width; unsigned int height = allocation.height; /* scrollbar spacing */ gint spacing; gtk_widget_style_get(session->gtk.view, "scrollbar_spacing", &spacing, NULL); width -= spacing; /* correct view size */ if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == true) { gtk_widget_get_allocation(session->gtk.inputbar, &allocation); height += allocation.height; } double scale = 1.0; unsigned int cell_height = 0, cell_width = 0; unsigned int document_height = 0, document_width = 0; zathura_document_set_scale(zathura->document, scale); zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width); zathura_get_document_size(zathura, cell_height, cell_width, &document_height, &document_width); double page_ratio = (double)cell_height / (double)document_width; double window_ratio = (double)height / (double)width; if (argument->n == ZATHURA_ADJUST_WIDTH || (argument->n == ZATHURA_ADJUST_BESTFIT && page_ratio < window_ratio)) { scale = (double)(width - (pages_per_row - 1) * padding) / (double)(pages_per_row * cell_width); zathura_document_set_scale(zathura->document, scale); bool show_scrollbars = false; girara_setting_get(session, "show-scrollbars", &show_scrollbars); if (show_scrollbars) { /* If the document is taller than the view, there's a vertical * scrollbar; we need to substract its width from the view's width. */ zathura_get_document_size(zathura, cell_height, cell_width, &document_height, &document_width); if (height < document_height) { GtkWidget* vscrollbar = gtk_scrolled_window_get_vscrollbar( GTK_SCROLLED_WINDOW(session->gtk.view)); if (vscrollbar != NULL) { GtkRequisition requisition; gtk_widget_get_requisition(vscrollbar, &requisition); if (0 < requisition.width && (unsigned)requisition.width < width) { width -= requisition.width; scale = (double)(width - (pages_per_row - 1) * padding) / (double)(pages_per_row * cell_width); zathura_document_set_scale(zathura->document, scale); } } } } } else if (argument->n == ZATHURA_ADJUST_BESTFIT) { scale = (double)height / (double)cell_height; zathura_document_set_scale(zathura->document, scale); } else { goto error_ret; } /* keep position */ readjust_view_after_zooming(zathura, old_zoom, false); /* re-render all pages */ render_all(zathura); error_ret: return false; }