shortcuts.c 43.6 KB
Newer Older
1
2
/* See LICENSE file for license and copyright information */

3
4
5
6
#include <girara/session.h>
#include <girara/settings.h>
#include <girara/datastructures.h>
#include <girara/shortcuts.h>
7
#include <girara/utils.h>
Moritz Lipp's avatar
Moritz Lipp committed
8
#include <gtk/gtk.h>
9
#include <glib/gi18n.h>
Moritz Lipp's avatar
Moritz Lipp committed
10
11

#include "callbacks.h"
12
#include "shortcuts.h"
13
#include "document.h"
Moritz Lipp's avatar
Moritz Lipp committed
14
#include "zathura.h"
15
#include "render.h"
16
#include "utils.h"
Moritz Lipp's avatar
Moritz Lipp committed
17
#include "page.h"
Moritz Lipp's avatar
Moritz Lipp committed
18
#include "print.h"
19
#include "page-widget.h"
20
#include "adjustment.h"
21

22
23
24
25
26
27
28
29
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif

#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Helper function; see sc_display_link and sc_follow. */
static bool
draw_links(zathura_t* zathura)
{
  /* set pages to draw links */
  bool show_links = false;
  unsigned int page_offset = 0;
  unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
  for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
    zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
    if (page == NULL) {
      continue;
    }

    GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
Marwan Tanager's avatar
Marwan Tanager committed
45
    g_object_set(page_widget, "draw-search-results", FALSE, NULL);
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    if (zathura_page_get_visibility(page) == true) {
      g_object_set(page_widget, "draw-links", TRUE, NULL);

      int number_of_links = 0;
      g_object_get(page_widget, "number-of-links", &number_of_links, NULL);
      if (number_of_links != 0) {
        show_links = true;
      }
      g_object_set(page_widget, "offset-links", page_offset, NULL);
      page_offset += number_of_links;
    } else {
      g_object_set(page_widget, "draw-links", FALSE, NULL);
    }
  }
  return show_links;
}

Moritz Lipp's avatar
Moritz Lipp committed
63
bool
64
sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
Moritz Lipp's avatar
Moritz Lipp committed
65
         girara_event_t* UNUSED(event), unsigned int UNUSED(t))
66
{
Moritz Lipp's avatar
Moritz Lipp committed
67
  g_return_val_if_fail(session != NULL, false);
68
69
70
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

71
72
73
  bool clear_search = true;
  girara_setting_get(session, "abort-clear-search", &clear_search);

Moritz Lipp's avatar
Moritz Lipp committed
74
  if (zathura->document != NULL) {
75
    unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
76
77
    for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) {
      zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
Moritz Lipp's avatar
Moritz Lipp committed
78
79
80
81
      if (page == NULL) {
        continue;
      }

Marwan Tanager's avatar
Marwan Tanager committed
82
83
      GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
      g_object_set(page_widget, "draw-links", FALSE, NULL);
84
      if (clear_search == true) {
Marwan Tanager's avatar
Marwan Tanager committed
85
        g_object_set(page_widget, "draw-search-results", FALSE, NULL);
86
      }
87
88
    }
  }
Moritz Lipp's avatar
Moritz Lipp committed
89

Moritz Lipp's avatar
Moritz Lipp committed
90
  girara_mode_set(session, session->modes.normal);
Moritz Lipp's avatar
Moritz Lipp committed
91
  girara_sc_abort(session, NULL, NULL, 0);
Moritz Lipp's avatar
Moritz Lipp committed
92

Moritz Lipp's avatar
Moritz Lipp committed
93
  return false;
94
95
}

96
97
bool
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
Moritz Lipp's avatar
Moritz Lipp committed
98
                 girara_event_t* UNUSED(event), unsigned int UNUSED(t))
99
{
100
101
102
103
  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);
Moritz Lipp's avatar
Moritz Lipp committed
104

105
106
  unsigned int pages_per_row = 1;
  girara_setting_get(session, "pages-per-row", &pages_per_row);
Moritz Lipp's avatar
Moritz Lipp committed
107

108
109
110
  unsigned int first_page_column = 1;
  girara_setting_get(session, "first-page-column", &first_page_column);

111
112
113
  int padding = 1;
  girara_setting_get(zathura->ui.session, "page-padding", &padding);

114
  if (zathura->ui.page_widget == NULL || zathura->document == NULL) {
Moritz Lipp's avatar
Moritz Lipp committed
115
116
117
    goto error_ret;
  }

118
119
  zathura_document_set_adjust_mode(zathura->document, argument->n);
  if (argument->n == ZATHURA_ADJUST_NONE) {
120
121
122
    /* there is nothing todo */
    goto error_ret;
  }
123

Moritz Lipp's avatar
Moritz Lipp committed
124
  /* get window size */
125
126
  GtkAllocation allocation;
  gtk_widget_get_allocation(session->gtk.view, &allocation);
127
128
  unsigned int width  = allocation.width;
  unsigned int height = allocation.height;
Moritz Lipp's avatar
Moritz Lipp committed
129

130
131
132
133
134
  /* scrollbar spacing */
  gint spacing;
  gtk_widget_style_get(session->gtk.view, "scrollbar_spacing", &spacing, NULL);
  width -= spacing;

135
136
137
138
139
140
  /* 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;
  }

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  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) /
Benoît Knecht's avatar
Benoît Knecht committed
156
            (double)(pages_per_row * cell_width);
157
158
    zathura_document_set_scale(zathura->document, scale);

159
160
    bool show_vscrollbar = false;
    girara_setting_get(session, "show-v-scrollbar", &show_vscrollbar);
161

162
    if (show_vscrollbar) {
163
164
165
166
167
168
169
170
171
172
173
174
175
176
      /* 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) /
Benoît Knecht's avatar
Benoît Knecht committed
177
                    (double)(pages_per_row * cell_width);
178
179
180
181
            zathura_document_set_scale(zathura->document, scale);
          }
        }
      }
Moritz Lipp's avatar
Moritz Lipp committed
182
183
    }
  }
184
185
186
  else if (argument->n == ZATHURA_ADJUST_BESTFIT) {
    scale = (double)height / (double)cell_height;
    zathura_document_set_scale(zathura->document, scale);
Moritz Lipp's avatar
Moritz Lipp committed
187
  }
188
189
  else {
    goto error_ret;
Moritz Lipp's avatar
Moritz Lipp committed
190
191
192
193
194
195
  }

  /* re-render all pages */
  render_all(zathura);

error_ret:
Moritz Lipp's avatar
Moritz Lipp committed
196

197
  return false;
198
199
}

Moritz Lipp's avatar
Moritz Lipp committed
200
bool
Moritz Lipp's avatar
Moritz Lipp committed
201
sc_change_mode(girara_session_t* session, girara_argument_t* argument,
Moritz Lipp's avatar
Moritz Lipp committed
202
               girara_event_t* UNUSED(event), unsigned int UNUSED(t))
203
{
Moritz Lipp's avatar
Moritz Lipp committed
204
205
206
207
  g_return_val_if_fail(session != NULL, false);

  girara_mode_set(session, argument->n);

Moritz Lipp's avatar
Moritz Lipp committed
208
  return false;
209
210
}

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
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) {
227
    zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR);
228
229
230
231
232
233
234
235
    girara_dialog(zathura->ui.session, "Display link:", FALSE, NULL,
        (girara_callback_inputbar_activate_t) cb_sc_display_link,
        zathura->ui.session);
  }

  return false;
}

236
237
238
239
240
241
242
243
244
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);

245
246
  zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR);

247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
  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) {
262
263
264
265
      const char* file_path = zathura_document_get_path(zathura->document);
      if (file_path == NULL) {
        return false;
      }
266

267
268
269
270
271
      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);
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291

      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;
}

Moritz Lipp's avatar
Moritz Lipp committed
292
bool
293
sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
Moritz Lipp's avatar
Moritz Lipp committed
294
          girara_event_t* UNUSED(event), unsigned int UNUSED(t))
295
{
Moritz Lipp's avatar
Moritz Lipp committed
296
  g_return_val_if_fail(session != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
297
298
299
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

Moritz Lipp's avatar
Moritz Lipp committed
300
  if (zathura->document == NULL || zathura->ui.session == NULL) {
Moritz Lipp's avatar
Moritz Lipp committed
301
302
303
    return false;
  }

304
  bool show_links = draw_links(zathura);
Moritz Lipp's avatar
Moritz Lipp committed
305

Moritz Lipp's avatar
Moritz Lipp committed
306
  /* ask for input */
Moritz Lipp's avatar
Moritz Lipp committed
307
  if (show_links == true) {
308
    zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_INPUTBAR);
Moritz Lipp's avatar
Moritz Lipp committed
309
    girara_dialog(zathura->ui.session, "Follow link:", FALSE, NULL, (girara_callback_inputbar_activate_t) cb_sc_follow, zathura->ui.session);
Moritz Lipp's avatar
Moritz Lipp committed
310
  }
Moritz Lipp's avatar
Moritz Lipp committed
311

Moritz Lipp's avatar
Moritz Lipp committed
312
313
  return false;
}
314

Moritz Lipp's avatar
Moritz Lipp committed
315
bool
Moritz Lipp's avatar
Moritz Lipp committed
316
sc_goto(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int t)
Moritz Lipp's avatar
Moritz Lipp committed
317
{
Moritz Lipp's avatar
Moritz Lipp committed
318
319
320
321
322
  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);
323

324
  zathura_jumplist_add(zathura);
Moritz Lipp's avatar
Moritz Lipp committed
325
  if (t != 0) {
326
    /* add offset */
Moritz Lipp's avatar
Moritz Lipp committed
327
    t += zathura_document_get_page_offset(zathura->document);
328

Moritz Lipp's avatar
Moritz Lipp committed
329
    page_set(zathura, t - 1);
Moritz Lipp's avatar
Moritz Lipp committed
330
  } else if (argument->n == TOP) {
Moritz Lipp's avatar
Moritz Lipp committed
331
    page_set(zathura, 0);
Moritz Lipp's avatar
Moritz Lipp committed
332
  } else if (argument->n == BOTTOM) {
333
    page_set(zathura, zathura_document_get_number_of_pages(zathura->document) - 1);
334
335
  }

336
337
  zathura_jumplist_add(zathura);

Moritz Lipp's avatar
Moritz Lipp committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
  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);

  if (zathura->document == NULL) {
    return false;
  }

Moritz Lipp's avatar
Moritz Lipp committed
354
355
356
357
358
359
360
  static int x = 0;
  static int y = 0;

  GtkAdjustment* x_adj = NULL;
  GtkAdjustment* y_adj = NULL;

  switch (event->type) {
Moritz Lipp's avatar
Moritz Lipp committed
361
      /* scroll */
Moritz Lipp's avatar
Moritz Lipp committed
362
363
364
365
366
367
    case GIRARA_EVENT_SCROLL_UP:
    case GIRARA_EVENT_SCROLL_DOWN:
    case GIRARA_EVENT_SCROLL_LEFT:
    case GIRARA_EVENT_SCROLL_RIGHT:
      return sc_scroll(session, argument, NULL, t);

Moritz Lipp's avatar
Moritz Lipp committed
368
      /* drag */
Moritz Lipp's avatar
Moritz Lipp committed
369
370
371
372
373
374
375
376
377
378
    case GIRARA_EVENT_BUTTON_PRESS:
      x = event->x;
      y = event->y;
      break;
    case GIRARA_EVENT_BUTTON_RELEASE:
      x = 0;
      y = 0;
      break;
    case GIRARA_EVENT_MOTION_NOTIFY:
      x_adj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
Moritz Lipp's avatar
Moritz Lipp committed
379
      y_adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
Moritz Lipp's avatar
Moritz Lipp committed
380
381
382
383

      if (x_adj == NULL || y_adj == NULL) {
        return false;
      }
Moritz Lipp's avatar
Moritz Lipp committed
384

385
386
387
388
      zathura_adjustment_set_value(x_adj,
          gtk_adjustment_get_value(x_adj) - (event->x - x));
      zathura_adjustment_set_value(y_adj,
          gtk_adjustment_get_value(y_adj) - (event->y - y));
Moritz Lipp's avatar
Moritz Lipp committed
389
390
      break;

Moritz Lipp's avatar
Moritz Lipp committed
391
      /* unhandled events */
Moritz Lipp's avatar
Moritz Lipp committed
392
393
    default:
      break;
Moritz Lipp's avatar
Moritz Lipp committed
394
395
  }

Moritz Lipp's avatar
Moritz Lipp committed
396
  return false;
397
398
}

Moritz Lipp's avatar
Moritz Lipp committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
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 */
413
414
415
416
417
418
419
420
421
  switch (event->type) {
    case GIRARA_EVENT_SCROLL_UP:
      argument->n = ZOOM_IN;
      break;
    case GIRARA_EVENT_SCROLL_DOWN:
      argument->n = ZOOM_OUT;
      break;
    default:
      return false;
Moritz Lipp's avatar
Moritz Lipp committed
422
423
  }

424
  return sc_zoom(session, argument, NULL, t);
425
426
}

Moritz Lipp's avatar
Moritz Lipp committed
427
bool
Moritz Lipp's avatar
Moritz Lipp committed
428
sc_navigate(girara_session_t* session, girara_argument_t* argument,
Moritz Lipp's avatar
Moritz Lipp committed
429
            girara_event_t* UNUSED(event), unsigned int t)
430
{
Moritz Lipp's avatar
Moritz Lipp committed
431
432
433
434
435
  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);
Moritz Lipp's avatar
Moritz Lipp committed
436

437
438
  int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
  int new_page        = zathura_document_get_current_page_number(zathura->document);
Moritz Lipp's avatar
Moritz Lipp committed
439

440
441
442
  bool scroll_wrap = false;
  girara_setting_get(session, "scroll-wrap", &scroll_wrap);

443
444
445
446
447
448
449
450
  bool columns_per_row_offset = false;
  girara_setting_get(session, "advance-pages-per-row", &columns_per_row_offset);

  int offset = 1;
  if (columns_per_row_offset == true) {
    girara_setting_get(session, "pages-per-row", &offset);
  }

Moritz Lipp's avatar
Moritz Lipp committed
451
  t = (t == 0) ? (unsigned int) offset : t;
Moritz Lipp's avatar
Moritz Lipp committed
452
  if (argument->n == NEXT) {
Benoît Knecht's avatar
Benoît Knecht committed
453
    if (scroll_wrap == false) {
454
455
456
457
      new_page = new_page + t;
    } else {
      new_page = (new_page + t) % number_of_pages;
    }
Moritz Lipp's avatar
Moritz Lipp committed
458
  } else if (argument->n == PREVIOUS) {
Benoît Knecht's avatar
Benoît Knecht committed
459
    if (scroll_wrap == false) {
460
461
462
463
464
465
      new_page = new_page - t;
    } else {
      new_page = (new_page + number_of_pages - t) % number_of_pages;
    }
  }

Benoît Knecht's avatar
Benoît Knecht committed
466
  if ((new_page < 0 || new_page >= number_of_pages) && !scroll_wrap) {
467
    return false;
Moritz Lipp's avatar
Moritz Lipp committed
468
469
  }

470
  page_set(zathura, new_page);
Moritz Lipp's avatar
Moritz Lipp committed
471

Moritz Lipp's avatar
Moritz Lipp committed
472
  return false;
473
474
}

Moritz Lipp's avatar
Moritz Lipp committed
475
476
bool
sc_print(girara_session_t* session, girara_argument_t* UNUSED(argument),
Moritz Lipp's avatar
Moritz Lipp committed
477
         girara_event_t* UNUSED(event), unsigned int UNUSED(t))
Moritz Lipp's avatar
Moritz Lipp committed
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
{
  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) {
    girara_notify(session, GIRARA_ERROR, _("No document opened."));
    return false;
  }

  print(zathura);

  return true;
}

Moritz Lipp's avatar
Moritz Lipp committed
493
bool
494
sc_recolor(girara_session_t* session, girara_argument_t* UNUSED(argument),
Moritz Lipp's avatar
Moritz Lipp committed
495
           girara_event_t* UNUSED(event), unsigned int UNUSED(t))
496
{
Moritz Lipp's avatar
Moritz Lipp committed
497
  g_return_val_if_fail(session != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
498

Moritz Lipp's avatar
Moritz Lipp committed
499
500
501
502
  bool value = false;
  girara_setting_get(session, "recolor", &value);
  value = !value;
  girara_setting_set(session, "recolor", &value);
Moritz Lipp's avatar
Moritz Lipp committed
503

Moritz Lipp's avatar
Moritz Lipp committed
504
  return false;
505
506
}

Moritz Lipp's avatar
Moritz Lipp committed
507
bool
508
sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument),
Moritz Lipp's avatar
Moritz Lipp committed
509
          girara_event_t* UNUSED(event), unsigned int UNUSED(t))
510
{
Moritz Lipp's avatar
Moritz Lipp committed
511
  g_return_val_if_fail(session != NULL, false);
Moritz Lipp's avatar
Moritz Lipp committed
512
513
514
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

Moritz Lipp's avatar
Moritz Lipp committed
515
  if (zathura->file_monitor.file_path == NULL) {
Moritz Lipp's avatar
Moritz Lipp committed
516
517
518
519
    return false;
  }

  /* close current document */
Moritz Lipp's avatar
Moritz Lipp committed
520
  document_close(zathura, true);
Moritz Lipp's avatar
Moritz Lipp committed
521
522

  /* reopen document */
523
524
525
  document_open(zathura, zathura->file_monitor.file_path,
                zathura->file_monitor.password,
                ZATHURA_PAGE_NUMBER_UNSPECIFIED);
Moritz Lipp's avatar
Moritz Lipp committed
526

Moritz Lipp's avatar
Moritz Lipp committed
527
  return false;
528
529
}

Moritz Lipp's avatar
Moritz Lipp committed
530
bool
531
sc_rotate(girara_session_t* session, girara_argument_t* argument,
Moritz Lipp's avatar
Moritz Lipp committed
532
          girara_event_t* UNUSED(event), unsigned int t)
533
{
Moritz Lipp's avatar
Moritz Lipp committed
534
535
536
537
  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);
Moritz Lipp's avatar
Moritz Lipp committed
538

