callbacks.c 2.19 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
#include "utils.h"
Moritz Lipp's avatar
Moritz Lipp committed
12
13
14
15

gboolean
cb_destroy(GtkWidget* widget, gpointer data)
{
Moritz Lipp's avatar
Moritz Lipp committed
16
  zathura_free(data);
17

Moritz Lipp's avatar
Moritz Lipp committed
18
19
  return TRUE;
}
Moritz Lipp's avatar
Moritz Lipp committed
20
21
22
23
24

void
buffer_changed(girara_session_t* session)
{
  g_return_if_fail(session != NULL);
Moritz Lipp's avatar
Moritz Lipp committed
25
26
27
  g_return_if_fail(session->global.data != NULL);

  zathura_t* zathura = session->global.data;
Moritz Lipp's avatar
Moritz Lipp committed
28
29
30

  char* buffer = girara_buffer_get(session);

Moritz Lipp's avatar
Moritz Lipp committed
31
  if (buffer) {
Moritz Lipp's avatar
Moritz Lipp committed
32
    girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, buffer);
Moritz Lipp's avatar
Moritz Lipp committed
33
    free(buffer);
Moritz Lipp's avatar
Moritz Lipp committed
34
  } else {
Moritz Lipp's avatar
Moritz Lipp committed
35
    girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, "");
36
  }
Moritz Lipp's avatar
Moritz Lipp committed
37
}
38
39
40
41

void
cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
{
Moritz Lipp's avatar
Moritz Lipp committed
42
  zathura_t* zathura = data;
Moritz Lipp's avatar
Update    
Moritz Lipp committed
43
  if (!zathura || !zathura->document || !zathura->document->pages || !zathura->ui.page_view) {
44
45
46
    return;
  }

47
  // FIXME
48
  /* get current adjustment values */
49
50
  gdouble lower = gtk_adjustment_get_value(adjustment);
  gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);
51
52

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

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

62
63
64
65
66
67
68
69
70
    page_offset_t* offset = page_calculate_offset(page);
    if (offset == NULL) {
      continue;
    }

    double begin = offset->y;
    double end   = offset->y + page->height;

    girara_info("%f %f; %f %f", begin, end, lower, upper);
Moritz Lipp's avatar
Moritz Lipp committed
71

72
73
74
75
    if (    ( (begin >= lower) && (end <= upper) ) /* [> page is in viewport <]*/
        || ( (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 <] */
      ) {
76
77
      page->visible = true;
      render_page(zathura->sync.render_thread, page);
78
79
80
81
    } else {
      page->visible = false;
      cairo_surface_destroy(page->surface);
      page->surface = NULL;
82
    }
83
84
    
    free(offset);
85
86
  }
}