callbacks.c 1.85 KB
Newer Older
Moritz Lipp's avatar
Moritz Lipp committed
1
/* See LICENSE file for license and copyright information */
Moritz Lipp's avatar
Moritz Lipp committed
2
3
4

#include <callbacks.h>
#include <girara.h>
Moritz Lipp's avatar
Moritz Lipp committed
5
#include <stdlib.h>
6
#include <gtk/gtk.h>
Moritz Lipp's avatar
Moritz Lipp committed
7
8

#include "zathura.h"
Moritz Lipp's avatar
Moritz Lipp committed
9
#include "render.h"
10
#include "document.h"
Moritz Lipp's avatar
Moritz Lipp committed
11
12
13
14

gboolean
cb_destroy(GtkWidget* widget, gpointer data)
{
Moritz Lipp's avatar
Moritz Lipp committed
15
  if (Zathura.UI.session) {
Moritz Lipp's avatar
Moritz Lipp committed
16
    girara_session_destroy(Zathura.UI.session);
Moritz Lipp's avatar
Moritz Lipp committed
17
  }
Moritz Lipp's avatar
Moritz Lipp committed
18

Moritz Lipp's avatar
Moritz Lipp committed
19
20
  document_close();

21
22
23
  /* free registered plugins */
  zathura_document_plugin_free();

Moritz Lipp's avatar
Moritz Lipp committed
24
25
  return TRUE;
}
Moritz Lipp's avatar
Moritz Lipp committed
26
27
28
29
30
31
32
33

void
buffer_changed(girara_session_t* session)
{
  g_return_if_fail(session != NULL);

  char* buffer = girara_buffer_get(session);

Moritz Lipp's avatar
Moritz Lipp committed
34
  if (buffer) {
Moritz Lipp's avatar
Moritz Lipp committed
35
    girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer);
Moritz Lipp's avatar
Moritz Lipp committed
36
    free(buffer);
Moritz Lipp's avatar
Moritz Lipp committed
37
  } else {
38
39
    girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, "");
  }
Moritz Lipp's avatar
Moritz Lipp committed
40
}
41
42
43
44

void
cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
{
Moritz Lipp's avatar
Moritz Lipp committed
45
  if (!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) {
46
47
48
49
    return;
  }

  /* get current adjustment values */
Moritz Lipp's avatar
Moritz Lipp committed
50
51
  gdouble lower = gtk_adjustment_get_value(adjustment);
  gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);
52
53

  /* find page that fits */
Moritz Lipp's avatar
Moritz Lipp committed
54
  for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++)
55
56
  {
    zathura_page_t* page = Zathura.document->pages[page_id];
Moritz Lipp's avatar
Moritz Lipp committed
57
58

    /* check for rendered attribute */
Moritz Lipp's avatar
Moritz Lipp committed
59
    if (page->rendered) {
Moritz Lipp's avatar
Moritz Lipp committed
60
61
62
      continue;
    }

63
    double begin = page->offset;
Moritz Lipp's avatar
Moritz Lipp committed
64
65
    double end   = page->offset + page->height;

Moritz Lipp's avatar
Moritz Lipp committed
66
    if (    ( (begin >= lower) && (end <= upper) ) /* page is in viewport */
Moritz Lipp's avatar
Moritz Lipp committed
67
68
69
        || ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */
        || ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */
      ) {
Moritz Lipp's avatar
Moritz Lipp committed
70
        render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]);
71
72
73
    }
  }
}