539
  unsigned int page_number = zathura_document_get_current_page_number(zathura->document);
540

541
542
543
544
545
  int angle = 90;
  if (argument != NULL && argument->n == ROTATE_CCW) {
    angle = 270;
  }

Moritz Lipp's avatar
Moritz Lipp committed
546
  /* update rotate value */
Moritz Lipp's avatar
Moritz Lipp committed
547
  t = (t == 0) ? 1 : t;
548
  unsigned int rotation = zathura_document_get_rotation(zathura->document);
Moritz Lipp's avatar
Moritz Lipp committed
549
  zathura_document_set_rotation(zathura->document, (rotation + angle * t) % 360);
Moritz Lipp's avatar
Moritz Lipp committed
550

551
552
553
554
  /* update scale */
  girara_argument_t new_argument = { zathura_document_get_adjust_mode(zathura->document), NULL };
  sc_adjust_window(zathura->ui.session, &new_argument, NULL, 0);

Moritz Lipp's avatar
Moritz Lipp committed
555
  /* render all pages again */
556
  render_all(zathura);
Moritz Lipp's avatar
Moritz Lipp committed
557

558
559
  page_set_delayed(zathura, page_number);

Moritz Lipp's avatar
Moritz Lipp committed
560
  return false;
561
562
}

Moritz Lipp's avatar
Moritz Lipp committed
563
bool
Moritz Lipp's avatar
Moritz Lipp committed
564
sc_scroll(girara_session_t* session, girara_argument_t* argument,
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
565
          girara_event_t* UNUSED(event), unsigned int t)
566
{
Moritz Lipp's avatar
Moritz Lipp committed
567
568
569
570
  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);
571
572
573
  if (zathura->document == NULL) {
    return false;
  }
Moritz Lipp's avatar
Moritz Lipp committed
574

Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
575
  if (t == 0) {
576
577
578
    t = 1;
  }

Moritz Lipp's avatar
Moritz Lipp committed
579
  GtkAdjustment* adjustment = NULL;
580
  if ( (argument->n == LEFT) || (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT) ||
Moritz Lipp's avatar
Moritz Lipp committed
581
       (argument->n == RIGHT) || (argument->n == FULL_RIGHT) || (argument->n == HALF_RIGHT)) {
Moritz Lipp's avatar
Moritz Lipp committed
582
    adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
Moritz Lipp's avatar
Moritz Lipp committed
583
  } else {
Moritz Lipp's avatar
Moritz Lipp committed
584
    adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
Moritz Lipp's avatar
Moritz Lipp committed
585
  }
Moritz Lipp's avatar
Moritz Lipp committed
586

587
588
589
  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;
590
  zathura->global.update_page_number = true;
591

592
593
  float scroll_step = 40;
  girara_setting_get(session, "scroll-step", &scroll_step);
Julian Orth's avatar
Julian Orth committed
594
595
596
597
598
  float scroll_hstep = -1;
  girara_setting_get(session, "scroll-hstep", &scroll_hstep);
  if (scroll_hstep < 0) {
    scroll_hstep = scroll_step;
  }
599
  float scroll_full_overlap = 0.0;
600
  girara_setting_get(session, "scroll-full-overlap", &scroll_full_overlap);
Jonas Hoersch's avatar
Jonas Hoersch committed
601
602
  bool scroll_page_aware = false;
  girara_setting_get(session, "scroll-page-aware", &scroll_page_aware);
603

604
605
606
  bool scroll_wrap = false;
  girara_setting_get(session, "scroll-wrap", &scroll_wrap);

607
608
609
  int padding = 1;
  girara_setting_get(session, "page-padding", &padding);

610
  gdouble new_value;
Moritz Lipp's avatar
Moritz Lipp committed
611

Moritz Lipp's avatar
Moritz Lipp committed
612
  switch(argument->n) {
Moritz Lipp's avatar
Moritz Lipp committed
613
    case FULL_UP:
614
    case FULL_LEFT:
615
      new_value = value - (1.0 - scroll_full_overlap) * view_size - padding;
Moritz Lipp's avatar
Moritz Lipp committed
616
617
      break;
    case FULL_DOWN:
618
    case FULL_RIGHT:
619
      new_value = value + (1.0 - scroll_full_overlap) * view_size + padding;
Moritz Lipp's avatar
Moritz Lipp committed
620
621
      break;
    case HALF_UP:
622
    case HALF_LEFT:
623
      new_value = value - ((view_size + padding) / 2);
Moritz Lipp's avatar
Moritz Lipp committed
624
625
      break;
    case HALF_DOWN:
626
    case HALF_RIGHT:
627
      new_value = value + ((view_size + padding) / 2);
Moritz Lipp's avatar
Moritz Lipp committed
628
629
      break;
    case LEFT:
630
      new_value = value - scroll_hstep * t;
Julian Orth's avatar
Julian Orth committed
631
      break;
Moritz Lipp's avatar
Moritz Lipp committed
632
    case UP:
633
      new_value = value - scroll_step * t;
Moritz Lipp's avatar
Moritz Lipp committed
634
635
      break;
    case RIGHT:
636
      new_value = value + scroll_hstep * t;
Julian Orth's avatar
Julian Orth committed
637
      break;
Moritz Lipp's avatar
Moritz Lipp committed
638
    case DOWN:
639
      new_value = value + scroll_step * t;
Moritz Lipp's avatar
Moritz Lipp committed
640
641
642
643
644
645
646
647
      break;
    case TOP:
      new_value = 0;
      break;
    case BOTTOM:
      new_value = max;
      break;
    default:
Moritz Lipp's avatar
Moritz Lipp committed
648
      new_value = value;
Moritz Lipp's avatar
Moritz Lipp committed
649
650
  }

651
652
653
654
655
656
657
  if (scroll_wrap == true) {
    if (new_value < 0)
      new_value = max;
    else if (new_value > max)
      new_value = 0;
  }

Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
658
  if (scroll_page_aware == true) {
Jonas Hoersch's avatar
Jonas Hoersch committed
659
660
661
662
663
664
665
666
667
668
669
    int page_offset;
    double page_size;

    {
      unsigned int page_id = zathura_document_get_current_page_number(zathura->document);
      zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
      page_offset_t offset;
      page_calculate_offset(zathura, page, &offset);

      double scale = zathura_document_get_scale(zathura->document);

Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
670
671
      if ((argument->n == LEFT) || (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT) ||
          (argument->n == RIGHT) || (argument->n == FULL_RIGHT) || (argument->n == HALF_RIGHT)) {
Jonas Hoersch's avatar
Jonas Hoersch committed
672
673
674
675
676
677
678
679
680
681
        page_offset = offset.x;
        page_size = zathura_page_get_width(page) * scale;
      } else {
        page_offset = offset.y;
        page_size = zathura_page_get_height(page) * scale;
      }

      page_offset -= padding / 2;
      page_size   += padding;
    }
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
682
683
684
685
686

    if ((argument->n == FULL_DOWN) || (argument->n == HALF_DOWN) ||
        (argument->n == FULL_RIGHT) || (argument->n == HALF_RIGHT)) {
      if ((page_offset > value) &&
          (page_offset < value + view_size)) {
Jonas Hoersch's avatar
Jonas Hoersch committed
687
        new_value = page_offset;
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
688
689
      } else if ((page_offset <= value) &&
                 (page_offset + page_size < value + view_size)) {
Jonas Hoersch's avatar
Jonas Hoersch committed
690
        new_value = page_offset + page_size + 1;
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
691
692
      } else if ((page_offset <= value) &&
                 (page_offset + page_size < new_value + view_size)) {
Jonas Hoersch's avatar
Jonas Hoersch committed
693
694
        new_value = page_offset + page_size - view_size + 1;
      }
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
695
696
697
698
    } else if ((argument->n == FULL_UP) || (argument->n == HALF_UP) ||
               (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT)) {
      if ((page_offset + 1 >= value) &&
          (page_offset < value + view_size)) {
Jonas Hoersch's avatar
Jonas Hoersch committed
699
        new_value = page_offset - view_size;
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
700
701
      } else if ((page_offset <= value) &&
                 (page_offset + page_size + 1 < value + view_size)) {
Jonas Hoersch's avatar
Jonas Hoersch committed
702
        new_value = page_offset + page_size - view_size;
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
703
704
      } else if ((page_offset <= value) &&
                 (page_offset > new_value)) {
Jonas Hoersch's avatar
Jonas Hoersch committed
705
706
        new_value = page_offset;
      }
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
707
    }
Jonas Hoersch's avatar
Jonas Hoersch committed
708
709
  }

710
  zathura_adjustment_set_value(adjustment, new_value);
Moritz Lipp's avatar
Moritz Lipp committed
711

Moritz Lipp's avatar
Moritz Lipp committed
712
  return false;
713
714
}

715
716

bool
717
718
sc_jumplist(girara_session_t* session, girara_argument_t* argument,
            girara_event_t* UNUSED(event), unsigned int UNUSED(t))
719
720
721
722
723
724
{
  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);
725
726
727

  /* if no jumps in the jumplist */
  if (zathura->jumplist.size == 0) {
Moritz Lipp's avatar
Moritz Lipp committed
728
    return true;
729
  }
730

731
732
733
734
  GtkAdjustment* hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
  GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
  double x = zathura_adjustment_get_ratio(hadj);
  double y = zathura_adjustment_get_ratio(vadj);
735
  zathura_jump_t* jump = NULL;
736
737
738
  zathura_jump_t* prev_jump = zathura_jumplist_current(zathura);
  bool go_to_current = false;

Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
739
  if (zathura_jumplist_has_next(zathura) == false || zathura_jumplist_has_previous(zathura) == false) {
740
741
742
743
744
745
746
    if (x == prev_jump->x && y == prev_jump->y) {
      go_to_current = false;
    } else {
      go_to_current = true;
    }
  }

747
748
  switch(argument->n) {
    case FORWARD:
749
750
751
752
753
754
      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);
      }
755
756
      break;
    case BACKWARD:
757
758
759
760
761
762
      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);
      }
763
764
765
      break;
  }

766
  if (jump == prev_jump) {
Sebastian Ramacher's avatar
CS    
Sebastian Ramacher committed
767
768
    if ((zathura_jumplist_has_previous(zathura) == false && argument->n == BACKWARD) ||
        (zathura_jumplist_has_next(zathura) == false && argument->n == FORWARD)) {
769
770
771
772
      jump = NULL;
    }
  }

773
  if (jump != NULL) {
774
775
    zathura_adjustment_set_value_from_ratio(hadj, jump->x);
    zathura_adjustment_set_value_from_ratio(vadj, jump->y);
776
777
    zathura_document_set_current_page_number(zathura->document, jump->page);
    statusbar_page_number_update(zathura);
778
}
779
780
781
782

  return false;
}

783
784
785
786
787
788
789
790
791
792
793

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);

794
795
  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);
796
797
798

  /* process arguments */
  int direction;
799
800
801
802
803
804
805
806
807
808
  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;
809
810
      direction = BACKWARD;
    } else {
811
812
      zathura->bisect.start = t;
      zathura->bisect.end = cur_page;
813
814
815
816
817
      direction = FORWARD;
    }
  } else if (argument != NULL)  {
    direction = argument->n;

Abdó Roig-Maranges's avatar
Abdó Roig-Maranges committed
818
    /* setup initial bisect range */
819
820
821
822
823
824
    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;

Moritz Lipp's avatar
Moritz Lipp committed
825
    } else if (jump->page != cur_page || jump->page != zathura->bisect.last_jump) {
Abdó Roig-Maranges's avatar
Abdó Roig-Maranges committed
826
827
828
      girara_debug("last jump doesn't match up, starting new bisecting");
      zathura->bisect.start = 0;
      zathura->bisect.end = num_pages - 1;
829

Abdó Roig-Maranges's avatar
Abdó Roig-Maranges committed
830
831
832
833
834
835
836
837
838
839
840
841
842
      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;
843
        }
Abdó Roig-Maranges's avatar
Abdó Roig-Maranges committed
844
        zathura_jumplist_forward(zathura);
845
      }
Abdó Roig-Maranges's avatar
Abdó Roig-Maranges committed
846
847
848
849

      zathura->bisect.start = MIN(prev_page, cur_page);
      zathura->bisect.end = MAX(prev_page, cur_page);
      zathura->bisect.last_jump = cur_page;
850
    }
851
852
853
854
855
856
857
858
  } 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;
859
860
  }

861
862
863
864
  unsigned int next_page = cur_page;
  unsigned int next_start = zathura->bisect.start;
  unsigned int next_end = zathura->bisect.end;

Abdó Roig-Maranges's avatar
Abdó Roig-Maranges committed
865
866
867
  /* here we have next_start <= next_page <= next_end */

  /* bisect step */
868
869
  switch(direction) {
    case FORWARD:
870
871
872
873
      if (cur_page != zathura->bisect.end) {
        next_page = (cur_page + zathura->bisect.end) / 2;
        if (next_page == cur_page) {
          ++next_page;
874
        }
875
        next_start = cur_page;
876
877
878
879
      }
      break;

    case BACKWARD:
880
881
882
883
      if (cur_page != zathura->bisect.start) {
        next_page = (cur_page + zathura->bisect.start) / 2;
        if (next_page == cur_page) {
          --next_page;
884
        }
885
        next_end = cur_page;
886
887
888
      }
      break;
  }
889

890
891
892
893
894
895
896
897
898
899
  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;

Abdó Roig-Maranges's avatar
Abdó Roig-Maranges committed
900
  zathura_jumplist_add(zathura);
901
902
903
  page_set(zathura, next_page);
  zathura_jumplist_add(zathura);

904
905
906
907
  return false;
}


