Commit c6d06f7c authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Merge branch 'develop' of pwmt.org:zathura into develop

parents b0cf2749 52775364
...@@ -42,6 +42,7 @@ enum properties_e ...@@ -42,6 +42,7 @@ enum properties_e
PROP_DRAW_LINKS, PROP_DRAW_LINKS,
PROP_LINKS_OFFSET, PROP_LINKS_OFFSET,
PROP_LINKS_NUMBER, PROP_LINKS_NUMBER,
PROP_SEARCH_RESULT,
PROP_SEARCH_RESULTS, PROP_SEARCH_RESULTS,
PROP_SEARCH_RESULTS_LENGTH, PROP_SEARCH_RESULTS_LENGTH,
PROP_SEARCH_RESULTS_CURRENT PROP_SEARCH_RESULTS_CURRENT
...@@ -73,7 +74,7 @@ zathura_page_widget_class_init(ZathuraPageClass* class) ...@@ -73,7 +74,7 @@ zathura_page_widget_class_init(ZathuraPageClass* class)
g_object_class_install_property(object_class, PROP_LINKS_NUMBER, g_object_class_install_property(object_class, PROP_LINKS_NUMBER,
g_param_spec_int("number-of-links", "number-of-links", "Number of links", 0, INT_MAX, 0, G_PARAM_READABLE)); g_param_spec_int("number-of-links", "number-of-links", "Number of links", 0, INT_MAX, 0, G_PARAM_READABLE));
g_object_class_install_property(object_class, PROP_SEARCH_RESULTS, g_object_class_install_property(object_class, PROP_SEARCH_RESULTS,
g_param_spec_pointer("search-results", "search-results", "Set to the list of search results", G_PARAM_WRITABLE)); g_param_spec_pointer("search-results", "search-results", "Set to the list of search results", G_PARAM_WRITABLE | G_PARAM_READABLE));
g_object_class_install_property(object_class, PROP_SEARCH_RESULTS_CURRENT, g_object_class_install_property(object_class, PROP_SEARCH_RESULTS_CURRENT,
g_param_spec_int("search-current", "search-current", "The current search result", -1, INT_MAX, 0, G_PARAM_WRITABLE | G_PARAM_READABLE)); g_param_spec_int("search-current", "search-current", "The current search result", -1, INT_MAX, 0, G_PARAM_WRITABLE | G_PARAM_READABLE));
g_object_class_install_property(object_class, PROP_SEARCH_RESULTS_LENGTH, g_object_class_install_property(object_class, PROP_SEARCH_RESULTS_LENGTH,
...@@ -89,6 +90,8 @@ zathura_page_widget_init(ZathuraPage* widget) ...@@ -89,6 +90,8 @@ zathura_page_widget_init(ZathuraPage* widget)
priv->links = NULL; priv->links = NULL;
priv->links_got = false; priv->links_got = false;
priv->link_offset = 0; priv->link_offset = 0;
priv->search_results = NULL;
priv->search_current = INT_MAX;
g_static_mutex_init(&(priv->lock)); g_static_mutex_init(&(priv->lock));
/* we want mouse events */ /* we want mouse events */
...@@ -175,13 +178,13 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v ...@@ -175,13 +178,13 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v
break; break;
case PROP_SEARCH_RESULTS_CURRENT: { case PROP_SEARCH_RESULTS_CURRENT: {
g_return_if_fail(priv->search_results != NULL); g_return_if_fail(priv->search_results != NULL);
if (priv->search_current < (signed) girara_list_size(priv->search_results)) { if (priv->search_current >= 0 && priv->search_current < (signed) girara_list_size(priv->search_results)) {
zathura_rectangle_t* rect = girara_list_nth(priv->search_results, priv->search_current); zathura_rectangle_t* rect = girara_list_nth(priv->search_results, priv->search_current);
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect); zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect);
redraw_rect(pageview, &rectangle); redraw_rect(pageview, &rectangle);
} }
int val = g_value_get_int(value); int val = g_value_get_int(value);
if (val == -1) { if (val < 0) {
priv->search_current = girara_list_size(priv->search_results); priv->search_current = girara_list_size(priv->search_results);
} else { } else {
priv->search_current = val; priv->search_current = val;
...@@ -212,6 +215,9 @@ zathura_page_widget_get_property(GObject* object, guint prop_id, GValue* value, ...@@ -212,6 +215,9 @@ zathura_page_widget_get_property(GObject* object, guint prop_id, GValue* value,
case PROP_SEARCH_RESULTS_CURRENT: case PROP_SEARCH_RESULTS_CURRENT:
g_value_set_int(value, priv->search_results == NULL ? -1 : priv->search_current); g_value_set_int(value, priv->search_results == NULL ? -1 : priv->search_current);
break; break;
case PROP_SEARCH_RESULTS:
g_value_set_pointer(value, priv->search_results);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
} }
...@@ -237,10 +243,6 @@ zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event) ...@@ -237,10 +243,6 @@ zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event)
unsigned int page_height = widget->allocation.height; unsigned int page_height = widget->allocation.height;
unsigned int page_width = widget->allocation.width; unsigned int page_width = widget->allocation.width;
if (priv->page->document->rotate % 180) {
page_height = widget->allocation.width;
page_width = widget->allocation.height;
}
switch (priv->page->document->rotate) { switch (priv->page->document->rotate) {
case 90: case 90:
......
...@@ -401,6 +401,9 @@ sc_search(girara_session_t* session, girara_argument_t* argument, ...@@ -401,6 +401,9 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
const int cur_page = zathura->document->current_page_number; const int cur_page = zathura->document->current_page_number;
int diff = argument->n == FORWARD ? 1 : -1; int diff = argument->n == FORWARD ? 1 : -1;
zathura_page_t* target_page = NULL;
int target_idx = 0;
for (int page_id = 0; page_id < num_pages; ++page_id) { for (int page_id = 0; page_id < num_pages; ++page_id) {
int tmp = cur_page + diff * page_id; int tmp = cur_page + diff * page_id;
zathura_page_t* page = zathura->document->pages[(tmp + num_pages) % num_pages]; zathura_page_t* page = zathura->document->pages[(tmp + num_pages) % num_pages];
...@@ -417,10 +420,13 @@ sc_search(girara_session_t* session, girara_argument_t* argument, ...@@ -417,10 +420,13 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
if (diff == 1 && current < num_search_results - 1) { if (diff == 1 && current < num_search_results - 1) {
/* the next result is on the same page */ /* the next result is on the same page */
g_object_set(page->drawing_area, "search-current", current + 1, NULL); target_page = page;
target_idx = current + 1;
// g_object_set(page->drawing_area, "search-current", current + 1, NULL);
} else if (diff == -1 && current >= 1) { } else if (diff == -1 && current >= 1) {
g_object_set(page->drawing_area, "search-current", current - 1, NULL); // g_object_set(page->drawing_area, "search-current", current - 1, NULL);
target_page = page;
target_idx = current - 1;
} else { } else {
/* the next result is on a different page */ /* the next result is on a different page */
g_object_set(page->drawing_area, "search-current", -1, NULL); g_object_set(page->drawing_area, "search-current", -1, NULL);
...@@ -430,9 +436,8 @@ sc_search(girara_session_t* session, girara_argument_t* argument, ...@@ -430,9 +436,8 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
zathura_page_t* npage = zathura->document->pages[(ntmp + 2*num_pages) % num_pages]; 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); g_object_get(npage->drawing_area, "search-length", &num_search_results, NULL);
if (num_search_results != 0) { if (num_search_results != 0) {
int next = diff == 1 ? 0 : num_search_results - 1; target_page = npage;
g_object_set(npage->drawing_area, "search-current", next, NULL); target_idx = diff == 1 ? 0 : num_search_results - 1;
page_set_delayed(zathura, npage->number);
break; break;
} }
} }
...@@ -440,6 +445,25 @@ sc_search(girara_session_t* session, girara_argument_t* argument, ...@@ -440,6 +445,25 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
break; break;
} }
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;
gtk_adjustment_set_value(view_hadjustment, MAX(view_hadjustment->lower, MIN(view_hadjustment->upper - view_hadjustment->page_size, x)));
gtk_adjustment_set_value(view_vadjustment, MAX(view_vadjustment->lower, MIN(view_vadjustment->upper - view_vadjustment->page_size, y)));
}
return false; return false;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment