bool sc_jumplist(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); g_return_val_if_fail(zathura->document != NULL, false); zathura_jump_t* jump = NULL; switch(argument->n) { case FORWARD: zathura_jumplist_save(zathura); zathura_jumplist_forward(zathura); jump = zathura_jumplist_current(zathura); break; case BACKWARD: zathura_jumplist_save(zathura); zathura_jumplist_backward(zathura); jump = zathura_jumplist_current(zathura); break; } if (jump != NULL) { page_set(zathura, jump->page); const double s = zathura_document_get_scale(zathura->document); position_set_delayed(zathura, jump->x * s, jump->y * s); } return false; }
bool sc_bisect(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); const unsigned int num_pages = zathura_document_get_number_of_pages(zathura->document); const unsigned int cur_page = zathura_document_get_current_page_number(zathura->document); /* process arguments */ int direction; if (t > 0 && t <= num_pages) { /* bisect between cur_page and t */ t -= 1; if (t == cur_page) { /* nothing to do */ return false; } else if (t > cur_page) { zathura->bisect.start = cur_page; zathura->bisect.end = t; direction = BACKWARD; } else { zathura->bisect.start = t; zathura->bisect.end = cur_page; direction = FORWARD; } } else if (argument != NULL) { direction = argument->n; /* setup initial bisect range */ zathura_jump_t* jump = zathura_jumplist_current(zathura); if (jump == NULL) { girara_debug("bisecting between first and last page because there are no jumps"); zathura->bisect.start = 0; zathura->bisect.end = num_pages - 1; } else if (jump->page != cur_page || jump->page != zathura->bisect.last_jump) { girara_debug("last jump doesn't match up, starting new bisecting"); zathura->bisect.start = 0; zathura->bisect.end = num_pages - 1; unsigned int prev_page; if (direction == FORWARD) { prev_page = num_pages - 1; } else { prev_page = 0; } /* check if we have previous jumps */ if (zathura_jumplist_has_previous(zathura) == true) { zathura_jumplist_backward(zathura); jump = zathura_jumplist_current(zathura); if (jump != NULL) { prev_page = jump->page; } zathura_jumplist_forward(zathura); } zathura->bisect.start = MIN(prev_page, cur_page); zathura->bisect.end = MAX(prev_page, cur_page); zathura->bisect.last_jump = cur_page; } } else { return false; } girara_debug("bisecting between %d and %d, at %d", zathura->bisect.start, zathura->bisect.end, cur_page); if (zathura->bisect.start == zathura->bisect.end) { /* nothing to do */ return false; } unsigned int next_page = cur_page; unsigned int next_start = zathura->bisect.start; unsigned int next_end = zathura->bisect.end; /* here we have next_start <= next_page <= next_end */ /* bisect step */ switch(direction) { case FORWARD: if (cur_page != zathura->bisect.end) { next_page = (cur_page + zathura->bisect.end) / 2; if (next_page == cur_page) { ++next_page; } next_start = cur_page; } break; case BACKWARD: if (cur_page != zathura->bisect.start) { next_page = (cur_page + zathura->bisect.start) / 2; if (next_page == cur_page) { --next_page; } next_end = cur_page; } break; } if (next_page == cur_page) { /* nothing to do */ return false; } girara_debug("bisecting between %d and %d, jumping to %d", zathura->bisect.start, zathura->bisect.end, next_page); zathura->bisect.last_jump = next_page; zathura->bisect.start = next_start; zathura->bisect.end = next_end; zathura_jumplist_add(zathura); page_set(zathura, next_page); zathura_jumplist_add(zathura); return false; }
bool sc_jumplist(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); g_return_val_if_fail(zathura->document != NULL, false); /* if no jumps in the jumplist */ if (zathura->jumplist.size == 0) { return true; } double x = zathura_document_get_position_x(zathura->document); double y = zathura_document_get_position_y(zathura->document); zathura_jump_t* jump = NULL; zathura_jump_t* prev_jump = zathura_jumplist_current(zathura); bool go_to_current = false; if (zathura_jumplist_has_next(zathura) == false || zathura_jumplist_has_previous(zathura) == false) { if (x == prev_jump->x && y == prev_jump->y) { go_to_current = false; } else { go_to_current = true; } } switch(argument->n) { case FORWARD: if (go_to_current == true && zathura_jumplist_has_previous(zathura) == false) { jump = zathura_jumplist_current(zathura); } else { zathura_jumplist_forward(zathura); jump = zathura_jumplist_current(zathura); } break; case BACKWARD: if (go_to_current == true && zathura_jumplist_has_next(zathura) == false) { jump = zathura_jumplist_current(zathura); } else { zathura_jumplist_backward(zathura); jump = zathura_jumplist_current(zathura); } break; } if (jump == prev_jump) { if ((zathura_jumplist_has_previous(zathura) == false && argument->n == BACKWARD) || (zathura_jumplist_has_next(zathura) == false && argument->n == FORWARD)) { jump = NULL; } } if (jump != NULL) { page_set(zathura, jump->page); position_set(zathura, jump->x, jump->y); } return false; }
bool sc_bisect(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); unsigned int number_of_pages, cur_page, prev_page, prev2_page; bool have_prev, have_prev2; zathura_jump_t* prev_jump = NULL; zathura_jump_t* prev2_jump = NULL; number_of_pages= zathura_document_get_number_of_pages(zathura->document); cur_page = zathura_document_get_current_page_number(zathura->document); prev_page = prev2_page = 0; have_prev = have_prev2 = false; /* save position at current jump point */ zathura_jumplist_save(zathura); /* process arguments */ int direction; if (t > 0 && t <= number_of_pages) { /* jump to page t, and bisect between cur_page and t */ page_set(zathura, t-1); zathura_jumplist_add(zathura); if (t-1 > cur_page) { direction = BACKWARD; } else { direction = FORWARD; } } else if (argument != NULL) { direction = argument->n; } else { return false; } cur_page = zathura_document_get_current_page_number(zathura->document); if (zathura_jumplist_has_previous(zathura)) { /* If there is a previous jump, get its page */ zathura_jumplist_backward(zathura); prev_jump = zathura_jumplist_current(zathura); if (prev_jump) { prev_page = prev_jump->page; have_prev = true; } if (zathura_jumplist_has_previous(zathura)) { /* If there is a second previous jump, get its page. */ zathura_jumplist_backward(zathura); prev2_jump = zathura_jumplist_current(zathura); if (prev2_jump) { prev2_page = prev2_jump->page; have_prev2 = true; } zathura_jumplist_forward(zathura); } zathura_jumplist_forward(zathura); } /* now, we are back at the initial jump. prev_page and prev2_page contain the pages for previous and second previous jump if they exist. */ /* bisect */ switch(direction) { case FORWARD: if (have_prev && cur_page <= prev_page) { /* add a new jump point */ if (cur_page < prev_page) { page_set(zathura, (cur_page + prev_page)/2); zathura_jumplist_add(zathura); } } else if (have_prev2 && cur_page <= prev2_page) { /* save current position at previous jump point */ if (cur_page < prev2_page) { zathura_jumplist_backward(zathura); zathura_jumplist_save(zathura); zathura_jumplist_forward(zathura); page_set(zathura, (cur_page + prev2_page)/2); zathura_jumplist_save(zathura); } } else { /* none of prev_page or prev2_page comes after cur_page */ page_set(zathura, (cur_page + number_of_pages - 1)/2); zathura_jumplist_add(zathura); } break; case BACKWARD: if (have_prev && prev_page <= cur_page) { /* add a new jump point */ if (prev_page < cur_page) { page_set(zathura, (cur_page + prev_page)/2); zathura_jumplist_add(zathura); } } else if (have_prev2 && prev2_page <= cur_page) { /* save current position at previous jump point */ if (prev2_page < cur_page) { zathura_jumplist_backward(zathura); zathura_jumplist_save(zathura); zathura_jumplist_forward(zathura); page_set(zathura, (cur_page + prev2_page)/2); zathura_jumplist_save(zathura); } } else { /* none of prev_page or prev2_page comes before cur_page */ page_set(zathura, cur_page/2); zathura_jumplist_add(zathura); } break; } /* adjust horizontal position */ GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); cb_view_hadjustment_changed(hadjustment, zathura); return false; }