Moritz Lipp's avatar
Moritz Lipp committed
908
bool
Moritz Lipp's avatar
Moritz Lipp committed
909
sc_search(girara_session_t* session, girara_argument_t* argument,
Moritz Lipp's avatar
Moritz Lipp committed
910
          girara_event_t* UNUSED(event), unsigned int UNUSED(t))
911
{
Moritz Lipp's avatar
Moritz Lipp committed
912
913
914
915
916
  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);
Moritz Lipp's avatar
Moritz Lipp committed
917

Marwan Tanager's avatar
Marwan Tanager committed
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
  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);
  GtkWidget *cur_page_widget = zathura_page_get_widget(zathura, zathura_document_get_page(zathura->document, cur_page));
  bool nohlsearch, first_time_after_abort, draw;

  nohlsearch = first_time_after_abort = draw = false;
  girara_setting_get(session, "nohlsearch", &nohlsearch);

  if (nohlsearch == false) {
    g_object_get(cur_page_widget, "draw-search-results", &draw, NULL);

    if (draw == false) {
      first_time_after_abort = true;
    }

    document_draw_search_results(zathura, true);
  }
935

936
  int diff = argument->n == FORWARD ? 1 : -1;
937
938
  if (zathura->global.search_direction == BACKWARD)
    diff = -diff;
939

Sebastian Ramacher's avatar
Sebastian Ramacher committed
940
941
942
  zathura_page_t* target_page = NULL;
  int target_idx = 0;

Marwan Tanager's avatar
Marwan Tanager committed
943
  for (unsigned int page_id = 0; page_id < num_pages; ++page_id) {
944
    int tmp = cur_page + diff * page_id;
945
    zathura_page_t* page = zathura_document_get_page(zathura->document, (tmp + num_pages) % num_pages);
946
947
948
949
    if (page == NULL) {
      continue;
    }

950
    GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
Moritz Lipp's avatar
Moritz Lipp committed
951

952
    int num_search_results = 0, current = -1;
Moritz Lipp's avatar
Moritz Lipp committed
953
    g_object_get(page_widget, "search-current", &current,
Moritz Lipp's avatar
Moritz Lipp committed
954
                 "search-length", &num_search_results, NULL);
955
956
957
958
    if (num_search_results == 0 || current == -1) {
      continue;
    }

Marwan Tanager's avatar
Marwan Tanager committed
959
960
961
962
963
964
    if (first_time_after_abort == true && num_search_results > 0) {
      target_page = page;
      target_idx = diff == 1 ? 0 : num_search_results - 1;
      break;
    }

965
966
    if (diff == 1 && current < num_search_results - 1) {
      /* the next result is on the same page */
Sebastian Ramacher's avatar
Sebastian Ramacher committed
967
968
      target_page = page;
      target_idx = current + 1;
969
    } else if (diff == -1 && current > 0) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
970
971
      target_page = page;
      target_idx = current - 1;
972
973
    } else {
      /* the next result is on a different page */
Moritz Lipp's avatar
Moritz Lipp committed
974
      g_object_set(page_widget, "search-current", -1, NULL);
975
976
977

      for (int npage_id = 1; page_id < num_pages; ++npage_id) {
        int ntmp = cur_page + diff * (page_id + npage_id);
978
        zathura_page_t* npage = zathura_document_get_page(zathura->document, (ntmp + 2*num_pages) % num_pages);
979
        GtkWidget* npage_page_widget = zathura_page_get_widget(zathura, npage);
Moritz Lipp's avatar
Moritz Lipp committed
980
        g_object_get(npage_page_widget, "search-length", &num_search_results, NULL);
981
        if (num_search_results != 0) {
Sebastian Ramacher's avatar
Sebastian Ramacher committed
982
983
          target_page = npage;
          target_idx = diff == 1 ? 0 : num_search_results - 1;
984
985
986
987
          break;
        }
      }
    }
988

989
990
    break;
  }
Moritz Lipp's avatar
Moritz Lipp committed
991

Sebastian Ramacher's avatar
Sebastian Ramacher committed
992
993
  if (target_page != NULL) {
    girara_list_t* results = NULL;
994
    GtkWidget* page_widget = zathura_page_get_widget(zathura, target_page);
Moritz Lipp's avatar
Moritz Lipp committed
995
996
    g_object_set(page_widget, "search-current", target_idx, NULL);
    g_object_get(page_widget, "search-results", &results, NULL);
Sebastian Ramacher's avatar
Sebastian Ramacher committed
997
998
999
1000

    zathura_rectangle_t* rect = girara_list_nth(results, target_idx);
    zathura_rectangle_t rectangle = recalc_rectangle(target_page, *rect);
    page_offset_t offset;
For faster browsing, not all history is shown. View entire blame